66 lines
2.3 KiB
Java
66 lines
2.3 KiB
Java
package com.yaohun.enderdragonwars.liveevent;
|
|
|
|
import com.io.yutian.mclive.event.LiveGiftEvents;
|
|
import com.yaohun.enderdragonwars.Main;
|
|
import com.yaohun.enderdragonwars.data.GiftData;
|
|
import com.yaohun.enderdragonwars.manager.GameManager;
|
|
import com.yaohun.enderdragonwars.manager.GiftEffectManager;
|
|
import com.yaohun.enderdragonwars.util.GameUtil;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.Listener;
|
|
|
|
public class LiveEvent implements Listener {
|
|
|
|
@EventHandler
|
|
public void onLive(LiveGiftEvents e){
|
|
Player zhubo = e.getPlayer();
|
|
String userName = e.getUser().nickName();
|
|
boolean butt = false;
|
|
if(userName != null){
|
|
userName = e.getUser().nickName();
|
|
butt = true;
|
|
}
|
|
String giftName = e.getName();
|
|
int giftAmount = (int) e.getAmount();
|
|
if(giftAmount < 0){
|
|
giftAmount = 1;
|
|
}
|
|
GameManager gameManager = Main.gameManager;
|
|
if(gameManager.getGiftData(giftName) == null){
|
|
return;
|
|
}
|
|
GiftData giftData = gameManager.getGiftData(giftName);
|
|
String hideUserName = GameUtil.hideName(userName);
|
|
String eventName = giftData.getEvent();
|
|
if(GameUtil.specialGiftEffectTriggers(zhubo,eventName,hideUserName,giftAmount)){
|
|
return;
|
|
}
|
|
String title = "§c" + eventName;
|
|
if(giftAmount >= 2) {
|
|
title = "§c" + eventName + " x" + giftAmount;
|
|
}
|
|
String subtitle = "§9" + giftName;
|
|
if(butt) {
|
|
subtitle = "§9" + hideUserName;
|
|
}
|
|
zhubo.sendTitle(title, subtitle,0, 30, 10);
|
|
if (giftAmount <= 1) {
|
|
giftData.playSoundEvent();
|
|
GiftEffectManager.addGiftEffect(hideUserName, eventName);
|
|
} else {
|
|
long dadey = 5L;
|
|
for (int i = 0; i < giftAmount; i++) {
|
|
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
|
|
giftData.playSoundEvent();
|
|
GiftEffectManager.addGiftEffect(hideUserName, eventName);
|
|
}, (long) i * dadey);
|
|
}
|
|
}
|
|
for (Player player : Bukkit.getOnlinePlayers()){
|
|
player.sendMessage("§a礼物: §e"+ hideUserName+" §d送来了 §e"+giftName+"x"+giftAmount);
|
|
}
|
|
}
|
|
}
|