From e20a708e89c2ba1f583233897b6c4ba703d8fac3 Mon Sep 17 00:00:00 2001 From: YuTian <2953516620@qq.com> Date: Sat, 10 Aug 2024 18:46:13 +0800 Subject: [PATCH] 1.0 --- .../io/yutian/thewardungeon/TheWarDungeon.java | 4 +--- .../yutian/thewardungeon/dungeon/Dungeon.java | 14 ++++++++++++-- .../thewardungeon/dungeon/DungeonInstance.java | 17 +++++++++++++++++ .../dungeon/world/WorldInstance.java | 5 ++--- .../io/yutian/thewardungeon/event/Event.java | 7 ------- .../thewardungeon/script/list/TitleScript.java | 2 +- .../yutian/thewardungeon/util/BossBarUtil.java | 17 +++++++++++++++++ 7 files changed, 50 insertions(+), 16 deletions(-) delete mode 100644 src/main/java/com/io/yutian/thewardungeon/event/Event.java create mode 100644 src/main/java/com/io/yutian/thewardungeon/util/BossBarUtil.java diff --git a/src/main/java/com/io/yutian/thewardungeon/TheWarDungeon.java b/src/main/java/com/io/yutian/thewardungeon/TheWarDungeon.java index 45c1ce8..d2e91c0 100644 --- a/src/main/java/com/io/yutian/thewardungeon/TheWarDungeon.java +++ b/src/main/java/com/io/yutian/thewardungeon/TheWarDungeon.java @@ -52,15 +52,13 @@ public final class TheWarDungeon extends JavaPlugin { CommandManager.unregisterAll(); - /* for (Dungeon dungeon : DungeonManager.getDungeons()) { for (DungeonInstance dungeonInstance : dungeon.getQueue().getAllDungeonInstance()) { dungeonInstance.getWorldInstance().remove(); } } - */ - checkWorldFile(); + //checkWorldFile(); } diff --git a/src/main/java/com/io/yutian/thewardungeon/dungeon/Dungeon.java b/src/main/java/com/io/yutian/thewardungeon/dungeon/Dungeon.java index c223785..6b9107d 100644 --- a/src/main/java/com/io/yutian/thewardungeon/dungeon/Dungeon.java +++ b/src/main/java/com/io/yutian/thewardungeon/dungeon/Dungeon.java @@ -6,6 +6,7 @@ import com.io.yutian.thewardungeon.dungeon.queue.DungeonQueue; import com.io.yutian.thewardungeon.dungeon.world.WorldInstance; import com.io.yutian.thewardungeon.util.Log; import com.io.yutian.thewarskyblocklib.util.FileUtil; +import org.bukkit.GameRule; import org.bukkit.World; import org.bukkit.WorldCreator; import org.jetbrains.annotations.Nullable; @@ -87,8 +88,7 @@ public class Dungeon { WorldCreator dungeonWorldCreator = new WorldCreator(worldName); try { world = dungeonWorldCreator.createWorld(); - world.setKeepSpawnInMemory(false); - world.setAutoSave(false); + initWorld(world); } catch (Exception e) { e.printStackTrace(); return null; @@ -98,6 +98,16 @@ public class Dungeon { return worldInstance; } + private void initWorld(World world) { + world.setGameRule(GameRule.KEEP_INVENTORY, true); + world.setGameRule(GameRule.MOB_GRIEFING, false); + world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false); + world.setGameRule(GameRule.DO_WEATHER_CYCLE, false); + world.setGameRule(GameRule.DO_MOB_SPAWNING, false); + world.setKeepSpawnInMemory(false); + world.setAutoSave(false); + } + @Nullable public DungeonInstance newInstance() { if (!hasFreeInstance()) { diff --git a/src/main/java/com/io/yutian/thewardungeon/dungeon/DungeonInstance.java b/src/main/java/com/io/yutian/thewardungeon/dungeon/DungeonInstance.java index 55116fb..ded99b4 100644 --- a/src/main/java/com/io/yutian/thewardungeon/dungeon/DungeonInstance.java +++ b/src/main/java/com/io/yutian/thewardungeon/dungeon/DungeonInstance.java @@ -12,6 +12,7 @@ import com.io.yutian.thewardungeon.dungeon.world.WorldInstance; import com.io.yutian.thewardungeon.lang.Lang; import com.io.yutian.thewardungeon.manager.DungeonManager; import com.io.yutian.thewardungeon.script.ScriptGourp; +import com.io.yutian.thewardungeon.util.BossBarUtil; import com.io.yutian.thewardungeon.util.LogUtil; import com.io.yutian.thewarskyblocklib.math.Point; import io.lumine.mythic.bukkit.BukkitAdapter; @@ -21,6 +22,9 @@ import io.lumine.mythic.core.mobs.MobRegistry; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; +import org.bukkit.boss.BarColor; +import org.bukkit.boss.BarStyle; +import org.bukkit.boss.BossBar; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; @@ -38,6 +42,8 @@ public class DungeonInstance { private DungeonState state = DungeonState.WAITING; + private BossBar bossBar; + private DungeonLobby dungeonLobby; private Point spawnPoint; @@ -60,12 +66,14 @@ public class DungeonInstance { this.uuid = uuid; this.dungeon = dungeon; this.worldInstance = worldInstance; + this.bossBar = Bukkit.createBossBar("倒计时", BarColor.WHITE, BarStyle.SOLID); } public void join(Player player, boolean start) { if (!canJoin(player)) { return; } + this.bossBar.addPlayer(player); addPlayer(player); if (start && players.size() == 1) { player.teleport(dungeon.getConfig().getLobbyPoint().toLocation(worldInstance.getWorld())); @@ -93,6 +101,7 @@ public class DungeonInstance { } public void leave(Player player) { + this.bossBar.removePlayer(player); if (dungeonLobby != null && state.equals(DungeonState.WAITING)) { dungeonLobby.removeBossBar(player); } @@ -256,6 +265,7 @@ public class DungeonInstance { cancel(); } } + updateBossBar(); } }.runTaskTimer(TheWarDungeon.inst(), 20L, 20L)); tasks.add(new BukkitRunnable() { @@ -293,6 +303,13 @@ public class DungeonInstance { } } + private void updateBossBar() { + bossBar.setTitle("倒计时: " + countdown + "/" + dungeon.getConfig().getOption().getCountdown()); + float progress = (float) countdown / (float) dungeon.getConfig().getOption().getCountdown(); + bossBar.setProgress(progress); + bossBar.setColor(BossBarUtil.getBarColor(progress)); + } + private boolean isWorldLoaded() { try { BukkitAdapter.adapt(worldInstance.getWorld()); diff --git a/src/main/java/com/io/yutian/thewardungeon/dungeon/world/WorldInstance.java b/src/main/java/com/io/yutian/thewardungeon/dungeon/world/WorldInstance.java index fb862f7..255a6a0 100644 --- a/src/main/java/com/io/yutian/thewardungeon/dungeon/world/WorldInstance.java +++ b/src/main/java/com/io/yutian/thewardungeon/dungeon/world/WorldInstance.java @@ -1,12 +1,9 @@ package com.io.yutian.thewardungeon.dungeon.world; -import com.io.yutian.thewardungeon.TheWarDungeon; -import org.apache.commons.io.FileUtils; import org.bukkit.Bukkit; import org.bukkit.World; import java.io.File; -import java.io.IOException; import java.util.UUID; public class WorldInstance { @@ -52,6 +49,7 @@ public class WorldInstance { } destroyed = true; unloadWorld(); + /* Bukkit.getScheduler().runTaskLater(TheWarDungeon.inst(), ()->{ try { FileUtils.deleteDirectory(folder); @@ -59,6 +57,7 @@ public class WorldInstance { e.printStackTrace(); } }, 10L); + */ } private void unloadWorld() { diff --git a/src/main/java/com/io/yutian/thewardungeon/event/Event.java b/src/main/java/com/io/yutian/thewardungeon/event/Event.java deleted file mode 100644 index 688f454..0000000 --- a/src/main/java/com/io/yutian/thewardungeon/event/Event.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.io.yutian.thewardungeon.event; - -public class Event { - - - -} diff --git a/src/main/java/com/io/yutian/thewardungeon/script/list/TitleScript.java b/src/main/java/com/io/yutian/thewardungeon/script/list/TitleScript.java index c6d2a1e..a25611f 100644 --- a/src/main/java/com/io/yutian/thewardungeon/script/list/TitleScript.java +++ b/src/main/java/com/io/yutian/thewardungeon/script/list/TitleScript.java @@ -27,7 +27,7 @@ public class TitleScript extends Script { @Override public void execute(DungeonInstance dungeonInstance) { - dungeonInstance.getPlayers().forEach(player -> player.getPlayer().showTitle(Title.title(Component.text(title), Component.text(subtitle), Title.Times.times(Duration.ofMillis(fadeIn), Duration.ofMillis(stay), Duration.ofMillis(fadeOut))))); + dungeonInstance.getPlayers().forEach(player -> player.getPlayer().showTitle(Title.title(Component.text(title), Component.text(subtitle), Title.Times.times(Duration.ofMillis(fadeIn * 50), Duration.ofMillis(stay * 50), Duration.ofMillis(fadeOut * 50))))); } } diff --git a/src/main/java/com/io/yutian/thewardungeon/util/BossBarUtil.java b/src/main/java/com/io/yutian/thewardungeon/util/BossBarUtil.java new file mode 100644 index 0000000..f602762 --- /dev/null +++ b/src/main/java/com/io/yutian/thewardungeon/util/BossBarUtil.java @@ -0,0 +1,17 @@ +package com.io.yutian.thewardungeon.util; + +import org.bukkit.boss.BarColor; + +public class BossBarUtil { + + public static BarColor getBarColor(double d) { + if (d >= 0 && d <= 0.3333) { + return BarColor.RED; + } else if (d <= 0.6666) { + return BarColor.YELLOW; + } else { + return BarColor.GREEN; + } + } + +}