diff --git a/src/main/java/com/yaohun/farmingwar/FarmingWar.java b/src/main/java/com/yaohun/farmingwar/FarmingWar.java index 07662e5..9290e98 100644 --- a/src/main/java/com/yaohun/farmingwar/FarmingWar.java +++ b/src/main/java/com/yaohun/farmingwar/FarmingWar.java @@ -1,7 +1,15 @@ package com.yaohun.farmingwar; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.math.BlockVector3; +import com.yaohun.farmingwar.data.RepairGiftGui; import com.yaohun.farmingwar.game.Game; +import com.yaohun.farmingwar.game.Point; +import com.yaohun.farmingwar.game.Region; import com.yaohun.farmingwar.listener.*; +import com.yaohun.farmingwar.liveevent.GiftEventHandler; import com.yaohun.farmingwar.liveevent.GiftListener; import com.yaohun.farmingwar.liveevent.LikeListener; import com.yaohun.farmingwar.manager.GameManager; @@ -10,6 +18,11 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; +import tools.GameUtil; +import tools.RandomUtil; + +import java.util.ArrayList; +import java.util.List; public class FarmingWar extends JavaPlugin { @@ -22,6 +35,7 @@ public class FarmingWar extends JavaPlugin { instance = this; gameManager = new GameManager(); game = new Game(); + Bukkit.getPluginManager().registerEvents(new RepairGiftGui(), this); Bukkit.getPluginManager().registerEvents(new GiftListener(), this); Bukkit.getPluginManager().registerEvents(new LikeListener(gameManager), this); Bukkit.getPluginManager().registerEvents(new GamePotect(), this); @@ -29,6 +43,7 @@ public class FarmingWar extends JavaPlugin { Bukkit.getPluginManager().registerEvents(new GameListener(this), this); Bukkit.getPluginManager().registerEvents(new PlayerListener(this), this); Bukkit.getPluginManager().registerEvents(new JoinListener(this), this); + Bukkit.getPluginManager().registerEvents(new KeepEntitiesOnDeath(), this); } @Override @@ -48,6 +63,36 @@ public class FarmingWar extends JavaPlugin { return true; } game.start(); + } else if (subCommand.equalsIgnoreCase("region")) { + String regionKey = args[1]; + Player player = (Player) sender; + Actor actor = BukkitAdapter.adapt(player); + LocalSession localSession = actor.getSession(); + com.sk89q.worldedit.regions.Region region = localSession.getSelection(BukkitAdapter.adapt(player.getWorld())); + if (region == null) { + player.sendMessage("请先选中一个区域"); + return true; + } + BlockVector3 min = region.getMinimumPoint(); + BlockVector3 max = region.getMaximumPoint(); + Point minPoint = new Point(min.getBlockX(), min.getBlockY(), min.getBlockZ()); + Point maxPoint = new Point(max.getBlockX(), max.getBlockY(), max.getBlockZ()); + Region region1 = new Region(player.getWorld(), minPoint, maxPoint); + game.createRegion(regionKey,region1); + player.sendMessage("区域创建成功."); + } else if(args.length == 2 && args[0].equalsIgnoreCase("effect")){ + List players = new ArrayList<>(Bukkit.getOnlinePlayers()); + Player player = players.get(0); + if(sender instanceof Player){ + player = (Player) sender; + } + String eventName = args[1]; + String userName = "观众"+ RandomUtil.getRandomInt(0,10); + String title = "§c" + eventName; + String subtitle = "§9" + GameUtil.hideName(userName); + player.sendTitle(title, subtitle,10, 30, 10); + GiftEventHandler.SendHandLer(player,userName,eventName); + return true; } } return false; diff --git a/src/main/java/com/yaohun/farmingwar/api/Farmingv2API.java b/src/main/java/com/yaohun/farmingwar/api/Farmingv2API.java new file mode 100644 index 0000000..c1934b2 --- /dev/null +++ b/src/main/java/com/yaohun/farmingwar/api/Farmingv2API.java @@ -0,0 +1,13 @@ +package com.yaohun.farmingwar.api; + +import com.yaohun.farmingwar.util.GiftUtil; +import org.bukkit.entity.Player; + +public class Farmingv2API { + public static void sendSimulatedGiftEffect(Player player, String userName, String giftName, int amount){ + GiftUtil.simulatedGiftEffect(player,userName,giftName,amount); + } + public static void sendSimulateEventEffect(Player player,String userName,String eventName,int amount){ + GiftUtil.simulateEventEffect(player,userName,eventName,amount); + } +} diff --git a/src/main/java/com/yaohun/farmingwar/GiftData.java b/src/main/java/com/yaohun/farmingwar/data/GiftData.java similarity index 98% rename from src/main/java/com/yaohun/farmingwar/GiftData.java rename to src/main/java/com/yaohun/farmingwar/data/GiftData.java index 7cae577..8d014a8 100644 --- a/src/main/java/com/yaohun/farmingwar/GiftData.java +++ b/src/main/java/com/yaohun/farmingwar/data/GiftData.java @@ -1,4 +1,4 @@ -package com.yaohun.farmingwar; +package com.yaohun.farmingwar.data; import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; diff --git a/src/main/java/com/yaohun/farmingwar/LikeData.java b/src/main/java/com/yaohun/farmingwar/data/LikeData.java similarity index 95% rename from src/main/java/com/yaohun/farmingwar/LikeData.java rename to src/main/java/com/yaohun/farmingwar/data/LikeData.java index 039c5b4..2e88cba 100644 --- a/src/main/java/com/yaohun/farmingwar/LikeData.java +++ b/src/main/java/com/yaohun/farmingwar/data/LikeData.java @@ -1,4 +1,4 @@ -package com.yaohun.farmingwar; +package com.yaohun.farmingwar.data; public class LikeData { diff --git a/src/main/java/com/yaohun/farmingwar/data/RepairGiftGui.java b/src/main/java/com/yaohun/farmingwar/data/RepairGiftGui.java new file mode 100644 index 0000000..8a09193 --- /dev/null +++ b/src/main/java/com/yaohun/farmingwar/data/RepairGiftGui.java @@ -0,0 +1,278 @@ +package com.yaohun.farmingwar.data; + +import com.io.yutian.mclive.event.ZhuboAPI; +import com.yaohun.farmingwar.FarmingWar; +import com.yaohun.farmingwar.liveevent.GiftEventHandler; +import com.yaohun.farmingwar.util.GiftUtil; +import de.tr7zw.nbtapi.NBTItem; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import tools.GameUtil; +import tools.RandomUtil; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class RepairGiftGui implements Listener { + + public static String invTitle = "我的世界整蛊 - 礼物触发管理"; + + public static String invTitle2 = "请选择触发礼物的数量"; + public static void OpenGui(Player p,ItemStack stack){ + Inventory inv = Bukkit.createInventory(null,18,invTitle2); + inv.setItem(0,getGiftStack(stack,1,1)); + inv.setItem(1,getGiftStack(stack,2,2)); + inv.setItem(2,getGiftStack(stack,3,3)); + inv.setItem(3,getGiftStack(stack,5,5)); + inv.setItem(4,getGiftStack(stack,6,6)); + inv.setItem(5,getGiftStack(stack,7,7)); + inv.setItem(6,getGiftStack(stack,8,8)); + inv.setItem(7,getGiftStack(stack,9,9)); + inv.setItem(8,getGiftStack(stack,10,10)); + inv.setItem(9,getGiftStack(stack,6,66)); + inv.setItem(10,getGiftStack(stack,18,188)); + inv.setItem(11,getGiftStack(stack,52,520)); + inv.setItem(12,getGiftStack(stack,64,1314)); + p.openInventory(inv); + } + + public static ItemStack getGiftStack(ItemStack stack,int itemAmount,int amount){ + ItemStack item = stack.clone(); + item.setAmount(itemAmount); + ItemMeta meta = item.getItemMeta(); + List lore = new ArrayList<>(); + lore.add(" "); + lore.add("§b§l★ §6点击 §7执行§e"+amount+"§7次"); + meta.setLore(lore); + item.setItemMeta(meta); + NBTItem nbti = new NBTItem(item); + nbti.setInteger("giftAmount",amount); + return nbti.getItem(); + } + + @EventHandler + public void onClick(InventoryClickEvent e){ + int rawSlot = e.getRawSlot(); + Player zhubo = (Player) e.getWhoClicked(); + Inventory inv = e.getInventory(); + if(e.getView().getTitle().equalsIgnoreCase(invTitle2)){ + e.setCancelled(true); + if(rawSlot < 0 || rawSlot >= 18) { return;} + 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 = nbti.getInteger("giftAmount"); + GiftData giftData = FarmingWar.getGameManager().getGiftData(giftName); + giftData.OutCompleEvent(amount); + String hide_userName = GameUtil.hideName(userName); + String eventName = giftData.getEvent(); + if (GiftUtil.specialGiftEffectTriggers(zhubo, eventName, hide_userName, amount)) { + giftData.OutPlaySoundsEvent(); + return; + } + if (amount <= 1) { + String title = "§c" + eventName; + String subtitle = "§9" + hide_userName; + zhubo.sendTitle(title, subtitle, 0, 30, 10); + giftData.OutPlaySoundsEvent(); + GiftEventHandler.SendHandLer(zhubo, userName, eventName); + } else { + String title = "§c" + eventName + " x" + amount; + String subtitle = "§9" + hide_userName; + zhubo.sendTitle(title, subtitle, 0, 30, 10); + for (int i = 0; i < amount; i++) { + Bukkit.getScheduler().runTaskLater(FarmingWar.inst(), () -> { + giftData.OutPlaySoundsEvent(); + GiftEventHandler.SendHandLer(zhubo, userName, eventName); + }, (long) i * 5); + } + } + } + } + } else if(e.getView().getTitle().equalsIgnoreCase(invTitle)){ + if(rawSlot >= 0) { + e.setCancelled(true); + 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; + zhubo.closeInventory(); + if(FarmingWar.getGameManager().getGiftData(giftName) == null){ + zhubo.sendTitle("§r", "§c未设置效果",10, 30, 10); + return; + } + if(e.getClick() == ClickType.SHIFT_RIGHT || e.getClick() == ClickType.SHIFT_LEFT){ + OpenGui(zhubo,stack); + return; + } + if (e.getClick() == ClickType.RIGHT) { + amount = 10; + } + GiftData giftData = FarmingWar.getGameManager().getGiftData(giftName); + giftData.OutCompleEvent(amount); + String hide_userName = GameUtil.hideName(userName); + String eventName = giftData.getEvent(); + if(GiftUtil.specialGiftEffectTriggers(zhubo,eventName,hide_userName,amount)){ + giftData.OutPlaySoundsEvent(); + return; + } + if (amount <= 1) { + String title = "§c" + eventName; + String subtitle = "§9" + hide_userName; + zhubo.sendTitle(title, subtitle, 0, 30, 10); + giftData.OutPlaySoundsEvent(); + GiftEventHandler.SendHandLer(zhubo, userName, eventName); + } else { + String title = "§c" + eventName + " x" + amount; + String subtitle = "§9" + hide_userName; + zhubo.sendTitle(title, subtitle, 0, 30, 10); + for (int i = 0; i < amount; i++) { + Bukkit.getScheduler().runTaskLater(FarmingWar.inst(), () -> { + giftData.OutPlaySoundsEvent(); + GiftEventHandler.SendHandLer(zhubo, userName, eventName); + }, (long) i * 5); + } + } + } + } + } + } + } + + public static void OpenGui(Player p){ + Inventory inv = Bukkit.createInventory(null,27,invTitle); + HashMap 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)); + hashMap.put("爱你哟", stackGift("爱你哟", 4)); + hashMap.put("棒棒糖", stackGift("棒棒糖", 5)); + hashMap.put("比心", stackGift("比心", 6)); + hashMap.put("比心兔兔", stackGift("比心兔兔", 7)); + hashMap.put("称心如意", stackGift("称心如意", 8)); + hashMap.put("大啤酒", stackGift("大啤酒", 9)); + hashMap.put("点亮孤单", stackGift("点亮孤单", 10)); + hashMap.put("抖音", stackGift("抖音", 11)); + hashMap.put("抖音1号", stackGift("抖音1号", 12)); + hashMap.put("多喝热水", stackGift("多喝热水", 13)); + hashMap.put("繁花秘语", stackGift("繁花秘语", 14)); + hashMap.put("粉丝团灯牌", stackGift("粉丝团灯牌", 15)); + hashMap.put("光之祝福", stackGift("光之祝福", 16)); + hashMap.put("豪华邮轮", stackGift("豪华邮轮", 17)); + hashMap.put("花开烂漫", stackGift("花开烂漫", 18)); + hashMap.put("花落长亭", stackGift("花落长亭", 19)); + hashMap.put("环球旅行车", stackGift("环球旅行车", 20)); + hashMap.put("黄桃罐头", stackGift("黄桃罐头", 21)); + hashMap.put("加油鸭", stackGift("加油鸭", 22)); + hashMap.put("嘉年华", stackGift("嘉年华", 23)); + hashMap.put("浪漫花火", stackGift("浪漫花火", 24)); + hashMap.put("礼花筒", stackGift("礼花筒", 25)); + hashMap.put("龙抬头", stackGift("龙抬头", 26)); + hashMap.put("玫瑰", stackGift("玫瑰", 27)); + hashMap.put("你最好看", stackGift("你最好看", 28)); + hashMap.put("捏捏小脸", stackGift("捏捏小脸", 29)); + hashMap.put("跑车", stackGift("跑车", 30)); + hashMap.put("保时捷", stackGift("保时捷", 30)); + hashMap.put("怦然心动", stackGift("怦然心动", 31)); + hashMap.put("亲吻", stackGift("亲吻", 32)); + hashMap.put("拳拳出击", stackGift("拳拳出击", 33)); + hashMap.put("热气球", stackGift("热气球", 34)); + hashMap.put("人气票", stackGift("人气票", 35)); + hashMap.put("日出相伴", stackGift("日出相伴", 36)); + hashMap.put("闪耀星辰", stackGift("闪耀星辰", 37)); + hashMap.put("私人飞机", stackGift("私人飞机", 38)); + hashMap.put("送你花花", stackGift("送你花花", 39)); + hashMap.put("万象烟花", stackGift("万象烟花", 40)); + hashMap.put("为你闪耀", stackGift("为你闪耀", 41)); + hashMap.put("为你举牌", stackGift("为你举牌", 42)); + hashMap.put("鲜花", stackGift("鲜花", 43)); + hashMap.put("小心心", stackGift("小心心", 44)); + hashMap.put("星星点灯", stackGift("星星点灯", 45)); + hashMap.put("一点心意", stackGift("一点心意", 46)); + hashMap.put("一束花开", stackGift("一束花开", 47)); + hashMap.put("荧光棒", stackGift("荧光棒", 48)); + hashMap.put("游戏手柄", stackGift("游戏手柄", 49)); + hashMap.put("掌上明珠", stackGift("掌上明珠", 50)); + hashMap.put("真爱玫瑰", stackGift("真爱玫瑰", 51)); + hashMap.put("真的爱你", stackGift("真的爱你", 52)); + hashMap.put("直升机", stackGift("直升机", 53)); + hashMap.put("纸短情长", stackGift("纸短情长", 54)); + hashMap.put("蝶 · 比翼鸟", stackGift("蝶 · 比翼鸟", 56)); + hashMap.put("永生花", stackGift("永生花", 57)); + } + HashMap giftData = FarmingWar.getGameManager().getGiftDataMap(); + for (String giftName : giftData.keySet()){ + if(hashMap.get(giftName) != null){ + inv.addItem(hashMap.get(giftName)); + }else{ + inv.addItem(stackGift(giftName,-1)); + } + } + p.openInventory(inv); + } + + public static ItemStack stackGift(String name,int model_id) { + ItemStack item = new ItemStack(Material.PAPER); + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName("§d§l★ §e礼物: " + name); + List lore = new ArrayList<>(); + if (FarmingWar.getGameManager().getGiftData(name) != null) { + GiftData giftData = FarmingWar.getGameManager().getGiftData(name); + lore.add("§7触发效果: §a" + giftData.getEvent() + " " + giftData.getComple_Show()); + } else { + lore.add("§7触发效果: §c无"); + } + lore.add(" "); + lore.add("§b§l★ §6左键点击 §7召唤1次"); + lore.add("§b§l★ §6右键点击 §7召唤10次"); + lore.add("§b§l★ §6SHIFT+点击 §7自定义数量"); + meta.setLore(lore); + if (model_id >= 1){ + meta.setCustomModelData(model_id); + }else{ + item.setType(Material.DIAMOND); + } + item.setItemMeta(meta); + NBTItem nbti = new NBTItem(item); + nbti.setString("giftName",name); + item = nbti.getItem(); + return item; + } +} diff --git a/src/main/java/com/yaohun/farmingwar/effects/BigWindill.java b/src/main/java/com/yaohun/farmingwar/effects/BigWindill.java index f0382f9..acfb356 100644 --- a/src/main/java/com/yaohun/farmingwar/effects/BigWindill.java +++ b/src/main/java/com/yaohun/farmingwar/effects/BigWindill.java @@ -22,10 +22,10 @@ public class BigWindill { String timepieceKey = "bigWindill"; startTimepieceEvent(game,zhubo,timepieceKey); if(CDTimeAPI.isCD(uuid,timepieceKey)){ - long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (1000L * seconds); + long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (995L * seconds); CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime); } else { - CDTimeAPI.setPlayerCD(uuid,timepieceKey,1000L * seconds); + CDTimeAPI.setPlayerCD(uuid,timepieceKey,995L * seconds); } } @@ -33,6 +33,7 @@ public class BigWindill { if(CDTimeAPI.isCD(zhubo.getUniqueId(),timepieceKey)){ return; } + zhubo.playSound(zhubo.getLocation(), "dafengche", 1, 1); BukkitTask task = new BukkitRunnable() { double yaw = 0; int time = 0; @@ -49,7 +50,7 @@ public class BigWindill { zhubo.playSound(zhubo.getLocation(), "dafengche", 1, 1); } } - yaw += 24.0; // 每次旋转2度 + yaw += 45.0; // 每次旋转2度 if (yaw >= 360) { yaw -= 360; } diff --git a/src/main/java/com/yaohun/farmingwar/effects/GameSiteExpand.java b/src/main/java/com/yaohun/farmingwar/effects/GameSiteExpand.java new file mode 100644 index 0000000..21a0e36 --- /dev/null +++ b/src/main/java/com/yaohun/farmingwar/effects/GameSiteExpand.java @@ -0,0 +1,155 @@ +package com.yaohun.farmingwar.effects; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.yaohun.farmingwar.FarmingWar; +import com.yaohun.farmingwar.game.Game; +import com.yaohun.farmingwar.game.GameSite; +import com.yaohun.farmingwar.game.Point; +import com.yaohun.farmingwar.game.Region; +import com.yaohun.farmingwar.util.ExpandType; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.boss.BossBar; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.entity.Wither; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; +import org.bukkit.util.Vector; +import tools.CDTimeAPI; +import tools.GameUtil; +import tools.RandomUtil; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.UUID; + +public class GameSiteExpand { + + public static void apply(Game game,ExpandType expandType, int amount) { + if (!game.isStarted()) { + return; + } + // 获取这个类型是否已存在数据 + if(integerHashMap.get(expandType) == null){ + integerHashMap.put(expandType,amount); + } else { + int theOldAmount = integerHashMap.get(expandType); + integerHashMap.put(expandType,(theOldAmount+amount)); + } + startTimepieceEvent(game); + } + + public static boolean timerState = false; + public static HashMap integerHashMap = new HashMap<>(); + + public static void startTimepieceEvent(Game game) { + if (timerState) {return;} + timerState = true; + BukkitTask task = new BukkitRunnable() { + private int i = 0; + @Override + public void run() { + if (integerHashMap.isEmpty()) { + timerState = false; + cancel(); + return; + } + for (ExpandType expandType : integerHashMap.keySet()){ + if(expandType.equals(ExpandType.KuoJian)){ + int theOldAmount = integerHashMap.get(expandType); + GameUtil.sendAllTitle("§c扩建场地§ex"+theOldAmount,"§r",0,10,10); + KuoJianSite(game); + if(theOldAmount <= 1){ + integerHashMap.remove(expandType); + } else { + integerHashMap.put(expandType,(theOldAmount-1)); + } + GameUtil.sendAllSound("ei"); + } else if(expandType.equals(ExpandType.ChaiChu)){ + int theOldAmount = integerHashMap.get(expandType); + GameUtil.sendAllTitle("§c扩建拆除§ex"+theOldAmount,"§r",0,10,10); + ChaiChuSite(game); + if(theOldAmount <= 1){ + integerHashMap.remove(expandType); + } else { + integerHashMap.put(expandType,(theOldAmount-1)); + } + GameUtil.sendAllSound("biu"); + } + } + i--; + } + }.runTaskTimer(FarmingWar.inst(), 0L, 2L); + game.addTasks(task); + } + + public static void KuoJianSite(Game game){ + Region region = game.getRegion(); + int cacheX = (int) Math.floor(region.getMax().getX()); + double x = cacheX + 1; + Point point = region.getMax(); + point.setX(x); + region.setMax(point); + int siteY = 72; + BlockVector3 p1 = BlockVector3.at((region.getMax().getX()+1), siteY, (region.getMin().getZ()-1)); + BlockVector3 p2 = BlockVector3.at((region.getMax().getX()+1), siteY, (region.getMax().getZ()+1)); + CuboidRegion oakLogRegion = new CuboidRegion(BukkitAdapter.adapt(region.getWorld()), p1, p2); + try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(region.getWorld()))) { + editSession.setBlocks((com.sk89q.worldedit.regions.Region) oakLogRegion, BukkitAdapter.asBlockType(Material.OAK_LOG)); + } catch (Exception e) { + e.printStackTrace(); + } + Bukkit.getScheduler().runTaskLater(FarmingWar.inst(), () -> { + BlockVector3 vector1 = BlockVector3.at((region.getMax().getX()), siteY, (region.getMin().getZ())); + BlockVector3 vector2 = BlockVector3.at((region.getMax().getX()), siteY, (region.getMax().getZ())); + CuboidRegion cuboidRegion = new CuboidRegion(BukkitAdapter.adapt(region.getWorld()), vector1, vector2); + try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(region.getWorld()))) { + editSession.setBlocks((com.sk89q.worldedit.regions.Region) cuboidRegion, BukkitAdapter.asBlockType(Material.FARMLAND)); + } catch (Exception e) { + e.printStackTrace(); + } + }, 1L); + } + + public static void ChaiChuSite(Game game){ + Region region = game.getRegion(); + int cacheX = (int) Math.floor(region.getMax().getX()); + double x = cacheX - 1; + if(x < -223){ + Bukkit.broadcastMessage("§c[消息]§a已经最小了,不能再继续拆啦!"); + return; + } + Point point = region.getMax(); + point.setX(x); + region.setMax(point); + int siteY = 72; + BlockVector3 p1 = BlockVector3.at((region.getMax().getX()+1), siteY, (region.getMin().getZ()-1)); + BlockVector3 p2 = BlockVector3.at((region.getMax().getX()+2), siteY+1, (region.getMax().getZ()+1)); + CuboidRegion clearRegion = new CuboidRegion(BukkitAdapter.adapt(region.getWorld()), p1, p2); + try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(region.getWorld()))) { + editSession.setBlocks((com.sk89q.worldedit.regions.Region) clearRegion, BukkitAdapter.asBlockType(Material.AIR)); + } catch (Exception e) { + e.printStackTrace(); + } + Bukkit.getScheduler().runTaskLater(FarmingWar.inst(), () -> { + BlockVector3 vector1 = BlockVector3.at((region.getMax().getX()+1), siteY, (region.getMin().getZ()-1)); + BlockVector3 vector2 = BlockVector3.at((region.getMax().getX()+1), siteY, (region.getMax().getZ()+1)); + CuboidRegion cuboidRegion = new CuboidRegion(BukkitAdapter.adapt(region.getWorld()), vector1, vector2); + try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(region.getWorld()))) { + editSession.setBlocks((com.sk89q.worldedit.regions.Region) cuboidRegion, BukkitAdapter.asBlockType(Material.OAK_LOG)); + } catch (Exception e) { + e.printStackTrace(); + } + }, 2L); + } + +} diff --git a/src/main/java/com/yaohun/farmingwar/effects/JumpSkyTnt.java b/src/main/java/com/yaohun/farmingwar/effects/JumpSkyTnt.java new file mode 100644 index 0000000..c2bb69b --- /dev/null +++ b/src/main/java/com/yaohun/farmingwar/effects/JumpSkyTnt.java @@ -0,0 +1,36 @@ +package com.yaohun.farmingwar.effects; + +import com.yaohun.farmingwar.FarmingWar; +import com.yaohun.farmingwar.game.Game; +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; +import org.bukkit.util.Vector; +import tools.CDTimeAPI; + +import java.util.UUID; + +public class JumpSkyTnt { + + public static void apply(Game game, Player zhubo, int seconds){ + // 检测游戏是否启动 + if(!game.isStarted()){return;} + // 获取主播的uuid + UUID uuid = zhubo.getUniqueId(); + // 计时器key + String timepieceKey = "skyTnt"; + if(CDTimeAPI.isCD(uuid,timepieceKey)){ + long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (1000L * seconds); + CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime); + } else { + CDTimeAPI.setPlayerCD(uuid,timepieceKey,1000L * seconds); + } + Vector launchVector = new Vector(0, 1, 0); + zhubo.setVelocity(launchVector); + } +} diff --git a/src/main/java/com/yaohun/farmingwar/effects/JumpTnt.java b/src/main/java/com/yaohun/farmingwar/effects/JumpTnt.java new file mode 100644 index 0000000..710a017 --- /dev/null +++ b/src/main/java/com/yaohun/farmingwar/effects/JumpTnt.java @@ -0,0 +1,73 @@ +package com.yaohun.farmingwar.effects; + +import com.yaohun.farmingwar.FarmingWar; +import com.yaohun.farmingwar.game.Game; +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.Sound; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; +import tools.CDTimeAPI; + +import java.util.UUID; + +public class JumpTnt { + + public static void apply(Game game, Player zhubo, int seconds){ + // 检测游戏是否启动 + if(!game.isStarted()){return;} + // 获取主播的uuid + UUID uuid = zhubo.getUniqueId(); + // 计时器key + String timepieceKey = "jumpTnt"; + startTimepieceEvent(game,zhubo,timepieceKey); + if(CDTimeAPI.isCD(uuid,timepieceKey)){ + long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (495L * seconds); + CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime); + } else { + CDTimeAPI.setPlayerCD(uuid,timepieceKey,495L * seconds); + } + } + + public static void startTimepieceEvent(Game game,Player zhubo,String timepieceKey){ + if(CDTimeAPI.isCD(zhubo.getUniqueId(),timepieceKey)){ + return; + } + BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + if (!CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + cancel(); + return; + } + if(zhubo.isFlying()){ + zhubo.setFlying(false); + } + zhubo.playSound(zhubo.getLocation(),"huwuqifei",1,1); + zhubo.setVelocity(zhubo.getLocation().getDirection().multiply(0.5).setY(1.0)); + zhubo.playEffect(zhubo.getLocation(), Effect.MOBSPAWNER_FLAMES, 10); + zhubo.playSound(zhubo.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 1.0F, 1.0F); + BukkitTask task1 = new BukkitRunnable() { + private int i= 0; + @Override + public void run() { + if(i >= 6){cancel();} + Location location = zhubo.getLocation(); + TNTPrimed tntPrimed = (TNTPrimed) location.getWorld().spawnEntity(location.clone().add(0,-0.5,0), EntityType.PRIMED_TNT); + tntPrimed.setFuseTicks(10); + tntPrimed.setYield(0.0F); + location.getWorld().playSound(location, Sound.ENTITY_CREEPER_PRIMED, 1.0f, 1.0f); + i++; + } + }.runTaskTimer(FarmingWar.inst(), 2L,1L); + game.addTasks(task1); + } + }.runTaskTimer(FarmingWar.inst(), 0L, 10L); + game.addTasks(task); + } + +} diff --git a/src/main/java/com/yaohun/farmingwar/effects/PotionBlindness.java b/src/main/java/com/yaohun/farmingwar/effects/PotionBlindness.java new file mode 100644 index 0000000..17ff006 --- /dev/null +++ b/src/main/java/com/yaohun/farmingwar/effects/PotionBlindness.java @@ -0,0 +1,70 @@ +package com.yaohun.farmingwar.effects; + +import com.yaohun.farmingwar.FarmingWar; +import com.yaohun.farmingwar.game.Game; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; +import tools.CDTimeAPI; + +import java.util.UUID; + +public class PotionBlindness { + + public static void apply(Game game, Player zhubo, int seconds){ + // 检测游戏是否启动 + if(!game.isStarted()){return;} + // 获取主播的uuid + UUID uuid = zhubo.getUniqueId(); + // 计时器key + String timepieceKey = "turnOffTheLight"; + startTimepieceEvent(game,zhubo,timepieceKey); + if(CDTimeAPI.isCD(uuid,timepieceKey)){ + long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (1000L * seconds); + CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime); + } else { + CDTimeAPI.setPlayerCD(uuid,timepieceKey,1000L * seconds); + } + double effectTime = (CDTimeAPI.getCD(uuid,timepieceKey) / 1000.0) * 20; + // 获取现有致盲效果 + PotionEffect existingEffect = zhubo.getPotionEffect(PotionEffectType.BLINDNESS); + if (existingEffect != null) { + zhubo.removePotionEffect(PotionEffectType.BLINDNESS); + } + PotionEffect newEffect = new PotionEffect(PotionEffectType.BLINDNESS, (int) effectTime, 1); // 持续6秒(6 * 20ticks) + zhubo.addPotionEffect(newEffect); + } + + public static void startTimepieceEvent(Game game,Player zhubo,String timepieceKey) { + if (CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + return; + } + BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + if (!CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + zhubo.removePotionEffect(PotionEffectType.BLINDNESS); + zhubo.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 5, 1)); + zhubo.playSound(zhubo.getLocation(), Sound.ENTITY_PLAYER_LEVELUP,1,1); + cancel(); + return; + } + + PotionEffect existingEffect = zhubo.getPotionEffect(PotionEffectType.BLINDNESS); + if (existingEffect != null) { + // 如果已经有致盲效果,则延长其持续时间 + int newDuration = existingEffect.getDuration(); + if(newDuration <= 20){ + zhubo.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 100, 1)); + } + } else { + zhubo.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 100, 1)); + } + } + }.runTaskTimer(FarmingWar.inst(), 0L, 10L); + game.addTasks(task); + } +} diff --git a/src/main/java/com/yaohun/farmingwar/effects/SiteFillALl.java b/src/main/java/com/yaohun/farmingwar/effects/SiteFillALl.java new file mode 100644 index 0000000..1ec1b59 --- /dev/null +++ b/src/main/java/com/yaohun/farmingwar/effects/SiteFillALl.java @@ -0,0 +1,92 @@ +package com.yaohun.farmingwar.effects; + +import com.yaohun.farmingwar.FarmingWar; +import com.yaohun.farmingwar.game.Game; +import com.yaohun.farmingwar.game.Region; +import org.bukkit.Material; +import org.bukkit.Particle; +import org.bukkit.block.Block; +import org.bukkit.block.data.Ageable; +import org.bukkit.block.data.type.Farmland; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; +import tools.CDTimeAPI; +import tools.GameUtil; + +import java.util.UUID; + +public class SiteFillALl { + + public static void apply(Game game, Player zhubo, boolean all_pro){ + // 检测游戏是否启动 + if(!game.isStarted()){return;} + int i = 1; + Region region = game.getRegion(); + for (int x = (int) Math.floor(region.getMin().getX()); x <= region.getMax().getX(); x++) { + long delay = 1 + (i * 3L); + int finalX = x; + int finalI = i; + BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + Region region = game.getRegion(); + if(finalX > region.getMax().getX()){ + cancel(); + return; + } + for (int z = (int) Math.floor(region.getMin().getZ()); z <= region.getMax().getZ(); z++) { + Block block = region.getWorld().getBlockAt(finalX, (int) region.getMax().getY(), z); + block.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, block.getLocation().add(0.5, 0.5, 0.5), 6, 0.5, 0.5, 0.5, 0.1); + // 获取方块是否是小麦 + if (block.getType() == Material.WHEAT) { + // 如果是小麦则设置为7 + if(block.getBlockData() instanceof Ageable ageable) { + ageable.setAge(7); + block.setBlockData(ageable); + } + } else { + // 获取泥土方块 + Block farmland_block = block.getRelative(0,-1,0); + if(farmland_block.getBlockData() instanceof Farmland farmland){ + if(all_pro){ + // 设置为湿润泥土并设置小麦 + farmland.setMoisture(7); + farmland_block.setBlockData(farmland); + block.setType(Material.WHEAT); + if (block.getBlockData() instanceof Ageable ageable) { + ageable.setAge(7); + block.setBlockData(ageable); + } + }else { + // 判断泥土是否是湿润泥土 + if (farmland.getMoisture() == farmland.getMaximumMoisture()) { + block.setType(Material.WHEAT); + if (block.getBlockData() instanceof Ageable ageable) { + ageable.setAge(7); + block.setBlockData(ageable); + } + }else{ + farmland.setMoisture(7); + farmland_block.setBlockData(farmland); + block.setType(Material.WHEAT); + if (block.getBlockData() instanceof Ageable ageable) { + ageable.setAge(3); + block.setBlockData(ageable); + } + } + } + } + } + } + if(finalI % 8 == 0) { + GameUtil.sendAllSound("mofaxiufu"); + } + } + }.runTaskLater(FarmingWar.inst(), delay); + i++; + game.addTasks(task); + } + } + +} diff --git a/src/main/java/com/yaohun/farmingwar/effects/SpawnTnt.java b/src/main/java/com/yaohun/farmingwar/effects/SpawnTnt.java new file mode 100644 index 0000000..7b58b68 --- /dev/null +++ b/src/main/java/com/yaohun/farmingwar/effects/SpawnTnt.java @@ -0,0 +1,74 @@ +package com.yaohun.farmingwar.effects; + +import com.yaohun.farmingwar.FarmingWar; +import com.yaohun.farmingwar.game.Game; +import org.bukkit.*; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; +import org.bukkit.util.Vector; +import tools.CDTimeAPI; +import tools.GameUtil; +import tools.RandomUtil; + +import java.util.UUID; + +public class SpawnTnt { + + public static void apply(Game game, Player zhubo, int seconds){ + // 检测游戏是否启动 + if(!game.isStarted()){return;} + // 获取主播的uuid + UUID uuid = zhubo.getUniqueId(); + // 计时器key + String timepieceKey = "spawnTnt"; + startTimepieceEvent(game,zhubo,timepieceKey); + if(CDTimeAPI.isCD(uuid,timepieceKey)){ + long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (495L * seconds); + CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime); + } else { + CDTimeAPI.setPlayerCD(uuid,timepieceKey,495L * seconds); + } + } + + public static void startTimepieceEvent(Game game,Player zhubo,String timepieceKey){ + if(CDTimeAPI.isCD(zhubo.getUniqueId(),timepieceKey)){ + return; + } + BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + if (!CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + cancel(); + return; + } + for (int i = 0; i < 3; i++) { + Bukkit.getScheduler().runTaskLater(FarmingWar.inst(), () -> { + Location location = zhubo.getLocation().clone(); + TNTPrimed tntPrimed = (TNTPrimed) zhubo.getWorld().spawnEntity(location, EntityType.PRIMED_TNT); + new BukkitRunnable() { + private int timer = 0; + @Override + public void run() { + if(timer >= 20 || tntPrimed.isDead()){ + cancel(); + return; + } + location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK,tntPrimed.getLocation(),2); + timer++; + } + }.runTaskTimer(FarmingWar.inst(),0,2L); + tntPrimed.setFuseTicks(30); + tntPrimed.setYield(2.0F); + tntPrimed.setVelocity(GameUtil.getRandomVector(0.5,0.2)); + location.getWorld().playSound(location, Sound.ENTITY_CREEPER_PRIMED, 1.0f, 1.0f); + }, (long) i * 2); + } + } + }.runTaskTimer(FarmingWar.inst(), 0L, 10L); + game.addTasks(task); + } + +} diff --git a/src/main/java/com/yaohun/farmingwar/effects/SummonTheBee.java b/src/main/java/com/yaohun/farmingwar/effects/SummonTheBee.java index 39a7241..c8c20da 100644 --- a/src/main/java/com/yaohun/farmingwar/effects/SummonTheBee.java +++ b/src/main/java/com/yaohun/farmingwar/effects/SummonTheBee.java @@ -9,6 +9,7 @@ import org.bukkit.entity.Bee; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.util.Vector; +import tools.GameUtil; import tools.RandomUtil; public class SummonTheBee { @@ -61,7 +62,6 @@ public class SummonTheBee { entity.setHealth(1); entity.setCustomName("§c" + userName); entity.setCustomNameVisible(true); - Vector vector = new Vector(RandomUtil.getRandomDouble(-1,1,1),RandomUtil.getRandomDouble(-1,1,1),RandomUtil.getRandomDouble(-1,1,1)); - entity.setVelocity(vector); + entity.setVelocity(GameUtil.getRandomVector(0.5)); } } diff --git a/src/main/java/com/yaohun/farmingwar/effects/SummonTheCow.java b/src/main/java/com/yaohun/farmingwar/effects/SummonTheCow.java new file mode 100644 index 0000000..c4f629a --- /dev/null +++ b/src/main/java/com/yaohun/farmingwar/effects/SummonTheCow.java @@ -0,0 +1,129 @@ +package com.yaohun.farmingwar.effects; + +import com.yaohun.farmingwar.FarmingWar; +import com.yaohun.farmingwar.game.Game; +import com.yaohun.farmingwar.game.GameSite; +import com.yaohun.farmingwar.game.Region; +import org.bukkit.DyeColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Particle; +import org.bukkit.block.Block; +import org.bukkit.block.data.Ageable; +import org.bukkit.block.data.BlockData; +import org.bukkit.entity.Cow; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.entity.Sheep; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; +import org.bukkit.util.Vector; +import tools.CDTimeAPI; +import tools.RandomUtil; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class SummonTheCow { + + public static void apply(Game game, Player zhubo, String userName, int amount) { + if (!game.isStarted()) { + return; + } + // 获取主播的uuid + UUID uuid = zhubo.getUniqueId(); + // 计时器key + String timepieceKey = "SummonCowEffect"; + startTimepieceEvent(game,zhubo,userName,timepieceKey); + if(CDTimeAPI.isCD(uuid,timepieceKey)){ + long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (245L * amount); + CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime); + } else { + CDTimeAPI.setPlayerCD(uuid,timepieceKey,245L * amount); + } + } + + public static void startTimepieceEvent(Game game,Player zhubo,String userName,String timepieceKey) { + if (CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + return; + } + BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + if (!CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + cancel(); + return; + } + spawnMobs(game,userName); + } + }.runTaskTimer(FarmingWar.inst(), 0L, 5L); + game.addTasks(task); + } + + public static void spawnMobs(Game game,String userName){ + Region region = game.getRegion(); + Location location = GameSite.getMinerWheat_MaxAmount_Location(); + location.setYaw(-90); + EntityType entityType = EntityType.COW; + Cow entity = (Cow) location.getWorld().spawnEntity(location, entityType); + entity.setMaxHealth(100); + entity.setCustomNameVisible(true); + entity.setCustomName("§c" + userName); + BukkitTask task = new BukkitRunnable() { + private int i = 0; + // 计算将在多少i后自动消失 + private double remove_x_i = (region.getMax().getX() - region.getMin().getX()) * 7; + private List integerList = new ArrayList<>(); + @Override + public void run() { + Location location = entity.getLocation().clone(); + if(i >= remove_x_i){ + if(!entity.isDead()) { + entity.remove(); + } + cancel(); + return; + } + if (entity.isDead() || location.getX() >= region.getMax().getX()+0.5) { + entity.remove(); + cancel(); + return; + } + Vector vector0 = new Vector(1, 0, 0); + vector0.normalize(); + vector0.multiply(0.15); + entity.setRotation(-90, 0); + entity.setVelocity(vector0); + location.setY(region.getMax().getY()); + // 获取生物当前所在位置的方块 + Block block = location.getBlock(); + // 判断这个方块是否在游戏场地 + if(region.isInRegion(block.getLocation())) { + // 获取这个方块的ID代号 + int hashCode = block.hashCode(); + // 判断这个方块是否已录入系统 若已录入则跳过 + if(!integerList.contains(hashCode)){ + integerList.add(hashCode); + // 判断方块是否是小麦 + if (block.getType() == Material.WHEAT) { + if(block.getBlockData() instanceof Ageable ageable){ + block.setType(Material.AIR); + // 增加积分Main.configYml.addUser_Wheat(userName, 1); + block.getWorld().spawnParticle(Particle.VILLAGER_ANGRY, block.getLocation().add(0.5, 0.5, 0.5), 2, 0.5, 0.5, 0.5, 0.1); + if(ageable.getAge() < 5){ + block.getRelative(0,-1,0).setType(Material.FARMLAND); + } + } + } else { + block.getRelative(0,-1,0).setType(Material.FARMLAND); + } + } + } + i++; + } + }.runTaskTimer(FarmingWar.inst(), 1L, 1L); + game.addTasks(task); + } + +} diff --git a/src/main/java/com/yaohun/farmingwar/effects/SummonTheDragon.java b/src/main/java/com/yaohun/farmingwar/effects/SummonTheDragon.java new file mode 100644 index 0000000..e37e654 --- /dev/null +++ b/src/main/java/com/yaohun/farmingwar/effects/SummonTheDragon.java @@ -0,0 +1,138 @@ +package com.yaohun.farmingwar.effects; + +import com.yaohun.farmingwar.FarmingWar; +import com.yaohun.farmingwar.game.Game; +import com.yaohun.farmingwar.game.Region; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.boss.BossBar; +import org.bukkit.entity.EnderDragon; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.entity.Wither; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; +import org.bukkit.util.Vector; +import tools.CDTimeAPI; +import tools.RandomUtil; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class SummonTheDragon { + + public static void apply(Game game, Player zhubo, String userName, int amount) { + if (!game.isStarted()) { + return; + } + // 获取主播的uuid + UUID uuid = zhubo.getUniqueId(); + // 计时器key + String timepieceKey = "SummonDragonEffect"; + startTimepieceEvent(game,zhubo,userName,timepieceKey); + if(CDTimeAPI.isCD(uuid,timepieceKey)){ + long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (4950L * amount); + CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime); + } else { + CDTimeAPI.setPlayerCD(uuid,timepieceKey,4950L * amount); + } + } + + public static void startTimepieceEvent(Game game,Player zhubo,String userName,String timepieceKey) { + if (CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + return; + } + BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + if (!CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + cancel(); + return; + } + World world = game.getRegion().getWorld(); + spawnMobs(game,userName,new Location(world,-224.5,73,252.0)); + spawnMobs(game,userName,new Location(world,-224.5,73,261.0)); + } + }.runTaskTimer(FarmingWar.inst(), 0L, 20L * 5); + game.addTasks(task); + } + + public static void spawnMobs(Game game,String userName,Location location){ + location.setYaw(-90); + Region region = game.getRegion(); + EnderDragon entity = (EnderDragon) location.getWorld().spawnEntity(location, EntityType.ENDER_DRAGON); + entity.setTarget(null); + entity.setCollidable(false); + entity.setMaxHealth(300); + BossBar bossBar = entity.getBossBar(); + if (bossBar != null) { + bossBar.removeAll(); + } + entity.setCustomNameVisible(true); + entity.setCustomName("§c" + userName); + BukkitTask task = new BukkitRunnable() { + private int i = 0; + // 计算将在多少i后自动消失 + private double remove_x_i = (region.getMax().getX() - region.getMin().getX()) * 7; + private List integerList = new ArrayList<>(); + @Override + public void run() { + Location location = entity.getLocation().clone(); + if(i >= remove_x_i){ + if(!entity.isDead()) { + entity.setHealth(0); + } + cancel(); + return; + } + if (entity.isDead() || location.getX() >= region.getMax().getX()+0.5) { + if(!entity.isDead()) { + entity.setHealth(0); + } + cancel(); + return; + } + Vector vector0 = new Vector(1, 0, 0); + vector0.normalize(); + vector0.multiply(0.15); + Location location1 = entity.getLocation().add(vector0); + location1.setYaw(90); + location1.setPitch(0); + entity.teleport(location1); + location.setY(region.getMax().getY()); + if(i % 4 == 0 && RandomUtil.getRandomInt(1,100) >= 95){ + location.getWorld().strikeLightningEffect(location); + } + BossBar bossBar = entity.getBossBar(); + if (bossBar != null) { + bossBar.removeAll(); + } + // 破坏方块的范围 + int range = 8; + int centerZ = location.getBlockZ(); + // 遍历周围的 z 坐标 + for (int z = centerZ - range; z <= centerZ + range; z++) { + // 获取当前坐标的方块 + Block block = region.getWorld().getBlockAt((int) location.getX(), (int) location.getY(), z); + // 判断这个方块是否在游戏场地 + if (region.isInRegion(block.getLocation())) { + // 获取这个方块的ID代号 + int hashCode = block.hashCode(); + // 判断这个方块是否已录入系统 若已录入则跳过 + if (!integerList.contains(hashCode)) { + integerList.add(hashCode); + block.setType(Material.AIR); + block.getRelative(0, -1, 0).setType(Material.FARMLAND); + } + } + } + i++; + } + }.runTaskTimer(FarmingWar.inst(), 1L, 1L); + game.addTasks(task); + } + +} diff --git a/src/main/java/com/yaohun/farmingwar/effects/SummonTheGiant.java b/src/main/java/com/yaohun/farmingwar/effects/SummonTheGiant.java new file mode 100644 index 0000000..850cb8f --- /dev/null +++ b/src/main/java/com/yaohun/farmingwar/effects/SummonTheGiant.java @@ -0,0 +1,131 @@ +package com.yaohun.farmingwar.effects; + +import com.yaohun.farmingwar.FarmingWar; +import com.yaohun.farmingwar.game.Game; +import com.yaohun.farmingwar.game.Region; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.boss.BossBar; +import org.bukkit.entity.EnderDragon; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Giant; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; +import org.bukkit.util.Vector; +import tools.CDTimeAPI; +import tools.RandomUtil; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class SummonTheGiant { + + public static void apply(Game game, Player zhubo, String userName, int amount) { + if (!game.isStarted()) { + return; + } + // 获取主播的uuid + UUID uuid = zhubo.getUniqueId(); + // 计时器key + String timepieceKey = "SummonGiantEffect"; + startTimepieceEvent(game,zhubo,userName,timepieceKey); + if(CDTimeAPI.isCD(uuid,timepieceKey)){ + long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (4995L * amount); + CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime); + } else { + CDTimeAPI.setPlayerCD(uuid,timepieceKey,4995L * amount); + } + } + + public static void startTimepieceEvent(Game game,Player zhubo,String userName,String timepieceKey) { + if (CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + return; + } + BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + if (!CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + cancel(); + return; + } + World world = game.getRegion().getWorld(); + spawnMobs(game,userName,new Location(world,-224.5,73,252.0)); + spawnMobs(game,userName,new Location(world,-224.5,73,261.0)); + } + }.runTaskTimer(FarmingWar.inst(), 0L, 100L); + game.addTasks(task); + } + + public static void spawnMobs(Game game,String userName,Location location){ + location.setYaw(-90); + Region region = game.getRegion(); + Giant entity = (Giant) location.getWorld().spawnEntity(location, EntityType.GIANT); + entity.setTarget(null); + entity.setCollidable(false); + entity.setMaxHealth(150); + entity.setCustomNameVisible(true); + entity.setCustomName("§c" + userName); + entity.setAI(false); + BukkitTask task = new BukkitRunnable() { + private int i = 0; + // 计算将在多少i后自动消失 + private double remove_x_i = (region.getMax().getX() - region.getMin().getX()) * 7; + private List integerList = new ArrayList<>(); + @Override + public void run() { + Location location = entity.getLocation().clone(); + if(i >= remove_x_i){ + if(!entity.isDead()) { + entity.setHealth(0); + } + cancel(); + return; + } + if (entity.isDead() || location.getX() >= region.getMax().getX()+0.5) { + if(!entity.isDead()) { + entity.setHealth(0); + } + cancel(); + return; + } + Vector vector0 = new Vector(1, 0, 0); + vector0.normalize(); + vector0.multiply(0.15); + Location location1 = entity.getLocation().add(vector0); + location1.setYaw(-90); + location1.setPitch(0); + entity.teleport(location1); + location.setY(region.getMax().getY()); + if(i % 4 == 0 && RandomUtil.getRandomInt(1,100) >= 95){ + location.getWorld().strikeLightningEffect(location); + } + // 破坏方块的范围 + int range = 8; + int centerZ = location.getBlockZ(); + // 遍历周围的 z 坐标 + for (int z = centerZ - range; z <= centerZ + range; z++) { + // 获取当前坐标的方块 + Block block = region.getWorld().getBlockAt((int) location.getX(), (int) location.getY(), z); + // 判断这个方块是否在游戏场地 + if (region.isInRegion(block.getLocation())) { + // 获取这个方块的ID代号 + int hashCode = block.hashCode(); + // 判断这个方块是否已录入系统 若已录入则跳过 + if (!integerList.contains(hashCode)) { + integerList.add(hashCode); + block.setType(Material.AIR); + block.getRelative(0, -1, 0).setType(Material.FARMLAND); + } + } + } + i++; + } + }.runTaskTimer(FarmingWar.inst(), 1L, 1L); + game.addTasks(task); + } + +} diff --git a/src/main/java/com/yaohun/farmingwar/effects/SummonTheHorse.java b/src/main/java/com/yaohun/farmingwar/effects/SummonTheHorse.java new file mode 100644 index 0000000..19a5489 --- /dev/null +++ b/src/main/java/com/yaohun/farmingwar/effects/SummonTheHorse.java @@ -0,0 +1,139 @@ +package com.yaohun.farmingwar.effects; + +import com.yaohun.farmingwar.FarmingWar; +import com.yaohun.farmingwar.game.Game; +import com.yaohun.farmingwar.game.GameSite; +import com.yaohun.farmingwar.game.Region; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Particle; +import org.bukkit.block.Block; +import org.bukkit.block.data.Ageable; +import org.bukkit.block.data.BlockData; +import org.bukkit.entity.*; +import org.bukkit.inventory.ItemStack; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; +import org.bukkit.util.Vector; +import tools.CDTimeAPI; +import tools.RandomUtil; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class SummonTheHorse { + + public static void apply(Game game, Player zhubo, String userName, int amount) { + if (!game.isStarted()) { + return; + } + // 获取主播的uuid + UUID uuid = zhubo.getUniqueId(); + // 计时器key 马 + String timepieceKey = "SummonHorseEffect"; + startTimepieceEvent(game,zhubo,userName,timepieceKey); + if(CDTimeAPI.isCD(uuid,timepieceKey)){ + long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (245L * amount); + CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime); + } else { + CDTimeAPI.setPlayerCD(uuid,timepieceKey,245L * amount); + } + + } + + public static void startTimepieceEvent(Game game,Player zhubo,String userName,String timepieceKey) { + if (CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + return; + } + BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + if (!CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + cancel(); + return; + } + for (int i = 0; i < 10; i++) { + spawnMobs(game,userName); + } + } + }.runTaskTimer(FarmingWar.inst(), 0L, 5L); + game.addTasks(task); + } + + public static void spawnMobs(Game game,String userName) { + Region region = game.getRegion(); + Location location = GameSite.getMinerWheat_MaxAmount_Location(); + location.setYaw(-90); + EntityType entityType = EntityType.HORSE; + Horse entity = (Horse) location.getWorld().spawnEntity(location, entityType); + entity.setTamed(true); + int rand = RandomUtil.getRandomInt(1,100); + if(rand >= 90){ + entity.getInventory().setArmor(new ItemStack(Material.DIAMOND_HORSE_ARMOR)); + }else if(rand >= 80){ + entity.getInventory().setArmor(new ItemStack(Material.GOLDEN_HORSE_ARMOR)); + } + entity.getInventory().setSaddle(new ItemStack(Material.SADDLE)); + entity.setAdult(); + entity.setMaxHealth(100); + entity.setCustomNameVisible(true); + entity.setCustomName("§c" + userName); + BukkitTask task = new BukkitRunnable() { + private int i = 0; + // 计算将在多少i后自动消失 + private double remove_x_i = (region.getMax().getX() - region.getMin().getX()) * 7; + private List integerList = new ArrayList<>(); + + @Override + public void run() { + Location location = entity.getLocation().clone(); + if (i >= remove_x_i) { + if (!entity.isDead()) { + entity.remove(); + } + cancel(); + return; + } + if (entity.isDead() || location.getX() >= region.getMax().getX() + 0.5) { + entity.remove(); + cancel(); + return; + } + Vector vector0 = new Vector(1, 0, 0); + vector0.normalize(); + vector0.multiply(0.15); + entity.setVelocity(vector0); + entity.setRotation(-90, 0); + location.setY(region.getMax().getY()); + // 获取生物当前所在位置的方块 + Block block = location.getBlock(); + // 判断这个方块是否在游戏场地 + if(region.isInRegion(block.getLocation())) { + // 获取这个方块的ID代号 + int hashCode = block.hashCode(); + // 判断这个方块是否已录入系统 若已录入则跳过 + if(!integerList.contains(hashCode)){ + integerList.add(hashCode); + // 判断方块是否是小麦 + if (block.getType() == Material.WHEAT) { + if(block.getBlockData() instanceof Ageable ageable){ + block.setType(Material.AIR); + // 增加积分Main.configYml.addUser_Wheat(userName, 1); + block.getWorld().spawnParticle(Particle.VILLAGER_ANGRY, block.getLocation().add(0.5, 0.5, 0.5), 2, 0.5, 0.5, 0.5, 0.1); + if(ageable.getAge() < 5){ + block.getRelative(0,-1,0).setType(Material.FARMLAND); + } + } + } else { + block.getRelative(0,-1,0).setType(Material.FARMLAND); + } + } + } + i++; + } + }.runTaskTimer(FarmingWar.inst(), 1L, 1L); + game.addTasks(task); + } + +} diff --git a/src/main/java/com/yaohun/farmingwar/effects/SummonTheIrongolem.java b/src/main/java/com/yaohun/farmingwar/effects/SummonTheIrongolem.java new file mode 100644 index 0000000..41d3622 --- /dev/null +++ b/src/main/java/com/yaohun/farmingwar/effects/SummonTheIrongolem.java @@ -0,0 +1,102 @@ +package com.yaohun.farmingwar.effects; + +import com.yaohun.farmingwar.FarmingWar; +import com.yaohun.farmingwar.game.Game; +import com.yaohun.farmingwar.game.Region; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.IronGolem; +import org.bukkit.entity.Player; +import org.bukkit.entity.TraderLlama; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; +import org.bukkit.util.Vector; +import tools.CDTimeAPI; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class SummonTheIrongolem { + + public static void apply(Game game, Player zhubo, String userName, int amount) { + if (!game.isStarted()) { + return; + } + // 获取主播的uuid + UUID uuid = zhubo.getUniqueId(); + // 计时器key + String timepieceKey = "SummonIrongolemEffect"; + startTimepieceEvent(game,zhubo,userName,timepieceKey); + if(CDTimeAPI.isCD(uuid,timepieceKey)){ + long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (1995L * amount); + CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime); + } else { + CDTimeAPI.setPlayerCD(uuid,timepieceKey,1995L * amount); + } + } + + public static void startTimepieceEvent(Game game,Player zhubo,String userName,String timepieceKey) { + if (CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + return; + } + BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + if (!CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + cancel(); + return; + } + World world = game.getRegion().getWorld(); + SiteFillALl.apply(game,zhubo,true); + spawnMobs(game,userName,new Location(world,-224.5,73,264.0)); + spawnMobs(game,userName,new Location(world,-224.5,73,259.0)); + spawnMobs(game,userName,new Location(world,-224.5,73,254.0)); + spawnMobs(game,userName,new Location(world,-224.5,73,249.0)); + } + }.runTaskTimer(FarmingWar.inst(), 0L, 40L); + game.addTasks(task); + } + + public static void spawnMobs(Game game,String userName,Location location){ + Region region = game.getRegion(); + location.setYaw(-90); + IronGolem entity = (IronGolem) location.getWorld().spawnEntity(location, EntityType.IRON_GOLEM); + entity.setTarget(null); + entity.setCollidable(false); + entity.setMaxHealth(100); + entity.setCustomNameVisible(true); + entity.setCustomName("§a" + userName); + BukkitTask task = new BukkitRunnable() { + private int i = 0; + // 计算将在多少i后自动消失 + private double remove_x_i = (region.getMax().getX() - region.getMin().getX()) * 4; + private List integerList = new ArrayList<>(); + @Override + public void run() { + Location location = entity.getLocation().clone(); + if(i >= remove_x_i){ + if(!entity.isDead()) { + entity.remove(); + } + cancel(); + return; + } + if (entity.isDead() || location.getX() >= region.getMax().getX()+0.5) { + entity.remove(); + cancel(); + return; + } + Vector vector0 = new Vector(1, 0, 0); + vector0.normalize(); + vector0.multiply(0.32); + entity.setRotation(-90, 0); + entity.setVelocity(vector0); + i++; + } + }.runTaskTimer(FarmingWar.inst(), 1L, 1L); + game.addTasks(task); + } + +} diff --git a/src/main/java/com/yaohun/farmingwar/effects/SummonTheMagmacube.java b/src/main/java/com/yaohun/farmingwar/effects/SummonTheMagmacube.java new file mode 100644 index 0000000..7752fc1 --- /dev/null +++ b/src/main/java/com/yaohun/farmingwar/effects/SummonTheMagmacube.java @@ -0,0 +1,133 @@ +package com.yaohun.farmingwar.effects; + +import com.yaohun.farmingwar.FarmingWar; +import com.yaohun.farmingwar.game.Game; +import com.yaohun.farmingwar.game.GameSite; +import com.yaohun.farmingwar.game.Region; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Particle; +import org.bukkit.block.Block; +import org.bukkit.block.data.Ageable; +import org.bukkit.entity.Cow; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.MagmaCube; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; +import org.bukkit.util.Vector; +import tools.CDTimeAPI; +import tools.RandomUtil; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class SummonTheMagmacube { + + public static void apply(Game game, Player zhubo, String userName, int amount) { + if (!game.isStarted()) { + return; + } + // 获取主播的uuid + UUID uuid = zhubo.getUniqueId(); + // 计时器key + String timepieceKey = "SummonMagmacubeEffect"; + startTimepieceEvent(game,zhubo,userName,timepieceKey); + if(CDTimeAPI.isCD(uuid,timepieceKey)){ + long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (1995L * amount); + CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime); + } else { + CDTimeAPI.setPlayerCD(uuid,timepieceKey,1995L * amount); + } + } + + public static void startTimepieceEvent(Game game,Player zhubo,String userName,String timepieceKey) { + if (CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + return; + } + BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + if (!CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + cancel(); + return; + } + spawnMobs(game,userName); + } + }.runTaskTimer(FarmingWar.inst(), 0L, 40L); + game.addTasks(task); + } + + public static void spawnMobs(Game game,String userName){ + Region region = game.getRegion(); + Location location = GameSite.getMinerWheat_MaxAmount_Location(); + location.setYaw(-90); + if(location.getZ() >= 41){ + location = location.add(0,0,-3); + }else if(location.getZ() <= 1){ + location = location.add(0,0,3); + } + MagmaCube entity = (MagmaCube) location.getWorld().spawnEntity(location, EntityType.MAGMA_CUBE); + entity.setSize(8); + entity.setTarget(null); + entity.setCollidable(false); + entity.setMaxHealth(100); + entity.setCustomNameVisible(true); + entity.setCustomName("§c" + userName); + BukkitTask task = new BukkitRunnable() { + private int i = 0; + // 计算将在多少i后自动消失 + private double remove_x_i = (region.getMax().getX() - region.getMin().getX()) * 10; + private List integerList = new ArrayList<>(); + @Override + public void run() { + Location location = entity.getLocation().clone(); + if(i >= remove_x_i){ + if(!entity.isDead()) { + entity.remove(); + } + cancel(); + return; + } + if (entity.isDead() || location.getX() >= region.getMax().getX()+0.5) { + entity.remove(); + cancel(); + return; + } + Vector vector0 = new Vector(1, 0, 0); + vector0.normalize(); + vector0.multiply(0.12); + entity.setTarget(null); + entity.setRotation(-90, 0); + entity.setVelocity(vector0); + location.setY(region.getMax().getY()); + if(i % 4 == 0 && RandomUtil.getRandomInt(1,100) >= 95){ + game.getRegion().getWorld().strikeLightningEffect(location); + } + // 破坏方块的范围 + int range = 4; + int centerZ = location.getBlockZ(); + // 遍历周围的 z 坐标 + for (int z = centerZ - range; z <= centerZ + range; z++) { + // 获取当前坐标的方块 + Block block = region.getWorld().getBlockAt((int) location.getX(), (int) location.getY(), z); + // 判断这个方块是否在游戏场地 + if (region.isInRegion(block.getLocation())) { + // 获取这个方块的ID代号 + int hashCode = block.hashCode(); + // 判断这个方块是否已录入系统 若已录入则跳过 + if (!integerList.contains(hashCode)) { + integerList.add(hashCode); + block.setType(Material.AIR); + block.getRelative(0, -1, 0).setType(Material.FARMLAND); + } + } + } + i++; + } + }.runTaskTimer(FarmingWar.inst(), 1L, 1L); + game.addTasks(task); + } + +} diff --git a/src/main/java/com/yaohun/farmingwar/effects/SummonThePanda.java b/src/main/java/com/yaohun/farmingwar/effects/SummonThePanda.java new file mode 100644 index 0000000..32dfe13 --- /dev/null +++ b/src/main/java/com/yaohun/farmingwar/effects/SummonThePanda.java @@ -0,0 +1,128 @@ +package com.yaohun.farmingwar.effects; + +import com.yaohun.farmingwar.FarmingWar; +import com.yaohun.farmingwar.game.Game; +import com.yaohun.farmingwar.game.GameSite; +import com.yaohun.farmingwar.game.Region; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Particle; +import org.bukkit.block.Block; +import org.bukkit.block.data.Ageable; +import org.bukkit.entity.Cow; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Panda; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; +import org.bukkit.util.Vector; +import tools.CDTimeAPI; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class SummonThePanda { + + public static void apply(Game game, Player zhubo, String userName, int amount) { + if (!game.isStarted()) { + return; + } + // 获取主播的uuid + UUID uuid = zhubo.getUniqueId(); + // 计时器key + String timepieceKey = "SummonPandaEffect"; + startTimepieceEvent(game,zhubo,userName,timepieceKey); + if(CDTimeAPI.isCD(uuid,timepieceKey)){ + long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (245L * amount); + CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime); + } else { + CDTimeAPI.setPlayerCD(uuid,timepieceKey,245L * amount); + } + } + + public static void startTimepieceEvent(Game game,Player zhubo,String userName,String timepieceKey) { + if (CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + return; + } + BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + if (!CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + cancel(); + return; + } + spawnMobs(game,userName); + } + }.runTaskTimer(FarmingWar.inst(), 0L, 5L); + game.addTasks(task); + } + + public static void spawnMobs(Game game,String userName){ + Region region = game.getRegion(); + Location location = GameSite.getMinerWheat_MaxAmount_Location(); + location.setYaw(-90); + EntityType entityType = EntityType.PANDA; + Panda entity = (Panda) location.getWorld().spawnEntity(location, entityType); + entity.setMaxHealth(100); + entity.setCustomNameVisible(true); + entity.setCustomName("§c" + userName); + BukkitTask task = new BukkitRunnable() { + private int i = 0; + // 计算将在多少i后自动消失 + private double remove_x_i = (region.getMax().getX() - region.getMin().getX()) * 7; + private List integerList = new ArrayList<>(); + @Override + public void run() { + Location location = entity.getLocation().clone(); + if(i >= remove_x_i){ + if(!entity.isDead()) { + entity.remove(); + } + cancel(); + return; + } + if (entity.isDead() || location.getX() >= region.getMax().getX()+0.5) { + entity.remove(); + cancel(); + return; + } + Vector vector0 = new Vector(1, 0, 0); + vector0.normalize(); + vector0.multiply(0.20); + entity.setTarget(null); + entity.setRotation(-90, 0); + entity.setVelocity(vector0); + location.setY(region.getMax().getY()); + // 破坏方块的范围 + int range = 1; + int centerZ = location.getBlockZ(); + // 遍历周围的 z 坐标 + for (int z = centerZ - range; z <= centerZ + range; z++) { + // 获取当前坐标的方块 + Block block = region.getWorld().getBlockAt((int) location.getX(), (int) location.getY(), z); + // 判断这个方块是否在游戏场地 + if (region.isInRegion(block.getLocation())) { + // 获取这个方块的ID代号 + int hashCode = block.hashCode(); + // 判断这个方块是否已录入系统 若已录入则跳过 + if (!integerList.contains(hashCode)) { + integerList.add(hashCode); + // 判断方块是否是小麦 + if (block.getType() == Material.WHEAT) { + block.setType(Material.AIR); + // Main.configYml.addUser_Wheat(userName, 1); + block.getWorld().spawnParticle(Particle.VILLAGER_ANGRY, block.getLocation().add(0.5, 0.5, 0.5), 2, 0.5, 0.5, 0.5, 0.1); + } else { + block.getRelative(0, -1, 0).setType(Material.FARMLAND); + } + } + } + } + i++; + } + }.runTaskTimer(FarmingWar.inst(), 1L, 1L); + game.addTasks(task); + } + +} diff --git a/src/main/java/com/yaohun/farmingwar/effects/SummonThePig.java b/src/main/java/com/yaohun/farmingwar/effects/SummonThePig.java new file mode 100644 index 0000000..a110c9e --- /dev/null +++ b/src/main/java/com/yaohun/farmingwar/effects/SummonThePig.java @@ -0,0 +1,133 @@ +package com.yaohun.farmingwar.effects; + +import com.yaohun.farmingwar.FarmingWar; +import com.yaohun.farmingwar.game.Game; +import com.yaohun.farmingwar.game.GameSite; +import com.yaohun.farmingwar.game.Region; +import org.bukkit.*; +import org.bukkit.block.Block; +import org.bukkit.block.data.Ageable; +import org.bukkit.entity.*; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; +import org.bukkit.util.Vector; +import tools.CDTimeAPI; +import tools.GameUtil; +import tools.RandomUtil; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class SummonThePig { + + public static void apply(Game game, Player zhubo, String userName, int amount) { + if (!game.isStarted()) { + return; + } + // 获取主播的uuid + UUID uuid = zhubo.getUniqueId(); + // 计时器key + String timepieceKey = "SummonPigEffect"; + startTimepieceEvent(game,zhubo,userName,timepieceKey); + if(CDTimeAPI.isCD(uuid,timepieceKey)){ + long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (445L * amount); + CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime); + } else { + CDTimeAPI.setPlayerCD(uuid,timepieceKey,445L * amount); + } + } + + public static void startTimepieceEvent(Game game,Player zhubo,String userName,String timepieceKey) { + if (CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + return; + } + BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + if (!CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + cancel(); + return; + } + Location location = zhubo.getLocation(); + for (int i = 0; i < 2; i++) { + Bukkit.getScheduler().runTaskLater(FarmingWar.inst(), () -> { + location.getWorld().spawnParticle(Particle.LAVA,location,5,1,1,1,0.085); + Pig entity = (Pig) location.getWorld().spawnEntity(location,EntityType.PIG); + entity.setHealth(1); + entity.setCustomName("§5"+userName); + entity.setCustomNameVisible(true); + entity.setVelocity(GameUtil.getRandomVector(0.5)); + }, (long) i * 2); + } + } + }.runTaskTimer(FarmingWar.inst(), 0L, 10L); + game.addTasks(task); + } + + public static void spawnMobs(Game game,String userName){ + Region region = game.getRegion(); + Location location = GameSite.getMinerWheat_MaxAmount_Location(); + location.setYaw(-90); + EntityType entityType = EntityType.COW; + Cow entity = (Cow) location.getWorld().spawnEntity(location, entityType); + entity.setMaxHealth(100); + entity.setCustomNameVisible(true); + entity.setCustomName("§c" + userName); + BukkitTask task = new BukkitRunnable() { + private int i = 0; + // 计算将在多少i后自动消失 + private double remove_x_i = (region.getMax().getX() - region.getMin().getX()) * 7; + private List integerList = new ArrayList<>(); + @Override + public void run() { + Location location = entity.getLocation().clone(); + if(i >= remove_x_i){ + if(!entity.isDead()) { + entity.remove(); + } + cancel(); + return; + } + if (entity.isDead() || location.getX() >= region.getMax().getX()+0.5) { + entity.remove(); + cancel(); + return; + } + Vector vector0 = new Vector(1, 0, 0); + vector0.normalize(); + vector0.multiply(0.15); + entity.setRotation(-90, 0); + entity.setVelocity(vector0); + location.setY(region.getMax().getY()); + // 获取生物当前所在位置的方块 + Block block = location.getBlock(); + // 判断这个方块是否在游戏场地 + if(region.isInRegion(block.getLocation())) { + // 获取这个方块的ID代号 + int hashCode = block.hashCode(); + // 判断这个方块是否已录入系统 若已录入则跳过 + if(!integerList.contains(hashCode)){ + integerList.add(hashCode); + // 判断方块是否是小麦 + if (block.getType() == Material.WHEAT) { + if(block.getBlockData() instanceof Ageable ageable){ + block.setType(Material.AIR); + // 增加积分Main.configYml.addUser_Wheat(userName, 1); + block.getWorld().spawnParticle(Particle.VILLAGER_ANGRY, block.getLocation().add(0.5, 0.5, 0.5), 2, 0.5, 0.5, 0.5, 0.1); + if(ageable.getAge() < 5){ + block.getRelative(0,-1,0).setType(Material.FARMLAND); + } + } + } else { + block.getRelative(0,-1,0).setType(Material.FARMLAND); + } + } + } + i++; + } + }.runTaskTimer(FarmingWar.inst(), 1L, 1L); + game.addTasks(task); + } + +} diff --git a/src/main/java/com/yaohun/farmingwar/effects/SummonThePolarBear.java b/src/main/java/com/yaohun/farmingwar/effects/SummonThePolarBear.java new file mode 100644 index 0000000..17b4b2e --- /dev/null +++ b/src/main/java/com/yaohun/farmingwar/effects/SummonThePolarBear.java @@ -0,0 +1,127 @@ +package com.yaohun.farmingwar.effects; + +import com.yaohun.farmingwar.FarmingWar; +import com.yaohun.farmingwar.game.Game; +import com.yaohun.farmingwar.game.GameSite; +import com.yaohun.farmingwar.game.Region; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Particle; +import org.bukkit.block.Block; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Panda; +import org.bukkit.entity.Player; +import org.bukkit.entity.PolarBear; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; +import org.bukkit.util.Vector; +import tools.CDTimeAPI; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class SummonThePolarBear { + + public static void apply(Game game, Player zhubo, String userName, int amount) { + if (!game.isStarted()) { + return; + } + // 获取主播的uuid + UUID uuid = zhubo.getUniqueId(); + // 计时器key + String timepieceKey = "SummonPolarBearEffect"; + startTimepieceEvent(game,zhubo,userName,timepieceKey); + if(CDTimeAPI.isCD(uuid,timepieceKey)){ + long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (245L * amount); + CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime); + } else { + CDTimeAPI.setPlayerCD(uuid,timepieceKey,245L * amount); + } + } + + public static void startTimepieceEvent(Game game,Player zhubo,String userName,String timepieceKey) { + if (CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + return; + } + BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + if (!CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + cancel(); + return; + } + spawnMobs(game,userName); + } + }.runTaskTimer(FarmingWar.inst(), 0L, 5L); + game.addTasks(task); + } + + public static void spawnMobs(Game game,String userName){ + Region region = game.getRegion(); + Location location = GameSite.getMinerWheat_MaxAmount_Location(); + location.setYaw(-90); + EntityType entityType = EntityType.POLAR_BEAR; + PolarBear entity = (PolarBear) location.getWorld().spawnEntity(location, entityType); + entity.setMaxHealth(100); + entity.setCustomNameVisible(true); + entity.setCustomName("§c" + userName); + BukkitTask task = new BukkitRunnable() { + private int i = 0; + // 计算将在多少i后自动消失 + private double remove_x_i = (region.getMax().getX() - region.getMin().getX()) * 7; + private List integerList = new ArrayList<>(); + @Override + public void run() { + Location location = entity.getLocation().clone(); + if(i >= remove_x_i){ + if(!entity.isDead()) { + entity.remove(); + } + cancel(); + return; + } + if (entity.isDead() || location.getX() >= region.getMax().getX()+0.5) { + entity.remove(); + cancel(); + return; + } + Vector vector0 = new Vector(1, 0, 0); + vector0.normalize(); + vector0.multiply(0.2); + entity.setTarget(null); + entity.setRotation(-90, 0); + entity.setVelocity(vector0); + location.setY(region.getMax().getY()); + // 破坏方块的范围 + int range = 2; + int centerZ = location.getBlockZ(); + // 遍历周围的 z 坐标 + for (int z = centerZ - range; z <= centerZ + range; z++) { + // 获取当前坐标的方块 + Block block = region.getWorld().getBlockAt((int) location.getX(), (int) location.getY(), z); + // 判断这个方块是否在游戏场地 + if (region.isInRegion(block.getLocation())) { + // 获取这个方块的ID代号 + int hashCode = block.hashCode(); + // 判断这个方块是否已录入系统 若已录入则跳过 + if (!integerList.contains(hashCode)) { + integerList.add(hashCode); + // 判断方块是否是小麦 + if (block.getType() == Material.WHEAT) { + block.setType(Material.AIR); + // Main.configYml.addUser_Wheat(userName, 1); + block.getWorld().spawnParticle(Particle.VILLAGER_ANGRY, block.getLocation().add(0.5, 0.5, 0.5), 2, 0.5, 0.5, 0.5, 0.1); + } else { + block.getRelative(0, -1, 0).setType(Material.FARMLAND); + } + } + } + } + i++; + } + }.runTaskTimer(FarmingWar.inst(), 1L, 1L); + game.addTasks(task); + } + +} diff --git a/src/main/java/com/yaohun/farmingwar/effects/SummonTheSheep.java b/src/main/java/com/yaohun/farmingwar/effects/SummonTheSheep.java new file mode 100644 index 0000000..e344abe --- /dev/null +++ b/src/main/java/com/yaohun/farmingwar/effects/SummonTheSheep.java @@ -0,0 +1,136 @@ +package com.yaohun.farmingwar.effects; + +import com.yaohun.farmingwar.FarmingWar; +import com.yaohun.farmingwar.game.Game; +import com.yaohun.farmingwar.game.GameSite; +import com.yaohun.farmingwar.game.Region; +import org.bukkit.DyeColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Particle; +import org.bukkit.block.Block; +import org.bukkit.block.data.Ageable; +import org.bukkit.block.data.BlockData; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.entity.Sheep; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; +import org.bukkit.util.Vector; +import tools.CDTimeAPI; +import tools.GameUtil; +import tools.RandomUtil; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class SummonTheSheep { + + public static void apply(Game game, Player zhubo, String userName, int amount) { + if (!game.isStarted()) { + return; + } + // 获取主播的uuid + UUID uuid = zhubo.getUniqueId(); + // 计时器key + String timepieceKey = "SummonSheepEffect"; + startTimepieceEvent(game,zhubo,userName,timepieceKey); + if(CDTimeAPI.isCD(uuid,timepieceKey)){ + long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (245L * amount); + CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime); + } else { + CDTimeAPI.setPlayerCD(uuid,timepieceKey,245L * amount); + } + } + + public static void startTimepieceEvent(Game game,Player zhubo,String userName,String timepieceKey) { + if (CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + return; + } + BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + if (!CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + cancel(); + return; + } + spawnMobs(game,userName); + } + }.runTaskTimer(FarmingWar.inst(), 0L, 5L); + game.addTasks(task); + } + + public static void spawnMobs(Game game,String userName){ + Region region = game.getRegion(); + Location location = GameSite.getMinerWheat_MaxAmount_Location(); + location.setYaw(-90); + Sheep entity = (Sheep) location.getWorld().spawnEntity(location, EntityType.SHEEP); + DyeColor dyeColor = DyeColor.values()[RandomUtil.getRandomInt(0, 15)]; + entity.setColor(dyeColor); + entity.setMaxHealth(100); + entity.setCustomNameVisible(true); + entity.setCustomName("§c" + userName); + BukkitTask task = new BukkitRunnable() { + private int i = 0; + // 计算将在多少i后自动消失 + private double remove_x_i = (region.getMax().getX() - region.getMin().getX()) * 7; + private List integerList = new ArrayList<>(); + @Override + public void run() { + Location location = entity.getLocation().clone(); + if(i >= remove_x_i){ + if(!entity.isDead()) { + entity.remove(); + } + cancel(); + return; + } + if (entity.isDead() || location.getX() >= region.getMax().getX()+0.5) { + entity.remove(); + cancel(); + return; + } + Vector vector0 = new Vector(1, 0, 0); + vector0.normalize(); + vector0.multiply(0.15); + entity.setVelocity(vector0); + entity.setRotation(-90, 0); + location.setY(region.getMax().getY()); + // 获取生物当前所在位置的方块 + Block block = location.getBlock(); + // 判断这个方块是否在游戏场地 + if(region.isInRegion(block.getLocation())) { + // 获取这个方块的ID代号 + int hashCode = block.hashCode(); + // 判断这个方块是否已录入系统 若已录入则跳过 + if(!integerList.contains(hashCode)){ + integerList.add(hashCode); + // 判断方块是否是小麦 + if (block.getType() == Material.WHEAT) { + // 判断小麦成熟度 + BlockData blockData = block.getBlockData(); + if (blockData instanceof Ageable) { + Ageable ageable = (Ageable) blockData; + // 若成熟度大于 1 则设置为 0 + if (ageable.getAge() >= 5) { + ageable.setAge(3); + block.setBlockData(ageable); + } else { + block.setType(Material.AIR); + } + // 增加积分Main.configYml.addUser_Wheat(userName, 1); + block.getWorld().spawnParticle(Particle.VILLAGER_ANGRY, block.getLocation().add(0.5, 0.5, 0.5), 2, 0.5, 0.5, 0.5, 0.1); + } + } else { + block.getRelative(0,-1,0).setType(Material.FARMLAND); + } + } + } + i++; + } + }.runTaskTimer(FarmingWar.inst(), 1L, 1L); + game.addTasks(task); + } + +} diff --git a/src/main/java/com/yaohun/farmingwar/effects/SummonTheTraderllama.java b/src/main/java/com/yaohun/farmingwar/effects/SummonTheTraderllama.java new file mode 100644 index 0000000..f6b95a2 --- /dev/null +++ b/src/main/java/com/yaohun/farmingwar/effects/SummonTheTraderllama.java @@ -0,0 +1,106 @@ +package com.yaohun.farmingwar.effects; + +import com.yaohun.farmingwar.FarmingWar; +import com.yaohun.farmingwar.game.Game; +import com.yaohun.farmingwar.game.Region; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.boss.BossBar; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.entity.TraderLlama; +import org.bukkit.entity.Wither; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; +import org.bukkit.util.Vector; +import tools.CDTimeAPI; +import tools.RandomUtil; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class SummonTheTraderllama { + + public static void apply(Game game, Player zhubo, String userName, int amount) { + if (!game.isStarted()) { + return; + } + // 获取主播的uuid + UUID uuid = zhubo.getUniqueId(); + // 计时器key + String timepieceKey = "SummonTraderllamaEffect"; + startTimepieceEvent(game,zhubo,userName,timepieceKey); + if(CDTimeAPI.isCD(uuid,timepieceKey)){ + long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (1995L * amount); + CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime); + } else { + CDTimeAPI.setPlayerCD(uuid,timepieceKey,1995L * amount); + } + } + + public static void startTimepieceEvent(Game game,Player zhubo,String userName,String timepieceKey) { + if (CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + return; + } + BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + if (!CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + cancel(); + return; + } + World world = game.getRegion().getWorld(); + SiteFillALl.apply(game,zhubo,true); + spawnMobs(game,userName,new Location(world,-224.5,73,264.0)); + spawnMobs(game,userName,new Location(world,-224.5,73,259.0)); + spawnMobs(game,userName,new Location(world,-224.5,73,254.0)); + spawnMobs(game,userName,new Location(world,-224.5,73,249.0)); + } + }.runTaskTimer(FarmingWar.inst(), 0L, 40L); + game.addTasks(task); + } + + public static void spawnMobs(Game game,String userName,Location location){ + Region region = game.getRegion(); + location.setYaw(-90); + TraderLlama entity = (TraderLlama) location.getWorld().spawnEntity(location, EntityType.TRADER_LLAMA); + entity.setTarget(null); + entity.setCollidable(false); + entity.setMaxHealth(100); + entity.setCustomNameVisible(true); + entity.setCustomName("§a" +userName); + + BukkitTask task = new BukkitRunnable() { + private int i = 0; + // 计算将在多少i后自动消失 + private double remove_x_i = (region.getMax().getX() - region.getMin().getX()) * 4; + @Override + public void run() { + Location location = entity.getLocation().clone(); + if(i >= remove_x_i){ + if(!entity.isDead()) { + entity.remove(); + } + cancel(); + return; + } + if (entity.isDead() || location.getX() >= region.getMax().getX()+0.5) { + entity.remove(); + cancel(); + return; + } + Vector vector0 = new Vector(1, 0, 0); + vector0.normalize(); + vector0.multiply(0.32); + entity.setRotation(-90, 0); + entity.setVelocity(vector0); + i++; + } + }.runTaskTimer(FarmingWar.inst(), 1L, 1L); + game.addTasks(task); + } + +} diff --git a/src/main/java/com/yaohun/farmingwar/effects/SummonTheVillager.java b/src/main/java/com/yaohun/farmingwar/effects/SummonTheVillager.java new file mode 100644 index 0000000..0464d4b --- /dev/null +++ b/src/main/java/com/yaohun/farmingwar/effects/SummonTheVillager.java @@ -0,0 +1,147 @@ +package com.yaohun.farmingwar.effects; + +import com.yaohun.farmingwar.FarmingWar; +import com.yaohun.farmingwar.game.Game; +import com.yaohun.farmingwar.game.GameSite; +import com.yaohun.farmingwar.game.Region; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Particle; +import org.bukkit.block.Block; +import org.bukkit.block.data.Ageable; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.type.Farmland; +import org.bukkit.entity.Cow; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.entity.Villager; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; +import org.bukkit.util.Vector; +import tools.CDTimeAPI; +import tools.RandomUtil; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class SummonTheVillager { + + public static void apply(Game game, Player zhubo, String userName, int amount) { + if (!game.isStarted()) { + return; + } + // 获取主播的uuid + UUID uuid = zhubo.getUniqueId(); + // 计时器key + String timepieceKey = "SummonVillagerEffect"; + startTimepieceEvent(game,zhubo,userName,timepieceKey); + if(CDTimeAPI.isCD(uuid,timepieceKey)){ + long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (245L * amount); + CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime); + } else { + CDTimeAPI.setPlayerCD(uuid,timepieceKey,245L * amount); + } + } + + public static void startTimepieceEvent(Game game,Player zhubo,String userName,String timepieceKey) { + if (CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + return; + } + BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + if (!CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + cancel(); + return; + } + spawnMobs(game,userName); + } + }.runTaskTimer(FarmingWar.inst(), 0L, 5L); + game.addTasks(task); + } + + public static void spawnMobs(Game game,String userName){ + Region region = game.getRegion(); + Location location = GameSite.getMinerWheat_MinAmount_Location(); + location.setYaw(-90); + Villager entity = (Villager) location.getWorld().spawnEntity(location, EntityType.VILLAGER); + entity.setMaxHealth(20); + entity.setProfession(Villager.Profession.ARMORER); + entity.setVillagerType(Villager.Type.PLAINS); + entity.setCustomNameVisible(true); + entity.setCustomName("§a" + userName); + BukkitTask task = new BukkitRunnable() { + private int i = 0; + // 计算将在多少i后自动消失 + private double remove_x_i = (region.getMax().getX() - region.getMin().getX()) * 7; + private List integerList = new ArrayList<>(); + @Override + public void run() { + Location location = entity.getLocation().clone(); + if(i >= remove_x_i){ + if(!entity.isDead()) { + entity.remove(); + } + cancel(); + return; + } + if (entity.isDead() || location.getX() >= region.getMax().getX()+0.5) { + entity.remove(); + cancel(); + return; + } + Vector vector0 = new Vector(1, 0, 0); + vector0.normalize(); + vector0.multiply(0.15); + entity.setRotation(-90, 0); + entity.setVelocity(vector0); + // 获取生物当前所在位置的方块 + Block block = location.getBlock(); + // 判断这个方块是否在游戏场地 + if(region.isInRegion(block.getLocation())) { + // 获取这个方块的ID代号 + int hashCode = block.hashCode(); + // 判断这个方块是否已录入系统 若已录入则跳过 + if(!integerList.contains(hashCode)){ + integerList.add(hashCode); + // 判断方块是否是小麦 + if (block.getType() == Material.WHEAT) { + // 判断小麦成熟度 + BlockData blockData = block.getBlockData(); + if (blockData instanceof Ageable) { + Ageable ageable = (Ageable) blockData; + ageable.setAge(7); + block.setBlockData(ageable); + } + } else { + Block next_block = block.getRelative(0,-1,0); + if(next_block.getType() == Material.FARMLAND){ + // 检索到泥土方块后判断方块是否是湿润状态 + if (next_block.getBlockData() instanceof Farmland farmland) { + // 如果没有打湿则跳过 + if (farmland.getMoisture() != 7) { + farmland.setMoisture(7); + next_block.setBlockData(farmland); + }else { + block.setType(Material.WHEAT); + if (block.getBlockData() instanceof Ageable ageable) { + ageable.setAge(3); + block.setBlockData(ageable); + } + } + } + } + } + } + } + if (RandomUtil.getRandomInt(1, 100) >= 50) { + block.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, block.getLocation().add(0.5, 0.5, 0.5), 2, 0.5, 0.5, 0.5, 0.1); + } + i++; + } + }.runTaskTimer(FarmingWar.inst(), 1L, 1L); + game.addTasks(task); + } + +} diff --git a/src/main/java/com/yaohun/farmingwar/effects/SummonTheWither.java b/src/main/java/com/yaohun/farmingwar/effects/SummonTheWither.java new file mode 100644 index 0000000..1a2b49e --- /dev/null +++ b/src/main/java/com/yaohun/farmingwar/effects/SummonTheWither.java @@ -0,0 +1,143 @@ +package com.yaohun.farmingwar.effects; + +import com.yaohun.farmingwar.FarmingWar; +import com.yaohun.farmingwar.game.Game; +import com.yaohun.farmingwar.game.GameSite; +import com.yaohun.farmingwar.game.Region; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.boss.BossBar; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.MagmaCube; +import org.bukkit.entity.Player; +import org.bukkit.entity.Wither; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; +import org.bukkit.util.Vector; +import tools.CDTimeAPI; +import tools.RandomUtil; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class SummonTheWither { + + public static void apply(Game game, Player zhubo, String userName, int amount) { + if (!game.isStarted()) { + return; + } + // 获取主播的uuid + UUID uuid = zhubo.getUniqueId(); + // 计时器key + String timepieceKey = "SummonWitherEffect"; + startTimepieceEvent(game,zhubo,userName,timepieceKey); + if(CDTimeAPI.isCD(uuid,timepieceKey)){ + long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (2995L * amount); + CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime); + } else { + CDTimeAPI.setPlayerCD(uuid,timepieceKey,2995L * amount); + } + } + + public static void startTimepieceEvent(Game game,Player zhubo,String userName,String timepieceKey) { + if (CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + return; + } + BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + if (!CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) { + cancel(); + return; + } + World world = game.getRegion().getWorld(); + spawnMobs(game,userName,new Location(world,-224.5,73,264.0)); + spawnMobs(game,userName,new Location(world,-224.5,73,259.0)); + spawnMobs(game,userName,new Location(world,-224.5,73,254.0)); + spawnMobs(game,userName,new Location(world,-224.5,73,249.0)); + } + }.runTaskTimer(FarmingWar.inst(), 0L, 60L); + game.addTasks(task); + } + + public static void spawnMobs(Game game,String userName,Location location){ + location.setYaw(-90); + Region region = game.getRegion(); + Wither entity = (Wither) location.getWorld().spawnEntity(location, EntityType.WITHER); + entity.setTarget(null); + entity.setCollidable(false); + entity.setMaxHealth(150); + BossBar bossBar = entity.getBossBar(); + if (bossBar != null) { + bossBar.removeAll(); + } + entity.setCustomNameVisible(true); + entity.setCustomName("§c" + userName); + entity.setAI(false); + BukkitTask task = new BukkitRunnable() { + private int i = 0; + // 计算将在多少i后自动消失 + private double remove_x_i = (region.getMax().getX() - region.getMin().getX()) * 7; + private List integerList = new ArrayList<>(); + @Override + public void run() { + Location location = entity.getLocation().clone(); + if (i >= remove_x_i) { + if(!entity.isDead()) { + entity.remove(); + } + cancel(); + return; + } + if (entity.isDead() || location.getX() >= region.getMax().getX()+0.5) { + if(!entity.isDead()) { + entity.remove(); + } + cancel(); + return; + } + Vector vector0 = new Vector(1, 0, 0); + vector0.normalize(); + vector0.multiply(0.15); + Location location1 = entity.getLocation().add(vector0); + location1.setYaw(-90); + location1.setPitch(0); + entity.teleport(location1); + location.setY(region.getMax().getY()); + if(i % 4 == 0 && RandomUtil.getRandomInt(1,100) >= 95){ + location.getWorld().strikeLightningEffect(location); + } + BossBar bossBar = entity.getBossBar(); + if (bossBar != null) { + bossBar.removeAll(); + } + // 破坏方块的范围 + int range = 8; + int centerZ = location.getBlockZ(); + // 遍历周围的 z 坐标 + for (int z = centerZ - range; z <= centerZ + range; z++) { + // 获取当前坐标的方块 + Block block = region.getWorld().getBlockAt((int) location.getX(), (int) location.getY(), z); + // 判断这个方块是否在游戏场地 + if (region.isInRegion(block.getLocation())) { + // 获取这个方块的ID代号 + int hashCode = block.hashCode(); + // 判断这个方块是否已录入系统 若已录入则跳过 + if (!integerList.contains(hashCode)) { + integerList.add(hashCode); + block.setType(Material.AIR); + block.getRelative(0, -1, 0).setType(Material.FARMLAND); + } + } + } + i++; + } + }.runTaskTimer(FarmingWar.inst(), 1L, 1L); + game.addTasks(task); + } + +} diff --git a/src/main/java/com/yaohun/farmingwar/game/Game.java b/src/main/java/com/yaohun/farmingwar/game/Game.java index 911d6d7..2045147 100644 --- a/src/main/java/com/yaohun/farmingwar/game/Game.java +++ b/src/main/java/com/yaohun/farmingwar/game/Game.java @@ -1,26 +1,217 @@ package com.yaohun.farmingwar.game; +import com.yaohun.farmingwar.FarmingWar; +import com.yaohun.farmingwar.data.LikeData; +import org.bukkit.*; +import org.bukkit.boss.BarColor; +import org.bukkit.boss.BarStyle; +import org.bukkit.boss.BossBar; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Entity; +import org.bukkit.entity.Firework; import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.FireworkMeta; +import org.bukkit.plugin.Plugin; +import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; +import org.bukkit.util.Vector; +import tools.*; import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; import java.util.List; public class Game { - + private Region region; + private World world; + private BossBar bossBar1; + private BossBar bossBar2; + private BossBar bossBar3; private boolean started = false; + private boolean checking = false; + private int completeAmount; + private int completeGoal; private List tasks = new ArrayList<>(); private List entities = new ArrayList<>(); public Game(){ + this.completeGoal = 15; + this.world = Bukkit.getWorld("world"); + this.region = new Region(world,new Point(-224,73,246),new Point(-204,73,266)); + bossBar1 = Bukkit.createBossBar("今日挑战进度", BarColor.WHITE, BarStyle.SEGMENTED_10); + bossBar2 = Bukkit.createBossBar("补种进度", BarColor.GREEN, BarStyle.SEGMENTED_20); + bossBar3 = Bukkit.createBossBar("点赞累积数量", BarColor.WHITE, BarStyle.SEGMENTED_10); + } + private void updateCompleteGoalBossBar() { + double d = (double) completeAmount / (double) completeGoal; + String bossTitle = "§6今日挑战进度: §f"+completeAmount+"/"+completeGoal; + bossBar1.setTitle(bossTitle); + BossBarUtil.setBarColor(bossBar1,d); + BossBarUtil.setBarProgress(bossBar1,d); + } + + private void updateCompleteWheatGoalBossBar() { + int cNow = GameSite.getCompleteWheatAmount(); + int cMax = GameSite.getCompleteWheatGoal(); + double d = (double) cNow / (double) cMax; + double d2 = MathUtil.round(d * 100, 2); + String bossTitle = "§6小麦生长: §f"+cNow+"/"+cMax+" §b("+d2+"%)"; + bossBar2.setTitle(bossTitle); + BossBarUtil.setBarColor(bossBar2,d); + BossBarUtil.setBarProgress(bossBar2,d); + } + public void updateDianZanBossBar() { + int dz = 0; + int needDz = 300; + String eventName = ""; + HashMap likeDataMap = FarmingWar.getGameManager().getLikeDataMap(); + for (String key : likeDataMap.keySet()){ + LikeData likeData = likeDataMap.get(key); + dz = likeData.getNowAmount(); + needDz = likeData.getNeedAmount(); + eventName = likeData.getEffectKey(); + break; + } + int dz_need = needDz; + double dz1 = (double) dz / (double) dz_need; + String bossTitle = "§6"+eventName+"(戳一戳): §d"+dz+"§f/§c"+dz_need; + bossBar3.setTitle(bossTitle); + BossBarUtil.setBarColor(bossBar3,dz1); + BossBarUtil.setBarProgress(bossBar3,dz1); } public void start() { - if(started){return;} + if (started) { + return; + } + this.started = true; + this.checking = false; + initWorld(); + GameUtil.loadSchematics("muban"); + this.completeAmount = 0; + tasks.add(new BukkitRunnable() { + @Override + public void run() { + updateCompleteGoalBossBar(); + updateCompleteWheatGoalBossBar(); + updateDianZanBossBar(); + if (!checking) { + checkSiteDegreeOfCompletion(); + } + } + }.runTaskTimer(FarmingWar.inst(), 0L, 10L)); + } + public void initPlayerData(Player player) { + player.setArrowCooldown(3600); + player.setGameMode(GameMode.SURVIVAL); + player.setAllowFlight(true); + player.teleport(region.getHub()); + bossBar3.addPlayer(player); + initPlayerBackpack(player); + } + public void initPlayerBackpack(Player player){ + Inventory inv = player.getInventory(); + inv.setItem(0, StackUtil.diamondSword()); + inv.setItem(1, StackUtil.trident()); + inv.setItem(2, StackUtil.quickPotion()); + inv.setItem(3, new ItemStack(Material.WHEAT_SEEDS,32)); + inv.setItem(4, new ItemStack(Material.BONE_MEAL,32)); + } + private void initWorld() { + this.world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false); + this.world.setGameRule(GameRule.DO_WEATHER_CYCLE, false); + this.world.setGameRule(GameRule.DO_MOB_SPAWNING, false); + this.world.setGameRule(GameRule.DO_MOB_LOOT, false); + this.world.setGameRule(GameRule.MOB_GRIEFING, false); + this.world.setGameRule(GameRule.RANDOM_TICK_SPEED, 0); + this.world.setTime(4500); + this.world.setDifficulty(Difficulty.NORMAL); } + private int countdown = 0; + private int countdownTime = 11; + public void checkSiteDegreeOfCompletion() { + if(checking){return;} + int i = GameSite.getCompleteWheatAmount(); + if(i >= GameSite.getCompleteWheatGoal()){ + checking = true; + countdown = 0; + BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + int i = GameSite.getCompleteWheatAmount(); + // 倒计时期间小麦受到破坏则停止倒计时 + if(i < GameSite.getCompleteWheatGoal()){ + tasks.remove(this); + checking = false; + Bukkit.broadcastMessage("§c[系统]§a小麦受到了破坏,需要进行修复."); + for (Player player : Bukkit.getOnlinePlayers()) { + player.sendTitle("§c哎呀!", "§6继续加油!"); + player.playSound(player.getLocation(), "niganma", 1.0F, 1.0F); + } + cancel(); + return; + } + if(countdown >= countdownTime-1){ + tasks.add(new BukkitRunnable() { + private int i = 0; + @Override + public void run() { + if(i >= 20){ + cancel(); + return; + } + for (Player player : Bukkit.getOnlinePlayers()){ + shoutFirework(player.getLocation().clone().add(RandomUtil.getRandomInt(-10,10),RandomUtil.getRandomInt(3,6),RandomUtil.getRandomInt(-10,10))); + } + i++; + } + }.runTaskTimer(FarmingWar.inst(),0L,5L)); + tasks.add(new BukkitRunnable() { + private int i = 0; + @Override + public void run() { + if (i >= 100) { + cancel(); + return; + } + region.getWorld().setTime(region.getWorld().getTime() + 480L); + i++; + } + }.runTaskTimer(FarmingWar.inst(), 0L, 1L)); + completeAmount++; + tasks.remove(this); + checking = false; + Bukkit.broadcastMessage("§c[系统]§a挑战成功! §b游戏进度+1"); + for (Player player : Bukkit.getOnlinePlayers()) { + player.playSound(player.getLocation(), "duolaameng", 1.0F, 1.0F); + player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0f, 1.1f); + } + GameSite.restoreInitialization(); + cancel(); + return; + } + countdownEvent(); + } + }.runTaskTimer(FarmingWar.inst(),0,20L); + addTasks(task); + } + } + private void countdownEvent(){ + countdown++; + int daojishi = countdownTime; + for (Player player : Bukkit.getOnlinePlayers()) { + player.sendTitle("§6§l" + (daojishi - countdown), "§6即将挑战成功!"); + player.playSound(player.getLocation(), "daojishi", 1.0f, 1.0f); + } + } + + public Region getRegion() {return region;} public boolean isStarted() {return started;} public List getTasks() { return tasks; @@ -28,4 +219,51 @@ public class Game { public void addTasks(BukkitTask task){ this.tasks.add(task); } + + private void shoutFirework(Location location){ + // 创建烟花对象 + Firework firework = location.getWorld().spawn(location.clone().add(0,1,0), Firework.class); + FireworkMeta fireworkMeta = firework.getFireworkMeta(); + Color color = Color.YELLOW; + int rand = RandomUtil.getRandomInt(1,100); + if(rand >= 75){ + color = Color.RED; + }else if(rand >= 50){ + color = Color.AQUA; + }else if(rand >= 25){ + color = Color.GREEN; + } + // 设置烟花效果 + FireworkEffect fireworkEffect = FireworkEffect.builder() + .withColor(color) + .with(FireworkEffect.Type.BURST) + .build(); + firework.setVelocity(new Vector(0, -0.2, 0)); + fireworkMeta.addEffect(fireworkEffect); + fireworkMeta.setPower(0); // 设置烟花强度 + firework.setFireworkMeta(fireworkMeta); + new BukkitRunnable() { + public void run() { + firework.detonate(); + cancel(); + } + }.runTaskLater( FarmingWar.inst(), 5L ); + } + + public void createRegion(String regionKey, Region region) { + FileConfiguration config = FarmingWar.inst().getConfig(); + ConfigurationSection section = config.createSection(regionKey); + section.set("world", region.getWorld().getName()); + Point point1 = region.getMin(); + Point point2 = region.getMax(); + ConfigurationSection section1 = section.createSection("min"); + section1.set("x", point1.getX()); + section1.set("y", point1.getY()); + section1.set("z", point1.getZ()); + ConfigurationSection section2 = section.createSection("max"); + section2.set("x", point2.getX()); + section2.set("y", point2.getY()); + section2.set("z", point2.getZ()); + FarmingWar.inst().saveConfig(); + } } diff --git a/src/main/java/com/yaohun/farmingwar/game/GameSite.java b/src/main/java/com/yaohun/farmingwar/game/GameSite.java new file mode 100644 index 0000000..a8adfde --- /dev/null +++ b/src/main/java/com/yaohun/farmingwar/game/GameSite.java @@ -0,0 +1,257 @@ +package com.yaohun.farmingwar.game; + +import com.yaohun.farmingwar.FarmingWar; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.data.Ageable; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.type.Farmland; +import org.bukkit.scheduler.BukkitRunnable; +import tools.RandomUtil; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; + +public class GameSite { + + public static void restoreInitialization(){ + Game game = FarmingWar.getGame(); + Region region = game.getRegion(); + int i = 0; + for (int y = (int) Math.floor(region.getMin().getY()); y <= region.getMax().getY(); y++) { + for (int x = (int) Math.floor(region.getMin().getX()); x <= region.getMax().getX(); x++) { + for (int z = (int) Math.floor(region.getMin().getZ()); z <= region.getMax().getZ(); z++) { + Block block = region.getWorld().getBlockAt(x, y, z); + if (!block.getType().equals(Material.AIR)) { + block.setType(Material.AIR); + } + } + } + } + } + + public static int getCompleteWheatAmount(){ + Game game = FarmingWar.getGame(); + Region region = game.getRegion(); + int i = 0; + for (int y = (int) Math.floor(region.getMin().getY()); y <= region.getMax().getY(); y++) { + for (int x = (int) Math.floor(region.getMin().getX()); x <= region.getMax().getX(); x++) { + for (int z = (int) Math.floor(region.getMin().getZ()); z <= region.getMax().getZ(); z++) { + Block block = region.getWorld().getBlockAt(x, y, z); + if (!block.getType().equals(Material.AIR)) { + BlockData blockData = block.getBlockData(); + if (blockData instanceof Ageable) { + Ageable ageable = (Ageable) blockData; + if (ageable.getAge() == 7) { + i++; + } + } + } + } + } + } + return i; + } + + public static int getCompleteWheatGoal(){ + Game game = FarmingWar.getGame(); + Region region = game.getRegion(); + int x = (int) Math.floor(region.getMax().getX()) - (int) Math.floor(region.getMin().getX()) + 1; + int y = (int) Math.floor(region.getMax().getY()) - (int) Math.floor(region.getMin().getY()) + 1; + int z = (int) Math.floor(region.getMax().getZ()) - (int) Math.floor(region.getMin().getZ()) + 1; + return x * y * z; + } + + // 获取场地哪一行小麦可以进行收割 + public static List Remove_indexZ_List = new ArrayList<>(); + public static Location getMinerWheat_MaxAmount_Location(){ + Region region = FarmingWar.getGame().getRegion(); + double x = region.getMin().getX() - 0.755; + double y = region.getMax().getY(); + int indexZ = (int) (region.getMin().getZ() + 0.5); + // 最终小麦种子数量统计 + LinkedHashMap wheatMap = new LinkedHashMap<>(); + LinkedHashMap seedsMap = new LinkedHashMap<>(); + LinkedHashMap farmlandMap = new LinkedHashMap<>(); + // 从第一行开始遍历至最后一行 + for (int z = indexZ; z <= Math.round(region.getMax().getZ()); z++) { + if(Remove_indexZ_List.contains(String.valueOf(z))){ + continue; + } + // 统计小麦数量 + int wheat_amount = 0; + int seeds_amount = 0; + int farmland_amount = 0; + // 获取纵行x的变化 + for (int x1 = (int) Math.round(region.getMin().getX()); x1 <= Math.round(region.getMax().getX()); x1++) { + Location location = new Location(region.getWorld(), x1, y, z); + // 判断方块是否是小麦 若是小麦则检测成熟度 + Block block = location.getBlock(); + if (block.getType() == Material.WHEAT) { + if (block.getBlockData() instanceof Ageable ageable) { + // 判断小麦成熟度 + if (ageable.getAge() == 7) { + wheat_amount++; + }else{ + seeds_amount++; + } + } + }else { + Block next_block = block.getRelative(0, -1, 0); + if (next_block.getType() == Material.FARMLAND) { + if (next_block.getBlockData() instanceof Farmland farmland) { + if (farmland.getMoisture() == farmland.getMaximumMoisture()) { + farmland_amount++; + } + } + } + } + } + if(wheat_amount >= 1){ + wheatMap.put(z,wheat_amount); + }else if(seeds_amount >= 1){ + seedsMap.put(z,seeds_amount); + }else if(farmland_amount >= 1){ + farmlandMap.put(z,farmland_amount); + } + } + if(wheatMap.size() >= 1){ + int a = 0; + for (Integer z : wheatMap.keySet()){ + if(wheatMap.get(z) >= a){ + a = wheatMap.get(z); + indexZ = z; + } + } + }else if(seedsMap.size() >= 1){ + int a = 0; + for (Integer z : seedsMap.keySet()){ + if(seedsMap.get(z) >= a){ + a = seedsMap.get(z); + indexZ = z; + } + } + }else if(farmlandMap.size() >= 1){ + int a = 0; + for (Integer z : farmlandMap.keySet()){ + if(farmlandMap.get(z) >= a){ + a = farmlandMap.get(z); + indexZ = z; + } + } + }else{ + indexZ = -1; + } + String indexZ_String = String.valueOf(indexZ); + Remove_indexZ_List.add(indexZ_String); + new BukkitRunnable() { + public void run() { + Remove_indexZ_List.remove(indexZ_String); + } + }.runTaskLater(FarmingWar.inst(), 100L); + Location location = new Location(region.getWorld(), x+0.5, y, indexZ+0.5); + if (indexZ == -1) { + location = RandomUtil.getRandomLocation(region.getWorld(), x, x, y, y, region.getMin().getZ() + 1, region.getMax().getZ() - 1); + } + return location; + } + + + public static List Fix_indexZ_List = new ArrayList<>(); + public static Location getMinerWheat_MinAmount_Location(){ + Region region = FarmingWar.getGame().getRegion(); + double x = region.getMin().getX() - 0.755; + double y = region.getMax().getY(); + int indexZ = (int) (region.getMin().getZ() + 0.5); + // 最终小麦种子数量统计 + LinkedHashMap seedsMap = new LinkedHashMap<>(); + LinkedHashMap farmlandMap = new LinkedHashMap<>(); + LinkedHashMap dirtMap = new LinkedHashMap<>(); + // 从第一行开始遍历至最后一行 + for (int z = indexZ; z <= Math.round(region.getMax().getZ()); z++) { + if(Fix_indexZ_List.contains(String.valueOf(z))){ + continue; + } + // 统计小麦数量 + int seeds_amount = 0; + int dirt_amount = 0; + int farmland_amount = 0; + // 获取纵行x的变化 + for (int x1 = (int) Math.round(region.getMin().getX()); x1 <= Math.round(region.getMax().getX()); x1++) { + Location location = new Location(region.getWorld(), x1, y, z); + // 判断方块是否是小麦 若是小麦则检测成熟度 + Block block = location.getBlock(); + if (block.getType() == Material.WHEAT) { + if (block.getBlockData() instanceof Ageable ageable) { + // 判断小麦成熟度 + if (ageable.getAge() != 7) { + seeds_amount++; + } + } + }else { + Block next_block = block.getRelative(0, -1, 0); + if (next_block.getType() == Material.FARMLAND) { + if (next_block.getBlockData() instanceof Farmland farmland) { + if (farmland.getMoisture() != farmland.getMaximumMoisture()) { + dirt_amount++; + } else { + farmland_amount++; + } + } + } + } + } + if(dirt_amount >= 1){ + dirtMap.put(z,dirt_amount); + }else if(farmland_amount >= 1){ + farmlandMap.put(z,farmland_amount); + }else if(seeds_amount >= 1){ + seedsMap.put(z,seeds_amount); + } + } + if(dirtMap.size() >= 1) { + int a = 0; + for (Integer z : dirtMap.keySet()){ + if(dirtMap.get(z) >= a){ + a = dirtMap.get(z); + indexZ = z; + } + } + }else if(farmlandMap.size() >= 1){ + int a = 0; + for (Integer z : farmlandMap.keySet()){ + if(farmlandMap.get(z) >= a){ + a = farmlandMap.get(z); + indexZ = z; + } + } + }else if(seedsMap.size() >= 1){ + int a = 0; + for (Integer z : seedsMap.keySet()){ + if(seedsMap.get(z) >= a){ + a = seedsMap.get(z); + indexZ = z; + } + } + }else{ + indexZ = -1; + } + String indexZ_String = String.valueOf(indexZ); + Fix_indexZ_List.add(indexZ_String); + + new BukkitRunnable() { + public void run() { + Fix_indexZ_List.remove(indexZ_String); + cancel(); + } + }.runTaskLater(FarmingWar.inst(), 100L); + Location location = new Location(region.getWorld(), x+0.5, y, indexZ+0.5); + if (indexZ == -1) { + location = RandomUtil.getRandomLocation(region.getWorld(), x, x, y, y, region.getMin().getZ() + 1, region.getMax().getZ() - 1); + } + return location; + } + +} diff --git a/src/main/java/com/yaohun/farmingwar/game/Point.java b/src/main/java/com/yaohun/farmingwar/game/Point.java new file mode 100644 index 0000000..6d82637 --- /dev/null +++ b/src/main/java/com/yaohun/farmingwar/game/Point.java @@ -0,0 +1,94 @@ +package com.yaohun.farmingwar.game; + +import com.sk89q.worldedit.math.BlockVector3; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.configuration.ConfigurationSection; + +import java.util.Objects; + +public class Point { + + private double x; + private double y; + private double z; + + public Point(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + public Point(double x, double y, double z) { + this.x = x; + this.y = y; + this.z = z; + } + + public double getX() { + return x; + } + + public double getY() { + return y; + } + + public double getZ() { + return z; + } + + public void setX(double x) { + this.x = x; + } + + public void setY(double y) { + this.y = y; + } + + public void setZ(double z) { + this.z = z; + } + + public Point clone() { + return new Point(x, y, z); + } + + public Location toLocation(World world) { + return new Location(world, x, y, z, 0, 0); + } + + public static Point of(Location location) { + return new Point(location.getX(), location.getY(), location.getZ()); + } + + public static Point deserialize(ConfigurationSection section) { + return new Point(section.getDouble("x"), section.getDouble("y"), section.getDouble("z")); + } + + public BlockVector3 toBlockVector3() { + return BlockVector3.at(x, y, z); + } + + @Override + public String toString() { + return "Point{" + + "x=" + x + + ", y=" + y + + ", z=" + z + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Point point = (Point) o; + return Double.compare(point.x, x) == 0 && Double.compare(point.y, y) == 0 && Double.compare(point.z, z) == 0; + } + + @Override + public int hashCode() { + return Objects.hash(x, y, z); + } + +} diff --git a/src/main/java/com/yaohun/farmingwar/game/Region.java b/src/main/java/com/yaohun/farmingwar/game/Region.java new file mode 100644 index 0000000..ca79eb8 --- /dev/null +++ b/src/main/java/com/yaohun/farmingwar/game/Region.java @@ -0,0 +1,79 @@ +package com.yaohun.farmingwar.game; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.configuration.ConfigurationSection; + +public class Region { + + private World world; + private Point min; + private Point max; + + public Region(World world, Point min, Point max) { + this.world = world; + this.min = min; + this.max = max; + } + + public Location getHub(){ + double x = (max.getX() - 2); + double z = (min.getZ() + max.getZ()) / 2; + double y = min.getY(); + if(max.getY() > y){ + y = max.getY(); + } + return new Location(world,x,(y+5 ),z,90,0); + } + + public World getWorld() { + return world; + } + + public Point getMin() { + return min; + } + + public Point getMax() { + return max; + } + + public void setMax(Point max) { + this.max = max; + } + + public void setMin(Point min) { + this.min = min; + } + + public static Region deserialize(ConfigurationSection section) { + World world1 = Bukkit.getWorld(section.getString("world")); + Point point1 = Point.deserialize(section.getConfigurationSection("min")); + Point point2 = Point.deserialize(section.getConfigurationSection("max")); + return new Region(world1, point1, point2); + } + + public boolean isInRegion(Location location) { + if (!location.getWorld().getName().equalsIgnoreCase(world.getName())) { + return false; + } + return (location.getBlockX() >= this.min.getX() + && location.getBlockX() <= this.max.getX() + && location.getBlockY() >= this.min.getY() + && location.getBlockY() <= this.max.getY() + && location.getBlockZ() >= this.min.getZ() + && location.getBlockZ() <= this.max.getZ()); + } + + public boolean isInRegionPlayer(Location location) { + if (!location.getWorld().getName().equalsIgnoreCase(world.getName())) { + return false; + } + return (location.getBlockX() >= this.min.getX()-1 + && location.getBlockX() <= this.max.getX()+1 + && location.getBlockZ() >= this.min.getZ()-1 + && location.getBlockZ() <= this.max.getZ()+1); + } + +} diff --git a/src/main/java/com/yaohun/farmingwar/listener/GameEffectListener.java b/src/main/java/com/yaohun/farmingwar/listener/GameEffectListener.java index 0b3a3f4..5c71aaf 100644 --- a/src/main/java/com/yaohun/farmingwar/listener/GameEffectListener.java +++ b/src/main/java/com/yaohun/farmingwar/listener/GameEffectListener.java @@ -1,15 +1,24 @@ package com.yaohun.farmingwar.listener; +import com.yaohun.farmingwar.FarmingWar; +import com.yaohun.farmingwar.game.Game; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.Color; -import org.bukkit.Location; -import org.bukkit.Particle; -import org.bukkit.World; +import org.bukkit.*; +import org.bukkit.block.Block; +import org.bukkit.block.data.Ageable; +import org.bukkit.block.data.type.Farmland; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; +import org.bukkit.entity.TNTPrimed; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.util.Vector; import tools.CDTimeAPI; import tools.RandomUtil; @@ -36,4 +45,388 @@ public class GameEffectListener implements Listener { } } + + /* + * 当玩家手持物品右键指定方块时触发效果 + * */ + @EventHandler + public void onPotion_drop_Main(PlayerInteractEvent e) { + Player p = e.getPlayer(); + ItemStack item = p.getInventory().getItemInMainHand(); + if (item.getType() != Material.AIR && item.getType() == Material.SPLASH_POTION) { + Block block = e.getClickedBlock(); + if (e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.LEFT_CLICK_BLOCK) { + boolean sound_butt = false; + Location location = block.getLocation(); + // 检测 3x2x3范围中的方块 + for (int x = -1; x <= 1; x++) { + for (int y = -1; y <= 1; y++) { + for (int z = -1; z <= 1; z++) { + Block newBlock = location.getWorld().getBlockAt(location.clone().add(x, y, z)); + // 判断方块是否是泥土 + if (newBlock.getType() == Material.FARMLAND) { + Farmland fdata = (Farmland) newBlock.getBlockData(); + if (fdata.getMoisture() < 7) { + sound_butt = true; + fdata.setMoisture(fdata.getMaximumMoisture()); + newBlock.setBlockData(fdata); + location.getWorld().spawnParticle(Particle.CRIMSON_SPORE, newBlock.getLocation().add(0.5, 0.5, 0.5), 3, 0.5, 0.5, 0.5, 0.1); + } + } + } + } + } + if (sound_butt) { + p.playSound(p.getLocation(), Sound.ITEM_BUCKET_EMPTY, 1, 1); + } + } + } + } + + + @EventHandler + public void onPotion_drop_Off(PlayerInteractEvent e) { + Player p = e.getPlayer(); + ItemStack item = p.getInventory().getItemInOffHand(); + if (item.getType() != Material.AIR && item.getType() == Material.SPLASH_POTION) { + Block block = e.getClickedBlock(); + if (e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.LEFT_CLICK_BLOCK) { + boolean sound_butt = false; + Location location = block.getLocation(); + // 检测 3x2x3范围中的方块 + for (int x = -1; x <= 1; x++) { + for (int y = -1; y <= 1; y++) { + for (int z = -1; z <= 1; z++) { + Block newBlock = location.getWorld().getBlockAt(location.clone().add(x, y, z)); + // 判断方块是否是泥土 + if (newBlock.getType() == Material.FARMLAND) { + Farmland fdata = (Farmland) newBlock.getBlockData(); + if (fdata.getMoisture() < 7) { + sound_butt = true; + fdata.setMoisture(fdata.getMaximumMoisture()); + newBlock.setBlockData(fdata); + location.getWorld().spawnParticle(Particle.CRIMSON_SPORE, newBlock.getLocation().add(0.5, 0.5, 0.5), 3, 0.5, 0.5, 0.5, 0.1); + } + } + } + } + } + if (sound_butt) { + p.playSound(p.getLocation(), Sound.ITEM_BUCKET_EMPTY, 1, 1); + } + } + } + } + + @EventHandler + public void onBone_meal_Main(PlayerInteractEvent e) { + Player p = e.getPlayer(); + Block block = e.getClickedBlock(); + if (e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.LEFT_CLICK_BLOCK) { + ItemStack item = p.getInventory().getItemInMainHand(); + // 检测手持物品是否是骨粉 + if (item.getType() == Material.BONE_MEAL) { + e.setCancelled(true); + boolean sound_butt = false; + Location location = block.getLocation(); + // 检测 3x2x3范围中的方块 + for (int x = -1; x <= 1; x++) { + for (int y = -1; y <= 1; y++) { + for (int z = -1; z <= 1; z++) { + Block newBlock = location.getWorld().getBlockAt(location.clone().add(x, y, z)); + if(newBlock.getType() == Material.WHEAT){ + if(newBlock.getBlockData() instanceof Ageable) { + Ageable ageable = (Ageable) newBlock.getBlockData(); + if (ageable.getAge() < 7) { + sound_butt = true; + ageable.setAge(ageable.getMaximumAge()); + newBlock.setBlockData(ageable); + block.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, newBlock.getLocation().add(0.5, 0.5, 0.5), 3, 0.5, 0.5, 0.5, 0.1); + } + } + } + } + } + } + if(sound_butt){ + p.playSound(p.getLocation(),Sound.BLOCK_CROP_BREAK,1,1); + } + } + } + } + @EventHandler + public void onBone_meal_Off(PlayerInteractEvent e) { + Player p = e.getPlayer(); + Block block = e.getClickedBlock(); + if (e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.LEFT_CLICK_BLOCK) { + ItemStack item = p.getInventory().getItemInOffHand(); + // 检测手持物品是否是骨粉 + if (item.getType() == Material.BONE_MEAL) { + e.setCancelled(true); + boolean sound_butt = false; + Location location = block.getLocation(); + // 检测 3x2x3范围中的方块 + for (int x = -1; x <= 1; x++) { + for (int y = -1; y <= 1; y++) { + for (int z = -1; z <= 1; z++) { + Block newBlock = location.getWorld().getBlockAt(location.clone().add(x, y, z)); + if(newBlock.getType() == Material.WHEAT){ + if(newBlock.getBlockData() instanceof Ageable) { + Ageable ageable = (Ageable) newBlock.getBlockData(); + if (ageable.getAge() < 7) { + sound_butt = true; + ageable.setAge(ageable.getMaximumAge()); + newBlock.setBlockData(ageable); + block.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, newBlock.getLocation().add(0.5, 0.5, 0.5), 3, 0.5, 0.5, 0.5, 0.1); + } + } + } + } + } + } + if(sound_butt){ + p.playSound(p.getLocation(),Sound.BLOCK_CROP_BREAK,1,1); + } + } + } + } + + @EventHandler + public void onWheat_Seeds(PlayerInteractEvent e){ + Player p = e.getPlayer(); + Block block = e.getClickedBlock(); + if(e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.LEFT_CLICK_BLOCK) { + ItemStack item = p.getInventory().getItemInMainHand(); + // 检测手持物品是否是小麦种子 + if (item.getType() == Material.WHEAT_SEEDS) { + boolean sound_butt = false; + // 获取玩家点击方块的坐标 + Location location = block.getLocation(); + if (p.isSneaking()) { + // 检索到泥土方块后判断方块是否是湿润状态 + if (block.getBlockData() instanceof Farmland) { + Farmland farmland = (Farmland) block.getBlockData(); + // 如果没有打湿则跳过 + if (farmland.getMoisture() != 7) { + return; + } + // 获取泥土方块上方是否有小麦 + Block blockWheat = block.getRelative(0, 1, 0); + if (blockWheat.getType() == Material.AIR) { + blockWheat.setType(Material.WHEAT); + if (blockWheat.getBlockData() instanceof Ageable) { + // 将小麦设置为刚种下时的阶段 + Ageable wheat = (Ageable) blockWheat.getBlockData(); + wheat.setAge(3); + blockWheat.setBlockData(wheat); + p.playSound(p.getLocation(), Sound.BLOCK_AMETHYST_BLOCK_PLACE, 1, 1); + block.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, blockWheat.getLocation().add(0.5, 0.5, 0.5), 3, 0.5, 0.5, 0.5, 0.1); + } + } + } + } else { + if(block.getType() == Material.FARMLAND){ + if (block.getBlockData() instanceof Farmland) { + Farmland farmland = (Farmland) block.getBlockData(); + if (farmland.getMoisture() != 7) { + e.setCancelled(true); + } + } + } + // 检测 3x2x3范围中的方块 + for (int x = -1; x <= 1; x++) { + for (int y = -1; y <= 0; y++) { + for (int z = -1; z <= 1; z++) { + Block newBlock = location.getWorld().getBlockAt(location.clone().add(x, y, z)); + // 检索到泥土方块后判断方块是否是湿润状态 + if (newBlock.getBlockData() instanceof Farmland) { + Farmland farmland = (Farmland) newBlock.getBlockData(); + // 如果没有打湿则跳过遍历 + if (farmland.getMoisture() != 7) { + continue; + } + // 获取泥土方块上方是否有小麦 + Block blockWheat = newBlock.getRelative(0, 1, 0); + if (blockWheat.getType() == Material.AIR) { + blockWheat.setType(Material.WHEAT); + if (blockWheat.getBlockData() instanceof Ageable) { + // 将小麦设置为刚种下时的阶段 + Ageable wheat = (Ageable) blockWheat.getBlockData(); + wheat.setAge(3); + blockWheat.setBlockData(wheat); + block.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, blockWheat.getLocation().add(0.5, 0.5, 0.5), 3, 0.5, 0.5, 0.5, 0.1); + sound_butt = true; + } + }else if (block.getType() == Material.WHEAT) { + if (block.getBlockData() instanceof Ageable) { + // 将小麦设置为刚种下时的阶段 + Ageable ageable = (Ageable) block.getBlockData(); + if (ageable.getAge() < 3) { + ageable.setAge(3); + block.setBlockData(ageable); + block.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, blockWheat.getLocation().add(0.5, 0.5, 0.5), 3, 0.5, 0.5, 0.5, 0.1); + sound_butt = true; + } + } + } + } + } + } + } + if(sound_butt){ + p.playSound(p.getLocation(),Sound.BLOCK_CROP_BREAK,1,1); + } + } + } + } + } + + + @EventHandler + public void onWheat_Seeds_off(PlayerInteractEvent e){ + Player p = e.getPlayer(); + Block block = e.getClickedBlock(); + if(e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.LEFT_CLICK_BLOCK) { + ItemStack item = p.getInventory().getItemInOffHand(); + // 检测手持物品是否是小麦种子 + if (item.getType() == Material.WHEAT_SEEDS) { + boolean sound_butt = false; + // 获取玩家点击方块的坐标 + Location location = block.getLocation(); + if (p.isSneaking()) { + // 检索到泥土方块后判断方块是否是湿润状态 + if (block.getBlockData() instanceof Farmland) { + Farmland farmland = (Farmland) block.getBlockData(); + // 如果没有打湿则跳过 + if (farmland.getMoisture() != 7) { + return; + } + // 获取泥土方块上方是否有小麦 + Block blockWheat = block.getRelative(0, 1, 0); + if (blockWheat.getType() == Material.AIR) { + blockWheat.setType(Material.WHEAT); + if (blockWheat.getBlockData() instanceof Ageable) { + // 将小麦设置为刚种下时的阶段 + Ageable wheat = (Ageable) blockWheat.getBlockData(); + wheat.setAge(3); + blockWheat.setBlockData(wheat); + p.playSound(p.getLocation(), Sound.BLOCK_AMETHYST_BLOCK_PLACE, 1, 1); + block.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, blockWheat.getLocation().add(0.5, 0.5, 0.5), 3, 0.5, 0.5, 0.5, 0.1); + } + } + } + } else { + if(block.getType() == Material.FARMLAND){ + if (block.getBlockData() instanceof Farmland) { + Farmland farmland = (Farmland) block.getBlockData(); + if (farmland.getMoisture() != 7) { + e.setCancelled(true); + } + } + } + // 检测 3x2x3范围中的方块 + for (int x = -1; x <= 1; x++) { + for (int y = -1; y <= 0; y++) { + for (int z = -1; z <= 1; z++) { + Block newBlock = location.getWorld().getBlockAt(location.clone().add(x, y, z)); + // 检索到泥土方块后判断方块是否是湿润状态 + if (newBlock.getBlockData() instanceof Farmland) { + Farmland farmland = (Farmland) newBlock.getBlockData(); + // 如果没有打湿则跳过遍历 + if (farmland.getMoisture() != 7) { + continue; + } + // 获取泥土方块上方是否有小麦 + Block blockWheat = newBlock.getRelative(0, 1, 0); + if (blockWheat.getType() == Material.AIR) { + blockWheat.setType(Material.WHEAT); + if (blockWheat.getBlockData() instanceof Ageable) { + // 将小麦设置为刚种下时的阶段 + Ageable wheat = (Ageable) blockWheat.getBlockData(); + wheat.setAge(3); + blockWheat.setBlockData(wheat); + block.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, blockWheat.getLocation().add(0.5, 0.5, 0.5), 3, 0.5, 0.5, 0.5, 0.1); + sound_butt = true; + } + }else if (block.getType() == Material.WHEAT) { + if (block.getBlockData() instanceof Ageable) { + // 将小麦设置为刚种下时的阶段 + Ageable ageable = (Ageable) block.getBlockData(); + if (ageable.getAge() < 3) { + ageable.setAge(3); + block.setBlockData(ageable); + block.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, blockWheat.getLocation().add(0.5, 0.5, 0.5), 3, 0.5, 0.5, 0.5, 0.1); + sound_butt = true; + } + } + } + } + } + } + } + if(sound_butt){ + p.playSound(p.getLocation(),Sound.BLOCK_CROP_BREAK,1,1); + } + } + } + } + } + + public static int skyTnt = 0; + public static int skyTntSound = 0; + @EventHandler + public void onplace(PlayerMoveEvent e) { + Player p = e.getPlayer(); + UUID uuid = p.getUniqueId(); + Location loc = p.getLocation(); + Game game = FarmingWar.getGame(); + if(CDTimeAPI.getCD(uuid,"skyTnt") >= 1){ + long milliseconds = CDTimeAPI.getCD(uuid, "skyTnt"); + double seconds = (double) milliseconds / 1000; + String message = "§6螺旋升天倒计时: §b" + String.format("%.1f", seconds) + "秒"; + p.sendTitle("§c§l"+String.format("%.1f",p.getLocation().getY())+"米","§e当前海拔高度",0,25,5); + p.spigot().sendMessage(ChatMessageType.ACTION_BAR,new TextComponent(message)); + String skyTntCdKey = "skyTntCd"; + long skyTntCd = CDTimeAPI.getCD(uuid,skyTntCdKey); + if(skyTntCd < 1) { + CDTimeAPI.setPlayerCD(uuid,skyTntCdKey,250); + new BukkitRunnable() { + public void run() { + double radius = 1.0; + double angleStep = Math.PI / 4; + double angle = skyTnt * angleStep; + Vector vector = new Vector(radius * Math.cos(angle), 0.5, radius * Math.sin(angle)); + p.setVelocity(vector); + skyTnt++; + skyTntSound++; + if (skyTnt >= 8) { + skyTnt = 0; + } + if(skyTntSound >= 14){ + skyTntSound = 0; + p.playSound(p.getLocation(),"dxj",1,1); + if(p.isFlying()){ + p.setFlying(false); + } + } + cancel(); + } + }.runTaskLater(FarmingWar.inst(), 5L); + } + new BukkitRunnable() { + public void run() { + Location newTnt_loc = p.getLocation().add(0,RandomUtil.getRandomInt(-2,2),0); + Vector launchVector = new Vector(RandomUtil.getRandomDouble(-0.5, 0.5, 1), 0 , RandomUtil.getRandomDouble(-0.5, 0.5, 1)); + TNTPrimed tntPrimed = (TNTPrimed) game.getRegion().getWorld().spawnEntity(newTnt_loc, EntityType.PRIMED_TNT); + tntPrimed.setFuseTicks(50); + tntPrimed.setYield(4); + if (RandomUtil.getRandomInt(1, 100) >= 80) { + tntPrimed.setVelocity(launchVector); + } + p.getWorld().playSound(newTnt_loc, Sound.ENTITY_CREEPER_PRIMED, 1.0f, 1.0f); + cancel(); + } + }.runTaskLater(FarmingWar.inst(), 10L); + } + } } diff --git a/src/main/java/com/yaohun/farmingwar/listener/GameListener.java b/src/main/java/com/yaohun/farmingwar/listener/GameListener.java index b2eaa24..99df61c 100644 --- a/src/main/java/com/yaohun/farmingwar/listener/GameListener.java +++ b/src/main/java/com/yaohun/farmingwar/listener/GameListener.java @@ -2,7 +2,25 @@ package com.yaohun.farmingwar.listener; import com.yaohun.farmingwar.FarmingWar; import com.yaohun.farmingwar.game.Game; +import com.yaohun.farmingwar.game.Region; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.data.Ageable; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.type.Farmland; +import org.bukkit.entity.*; +import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.ProjectileLaunchEvent; +import org.bukkit.event.server.ServerListPingEvent; +import org.bukkit.scheduler.BukkitRunnable; +import tools.StackUtil; + +import java.util.Iterator; public class GameListener implements Listener { @@ -12,4 +30,120 @@ public class GameListener implements Listener { farmingWar = farmingWarMainClass; game = FarmingWar.getGame(); } + + @EventHandler + public void onPingMotd(ServerListPingEvent e){ + if(game.isStarted()){ + e.setMotd("§a整蛊模式: §6保卫小麦 §a当前版本: §6复刻版 §b运行中"); + } else { + e.setMotd("§a整蛊模式: §6保卫小麦 §a当前版本: §6复刻版 §b运行中"); + } + } + + @EventHandler + public void onDamageByEntity(EntityDamageByEntityEvent e){ + Entity entity = e.getEntity(); + if(entity instanceof Player player){ + if(e.getDamager() instanceof Bee) { + ((Bee) e.getDamager()).damage(100); + ((Player) entity).damage(1.0); + if(player.isFlying()){ + player.setFlying(false); + } + } else { + e.setDamage(0); + if(player.isFlying()){ + player.setFlying(false); + } + } + } + } + + @EventHandler /*生物免摔落伤害*/ + public void onAntiFall(EntityDamageEvent event) { + if (event.getCause().equals(EntityDamageEvent.DamageCause.FALL)) { + event.setCancelled(true); + } + } + + /* + * 爆炸会检测被炸的方块是否是小麦 + * 如果是小麦并有小麦的情况下会将小麦变成种子状态 + * */ + @EventHandler + public void onEntityExplode(EntityExplodeEvent event) { + if(game.isStarted()){ + Iterator iterator = event.blockList().iterator(); + while (iterator.hasNext()) { + Block block = iterator.next(); + Region region = game.getRegion(); + if (region.isInRegion(block.getLocation())) { + if (block.getType() == Material.WHEAT) { + BlockData blockData = block.getBlockData(); + if (blockData instanceof Ageable ageable) { + if (ageable.getAge() >= 3) { + block.setType(Material.AIR); + } + } + } + iterator.remove(); + } else if(region.isInRegionPlayer(block.getLocation())){ + if(block.getType() == Material.FARMLAND){ + Block wheatBlock = block.getRelative(0,1,0); + if (wheatBlock.getType() != Material.WHEAT) { + if (block.getBlockData() instanceof Farmland farmland) { + if (farmland.getMoisture() == farmland.getMaximumMoisture()) { + block.setType(Material.FARMLAND); + } + } + } + } + iterator.remove(); + } + } + } + } + + /* + * 当玩家投掷三叉戟时会给玩家背包刷新一个三叉戟 + * */ + @EventHandler + public void onTridentThrow(ProjectileLaunchEvent event) { + if (event.getEntity() instanceof Trident) { + Trident trident = (Trident) event.getEntity(); + if(trident.getShooter() instanceof Player player){ + player.getInventory().setItem(1, StackUtil.trident()); + } + new BukkitRunnable() { + @Override + public void run() { + if (!trident.isDead()) { + trident.remove(); // 移除三叉戟 + } + } + }.runTaskLater(FarmingWar.inst(), 5 * 20L); // 5秒延迟,1秒 = 20 tick + } + if (event.getEntity() instanceof ThrownPotion) { + ThrownPotion potion = (ThrownPotion) event.getEntity(); + // 获取投掷者 + if (potion.getShooter() instanceof Player player) { + event.setCancelled(true); + } + } + } + + + /* + * 禁止破坏游戏区域外的方块 + * */ + @EventHandler + public void onBlockBreak(BlockBreakEvent event) { + Block block = event.getBlock(); + if (game.isStarted()) { + Region region = game.getRegion(); + if (region.isInRegionPlayer(block.getLocation())) { + event.setCancelled(true); + } + } + } } diff --git a/src/main/java/com/yaohun/farmingwar/listener/GamePotect.java b/src/main/java/com/yaohun/farmingwar/listener/GamePotect.java index 2bf8fc0..4120acb 100644 --- a/src/main/java/com/yaohun/farmingwar/listener/GamePotect.java +++ b/src/main/java/com/yaohun/farmingwar/listener/GamePotect.java @@ -1,6 +1,9 @@ package com.yaohun.farmingwar.listener; +import org.bukkit.Material; import org.bukkit.Sound; +import org.bukkit.block.Block; +import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -9,8 +12,10 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.*; import org.bukkit.event.entity.EntityCombustEvent; import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.EntityInteractEvent; import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.weather.WeatherChangeEvent; @@ -41,11 +46,35 @@ public class GamePotect implements Listener { @EventHandler // 拾取任何物品不进入背包直接清理 public void onPick(PlayerPickupItemEvent e){ Player p = e.getPlayer(); - p.playSound(p.getLocation(), Sound.ENTITY_ITEM_PICKUP, 1, 1); e.setCancelled(true); - e.getItem().remove(); + if(e.getItem().getItemStack().getType() != Material.TRIDENT) { + p.playSound(p.getLocation(), Sound.ENTITY_ITEM_PICKUP,1,1); + e.getItem().remove(); + } } @EventHandler // 禁止丢弃任何物品 public void onDrop(PlayerDropItemEvent e){e.setCancelled(true);} + + @EventHandler /*保护农作物免踩踏*/ + public void onJumpFarm(PlayerInteractEvent e){ + if (e.isCancelled()) {return;} + if(e.getAction() == Action.PHYSICAL){ + Block block = e.getClickedBlock(); + if(block.getType() == Material.FARMLAND){ + e.setCancelled(true); + } + } + } + + @EventHandler /*保护农作物免踩踏*/ + public void onMobsFarm(EntityInteractEvent e){ + if (e.isCancelled()) {return;} + if(e.getEntityType() != EntityType.PLAYER){ + Block block = e.getBlock(); + if(block.getType() == Material.FARMLAND){ + e.setCancelled(true); + } + } + } } diff --git a/src/main/java/com/yaohun/farmingwar/listener/JoinListener.java b/src/main/java/com/yaohun/farmingwar/listener/JoinListener.java index 5defdf4..d2990b3 100644 --- a/src/main/java/com/yaohun/farmingwar/listener/JoinListener.java +++ b/src/main/java/com/yaohun/farmingwar/listener/JoinListener.java @@ -20,14 +20,13 @@ public class JoinListener implements Listener { @EventHandler public void onJoin(PlayerJoinEvent e){ - Player p = e.getPlayer(); - p.setGameMode(GameMode.ADVENTURE); new BukkitRunnable() { @Override public void run() { if(!game.isStarted()) { game.start(); } + game.initPlayerData(e.getPlayer()); } }.runTaskLater(farmingWar,10L); } diff --git a/src/main/java/com/yaohun/farmingwar/listener/KeepEntitiesOnDeath.java b/src/main/java/com/yaohun/farmingwar/listener/KeepEntitiesOnDeath.java new file mode 100644 index 0000000..07b9b95 --- /dev/null +++ b/src/main/java/com/yaohun/farmingwar/listener/KeepEntitiesOnDeath.java @@ -0,0 +1,79 @@ +package com.yaohun.farmingwar.listener; + +import com.jgxs.yaohun.teleportspigot.api.WarpAPI; +import com.yaohun.farmingwar.FarmingWar; +import com.yaohun.farmingwar.game.Game; +import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.scheduler.BukkitRunnable; +import tools.RandomUtil; + +public class KeepEntitiesOnDeath implements Listener { + + @EventHandler + public void onAutoRespawn(EntityDamageByEntityEvent e){ + Entity entity = e.getEntity(); + // 获取当前游戏记录点高度 + Game game = FarmingWar.getGame(); + if(game.isStarted()) { + if (entity instanceof LivingEntity living) { + if(living instanceof Player player) { + double health = living.getHealth(); + double beHurt = health - e.getDamage(); + if (beHurt <= 0) { + e.setCancelled(true); + player.teleport(game.getRegion().getHub()); + player.setHealth(player.getMaxHealth()); + player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP,1,1); + if (RandomUtil.getRandomInt(1,100) >= 50) { + player.sendTitle("§4你嘎了", "行不行啊?菜就多练!"); + } else { + player.sendTitle("§4你嘎了", "汗流浃背了?"); + } + } + } + } + } + } + @EventHandler + public void onAutoRespawn(PlayerDeathEvent e) { + e.setDeathMessage(null); + Player p = e.getEntity(); + // 获取当前游戏记录点高度 + Game game = FarmingWar.getGame(); + if (game.isStarted()) { + new BukkitRunnable() { + private int i = 0; + + public void run() { + if (i == 1) { + p.spigot().respawn(); + } + if(i == 3) { + if (RandomUtil.getRandomInt(1,100) >= 50) { + p.sendTitle("§4你嘎了", "行不行啊?菜就多练!"); + } else { + p.sendTitle("§4你嘎了", "汗流浃背了?"); + } + p.setHealth(p.getMaxHealth()); + game.initPlayerBackpack(p); + } + if(i == 4) { + p.teleport(game.getRegion().getHub()); + cancel(); + } + i++; + } + }.runTaskTimer(FarmingWar.inst(),0L, 2L); + } + } +} diff --git a/src/main/java/com/yaohun/farmingwar/listener/PlayerListener.java b/src/main/java/com/yaohun/farmingwar/listener/PlayerListener.java index 62a1adf..1e17ab8 100644 --- a/src/main/java/com/yaohun/farmingwar/listener/PlayerListener.java +++ b/src/main/java/com/yaohun/farmingwar/listener/PlayerListener.java @@ -1,8 +1,13 @@ package com.yaohun.farmingwar.listener; import com.yaohun.farmingwar.FarmingWar; +import com.yaohun.farmingwar.data.RepairGiftGui; import com.yaohun.farmingwar.game.Game; +import org.bukkit.GameMode; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerDropItemEvent; public class PlayerListener implements Listener { @@ -12,4 +17,14 @@ public class PlayerListener implements Listener { farmingWar = farmingWarMainClass; game = FarmingWar.getGame(); } + + @EventHandler + public void onPick(PlayerDropItemEvent e){ + Player p = e.getPlayer(); + if (game.isStarted()) { + if(p.isSneaking()){ + RepairGiftGui.OpenGui(p); + } + } + } } diff --git a/src/main/java/com/yaohun/farmingwar/liveevent/GiftEventHandler.java b/src/main/java/com/yaohun/farmingwar/liveevent/GiftEventHandler.java index 72fce7d..b4f2ab5 100644 --- a/src/main/java/com/yaohun/farmingwar/liveevent/GiftEventHandler.java +++ b/src/main/java/com/yaohun/farmingwar/liveevent/GiftEventHandler.java @@ -1,20 +1,101 @@ package com.yaohun.farmingwar.liveevent; import com.yaohun.farmingwar.FarmingWar; -import com.yaohun.farmingwar.effects.BigWindill; -import com.yaohun.farmingwar.effects.SummonTheBee; +import com.yaohun.farmingwar.effects.*; import com.yaohun.farmingwar.game.Game; +import com.yaohun.farmingwar.util.ExpandType; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import tools.GameUtil; +import tools.RandomUtil; public class GiftEventHandler { public static void SendHandLer(Player zhubo, String userName, String eventName){ Game game = FarmingWar.getGame(); userName = GameUtil.hideName(userName); - if (eventName.equalsIgnoreCase("大风车5秒")) { + if (eventName.equalsIgnoreCase("螺旋升天")) { + JumpSkyTnt.apply(game,zhubo,10); + zhubo.playSound(zhubo.getLocation(),"dxj",1,1); + }else if (eventName.equalsIgnoreCase("大风车5秒")) { BigWindill.apply(game,zhubo,5); - } else if (eventName.contains("蜜蜂")) { + }else if (eventName.equalsIgnoreCase("大风车60秒")) { + BigWindill.apply(game,zhubo,60); + } else if (eventName.equalsIgnoreCase("关灯100秒")) { + PotionBlindness.apply(game,zhubo,100); + } else if (eventName.contains("羊羊")) { + int amount = 1; + if(eventName.contains("X") || eventName.contains("x") || eventName.contains("*")) { + eventName = eventName.replace("*","X"); + String[] eventSp = eventName.toUpperCase().split("X"); + amount = Integer.parseInt(eventSp[1]); + } + SummonTheSheep.apply(game, zhubo, userName, amount); + } else if (eventName.contains("牛牛")) { + int amount = 1; + if(eventName.contains("X") || eventName.contains("x") || eventName.contains("*")) { + eventName = eventName.replace("*","X"); + String[] eventSp = eventName.toUpperCase().split("X"); + amount = Integer.parseInt(eventSp[1]); + } + SummonTheCow.apply(game, zhubo, userName, amount); + } else if (eventName.contains("史莱姆")) { + int amount = 1; + if(eventName.contains("X") || eventName.contains("x") || eventName.contains("*")) { + eventName = eventName.replace("*","X"); + String[] eventSp = eventName.toUpperCase().split("X"); + amount = Integer.parseInt(eventSp[1]); + } + SummonTheMagmacube.apply(game, zhubo, userName, amount); + } else if (eventName.contains("马")) { + int amount = 1; + if(eventName.contains("X") || eventName.contains("x") || eventName.contains("*")) { + eventName = eventName.replace("*","X"); + String[] eventSp = eventName.toUpperCase().split("X"); + amount = Integer.parseInt(eventSp[1]); + } + SummonTheHorse.apply(game, zhubo, userName, amount); + } else if (eventName.contains("凋零")) { + int amount = 1; + if(eventName.contains("X") || eventName.contains("x") || eventName.contains("*")) { + eventName = eventName.replace("*","X"); + String[] eventSp = eventName.toUpperCase().split("X"); + amount = Integer.parseInt(eventSp[1]); + } + SummonTheWither.apply(game, zhubo, userName, amount); + } else if (eventName.contains("末影龙")) { + int amount = 1; + if(eventName.contains("X") || eventName.contains("x") || eventName.contains("*")) { + eventName = eventName.replace("*","X"); + String[] eventSp = eventName.toUpperCase().split("X"); + amount = Integer.parseInt(eventSp[1]); + } + SummonTheDragon.apply(game, zhubo, userName, amount); + } else if (eventName.contains("村民")) { + int amount = 1; + if(eventName.contains("X") || eventName.contains("x") || eventName.contains("*")) { + eventName = eventName.replace("*","X"); + String[] eventSp = eventName.toUpperCase().split("X"); + amount = Integer.parseInt(eventSp[1]); + } + SummonTheVillager.apply(game, zhubo, userName, amount); + } else if (eventName.contains("羊驼")) { + int amount = 1; + if(eventName.contains("X") || eventName.contains("x") || eventName.contains("*")) { + eventName = eventName.replace("*","X"); + String[] eventSp = eventName.toUpperCase().split("X"); + amount = Integer.parseInt(eventSp[1]); + } + SummonTheTraderllama.apply(game, zhubo, userName, amount); + } else if (eventName.contains("钢铁人")) { + int amount = 1; + if(eventName.contains("X") || eventName.contains("x") || eventName.contains("*")) { + eventName = eventName.replace("*","X"); + String[] eventSp = eventName.toUpperCase().split("X"); + amount = Integer.parseInt(eventSp[1]); + } + SummonTheIrongolem.apply(game, zhubo, userName, amount); + } else if (eventName.contains("小蜜蜂")) { int amount = 1; if(eventName.contains("X") || eventName.contains("x") || eventName.contains("*")) { eventName = eventName.replace("*","X"); @@ -22,6 +103,78 @@ public class GiftEventHandler { amount = Integer.parseInt(eventSp[1]); } SummonTheBee.apply(game, zhubo, userName, amount); + } else if (eventName.contains("巨人")) { + int amount = 1; + if(eventName.contains("X") || eventName.contains("x") || eventName.contains("*")) { + eventName = eventName.replace("*","X"); + String[] eventSp = eventName.toUpperCase().split("X"); + amount = Integer.parseInt(eventSp[1]); + } + SummonTheGiant.apply(game, zhubo, userName, amount); + } else if (eventName.contains("芜湖起飞")) { + int amount = 1; + if(eventName.contains("X") || eventName.contains("x") || eventName.contains("*")) { + eventName = eventName.replace("*","X"); + String[] eventSp = eventName.toUpperCase().split("X"); + amount = Integer.parseInt(eventSp[1]); + } + JumpTnt.apply(game, zhubo, amount); + } else if (eventName.contains("炸弹")) { + int amount = 1; + if(eventName.contains("X") || eventName.contains("x") || eventName.contains("*")) { + eventName = eventName.replace("*","X"); + String[] eventSp = eventName.toUpperCase().split("X"); + amount = Integer.parseInt(eventSp[1]); + } + SpawnTnt.apply(game, zhubo, amount); + } else if (eventName.contains("猪猪")) { + int amount = 1; + if(eventName.contains("X") || eventName.contains("x") || eventName.contains("*")) { + eventName = eventName.replace("*","X"); + String[] eventSp = eventName.toUpperCase().split("X"); + amount = Integer.parseInt(eventSp[1]); + } + SummonThePig.apply(game, zhubo, userName,amount); + } else if (eventName.contains("熊猫")) { + int amount = 1; + if(eventName.contains("X") || eventName.contains("x") || eventName.contains("*")) { + eventName = eventName.replace("*","X"); + String[] eventSp = eventName.toUpperCase().split("X"); + amount = Integer.parseInt(eventSp[1]); + } + SummonThePanda.apply(game, zhubo, userName,amount); + }else if (eventName.contains("北极熊")) { + int amount = 1; + if(eventName.contains("X") || eventName.contains("x") || eventName.contains("*")) { + eventName = eventName.replace("*","X"); + String[] eventSp = eventName.toUpperCase().split("X"); + amount = Integer.parseInt(eventSp[1]); + } + SummonThePolarBear.apply(game, zhubo, userName,amount); + } else if (eventName.equalsIgnoreCase("随机扩建")) { + int amount = RandomUtil.getRandomInt(10,20); + Bukkit.broadcastMessage("§c[系统]§a观众 §e"+userName+" §a触发效果随机扩建,本次将扩建 §e§l"+amount+"次"); + GameSiteExpand.apply(game, ExpandType.KuoJian,amount); + } else if (eventName.equalsIgnoreCase("随机拆除")) { + int amount = RandomUtil.getRandomInt(10,20); + Bukkit.broadcastMessage("§c[系统]§a观众 §e"+userName+" §a触发效果随机拆除,本次将拆除 §e§l"+amount+"次"); + GameSiteExpand.apply(game, ExpandType.ChaiChu,amount); + } else if (eventName.contains("扩建")) { + int amount = 1; + if(eventName.contains("X") || eventName.contains("x") || eventName.contains("*")) { + eventName = eventName.replace("*","X"); + String[] eventSp = eventName.toUpperCase().split("X"); + amount = Integer.parseInt(eventSp[1]); + } + GameSiteExpand.apply(game, ExpandType.KuoJian,amount); + } else if (eventName.contains("拆除")) { + int amount = 1; + if(eventName.contains("X") || eventName.contains("x") || eventName.contains("*")) { + eventName = eventName.replace("*","X"); + String[] eventSp = eventName.toUpperCase().split("X"); + amount = Integer.parseInt(eventSp[1]); + } + GameSiteExpand.apply(game, ExpandType.ChaiChu,amount); } } } diff --git a/src/main/java/com/yaohun/farmingwar/liveevent/LikeListener.java b/src/main/java/com/yaohun/farmingwar/liveevent/LikeListener.java index 6a1aa3d..9813a84 100644 --- a/src/main/java/com/yaohun/farmingwar/liveevent/LikeListener.java +++ b/src/main/java/com/yaohun/farmingwar/liveevent/LikeListener.java @@ -1,7 +1,7 @@ package com.yaohun.farmingwar.liveevent; import com.io.yutian.mclive.event.LiveLikeEvents; -import com.yaohun.farmingwar.LikeData; +import com.yaohun.farmingwar.data.LikeData; import com.yaohun.farmingwar.manager.GameManager; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; diff --git a/src/main/java/com/yaohun/farmingwar/manager/GameManager.java b/src/main/java/com/yaohun/farmingwar/manager/GameManager.java index c5047b9..2b8797b 100644 --- a/src/main/java/com/yaohun/farmingwar/manager/GameManager.java +++ b/src/main/java/com/yaohun/farmingwar/manager/GameManager.java @@ -1,8 +1,8 @@ package com.yaohun.farmingwar.manager; import com.io.yutian.mclive.event.ZhuboAPI; -import com.yaohun.farmingwar.GiftData; -import com.yaohun.farmingwar.LikeData; +import com.yaohun.farmingwar.data.GiftData; +import com.yaohun.farmingwar.data.LikeData; import org.bukkit.Bukkit; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; diff --git a/src/main/java/com/yaohun/farmingwar/util/ExpandType.java b/src/main/java/com/yaohun/farmingwar/util/ExpandType.java new file mode 100644 index 0000000..f02ccda --- /dev/null +++ b/src/main/java/com/yaohun/farmingwar/util/ExpandType.java @@ -0,0 +1,5 @@ +package com.yaohun.farmingwar.util; + +public enum ExpandType { + KuoJian,ChaiChu +} diff --git a/src/main/java/com/yaohun/farmingwar/util/GiftUtil.java b/src/main/java/com/yaohun/farmingwar/util/GiftUtil.java index 7927c58..b3e9c06 100644 --- a/src/main/java/com/yaohun/farmingwar/util/GiftUtil.java +++ b/src/main/java/com/yaohun/farmingwar/util/GiftUtil.java @@ -2,13 +2,19 @@ package com.yaohun.farmingwar.util; import com.yaohun.RandomBox.api.RBoxAPI; import com.yaohun.farmingwar.FarmingWar; -import com.yaohun.farmingwar.GiftData; +import com.yaohun.farmingwar.data.GiftData; import com.yaohun.farmingwar.liveevent.GiftEventHandler; import com.yaohun.farmingwar.manager.GameManager; import org.bukkit.Bukkit; import org.bukkit.entity.Player; public class GiftUtil { + public static void simulateEventEffect(Player player,String userName, String eventName, int amount){ + if(specialGiftEffectTriggers(player,eventName,userName,amount)){ + return; + } + GiftEventHandler.SendHandLer(player, userName, eventName); + } public static void simulatedGiftEffect(Player player, String userName, String giftName, int amount){ GameManager manager = FarmingWar.getGameManager(); if(!manager.isGiftDataExit(giftName)){ @@ -31,12 +37,12 @@ public class GiftUtil { giftData.OutPlaySoundsEvent(); GiftEventHandler.SendHandLer(player, userName, eventName); } else { - long dadey = 10L; + long dadey = 5L; for (int i = 0; i < amount; i++) { - Bukkit.getScheduler().runTaskLater(FarmingWar.inst(), () -> { - giftData.OutPlaySoundsEvent(); - GiftEventHandler.SendHandLer(player, userName, eventName); - }, (long) i * dadey); + Bukkit.getScheduler().runTaskLater(FarmingWar.inst(), giftData::OutPlaySoundsEvent, (long) i * dadey); + } + for (int i = 0; i < amount; i++) { + GiftEventHandler.SendHandLer(player, userName, eventName); } } } diff --git a/src/main/java/tools/GameUtil.java b/src/main/java/tools/GameUtil.java index 7efa7ea..985c495 100644 --- a/src/main/java/tools/GameUtil.java +++ b/src/main/java/tools/GameUtil.java @@ -1,9 +1,20 @@ package tools; -import org.bukkit.Bukkit; -import org.bukkit.Sound; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.yaohun.farmingwar.FarmingWar; +import com.yaohun.farmingwar.game.Game; +import org.bukkit.*; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +import java.io.File; public class GameUtil { public static String hideName(String audience) { @@ -30,4 +41,43 @@ public class GameUtil { } } } + public static void sendAllTitle(String title,String subTitle,int t1,int t2,int t3) { + for (Player player : Bukkit.getOnlinePlayers()) { + player.sendTitle(title,subTitle,t1,t2,t3); + } + } + + public static Vector getRandomVector(double radius){ + double x = RandomUtil.getRandomDouble(0-radius, 0+radius, 1); + double y = RandomUtil.getRandomDouble(0, 0.5, 1); + double z = RandomUtil.getRandomDouble(0-radius, 0+radius, 1); + return new Vector(x, y, z); + } + public static Vector getRandomVector(double radius,double radiusY){ + double x = RandomUtil.getRandomDouble(0-radius, 0+radius, 1); + double y = RandomUtil.getRandomDouble(0+radiusY, 0.5+radiusY, 1); + double z = RandomUtil.getRandomDouble(0-radius, 0+radius, 1); + return new Vector(x, y, z); + } + + public static void loadSchematics(String fileName) { + Game game = FarmingWar.getGame(); + File schema_file = new File("plugins/FastAsyncWorldEdit/schematics",fileName+".schem"); + Location location = new Location(game.getRegion().getWorld(), -233,74,258); + World world = location.getWorld(); + EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(world)); + Bukkit.getScheduler().runTaskAsynchronously( + FarmingWar.inst(), () -> { + try { + Clipboard clipboard = ClipboardFormats.findByFile(schema_file).load(schema_file); + clipboard.paste(BukkitAdapter.adapt(world), BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ())); + clipboard.flush(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + editSession.close(); + } + } + ); + } } diff --git a/src/main/java/tools/StackUtil.java b/src/main/java/tools/StackUtil.java new file mode 100644 index 0000000..a13ddfd --- /dev/null +++ b/src/main/java/tools/StackUtil.java @@ -0,0 +1,56 @@ +package tools; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemFlag; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.meta.PotionMeta; +import org.bukkit.potion.PotionData; +import org.bukkit.potion.PotionType; + +import java.util.ArrayList; +import java.util.List; + +public class StackUtil { + public static ItemStack diamondSword(){ + ItemStack item = new ItemStack(Material.DIAMOND_SWORD); + int randint = RandomUtil.getRandomInt(0,100); + if(randint >= 50){ + item.setType(Material.NETHERITE_SWORD); + } + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName("§6§l农夫的神剑"); + List lore = new ArrayList<>(); + lore.add("§7#极光像素工作室制作"); + meta.setLore(lore); + meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE); + meta.setUnbreakable(true); + item.setItemMeta(meta); + return item; + } + public static ItemStack trident(){ + ItemStack item = new ItemStack(Material.TRIDENT); + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName("§6§l三叉戟"); + List lore = new ArrayList<>(); + lore.add("§7#极光像素工作室制作"); + meta.setLore(lore); + meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE); + meta.setUnbreakable(true); + item.setItemMeta(meta); + return item; + } + public static ItemStack quickPotion(){ + ItemStack item = new ItemStack(Material.SPLASH_POTION); + item.setAmount(6); + PotionMeta meta = (PotionMeta) item.getItemMeta(); + meta.setBasePotionData(new PotionData(PotionType.SPEED,false,false)); + meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS); + item.setItemMeta(meta); + return item; + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..bfc5249 --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,2 @@ +completeAmount: 10 +countdownTime: 10 \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7cc6b15..896a08b 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: FarmingWar main: com.yaohun.farmingwar.FarmingWar version: 1.0 -api-version: 1.18.2 +api-version: '1.18' commands: game: \ No newline at end of file