From 134444243a491a5b22c2cc4219e8fdd361ce2693 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Fri, 6 May 2022 12:22:04 -0400 Subject: [PATCH] option to disable mapsave --- .../hideAndSeek/command/SaveMap.java | 4 +++ .../hideAndSeek/command/SetSpawnLocation.java | 2 +- .../hideAndSeek/command/Setup.java | 11 +++++--- .../hideAndSeek/configuration/Config.java | 4 ++- .../hideAndSeek/game/EventListener.java | 10 ++++---- .../tylermurphy/hideAndSeek/game/Game.java | 25 ++++++++++++------- src/main/resources/config.yml | 12 +++++++-- .../resources/lang/localization_de-DE.yml | 1 + .../resources/lang/localization_en-US.yml | 1 + 9 files changed, 48 insertions(+), 22 deletions(-) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java index c48e1c6..f5e63a5 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java @@ -36,6 +36,10 @@ public class SaveMap implements ICommand { public static boolean runningBackup = false; public void execute(CommandSender sender, String[] args) { + if(!mapSaveEnabled){ + sender.sendMessage(errorPrefix + message("MAPSAVE_DISABLED")); + return; + } if(Game.status != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java index 7afe861..d5e1cba 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java @@ -56,7 +56,7 @@ public class SetSpawnLocation implements ICommand { if(world == null){ throw new RuntimeException("Unable to get world: " + spawnWorld); } - if(!world.getName().equals(spawnWorld)){ + if(mapSaveEnabled && !world.getName().equals(spawnWorld)){ Game.worldLoader.unloadMap(); Game.worldLoader = new WorldLoader(world.getName()); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java index 74c29bf..14a5d6f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java @@ -19,6 +19,7 @@ package net.tylermurphy.hideAndSeek.command; +import net.tylermurphy.hideAndSeek.game.Game; import org.bukkit.command.CommandSender; import net.tylermurphy.hideAndSeek.Main; @@ -51,10 +52,12 @@ public class Setup implements ICommand { msg = msg + "\n" + message("SETUP_BOUNDS"); count++; } - File destenation = new File(Main.root+File.separator+"hideandseek_"+spawnWorld); - if(!destenation.exists()) { - msg = msg + "\n" + message("SETUP_SAVEMAP"); - count++; + if(mapSaveEnabled) { + File destenation = new File(Main.root + File.separator + Game.getGameWorld()); + if (!destenation.exists()) { + msg = msg + "\n" + message("SETUP_SAVEMAP"); + count++; + } } if(count < 1) { sender.sendMessage(messagePrefix + message("SETUP_COMPLETE")); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java index 835b03d..ec4e84e 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java @@ -78,7 +78,8 @@ public class Config { seekerPing, bungeeLeave, lobbyItemStartAdmin, - leaveOnEnd; + leaveOnEnd, + mapSaveEnabled; public static int minPlayers, @@ -201,6 +202,7 @@ public class Config { saveMinZ = config.getInt("bounds.min.z"); saveMaxX = config.getInt("bounds.max.x"); saveMaxZ = config.getInt("bounds.max.z"); + mapSaveEnabled = config.getBoolean("mapSaveEnabled"); //Taunt tauntEnabled = config.getBoolean("taunt.enabled"); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java index e464fba..35089e4 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java @@ -61,12 +61,12 @@ public class EventListener implements Listener { if(autoJoin){ Game.join(event.getPlayer()); } else if(teleportToExit) { - if (event.getPlayer().getWorld().getName().equals("hideandseek_" + spawnWorld) || event.getPlayer().getWorld().getName().equals(lobbyWorld)) { + if (event.getPlayer().getWorld().getName().equals(Game.getGameWorld()) || 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)) { + if (event.getPlayer().getWorld().getName().equals(Game.getGameWorld())) { if(Game.status != Status.STANDBY){ Game.join(event.getPlayer()); } else { @@ -115,10 +115,10 @@ public class EventListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST) public void onMove(PlayerMoveEvent event){ - if(!event.getPlayer().getWorld().getName().equals("hideandseek_" + spawnWorld)) return; + if(!event.getPlayer().getWorld().getName().equals(Game.getGameWorld())) return; if(event.getPlayer().hasPermission("hideandseek.leavebounds")) return; if(event.getTo() == null || event.getTo().getWorld() == null) return; - if(!event.getTo().getWorld().getName().equals("hideandseek_" + spawnWorld)) return; + if(!event.getTo().getWorld().getName().equals(Game.getGameWorld())) return; if(event.getTo().getBlockX() < saveMinX || event.getTo().getBlockX() > saveMaxX || event.getTo().getBlockZ() < saveMinZ || event.getTo().getBlockZ() > saveMaxZ){ event.setCancelled(true); } @@ -211,7 +211,7 @@ public class EventListener implements Listener { } else { player.setHealth(player.getMaxHealth()); } - player.teleport(new Location(Bukkit.getWorld("hideandseek_" + spawnWorld), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ())); + player.teleport(new Location(Bukkit.getWorld(Game.getGameWorld()), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ())); if(Version.atLeast("1.9")){ XSound.ENTITY_PLAYER_DEATH.play(player, 1, 1); } else { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java index d61d11f..16caee4 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java @@ -89,7 +89,7 @@ public class Game { public static void start(Player seeker){ if(status == Status.STARTING || status == Status.PLAYING) return; - if(worldLoader.getWorld() != null) { + if(mapSaveEnabled && worldLoader.getWorld() != null) { worldLoader.rollback(); } else { worldLoader.loadMap(); @@ -105,7 +105,7 @@ public class Game { for(Player player : Board.getPlayers()) { player.getInventory().clear(); player.setGameMode(GameMode.ADVENTURE); - player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); + player.teleport(new Location(Bukkit.getWorld(getGameWorld()), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); for(PotionEffect effect : player.getActivePotionEffects()){ player.removePotionEffect(effect.getType()); } @@ -125,7 +125,7 @@ public class Game { if (glowEnabled) glow = new Glow(); worldBorder = new Border(); - worldBorder.resetWorldborder("hideandseek_"+spawnWorld); + worldBorder.resetWorldborder(getGameWorld()); if(gameLength > 0) timeLeft = gameLength; for(Player player : Board.getPlayers()) @@ -184,7 +184,7 @@ public class Game { winners.add(Board.getFirstSeeker().getUniqueId()); Database.playerInfo.addWins(players, winners, type); } - worldBorder.resetWorldborder("hideandseek_"+spawnWorld); + worldBorder.resetWorldborder(getGameWorld()); for(Player player : Board.getPlayers()) { if(Version.atLeast("1.9")){ for(Player temp : Board.getPlayers()) { @@ -220,7 +220,7 @@ public class Game { } } EventListener.temp_loc.clear(); - worldLoader.unloadMap(); + if(mapSaveEnabled) worldLoader.unloadMap(); Board.reloadLobbyBoards(); } @@ -228,11 +228,18 @@ public class Game { if(spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) return true; if(lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0) return true; if(exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) return true; - File destenation = new File(Main.root+File.separator+"hideandseek_"+spawnWorld); - if(!destenation.exists()) return true; + if(mapSaveEnabled) { + File destenation = new File(Main.root + File.separator + getGameWorld()); + if (!destenation.exists()) return true; + } return saveMinX == 0 || saveMinZ == 0 || saveMaxX == 0 || saveMaxZ == 0; } + public static String getGameWorld(){ + if(mapSaveEnabled) return "hideandseek_"+spawnWorld; + else return spawnWorld; + } + public static void onTick() { if(isNotSetup()) return; if(status == Status.STANDBY) whileWaiting(); @@ -294,7 +301,7 @@ public class Game { player.sendMessage(messagePrefix + message("GAME_JOIN_SPECTATOR")); player.setGameMode(GameMode.SPECTATOR); Board.createGameBoard(player); - player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); + player.teleport(new Location(Bukkit.getWorld(getGameWorld()), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); Titles.sendTitle(player, 10, 70, 20, ChatColor.GRAY + "" + ChatColor.BOLD + "SPECTATING", ChatColor.WHITE + message("SPECTATOR_SUBTITLE").toString()); } @@ -601,7 +608,7 @@ class Border { running = true; broadcastMessage(worldborderPrefix + message("WORLDBORDER_DECREASING").addAmount(change)); currentWorldborderSize -= worldborderChange; - World world = Bukkit.getWorld("hideandseek_"+spawnWorld); + World world = Bukkit.getWorld(Game.getGameWorld()); assert world != null; org.bukkit.WorldBorder border = world.getWorldBorder(); border.setSize(border.getSize()-change,30); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index cdf88ac..88eab62 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -60,12 +60,12 @@ teleportToExit: false # Normally when the game ends, players are set back to the lobby to play another game. # You can disable this, and empty the lobby after the game finishes. This is like everyone # running /hs leave at the end of the game. Players will leave either to the exit position -# or another server depending what you have `leaveType` set too. +# or another server depending on what you have `leaveType` set too. # default: false leaveOnEnd: false # What do you want to happen when a player leaves the lobby. If you are running a single server, maybe you want to send -# them to the world hub. But if you are running a bungee-cord or velocity server, maybe you want to send them to the servers +# them to the world hub. But if you are running a bungee-cord or velocity server, maybe you want to send them to the servers' # hub. # # EXIT - Sends the player to the specified exit position set by /hs setexit @@ -79,6 +79,14 @@ leaveType: EXIT # players too. leaveServer: hub +# By default, the plugin forces you to use a map save to protect from changes to a map thought a game play though. It copies your +# hide-and-seek world to a separate world, and loads the game there to contain the game in an isolated and backed up map This allows you to +# not worry about your hide-and-seek map from changing, as all changes are made are in a separate world file that doesn't get saved. Once the game +# ends, it unloads the map and doesn't save. Then reloads the duplicate to the original state, rolling back the map for the next game. +# It is highly recommended that you keep this set to true unless you have other means of protecting your hide-and-seek map. +# default: true +mapSaveEnabled: true + # 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/lang/localization_de-DE.yml b/src/main/resources/lang/localization_de-DE.yml index d560d24..5fd80d6 100644 --- a/src/main/resources/lang/localization_de-DE.yml +++ b/src/main/resources/lang/localization_de-DE.yml @@ -30,6 +30,7 @@ Localization: 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." + MAPSAVE_DISABLED: "Mapsave ist in config.yml deaktiviert." 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." diff --git a/src/main/resources/lang/localization_en-US.yml b/src/main/resources/lang/localization_en-US.yml index 1757877..b047bdb 100644 --- a/src/main/resources/lang/localization_en-US.yml +++ b/src/main/resources/lang/localization_en-US.yml @@ -30,6 +30,7 @@ Localization: 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." + MAPSAVE_DISABLED: "Mapsave is disabled in config.yml." WORLDBORDER_DISABLE: "Disabled world border." WORLDBORDER_INVALID_INPUT: "Invalid integer {AMOUNT}." WORLDBORDER_MIN_SIZE: "World border cannot be smaller than 100 blocks."