测试版1.0.3

This commit is contained in:
tianyu 2024-08-12 12:37:08 +08:00
parent 6f4263d815
commit 5b76ef37c9
2 changed files with 193 additions and 117 deletions

View File

@ -1,9 +1,10 @@
package com.yaohun.enderdragonwars.listener;
import com.io.yutian.mclive.event.ZhuboAPI;
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 com.yaohun.enderdragonwars.util.RandomUtil;
import de.tr7zw.nbtapi.NBTItem;
import org.bukkit.Bukkit;
@ -26,9 +27,74 @@ public class RepairGiftGui implements Listener {
public static String invTitle = "我的世界整蛊 - 礼物触发管理";
@EventHandler
public void onClick(InventoryClickEvent e) {
int rawSlot = e.getRawSlot();
Player zhubo = (Player) e.getWhoClicked();
Inventory inv = e.getInventory();
if (e.getView().getTitle().equalsIgnoreCase(invTitle)) {
if (rawSlot >= 0) {
e.setCancelled(true);
zhubo.closeInventory();
ItemStack stack = e.getCurrentItem();
if (stack != null && stack.getType() != Material.AIR) {
NBTItem nbti = new NBTItem(stack);
if (nbti.hasKey("giftName")) {
String giftName = nbti.getString("giftName");
String userName = "抖音" + RandomUtil.getRandomInt(1, 100);
int amount = 1;
if (e.getClick() == ClickType.RIGHT) {
amount = 10;
} else if (e.getClick() == ClickType.SHIFT_LEFT) {
amount = 66;
} else if (e.getClick() == ClickType.SHIFT_RIGHT) {
amount = 188;
}
if (Main.gameManager.getGiftData(giftName) == null) {
zhubo.sendTitle("§r", "§c未设置效果", 10, 30, 10);
return;
}
GiftData giftData = Main.gameManager.getGiftData(giftName);
String eventName = giftData.getEvent();
if (amount <= 1) {
GiftEffectManager.addGiftEffect(userName, eventName);
} else {
for (int i = 0; i < amount; i++) {
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
GiftEffectManager.addGiftEffect(userName, eventName);
}, (long) i * 5);
}
}
}
}
}
}
}
public static void OpenGui(Player p) {
Inventory inv = Bukkit.createInventory(null, 27, invTitle);
HashMap<String, ItemStack> hashMap = new HashMap<>();
if (ZhuboAPI.getRoomLiveName().equalsIgnoreCase("KuaiShou")) {
hashMap.put("棒棒糖", stackGift("棒棒糖", 101));
hashMap.put("比心", stackGift("比心", 102));
hashMap.put("粉丝团灯牌", stackGift("粉丝团灯牌", 103));
hashMap.put("集结票", stackGift("集结票", 104));
hashMap.put("浪漫风铃", stackGift("浪漫风铃", 105));
hashMap.put("玫瑰", stackGift("玫瑰", 106));
hashMap.put("玫瑰花园", stackGift("玫瑰花园", 107));
hashMap.put("魔法箱子", stackGift("魔法箱子", 108));
hashMap.put("摸摸头", stackGift("摸摸头", 109));
hashMap.put("陪伴你", stackGift("陪伴你", 110));
hashMap.put("啤酒", stackGift("啤酒", 111));
hashMap.put("人气卡", stackGift("人气卡", 112));
hashMap.put("人气票", stackGift("人气票", 113));
hashMap.put("送你花环", stackGift("送你花环", 114));
hashMap.put("童话日记", stackGift("童话日记", 115));
hashMap.put("小白菜", stackGift("小白菜", 116));
hashMap.put("钻戒", stackGift("钻戒", 117));
hashMap.put("荧光棒", stackGift("荧光棒", 118));
hashMap.put("小可爱", stackGift("小可爱", 119));
} else {
hashMap.put("ONE礼挑一", stackGift("ONE礼挑一", 1));
hashMap.put("Thuglife", stackGift("Thuglife", 2));
hashMap.put("爱的纸鹤", stackGift("爱的纸鹤", 3));
@ -86,6 +152,7 @@ public class RepairGiftGui implements Listener {
hashMap.put("纸短情长", stackGift("纸短情长", 54));
hashMap.put("蝶 · 比翼鸟", stackGift("蝶 · 比翼鸟", 56));
hashMap.put("永生花", stackGift("永生花", 57));
}
Map<String, GiftData> giftData = Main.gameManager.getGiftDataMap();
for (String giftName : giftData.keySet()) {
if (hashMap.get(giftName) != null) {
@ -98,6 +165,7 @@ public class RepairGiftGui implements Listener {
}
public static ItemStack stackGift(String name, int model_id) {
boolean hdError = true;
ItemStack item = new ItemStack(Material.PAPER);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§d§l★ §e礼物: " + name);
@ -115,10 +183,15 @@ public class RepairGiftGui implements Listener {
lore.add("§b§l★ §6SHIFT+右键 §7召唤188次");
meta.setLore(lore);
if (model_id >= 1) {
if (!hdError) {
meta.setCustomModelData(model_id);
}
} else {
item.setType(Material.DIAMOND);
}
if (hdError) {
item.setType(getMaterial(name));
}
item.setItemMeta(meta);
NBTItem nbti = new NBTItem(item);
nbti.setString("giftName", name);
@ -126,60 +199,62 @@ public class RepairGiftGui implements Listener {
return item;
}
@EventHandler
public void onClick(InventoryClickEvent e) {
int rawSlot = e.getRawSlot();
Player zhubo = (Player) e.getWhoClicked();
Inventory inv = e.getInventory();
if (e.getView().getTitle().equalsIgnoreCase(invTitle)) {
if (rawSlot >= 0) {
e.setCancelled(true);
zhubo.closeInventory();
ItemStack stack = e.getCurrentItem();
if (stack != null && stack.getType() != Material.AIR) {
NBTItem nbti = new NBTItem(stack);
if (nbti.hasKey("giftName")) {
String giftName = nbti.getString("giftName");
String userName = "抖音" + RandomUtil.getRandomInt(1, 100);
int amount = 1;
if (e.getClick() == ClickType.RIGHT) {
amount = 10;
} else if (e.getClick() == ClickType.SHIFT_LEFT) {
amount = 66;
} else if (e.getClick() == ClickType.SHIFT_RIGHT) {
amount = 188;
}
if (Main.gameManager.getGiftData(giftName) == null) {
zhubo.sendTitle("§r", "§c未设置效果", 10, 30, 10);
return;
}
GiftData giftData = Main.gameManager.getGiftData(giftName);
String hide_userName = GameUtil.hideName(userName);
String eventName = giftData.getEvent();
String eventName_Show = eventName;
if (amount >= 2) {
String title = "§c" + eventName_Show + " x" + amount;
String subtitle = "§9" + hide_userName;
zhubo.sendTitle(title, subtitle, 0, 30, 10);
} else {
String title = "§c" + eventName_Show;
String subtitle = "§9" + hide_userName;
zhubo.sendTitle(title, subtitle, 0, 30, 10);
}
if (amount <= 1) {
giftData.playSoundEvent();
GiftEffectManager.addGiftEffect(hide_userName, eventName);
} else {
for (int i = 0; i < amount; i++) {
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
giftData.playSoundEvent();
GiftEffectManager.addGiftEffect(hide_userName, eventName);
}, (long) i * 5);
}
}
}
}
}
public static Material getMaterial(String giftName) {
if (giftName.equalsIgnoreCase("抖音")) {
return Material.YELLOW_DYE;
} else if (giftName.equalsIgnoreCase("人气票")) {
return Material.MUSIC_DISC_WAIT;
} else if (giftName.equalsIgnoreCase("小心心")) {
return Material.LIME_DYE;
} else if (giftName.equalsIgnoreCase("粉丝团灯牌")) {
return Material.MAGENTA_DYE;
} else if (giftName.equalsIgnoreCase("你最好看")) {
return Material.MUSIC_DISC_BLOCKS;
} else if (giftName.equalsIgnoreCase("闪耀星辰")) {
return Material.MUSIC_DISC_WARD;
} else if (giftName.equalsIgnoreCase("黄桃罐头")) {
return Material.MUSIC_DISC_PIGSTEP;
} else if (giftName.equalsIgnoreCase("多喝热水")) {
return Material.MUSIC_DISC_CAT;
} else if (giftName.equalsIgnoreCase("比心兔兔")) {
return Material.MUSIC_DISC_13;
} else if (giftName.equalsIgnoreCase("捏捏小脸")) {
return Material.MUSIC_DISC_11;
} else if (giftName.equalsIgnoreCase("礼花筒")) {
return Material.MUSIC_DISC_STRAD;
} else if (giftName.equalsIgnoreCase("真爱玫瑰")) {
return Material.MUSIC_DISC_FAR;
} else if (giftName.equalsIgnoreCase("Thuglife")) {
return Material.PINK_DYE;
} else if (giftName.equalsIgnoreCase("助力票")) {
return Material.MUSIC_DISC_MALL;
} else if (giftName.equalsIgnoreCase("抖音1号")) {
return Material.MUSIC_DISC_STAL;
} else if (giftName.equalsIgnoreCase("大啤酒")) {
return Material.GREEN_DYE;
} else if (giftName.equalsIgnoreCase("玫瑰")) {
return Material.ORANGE_DYE;
} else if (giftName.equalsIgnoreCase("棒棒糖")) {
return Material.BROWN_DYE;
} else if (giftName.equalsIgnoreCase("鲜花")) {
return Material.GRAY_DYE;
} else if (giftName.equalsIgnoreCase("加油鸭")) {
return Material.CYAN_DYE;
} else if (giftName.equalsIgnoreCase("爱你哟")) {
return Material.BLUE_DYE;
} else if (giftName.equalsIgnoreCase("送你花花")) {
return Material.MUSIC_DISC_MELLOHI;
} else if (giftName.equalsIgnoreCase("爱的纸鹤")) {
return Material.BLACK_DYE;
} else if (giftName.equalsIgnoreCase("亲吻")) {
return Material.LIGHT_BLUE_DYE;
} else if (giftName.equalsIgnoreCase("真的爱你")) {
return Material.RED_DYE;
} else if (giftName.equalsIgnoreCase("热气球")) {
return Material.LIGHT_GRAY_DYE;
} else if (giftName.equalsIgnoreCase("跑车")) {
return Material.PURPLE_DYE;
}
return Material.GOLD_INGOT;
}
}

View File

@ -58,6 +58,7 @@ public class GiftEffectManager {
registerGiftEffect("螺旋升天", ToHeavenEffect::new);
registerGiftEffect("怪物军团", SummonMobs::new);
registerGiftEffect("芜湖起飞", WuHuJump::new);
registerGiftEffect("随机盲盒", RandomBox::new);
}
private static void registerGiftEffect(String id, Function<String, GiftEffect> giftEffectGetter) {