From e79c4ad1c5dbbc3717fbb7ab1c5fcb7e2d538409 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Wed, 18 May 2022 21:45:38 -0400 Subject: [PATCH] 1.5.0 Release Canidate 2 (Previously 1.4.3) --- pom.xml | 4 +- .../net/tylermurphy/hideAndSeek/Main.java | 43 +++++++++++++------ .../hideAndSeek/command/About.java | 2 +- .../configuration/ConfigManager.java | 23 +++++++--- .../tylermurphy/hideAndSeek/game/Board.java | 8 ++-- .../tylermurphy/hideAndSeek/game/Game.java | 2 +- .../game/listener/DamageHandler.java | 4 +- .../hideAndSeek/world/WorldLoader.java | 2 + src/main/resources/plugin.yml | 4 +- 9 files changed, 61 insertions(+), 31 deletions(-) diff --git a/pom.xml b/pom.xml index 42cd0f7..7e1be5a 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ 4.0.0 net.tylermurphy - HideAndSeek - 1.4.3 + KenshinsHideAndSeek + 1.5.0 Hide and Seek Plugin UTF-8 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index 7bd86cb..1248551 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -24,6 +24,7 @@ import net.tylermurphy.hideAndSeek.configuration.Items; import net.tylermurphy.hideAndSeek.configuration.Localization; import net.tylermurphy.hideAndSeek.database.Database; import net.tylermurphy.hideAndSeek.game.Board; +import net.tylermurphy.hideAndSeek.game.PlayerLoader; import net.tylermurphy.hideAndSeek.game.util.Status; import net.tylermurphy.hideAndSeek.util.CommandHandler; import net.tylermurphy.hideAndSeek.game.Game; @@ -31,6 +32,7 @@ import net.tylermurphy.hideAndSeek.game.listener.*; import net.tylermurphy.hideAndSeek.util.PAPIExpansion; import net.tylermurphy.hideAndSeek.util.TabCompleter; import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.event.Listener; @@ -44,6 +46,9 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static net.tylermurphy.hideAndSeek.configuration.Config.exitPosition; +import static net.tylermurphy.hideAndSeek.configuration.Config.exitWorld; + public class Main extends JavaPlugin implements Listener { private static Main instance; @@ -56,11 +61,7 @@ public class Main extends JavaPlugin implements Listener { public Main() { super(); - instance = this; - - Config.loadConfig(); - Localization.loadLocalization(); - Items.loadItems(); + onConstructed(); board = new Board(); database = new Database(); @@ -68,15 +69,27 @@ public class Main extends JavaPlugin implements Listener { protected Main(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) { super(loader, description, dataFolder, file); + onConstructed(); + + board = new Board(); + database = new Database(); + } + + private void onConstructed(){ instance = this; + Matcher matcher = Pattern.compile("MC: \\d\\.(\\d+)").matcher(Bukkit.getVersion()); + if (matcher.find()) { + version = Integer.parseInt(matcher.group(1)); + } else { + throw new IllegalArgumentException("Failed to parse server version from: " + Bukkit.getVersion()); + } + Config.loadConfig(); Localization.loadLocalization(); Items.loadItems(); - board = new Board(); - database = new Database(); } public void onEnable() { @@ -94,16 +107,18 @@ public class Main extends JavaPlugin implements Listener { if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) { new PAPIExpansion().register(); } - - Matcher matcher = Pattern.compile("MC: \\d\\.(\\d+)").matcher(Bukkit.getVersion()); - if (matcher.find()) { - version = Integer.parseInt(matcher.group(1)); - } else { - throw new IllegalArgumentException("Failed to parse server version from: " + Bukkit.getVersion()); - } } public void onDisable() { + + version = 0; + + board.getPlayers().forEach(player -> { + board.removeBoard(player); + PlayerLoader.unloadPlayer(player); + player.teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); + }); + Bukkit.getServer().getMessenger().unregisterOutgoingPluginChannel(this); board.cleanup(); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java index f996519..bda6016 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java @@ -26,7 +26,7 @@ public class About implements ICommand { public void execute(Player sender, String[] args) { sender.sendMessage( - String.format("%s%sHide and Seek %s(%s1.4.3%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + + String.format("%s%sHide and Seek %s(%s1.5.0%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) + String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE) ); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java index 381a41c..5e28258 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -46,12 +46,25 @@ public class ConfigManager { private ConfigManager(String filename, String defaultFilename) { - this.defaultFilename = defaultFilename; - this.file = new File(Main.getInstance().getDataFolder(), filename); + File dataFolder = Main.getInstance().getDataFolder(); + File oldDataFolder = new File(Main.getInstance().getDataFolder().getParent() + File.separator + "HideAndSeek"); - File folder = Main.getInstance().getDataFolder(); - if (!folder.exists()) { - if (!folder.mkdirs()) { + this.defaultFilename = defaultFilename; + this.file = new File(dataFolder, filename); + + if(oldDataFolder.exists()){ + if(!dataFolder.exists()){ + if(!oldDataFolder.renameTo(dataFolder)){ + throw new RuntimeException("Could not rename folder: " + oldDataFolder.getPath()); + } + } else { + throw new RuntimeException("Plugin folders for HideAndSeek & KenshinsHideAndSeek both exists. There can only be one!"); + } + + } + + if (!dataFolder.exists()) { + if (!dataFolder.mkdirs()) { throw new RuntimeException("Failed to make directory: " + file.getPath()); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java index a8e41c7..bb1984e 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java @@ -79,11 +79,11 @@ public class Board { } public List getHiders() { - return Hider.stream().map(playerList::get).collect(Collectors.toList()); + return Hider.stream().filter(Objects::nonNull).map(playerList::get).collect(Collectors.toList()); } public List getSeekers() { - return Seeker.stream().map(playerList::get).collect(Collectors.toList()); + return Seeker.stream().filter(Objects::nonNull).map(playerList::get).collect(Collectors.toList()); } public Player getFirstSeeker() { @@ -91,11 +91,11 @@ public class Board { } public List getSpectators() { - return Spectator.stream().map(playerList::get).collect(Collectors.toList()); + return Spectator.stream().filter(Objects::nonNull).map(playerList::get).collect(Collectors.toList()); } public List getPlayers() { - return new ArrayList<>(playerList.values()); + return playerList.values().stream().filter(Objects::nonNull).collect(Collectors.toList()); } public Player getPlayer(UUID uuid) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java index cb3ad1f..34f3a46 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java @@ -121,11 +121,11 @@ public class Game { board.addSeeker(seeker); PlayerLoader.loadSeeker(seeker, getGameWorld()); board.getPlayers().forEach(player -> { - board.createGameBoard(player); if(board.isSeeker(player)) return; board.addHider(player); PlayerLoader.loadHider(player, getGameWorld()); }); + board.getPlayers().forEach(board::createGameBoard); worldBorder.resetWorldBorder(getGameWorld()); if (gameLength > 0) gameTimer = gameLength; status = Status.STARTING; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DamageHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DamageHandler.java index 3b90d39..086a48a 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DamageHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/DamageHandler.java @@ -69,9 +69,9 @@ public class DamageHandler implements Listener { // Spectators cannot take damage if (board.isSpectator(player)) { event.setCancelled(true); - if (Main.getInstance().supports(18) && player.getLocation().getY() < -64) { + if (Main.getInstance().supports(18) && player.getLocation().getBlockY() < -64) { player.teleport(new Location(Bukkit.getWorld(game.getGameWorld()), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ())); - } else if (player.getLocation().getY() < 0) { + } else if (!Main.getInstance().supports(18) && player.getLocation().getY() < 0) { player.teleport(new Location(Bukkit.getWorld(game.getGameWorld()), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ())); } return; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java index ebfedcd..1d4ff71 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java @@ -21,6 +21,7 @@ package net.tylermurphy.hideAndSeek.world; import net.tylermurphy.hideAndSeek.Main; import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.World; import org.bukkit.WorldCreator; @@ -55,6 +56,7 @@ public class WorldLoader { Main.getInstance().getLogger().warning(saveName + " already unloaded."); return; } + world.getPlayers().forEach(player -> player.teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ()))); if (Bukkit.getServer().unloadWorld(world, false)) { Main.getInstance().getLogger().info("Successfully unloaded " + saveName); }else{ diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 74c4855..c4224dc 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ -name: HideAndSeek +name: KenshinsHideAndSeek main: net.tylermurphy.hideAndSeek.Main -version: 1.4.3 +version: 1.5.0 author: KenshinEto load: STARTUP api-version: 1.13