From 68fb33528fb91b560491d61833cbccb54a329232 Mon Sep 17 00:00:00 2001 From: yaohunya <31456652@qq.com> Date: Sun, 11 Aug 2024 12:04:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=89=881.0.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 17 ++- .../java/com/yaohun/enderdragonWars/Main.java | 27 ---- .../yaohun/enderdragonWars/data/GiftData.java | 41 ------ .../enderdragonWars/effect/GiftEffect.java | 21 --- .../enderdragonWars/effect/GiftQueue.java | 54 -------- .../com/yaohun/enderdragonWars/game/Game.java | 20 --- .../liveevent/GiftEventHandler.java | 13 -- .../yaohun/enderdragonWars/util/GameUtil.java | 37 ------ .../yaohun/enderdragonWars/util/GiftUtil.java | 38 ------ .../enderdragonWars/util/RandomUtil.java | 31 ----- .../java/com/yaohun/enderdragonwars/Main.java | 9 +- .../data/DirectionPoint.java | 0 .../data/Point.java | 0 .../data/Region.java | 0 .../effect/types/AddMaxHealthEffect.java | 0 .../effect/types/BlackHoleEffect.java | 0 .../effect/types/BomBomEffect.java | 1 + .../effect/types/ClearInventoryEffect.java | 0 .../effect/types/FiveLightningEffect.java | 0 .../effect/types/GiveTotemEffect.java | 0 .../effect/types/LavaPoolEffect.java | 0 .../effect/types/LuckyBlockEffect.java | 0 .../effect/types/PlayerBigEffect.java | 0 .../effect/types/PlayerResetEffect.java | 0 .../effect/types/PlayerSmallEffect.java | 0 .../effect/types/SpawnBuildEffect.java | 0 .../effect/types/SpawnEnderPortalEffect.java | 0 .../effect/types/SummonIronGolem.java | 0 .../effect/types/TakeMaxHealthEffect.java | 0 .../effect/types/ToHeavenEffect.java | 0 .../effect/types/WorldDestroyEffect.java | 0 .../com/yaohun/enderdragonwars/game/Game.java | 124 ++++++++++++++++-- .../listener/GameListener.java | 71 ++++++++++ .../listener/PlayerListener.java | 0 .../manager/GameManager.java | 0 .../manager/GiftEffectManager.java | 0 .../enderdragonwars/util/BossBarUtil.java | 55 ++++++++ .../util/BuildSpawner.java | 0 .../util/EntityUtil.java | 0 .../util/ItemStackBuilder.java | 0 .../util/WEUtil.java | 0 41 files changed, 262 insertions(+), 297 deletions(-) delete mode 100644 src/main/java/com/yaohun/enderdragonWars/Main.java delete mode 100644 src/main/java/com/yaohun/enderdragonWars/data/GiftData.java delete mode 100644 src/main/java/com/yaohun/enderdragonWars/effect/GiftEffect.java delete mode 100644 src/main/java/com/yaohun/enderdragonWars/effect/GiftQueue.java delete mode 100644 src/main/java/com/yaohun/enderdragonWars/game/Game.java delete mode 100644 src/main/java/com/yaohun/enderdragonWars/liveevent/GiftEventHandler.java delete mode 100644 src/main/java/com/yaohun/enderdragonWars/util/GameUtil.java delete mode 100644 src/main/java/com/yaohun/enderdragonWars/util/GiftUtil.java delete mode 100644 src/main/java/com/yaohun/enderdragonWars/util/RandomUtil.java rename src/main/java/com/yaohun/{enderdragonWars => enderdragonwars}/data/DirectionPoint.java (100%) rename src/main/java/com/yaohun/{enderdragonWars => enderdragonwars}/data/Point.java (100%) rename src/main/java/com/yaohun/{enderdragonWars => enderdragonwars}/data/Region.java (100%) rename src/main/java/com/yaohun/{enderdragonWars => enderdragonwars}/effect/types/AddMaxHealthEffect.java (100%) rename src/main/java/com/yaohun/{enderdragonWars => enderdragonwars}/effect/types/BlackHoleEffect.java (100%) rename src/main/java/com/yaohun/{enderdragonWars => enderdragonwars}/effect/types/BomBomEffect.java (99%) rename src/main/java/com/yaohun/{enderdragonWars => enderdragonwars}/effect/types/ClearInventoryEffect.java (100%) rename src/main/java/com/yaohun/{enderdragonWars => enderdragonwars}/effect/types/FiveLightningEffect.java (100%) rename src/main/java/com/yaohun/{enderdragonWars => enderdragonwars}/effect/types/GiveTotemEffect.java (100%) rename src/main/java/com/yaohun/{enderdragonWars => enderdragonwars}/effect/types/LavaPoolEffect.java (100%) rename src/main/java/com/yaohun/{enderdragonWars => enderdragonwars}/effect/types/LuckyBlockEffect.java (100%) rename src/main/java/com/yaohun/{enderdragonWars => enderdragonwars}/effect/types/PlayerBigEffect.java (100%) rename src/main/java/com/yaohun/{enderdragonWars => enderdragonwars}/effect/types/PlayerResetEffect.java (100%) rename src/main/java/com/yaohun/{enderdragonWars => enderdragonwars}/effect/types/PlayerSmallEffect.java (100%) rename src/main/java/com/yaohun/{enderdragonWars => enderdragonwars}/effect/types/SpawnBuildEffect.java (100%) rename src/main/java/com/yaohun/{enderdragonWars => enderdragonwars}/effect/types/SpawnEnderPortalEffect.java (100%) rename src/main/java/com/yaohun/{enderdragonWars => enderdragonwars}/effect/types/SummonIronGolem.java (100%) rename src/main/java/com/yaohun/{enderdragonWars => enderdragonwars}/effect/types/TakeMaxHealthEffect.java (100%) rename src/main/java/com/yaohun/{enderdragonWars => enderdragonwars}/effect/types/ToHeavenEffect.java (100%) rename src/main/java/com/yaohun/{enderdragonWars => enderdragonwars}/effect/types/WorldDestroyEffect.java (100%) create mode 100644 src/main/java/com/yaohun/enderdragonwars/listener/GameListener.java rename src/main/java/com/yaohun/{enderdragonWars => enderdragonwars}/listener/PlayerListener.java (100%) rename src/main/java/com/yaohun/{enderdragonWars => enderdragonwars}/manager/GameManager.java (100%) rename src/main/java/com/yaohun/{enderdragonWars => enderdragonwars}/manager/GiftEffectManager.java (100%) create mode 100644 src/main/java/com/yaohun/enderdragonwars/util/BossBarUtil.java rename src/main/java/com/yaohun/{enderdragonWars => enderdragonwars}/util/BuildSpawner.java (100%) rename src/main/java/com/yaohun/{enderdragonWars => enderdragonwars}/util/EntityUtil.java (100%) rename src/main/java/com/yaohun/{enderdragonWars => enderdragonwars}/util/ItemStackBuilder.java (100%) rename src/main/java/com/yaohun/{enderdragonWars => enderdragonwars}/util/WEUtil.java (100%) diff --git a/pom.xml b/pom.xml index 5e1d3a1..e5b6224 100644 --- a/pom.xml +++ b/pom.xml @@ -26,21 +26,26 @@ public-rpg https://repo.aurora-pixels.com/repository/public-rpg/ + + spigotmc-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + - - io.papermc.paper - paper-api - 1.20.6-R0.1-SNAPSHOT - provided - com.sk89q fastasyncworldedit 2.11.1 857 + + org.spigotmc + spigot-api + 1.20.6-R0.1-SNAPSHOT + provided + + \ No newline at end of file diff --git a/src/main/java/com/yaohun/enderdragonWars/Main.java b/src/main/java/com/yaohun/enderdragonWars/Main.java deleted file mode 100644 index 1d117b3..0000000 --- a/src/main/java/com/yaohun/enderdragonWars/Main.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.yaohun.enderdragonWars; - -import com.yaohun.enderdragonWars.game.Game; -import com.yaohun.enderdragonWars.manage.GameManage; -import com.yaohun.enderdragonWars.manage.GiftEffectManager; -import org.bukkit.plugin.java.JavaPlugin; - -public class Main extends JavaPlugin { - - public static Main plugin; - public static GameManage gameManage; - public static Game game; - - @Override - public void onEnable() { - plugin = this; - GiftEffectManager.registerAll(); - gameManage = new GameManage(); - game = new Game(); - } - - - @Override - public void onDisable() { - GiftEffectManager.stopQueue(); - } -} diff --git a/src/main/java/com/yaohun/enderdragonWars/data/GiftData.java b/src/main/java/com/yaohun/enderdragonWars/data/GiftData.java deleted file mode 100644 index 4bf85dd..0000000 --- a/src/main/java/com/yaohun/enderdragonWars/data/GiftData.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.yaohun.enderdragonWars.data; - -import com.yaohun.enderdragonWars.util.GameUtil; -import org.bukkit.Bukkit; -import org.bukkit.configuration.file.FileConfiguration; - -public class GiftData { - private String giftName; // 礼物名 - private String event; // 效果名 - private int minutes; // 加播或减播 - private String sounds; // 自定义音效 - - public GiftData(String giftName, FileConfiguration yml) { - this.giftName = giftName; - String str = "礼物设置." + giftName + "."; - if (yml.getString(str + "声音") != null) { - this.sounds = yml.getString(str + "声音"); - } - this.event = yml.getString(str + "效果"); - this.minutes = yml.getInt(str + "加播"); - if (this.minutes >= 1) { - Bukkit.getConsoleSender().sendMessage("事件: " + this.event + " 条件: " + giftName + " 加播: +" + minutes + "分钟"); - } else { - Bukkit.getConsoleSender().sendMessage("事件: " + this.event + " 条件: " + giftName + " 减播: -" + minutes + "分钟"); - } - } - - public String getGiftName() { - return giftName; - } - - public String getEvent() { - return event; - } - - public void OutPlaySoundsEvent() { - if(!sounds.equalsIgnoreCase("NULL")) { - GameUtil.SendAllSounds(sounds); - } - } -} diff --git a/src/main/java/com/yaohun/enderdragonWars/effect/GiftEffect.java b/src/main/java/com/yaohun/enderdragonWars/effect/GiftEffect.java deleted file mode 100644 index f9d161d..0000000 --- a/src/main/java/com/yaohun/enderdragonWars/effect/GiftEffect.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.yaohun.enderdragonWars.effect; - -import com.yaohun.enderdragonWars.game.Game; - -public abstract class GiftEffect { - private String audience; - - public GiftEffect(String audience) { - this.audience = audience; - } - - public String getAudience() { - return audience; - } - - public abstract void apply(Game game); - - public int getQueueTime() { - return 20; - } -} diff --git a/src/main/java/com/yaohun/enderdragonWars/effect/GiftQueue.java b/src/main/java/com/yaohun/enderdragonWars/effect/GiftQueue.java deleted file mode 100644 index e4bafa3..0000000 --- a/src/main/java/com/yaohun/enderdragonWars/effect/GiftQueue.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.yaohun.enderdragonWars.effect; - -import com.yaohun.enderdragonWars.Main; -import com.yaohun.enderdragonWars.game.Game; -import org.bukkit.Bukkit; -import org.bukkit.scheduler.BukkitTask; - -import java.util.LinkedList; -import java.util.Queue; - -public class GiftQueue { - - private Queue effectQueue = new LinkedList<>(); - - private BukkitTask task; - - public GiftQueue(int waitTime) { - task = Bukkit.getScheduler().runTaskTimer(Main.plugin, new Runnable() { - private int timer = 0; - private boolean running = false; - @Override - public void run() { - timer++; - if (!running) { - timer = waitTime; - running = true; - } - if (timer >= waitTime) { - timer = 0; - if (effectQueue.isEmpty()) { - running = false; - return; - } - Game game = Main.game; - GiftEffect effect = effectQueue.poll(); - effect.apply(game); - } - } - }, 0L, 1L); - } - - public void addEffect(GiftEffect effect) { - effectQueue.add(effect); - } - - public Queue getEffectQueue() { - return effectQueue; - } - - public BukkitTask getTask() { - return task; - } - -} diff --git a/src/main/java/com/yaohun/enderdragonWars/game/Game.java b/src/main/java/com/yaohun/enderdragonWars/game/Game.java deleted file mode 100644 index dcab460..0000000 --- a/src/main/java/com/yaohun/enderdragonWars/game/Game.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.yaohun.enderdragonWars.game; - -import org.bukkit.World; -import org.bukkit.entity.Player; - -public class Game { - - private Player player; - private World world; - private boolean startd; - public Game(){ - - } - - public void startGame(Player player){ - if(startd){return;} - this.player = player; - this.startd = true; - } -} diff --git a/src/main/java/com/yaohun/enderdragonWars/liveevent/GiftEventHandler.java b/src/main/java/com/yaohun/enderdragonWars/liveevent/GiftEventHandler.java deleted file mode 100644 index 1f6ca52..0000000 --- a/src/main/java/com/yaohun/enderdragonWars/liveevent/GiftEventHandler.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.yaohun.enderdragonWars.liveevent; - -import com.yaohun.enderdragonWars.manage.GiftEffectManager; -import org.bukkit.entity.Player; - -public class GiftEventHandler { - - public static void SendHandLer(Player zhubo, String hideName, String eventName){ - if(eventName.equalsIgnoreCase("清空背包")){ - GiftEffectManager.addGiftEffect(hideName,eventName); - } - } -} diff --git a/src/main/java/com/yaohun/enderdragonWars/util/GameUtil.java b/src/main/java/com/yaohun/enderdragonWars/util/GameUtil.java deleted file mode 100644 index 819fb16..0000000 --- a/src/main/java/com/yaohun/enderdragonWars/util/GameUtil.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.yaohun.enderdragonWars.util; - - -import org.bukkit.*; -import org.bukkit.block.Block; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Pig; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; - -public class GameUtil { - - public static String HideName(String audience){ - if(audience.length() <= 2){ - return "**"; - } - // 获取第一个和第二个字符 - char firstChar = audience.charAt(0); - char lastChar = audience.charAt(audience.length() - 1); - // 构建屏蔽后的字符串 - StringBuilder maskedString = new StringBuilder(); - for (int i = 1; i < audience.length() - 1; i++) { - maskedString.append('*'); - } - return String.valueOf(firstChar) + maskedString + lastChar; - } - - public static void SendAllSounds(String sound){ - for (Player player : Bukkit.getOnlinePlayers()) { - if (!sound.contains("_")) { - player.playSound(player.getLocation(), sound, 0.5F, 1); - } - } - } -} diff --git a/src/main/java/com/yaohun/enderdragonWars/util/GiftUtil.java b/src/main/java/com/yaohun/enderdragonWars/util/GiftUtil.java deleted file mode 100644 index b3a3919..0000000 --- a/src/main/java/com/yaohun/enderdragonWars/util/GiftUtil.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.yaohun.enderdragonWars.util; - -import com.yaohun.enderdragonWars.Main; -import com.yaohun.enderdragonWars.data.GiftData; -import com.yaohun.enderdragonWars.liveevent.GiftEventHandler; -import com.yaohun.enderdragonWars.manage.GameManage; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -public class GiftUtil { - - // 执行礼物效果 - public static void executeGiftEffect(Player zhubo,String userName,String giftName,int giftAmount){ - GameManage gameManage = Main.gameManage; - if(gameManage.getGiftData(giftName) == null){ - zhubo.sendMessage("§c[系统]§a礼物 "+giftName+" 的未设置任何礼物效果."); - return; - } - // 获取礼物数据 - GiftData giftData = gameManage.getGiftData(giftName); - // 获取隐藏名字后的观众名 - String hide_name = GameUtil.HideName(userName); - // 获取效果名 - String eventName = giftData.getEvent(); - if(giftAmount <= 1){ - giftData.OutPlaySoundsEvent(); - GiftEventHandler.SendHandLer(zhubo, userName, eventName); - }else{ - long dadey = 5L; - for (int i = 0; i < giftAmount; i++) { - Bukkit.getScheduler().runTaskLater(Main.plugin, () -> { - giftData.OutPlaySoundsEvent(); - GiftEventHandler.SendHandLer(zhubo, userName, eventName); - }, (long) i * dadey); - } - } - } -} diff --git a/src/main/java/com/yaohun/enderdragonWars/util/RandomUtil.java b/src/main/java/com/yaohun/enderdragonWars/util/RandomUtil.java deleted file mode 100644 index 3e189db..0000000 --- a/src/main/java/com/yaohun/enderdragonWars/util/RandomUtil.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.yaohun.enderdragonWars.util; - -import org.bukkit.Location; -import org.bukkit.World; - -import javax.swing.plaf.synth.Region; -import java.awt.*; -import java.util.Random; - -public class RandomUtil { - - public static boolean random(double d) { - return d >= new Random().nextFloat(); - } - - public static int getRandomInt(int min, int max) { - if (min == max) { - return max; - } - Random r = new Random(); - int i = min < max ? min : max; - int a = min < max ? max : min; - return r.nextInt(a - i + 1) + i; - } - - public static double getRandomDouble(double min, double max, int scl) { - int pow = (int) Math.pow(10, scl); - return Math.floor((Math.random() * (max - min) + min) * pow) / pow; - } - -} diff --git a/src/main/java/com/yaohun/enderdragonwars/Main.java b/src/main/java/com/yaohun/enderdragonwars/Main.java index a4933b1..0aa6f7d 100644 --- a/src/main/java/com/yaohun/enderdragonwars/Main.java +++ b/src/main/java/com/yaohun/enderdragonwars/Main.java @@ -2,6 +2,7 @@ package com.yaohun.enderdragonwars; import com.yaohun.enderdragonwars.effect.types.*; import com.yaohun.enderdragonwars.game.Game; +import com.yaohun.enderdragonwars.listener.GameListener; import com.yaohun.enderdragonwars.listener.PlayerListener; import com.yaohun.enderdragonwars.manager.GameManager; import com.yaohun.enderdragonwars.manager.GiftEffectManager; @@ -26,10 +27,16 @@ public class Main extends JavaPlugin { game = new Game(); Bukkit.getPluginManager().registerEvents(new PlayerListener(), this); + Bukkit.getPluginManager().registerEvents(new GameListener(), this); } @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + public boolean onCommand(CommandSender sender, Command command, String Command, String[] args) { + if(args.length == 1 && args[0].equalsIgnoreCase("start")){ + Player player = (Player) sender; + game.startGame(player); + return true; + } if (args.length == 1) { String subCommand = args[0]; Player player = (Player) sender; diff --git a/src/main/java/com/yaohun/enderdragonWars/data/DirectionPoint.java b/src/main/java/com/yaohun/enderdragonwars/data/DirectionPoint.java similarity index 100% rename from src/main/java/com/yaohun/enderdragonWars/data/DirectionPoint.java rename to src/main/java/com/yaohun/enderdragonwars/data/DirectionPoint.java diff --git a/src/main/java/com/yaohun/enderdragonWars/data/Point.java b/src/main/java/com/yaohun/enderdragonwars/data/Point.java similarity index 100% rename from src/main/java/com/yaohun/enderdragonWars/data/Point.java rename to src/main/java/com/yaohun/enderdragonwars/data/Point.java diff --git a/src/main/java/com/yaohun/enderdragonWars/data/Region.java b/src/main/java/com/yaohun/enderdragonwars/data/Region.java similarity index 100% rename from src/main/java/com/yaohun/enderdragonWars/data/Region.java rename to src/main/java/com/yaohun/enderdragonwars/data/Region.java diff --git a/src/main/java/com/yaohun/enderdragonWars/effect/types/AddMaxHealthEffect.java b/src/main/java/com/yaohun/enderdragonwars/effect/types/AddMaxHealthEffect.java similarity index 100% rename from src/main/java/com/yaohun/enderdragonWars/effect/types/AddMaxHealthEffect.java rename to src/main/java/com/yaohun/enderdragonwars/effect/types/AddMaxHealthEffect.java diff --git a/src/main/java/com/yaohun/enderdragonWars/effect/types/BlackHoleEffect.java b/src/main/java/com/yaohun/enderdragonwars/effect/types/BlackHoleEffect.java similarity index 100% rename from src/main/java/com/yaohun/enderdragonWars/effect/types/BlackHoleEffect.java rename to src/main/java/com/yaohun/enderdragonwars/effect/types/BlackHoleEffect.java diff --git a/src/main/java/com/yaohun/enderdragonWars/effect/types/BomBomEffect.java b/src/main/java/com/yaohun/enderdragonwars/effect/types/BomBomEffect.java similarity index 99% rename from src/main/java/com/yaohun/enderdragonWars/effect/types/BomBomEffect.java rename to src/main/java/com/yaohun/enderdragonwars/effect/types/BomBomEffect.java index 0d01368..9cb012f 100644 --- a/src/main/java/com/yaohun/enderdragonWars/effect/types/BomBomEffect.java +++ b/src/main/java/com/yaohun/enderdragonwars/effect/types/BomBomEffect.java @@ -1,6 +1,7 @@ package com.yaohun.enderdragonwars.effect.types; import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.world.entity.EntityType; import com.yaohun.enderdragonwars.Main; import com.yaohun.enderdragonwars.effect.GiftEffect; import com.yaohun.enderdragonwars.game.Game; diff --git a/src/main/java/com/yaohun/enderdragonWars/effect/types/ClearInventoryEffect.java b/src/main/java/com/yaohun/enderdragonwars/effect/types/ClearInventoryEffect.java similarity index 100% rename from src/main/java/com/yaohun/enderdragonWars/effect/types/ClearInventoryEffect.java rename to src/main/java/com/yaohun/enderdragonwars/effect/types/ClearInventoryEffect.java diff --git a/src/main/java/com/yaohun/enderdragonWars/effect/types/FiveLightningEffect.java b/src/main/java/com/yaohun/enderdragonwars/effect/types/FiveLightningEffect.java similarity index 100% rename from src/main/java/com/yaohun/enderdragonWars/effect/types/FiveLightningEffect.java rename to src/main/java/com/yaohun/enderdragonwars/effect/types/FiveLightningEffect.java diff --git a/src/main/java/com/yaohun/enderdragonWars/effect/types/GiveTotemEffect.java b/src/main/java/com/yaohun/enderdragonwars/effect/types/GiveTotemEffect.java similarity index 100% rename from src/main/java/com/yaohun/enderdragonWars/effect/types/GiveTotemEffect.java rename to src/main/java/com/yaohun/enderdragonwars/effect/types/GiveTotemEffect.java diff --git a/src/main/java/com/yaohun/enderdragonWars/effect/types/LavaPoolEffect.java b/src/main/java/com/yaohun/enderdragonwars/effect/types/LavaPoolEffect.java similarity index 100% rename from src/main/java/com/yaohun/enderdragonWars/effect/types/LavaPoolEffect.java rename to src/main/java/com/yaohun/enderdragonwars/effect/types/LavaPoolEffect.java diff --git a/src/main/java/com/yaohun/enderdragonWars/effect/types/LuckyBlockEffect.java b/src/main/java/com/yaohun/enderdragonwars/effect/types/LuckyBlockEffect.java similarity index 100% rename from src/main/java/com/yaohun/enderdragonWars/effect/types/LuckyBlockEffect.java rename to src/main/java/com/yaohun/enderdragonwars/effect/types/LuckyBlockEffect.java diff --git a/src/main/java/com/yaohun/enderdragonWars/effect/types/PlayerBigEffect.java b/src/main/java/com/yaohun/enderdragonwars/effect/types/PlayerBigEffect.java similarity index 100% rename from src/main/java/com/yaohun/enderdragonWars/effect/types/PlayerBigEffect.java rename to src/main/java/com/yaohun/enderdragonwars/effect/types/PlayerBigEffect.java diff --git a/src/main/java/com/yaohun/enderdragonWars/effect/types/PlayerResetEffect.java b/src/main/java/com/yaohun/enderdragonwars/effect/types/PlayerResetEffect.java similarity index 100% rename from src/main/java/com/yaohun/enderdragonWars/effect/types/PlayerResetEffect.java rename to src/main/java/com/yaohun/enderdragonwars/effect/types/PlayerResetEffect.java diff --git a/src/main/java/com/yaohun/enderdragonWars/effect/types/PlayerSmallEffect.java b/src/main/java/com/yaohun/enderdragonwars/effect/types/PlayerSmallEffect.java similarity index 100% rename from src/main/java/com/yaohun/enderdragonWars/effect/types/PlayerSmallEffect.java rename to src/main/java/com/yaohun/enderdragonwars/effect/types/PlayerSmallEffect.java diff --git a/src/main/java/com/yaohun/enderdragonWars/effect/types/SpawnBuildEffect.java b/src/main/java/com/yaohun/enderdragonwars/effect/types/SpawnBuildEffect.java similarity index 100% rename from src/main/java/com/yaohun/enderdragonWars/effect/types/SpawnBuildEffect.java rename to src/main/java/com/yaohun/enderdragonwars/effect/types/SpawnBuildEffect.java diff --git a/src/main/java/com/yaohun/enderdragonWars/effect/types/SpawnEnderPortalEffect.java b/src/main/java/com/yaohun/enderdragonwars/effect/types/SpawnEnderPortalEffect.java similarity index 100% rename from src/main/java/com/yaohun/enderdragonWars/effect/types/SpawnEnderPortalEffect.java rename to src/main/java/com/yaohun/enderdragonwars/effect/types/SpawnEnderPortalEffect.java diff --git a/src/main/java/com/yaohun/enderdragonWars/effect/types/SummonIronGolem.java b/src/main/java/com/yaohun/enderdragonwars/effect/types/SummonIronGolem.java similarity index 100% rename from src/main/java/com/yaohun/enderdragonWars/effect/types/SummonIronGolem.java rename to src/main/java/com/yaohun/enderdragonwars/effect/types/SummonIronGolem.java diff --git a/src/main/java/com/yaohun/enderdragonWars/effect/types/TakeMaxHealthEffect.java b/src/main/java/com/yaohun/enderdragonwars/effect/types/TakeMaxHealthEffect.java similarity index 100% rename from src/main/java/com/yaohun/enderdragonWars/effect/types/TakeMaxHealthEffect.java rename to src/main/java/com/yaohun/enderdragonwars/effect/types/TakeMaxHealthEffect.java diff --git a/src/main/java/com/yaohun/enderdragonWars/effect/types/ToHeavenEffect.java b/src/main/java/com/yaohun/enderdragonwars/effect/types/ToHeavenEffect.java similarity index 100% rename from src/main/java/com/yaohun/enderdragonWars/effect/types/ToHeavenEffect.java rename to src/main/java/com/yaohun/enderdragonwars/effect/types/ToHeavenEffect.java diff --git a/src/main/java/com/yaohun/enderdragonWars/effect/types/WorldDestroyEffect.java b/src/main/java/com/yaohun/enderdragonwars/effect/types/WorldDestroyEffect.java similarity index 100% rename from src/main/java/com/yaohun/enderdragonWars/effect/types/WorldDestroyEffect.java rename to src/main/java/com/yaohun/enderdragonwars/effect/types/WorldDestroyEffect.java diff --git a/src/main/java/com/yaohun/enderdragonwars/game/Game.java b/src/main/java/com/yaohun/enderdragonwars/game/Game.java index 570cb68..b712fd6 100644 --- a/src/main/java/com/yaohun/enderdragonwars/game/Game.java +++ b/src/main/java/com/yaohun/enderdragonwars/game/Game.java @@ -1,26 +1,96 @@ package com.yaohun.enderdragonwars.game; +import com.yaohun.enderdragonwars.Main; +import com.yaohun.enderdragonwars.util.BossBarUtil; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; import org.bukkit.World; +import org.bukkit.boss.BarColor; +import org.bukkit.boss.BarStyle; +import org.bukkit.boss.BossBar; import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Random; public class Game { private Player player; private World world; + private BossBar bossBar1; + private BossBar bossBar2; private boolean startd; + private long liveTime; + private List tasks = new ArrayList<>(); + public Game(){ + bossBar1 = Bukkit.createBossBar("下播时间", BarColor.WHITE, BarStyle.SEGMENTED_20); + bossBar2 = Bukkit.createBossBar("挑战目标", BarColor.WHITE, BarStyle.SOLID); + } - private int remainTime; + public void updateBossBar() { + // 击败末影龙提示 + targetCueBossBar(); + // 获取最大时间 + long maxLiveTime = 1000 * 60 * 60 * 6; + double d = (double) getLiveTime() / (double)maxLiveTime; + d = Math.max(0, Math.min(d, 1)); + long liveTimeInSeconds = getLiveTime() / 1000; + long hours = liveTimeInSeconds / 3600; + long minutes = (liveTimeInSeconds % 3600) / 60; + long seconds = liveTimeInSeconds % 60; + if (hours >= 1) { + bossBar1.setTitle("§6§l距离下播还有§f§l: §a" + hours + "小时" + minutes + "分" + seconds + "秒"); + } else if (minutes >= 1) { + bossBar1.setTitle("§6§l距离下播还有§f§l: §a" + minutes + "分" + seconds + "秒"); + } else if (seconds >= 1) { + bossBar1.setTitle("§6§l距离下播还有§f§l: §a" + seconds + "秒"); + } else { + bossBar1.setTitle("§a§l恭喜您完成挑战!下播吧!"); + } + BossBarUtil.setBarProgress(bossBar1,d); + BossBarUtil.setBarColor(bossBar1,d); + } - public Game() { + private int tragetCueI = 0; + public void targetCueBossBar(){ + tragetCueI--; + if(tragetCueI <= 0) { + bossBar2.addPlayer(player); + List stringList = new ArrayList<>(); + stringList.add("§c§l击败末影龙 §b§l减播1小时!"); + Collections.shuffle(stringList); + Random random = new Random(); + String titleShow = stringList.get(random.nextInt(stringList.size())); + bossBar2.setTitle(titleShow); + BossBarUtil.setBarColor(bossBar2); + tragetCueI = 20; + }else{ + if(tragetCueI == 16) { + if (bossBar2.getPlayers().contains(player)) { + bossBar2.removePlayer(player); + } + } + } } public void startGame(Player player) { - if (startd) { - return; - } + if(startd){return;} this.player = player; - this.world = player.getWorld(); this.startd = true; + this.liveTime = 1000 * 60 * 60 * 3; // 默认下播时间 60秒x60分钟x2小时 + // 添加boss血条 + updataPlayerData(player); + tasks.add(new BukkitRunnable() { + @Override + public void run() { + liveTime = liveTime - 500; + updateBossBar(); + } + }.runTaskTimer(Main.plugin, 0L, 10L)); } public Player getPlayer() { @@ -30,9 +100,47 @@ public class Game { public World getWorld() { return world; } + public void updataPlayerData(Player player){ + player.setFoodLevel(20); + player.setGameMode(GameMode.SURVIVAL); + bossBar1.addPlayer(player); + bossBar2.addPlayer(player); + } - public int getRemainTime() { - return remainTime; + public void removePlayerDataBossBar(){ + bossBar1.removeAll(); + bossBar2.removeAll(); + bossBar1 = Bukkit.createBossBar("下播时间", BarColor.WHITE, BarStyle.SEGMENTED_20); + bossBar2 = Bukkit.createBossBar("挑战目标", BarColor.WHITE, BarStyle.SOLID); + } + + public boolean isStartd() { + return startd; + } + + public long getLiveTime() { + return liveTime; + } + public void setLiveTime(long liveTime) { + this.liveTime = liveTime; + } + + public void takeLiveTime(long minutes){ + long minutesTime = 1000 * 60 * minutes; + long newTime = getLiveTime() - minutesTime; + if(newTime < 0){ + newTime = 0; + } + setLiveTime(newTime); + } + + public void addLiveTime(long minutes){ + long minutesTime = 1000 * 60 * minutes; + long newTime = getLiveTime() + minutesTime; + if(newTime < 0){ + newTime = 0; + } + setLiveTime(newTime); } } diff --git a/src/main/java/com/yaohun/enderdragonwars/listener/GameListener.java b/src/main/java/com/yaohun/enderdragonwars/listener/GameListener.java new file mode 100644 index 0000000..840e151 --- /dev/null +++ b/src/main/java/com/yaohun/enderdragonwars/listener/GameListener.java @@ -0,0 +1,71 @@ +package com.yaohun.enderdragonwars.listener; + +import com.yaohun.enderdragonwars.Main; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerKickEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.server.ServerListPingEvent; +import org.bukkit.scheduler.BukkitRunnable; + +public class GameListener implements Listener { + + @EventHandler + public void onPing(ServerListPingEvent e){ + e.setMotd("§a整蛊模式: §6生存挑战 §a当前版本: §6常规版 §b运行中"); + } + + @EventHandler + public void onJoinItems(PlayerJoinEvent e) { + Player p = e.getPlayer(); + new BukkitRunnable() { + public void run() { + if (!Main.game.isStartd()) { + p.performCommand("game start"); + } + Main.game.updataPlayerData(p); + cancel(); + } + }.runTaskLater(Main.plugin, 20L); + } + + @EventHandler + public void onQuit(PlayerQuitEvent e){ + Player p = e.getPlayer(); + Main.game.removePlayerDataBossBar(); + } + + @EventHandler + public void onKick(PlayerKickEvent e){ + Player p = e.getPlayer(); + Main.game.removePlayerDataBossBar( ); + } + + /* + * 死亡后游戏时间 +5分钟 + * */ + @EventHandler + public void onDeath(PlayerDeathEvent e){ + e.setDeathMessage(null); + Player p = e.getEntity(); + new BukkitRunnable() { + private int i = 0; + public void run() { + if (i == 1) { + p.spigot().respawn(); + } + // 增加游戏时间5分钟 + if(i == 3) { + Main.game.addLiveTime(5); + p.sendTitle("§4你嘎了", "§e加播5分钟!"); + cancel(); + } + i++; + } + }.runTaskTimer(Main.plugin,0L, 2L); + } + +} diff --git a/src/main/java/com/yaohun/enderdragonWars/listener/PlayerListener.java b/src/main/java/com/yaohun/enderdragonwars/listener/PlayerListener.java similarity index 100% rename from src/main/java/com/yaohun/enderdragonWars/listener/PlayerListener.java rename to src/main/java/com/yaohun/enderdragonwars/listener/PlayerListener.java diff --git a/src/main/java/com/yaohun/enderdragonWars/manager/GameManager.java b/src/main/java/com/yaohun/enderdragonwars/manager/GameManager.java similarity index 100% rename from src/main/java/com/yaohun/enderdragonWars/manager/GameManager.java rename to src/main/java/com/yaohun/enderdragonwars/manager/GameManager.java diff --git a/src/main/java/com/yaohun/enderdragonWars/manager/GiftEffectManager.java b/src/main/java/com/yaohun/enderdragonwars/manager/GiftEffectManager.java similarity index 100% rename from src/main/java/com/yaohun/enderdragonWars/manager/GiftEffectManager.java rename to src/main/java/com/yaohun/enderdragonwars/manager/GiftEffectManager.java diff --git a/src/main/java/com/yaohun/enderdragonwars/util/BossBarUtil.java b/src/main/java/com/yaohun/enderdragonwars/util/BossBarUtil.java new file mode 100644 index 0000000..a162463 --- /dev/null +++ b/src/main/java/com/yaohun/enderdragonwars/util/BossBarUtil.java @@ -0,0 +1,55 @@ +package com.yaohun.enderdragonwars.util; + +import org.bukkit.boss.BarColor; +import org.bukkit.boss.BossBar; +import org.bukkit.entity.Player; + +import java.util.List; + +public class BossBarUtil { + + public static void setBarColor(BossBar bossBar){ + double random = RandomUtil.getRandomDouble(0,1,1); + if (random >= 0 && random <= 0.2) { + bossBar.setColor(BarColor.RED); + } else if (random <= 0.4) { + bossBar.setColor(BarColor.YELLOW); + } else if (random <= 0.6) { + bossBar.setColor(BarColor.GREEN); + } else if (random <= 0.8) { + bossBar.setColor(BarColor.BLUE); + } else { + bossBar.setColor(BarColor.PURPLE); + } + } + + public static void setBarColor(BossBar bossBar,double percent){ + if (percent >= 0 && percent <= 0.3333) { + bossBar.setColor(BarColor.RED); + } else if (percent <= 0.6666) { + bossBar.setColor(BarColor.YELLOW); + } else { + bossBar.setColor(BarColor.GREEN); + } + } + public static void setBarProgress(BossBar bossBar,double percent){ + if (percent <= 0) { + percent = 0; + } else if (percent >= 1) { + percent = 1; + } + bossBar.setProgress(percent); + } + + public static void addBossBar(Player player, List bossBarList){ + for (BossBar bossBar : bossBarList) { + bossBar.addPlayer(player); + } + } + + public static void removeBossBar(Player player,List bossBarList){ + for (BossBar bossBar : bossBarList) { + bossBar.removePlayer(player); + } + } +} diff --git a/src/main/java/com/yaohun/enderdragonWars/util/BuildSpawner.java b/src/main/java/com/yaohun/enderdragonwars/util/BuildSpawner.java similarity index 100% rename from src/main/java/com/yaohun/enderdragonWars/util/BuildSpawner.java rename to src/main/java/com/yaohun/enderdragonwars/util/BuildSpawner.java diff --git a/src/main/java/com/yaohun/enderdragonWars/util/EntityUtil.java b/src/main/java/com/yaohun/enderdragonwars/util/EntityUtil.java similarity index 100% rename from src/main/java/com/yaohun/enderdragonWars/util/EntityUtil.java rename to src/main/java/com/yaohun/enderdragonwars/util/EntityUtil.java diff --git a/src/main/java/com/yaohun/enderdragonWars/util/ItemStackBuilder.java b/src/main/java/com/yaohun/enderdragonwars/util/ItemStackBuilder.java similarity index 100% rename from src/main/java/com/yaohun/enderdragonWars/util/ItemStackBuilder.java rename to src/main/java/com/yaohun/enderdragonwars/util/ItemStackBuilder.java diff --git a/src/main/java/com/yaohun/enderdragonWars/util/WEUtil.java b/src/main/java/com/yaohun/enderdragonwars/util/WEUtil.java similarity index 100% rename from src/main/java/com/yaohun/enderdragonWars/util/WEUtil.java rename to src/main/java/com/yaohun/enderdragonwars/util/WEUtil.java