From 27dc2bbf908f10c103759a82c37560d63683ebce Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Wed, 27 Oct 2021 19:57:44 -0400 Subject: [PATCH 01/10] 1.3.1 build 1 --- .../net/tylermurphy/hideAndSeek/Main.java | 8 ++ .../hideAndSeek/bukkit/CommandHandler.java | 1 + .../hideAndSeek/bukkit/EventListener.java | 10 ++ .../hideAndSeek/command/SaveMap.java | 68 +-------- .../hideAndSeek/command/SetBounds.java | 67 +++++++++ .../hideAndSeek/command/Setup.java | 6 +- .../hideAndSeek/command/Start.java | 7 +- .../tylermurphy/hideAndSeek/command/Stop.java | 2 +- .../hideAndSeek/configuration/Config.java | 16 ++- .../configuration/Localization.java | 30 +++- .../tylermurphy/hideAndSeek/util/Util.java | 19 --- .../hideAndSeek/world/VoidGenerator.java | 57 ++++++++ .../hideAndSeek/world/WorldLoader.java | 129 ++++++++++++++++++ src/main/resources/localization.yml | 7 +- 14 files changed, 330 insertions(+), 97 deletions(-) create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index 30d0233..1e78bc9 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -1,5 +1,7 @@ package net.tylermurphy.hideAndSeek; +import static net.tylermurphy.hideAndSeek.configuration.Config.spawnWorld; + import java.io.File; import java.util.HashMap; import java.util.List; @@ -24,6 +26,7 @@ import net.tylermurphy.hideAndSeek.events.Glow; import net.tylermurphy.hideAndSeek.events.Taunt; import net.tylermurphy.hideAndSeek.events.Worldborder; import net.tylermurphy.hideAndSeek.util.Board; +import net.tylermurphy.hideAndSeek.world.WorldLoader; public class Main extends JavaPlugin implements Listener { @@ -36,6 +39,8 @@ public class Main extends JavaPlugin implements Listener { public Board board; + public WorldLoader worldLoader; + public Map playerList = new HashMap(); public String status = "Standby"; @@ -61,6 +66,9 @@ public class Main extends JavaPlugin implements Listener { Config.loadConfig(); Localization.init(); + // Create World Loader + worldLoader = new WorldLoader(spawnWorld); + // Register Commands CommandHandler.registerCommands(); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/CommandHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/CommandHandler.java index 2001df6..1efb505 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/CommandHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/CommandHandler.java @@ -35,6 +35,7 @@ public class CommandHandler { registerCommand(new SetBorder()); registerCommand(new Reload()); registerCommand(new SaveMap()); + registerCommand(new SetBounds()); registerCommand(new Join()); registerCommand(new Leave()); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java index c0ee5eb..4a4bac1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java @@ -46,11 +46,21 @@ public class EventListener implements Listener { @EventHandler public void onQuit(PlayerQuitEvent event) { Main.plugin.board.remove(event.getPlayer()); + if(Main.plugin.status.equals("Standby")) { + Main.plugin.board.reloadLobbyBoards(); + } else { + Main.plugin.board.reloadGameBoards(); + } } @EventHandler public void onKick(PlayerKickEvent event) { Main.plugin.board.remove(event.getPlayer()); + if(Main.plugin.status.equals("Standby")) { + Main.plugin.board.reloadLobbyBoards(); + } else { + Main.plugin.board.reloadGameBoards(); + } } @EventHandler(priority = EventPriority.HIGHEST) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java index a2554d1..2befd73 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java @@ -2,15 +2,6 @@ package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Arrays; - import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.scheduler.BukkitRunnable; @@ -36,66 +27,15 @@ public class SaveMap implements ICommand { Bukkit.getServer().getWorld(spawnWorld).save(); BukkitRunnable runnable = new BukkitRunnable() { public void run() { - File current = new File(Main.root+File.separator+spawnWorld); - if(current.exists()) { - File temp_destenation = new File(Main.root+File.separator+"temp_hideandseek_"+spawnWorld); - File destenation = new File(Main.root+File.separator+"hideandseek_"+spawnWorld); - copyFileStructure(current, temp_destenation); - if(destenation.exists()) { - deleteDirectory(destenation); - destenation.mkdir(); - } - temp_destenation.renameTo(destenation); - sender.sendMessage(messagePrefix + message("MAPSAVE_END")); - runningBackup = false; - } else { - sender.sendMessage(errorPrefix + message("MAPSAVE_ERROR")); - } + sender.sendMessage( + Main.plugin.worldLoader.save() + ); + runningBackup = false; } }; runnable.runTaskAsynchronously(Main.plugin); runningBackup = true; } - - private static void copyFileStructure(File source, File target){ - try { - ArrayList ignore = new ArrayList<>(Arrays.asList("uid.dat", "session.lock")); - if(!ignore.contains(source.getName())) { - if(source.isDirectory()) { - if(!target.exists()) - if (!target.mkdirs()) - throw new IOException("Couldn't create world directory!"); - String files[] = source.list(); - for (String file : files) { - File srcFile = new File(source, file); - File destFile = new File(target, file); - copyFileStructure(srcFile, destFile); - } - } else { - InputStream in = new FileInputStream(source); - OutputStream out = new FileOutputStream(target); - byte[] buffer = new byte[1024]; - int length; - while ((length = in.read(buffer)) > 0) - out.write(buffer, 0, length); - in.close(); - out.close(); - } - } - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - private boolean deleteDirectory(File directoryToBeDeleted) { - File[] allContents = directoryToBeDeleted.listFiles(); - if (allContents != null) { - for (File file : allContents) { - deleteDirectory(file); - } - } - return directoryToBeDeleted.delete(); - } public String getLabel() { return "saveMap"; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java new file mode 100644 index 0000000..210f7fe --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java @@ -0,0 +1,67 @@ +package net.tylermurphy.hideAndSeek.command; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import net.tylermurphy.hideAndSeek.Main; +import static net.tylermurphy.hideAndSeek.configuration.Localization.*; + +public class SetBounds implements ICommand { + + public void execute(CommandSender sender, String[] args) { + if(!Main.plugin.status.equals("Standby")) { + sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); + return; + } + if(spawnPosition == null) { + sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN")); + return; + } + Player player = (Player) sender; + if(!player.getWorld().getName().equals(spawnWorld)){ + sender.sendMessage(errorPrefix + message("BOUNDS_WRONG_WORLD")); + return; + } + if(saveMaxX == 0) { + addToConfig("bounds.max.x", player.getLocation().getBlockX()); + saveMaxX = player.getLocation().getBlockX(); + } else if(saveMaxX < player.getLocation().getBlockX()) { + addToConfig("bounds.max.x", player.getLocation().getBlockX()); + addToConfig("bounds.min.x", saveMaxX); + saveMinX = saveMaxX; + saveMaxX = player.getLocation().getBlockX(); + } else { + addToConfig("bounds.min.x", player.getLocation().getBlockX()); + saveMinX = player.getLocation().getBlockX(); + } + if(saveMaxZ == 0) { + addToConfig("bounds.max.z", player.getLocation().getBlockZ()); + saveMaxZ = player.getLocation().getBlockZ(); + } else if(saveMaxZ < player.getLocation().getBlockZ()) { + addToConfig("bounds.max.z", player.getLocation().getBlockZ()); + addToConfig("bounds.min.z", saveMaxZ); + saveMinZ = saveMaxZ; + saveMaxZ = player.getLocation().getBlockZ(); + } else { + addToConfig("bounds.min.z", player.getLocation().getBlockZ()); + saveMinZ = player.getLocation().getBlockZ(); + } + sender.sendMessage(messagePrefix + message("BOUNDS")); + saveConfig(); + } + + public String getLabel() { + return "setBounds"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Sets the map bounds for the game."; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java index 8be0141..f47503a 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java @@ -28,9 +28,13 @@ public class Setup implements ICommand { msg = msg + "\n" + message("SETUP_EXIT").toString(); count++; } + if(saveMinX == 0 || saveMinZ == 0 || saveMaxX == 0 || saveMaxZ == 0) { + msg = msg + "\n" + message("SETUP_BOUNDS").toString(); + count++; + } File destenation = new File(Main.root+File.separator+"hideandseek_"+spawnWorld); if(!destenation.exists()) { - msg = msg + "\n" + message("SETUP_MAPSAVE").toString(); + msg = msg + "\n" + message("SETUP_SAVEMAP").toString(); count++; } if(count < 1) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java index 89cbc09..4bedd2f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -49,9 +49,9 @@ public class Start implements ICommand { return; } if(Bukkit.getServer().getWorld("hideandseek_"+spawnWorld) != null) { - Util.rollback("hideandseek_"+spawnWorld); + Main.plugin.worldLoader.rollback(); } else { - Util.loadMap("hideandseek_"+spawnWorld); + Main.plugin.worldLoader.loadMap(); } String seekerName; if(args.length < 1) { @@ -124,9 +124,6 @@ public class Start implements ICommand { if(gameLength > 0) { Main.plugin.timeLeft = gameLength; - for(Player player : Main.plugin.board.getPlayers()) { - player.setLevel(gameLength); - } } } }, 20 * 30); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java index 810c071..52bf310 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java @@ -58,7 +58,7 @@ public class Stop implements ICommand { Packet.setGlow(player, temp, false); } } - Util.unloadMap("hideandseek_"+spawnWorld); + Main.plugin.worldLoader.unloadMap(); Main.plugin.board.reloadLobbyBoards(); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java index 83b6ceb..efae5d2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java @@ -40,7 +40,11 @@ public class Config { worldborderSize, worldborderDelay, currentWorldborderSize, - gameLength; + gameLength, + saveMinX, + saveMinZ, + saveMaxX, + saveMaxZ; public static FileConfiguration getConfig() { return Main.plugin.getConfig(); @@ -101,6 +105,12 @@ public class Config { gameoverPrefix = getConfig().getString("prefix.gameover").replace("&", SYMBOLE_STRING); warningPrefix = getConfig().getString("prefix.warning").replace("&", SYMBOLE_STRING); + //Map Bounds + saveMinX = getConfig().getInt("bounds.min.x"); + saveMinZ = getConfig().getInt("bounds.min.z"); + saveMaxX = getConfig().getInt("bounds.max.x"); + saveMaxZ = getConfig().getInt("bounds.max.z"); + //Other nametagsVisible = getConfig().getBoolean("nametagsVisible"); permissionsRequired = getConfig().getBoolean("permissionsRequired"); @@ -123,4 +133,8 @@ public class Config { saveConfig(); } + public static void addToConfig(String path, Object value) { + getConfig().set(path, value); + } + } \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java index 177b5bf..ee34d4a 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java @@ -1,6 +1,9 @@ package net.tylermurphy.hideAndSeek.configuration; import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; @@ -13,12 +16,20 @@ public class Localization { public static final Map LOCAL = new HashMap(); - static YamlConfiguration config; + static YamlConfiguration config, defaultConfig; + static File location; public static boolean init() { + Main.plugin.saveResource("localization.yml", false); String path = Main.data.getAbsolutePath()+File.separator + "localization.yml"; - config = YamlConfiguration.loadConfiguration(new File(path)); + location = new File(path); + config = YamlConfiguration.loadConfiguration(location); + + InputStream is = Main.plugin.getResource("localization.yml"); + InputStreamReader isr = new InputStreamReader(is); + defaultConfig = YamlConfiguration.loadConfiguration(isr); + for(String key : config.getConfigurationSection("Localization").getKeys(false)) { LOCAL.put( key, @@ -30,8 +41,19 @@ public class Localization { public static LocalizationString message(String key) { LocalizationString temp = LOCAL.get(key); - if(temp == null) - return new LocalizationString(key+" missing from localization.yml"); + if(temp == null) { + config.set("Localization."+key, defaultConfig.getString("Localization."+key)); + try { + config.save(location); + } catch (IOException e) { + Main.plugin.getLogger().severe(e.getMessage()); + } + LOCAL.put(key, + new LocalizationString( ChatColor.translateAlternateColorCodes('&', defaultConfig.getString("Localization."+key) ) ) + ); + return new LocalizationString(LOCAL.get(key).toString()); + } return new LocalizationString(temp.toString()); + } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java index 028b217..57839f1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java @@ -5,7 +5,6 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.*; import java.io.File; import org.bukkit.Bukkit; -import org.bukkit.WorldCreator; import org.bukkit.entity.Player; import net.tylermurphy.hideAndSeek.Main; @@ -27,24 +26,6 @@ public class Util { return true; } - public static void unloadMap(String mapname){ - if(Bukkit.getServer().unloadWorld(Bukkit.getServer().getWorld(mapname), false)){ - Main.plugin.getLogger().info("Successfully unloaded " + mapname); - }else{ - Main.plugin.getLogger().severe("COULD NOT UNLOAD " + mapname); - } - } - - public static void loadMap(String mapname){ - Bukkit.getServer().createWorld(new WorldCreator(mapname)); - Bukkit.getServer().getWorld("hideandseek_"+spawnWorld).setAutoSave(false); - } - - public static void rollback(String mapname){ - unloadMap(mapname); - loadMap(mapname); - } - public static void sendDelayedMessage(String message, int gameId, int delay) { Bukkit.getScheduler().runTaskLaterAsynchronously(Main.plugin, new Runnable() { public void run() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java b/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java new file mode 100644 index 0000000..d03fd17 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java @@ -0,0 +1,57 @@ +package net.tylermurphy.hideAndSeek.world; + +import java.util.Collections; +import java.util.List; + +import org.bukkit.World; +import org.bukkit.generator.BlockPopulator; +import org.bukkit.generator.ChunkGenerator; + +public class VoidGenerator extends ChunkGenerator{ + + @Override + public List getDefaultPopulators(World world) { + return Collections.emptyList(); + } + + @Override + public boolean shouldGenerateNoise() { + return false; + } + + @Override + public boolean shouldGenerateSurface() { + return false; + } + + @Override + public boolean shouldGenerateBedrock() { + return false; + } + + @Override + public boolean shouldGenerateCaves() { + return false; + } + + @Override + public boolean shouldGenerateDecorations() { + return false; + } + + @Override + public boolean shouldGenerateMobs() { + return false; + } + + @Override + public boolean shouldGenerateStructures() { + return false; + } + + @Override + public boolean canSpawn(World world, int x, int z) { + return true; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java new file mode 100644 index 0000000..cfb85bf --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java @@ -0,0 +1,129 @@ +package net.tylermurphy.hideAndSeek.world; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import org.bukkit.Bukkit; +import org.bukkit.WorldCreator; + +import net.tylermurphy.hideAndSeek.Main; + +public class WorldLoader { + + String mapname; + String savename; + + public WorldLoader(String mapname) { + this.mapname = mapname; + this.savename = "hideandseek_"+mapname; + } + + public void unloadMap(){ + if(Bukkit.getServer().unloadWorld(Bukkit.getServer().getWorld(savename), false)){ + Main.plugin.getLogger().info("Successfully unloaded " + savename); + }else{ + Main.plugin.getLogger().severe("COULD NOT UNLOAD " + savename); + } + } + + public void loadMap(){ + Bukkit.getServer().createWorld(new WorldCreator(savename).generator(new VoidGenerator())); + Bukkit.getServer().getWorld(savename).setAutoSave(false); + } + + public void rollback(){ + unloadMap(); + loadMap(); + } + + public String save() { + File current = new File(Main.root+File.separator+mapname); + if(current.exists()) { + try { + File destenation = new File(Main.root+File.separator+savename); + File temp_destenation = new File(Main.root+File.separator+"temp_"+savename); + copyFileFolder("region",true); + copyFileFolder("entities",true); + copyFileFolder("datapacks",false); + File srcFile = new File(current, "level.dat"); + File destFile = new File(temp_destenation, "level.dat"); + copyFile(srcFile,destFile); + if(destenation.exists()) { + deleteDirectory(destenation); + destenation.mkdir(); + } + temp_destenation.renameTo(destenation); + } catch(IOException e) { + e.printStackTrace(); + return errorPrefix + message("COMMAND_ERROR"); + } + return messagePrefix + message("MAPSAVE_END"); + } else { + return errorPrefix + message("MAPSAVE_ERROR"); + } + } + + private void copyFileFolder(String name, Boolean isMca) throws IOException { + File region = new File(Main.root+File.separator+mapname+File.separator+name); + File temp = new File(Main.root+File.separator+"temp_"+savename+File.separator+name); + if(region.exists() && region.isDirectory()) { + if(!temp.exists()) + if(!temp.mkdirs()) + throw new IOException("Couldn't create region directory!"); + String files[] = region.list(); + for (String file : files) { + + if(isMca) { + int minX = (int)Math.floor(saveMinX / 32.0); + int minZ = (int)Math.floor(saveMinZ / 32.0); + int maxX = (int)Math.floor(saveMaxX / 32.0); + int maxZ = (int)Math.floor(saveMaxZ / 32.0); + + String[] parts = file.split("."); + if(parts.length > 1) { + Main.plugin.getLogger().info(file); + if( Integer.parseInt(parts[1]) < minX || Integer.parseInt(parts[1]) > maxX ||Integer.parseInt(parts[2]) < minZ || Integer.parseInt(parts[2]) > maxZ ) + continue; + } + } + + File srcFile = new File(region, file); + if(srcFile.isDirectory()) { + copyFileFolder(name+File.separator+file, false); + } else { + File destFile = new File(temp, file); + copyFile(srcFile, destFile); + } + } + } + } + + private void copyFile(File source, File target) throws IOException { + InputStream in = new FileInputStream(source); + OutputStream out = new FileOutputStream(target); + byte[] buffer = new byte[1024]; + int length; + while ((length = in.read(buffer)) > 0) + out.write(buffer, 0, length); + in.close(); + out.close(); + } + + private boolean deleteDirectory(File directoryToBeDeleted) { + File[] allContents = directoryToBeDeleted.listFiles(); + if (allContents != null) { + for (File file : allContents) { + deleteDirectory(file); + } + } + return directoryToBeDeleted.delete(); + } + +} diff --git a/src/main/resources/localization.yml b/src/main/resources/localization.yml index cf2fd30..e714046 100644 --- a/src/main/resources/localization.yml +++ b/src/main/resources/localization.yml @@ -19,7 +19,7 @@ Localization: CONFIG_RELOAD: "Reloaded the config." MAPSAVE_INPROGRESS: "Map save is currently in progress. Try again later." MAPSAVE_START: "Starting map save." - MAPSAVE_WARNING: "All commands will be disabled whenthe save is in progress. Do not turn off the server." + MAPSAVE_WARNING: "All commands will be disabled when the save is in progress. Do not turn off the server." MAPSAVE_END: "Map save complete." MAPSAVE_ERROR: "Coudnt find current map." WORLDBORDER_DISABLE: "Disabled worldborder." @@ -37,6 +37,7 @@ Localization: SETUP_LOBBY: "&c&l- &fLobby spawn isnt set, /hs setlobby" SETUP_EXIT: "&c&l- &fQuit/exit teleport location isnt set, /hs setexit" SETUP_SAVEMAP: "&c&l- &fHide and seek map isnt saved, /hs savemap (after /hs setspawn)" + SETUP_BOUNDS: "&c&l- &fPlease set game bounds in 2 opposite corners of the game map, /hs setbounds" SETUP_COMPLETE: "Everything is setup and ready to go!" GAME_SPAWN: "Set game spawn position to current location" LOBBY_SPAWN: "Set lobby position to current location" @@ -45,6 +46,8 @@ Localization: START_INVALID_NAME: "Invalid player: {PLAYER}." START_COUNTDOWN: "Hiders have {AMOUNT} seconds to hide!" START: "Attetion SEEKERS, its time to fin the hiders!" - STOP: "Game has been force stopped" + STOP: "Game has been force stopped." HIDERS_SUBTITLE: "Hide away from the seekers" SEEKERS_SUBTITLE: "Eliminate all hiders" + BOUNDS_WRONG_WORLD: "Please run this command in the game world." + BOUNDS: "Sucessfully set bounds at this position." From 3ebb86268a543d154cdf20ac2ffbf7b56bdf9794 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Thu, 28 Oct 2021 23:09:28 -0400 Subject: [PATCH 02/10] 1.3.1 build 2 --- .gitignore | 2 + .project | 23 --- pom.xml | 82 +++++---- .../net/tylermurphy/hideAndSeek/Main.java | 4 +- .../hideAndSeek/bukkit/EventListener.java | 1 + .../hideAndSeek/command/About.java | 2 +- .../hideAndSeek/command/Reload.java | 2 +- .../hideAndSeek/command/SetBorder.java | 16 +- .../hideAndSeek/command/SetExitLocation.java | 9 +- .../hideAndSeek/command/SetLobbyLocation.java | 10 +- .../hideAndSeek/command/SetSpawnLocation.java | 12 +- .../hideAndSeek/configuration/Config.java | 135 +++++++-------- .../configuration/ConfigManager.java | 156 ++++++++++++++++++ .../configuration/Localization.java | 35 ++-- .../tylermurphy/hideAndSeek/util/Util.java | 29 +++- src/main/resources/config.yml | 39 ++++- src/main/resources/plugin.yml | 2 +- 17 files changed, 368 insertions(+), 191 deletions(-) delete mode 100644 .project create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java diff --git a/.gitignore b/.gitignore index 1679bd7..633697f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ project bin/ target/ .git/ +.idea +hideandseek-plugin.iml diff --git a/.project b/.project deleted file mode 100644 index e024f12..0000000 --- a/.project +++ /dev/null @@ -1,23 +0,0 @@ - - - hideandseek-plugin - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.jdt.core.javanature - org.eclipse.m2e.core.maven2Nature - - diff --git a/pom.xml b/pom.xml index 5a78364..e0cca85 100644 --- a/pom.xml +++ b/pom.xml @@ -1,43 +1,57 @@ -4.0.0 - net.tylermurphy - HideAndSeek - 1.3.0 - Hide and Seek Plugin - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - 1.8 - 1.8 - - - - - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/public/ - + + + 4.0.0 + + net.tylermurphy + HideAndSeek + 1.3.1 + Hide and Seek Plugin + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.8 + 1.8 + + + + + + - dmulloy2-repo - https://repo.dmulloy2.net/repository/public/ - + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/public/ + + + dmulloy2-repo + https://repo.dmulloy2.net/repository/public/ + + - + org.spigotmc spigot-api 1.17.1-R0.1-SNAPSHOT jar - provided + provided - - com.comphenix.protocol - ProtocolLib - 4.7.0 - - + + com.comphenix.protocol + ProtocolLib + 4.7.0 + + + + + 11 + 11 + + \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index 1e78bc9..1a5570e 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -61,10 +61,8 @@ public class Main extends JavaPlugin implements Listener { data = this.getDataFolder(); // Init Configuration - Main.plugin.saveResource("localization.yml", false); - Main.plugin.saveResource("config.yml", false); Config.loadConfig(); - Localization.init(); + Localization.loadLocalization(); // Create World Loader worldLoader = new WorldLoader(spawnWorld); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java index 4a4bac1..9c88ccf 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java @@ -40,6 +40,7 @@ public class EventListener implements Listener { if(event.getPlayer().getWorld().getName().equals("hideandseek_"+spawnWorld) || event.getPlayer().getWorld().getName().equals(lobbyWorld)){ event.getPlayer().teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); event.getPlayer().setGameMode(GameMode.ADVENTURE); + } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java index 4b207fb..897a9a0 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java @@ -7,7 +7,7 @@ public class About implements ICommand { public void execute(CommandSender sender, String[] args) { sender.sendMessage( - String.format("%s%sHide and Seek %s(1.3.0%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + + String.format("%s%sHide and Seek %s(1.3.1%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/command/Reload.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java index cf580c9..2c7ba04 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java @@ -19,7 +19,7 @@ public class Reload implements ICommand { return; } Config.loadConfig(); - Localization.init(); + Localization.loadLocalization(); sender.sendMessage(messagePrefix + message("CONFIG_RELOAD")); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java index 25e0a87..472396c 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java @@ -26,9 +26,7 @@ public class SetBorder implements ICommand { } if(args.length < 2) { worldborderEnabled = false; - Map temp = new HashMap(); - temp.put("enabled", false); - addToSection("worldBorder",temp); + addToConfig("worldBorder.enabled",false); saveConfig(); sender.sendMessage(messagePrefix + message("WORLDBORDER_DISABLE")); Worldborder.resetWorldborder(spawnWorld); @@ -60,13 +58,11 @@ public class SetBorder implements ICommand { worldborderSize = num; worldborderDelay = delay; worldborderEnabled = true; - Map temp = new HashMap(); - temp.put("x", worldborderPosition.getBlockX()); - temp.put("z", worldborderPosition.getBlockZ()); - temp.put("delay", worldborderDelay); - temp.put("size", worldborderSize); - temp.put("enabled", true); - addToSection("worldBorder",temp); + addToConfig("worldBorder.x", worldborderPosition.getBlockX()); + addToConfig("worldBorder.z", worldborderPosition.getBlockZ()); + addToConfig("worldBorder.delay", worldborderDelay); + addToConfig("worldBorder.size", worldborderSize); + addToConfig("worldBorder.enabled", true); sender.sendMessage(messagePrefix + message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay)); saveConfig(); Worldborder.resetWorldborder(spawnWorld); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java index e82d0e4..c9d2fae 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java @@ -27,11 +27,10 @@ public class SetExitLocation implements ICommand { exitPosition = newExitPosition; sender.sendMessage(messagePrefix + message("EXIT_SPAWN")); Map temp = new HashMap(); - temp.put("x", exitPosition.getX()); - temp.put("y", exitPosition.getY()); - temp.put("z", exitPosition.getZ()); - temp.put("world", player.getLocation().getWorld().getName()); - addToSection("spawns.exit",temp); + addToConfig("spawns.exit.x", exitPosition.getX()); + addToConfig("spawns.exit.y", exitPosition.getY()); + addToConfig("spawns.exit.z", exitPosition.getZ()); + addToConfig("spawns.exit.world", player.getLocation().getWorld().getName()); saveConfig(); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java index 31cad53..a8a1887 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java @@ -26,12 +26,10 @@ public class SetLobbyLocation implements ICommand { } lobbyPosition = newLobbyPosition; sender.sendMessage(messagePrefix + message("LOBBY_SPAWN")); - Map temp = new HashMap(); - temp.put("x", lobbyPosition.getX()); - temp.put("y", lobbyPosition.getY()); - temp.put("z", lobbyPosition.getZ()); - temp.put("world", player.getLocation().getWorld().getName()); - addToSection("spawns.lobby",temp); + addToConfig("spawns.lobby.x", lobbyPosition.getX()); + addToConfig("spawns.lobby.y", lobbyPosition.getY()); + addToConfig("spawns.lobby.z", lobbyPosition.getZ()); + addToConfig("spawns.lobby.world", player.getLocation().getWorld().getName()); saveConfig(); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java index 45ee758..d634968 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java @@ -10,6 +10,8 @@ import org.bukkit.entity.Player; import org.bukkit.util.Vector; import net.tylermurphy.hideAndSeek.Main; + +import static net.tylermurphy.hideAndSeek.configuration.Config.addToConfig; import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class SetSpawnLocation implements ICommand { @@ -30,12 +32,10 @@ public class SetSpawnLocation implements ICommand { } spawnPosition = newSpawnPosition; sender.sendMessage(messagePrefix + message("GAME_SPAWN")); - Map temp = new HashMap(); - temp.put("x", spawnPosition.getX()); - temp.put("y", spawnPosition.getY()); - temp.put("z", spawnPosition.getZ()); - temp.put("world", player.getLocation().getWorld().getName()); - addToSection("spawns.game",temp); + addToConfig("spawns.game.x", spawnPosition.getX()); + addToConfig("spawns.game.y", spawnPosition.getY()); + addToConfig("spawns.game.z", spawnPosition.getZ()); + addToConfig("spawns.game.world", player.getLocation().getWorld().getName()); saveConfig(); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java index efae5d2..d82f01c 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java @@ -1,15 +1,19 @@ package net.tylermurphy.hideAndSeek.configuration; +import java.io.File; import java.util.Map; import java.util.Map.Entry; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.util.Vector; import net.tylermurphy.hideAndSeek.Main; public class Config { + + static ConfigManager manager; public static String messagePrefix, @@ -46,95 +50,78 @@ public class Config { saveMaxX, saveMaxZ; - public static FileConfiguration getConfig() { - return Main.plugin.getConfig(); - } - - public static void saveConfig() { - Main.plugin.saveConfig(); - } - public static void loadConfig() { - - Main.plugin.reloadConfig(); - + + manager = new ConfigManager("config.yml"); + //Spawn spawnPosition = new Vector( - getConfig().getDouble("spawns.game.x"), - Math.max(0,Math.min(255,getConfig().getDouble("spawns.game.y"))), - getConfig().getDouble("spawns.game.z") - ); - spawnWorld = getConfig().getString("spawns.game.world"); - + manager.getDouble("spawns.game.x"), + Math.max(0, Math.min(255, manager.getDouble("spawns.game.y"))), + manager.getDouble("spawns.game.z") + ); + spawnWorld = manager.getString("spawns.game.world"); + ///Lobby lobbyPosition = new Vector( - getConfig().getDouble("spawns.lobby.x"), - Math.max(0,Math.min(255,getConfig().getDouble("spawns.lobby.y"))), - getConfig().getDouble("spawns.lobby.z") - ); - lobbyWorld = getConfig().getString("spawns.lobby.world"); - - announceMessagesToNonPlayers = getConfig().getBoolean("announceMessagesToNonPlayers"); - + manager.getDouble("spawns.lobby.x"), + Math.max(0, Math.min(255, manager.getDouble("spawns.lobby.y"))), + manager.getDouble("spawns.lobby.z") + ); + lobbyWorld = manager.getString("spawns.lobby.world"); + + announceMessagesToNonPlayers = manager.getBoolean("announceMessagesToNonPlayers"); + exitPosition = new Vector( - getConfig().getDouble("spawns.exit.x"), - Math.max(0,Math.min(255,getConfig().getDouble("spawns.exit.y"))), - getConfig().getDouble("spawns.exit.z") - ); - exitWorld = getConfig().getString("spawns.exit.world"); - + manager.getDouble("spawns.exit.x"), + Math.max(0, Math.min(255, manager.getDouble("spawns.exit.y"))), + manager.getDouble("spawns.exit.z") + ); + exitWorld = manager.getString("spawns.exit.world"); + //World border worldborderPosition = new Vector( - getConfig().getInt("worldBorder.x"), - 0, - getConfig().getInt("worldBorder.z") - ); - worldborderSize = Math.max(100,getConfig().getInt("worldBorder.size")); - worldborderDelay = Math.max(1,getConfig().getInt("worldBorder.delay")); - worldborderEnabled = getConfig().getBoolean("worldBorder.enabled"); - + manager.getInt("worldBorder.x"), + 0, + manager.getInt("worldBorder.z") + ); + worldborderSize = Math.max(100, manager.getInt("worldBorder.size")); + worldborderDelay = Math.max(1, manager.getInt("worldBorder.delay")); + worldborderEnabled = manager.getBoolean("worldBorder.enabled"); + //Prefix char SYMBOLE = '\u00A7'; - String SYMBOLE_STRING = new String(new char[] {SYMBOLE}); - - messagePrefix = getConfig().getString("prefix.default").replace("&", SYMBOLE_STRING); - errorPrefix = getConfig().getString("prefix.error").replace("&", SYMBOLE_STRING); - tauntPrefix = getConfig().getString("prefix.taunt").replace("&", SYMBOLE_STRING); - worldborderPrefix = getConfig().getString("prefix.border").replace("&", SYMBOLE_STRING); - abortPrefix = getConfig().getString("prefix.abort").replace("&", SYMBOLE_STRING); - gameoverPrefix = getConfig().getString("prefix.gameover").replace("&", SYMBOLE_STRING); - warningPrefix = getConfig().getString("prefix.warning").replace("&", SYMBOLE_STRING); - + String SYMBOLE_STRING = new String(new char[]{SYMBOLE}); + + messagePrefix = manager.getString("prefix.default").replace("&", SYMBOLE_STRING); + errorPrefix = manager.getString("prefix.error").replace("&", SYMBOLE_STRING); + tauntPrefix = manager.getString("prefix.taunt").replace("&", SYMBOLE_STRING); + worldborderPrefix = manager.getString("prefix.border").replace("&", SYMBOLE_STRING); + abortPrefix = manager.getString("prefix.abort").replace("&", SYMBOLE_STRING); + gameoverPrefix = manager.getString("prefix.gameover").replace("&", SYMBOLE_STRING); + warningPrefix = manager.getString("prefix.warning").replace("&", SYMBOLE_STRING); + //Map Bounds - saveMinX = getConfig().getInt("bounds.min.x"); - saveMinZ = getConfig().getInt("bounds.min.z"); - saveMaxX = getConfig().getInt("bounds.max.x"); - saveMaxZ = getConfig().getInt("bounds.max.z"); - + saveMinX = manager.getInt("bounds.min.x"); + saveMinZ = manager.getInt("bounds.min.z"); + saveMaxX = manager.getInt("bounds.max.x"); + saveMaxZ = manager.getInt("bounds.max.z"); + //Other - nametagsVisible = getConfig().getBoolean("nametagsVisible"); - permissionsRequired = getConfig().getBoolean("permissionsRequired"); - minPlayers = Math.max(2,getConfig().getInt("minPlayers")); - gameLength = getConfig().getInt("gameLength"); - - getConfig().options().copyDefaults(true); - saveConfig(); - - } - - public static void addToSection(String sectionName, Map values) { - ConfigurationSection section = getConfig().getConfigurationSection(sectionName); - if(section == null) section = getConfig().createSection(sectionName); - Map sectionValues = section.getValues(true); - for(Entry entry : values.entrySet()) { - sectionValues.put(entry.getKey(), entry.getValue()); - } - getConfig().createSection(sectionName, sectionValues); - saveConfig(); + nametagsVisible = manager.getBoolean("nametagsVisible"); + permissionsRequired = manager.getBoolean("permissionsRequired"); + minPlayers = Math.max(2, manager.getInt("minPlayers")); + gameLength = manager.getInt("gameLength"); + + manager.saveConfig(); } public static void addToConfig(String path, Object value) { - getConfig().set(path, value); + manager.set(path, value); + } + + public static void saveConfig() { + manager.saveConfig(); } } \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java new file mode 100644 index 0000000..7ea38db --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -0,0 +1,156 @@ +package net.tylermurphy.hideAndSeek.configuration; + +import net.tylermurphy.hideAndSeek.Main; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.*; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.util.Map; + +public class ConfigManager { + + private File file; + private YamlConfiguration config,defaultConfig; + + public ConfigManager(String filename){ + this.file = new File(Main.plugin.getDataFolder(), filename); + + if(!file.exists()){ + saveDefaultConfiguration(); + } + + this.config = YamlConfiguration.loadConfiguration(file); + + InputStream input = Main.plugin.getResource(file.getName()); + InputStreamReader reader = new InputStreamReader(input); + this.defaultConfig = YamlConfiguration.loadConfiguration(reader); + try{ + input.close(); + reader.close(); + } catch (IOException e){} + + } + + private void saveDefaultConfiguration(){ + try{ + InputStream input = Main.plugin.getResource(file.getName()); + java.nio.file.Files.copy(input, file.toPath()); + input.close(); + } catch(IOException e){ + e.printStackTrace(); + } + } + + public void addToSection(String sectionName, Map values) { + ConfigurationSection section = config.getConfigurationSection(sectionName); + if(section == null) section = config.createSection(sectionName); + Map sectionValues = section.getValues(true); + for(Map.Entry entry : values.entrySet()) { + sectionValues.put(entry.getKey(), entry.getValue()); + } + config.createSection(sectionName, sectionValues); + } + + public void addToConfig(String path, Object value) { + config.set(path, value); + } + + public double getDouble(String path){ + double value = config.getDouble(path); + if(value == 0.0D){ + return defaultConfig.getDouble(path); + } else { + return value; + } + } + + public int getInt(String path){ + int value = config.getInt(path); + if(value == 0){ + return defaultConfig.getInt(path); + } else { + return value; + } + } + + public String getString(String path){ + String value = config.getString(path); + if(value == null){ + return defaultConfig.getString(path); + } else { + return value; + } + } + + public boolean getBoolean(String path){ + boolean value = config.getBoolean(path); + if(value == false){ + return defaultConfig.getBoolean(path); + } else { + return value; + } + } + + public ConfigurationSection getConfigurationSection(String path){ + ConfigurationSection section = config.getConfigurationSection(path); + if(section == null){ + return defaultConfig.getConfigurationSection(path); + } else { + return section; + } + } + + public void set(String path, Object value){ + config.set(path, value); + } + + public void saveConfig(){ + try { + InputStream is = Main.plugin.getResource(file.getName()); + StringBuilder textBuilder = new StringBuilder(); + Reader reader = new BufferedReader(new InputStreamReader(is, Charset.forName(StandardCharsets.UTF_8.name()))); + int c = 0; + while((c = reader.read()) != -1){ + textBuilder.append((char) c); + } + String yamlString = textBuilder.toString(); + Map temp = config.getValues(true); + for(Map.Entry entry: temp.entrySet()){ + System.out.println(entry.getKey() + " " + entry.getValue().getClass().getName()); + if(entry.getValue() instanceof Integer || entry.getValue() instanceof Double || entry.getValue() instanceof String || entry.getValue() instanceof Boolean){ + String[] parts = entry.getKey().split("\\."); + int index = 0; + int i = 0; + for(String part : parts) { + if(i == 0) { + index = yamlString.indexOf(part, index); + } else { + index = yamlString.indexOf(" " + part, index); + index++; + } + i++; + if(index == -1) break; + } + if(index == -1) continue;; + int start = yamlString.indexOf(' ', index); + int end = yamlString.indexOf('\n', index); + String replace = entry.getValue().toString(); + if(entry.getValue() instanceof String){ + replace = "\"" + replace + "\""; + } + StringBuilder builder = new StringBuilder(yamlString); + builder.replace(start+1, end, replace); + yamlString = builder.toString(); + } + } + PrintWriter out = new PrintWriter(file); + out.print(yamlString); + out.close(); + } catch (IOException e){ + e.printStackTrace(); + } + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java index ee34d4a..82d19d4 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java @@ -16,44 +16,29 @@ public class Localization { public static final Map LOCAL = new HashMap(); - static YamlConfiguration config, defaultConfig; - static File location; + private static ConfigManager manager; - public static boolean init() { + public static boolean loadLocalization() { + + manager = new ConfigManager("localization.yml"); - Main.plugin.saveResource("localization.yml", false); - String path = Main.data.getAbsolutePath()+File.separator + "localization.yml"; - location = new File(path); - config = YamlConfiguration.loadConfiguration(location); - - InputStream is = Main.plugin.getResource("localization.yml"); - InputStreamReader isr = new InputStreamReader(is); - defaultConfig = YamlConfiguration.loadConfiguration(isr); - - for(String key : config.getConfigurationSection("Localization").getKeys(false)) { + for(String key : manager.getConfigurationSection("Localization").getKeys(false)) { LOCAL.put( key, - new LocalizationString( ChatColor.translateAlternateColorCodes('&', config.getString("Localization."+key) ) ) + new LocalizationString( ChatColor.translateAlternateColorCodes('&', manager.getString("Localization."+key) ) ) ); } + + manager.saveConfig(); + return true; } public static LocalizationString message(String key) { LocalizationString temp = LOCAL.get(key); if(temp == null) { - config.set("Localization."+key, defaultConfig.getString("Localization."+key)); - try { - config.save(location); - } catch (IOException e) { - Main.plugin.getLogger().severe(e.getMessage()); - } - LOCAL.put(key, - new LocalizationString( ChatColor.translateAlternateColorCodes('&', defaultConfig.getString("Localization."+key) ) ) - ); - return new LocalizationString(LOCAL.get(key).toString()); + return new LocalizationString(ChatColor.RED + "" + ChatColor.ITALIC + key + "is not found in localization.yml. This is a plugin issue, please report it."); } return new LocalizationString(temp.toString()); - } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java index 57839f1..9c6c1eb 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java @@ -2,9 +2,12 @@ package net.tylermurphy.hideAndSeek.util; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import java.io.File; +import java.io.*; +import net.md_5.bungee.api.ChatColor; +import net.tylermurphy.hideAndSeek.configuration.LocalizationString; import org.bukkit.Bukkit; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import net.tylermurphy.hideAndSeek.Main; @@ -23,6 +26,7 @@ public class Util { if(exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) return false; File destenation = new File(Main.root+File.separator+"hideandseek_"+spawnWorld); if(!destenation.exists()) return false; + if(saveMinX == 0 || saveMinZ == 0 || saveMaxX == 0 || saveMaxZ == 0) return false; return true; } @@ -34,5 +38,28 @@ public class Util { } }, delay); } + + public YamlConfiguration loadDefaultConfig(String name) { + + YamlConfiguration defaultConfig = null; + + InputStream deafult_stream = null; + InputStreamReader default_stream_reader = null; + try { + deafult_stream = Class.class.getResourceAsStream(name + ".yml"); + default_stream_reader = new InputStreamReader(deafult_stream); + defaultConfig = YamlConfiguration.loadConfiguration(default_stream_reader); + } catch (Exception e) { + // No Issue Here + } finally { + try { + deafult_stream.close(); + default_stream_reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return defaultConfig; + } } \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 368bca4..f826a88 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -42,13 +42,34 @@ spawns: # The worldborder closes every interval, whish is evey [delay] in minutes. # Thw worldborder stharts at [size], and decreaces 100 blocks every interval. # x & z are the center location. [enabled] is whenever the border is enabled. +# You can choose if Hiders are warned 30 seconds before the border moves. worldBorder: x: 0 z: 0 delay: 10 size: 500 + warn: true enabled: false +# The taunt will activate every delay set in seconds. It will spawn a firework +# on a random Hider to alert a Seeker where someone may be. You can choose +# to publially show the taunt countdown, and have the taunt run with only +# one Hider left. +taunt: + delay: 360 + whenLastPerson: false + showCountdown: true + enabled: true + +# The glow powerup allows all Hiders to see where every Seeker is. It last for +# the amount of time set in seconds. You can allow it to be stackable, meaning +# when multiple Hiders use the powerup at the same time, it stacks the times, or +# just overwrites. Only Hiders can see that the Seekers are glowing. +glow: + time: 30 + stackable: true + enabled: true + # The message prefixes displayed before messages. The message contents themselvs # can be changed in localization.yml. prefix: @@ -58,4 +79,20 @@ prefix: border: '&cWorld Border > &f' abort: '&cAbort > &f' gameover: '&aGame Over > &f' - warning: '&cWarning > &f' \ No newline at end of file + warning: '&cWarning > &f' + +# ---------------------------------------------------------- # +# ONLY EDIT BEYOND THIS POINT IF YOU KNOW WHAT YOU ARE DOING # +# ---------------------------------------------------------- # + +# The 2 coordinate bounds that will contain your hideAndSeek map. Its reccomended +# that you use /hs setbounds for this, and not edit this directly, as breaking +# this section will completly break the entire plugin when you run /hs mapsave. +bounds: + min: + x: 0 + z: 0 + max: + x: 0 + z: 0 + diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 200d799..2f6b145 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: HideAndSeek main: net.tylermurphy.hideAndSeek.Main -version: 1.3.0 +version: 1.3.1 author: KenshinEto load: STARTUP api-version: 1.17 From 4188dadbe3825178349417ba8d594bca00761dc4 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Fri, 29 Oct 2021 19:57:40 -0400 Subject: [PATCH 03/10] 1.3.1 build 3 --- .../hideAndSeek/bukkit/EventListener.java | 13 +- .../tylermurphy/hideAndSeek/command/Join.java | 7 +- .../hideAndSeek/command/Leave.java | 1 + .../hideAndSeek/command/Start.java | 82 ++---------- .../tylermurphy/hideAndSeek/command/Stop.java | 2 +- .../hideAndSeek/configuration/Config.java | 27 +++- .../tylermurphy/hideAndSeek/events/Glow.java | 14 ++- .../tylermurphy/hideAndSeek/events/Taunt.java | 49 ++++---- .../tylermurphy/hideAndSeek/util/Board.java | 108 +++++++++------- .../hideAndSeek/util/CustomBoard.java | 117 ++++++++++++++++++ .../tylermurphy/hideAndSeek/util/Util.java | 92 +++++++++++--- src/main/resources/config.yml | 5 +- 12 files changed, 345 insertions(+), 172 deletions(-) create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/util/CustomBoard.java diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java index 9c88ccf..dc8b9ce 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java @@ -27,7 +27,8 @@ import org.bukkit.event.player.PlayerQuitEvent; import net.tylermurphy.hideAndSeek.util.Packet; import net.tylermurphy.hideAndSeek.util.Util; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.command.Start; +import org.bukkit.potion.PotionEffect; + import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class EventListener implements Listener { @@ -52,6 +53,9 @@ public class EventListener implements Listener { } else { Main.plugin.board.reloadGameBoards(); } + for(PotionEffect effect : event.getPlayer().getActivePotionEffects()){ + event.getPlayer().removePotionEffect(effect.getType()); + } } @EventHandler @@ -62,6 +66,9 @@ public class EventListener implements Listener { } else { Main.plugin.board.reloadGameBoards(); } + for(PotionEffect effect : event.getPlayer().getActivePotionEffects()){ + event.getPlayer().removePotionEffect(effect.getType()); + } } @EventHandler(priority = EventPriority.HIGHEST) @@ -100,7 +107,8 @@ public class EventListener implements Listener { } Main.plugin.board.addSeeker(player); } - Start.resetPlayer(player); + Util.resetPlayer(player); + Main.plugin.board.reloadBoardTeams(); } } } @@ -109,6 +117,7 @@ public class EventListener implements Listener { public void onProjectile(ProjectileLaunchEvent event) { if(!Main.plugin.status.equals("Playing")) return; if(event.getEntity() instanceof Snowball) { + if(!glowEnabled) return; Snowball snowball = (Snowball) event.getEntity(); if(snowball.getShooter() instanceof Player) { Player player = (Player) snowball.getShooter(); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java index 9e77381..b3691bf 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java @@ -29,18 +29,21 @@ public class Join implements ICommand { sender.sendMessage(errorPrefix + message("GAME_INGAME")); return; } - + if(Main.plugin.status.equals("Standby")) { + player.getInventory().clear(); Main.plugin.board.addHider(player); if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player)); else Util.broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player)); player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ())); player.setGameMode(GameMode.ADVENTURE); + Main.plugin.board.createLobbyBoard(player); Main.plugin.board.reloadLobbyBoards(); } else { - Main.plugin.board.addSeeker(player); + Main.plugin.board.addSpectator(player); player.sendMessage(messagePrefix + message("GAME_JOIN_SPECTATOR")); player.setGameMode(GameMode.SPECTATOR); + Main.plugin.board.createGameBoard(player); player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java index 73dafbd..8809b5d 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java @@ -36,6 +36,7 @@ public class Leave implements ICommand { Main.plugin.board.reloadLobbyBoards(); } else { Main.plugin.board.reloadGameBoards(); + Main.plugin.board.reloadBoardTeams(); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java index 4bedd2f..05565da 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -90,6 +90,9 @@ public class Start implements ICommand { player.sendTitle(ChatColor.GOLD + "" + ChatColor.BOLD + "HIDER", ChatColor.WHITE + message("HIDERS_SUBTITLE").toString(), 10, 70, 20); } Worldborder.resetWorldborder("hideandseek_"+spawnWorld); + for(Player player : Main.plugin.board.getPlayers()){ + Main.plugin.board.createGameBoard(player); + } Main.plugin.board.reloadGameBoards(); Main.plugin.status = "Starting"; int temp = Main.plugin.gameId; @@ -106,7 +109,7 @@ public class Start implements ICommand { Util.broadcastMessage(messagePrefix + message("START")); Main.plugin.status = "Playing"; for(Player player : Main.plugin.board.getPlayers()) { - resetPlayer(player); + Util.resetPlayer(player); } Main.plugin.worldborder = null; Main.plugin.taunt = null; @@ -116,11 +119,15 @@ public class Start implements ICommand { Main.plugin.worldborder = new Worldborder(Main.plugin.gameId); Main.plugin.worldborder.schedule(); } - - Main.plugin.taunt = new Taunt(Main.plugin.gameId); - Main.plugin.taunt.schedule(); - - Main.plugin.glow = new Glow(Main.plugin.gameId); + + if(tauntEnabled) { + Main.plugin.taunt = new Taunt(Main.plugin.gameId); + Main.plugin.taunt.schedule(); + } + + if (glowEnabled) { + Main.plugin.glow = new Glow(Main.plugin.gameId); + } if(gameLength > 0) { Main.plugin.timeLeft = gameLength; @@ -130,69 +137,6 @@ public class Start implements ICommand { } - public static void resetPlayer(Player player) { - player.getInventory().clear(); - for(PotionEffect effect : player.getActivePotionEffects()){ - player.removePotionEffect(effect.getType()); - } - player.addPotionEffect(new PotionEffect(PotionEffectType.DOLPHINS_GRACE, 1000000, 1, false, false)); - if(Main.plugin.board.isSeeker(player)){ - ItemStack diamondSword = new ItemStack(Material.DIAMOND_SWORD,1); - diamondSword.addEnchantment(Enchantment.DAMAGE_ALL, 1); - ItemMeta diamondSwordMeta = diamondSword.getItemMeta(); - diamondSwordMeta.setDisplayName("Seeker Sword"); - diamondSwordMeta.setUnbreakable(true); - diamondSword.setItemMeta(diamondSwordMeta); - player.getInventory().addItem(diamondSword); - - ItemStack wackyStick = new ItemStack(Material.STICK,1); - wackyStick.addUnsafeEnchantment(Enchantment.KNOCKBACK, 3); - ItemMeta wackyStickMeta = wackyStick.getItemMeta(); - wackyStickMeta.setDisplayName("Wacky Stick"); - wackyStick.setItemMeta(wackyStickMeta); - player.getInventory().addItem(wackyStick); - - player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 1000000, 2, false, false)); - player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 1000000, 1, false, false)); - player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 1000000, 1, false, false)); - player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 1000000, 10, false, false)); - } - else if(Main.plugin.board.isHider(player)){ - ItemStack stoneSword = new ItemStack(Material.STONE_SWORD,1); - stoneSword.addEnchantment(Enchantment.DAMAGE_ALL, 2); - ItemMeta stoneSwordMeta = stoneSword.getItemMeta(); - stoneSwordMeta.setDisplayName("Hider Sword"); - stoneSwordMeta.setUnbreakable(true); - stoneSword.setItemMeta(stoneSwordMeta); - player.getInventory().addItem(stoneSword); - - ItemStack splashPotion = new ItemStack(Material.SPLASH_POTION,1); - PotionMeta splashPotionMeta = (PotionMeta) splashPotion.getItemMeta(); - splashPotionMeta.setBasePotionData(new PotionData(PotionType.REGEN)); - splashPotion.setItemMeta(splashPotionMeta); - player.getInventory().addItem(splashPotion); - - ItemStack potion = new ItemStack(Material.POTION,2); - PotionMeta potionMeta = (PotionMeta) potion.getItemMeta(); - potionMeta.setBasePotionData(new PotionData(PotionType.INSTANT_HEAL)); - potion.setItemMeta(potionMeta); - player.getInventory().addItem(potion); - - ItemStack snowball = new ItemStack(Material.SNOWBALL,1); - ItemMeta snowballMeta = snowball.getItemMeta(); - snowballMeta.setDisplayName("Glow Powerup"); - List snowballLore = new ArrayList(); - snowballLore.add("Throw to make all seekers glow"); - snowballLore.add("Last 30s, all hiders can see it"); - snowballLore.add("Time stacks on multi use"); - snowballMeta.setLore(snowballLore); - snowball.setItemMeta(snowballMeta); - player.getInventory().addItem(snowball); - - player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 1000000, 1, false, false)); - } - } - public String getLabel() { return "start"; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java index 52bf310..e4dd16e 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java @@ -45,8 +45,8 @@ public class Stop implements ICommand { Main.plugin.timeLeft = 0; Worldborder.resetWorldborder("hideandseek_"+spawnWorld); for(Player player : Main.plugin.board.getPlayers()) { + Main.plugin.board.createLobbyBoard(player); player.setGameMode(GameMode.ADVENTURE); - player.setLevel(0); Main.plugin.board.addHider(player); player.getInventory().clear(); player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ())); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java index d82f01c..04faca2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java @@ -37,7 +37,12 @@ public class Config { nametagsVisible, permissionsRequired, announceMessagesToNonPlayers, - worldborderEnabled; + worldborderEnabled, + tauntEnabled, + tauntCountdown, + tauntLast, + glowEnabled, + glowStackable; public static int minPlayers, @@ -48,11 +53,14 @@ public class Config { saveMinX, saveMinZ, saveMaxX, - saveMaxZ; + saveMaxZ, + tauntDelay, + glowLength; public static void loadConfig() { manager = new ConfigManager("config.yml"); + manager.saveConfig(); //Spawn spawnPosition = new Vector( @@ -91,7 +99,7 @@ public class Config { //Prefix char SYMBOLE = '\u00A7'; - String SYMBOLE_STRING = new String(new char[]{SYMBOLE}); + String SYMBOLE_STRING = String.valueOf(SYMBOLE); messagePrefix = manager.getString("prefix.default").replace("&", SYMBOLE_STRING); errorPrefix = manager.getString("prefix.error").replace("&", SYMBOLE_STRING); @@ -107,13 +115,22 @@ public class Config { saveMaxX = manager.getInt("bounds.max.x"); saveMaxZ = manager.getInt("bounds.max.z"); + //Taunt + tauntEnabled = manager.getBoolean("taunt.enabled"); + tauntCountdown = manager.getBoolean("taunt.showCountdown"); + tauntDelay = Math.max(60,manager.getInt("taunt.delay")); + tauntLast = manager.getBoolean("taunt.whenLastPerson"); + + //Glow + glowLength = Math.max(1,manager.getInt("glow.time")); + glowStackable = manager.getBoolean("glow.stackable"); + glowEnabled = manager.getBoolean("glow.enabled"); + //Other nametagsVisible = manager.getBoolean("nametagsVisible"); permissionsRequired = manager.getBoolean("permissionsRequired"); minPlayers = Math.max(2, manager.getInt("minPlayers")); gameLength = manager.getInt("gameLength"); - - manager.saveConfig(); } public static void addToConfig(String path, Object value) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/events/Glow.java b/src/main/java/net/tylermurphy/hideAndSeek/events/Glow.java index dec3b0f..6ea5ab8 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/events/Glow.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/events/Glow.java @@ -6,6 +6,8 @@ import org.bukkit.entity.Player; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.util.Packet; +import static net.tylermurphy.hideAndSeek.configuration.Config.*; + public class Glow { private final int temp; @@ -18,7 +20,8 @@ public class Glow { } public void onProjectilve() { - glowTime++; + if(glowStackable) glowTime += glowLength; + else glowTime = glowLength; if(!running) startGlow(); } @@ -45,15 +48,20 @@ public class Glow { waitGlow(); } } - }, 20*30); + }, 20); } private void stopGlow() { + running = false; for(Player hider : Main.plugin.board.getHiders()) { - for(Player seeker : Main.plugin.board.getSeekers()) { + for (Player seeker : Main.plugin.board.getSeekers()) { Packet.setGlow(hider, seeker, false); } } } + + public boolean isRunning() { + return running; + } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java b/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java index 8413cc2..748ae40 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java @@ -18,38 +18,31 @@ public class Taunt { private final int temp; private String tauntPlayer; + private int delay; + private boolean running; public Taunt(int temp) { this.temp = temp; + this.delay = 0; } public void schedule() { - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, new Runnable() { - public void run() { - tryTaunt(); - } - },20*60*5); + delay = tauntDelay; + waitTaunt(); } - + private void waitTaunt() { Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, new Runnable() { public void run() { - tryTaunt(); - } - },20*60); - } - - private void tryTaunt() { - if(temp != Main.plugin.gameId) return; - if(Math.random() > .8) { - executeTaunt(); - } else { - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, new Runnable() { - public void run() { - tryTaunt(); + if(delay == 0) { + if(!tauntLast && Main.plugin.board.size() < 2) return; + else executeTaunt(); + } else { + delay--; + waitTaunt(); } - },20*60); - } + } + },20); } private void executeTaunt() { @@ -65,6 +58,7 @@ public class Taunt { } } if(taunted != null) { + running = true; taunted.sendMessage(message("TAUNTED").toString()); Util.broadcastMessage(tauntPrefix + message("TAUNT")); tauntPlayer = taunted.getName(); @@ -90,12 +84,21 @@ public class Taunt { Util.broadcastMessage(tauntPrefix + message("TAUNT_ACTIVATE")); } tauntPlayer = ""; - waitTaunt(); + running = false; + schedule(); } },20*30); } else { - waitTaunt(); + schedule(); } } + + public int getDelay(){ + return delay; + } + + public boolean isRunning() { + return running; + } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java index 17a60b1..59b9ac8 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java @@ -26,7 +26,8 @@ public class Board { private List Hider, Seeker, Spectator; private Map playerList = new HashMap(); - + private Map customBoards = new HashMap(); + public boolean isPlayer(Player player) { return playerList.containsKey(player.getName()); } @@ -145,64 +146,81 @@ public class Board { seekerTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER); } } - - private void createLobbyBoard(Player player) { - - Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard(); - Objective obj = board.registerNewObjective("LobbyScoreboard", "dummy", - ChatColor.translateAlternateColorCodes('&', "&l&eHIDE AND SEEK")); - createTeamsForBoard(board); - obj.setDisplaySlot(DisplaySlot.SIDEBAR); - Score waiting = obj.getScore("Waiting to start..."); - waiting.setScore(6); - Score blank1 = obj.getScore(ChatColor.RESET.toString()); - blank1.setScore(5); - Score players = obj.getScore("Players: "+playerList.values().size()); - players.setScore(4); - Score blank2 = obj.getScore(ChatColor.RESET.toString() + ChatColor.RESET.toString()); - blank2.setScore(3); - Score seeker = obj.getScore(ChatColor.BOLD + "" + ChatColor.RED + "SEEKER%" + ChatColor.WHITE + getSeekerPercent()); - seeker.setScore(2); - Score hider = obj.getScore(ChatColor.BOLD + "" + ChatColor.GOLD + "HIDER%" + ChatColor.WHITE + getHiderPercent()); - hider.setScore(1); - player.setScoreboard(board); + + public void createLobbyBoard(Player player) { + createLobbyBoard(player, true); } - - private void createGameBoard(Player player) { - Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard(); - Objective obj = board.registerNewObjective("GameScoreboard", "dummy", - ChatColor.translateAlternateColorCodes('&', "&l&eHIDE AND SEEK")); - createTeamsForBoard(board); - obj.setDisplaySlot(DisplaySlot.SIDEBAR); - Score team = obj.getScore("Team: " + getTeam(player)); - team.setScore(6); - Score blank1 = obj.getScore(ChatColor.RESET.toString()); - blank1.setScore(5); - if(gameLength > 0) { - Score waiting = obj.getScore(ChatColor.GREEN + "Time Left: " + ChatColor.WHITE + Main.plugin.timeLeft/60 + "m" + Main.plugin.timeLeft%60 + "s"); - waiting.setScore(4); - Score blank2 = obj.getScore(ChatColor.RESET.toString() + ChatColor.RESET.toString()); - blank2.setScore(3); + + private void createLobbyBoard(Player player, boolean recreate) { + CustomBoard board = customBoards.get(player.getName()); + if(recreate) { + board = new CustomBoard(player, "&l&eHIDE AND SEEK"); + board.updateTeams(); } - Score seeker = obj.getScore(ChatColor.BOLD + "" + ChatColor.RED + "SEEKERS:" + ChatColor.WHITE + " " + Seeker.size()); - seeker.setScore(2); - Score hider = obj.getScore(ChatColor.BOLD + "" + ChatColor.GOLD + "HIDERS:" + ChatColor.WHITE + " " + Hider.size()); - hider.setScore(1); - player.setScoreboard(board); + board.setLine("hiders", ChatColor.BOLD + "" + ChatColor.YELLOW + "HIDER%" + ChatColor.WHITE + getHiderPercent()); + board.setLine("seekers", ChatColor.BOLD + "" + ChatColor.RED + "SEEKER%" + ChatColor.WHITE + getSeekerPercent()); + board.addBlank(recreate); + board.setLine("players", "Players: " + playerList.values().size()); + board.addBlank(recreate); + board.setLine("waiting", "Waiting to start..."); + board.display(); + customBoards.put(player.getName(), board); + } + + public void createGameBoard(Player player){ + createGameBoard(player, true); + } + + private void createGameBoard(Player player, boolean recreate){ + CustomBoard board = customBoards.get(player.getName()); + if(recreate) { + board = new CustomBoard(player, "&l&eHIDE AND SEEK"); + board.updateTeams(); + } + board.setLine("hiders", ChatColor.BOLD + "" + ChatColor.YELLOW + "HIDERS:" + ChatColor.WHITE + " " + Hider.size()); + board.setLine("seekers", ChatColor.BOLD + "" + ChatColor.RED + "SEEKERS:" + ChatColor.WHITE + " " + Seeker.size()); + board.addBlank(recreate); + if(glowEnabled){ + if(Main.plugin.glow == null || !Main.plugin.glow.isRunning()) + board.setLine("glow", "Glow: " + ChatColor.RED + "Inactive"); + else + board.setLine("glow", "Glow: " + ChatColor.GREEN + "Active"); + } + if(tauntEnabled && tauntCountdown){ + if(Main.plugin.taunt == null) + board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "0m0s"); + else if(!Main.plugin.taunt.isRunning()) + board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + Main.plugin.taunt.getDelay()/60 + "m" + Main.plugin.taunt.getDelay()%60 + "s"); + else + board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Active"); + } + if(glowEnabled || (tauntEnabled && tauntCountdown)) + board.addBlank(recreate); + board.setLine("time", "Time Left: " + ChatColor.GREEN + Main.plugin.timeLeft/60 + "m" + Main.plugin.timeLeft%60 + "s"); + board.addBlank(recreate); + board.setLine("team", "Team: " + getTeam(player)); + board.display(); + customBoards.put(player.getName(), board); } public void removeBoard(Player player) { player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard()); + customBoards.remove(player.getName()); } public void reloadLobbyBoards() { for(Player player : playerList.values()) - createLobbyBoard(player); + createLobbyBoard(player, false); } public void reloadGameBoards() { for(Player player : playerList.values()) - createGameBoard(player); + createGameBoard(player, false); + } + + public void reloadBoardTeams() { + for(CustomBoard board : customBoards.values()) + board.updateTeams(); } private String getSeekerPercent() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/CustomBoard.java b/src/main/java/net/tylermurphy/hideAndSeek/util/CustomBoard.java new file mode 100644 index 0000000..a01d965 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/CustomBoard.java @@ -0,0 +1,117 @@ +package net.tylermurphy.hideAndSeek.util; + +import net.tylermurphy.hideAndSeek.Main; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.scoreboard.*; + +import java.util.HashMap; +import java.util.Map; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; + +public class CustomBoard { + + private final Scoreboard board; + private final Objective obj; + private final Player player; + private final Map LINES; + private int blanks; + + public CustomBoard(Player player, String title){ + this.board = Bukkit.getScoreboardManager().getNewScoreboard(); + this.LINES = new HashMap(); + this.player = player; + this.obj = board.registerNewObjective( + "Scoreboard", "dummy", ChatColor.translateAlternateColorCodes('&', title)); + this.blanks = 0; + } + + public void updateTeams() { + try{ board.registerNewTeam("Hider"); } catch (Exception e){} + try{ board.registerNewTeam("Seeker"); } catch (Exception e){} + Team hiderTeam = board.getTeam("Hider"); + for(String entry : hiderTeam.getEntries()) + hiderTeam.removeEntry(entry); + for(Player player : Main.plugin.board.getHiders()) + hiderTeam.addEntry(player.getName()); + Team seekerTeam = board.getTeam("Seeker"); + for(String entry : seekerTeam.getEntries()) + seekerTeam.removeEntry(entry); + for(Player player : Main.plugin.board.getSeekers()) + seekerTeam.addEntry(player.getName()); + if(nametagsVisible) { + hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OWN_TEAM); + seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OTHER_TEAMS); + } else { + hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER); + seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER); + } + hiderTeam.setColor(ChatColor.GOLD); + seekerTeam.setColor(ChatColor.RED); + } + + public void setLine(String key, String message){ + Line line = LINES.get(key); + if(line == null) + addLine(key, message); + else + updateLine(key, message); + } + + private void addLine(String key, String message){ + Score score = obj.getScore(message); + score.setScore(LINES.values().size()+1); + Line line = new Line(LINES.values().size()+1, message); + LINES.put(key, line); + } + + public void addBlank(boolean value){ + if(!value) return; + String temp = ""; + for(int i = 0; i <= blanks; i ++) + temp += ChatColor.RESET; + blanks++; + addLine("blank"+blanks, temp); + } + + private void updateLine(String key, String message){ + Line line = LINES.get(key); + board.resetScores(line.getMessage()); + line.setMessage(message); + Score newScore = obj.getScore(message); + + newScore.setScore(line.getScore()); + } + + public void display() { + obj.setDisplaySlot(DisplaySlot.SIDEBAR); + player.setScoreboard(board); + } + +} + +class Line { + + private int score; + private String message; + + public Line(int score, String message){ + this.score = score; + this.message = message; + } + + public int getScore() { + return score; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java index 9c6c1eb..3ab04a9 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java @@ -3,14 +3,25 @@ package net.tylermurphy.hideAndSeek.util; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import java.io.*; +import java.util.ArrayList; +import java.util.List; import net.md_5.bungee.api.ChatColor; import net.tylermurphy.hideAndSeek.configuration.LocalizationString; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import net.tylermurphy.hideAndSeek.Main; +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.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.potion.PotionType; public class Util { @@ -39,27 +50,68 @@ public class Util { }, delay); } - public YamlConfiguration loadDefaultConfig(String name) { - - YamlConfiguration defaultConfig = null; - - InputStream deafult_stream = null; - InputStreamReader default_stream_reader = null; - try { - deafult_stream = Class.class.getResourceAsStream(name + ".yml"); - default_stream_reader = new InputStreamReader(deafult_stream); - defaultConfig = YamlConfiguration.loadConfiguration(default_stream_reader); - } catch (Exception e) { - // No Issue Here - } finally { - try { - deafult_stream.close(); - default_stream_reader.close(); - } catch (IOException e) { - e.printStackTrace(); - } + public static void resetPlayer(Player player) { + player.getInventory().clear(); + for (PotionEffect effect : player.getActivePotionEffects()) { + player.removePotionEffect(effect.getType()); + } + player.addPotionEffect(new PotionEffect(PotionEffectType.DOLPHINS_GRACE, 1000000, 1, false, false)); + if (Main.plugin.board.isSeeker(player)) { + ItemStack diamondSword = new ItemStack(Material.DIAMOND_SWORD, 1); + diamondSword.addEnchantment(Enchantment.DAMAGE_ALL, 1); + ItemMeta diamondSwordMeta = diamondSword.getItemMeta(); + diamondSwordMeta.setDisplayName("Seeker Sword"); + diamondSwordMeta.setUnbreakable(true); + diamondSword.setItemMeta(diamondSwordMeta); + player.getInventory().addItem(diamondSword); + + ItemStack wackyStick = new ItemStack(Material.STICK, 1); + wackyStick.addUnsafeEnchantment(Enchantment.KNOCKBACK, 3); + ItemMeta wackyStickMeta = wackyStick.getItemMeta(); + wackyStickMeta.setDisplayName("Wacky Stick"); + wackyStick.setItemMeta(wackyStickMeta); + player.getInventory().addItem(wackyStick); + + player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 1000000, 2, false, false)); + player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 1000000, 1, false, false)); + player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 1000000, 1, false, false)); + player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 1000000, 10, false, false)); + } else if (Main.plugin.board.isHider(player)) { + ItemStack stoneSword = new ItemStack(Material.STONE_SWORD, 1); + stoneSword.addEnchantment(Enchantment.DAMAGE_ALL, 2); + ItemMeta stoneSwordMeta = stoneSword.getItemMeta(); + stoneSwordMeta.setDisplayName("Hider Sword"); + stoneSwordMeta.setUnbreakable(true); + stoneSword.setItemMeta(stoneSwordMeta); + player.getInventory().addItem(stoneSword); + + ItemStack splashPotion = new ItemStack(Material.SPLASH_POTION, 1); + PotionMeta splashPotionMeta = (PotionMeta) splashPotion.getItemMeta(); + splashPotionMeta.setBasePotionData(new PotionData(PotionType.REGEN)); + splashPotion.setItemMeta(splashPotionMeta); + player.getInventory().addItem(splashPotion); + + ItemStack potion = new ItemStack(Material.POTION, 2); + PotionMeta potionMeta = (PotionMeta) potion.getItemMeta(); + potionMeta.setBasePotionData(new PotionData(PotionType.INSTANT_HEAL)); + potion.setItemMeta(potionMeta); + player.getInventory().addItem(potion); + + if(glowEnabled) { + ItemStack snowball = new ItemStack(Material.SNOWBALL, 1); + ItemMeta snowballMeta = snowball.getItemMeta(); + snowballMeta.setDisplayName("Glow Powerup"); + List snowballLore = new ArrayList(); + snowballLore.add("Throw to make all seekers glow"); + snowballLore.add("Last 30s, all hiders can see it"); + snowballLore.add("Time stacks on multi use"); + snowballMeta.setLore(snowballLore); + snowball.setItemMeta(snowballMeta); + player.getInventory().addItem(snowball); + } + + player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 1000000, 1, false, false)); } - return defaultConfig; } } \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index f826a88..457bb3a 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -54,7 +54,7 @@ worldBorder: # The taunt will activate every delay set in seconds. It will spawn a firework # on a random Hider to alert a Seeker where someone may be. You can choose # to publially show the taunt countdown, and have the taunt run with only -# one Hider left. +# one Hider left. Taunt delay must at least be 60s. taunt: delay: 360 whenLastPerson: false @@ -64,7 +64,8 @@ taunt: # The glow powerup allows all Hiders to see where every Seeker is. It last for # the amount of time set in seconds. You can allow it to be stackable, meaning # when multiple Hiders use the powerup at the same time, it stacks the times, or -# just overwrites. Only Hiders can see that the Seekers are glowing. +# just overwrites. Only Hiders can see that the Seekers are glowing. Delay must +# be longer than 1s. glow: time: 30 stackable: true From 2a526291526811841d02ff813d9b3a7752570b43 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Sun, 31 Oct 2021 11:25:27 -0400 Subject: [PATCH 04/10] 1.3.1 build 4 --- .../net/tylermurphy/hideAndSeek/Main.java | 2 + .../hideAndSeek/bukkit/EventListener.java | 19 ++- .../tylermurphy/hideAndSeek/command/Join.java | 6 +- .../hideAndSeek/command/Reload.java | 2 + .../hideAndSeek/command/SetBounds.java | 14 +- .../hideAndSeek/command/SetExitLocation.java | 15 +- .../hideAndSeek/command/SetLobbyLocation.java | 14 +- .../hideAndSeek/command/SetSpawnLocation.java | 16 +- .../hideAndSeek/configuration/Config.java | 10 +- .../configuration/ConfigManager.java | 13 +- .../hideAndSeek/configuration/Items.java | 131 ++++++++++++++++ .../configuration/Localization.java | 5 +- .../tylermurphy/hideAndSeek/util/Board.java | 15 +- .../hideAndSeek/util/CustomBoard.java | 8 +- .../tylermurphy/hideAndSeek/util/Util.java | 54 ++----- .../hideAndSeek/world/WorldLoader.java | 2 +- src/main/resources/config.yml | 141 ++++++++++-------- src/main/resources/items.yml | 87 +++++++++++ src/main/resources/localization.yml | 31 ++-- src/main/resources/plugin.yml | 4 + 20 files changed, 418 insertions(+), 171 deletions(-) create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java create mode 100644 src/main/resources/items.yml diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index 1a5570e..f5c8518 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -22,6 +22,7 @@ import net.tylermurphy.hideAndSeek.bukkit.TabCompleter; import net.tylermurphy.hideAndSeek.bukkit.Tick; import net.tylermurphy.hideAndSeek.configuration.Config; import net.tylermurphy.hideAndSeek.configuration.Localization; +import net.tylermurphy.hideAndSeek.configuration.Items; import net.tylermurphy.hideAndSeek.events.Glow; import net.tylermurphy.hideAndSeek.events.Taunt; import net.tylermurphy.hideAndSeek.events.Worldborder; @@ -63,6 +64,7 @@ public class Main extends JavaPlugin implements Listener { // Init Configuration Config.loadConfig(); Localization.loadLocalization(); + Items.loadItems(); // Create World Loader worldLoader = new WorldLoader(spawnWorld); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java index dc8b9ce..2e8eafb 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java @@ -2,6 +2,7 @@ package net.tylermurphy.hideAndSeek.bukkit; import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import net.tylermurphy.hideAndSeek.command.Join; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; @@ -38,10 +39,18 @@ public class EventListener implements Listener { event.getPlayer().setLevel(0); Main.plugin.board.remove(event.getPlayer()); if(!Util.isSetup()) return; - if(event.getPlayer().getWorld().getName().equals("hideandseek_"+spawnWorld) || event.getPlayer().getWorld().getName().equals(lobbyWorld)){ - event.getPlayer().teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); - event.getPlayer().setGameMode(GameMode.ADVENTURE); - + if(autoJoin){ + Join.join(event.getPlayer()); + } else if(teleportToExit) { + if (event.getPlayer().getWorld().getName().equals("hideandseek_" + spawnWorld) || event.getPlayer().getWorld().getName().equals(lobbyWorld)) { + event.getPlayer().teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); + event.getPlayer().setGameMode(GameMode.ADVENTURE); + } + } else { + if (event.getPlayer().getWorld().getName().equals("hideandseek_" + spawnWorld)) { + event.getPlayer().teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); + event.getPlayer().setGameMode(GameMode.ADVENTURE); + } } } @@ -90,7 +99,7 @@ public class EventListener implements Listener { } } Player player = (Player) event.getEntity(); - if(player.getHealth()-event.getDamage() < 0) { + if(player.getHealth()-event.getDamage() < 0 || !pvpEnabled) { if(spawnPosition == null) return; event.setCancelled(true); player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java index b3691bf..17b8f7a 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java @@ -30,6 +30,10 @@ public class Join implements ICommand { return; } + join(player); + } + + public static void join(Player player){ if(Main.plugin.status.equals("Standby")) { player.getInventory().clear(); Main.plugin.board.addHider(player); @@ -46,7 +50,7 @@ public class Join implements ICommand { Main.plugin.board.createGameBoard(player); player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); } - + player.setFoodLevel(20); player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue()); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java index 2c7ba04..971cd13 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java @@ -2,6 +2,7 @@ package net.tylermurphy.hideAndSeek.command; import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import net.tylermurphy.hideAndSeek.configuration.Items; import org.bukkit.command.CommandSender; import net.tylermurphy.hideAndSeek.Main; @@ -20,6 +21,7 @@ public class Reload implements ICommand { } Config.loadConfig(); Localization.loadLocalization(); + Items.loadItems(); sender.sendMessage(messagePrefix + message("CONFIG_RELOAD")); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java index 210f7fe..c94a0d1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java @@ -24,15 +24,25 @@ public class SetBounds implements ICommand { sender.sendMessage(errorPrefix + message("BOUNDS_WRONG_WORLD")); return; } + if(player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0){ + sender.sendMessage(errorPrefix + message("NOT_AT_ZERO")); + return; + } + boolean first = true; + if(saveMinX != 0 && saveMinZ != 0 && saveMaxX != 0 && saveMaxZ != 0) { + saveMinX = 0; saveMinZ= 0; saveMaxX = 0; saveMaxZ = 0; + } if(saveMaxX == 0) { addToConfig("bounds.max.x", player.getLocation().getBlockX()); saveMaxX = player.getLocation().getBlockX(); } else if(saveMaxX < player.getLocation().getBlockX()) { + first = false; addToConfig("bounds.max.x", player.getLocation().getBlockX()); addToConfig("bounds.min.x", saveMaxX); saveMinX = saveMaxX; saveMaxX = player.getLocation().getBlockX(); } else { + first = false; addToConfig("bounds.min.x", player.getLocation().getBlockX()); saveMinX = player.getLocation().getBlockX(); } @@ -40,15 +50,17 @@ public class SetBounds implements ICommand { addToConfig("bounds.max.z", player.getLocation().getBlockZ()); saveMaxZ = player.getLocation().getBlockZ(); } else if(saveMaxZ < player.getLocation().getBlockZ()) { + first = false; addToConfig("bounds.max.z", player.getLocation().getBlockZ()); addToConfig("bounds.min.z", saveMaxZ); saveMinZ = saveMaxZ; saveMaxZ = player.getLocation().getBlockZ(); } else { + first = false; addToConfig("bounds.min.z", player.getLocation().getBlockZ()); saveMinZ = player.getLocation().getBlockZ(); } - sender.sendMessage(messagePrefix + message("BOUNDS")); + sender.sendMessage(messagePrefix + message("BOUNDS").addAmount(first ? 1 : 2)); saveConfig(); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java index c9d2fae..e0b8a5d 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java @@ -15,18 +15,21 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class SetExitLocation implements ICommand { public void execute(CommandSender sender, String[] args) { - Vector newExitPosition = new Vector(); - Player player = (Player) sender; - newExitPosition.setX(player.getLocation().getBlockX()); - newExitPosition.setY(player.getLocation().getBlockY()); - newExitPosition.setZ(player.getLocation().getBlockZ()); if(!Main.plugin.status.equals("Standby")) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } + Vector newExitPosition = new Vector(); + Player player = (Player) sender; + if(player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0 || player.getLocation().getBlockY() == 0){ + sender.sendMessage(errorPrefix + message("NOT_AT_ZERO")); + return; + } + newExitPosition.setX(player.getLocation().getBlockX()); + newExitPosition.setY(player.getLocation().getBlockY()); + newExitPosition.setZ(player.getLocation().getBlockZ()); exitPosition = newExitPosition; sender.sendMessage(messagePrefix + message("EXIT_SPAWN")); - Map temp = new HashMap(); addToConfig("spawns.exit.x", exitPosition.getX()); addToConfig("spawns.exit.y", exitPosition.getY()); addToConfig("spawns.exit.z", exitPosition.getZ()); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java index a8a1887..53ae721 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java @@ -15,15 +15,19 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class SetLobbyLocation implements ICommand { public void execute(CommandSender sender, String[] args) { - Vector newLobbyPosition = new Vector(); - Player player = (Player) sender; - newLobbyPosition.setX(player.getLocation().getBlockX()); - newLobbyPosition.setY(player.getLocation().getBlockY()); - newLobbyPosition.setZ(player.getLocation().getBlockZ()); if(!Main.plugin.status.equals("Standby")) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } + Vector newLobbyPosition = new Vector(); + Player player = (Player) sender; + if(player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0 || player.getLocation().getBlockY() == 0){ + sender.sendMessage(errorPrefix + message("NOT_AT_ZERO")); + return; + } + newLobbyPosition.setX(player.getLocation().getBlockX()); + newLobbyPosition.setY(player.getLocation().getBlockY()); + newLobbyPosition.setZ(player.getLocation().getBlockZ()); lobbyPosition = newLobbyPosition; sender.sendMessage(messagePrefix + message("LOBBY_SPAWN")); addToConfig("spawns.lobby.x", lobbyPosition.getX()); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java index d634968..5324ecf 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java @@ -17,16 +17,20 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.*; public class SetSpawnLocation implements ICommand { public void execute(CommandSender sender, String[] args) { - Vector newSpawnPosition = new Vector(); - Player player = (Player) sender; - newSpawnPosition.setX(player.getLocation().getBlockX()); - newSpawnPosition.setY(player.getLocation().getBlockY()); - newSpawnPosition.setZ(player.getLocation().getBlockZ()); if(!Main.plugin.status.equals("Standby")) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } - if(worldborderEnabled && spawnPosition.distance(worldborderPosition) > 100) { + Vector newSpawnPosition = new Vector(); + Player player = (Player) sender; + if(player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0 || player.getLocation().getBlockY() == 0){ + sender.sendMessage(errorPrefix + message("NOT_AT_ZERO")); + return; + } + newSpawnPosition.setX(player.getLocation().getBlockX()); + newSpawnPosition.setY(player.getLocation().getBlockY()); + newSpawnPosition.setZ(player.getLocation().getBlockZ()); + if(worldborderEnabled && newSpawnPosition.distance(worldborderPosition) > 100) { sender.sendMessage(errorPrefix + message("WORLDBORDER_POSITION")); return; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java index 04faca2..f2b7680 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java @@ -13,7 +13,7 @@ import net.tylermurphy.hideAndSeek.Main; public class Config { - static ConfigManager manager; + private static ConfigManager manager; public static String messagePrefix, @@ -42,7 +42,10 @@ public class Config { tauntCountdown, tauntLast, glowEnabled, - glowStackable; + glowStackable, + pvpEnabled, + autoJoin, + teleportToExit; public static int minPlayers, @@ -131,6 +134,9 @@ public class Config { permissionsRequired = manager.getBoolean("permissionsRequired"); minPlayers = Math.max(2, manager.getInt("minPlayers")); gameLength = manager.getInt("gameLength"); + pvpEnabled = manager.getBoolean("pvp"); + autoJoin = manager.getBoolean("autoJoin"); + teleportToExit = manager.getBoolean("teleportToExit"); } public static void addToConfig(String path, Object value) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java index 7ea38db..df970bf 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -30,7 +30,6 @@ public class ConfigManager { input.close(); reader.close(); } catch (IOException e){} - } private void saveDefaultConfiguration(){ @@ -43,16 +42,6 @@ public class ConfigManager { } } - public void addToSection(String sectionName, Map values) { - ConfigurationSection section = config.getConfigurationSection(sectionName); - if(section == null) section = config.createSection(sectionName); - Map sectionValues = section.getValues(true); - for(Map.Entry entry : values.entrySet()) { - sectionValues.put(entry.getKey(), entry.getValue()); - } - config.createSection(sectionName, sectionValues); - } - public void addToConfig(String path, Object value) { config.set(path, value); } @@ -89,7 +78,7 @@ public class ConfigManager { if(value == false){ return defaultConfig.getBoolean(path); } else { - return value; + return true; } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java new file mode 100644 index 0000000..fbf5d2c --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java @@ -0,0 +1,131 @@ +package net.tylermurphy.hideAndSeek.configuration; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.meta.PotionMeta; +import org.bukkit.potion.*; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public class Items { + + private static ConfigManager manager; + + public static List HIDER_ITEMS, SEEKER_ITEMS; + public static List HIDER_EFFECTS, SEEKER_EFFECTS; + + public static void loadItems() { + + manager = new ConfigManager("items.yml"); + + SEEKER_ITEMS = new ArrayList(); + ConfigurationSection SeekerItems = manager.getConfigurationSection("items.seeker"); + int i = 1; + while (true) { + ConfigurationSection section = SeekerItems.getConfigurationSection(String.valueOf(i)); + if(section == null) break; + ItemStack item = createItem(section); + if(item != null) SEEKER_ITEMS.add(item); + i++; + } + + HIDER_ITEMS = new ArrayList(); + ConfigurationSection HiderItems = manager.getConfigurationSection("items.hider"); + i = 1; + while (true) { + ConfigurationSection section = HiderItems.getConfigurationSection(String.valueOf(i)); + if(section == null) break; + ItemStack item = createItem(section); + if(item != null) HIDER_ITEMS.add(item); + i++; + } + + SEEKER_EFFECTS = new ArrayList(); + ConfigurationSection SeekerEffects = manager.getConfigurationSection("effects.seeker"); + i = 1; + while (true) { + ConfigurationSection section = SeekerEffects.getConfigurationSection(String.valueOf(i)); + if(section == null) break; + PotionEffect effect = getPotionEffect(section); + if(effect != null) SEEKER_EFFECTS.add(effect); + i++; + } + + HIDER_EFFECTS = new ArrayList(); + ConfigurationSection HiderEffects = manager.getConfigurationSection("effects.hider"); + i = 1; + while (true) { + ConfigurationSection section = HiderEffects.getConfigurationSection(String.valueOf(i)); + if(section == null) break; + PotionEffect effect = getPotionEffect(section); + if(effect != null) HIDER_EFFECTS.add(effect); + i++; + } + + } + + private static ItemStack createItem(ConfigurationSection item) { + String material_string = item.getString("material"); + if(material_string == null) return null; + Material material = Material.valueOf(material_string.toUpperCase()); + int amount = item.getInt("amount"); + ItemStack stack = new ItemStack(material, amount); + if(material == Material.POTION || material == Material.SPLASH_POTION || material == Material.LINGERING_POTION){ + PotionMeta meta = getPotionMeta(stack, item); + stack.setItemMeta(meta); + } else { + ConfigurationSection enchantments = item.getConfigurationSection("enchantments"); + if (enchantments != null) + for (String enchantment_string : enchantments.getKeys(false)) { + Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft(enchantment_string)); + if (enchantment == null) continue; + stack.addUnsafeEnchantment( + enchantment, + enchantments.getInt(enchantment_string) + ); + } + ItemMeta meta = getItemMeta(stack,item); + stack.setItemMeta(meta); + } + return stack; + } + + private static ItemMeta getItemMeta(ItemStack stack, ConfigurationSection item){ + ItemMeta meta = stack.getItemMeta(); + assert meta != null; + String name = item.getString("name"); + if(name != null) + meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); + meta.setUnbreakable(item.getBoolean("unbreakable")); + meta.setLore(item.getStringList("lore")); + return meta; + } + + private static PotionMeta getPotionMeta(ItemStack stack, ConfigurationSection item){ + String type = item.getString("type"); + PotionMeta meta = (PotionMeta) stack.getItemMeta(); + if(type==null) return meta; + assert meta != null; + meta.setBasePotionData(new PotionData((PotionType.valueOf(type.toUpperCase())))); + return meta; + } + + private static PotionEffect getPotionEffect(ConfigurationSection item){ + String type = item.getString("type"); + if(type == null) return null; + return new PotionEffect( + Objects.requireNonNull(PotionEffectType.getByName(type.toUpperCase())), + item.getInt("duration"), + item.getInt("amplifier"), + item.getBoolean("ambient"), + item.getBoolean("particles") + ); + } +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java index 82d19d4..9980a4e 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java @@ -21,7 +21,8 @@ public class Localization { public static boolean loadLocalization() { manager = new ConfigManager("localization.yml"); - + manager.saveConfig(); + for(String key : manager.getConfigurationSection("Localization").getKeys(false)) { LOCAL.put( key, @@ -29,8 +30,6 @@ public class Localization { ); } - manager.saveConfig(); - return true; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java index 59b9ac8..80cbdee 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java @@ -159,9 +159,9 @@ public class Board { } board.setLine("hiders", ChatColor.BOLD + "" + ChatColor.YELLOW + "HIDER%" + ChatColor.WHITE + getHiderPercent()); board.setLine("seekers", ChatColor.BOLD + "" + ChatColor.RED + "SEEKER%" + ChatColor.WHITE + getSeekerPercent()); - board.addBlank(recreate); + board.addBlank(); board.setLine("players", "Players: " + playerList.values().size()); - board.addBlank(recreate); + board.addBlank(); board.setLine("waiting", "Waiting to start..."); board.display(); customBoards.put(player.getName(), board); @@ -175,11 +175,10 @@ public class Board { CustomBoard board = customBoards.get(player.getName()); if(recreate) { board = new CustomBoard(player, "&l&eHIDE AND SEEK"); - board.updateTeams(); } board.setLine("hiders", ChatColor.BOLD + "" + ChatColor.YELLOW + "HIDERS:" + ChatColor.WHITE + " " + Hider.size()); board.setLine("seekers", ChatColor.BOLD + "" + ChatColor.RED + "SEEKERS:" + ChatColor.WHITE + " " + Seeker.size()); - board.addBlank(recreate); + board.addBlank(); if(glowEnabled){ if(Main.plugin.glow == null || !Main.plugin.glow.isRunning()) board.setLine("glow", "Glow: " + ChatColor.RED + "Inactive"); @@ -189,15 +188,17 @@ public class Board { if(tauntEnabled && tauntCountdown){ if(Main.plugin.taunt == null) board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "0m0s"); - else if(!Main.plugin.taunt.isRunning()) + else if(!tauntLast && Hider.size() == 1){ + board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Expired"); + } else if(!Main.plugin.taunt.isRunning()) board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + Main.plugin.taunt.getDelay()/60 + "m" + Main.plugin.taunt.getDelay()%60 + "s"); else board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Active"); } if(glowEnabled || (tauntEnabled && tauntCountdown)) - board.addBlank(recreate); + board.addBlank(); board.setLine("time", "Time Left: " + ChatColor.GREEN + Main.plugin.timeLeft/60 + "m" + Main.plugin.timeLeft%60 + "s"); - board.addBlank(recreate); + board.addBlank(); board.setLine("team", "Team: " + getTeam(player)); board.display(); customBoards.put(player.getName(), board); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/CustomBoard.java b/src/main/java/net/tylermurphy/hideAndSeek/util/CustomBoard.java index a01d965..69d865a 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/CustomBoard.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/CustomBoard.java @@ -18,6 +18,7 @@ public class CustomBoard { private final Player player; private final Map LINES; private int blanks; + private boolean displayed; public CustomBoard(Player player, String title){ this.board = Bukkit.getScoreboardManager().getNewScoreboard(); @@ -26,6 +27,8 @@ public class CustomBoard { this.obj = board.registerNewObjective( "Scoreboard", "dummy", ChatColor.translateAlternateColorCodes('&', title)); this.blanks = 0; + this.displayed = false; + this.updateTeams(); } public void updateTeams() { @@ -67,8 +70,8 @@ public class CustomBoard { LINES.put(key, line); } - public void addBlank(boolean value){ - if(!value) return; + public void addBlank(){ + if(displayed) return; String temp = ""; for(int i = 0; i <= blanks; i ++) temp += ChatColor.RESET; @@ -86,6 +89,7 @@ public class CustomBoard { } public void display() { + displayed = true; obj.setDisplaySlot(DisplaySlot.SIDEBAR); player.setScoreboard(board); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java index 3ab04a9..c24936b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Util.java @@ -7,6 +7,7 @@ import java.util.ArrayList; import java.util.List; import net.md_5.bungee.api.ChatColor; +import net.tylermurphy.hideAndSeek.configuration.Items; import net.tylermurphy.hideAndSeek.configuration.LocalizationString; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -55,48 +56,18 @@ public class Util { for (PotionEffect effect : player.getActivePotionEffects()) { player.removePotionEffect(effect.getType()); } - player.addPotionEffect(new PotionEffect(PotionEffectType.DOLPHINS_GRACE, 1000000, 1, false, false)); if (Main.plugin.board.isSeeker(player)) { - ItemStack diamondSword = new ItemStack(Material.DIAMOND_SWORD, 1); - diamondSword.addEnchantment(Enchantment.DAMAGE_ALL, 1); - ItemMeta diamondSwordMeta = diamondSword.getItemMeta(); - diamondSwordMeta.setDisplayName("Seeker Sword"); - diamondSwordMeta.setUnbreakable(true); - diamondSword.setItemMeta(diamondSwordMeta); - player.getInventory().addItem(diamondSword); - - ItemStack wackyStick = new ItemStack(Material.STICK, 1); - wackyStick.addUnsafeEnchantment(Enchantment.KNOCKBACK, 3); - ItemMeta wackyStickMeta = wackyStick.getItemMeta(); - wackyStickMeta.setDisplayName("Wacky Stick"); - wackyStick.setItemMeta(wackyStickMeta); - player.getInventory().addItem(wackyStick); - - player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 1000000, 2, false, false)); - player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 1000000, 1, false, false)); - player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 1000000, 1, false, false)); - player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 1000000, 10, false, false)); + if(pvpEnabled) + for(ItemStack item : Items.SEEKER_ITEMS) + player.getInventory().addItem(item); + for(PotionEffect effect : Items.SEEKER_EFFECTS) + player.addPotionEffect(effect); } else if (Main.plugin.board.isHider(player)) { - ItemStack stoneSword = new ItemStack(Material.STONE_SWORD, 1); - stoneSword.addEnchantment(Enchantment.DAMAGE_ALL, 2); - ItemMeta stoneSwordMeta = stoneSword.getItemMeta(); - stoneSwordMeta.setDisplayName("Hider Sword"); - stoneSwordMeta.setUnbreakable(true); - stoneSword.setItemMeta(stoneSwordMeta); - player.getInventory().addItem(stoneSword); - - ItemStack splashPotion = new ItemStack(Material.SPLASH_POTION, 1); - PotionMeta splashPotionMeta = (PotionMeta) splashPotion.getItemMeta(); - splashPotionMeta.setBasePotionData(new PotionData(PotionType.REGEN)); - splashPotion.setItemMeta(splashPotionMeta); - player.getInventory().addItem(splashPotion); - - ItemStack potion = new ItemStack(Material.POTION, 2); - PotionMeta potionMeta = (PotionMeta) potion.getItemMeta(); - potionMeta.setBasePotionData(new PotionData(PotionType.INSTANT_HEAL)); - potion.setItemMeta(potionMeta); - player.getInventory().addItem(potion); - + if(pvpEnabled) + for(ItemStack item : Items.HIDER_ITEMS) + player.getInventory().addItem(item); + for(PotionEffect effect : Items.HIDER_EFFECTS) + player.addPotionEffect(effect); if(glowEnabled) { ItemStack snowball = new ItemStack(Material.SNOWBALL, 1); ItemMeta snowballMeta = snowball.getItemMeta(); @@ -109,9 +80,6 @@ public class Util { snowball.setItemMeta(snowballMeta); player.getInventory().addItem(snowball); } - - player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 1000000, 1, false, false)); } } - } \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java index cfb85bf..5a8c324 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java @@ -35,7 +35,7 @@ public class WorldLoader { public void loadMap(){ Bukkit.getServer().createWorld(new WorldCreator(savename).generator(new VoidGenerator())); - Bukkit.getServer().getWorld(savename).setAutoSave(false); + Bukkit.getServer().getWorld(savename).setAutoSave(false); } public void rollback(){ diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 457bb3a..64fdece 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -10,14 +10,90 @@ announceMessagesToNonPlayers: true # default: false nametagsVisible: false -# Require bukkit permessions though a plugin to run commands, recomended on large servers +# Require bukkit permissions though a plugin to run commands, recommended on large servers # default: true permissionsRequired: true -# Minimum ammount of players to start the game. Cannot go lower than 2. +# Minimum amount of players to start the game. Cannot go lower than 2. # default: 2 minPlayers: 2 +# This plugin by default functions as not tag to catch Hiders, but to pvp. All players are given weapons, +# and seekers slightly better weapons (this can be changed in items.yml). If you want, you can disable this +# entire pvp functionality, and make Hiders get found on a single hit. Hiders would also not be able to fight +# back against Seekers if disabled. +# default: true +pvp: true + +# Players that join the server will automatically be placed into the lobby. +# default: false +autoJoin: false + +# (When autoJoin is false), when players join the world containing the lobby, they are automatically teleported +# to the designated exit position so that they possibly don't spawn in the lobby while not in the queue. Anyone +# who ever joins in the game world (the duplicated world where the game is played) will always be teleported +# out regardless. +# default: false +teleportToExit: false + +# The worldborder closes every interval, which is evey [delay] in minutes. +# Thw worldborder starts at [size], and decreases 100 blocks every interval. +# x & z are the center location. [enabled] is whenever the border is enabled. +# You can choose if Hiders are warned 30 seconds before the border moves. +worldBorder: + x: 0 + z: 0 + delay: 10 + size: 500 + warn: true + enabled: false + +# The taunt will activate every delay set in seconds. It will spawn a firework +# on a random Hider to alert a Seeker where someone may be. You can choose +# to publicly show the taunt countdown, and have the taunt run with only +# one Hider left. Taunt delay must at least be 60s. +taunt: + delay: 360 + whenLastPerson: false + showCountdown: true + enabled: true + +# The glow powerup allows all Hiders to see where every Seeker is. It last for +# the amount of time set in seconds. You can allow it to be stackable, meaning +# when multiple Hiders use the powerup at the same time, it stacks the times, or +# just overwrites. Only Hiders can see that the Seekers are glowing. Delay must +# be longer than 1s. +glow: + time: 30 + stackable: true + enabled: true + +# The message prefixes displayed before messages. The message contents themselves +# can be changed in localization.yml. +prefix: + default: '&9Hide and Seek > &f' + error: '&cError > &f' + taunt: '&eTaunt > &f' + border: '&cWorld Border > &f' + abort: '&cAbort > &f' + gameover: '&aGame Over > &f' + warning: '&cWarning > &f' + +# ---------------------------------------------------------- # +# ONLY EDIT BEYOND THIS POINT IF YOU KNOW WHAT YOU ARE DOING # +# ---------------------------------------------------------- # + +# The 2 coordinate bounds that will contain your hideAndSeek map. Its recommended +# that you use /hs setbounds for this, and not edit this directly, as breaking +# this section will completely break the entire plugin when you run /hs mapsave. +bounds: + min: + x: 0 + z: 0 + max: + x: 0 + z: 0 + # Spawn locations where players are teleported spawns: # Location where players are teleported into the game (/hs start) @@ -37,63 +113,4 @@ spawns: x: 0 y: 0 z: 0 - world: world - -# The worldborder closes every interval, whish is evey [delay] in minutes. -# Thw worldborder stharts at [size], and decreaces 100 blocks every interval. -# x & z are the center location. [enabled] is whenever the border is enabled. -# You can choose if Hiders are warned 30 seconds before the border moves. -worldBorder: - x: 0 - z: 0 - delay: 10 - size: 500 - warn: true - enabled: false - -# The taunt will activate every delay set in seconds. It will spawn a firework -# on a random Hider to alert a Seeker where someone may be. You can choose -# to publially show the taunt countdown, and have the taunt run with only -# one Hider left. Taunt delay must at least be 60s. -taunt: - delay: 360 - whenLastPerson: false - showCountdown: true - enabled: true - -# The glow powerup allows all Hiders to see where every Seeker is. It last for -# the amount of time set in seconds. You can allow it to be stackable, meaning -# when multiple Hiders use the powerup at the same time, it stacks the times, or -# just overwrites. Only Hiders can see that the Seekers are glowing. Delay must -# be longer than 1s. -glow: - time: 30 - stackable: true - enabled: true - -# The message prefixes displayed before messages. The message contents themselvs -# can be changed in localization.yml. -prefix: - default: '&9Hide and Seek > &f' - error: '&cError > &f' - taunt: '&eTaunt > &f' - border: '&cWorld Border > &f' - abort: '&cAbort > &f' - gameover: '&aGame Over > &f' - warning: '&cWarning > &f' - -# ---------------------------------------------------------- # -# ONLY EDIT BEYOND THIS POINT IF YOU KNOW WHAT YOU ARE DOING # -# ---------------------------------------------------------- # - -# The 2 coordinate bounds that will contain your hideAndSeek map. Its reccomended -# that you use /hs setbounds for this, and not edit this directly, as breaking -# this section will completly break the entire plugin when you run /hs mapsave. -bounds: - min: - x: 0 - z: 0 - max: - x: 0 - z: 0 - + world: world \ No newline at end of file diff --git a/src/main/resources/items.yml b/src/main/resources/items.yml new file mode 100644 index 0000000..d9b3b2a --- /dev/null +++ b/src/main/resources/items.yml @@ -0,0 +1,87 @@ +# For materials, look at https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html +# For potion types, look at https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/potion/PotionType.html +# For effects, look at https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/potion/PotionEffectType.html +# If pvp is disabled in config.yml, only effects will be given to players. +items: + seeker: + '1': + material: DIAMOND_SWORD + amount: 1 + enchantments: + sharpness: 1 + name: 'Seeker Sword' + unbreakable: true + lore: + - 'This is the seeker sword' + '2': + material: STICK + amount: 1 + enchantments: + knockback: 3 + name: 'Wacky Stick' + lore: + - 'It will launch people very far' + - 'Use wisely!' + hider: + '1': + material: STONE_SWORD + amount: 1 + enchantments: + sharpness: 2 + name: 'Hider Sword' + unbreakable: true + lore: + - 'This is the hider sword' + '2': + material: SPLASH_POTION + amount: 1 + type: REGEN + '3': + material: POTION + amount: 2 + type: INSTANT_HEAL + '4': + type: DOLPHINS_GRACE + duration: 1000000 + amplifier: 1 + ambient: false + particles: false +effects: + seeker: + '1': + type: SPEED + duration: 1000000 + amplifier: 2 + ambient: false + particles: false + '2': + type: JUMP + duration: 1000000 + amplifier: 1 + ambient: false + particles: false + '3': + type: SLOW_FALLING + duration: 1000000 + amplifier: 1 + ambient: false + particles: false + '4': + type: WATER_BREATHING + duration: 1000000 + amplifier: 10 + ambient: false + particles: false + hider: + '1': + type: WATER_BREATHING + duration: 1000000 + amplifier: 1 + ambient: false + particles: false + '2': + type: DOLPHINS_GRACE + duration: 1000000 + amplifier: 1 + ambient: false + particles: false \ No newline at end of file diff --git a/src/main/resources/localization.yml b/src/main/resources/localization.yml index e714046..f6a82dc 100644 --- a/src/main/resources/localization.yml +++ b/src/main/resources/localization.yml @@ -1,7 +1,7 @@ Localization: COMMAND_PLAYER_ONLY: "This command can only be run as a player." COMMAND_NOT_ALLOWED: "You are not allowed to run this command." - COMMAND_ERROR: "An internal error has occoured." + COMMAND_ERROR: "An internal error has occurred." GAME_PLAYER_DEATH: "&c{PLAYER}&f was killed." GAME_PLAYER_FOUND: "&e{PLAYER}&f was found and became a seeker." GAME_PLAYER_FOUND_BY: "&e{PLAYER}&f was found by &c{PLAYER}&f and became a seeker." @@ -11,32 +11,32 @@ Localization: GAME_SETUP: "Game is not setup. Run /hs setup to see what you need to do." GAME_INGAME: "You are already in the lobby/game." GAME_NOT_INGAME: "You are not in a lobby/game." - GAME_INPROGRESS: "There is currently a game inprogress." - GAME_NOT_INPROGRESS: "There is no game inprogress." + GAME_INPROGRESS: "There is currently a game in progress." + GAME_NOT_INPROGRESS: "There is no game in progress." GAME_JOIN: "{PLAYER} has joined the HideAndSeek lobby." - GAME_JOIN_SPECTATOR: "You have joined midgame and are now a spectator." + GAME_JOIN_SPECTATOR: "You have joined mid game and are now a spectator." GAME_LEAVE: "{PLAYER} has left the HideAndSeek lobby." CONFIG_RELOAD: "Reloaded the config." MAPSAVE_INPROGRESS: "Map save is currently in progress. Try again later." MAPSAVE_START: "Starting map save." MAPSAVE_WARNING: "All commands will be disabled when the save is in progress. Do not turn off the server." MAPSAVE_END: "Map save complete." - MAPSAVE_ERROR: "Coudnt find current map." - WORLDBORDER_DISABLE: "Disabled worldborder." + MAPSAVE_ERROR: "Couldn't find current map." + WORLDBORDER_DISABLE: "Disabled world border." WORLDBORDER_INVALID_INPUT: "Invalid integer {AMOUNT}." - WORLDBORDER_MIN_SIZE: "Worldborder cannot be smaller than 100 blocks." - WORLDBORDER_POSITION: "Spawn position must be 100 from worldborder center." + WORLDBORDER_MIN_SIZE: "World border cannot be smaller than 100 blocks." + WORLDBORDER_POSITION: "Spawn position must be 100 from world border center." WORLDBORDER_ENABLE: "Set border center to current location, size to {AMOUNT}, and delay to {AMOUNT}." - WORLDBORDER_DECREASING: "Worlderborder decreasing by 100 blocks over the next 30s." + WORLDBORDER_DECREASING: "Would border decreasing by 100 blocks over the next 30s." TAUNTED: "$c$oOh no! You have been chosen to be taunted." TAUNT: "A random hider will be taunted in the next 30s." TAUNT_ACTIVATE: "Taunt has been activated." ERROR_GAME_SPAWN: "Please set game spawn location first" SETUP: "&f&lThe following is needed for setup..." - SETUP_GAME: "&c&l- &fGame spawn isnt set, /hs setspawn" - SETUP_LOBBY: "&c&l- &fLobby spawn isnt set, /hs setlobby" - SETUP_EXIT: "&c&l- &fQuit/exit teleport location isnt set, /hs setexit" - SETUP_SAVEMAP: "&c&l- &fHide and seek map isnt saved, /hs savemap (after /hs setspawn)" + SETUP_GAME: "&c&l- &fGame spawn isn't set, /hs setspawn" + SETUP_LOBBY: "&c&l- &fLobby spawn isn't set, /hs setlobby" + SETUP_EXIT: "&c&l- &fQuit/exit teleport location isn't set, /hs setexit" + SETUP_SAVEMAP: "&c&l- &fHide and seek map isn't saved, /hs savemap (after /hs setspawn)" SETUP_BOUNDS: "&c&l- &fPlease set game bounds in 2 opposite corners of the game map, /hs setbounds" SETUP_COMPLETE: "Everything is setup and ready to go!" GAME_SPAWN: "Set game spawn position to current location" @@ -45,9 +45,10 @@ Localization: START_MIN_PLAYERS: "You must have at least {AMOUNT} players to start." START_INVALID_NAME: "Invalid player: {PLAYER}." START_COUNTDOWN: "Hiders have {AMOUNT} seconds to hide!" - START: "Attetion SEEKERS, its time to fin the hiders!" + START: "Attention SEEKERS, its time to fin the hiders!" STOP: "Game has been force stopped." HIDERS_SUBTITLE: "Hide away from the seekers" SEEKERS_SUBTITLE: "Eliminate all hiders" BOUNDS_WRONG_WORLD: "Please run this command in the game world." - BOUNDS: "Sucessfully set bounds at this position." + BOUNDS: "Successfully set bounds at this position ({AMOUNT}/2)." + NOT_AT_ZERO: "Please do not set at a location containing a coordinate at 0." diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 2f6b145..ad5b2e3 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -21,6 +21,7 @@ permissions: hideandseek.setspawn: true hideandseek.setlobby: true hideandseek.setexit: true + hideadnseek.setbounds: true hideandseek.setup: true hideandseek.start: true hideandseek.stop: true @@ -48,6 +49,9 @@ permissions: hideandseek.setexit: description: Allows you to set the game exit point default: op + hideandseek.setbounds: + description: Allows you to set bounds for the game map + default: op hideandseek.setup: description: Allows you to see what needs to be setup for the plugin to function default: op From 72f093b243c07766d1cce808c9a0fccb30227b9d Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 8 Nov 2021 15:53:13 -0500 Subject: [PATCH 05/10] 1.3.1 build 6 --- HideAndSeekPlugin.iml | 12 ++++ pom.xml | 16 +---- .../net/tylermurphy/hideAndSeek/Main.java | 16 ++--- .../hideAndSeek/bukkit/EventListener.java | 70 ++++++++++--------- .../tylermurphy/hideAndSeek/bukkit/Tick.java | 8 ++- .../configuration/ConfigManager.java | 1 + .../tylermurphy/hideAndSeek/events/Glow.java | 18 +++-- .../tylermurphy/hideAndSeek/events/Taunt.java | 63 ++++++++--------- .../hideAndSeek/events/Worldborder.java | 32 ++++++--- .../tylermurphy/hideAndSeek/util/Board.java | 15 +++- 10 files changed, 137 insertions(+), 114 deletions(-) create mode 100644 HideAndSeekPlugin.iml diff --git a/HideAndSeekPlugin.iml b/HideAndSeekPlugin.iml new file mode 100644 index 0000000..fa63d4b --- /dev/null +++ b/HideAndSeekPlugin.iml @@ -0,0 +1,12 @@ + + + + + + + SPIGOT + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index e0cca85..4d9cd0f 100644 --- a/pom.xml +++ b/pom.xml @@ -1,14 +1,8 @@ - - - 4.0.0 - +4.0.0 net.tylermurphy HideAndSeek 1.3.1 Hide and Seek Plugin - @@ -22,7 +16,6 @@ - spigot-repo @@ -33,7 +26,6 @@ https://repo.dmulloy2.net/repository/public/ - org.spigotmc @@ -48,10 +40,4 @@ 4.7.0 - - - 11 - 11 - - \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index f5c8518..4815a30 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -77,15 +77,13 @@ public class Main extends JavaPlugin implements Listener { board.reload(); // Start Tick Timer - onTickTask = Bukkit.getServer().getScheduler().runTaskTimer(this, new Runnable(){ - public void run(){ - try{ - Tick.onTick(); - } catch (Exception e) { - e.printStackTrace(); - } - } - },0,1); + onTickTask = Bukkit.getServer().getScheduler().runTaskTimer(this, () -> { + try{ + Tick.onTick(); + } catch (Exception e) { + e.printStackTrace(); + } + },0,1); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java index 2e8eafb..ffad241 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java @@ -82,43 +82,47 @@ public class EventListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST) public void onEntityDamage(EntityDamageEvent event) { - if(event.getEntity() instanceof Player) { - Player p = (Player) event.getEntity(); - if(!Main.plugin.board.isPlayer(p)) return; - if(!Main.plugin.status.equals("Playing")) { - event.setCancelled(true); - return; - } - Player attacker = null; - if(event instanceof EntityDamageByEntityEvent) { - Entity damager = ((EntityDamageByEntityEvent)event).getDamager(); - if(damager instanceof Player) { - attacker = (Player) damager; - if(Main.plugin.board.onSameTeam(p, attacker)) event.setCancelled(true); - if(Main.plugin.board.isSpectator(p)) event.setCancelled(true); - } - } - Player player = (Player) event.getEntity(); - if(player.getHealth()-event.getDamage() < 0 || !pvpEnabled) { - if(spawnPosition == null) return; - event.setCancelled(true); - player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); - player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ())); - Packet.playSound(player, Sound.ENTITY_PLAYER_DEATH, 1, 1); - if(Main.plugin.board.isSeeker(player)) { - Bukkit.broadcastMessage(message("GAME_PLAYER_DEATH").addPlayer(event.getEntity()).toString()); + try { + if (event.getEntity() instanceof Player) { + Player p = (Player) event.getEntity(); + if (!Main.plugin.board.isPlayer(p)) return; + if (!Main.plugin.status.equals("Playing")) { + event.setCancelled(true); + return; } - if(Main.plugin.board.isHider(player)) { - if(attacker == null) { - Util.broadcastMessage(message("GAME_PLAYER_FOUND").addPlayer(event.getEntity()).toString()); - } else { - Util.broadcastMessage(message("GAME_PLAYER_FOUND_BY").addPlayer(event.getEntity()).addPlayer(attacker).toString()); + Player attacker = null; + if (event instanceof EntityDamageByEntityEvent) { + Entity damager = ((EntityDamageByEntityEvent) event).getDamager(); + if (damager instanceof Player) { + attacker = (Player) damager; + if (Main.plugin.board.onSameTeam(p, attacker)) event.setCancelled(true); + if (Main.plugin.board.isSpectator(p)) event.setCancelled(true); } - Main.plugin.board.addSeeker(player); } - Util.resetPlayer(player); - Main.plugin.board.reloadBoardTeams(); + Player player = (Player) event.getEntity(); + if (player.getHealth() - event.getDamage() < 0 || !pvpEnabled) { + if (spawnPosition == null) return; + event.setCancelled(true); + player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); + player.teleport(new Location(Bukkit.getWorld("hideandseek_" + spawnWorld), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ())); + Packet.playSound(player, Sound.ENTITY_PLAYER_DEATH, 1, 1); + if (Main.plugin.board.isSeeker(player)) { + Bukkit.broadcastMessage(message("GAME_PLAYER_DEATH").addPlayer(event.getEntity()).toString()); + } + if (Main.plugin.board.isHider(player)) { + if (attacker == null) { + Util.broadcastMessage(message("GAME_PLAYER_FOUND").addPlayer(event.getEntity()).toString()); + } else { + Util.broadcastMessage(message("GAME_PLAYER_FOUND_BY").addPlayer(event.getEntity()).addPlayer(attacker).toString()); + } + Main.plugin.board.addSeeker(player); + } + Util.resetPlayer(player); + Main.plugin.board.reloadBoardTeams(); + } } + } catch (Exception e){ + //Has shown to cause problems, so ignore if exception } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/Tick.java b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/Tick.java index eadcf14..8efbe80 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/Tick.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/Tick.java @@ -40,9 +40,13 @@ public class Tick { else tick = 1; for(Player hider : Main.plugin.board.getHiders()) { - int distance = 100; + int distance = 100, temp = 100; for(Player seeker : Main.plugin.board.getSeekers()) { - int temp = (int) hider.getLocation().distance(seeker.getLocation()); + try { + temp = (int) hider.getLocation().distance(seeker.getLocation()); + } catch (Exception e){ + //Players in different worlds, NOT OK!!! + } if(distance > temp) { distance = temp; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java index df970bf..09b3dcf 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -125,6 +125,7 @@ public class ConfigManager { if(index == -1) continue;; int start = yamlString.indexOf(' ', index); int end = yamlString.indexOf('\n', index); + if(end == -1) end = yamlString.length(); String replace = entry.getValue().toString(); if(entry.getValue() instanceof String){ replace = "\"" + replace + "\""; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/events/Glow.java b/src/main/java/net/tylermurphy/hideAndSeek/events/Glow.java index 6ea5ab8..a817df3 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/events/Glow.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/events/Glow.java @@ -37,16 +37,14 @@ public class Glow { } private void waitGlow() { - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, new Runnable() { - public void run() { - if(temp != Main.plugin.gameId) return; - glowTime--; - glowTime = Math.max(glowTime, 0); - if(glowTime == 0) { - stopGlow(); - } else { - waitGlow(); - } + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, () -> { + if(temp != Main.plugin.gameId) return; + glowTime--; + glowTime = Math.max(glowTime, 0); + if(glowTime == 0) { + stopGlow(); + } else { + waitGlow(); } }, 20); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java b/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java index 748ae40..d24c93f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java @@ -32,20 +32,19 @@ public class Taunt { } private void waitTaunt() { - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, new Runnable() { - public void run() { - if(delay == 0) { - if(!tauntLast && Main.plugin.board.size() < 2) return; - else executeTaunt(); - } else { - delay--; - waitTaunt(); - } + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, () -> { + if(delay == 0) { + if(!tauntLast && Main.plugin.board.size() < 2) return; + else executeTaunt(); + } else { + delay--; + waitTaunt(); } },20); } private void executeTaunt() { + if(temp != Main.plugin.gameId) return; Player taunted = null; int rand = (int) (Math.random()*Main.plugin.board.sizeHider()); for(Player player : Main.plugin.board.getPlayers()) { @@ -62,31 +61,29 @@ public class Taunt { taunted.sendMessage(message("TAUNTED").toString()); Util.broadcastMessage(tauntPrefix + message("TAUNT")); tauntPlayer = taunted.getName(); - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, new Runnable() { - public void run() { - if(temp != Main.plugin.gameId) return; - Player taunted = Main.plugin.board.getPlayer(tauntPlayer); - if(taunted != null) { - Firework fw = (Firework) taunted.getLocation().getWorld().spawnEntity(taunted.getLocation(), EntityType.FIREWORK); - FireworkMeta fwm = fw.getFireworkMeta(); - fwm.setPower(4); - fwm.addEffect(FireworkEffect.builder() - .withColor(Color.BLUE) - .withColor(Color.RED) - .withColor(Color.YELLOW) - .with(FireworkEffect.Type.STAR) - .with(FireworkEffect.Type.BALL) - .with(FireworkEffect.Type.BALL_LARGE) - .flicker(true) - .withTrail() - .build()); - fw.setFireworkMeta(fwm); - Util.broadcastMessage(tauntPrefix + message("TAUNT_ACTIVATE")); - } - tauntPlayer = ""; - running = false; - schedule(); + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, () -> { + if(temp != Main.plugin.gameId) return; + Player taunted1 = Main.plugin.board.getPlayer(tauntPlayer); + if(taunted1 != null) { + Firework fw = (Firework) taunted1.getLocation().getWorld().spawnEntity(taunted1.getLocation(), EntityType.FIREWORK); + FireworkMeta fwm = fw.getFireworkMeta(); + fwm.setPower(4); + fwm.addEffect(FireworkEffect.builder() + .withColor(Color.BLUE) + .withColor(Color.RED) + .withColor(Color.YELLOW) + .with(FireworkEffect.Type.STAR) + .with(FireworkEffect.Type.BALL) + .with(FireworkEffect.Type.BALL_LARGE) + .flicker(true) + .withTrail() + .build()); + fw.setFireworkMeta(fwm); + Util.broadcastMessage(tauntPrefix + message("TAUNT_ACTIVATE")); } + tauntPlayer = ""; + running = false; + schedule(); },20*30); } else { schedule(); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/events/Worldborder.java b/src/main/java/net/tylermurphy/hideAndSeek/events/Worldborder.java index 5884a94..5d0e48c 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/events/Worldborder.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/events/Worldborder.java @@ -13,32 +13,38 @@ import net.tylermurphy.hideAndSeek.util.Util; public class Worldborder { private final int temp; + private int delay; + private boolean running; public Worldborder(int temp) { this.temp = temp; } public void schedule() { - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, new Runnable() { - public void run() { - decreaceWorldborder(); + delay = 60*worldborderDelay; + running = false; + waitBorder(); + } + + private void waitBorder(){ + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, () -> { + if(delay == 0) decreaceWorldborder(); + else { + delay--; waitBorder(); } - },20*60*worldborderDelay); + }, 20); } private void decreaceWorldborder() { if(temp != Main.plugin.gameId) return; if(currentWorldborderSize-100 > 100) { + running = true; Util.broadcastMessage(worldborderPrefix + message("WORLDBORDER_DECREASING")); currentWorldborderSize -= 100; World world = Bukkit.getWorld("hideandseek_"+spawnWorld); WorldBorder border = world.getWorldBorder(); border.setSize(border.getSize()-100,30); - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, new Runnable() { - public void run() { - decreaceWorldborder(); - } - },20*60*worldborderDelay); + schedule(); } } @@ -56,5 +62,13 @@ public class Worldborder { border.setCenter(0, 0); } } + + public int getDelay(){ + return delay; + } + + public boolean isRunning() { + return running; + } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java index 80cbdee..9d856b5 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java @@ -180,13 +180,13 @@ public class Board { board.setLine("seekers", ChatColor.BOLD + "" + ChatColor.RED + "SEEKERS:" + ChatColor.WHITE + " " + Seeker.size()); board.addBlank(); if(glowEnabled){ - if(Main.plugin.glow == null || !Main.plugin.glow.isRunning()) + if(Main.plugin.glow == null || Main.plugin.status.equals("Starting") || !Main.plugin.glow.isRunning()) board.setLine("glow", "Glow: " + ChatColor.RED + "Inactive"); else board.setLine("glow", "Glow: " + ChatColor.GREEN + "Active"); } if(tauntEnabled && tauntCountdown){ - if(Main.plugin.taunt == null) + if(Main.plugin.taunt == null || Main.plugin.status.equals("Starting")) board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "0m0s"); else if(!tauntLast && Hider.size() == 1){ board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Expired"); @@ -195,7 +195,16 @@ public class Board { else board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Active"); } - if(glowEnabled || (tauntEnabled && tauntCountdown)) + if(worldborderEnabled){ + if(Main.plugin.worldborder == null || Main.plugin.status.equals("Starting")){ + board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + "0m0s"); + } else if(!Main.plugin.worldborder.isRunning()) { + board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + Main.plugin.worldborder.getDelay()/60 + "m" + Main.plugin.worldborder.getDelay()%60 + "s"); + } else { + board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + "Decreasing"); + } + } + if(glowEnabled || (tauntEnabled && tauntCountdown) || worldborderEnabled) board.addBlank(); board.setLine("time", "Time Left: " + ChatColor.GREEN + Main.plugin.timeLeft/60 + "m" + Main.plugin.timeLeft%60 + "s"); board.addBlank(); From 609f7204d1d171478ae9afe8420efdc0e49eefaf Mon Sep 17 00:00:00 2001 From: HerrMelodious <88331632+HerrMelodious@users.noreply.github.com> Date: Mon, 20 Dec 2021 20:36:50 +0100 Subject: [PATCH 06/10] Create localization_de-DE.yml --- src/main/resource/lang/localization_de-DE.yml | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/main/resource/lang/localization_de-DE.yml diff --git a/src/main/resource/lang/localization_de-DE.yml b/src/main/resource/lang/localization_de-DE.yml new file mode 100644 index 0000000..0954f93 --- /dev/null +++ b/src/main/resource/lang/localization_de-DE.yml @@ -0,0 +1,58 @@ +#============================================================# +# +--------------------------------------------------------+ # +# | Kenshins Hide and Seek 1.3.0 | # +# | German language file | # +# | by HerrMelodious | # +# +--------------------------------------------------------+ # +#============================================================# + +Localization: + COMMAND_PLAYER_ONLY: "Dieser Befehl kann nur als Spieler ausgeführt werden." + COMMAND_NOT_ALLOWED: "Es ist dir nicht gestattet diesen Befehl auszuführen." + COMMAND_ERROR: "Ein unbekannter Fehler ist aufgetreten." + GAME_PLAYER_DEATH: "&c{PLAYER}&f ist gestorben." + GAME_PLAYER_FOUND: "&e{PLAYER}&f wurde gefunden und ist nun ein Seeker." + GAME_PLAYER_FOUND_BY: "&e{PLAYER}&f wurde von &c{PLAYER}&f gefunden und ist nun ein Seeker." + GAME_GAMEOVER_HIDERS_FOUND: "Alle Hider wurden gefunden." + GAME_GAMEOVER_SEEKERS_QUIT: "All Seeker haben das Spiel verlassen." + GAME_GAMEOVER_TIME: "Seekers haben keine Spielzeit mehr. Die Hiders haben gewonnen!" + GAME_SETUP: "Spiel wurde noch nicht eingerichtet. Führe &c/hs setup&f aus, um die Einrichtungsschritte zu sehen." + GAME_INGAME: "Du bist bereits in der Lobby oder im Spiel." + GAME_NOT_INGAME: "Du bist weder in einer Lobby noch in einem Spiel." + GAME_INPROGRESS: "Es läuft bereits ein Spiel." + GAME_NOT_INPROGRESS: "Es läuft kein Spiel." + GAME_JOIN: "{PLAYER} hat die Hide and Seek Lobby betreten." + GAME_JOIN_SPECTATOR: "Du bist als Beobachter einem laufenden Spiel beigetreten." + GAME_LEAVE: "{PLAYER} hat die Hide and Seek Lobby verlassen." + CONFIG_RELOAD: "Konfiguration neu geladen." + MAPSAVE_INPROGRESS: "Weltkarte wird aktuell gespeichert. Versuche es später nochmal." + MAPSAVE_START: "Starte Speichervorgang der Weltkarte" + MAPSAVE_WARNING: "All commands will be disabled whenthe save is in progress. Do not turn off the server." + MAPSAVE_END: "Speichervorgang abgeschlossen." + MAPSAVE_ERROR: "Aktuelle Weltkarte konnte nicht gefunden werden." + WORLDBORDER_DISABLE: "World Border ausgeschaltet." + WORLDBORDER_INVALID_INPUT: "Ungültiger Wert: {AMOUNT}" + WORLDBORDER_MIN_SIZE: "World Border darf nicht geringer als 100 Blöcke sein." + WORLDBORDER_POSITION: "Spawn muss mindestens 100 Blöcke vom Zentrum der World Border entfernt sein." + WORLDBORDER_ENABLE: "Setze World Border zentriert von dieser Position aus. Größe: {AMOUNT}. Verzögerung: {AMOUNT}." + WORLDBORDER_DECREASING: "World Norder schrumpoft 100 Blöcke über die nächsten 30 Sekunden!" + TAUNTED: "$c$oOh nein! Du wurdest geärgert!" + TAUNT: "Ein zufälliger Hider wird in den nächsten 30 Sekunden geärgert." + TAUNT_ACTIVATE: "Ärgern wurde aktiviert" + ERROR_GAME_SPAWN: "Bitte erst die Spawn-Position für das Spiel festlegen." + SETUP: "&f&lFühre die folgenden Schritte zur Einrichtung aus:" + SETUP_GAME: "&c&l- &fTeleport-Position für den Spielbeginn festlegen mit /hs setspawn" + SETUP_LOBBY: "&c&l- &fTeleport-Position für die Lobby festlegen mit /hs setlobby" + SETUP_EXIT: "&c&l- &fTeleport-Position für das Spielende festlegen mit /hs setexit" + SETUP_SAVEMAP: "&c&l- &fHide and Seek Weltkarte speichern mit /hs savemap (nach /hs setspawn)" + SETUP_COMPLETE: "Alles eingerichtet! Hide and Seek ist spielbereit." + GAME_SPAWN: "Teleport-Position für Spielbeginn festgelegt" + LOBBY_SPAWN: "Teleport-Position für Lobby festgelegt" + EXIT_SPAWN: "Teleport-Position für Spielende festgelegt" + START_MIN_PLAYERS: "Um das Spiel zu starten benötigst du mindestens {AMOUNT} Spieler." + START_INVALID_NAME: "Ungültiger Spieler: {PLAYER}." + START_COUNTDOWN: "Die Hider haben {AMOUNT} Sekunden Zeit sich zu verstecken!" + START: "Los, Seeker! Es ist Zeit, die Hider zu finden." + STOP: "Das Spiel wurde gestoppt." + HIDERS_SUBTITLE: "Verstecke dich gut vor den Seekern!" + SEEKERS_SUBTITLE: "Finde alle Hider!" From 4ae9510e16a38f623b36368f5bd2229e371f4908 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 20 Dec 2021 16:36:39 -0500 Subject: [PATCH 07/10] remove iml file --- HideAndSeekPlugin.iml | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 HideAndSeekPlugin.iml diff --git a/HideAndSeekPlugin.iml b/HideAndSeekPlugin.iml deleted file mode 100644 index fa63d4b..0000000 --- a/HideAndSeekPlugin.iml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - SPIGOT - - - - - \ No newline at end of file From d09daa4682bba968a9180aee62a65cad9fea3766 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 20 Dec 2021 16:51:44 -0500 Subject: [PATCH 08/10] localization resets on internal update --- .../net/tylermurphy/hideAndSeek/Main.java | 3 +- .../hideAndSeek/configuration/Config.java | 9 ----- .../configuration/ConfigManager.java | 7 ++-- .../hideAndSeek/configuration/Items.java | 12 +++---- .../configuration/Localization.java | 34 +++++++++++-------- src/main/resources/config.yml | 3 ++ src/main/resources/items.yml | 12 +++---- src/main/resources/localization.yml | 5 ++- 8 files changed, 44 insertions(+), 41 deletions(-) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index 4815a30..f92bf15 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -88,7 +88,8 @@ public class Main extends JavaPlugin implements Listener { } public void onDisable() { - onTickTask.cancel(); + if(onTickTask != null) + onTickTask.cancel(); } public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java index f2b7680..be86660 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java @@ -1,16 +1,7 @@ package net.tylermurphy.hideAndSeek.configuration; -import java.io.File; -import java.util.Map; -import java.util.Map.Entry; - -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.util.Vector; -import net.tylermurphy.hideAndSeek.Main; - public class Config { private static ConfigManager manager; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java index 09b3dcf..0129680 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -73,6 +73,10 @@ public class ConfigManager { } } + public void reset(String path){ + config.set(path, defaultConfig.get(path)); + } + public boolean getBoolean(String path){ boolean value = config.getBoolean(path); if(value == false){ @@ -107,7 +111,6 @@ public class ConfigManager { String yamlString = textBuilder.toString(); Map temp = config.getValues(true); for(Map.Entry entry: temp.entrySet()){ - System.out.println(entry.getKey() + " " + entry.getValue().getClass().getName()); if(entry.getValue() instanceof Integer || entry.getValue() instanceof Double || entry.getValue() instanceof String || entry.getValue() instanceof Boolean){ String[] parts = entry.getKey().split("\\."); int index = 0; @@ -131,7 +134,7 @@ public class ConfigManager { replace = "\"" + replace + "\""; } StringBuilder builder = new StringBuilder(yamlString); - builder.replace(start+1, end, replace); + builder.replace(start+1, end == -1 ? yamlString.length() : end, replace); yamlString = builder.toString(); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java index fbf5d2c..e5470af 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java @@ -16,16 +16,14 @@ import java.util.Objects; public class Items { - private static ConfigManager manager; - public static List HIDER_ITEMS, SEEKER_ITEMS; public static List HIDER_EFFECTS, SEEKER_EFFECTS; public static void loadItems() { - manager = new ConfigManager("items.yml"); + ConfigManager manager = new ConfigManager("items.yml"); - SEEKER_ITEMS = new ArrayList(); + SEEKER_ITEMS = new ArrayList<>(); ConfigurationSection SeekerItems = manager.getConfigurationSection("items.seeker"); int i = 1; while (true) { @@ -36,7 +34,7 @@ public class Items { i++; } - HIDER_ITEMS = new ArrayList(); + HIDER_ITEMS = new ArrayList<>(); ConfigurationSection HiderItems = manager.getConfigurationSection("items.hider"); i = 1; while (true) { @@ -47,7 +45,7 @@ public class Items { i++; } - SEEKER_EFFECTS = new ArrayList(); + SEEKER_EFFECTS = new ArrayList<>(); ConfigurationSection SeekerEffects = manager.getConfigurationSection("effects.seeker"); i = 1; while (true) { @@ -58,7 +56,7 @@ public class Items { i++; } - HIDER_EFFECTS = new ArrayList(); + HIDER_EFFECTS = new ArrayList<>(); ConfigurationSection HiderEffects = manager.getConfigurationSection("effects.hider"); i = 1; while (true) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java index 9980a4e..1ae8ca2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java @@ -1,26 +1,32 @@ package net.tylermurphy.hideAndSeek.configuration; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; -import org.bukkit.configuration.file.YamlConfiguration; - import net.md_5.bungee.api.ChatColor; -import net.tylermurphy.hideAndSeek.Main; public class Localization { - public static final Map LOCAL = new HashMap(); - - private static ConfigManager manager; - - public static boolean loadLocalization() { + public static final Map LOCAL = new HashMap<>(); + + private static String[][] CHANGES = {{"WORLDBORDER_DECREASING"}}; + + public static void loadLocalization() { + + ConfigManager manager = new ConfigManager("localization.yml"); + + int PLUGIN_VERSION = 2; + int VERSION = manager.getInt("version"); + if(VERSION < PLUGIN_VERSION){ + for(int i = VERSION; i < PLUGIN_VERSION; i++){ + if(i < 1) continue; + String[] changeList = CHANGES[i-1]; + for(String change : changeList) + manager.reset("Localization." + change); + } + manager.reset("version"); + } - manager = new ConfigManager("localization.yml"); manager.saveConfig(); for(String key : manager.getConfigurationSection("Localization").getKeys(false)) { @@ -29,8 +35,6 @@ public class Localization { new LocalizationString( ChatColor.translateAlternateColorCodes('&', manager.getString("Localization."+key) ) ) ); } - - return true; } public static LocalizationString message(String key) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 64fdece..c6b5ecd 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -36,6 +36,9 @@ autoJoin: false # default: false teleportToExit: false +countdown: + + # The worldborder closes every interval, which is evey [delay] in minutes. # Thw worldborder starts at [size], and decreases 100 blocks every interval. # x & z are the center location. [enabled] is whenever the border is enabled. diff --git a/src/main/resources/items.yml b/src/main/resources/items.yml index d9b3b2a..4ef7953 100644 --- a/src/main/resources/items.yml +++ b/src/main/resources/items.yml @@ -40,12 +40,6 @@ items: material: POTION amount: 2 type: INSTANT_HEAL - '4': - type: DOLPHINS_GRACE - duration: 1000000 - amplifier: 1 - ambient: false - particles: false effects: seeker: '1': @@ -72,6 +66,12 @@ effects: amplifier: 10 ambient: false particles: false + '5': + type: DOLPHINS_GRACE + duration: 1000000 + amplifier: 1 + ambient: false + particles: false hider: '1': type: WATER_BREATHING diff --git a/src/main/resources/localization.yml b/src/main/resources/localization.yml index f6a82dc..e73ee80 100644 --- a/src/main/resources/localization.yml +++ b/src/main/resources/localization.yml @@ -27,7 +27,7 @@ Localization: WORLDBORDER_MIN_SIZE: "World border cannot be smaller than 100 blocks." WORLDBORDER_POSITION: "Spawn position must be 100 from world border center." WORLDBORDER_ENABLE: "Set border center to current location, size to {AMOUNT}, and delay to {AMOUNT}." - WORLDBORDER_DECREASING: "Would border decreasing by 100 blocks over the next 30s." + WORLDBORDER_DECREASING: "World border decreasing by 100 blocks over the next 30s." TAUNTED: "$c$oOh no! You have been chosen to be taunted." TAUNT: "A random hider will be taunted in the next 30s." TAUNT_ACTIVATE: "Taunt has been activated." @@ -52,3 +52,6 @@ Localization: BOUNDS_WRONG_WORLD: "Please run this command in the game world." BOUNDS: "Successfully set bounds at this position ({AMOUNT}/2)." NOT_AT_ZERO: "Please do not set at a location containing a coordinate at 0." + +# DO NOT EDIT +version: 2 From 08c6e6b24bcbdb9b4ed0e6d3db102fc804b5631a Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 20 Dec 2021 17:24:43 -0500 Subject: [PATCH 09/10] added support for multiple default local files --- .gitignore | 2 +- .../hideAndSeek/configuration/Config.java | 4 +- .../configuration/ConfigManager.java | 27 ++++++++ .../configuration/Localization.java | 9 ++- src/main/resources/config.yml | 5 ++ .../lang/localization_de-DE.yml | 4 +- .../resources/lang/localization_en-US.yml | 64 +++++++++++++++++++ src/main/resources/localization.yml | 3 +- 8 files changed, 113 insertions(+), 5 deletions(-) rename src/main/{resource => resources}/lang/localization_de-DE.yml (98%) create mode 100644 src/main/resources/lang/localization_en-US.yml diff --git a/.gitignore b/.gitignore index 633697f..3c5a335 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ bin/ target/ .git/ .idea -hideandseek-plugin.iml +*.iml diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java index be86660..ee9d88d 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java @@ -16,7 +16,8 @@ public class Config { warningPrefix, spawnWorld, exitWorld, - lobbyWorld; + lobbyWorld, + local; public static Vector spawnPosition, @@ -128,6 +129,7 @@ public class Config { pvpEnabled = manager.getBoolean("pvp"); autoJoin = manager.getBoolean("autoJoin"); teleportToExit = manager.getBoolean("teleportToExit"); + local = manager.getString("local"); } public static void addToConfig(String path, Object value) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java index 0129680..d16f3d8 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -32,6 +32,28 @@ public class ConfigManager { } catch (IOException e){} } + public ConfigManager(String filename, String defaultFilename){ + this.file = new File(Main.plugin.getDataFolder(), filename); + + if(!file.exists()){ + saveDefaultConfiguration(); + } + + this.config = YamlConfiguration.loadConfiguration(file); + + InputStream input = Main.plugin.getResource(defaultFilename); + InputStreamReader reader = new InputStreamReader(input); + this.defaultConfig = YamlConfiguration.loadConfiguration(reader); + try{ + input.close(); + reader.close(); + } catch (IOException e){ + Main.plugin.getLogger().severe("Couldn't find "+defaultFilename+" internally. Did you set an incorrect local?"); + Main.plugin.getServer().getPluginManager().disablePlugin(Main.plugin); + throw new RuntimeException(); + } + } + private void saveDefaultConfiguration(){ try{ InputStream input = Main.plugin.getResource(file.getName()); @@ -77,6 +99,11 @@ public class ConfigManager { config.set(path, defaultConfig.get(path)); } + public void resetConfig(){ + config = defaultConfig; + saveConfig(); + } + public boolean getBoolean(String path){ boolean value = config.getBoolean(path); if(value == false){ diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java index 1ae8ca2..c404aa3 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java @@ -1,5 +1,6 @@ package net.tylermurphy.hideAndSeek.configuration; +import java.io.File; import java.util.HashMap; import java.util.Map; @@ -13,7 +14,7 @@ public class Localization { public static void loadLocalization() { - ConfigManager manager = new ConfigManager("localization.yml"); + ConfigManager manager = new ConfigManager("localization.yml", "lang"+File.separator+"localization_"+Config.local+".yml"); int PLUGIN_VERSION = 2; int VERSION = manager.getInt("version"); @@ -27,6 +28,12 @@ public class Localization { manager.reset("version"); } + String SELECTED_LOCAL = manager.getString("local"); + if(!SELECTED_LOCAL.equals(Config.local)){ + manager.resetConfig(); + } + + manager.saveConfig(); for(String key : manager.getConfigurationSection("Localization").getKeys(false)) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index c6b5ecd..7d16cae 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -82,6 +82,11 @@ prefix: gameover: '&aGame Over > &f' warning: '&cWarning > &f' +# Changes the default plugin language. Currently, Supported localizations are: +# en-US (United States) +# de-DE (German) +local: "en-US" + # ---------------------------------------------------------- # # ONLY EDIT BEYOND THIS POINT IF YOU KNOW WHAT YOU ARE DOING # # ---------------------------------------------------------- # diff --git a/src/main/resource/lang/localization_de-DE.yml b/src/main/resources/lang/localization_de-DE.yml similarity index 98% rename from src/main/resource/lang/localization_de-DE.yml rename to src/main/resources/lang/localization_de-DE.yml index 0954f93..d8930f8 100644 --- a/src/main/resource/lang/localization_de-DE.yml +++ b/src/main/resources/lang/localization_de-DE.yml @@ -1,6 +1,6 @@ #============================================================# # +--------------------------------------------------------+ # -# | Kenshins Hide and Seek 1.3.0 | # +# | Kenshins Hide and Seek | # # | German language file | # # | by HerrMelodious | # # +--------------------------------------------------------+ # @@ -56,3 +56,5 @@ Localization: STOP: "Das Spiel wurde gestoppt." HIDERS_SUBTITLE: "Verstecke dich gut vor den Seekern!" SEEKERS_SUBTITLE: "Finde alle Hider!" + +type: "de-DE" diff --git a/src/main/resources/lang/localization_en-US.yml b/src/main/resources/lang/localization_en-US.yml new file mode 100644 index 0000000..19c79b7 --- /dev/null +++ b/src/main/resources/lang/localization_en-US.yml @@ -0,0 +1,64 @@ +#============================================================# +# +--------------------------------------------------------+ # +# | Kenshins Hide and Seek | # +# | English language file | # +# | by KenshinEto | # +# +--------------------------------------------------------+ # +#============================================================# + +Localization: + COMMAND_PLAYER_ONLY: "This command can only be run as a player." + COMMAND_NOT_ALLOWED: "You are not allowed to run this command." + COMMAND_ERROR: "An internal error has occurred." + GAME_PLAYER_DEATH: "&c{PLAYER}&f was killed." + GAME_PLAYER_FOUND: "&e{PLAYER}&f was found and became a seeker." + GAME_PLAYER_FOUND_BY: "&e{PLAYER}&f was found by &c{PLAYER}&f and became a seeker." + GAME_GAMEOVER_HIDERS_FOUND: "All hiders have been found." + GAME_GAMEOVER_SEEKERS_QUIT: "All seekers have quit." + GAME_GAMEOVER_TIME: "Seekers ran out of time. Hiders win!" + GAME_SETUP: "Game is not setup. Run /hs setup to see what you need to do." + GAME_INGAME: "You are already in the lobby/game." + GAME_NOT_INGAME: "You are not in a lobby/game." + GAME_INPROGRESS: "There is currently a game in progress." + GAME_NOT_INPROGRESS: "There is no game in progress." + GAME_JOIN: "{PLAYER} has joined the HideAndSeek lobby." + GAME_JOIN_SPECTATOR: "You have joined mid game and are now a spectator." + GAME_LEAVE: "{PLAYER} has left the HideAndSeek lobby." + CONFIG_RELOAD: "Reloaded the config." + MAPSAVE_INPROGRESS: "Map save is currently in progress. Try again later." + MAPSAVE_START: "Starting map save." + MAPSAVE_WARNING: "All commands will be disabled when the save is in progress. Do not turn off the server." + MAPSAVE_END: "Map save complete." + MAPSAVE_ERROR: "Couldn't find current map." + WORLDBORDER_DISABLE: "Disabled world border." + WORLDBORDER_INVALID_INPUT: "Invalid integer {AMOUNT}." + WORLDBORDER_MIN_SIZE: "World border cannot be smaller than 100 blocks." + WORLDBORDER_POSITION: "Spawn position must be 100 from world border center." + WORLDBORDER_ENABLE: "Set border center to current location, size to {AMOUNT}, and delay to {AMOUNT}." + WORLDBORDER_DECREASING: "World border decreasing by 100 blocks over the next 30s." + TAUNTED: "$c$oOh no! You have been chosen to be taunted." + TAUNT: "A random hider will be taunted in the next 30s." + TAUNT_ACTIVATE: "Taunt has been activated." + ERROR_GAME_SPAWN: "Please set game spawn location first" + SETUP: "&f&lThe following is needed for setup..." + SETUP_GAME: "&c&l- &fGame spawn isn't set, /hs setspawn" + SETUP_LOBBY: "&c&l- &fLobby spawn isn't set, /hs setlobby" + SETUP_EXIT: "&c&l- &fQuit/exit teleport location isn't set, /hs setexit" + SETUP_SAVEMAP: "&c&l- &fHide and seek map isn't saved, /hs savemap (after /hs setspawn)" + SETUP_BOUNDS: "&c&l- &fPlease set game bounds in 2 opposite corners of the game map, /hs setbounds" + SETUP_COMPLETE: "Everything is setup and ready to go!" + GAME_SPAWN: "Set game spawn position to current location" + LOBBY_SPAWN: "Set lobby position to current location" + EXIT_SPAWN: "Set exit position to current location" + START_MIN_PLAYERS: "You must have at least {AMOUNT} players to start." + START_INVALID_NAME: "Invalid player: {PLAYER}." + START_COUNTDOWN: "Hiders have {AMOUNT} seconds to hide!" + START: "Attention SEEKERS, its time to fin the hiders!" + STOP: "Game has been force stopped." + HIDERS_SUBTITLE: "Hide away from the seekers" + SEEKERS_SUBTITLE: "Eliminate all hiders" + BOUNDS_WRONG_WORLD: "Please run this command in the game world." + BOUNDS: "Successfully set bounds at this position ({AMOUNT}/2)." + NOT_AT_ZERO: "Please do not set at a location containing a coordinate at 0." + +type: "en-US" \ No newline at end of file diff --git a/src/main/resources/localization.yml b/src/main/resources/localization.yml index e73ee80..2acb0fc 100644 --- a/src/main/resources/localization.yml +++ b/src/main/resources/localization.yml @@ -53,5 +53,6 @@ Localization: BOUNDS: "Successfully set bounds at this position ({AMOUNT}/2)." NOT_AT_ZERO: "Please do not set at a location containing a coordinate at 0." -# DO NOT EDIT +# DO NOT EDIT IT OR IT MAY BREAK OR RESET FILE version: 2 +type: "en-US" \ No newline at end of file From a549cfb7a6a8451466cb656462d1c8c360e8c10a Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 20 Dec 2021 18:20:57 -0500 Subject: [PATCH 10/10] Add Workflows --- .github/workflows/beta.yml | 30 ++++++++++++++++++++++++++++++ .github/workflows/release.yml | 30 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 .github/workflows/beta.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/beta.yml b/.github/workflows/beta.yml new file mode 100644 index 0000000..4220d3c --- /dev/null +++ b/.github/workflows/beta.yml @@ -0,0 +1,30 @@ +name: Beta + +on: + release: + types: [ 1.3.1 ] + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout branch + uses: actions/checkout@v2 + + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + + - name: Build with Maven + run: mvn -B package --file pom.xml + + - name: Publish to GitHub Packages Apache Maven + run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml + env: + GITHUB_TOKEN: ${{ github.token }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..39d7f56 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,30 @@ +name: Release + +on: + release: + types: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout branch + uses: actions/checkout@v2 + + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + + - name: Build with Maven + run: mvn -B package --file pom.xml + + - name: Publish to GitHub Packages Apache Maven + run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml + env: + GITHUB_TOKEN: ${{ github.token }}