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