From 77a94812d533432c935e3909b7c02e523de58272 Mon Sep 17 00:00:00 2001 From: SuperRonanCraft Date: Thu, 13 Aug 2020 16:00:47 -0400 Subject: [PATCH] edit command fixes + dutch translation added --- .../player/commands/types/CmdEdit.java | 126 ++++++++++++------ .../BetterRTP/player/rtp/RTP.java | 38 +++--- .../BetterRTP/references/file/LangFile.java | 4 +- .../BetterRTP/references/file/Messages.java | 10 +- src/main/resources/lang/chn.yml | 5 +- src/main/resources/lang/cht.yml | 5 +- src/main/resources/lang/du.yml | 48 +++++++ src/main/resources/lang/en.yml | 9 +- src/main/resources/lang/fr.yml | 5 +- src/main/resources/lang/ja.yml | 5 +- src/main/resources/lang/ru.yml | 5 +- 11 files changed, 196 insertions(+), 64 deletions(-) create mode 100644 src/main/resources/lang/du.yml diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/player/commands/types/CmdEdit.java b/src/main/java/me/SuperRonanCraft/BetterRTP/player/commands/types/CmdEdit.java index b1001c0..4ba1185 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/player/commands/types/CmdEdit.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/player/commands/types/CmdEdit.java @@ -3,17 +3,13 @@ package me.SuperRonanCraft.BetterRTP.player.commands.types; import me.SuperRonanCraft.BetterRTP.Main; import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommand; import me.SuperRonanCraft.BetterRTP.references.file.FileBasics; -import me.SuperRonanCraft.BetterRTP.references.worlds.Custom; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.YamlConfiguration; import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class CmdEdit implements RTPCommand { //Edit a worlds properties @@ -25,74 +21,104 @@ public class CmdEdit implements RTPCommand { //Edit a worlds properties switch (cmd) { case WORLD: if (args.length >= 5) { - //for (World world : Bukkit.getWorlds()) - //if (world.getName().toLowerCase().startsWith(args[2].toLowerCase())) { + for (World world : Bukkit.getWorlds()) { + if (world.getName().toLowerCase().startsWith(args[2].toLowerCase())) { for (RTP_CMD_EDIT_SUB cmde : RTP_CMD_EDIT_SUB.values()) if (cmde.name().toLowerCase().startsWith(args[3].toLowerCase())) { editWorld(sendi, cmde, args[4], args[2]); return; } - usage(sendi, label); + usage(sendi, label, cmd); return; - // } - //Main.getInstance().getText().getNotExist(sendi, label); - } else - usage(sendi, label); - break; + } + } + Main.getInstance().getText().getNotExist(sendi, label); + return; + } + usage(sendi, label, cmd); + return; case DEFAULT: for (RTP_CMD_EDIT_SUB cmde : RTP_CMD_EDIT_SUB.values()) if (cmde.name().toLowerCase().startsWith(args[2].toLowerCase())) { editDefault(sendi, cmde, args[3]); return; } - usage(sendi, label); - break; + usage(sendi, label, cmd); + return; } } - } else - usage(sendi, label); + } else if (args.length >= 2) { + for (RTP_CMD_EDIT cmd : RTP_CMD_EDIT.values()) + if (cmd.name().toLowerCase().startsWith(args[1].toLowerCase())) { + usage(sendi, label, cmd); + return; + } + } + usage(sendi, label, null); } - private void editWorld(CommandSender sendi, RTP_CMD_EDIT_SUB cmd, String value, String world) { + private void editWorld(CommandSender sendi, RTP_CMD_EDIT_SUB cmd, String val, String world) { + Object value = val; + try { + value = cmd.getResult(val); + } catch (Exception e) { + e.printStackTrace(); + Main.getInstance().getText().sms(sendi, "Invalid input!"); + return; + } + FileBasics.FILETYPE file = FileBasics.FILETYPE.CONFIG; YamlConfiguration config = file.getConfig(); - HashMap> cmap = new HashMap<>(); - List> map = config.getMapList("CustomWorlds"); - //for (Map m : map) - // cmap.put(m.toString(), (Map) m.entrySet(entry)); - - if (cmap.containsKey(world)) { - System.out.println(cmap.toString()); - Map list = cmap.get(world); - for (Map.Entry e : list.entrySet()) { - System.out.println(e.getKey()); + boolean found = false; + for (Map m : map) { + if (m.keySet().toArray()[0].equals(world)) { + found = true; + for (Object map2 : m.values()) { + Map values = (Map) map2; + values.put(cmd.get(), value); + Main.getInstance().getText().sms(sendi, cmd.get() + " set to " + value); + } + break; } - cmap.put(world, list); - } else { - Map list = new HashMap<>(); - list.put(cmd.get(), value); - cmap.put(world, list); + } + if (!found) { + Map map2 = new HashMap<>(); + Map values = new HashMap<>(); + values.put(cmd.get(), value); + map2.put(world, values); + map.add(map2); } config.set("CustomWorlds", map); try { config.save(file.getFile()); + Main.getInstance().getRTP().loadWorldSettings(); } catch (IOException e) { e.printStackTrace(); } } - private void editDefault(CommandSender sendi, RTP_CMD_EDIT_SUB cmd, String value) { + private void editDefault(CommandSender sendi, RTP_CMD_EDIT_SUB cmd, String val) { + Object value = val; + try { + value = cmd.getResult(val); + } catch (Exception e) { + e.printStackTrace(); + Main.getInstance().getText().sms(sendi, "Invalid input!"); + return; + } + FileBasics.FILETYPE file = FileBasics.FILETYPE.CONFIG; YamlConfiguration config = file.getConfig(); - + config.set("Default." + cmd.get(), value); try { config.save(file.getFile()); + Main.getInstance().getRTP().loadWorldSettings(); } catch (IOException e) { e.printStackTrace(); } @@ -143,8 +169,16 @@ public class CmdEdit implements RTPCommand { //Edit a worlds properties return Main.getInstance().getPerms().getEdit(sendi); } - private void usage(CommandSender sendi, String label) { - Main.getInstance().getText().getUsageEdit(sendi, label); + private void usage(CommandSender sendi, String label, RTP_CMD_EDIT type) { + if (type != null) + switch (type) { + case DEFAULT: + Main.getInstance().getText().getUsageEditDefault(sendi, label); break; + case WORLD: + Main.getInstance().getText().getUsageEditWorld(sendi, label); break; + } + else + Main.getInstance().getText().getUsageEdit(sendi, label); } enum RTP_CMD_EDIT { @@ -152,16 +186,30 @@ public class CmdEdit implements RTPCommand { //Edit a worlds properties } enum RTP_CMD_EDIT_SUB { - CENTER("Center"), MAX("MaxRadius"), MIN("MinRadius"), USEWORLDBORDER("UseWorldBorder"); + CENTER_X("CenterX", "INT"), + CENTER_Y("CenterY", "INT"), + MAX("MaxRadius", "INT"), + MIN("MinRadius", "INT"), + USEWORLDBORDER("UseWorldBorder", "BOL"); + private String type; private String str; - RTP_CMD_EDIT_SUB(String str) { + RTP_CMD_EDIT_SUB(String str, String type) { this.str = str; + this.type = type; } String get() { return str; } + + Object getResult(String input) { + if (this.type.equalsIgnoreCase("INT")) + return Integer.parseInt(input); + else if (this.type.equalsIgnoreCase("BOL")) + return Boolean.valueOf(input); + return null; + } } } \ No newline at end of file diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTP.java b/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTP.java index 2e401ef..77752a8 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTP.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTP.java @@ -41,8 +41,7 @@ public class RTP { } public void load() { - defaultWorld.setup(); - FileBasics.FILETYPE config = getPl().getFiles().getType(FileBasics.FILETYPE.CONFIG); + FileBasics.FILETYPE config = FileBasics.FILETYPE.CONFIG; disabledWorlds = config.getStringList("DisabledWorlds"); maxAttempts = config.getInt("Settings.MaxAttempts"); delayTime = config.getInt("Settings.Delay.Time"); @@ -65,20 +64,6 @@ public class RTP { //No Overrides } - //CUSTOM WORLDS - try { - customWorlds.clear(); - List> map = config.getMapList("CustomWorlds"); - for (Map m : map) - for (Map.Entry entry : m.entrySet()) { - customWorlds.put(entry.getKey().toString(), new Custom(entry.getKey().toString())); - if (getPl().getSettings().debug) - getPl().getLogger().info("- Custom World '" + entry.getKey() + "' registered"); - } - } catch (Exception e) { - //No Custom Worlds - } - try { world_type.clear(); for (World world : Bukkit.getWorlds()) @@ -111,9 +96,30 @@ public class RTP { e.printStackTrace(); //No World Types } + + loadWorldSettings(); + teleport.load(); //Load teleporting stuff } + public void loadWorldSettings() { + FileBasics.FILETYPE config = FileBasics.FILETYPE.CONFIG; + defaultWorld.setup(); + //CUSTOM WORLDS + try { + customWorlds.clear(); + List> map = config.getMapList("CustomWorlds"); + for (Map m : map) + for (Map.Entry entry : m.entrySet()) { + customWorlds.put(entry.getKey().toString(), new Custom(entry.getKey().toString())); + if (getPl().getSettings().debug) + getPl().getLogger().info("- Custom World '" + entry.getKey() + "' registered"); + } + } catch (Exception e) { + //No Custom Worlds + } + } + public List disabledWorlds() { return disabledWorlds; } diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/references/file/LangFile.java b/src/main/java/me/SuperRonanCraft/BetterRTP/references/file/LangFile.java index 38d7133..f18b897 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/references/file/LangFile.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/references/file/LangFile.java @@ -52,10 +52,10 @@ public class LangFile { generateDefaults(pl); } - private String[] defaultLangs = {"en.yml", "fr.yml", "ja.yml", "ru.yml"}; + private String[] defaultLangs = {"en.yml", "fr.yml", "ja.yml", "ru.yml", "chn.yml", "cht.yml", "du.yml"}; private void generateDefaults(Main pl) { - //Generate allLangs + //Generate all language files for (String yaml : defaultLangs) { if (yaml.equals(defaultLangs[0]) && config.getName().equals(defaultLangs[0])) continue; diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/references/file/Messages.java b/src/main/java/me/SuperRonanCraft/BetterRTP/references/file/Messages.java index 1907158..ae58c96 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/references/file/Messages.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/references/file/Messages.java @@ -155,7 +155,15 @@ public class Messages { } public void getUsageEdit(CommandSender sendi, String cmd) { - sms(sendi, getLang().getString(preU + "Edit").replaceAll("%command%", cmd)); + sms(sendi, getLang().getString(preU + "Edit.Base").replaceAll("%command%", cmd)); + } + + public void getUsageEditDefault(CommandSender sendi, String cmd) { + sms(sendi, getLang().getString(preU + "Edit.Default").replaceAll("%command%", cmd)); + } + + public void getUsageEditWorld(CommandSender sendi, String cmd) { + sms(sendi, getLang().getString(preU + "Edit.World").replaceAll("%command%", cmd)); } // Not Found diff --git a/src/main/resources/lang/chn.yml b/src/main/resources/lang/chn.yml index a3f5f18..fec3583 100644 --- a/src/main/resources/lang/chn.yml +++ b/src/main/resources/lang/chn.yml @@ -43,4 +43,7 @@ Usage: Player: '&cUsage&7: /%command% player <玩家> [世界] [生物群系1, 生物群系2]' World: '&cUsage&7: /%command% world <世界> [生物群系1, 生物群系2...]' Biome: '&cUsage&7: /%command% biome <生物群系1, 生物群系2...>' - Edit: '&cUsage&7: /%command% edit [max/min/useworldborder/center]' \ No newline at end of file + Edit: + Base: '&cUsage&7: /%command% edit [args...]' + Default: '&cUsage&7: /%command% edit default ' + World: '&cUsage&7: /%command% edit world ' \ No newline at end of file diff --git a/src/main/resources/lang/cht.yml b/src/main/resources/lang/cht.yml index d12c929..6b62aba 100644 --- a/src/main/resources/lang/cht.yml +++ b/src/main/resources/lang/cht.yml @@ -43,4 +43,7 @@ Usage: Player: '&cUsage&7: /%command% player <玩家> [世界] [生態域1, 生態域2]' World: '&cUsage&7: /%command% world <世界> [生態域1, 生態域2...]' Biome: '&cUsage&7: /%command% biome <生態域1, 生態域2...>' - Edit: '&cUsage&7: /%command% edit [max/min/useworldborder/center]' \ No newline at end of file + Edit: + Base: '&cUsage&7: /%command% edit [args...]' + Default: '&cUsage&7: /%command% edit default ' + World: '&cUsage&7: /%command% edit world ' \ No newline at end of file diff --git a/src/main/resources/lang/du.yml b/src/main/resources/lang/du.yml new file mode 100644 index 0000000..44a49cf --- /dev/null +++ b/src/main/resources/lang/du.yml @@ -0,0 +1,48 @@ +Messages: + Prefix: '&7[&6BetterRTP&7] ' + Success: ## Placeholders! %x% %y% and %z% are the x, y, and z coordinates that the player is being teleported to! # + Paid: '&aJe bent getp''d naar&7 x=%x% y=%y% z=%z% for &c$%price%&7 in &f%attempts% &7attempts!' + Bypass: '&aJe bent getp''d naar&7 x=%x% y=%y% z=%z%' + Loading: '&aSafe spot located! &7Loading chunks...' + Failed: + Price: '&cKan niet rtpen vanwege onvoldoende saldo! &7Je moet minstens $%price% &7hebben om te rtpen!' + NotSafe: '&cKon geen veilige plek vinden, Probeer opnieuw! &7Je bent niet ge tp''d!' + Other: + Success: '&a%player% is getp''d naar&7 x=%x% y=%y% z=%z% in &f%attempts% &7pogingen!' + NotSafe: '&cKon geen veilige plek binnenin %attempts% pogingen! &7%player% is niet gertp''d!' + Biome: '&cHet lijkt er naar dat de biome&7 %biome%&c niet bestaat! &7Probeer de tab list te gebruiken!' + Reload: '&eConfig succesvol herladen!' + NoPermission: + Basic: '&cSorry! &7U heeft geen toestemming om deze command te gebruiken!' + World: '&cSorry! &7Je mag niet rtpen in de %world% wereld!' + ## %world% is the world the player is in that is disabled to rtp in! # + DisabledWorld: '&cUitgeschakeld %world%! &7Kon niet RTPen!' + Cooldown: '&cSorry! &7Je kan niet rtpen voor &c%time% &7seconden!' + Invalid: '&cOngeldig argument. probeer ''/%command% help''' + NotOnline: '&cDe speler &7%player% &cis niet online!' + Delay: '&aTeleportering in &f%time% &aseconden! Niet bewegen!' + Moved: '&cJe hebt bewogen! &7RTP was afgelast!' + NotExist: '&cLijkt dat de wereld &7%world% &cniet bestaat!' + Already: '&cOepsie! &7Het lijkt erop dat je al aan het rtpen bent, heb wat geduld!' + Sign: '&7Commando bordje is aangemaakt! &7Commando is... ''&f/rtp %command%&7''' + +Help: + List: + - '&e&m------&r &6&lBetterRTP &8| &7Help &e&m------' + - ' &7- &e/%command% &7- Teleporteert jou naar een random locatie!' + - ' &7- &e/%command% help &7- Toont help lijst.' + ##If the player has permission to rtp another player, this message will be added under the list! + Player: ' &7- &e/%command% player [world] [biome1, biome2...] &7- Random teleport een andere speler' + World: ' &7- &e/%command% world [biome1, biome2...] &7- Random teleport in een andere wereld' + ##If the player has permission to reload the plugin this message will be added under the list! + Biome: ' &7- &e/%command% biome &7- Random teleport in deze biome' + Reload: ' &7- &e/%command% reload &7- Herlaad de plugin' + +Usage: + Player: '&cUsage&7: /%command% player [world] [biome1, biome2]' + World: '&cUsage&7: /%command% world [biome1, biome2...]' + Biome: '&cUsage&7: /%command% biome ' + Edit: + Base: '&cUsage&7: /%command% edit [args...]' + Default: '&cUsage&7: /%command% edit default ' + World: '&cUsage&7: /%command% edit world ' \ No newline at end of file diff --git a/src/main/resources/lang/en.yml b/src/main/resources/lang/en.yml index cdf1615..57ebec4 100644 --- a/src/main/resources/lang/en.yml +++ b/src/main/resources/lang/en.yml @@ -26,6 +26,10 @@ Messages: NotExist: '&cLooks like the world &7%world% &cdoesn''t exist!' Already: '&cWhoops! &7Looks like you are already rtp''ing, have some patience!' Sign: '&7Command sign has been created! &7Command is... ''&f/rtp %command%&7''' + Edit: + Error: '&cError! &7Invalid input provided!' + Set: '&bSuccess! &7%type% set to %value%' + Remove: '&cRemoved! &7You removed the Custom World %world%' Help: List: @@ -43,4 +47,7 @@ Usage: Player: '&cUsage&7: /%command% player [world] [biome1, biome2]' World: '&cUsage&7: /%command% world [biome1, biome2...]' Biome: '&cUsage&7: /%command% biome ' - Edit: '&cUsage&7: /%command% edit [max/min/useworldborder/center]' \ No newline at end of file + Edit: + Base: '&cUsage&7: /%command% edit [args...]' + Default: '&cUsage&7: /%command% edit default ' + World: '&cUsage&7: /%command% edit world ' \ No newline at end of file diff --git a/src/main/resources/lang/fr.yml b/src/main/resources/lang/fr.yml index f64f8ca..e2c9ae8 100644 --- a/src/main/resources/lang/fr.yml +++ b/src/main/resources/lang/fr.yml @@ -42,4 +42,7 @@ Usage: Player: '&cUtilisation&7: /%command% player [monde]' World: '&cUtilisation&7: /%command% world ' Biome: '&cUtilisation&7: /%command% biome ' - Edit: '&cUsage&7: /%command% edit [max/min/useworldborder/center]' \ No newline at end of file + Edit: + Base: '&cUsage&7: /%command% edit [args...]' + Default: '&cUsage&7: /%command% edit default ' + World: '&cUsage&7: /%command% edit world ' \ No newline at end of file diff --git a/src/main/resources/lang/ja.yml b/src/main/resources/lang/ja.yml index f40decb..0875109 100644 --- a/src/main/resources/lang/ja.yml +++ b/src/main/resources/lang/ja.yml @@ -43,4 +43,7 @@ Usage: Player: '&c使い方&7: /%command% player <プレイヤー> [ワールド]' World: '&c使い方&7: /%command% world <ワールド>' Biome: '&cUsage&7: /%command% biome ' - Edit: '&cUsage&7: /%command% edit [max/min/useworldborder/center]' \ No newline at end of file + Edit: + Base: '&cUsage&7: /%command% edit [args...]' + Default: '&cUsage&7: /%command% edit default ' + World: '&cUsage&7: /%command% edit world ' \ No newline at end of file diff --git a/src/main/resources/lang/ru.yml b/src/main/resources/lang/ru.yml index d88839c..5d06b82 100644 --- a/src/main/resources/lang/ru.yml +++ b/src/main/resources/lang/ru.yml @@ -43,4 +43,7 @@ Usage: Player: '&cИспользование&7: /%command% player <игрок> [мир]' World: '&cИспользование&7: /%command% world <мир>' Biome: '&cUsage&7: /%command% biome ' - Edit: '&cUsage&7: /%command% edit [max/min/useworldborder/center]' \ No newline at end of file + Edit: + Base: '&cUsage&7: /%command% edit [args...]' + Default: '&cUsage&7: /%command% edit default ' + World: '&cUsage&7: /%command% edit world ' \ No newline at end of file