edit command fixes + dutch translation added

This commit is contained in:
SuperRonanCraft 2020-08-13 16:00:47 -04:00
parent a1cc310c74
commit 77a94812d5
11 changed files with 196 additions and 64 deletions

View File

@ -3,17 +3,13 @@ package me.SuperRonanCraft.BetterRTP.player.commands.types;
import me.SuperRonanCraft.BetterRTP.Main; import me.SuperRonanCraft.BetterRTP.Main;
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommand; import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommand;
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics; import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
import me.SuperRonanCraft.BetterRTP.references.worlds.Custom;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class CmdEdit implements RTPCommand { //Edit a worlds properties public class CmdEdit implements RTPCommand { //Edit a worlds properties
@ -25,74 +21,104 @@ public class CmdEdit implements RTPCommand { //Edit a worlds properties
switch (cmd) { switch (cmd) {
case WORLD: case WORLD:
if (args.length >= 5) { if (args.length >= 5) {
//for (World world : Bukkit.getWorlds()) for (World world : Bukkit.getWorlds()) {
//if (world.getName().toLowerCase().startsWith(args[2].toLowerCase())) { if (world.getName().toLowerCase().startsWith(args[2].toLowerCase())) {
for (RTP_CMD_EDIT_SUB cmde : RTP_CMD_EDIT_SUB.values()) for (RTP_CMD_EDIT_SUB cmde : RTP_CMD_EDIT_SUB.values())
if (cmde.name().toLowerCase().startsWith(args[3].toLowerCase())) { if (cmde.name().toLowerCase().startsWith(args[3].toLowerCase())) {
editWorld(sendi, cmde, args[4], args[2]); editWorld(sendi, cmde, args[4], args[2]);
return; return;
} }
usage(sendi, label); usage(sendi, label, cmd);
return;
}
}
Main.getInstance().getText().getNotExist(sendi, label);
return;
}
usage(sendi, label, cmd);
return; return;
// }
//Main.getInstance().getText().getNotExist(sendi, label);
} else
usage(sendi, label);
break;
case DEFAULT: case DEFAULT:
for (RTP_CMD_EDIT_SUB cmde : RTP_CMD_EDIT_SUB.values()) for (RTP_CMD_EDIT_SUB cmde : RTP_CMD_EDIT_SUB.values())
if (cmde.name().toLowerCase().startsWith(args[2].toLowerCase())) { if (cmde.name().toLowerCase().startsWith(args[2].toLowerCase())) {
editDefault(sendi, cmde, args[3]); editDefault(sendi, cmde, args[3]);
return; return;
} }
usage(sendi, label); usage(sendi, label, cmd);
break; return;
} }
} }
} else } else if (args.length >= 2) {
usage(sendi, label); 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 val, String world) {
Object value = val;
try {
value = cmd.getResult(val);
} catch (Exception e) {
e.printStackTrace();
Main.getInstance().getText().sms(sendi, "Invalid input!");
return;
} }
private void editWorld(CommandSender sendi, RTP_CMD_EDIT_SUB cmd, String value, String world) {
FileBasics.FILETYPE file = FileBasics.FILETYPE.CONFIG; FileBasics.FILETYPE file = FileBasics.FILETYPE.CONFIG;
YamlConfiguration config = file.getConfig(); YamlConfiguration config = file.getConfig();
HashMap<String, Map<?, ?>> cmap = new HashMap<>();
List<Map<?, ?>> map = config.getMapList("CustomWorlds"); List<Map<?, ?>> map = config.getMapList("CustomWorlds");
//for (Map<?, ?> m : map) boolean found = false;
// cmap.put(m.toString(), (Map<?, ?>) m.entrySet(entry)); for (Map<?, ?> m : map) {
if (m.keySet().toArray()[0].equals(world)) {
if (cmap.containsKey(world)) { found = true;
System.out.println(cmap.toString()); for (Object map2 : m.values()) {
Map<?, ?> list = cmap.get(world); Map<Object, Object> values = (Map<Object, Object>) map2;
for (Map.Entry<?, ?> e : list.entrySet()) { values.put(cmd.get(), value);
System.out.println(e.getKey()); Main.getInstance().getText().sms(sendi, cmd.get() + " set to " + value);
} }
cmap.put(world, list); break;
} else { }
Map<String, Object> list = new HashMap<>(); }
list.put(cmd.get(), value); if (!found) {
cmap.put(world, list); Map<Object, Object> map2 = new HashMap<>();
Map<Object, Object> values = new HashMap<>();
values.put(cmd.get(), value);
map2.put(world, values);
map.add(map2);
} }
config.set("CustomWorlds", map); config.set("CustomWorlds", map);
try { try {
config.save(file.getFile()); config.save(file.getFile());
Main.getInstance().getRTP().loadWorldSettings();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); 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; FileBasics.FILETYPE file = FileBasics.FILETYPE.CONFIG;
YamlConfiguration config = file.getConfig(); YamlConfiguration config = file.getConfig();
config.set("Default." + cmd.get(), value);
try { try {
config.save(file.getFile()); config.save(file.getFile());
Main.getInstance().getRTP().loadWorldSettings();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -143,7 +169,15 @@ public class CmdEdit implements RTPCommand { //Edit a worlds properties
return Main.getInstance().getPerms().getEdit(sendi); return Main.getInstance().getPerms().getEdit(sendi);
} }
private void usage(CommandSender sendi, String 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); Main.getInstance().getText().getUsageEdit(sendi, label);
} }
@ -152,16 +186,30 @@ public class CmdEdit implements RTPCommand { //Edit a worlds properties
} }
enum RTP_CMD_EDIT_SUB { 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; private String str;
RTP_CMD_EDIT_SUB(String str) { RTP_CMD_EDIT_SUB(String str, String type) {
this.str = str; this.str = str;
this.type = type;
} }
String get() { String get() {
return str; 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;
}
} }
} }

View File

@ -41,8 +41,7 @@ public class RTP {
} }
public void load() { public void load() {
defaultWorld.setup(); FileBasics.FILETYPE config = FileBasics.FILETYPE.CONFIG;
FileBasics.FILETYPE config = getPl().getFiles().getType(FileBasics.FILETYPE.CONFIG);
disabledWorlds = config.getStringList("DisabledWorlds"); disabledWorlds = config.getStringList("DisabledWorlds");
maxAttempts = config.getInt("Settings.MaxAttempts"); maxAttempts = config.getInt("Settings.MaxAttempts");
delayTime = config.getInt("Settings.Delay.Time"); delayTime = config.getInt("Settings.Delay.Time");
@ -65,20 +64,6 @@ public class RTP {
//No Overrides //No Overrides
} }
//CUSTOM WORLDS
try {
customWorlds.clear();
List<Map<?, ?>> 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 { try {
world_type.clear(); world_type.clear();
for (World world : Bukkit.getWorlds()) for (World world : Bukkit.getWorlds())
@ -111,9 +96,30 @@ public class RTP {
e.printStackTrace(); e.printStackTrace();
//No World Types //No World Types
} }
loadWorldSettings();
teleport.load(); //Load teleporting stuff teleport.load(); //Load teleporting stuff
} }
public void loadWorldSettings() {
FileBasics.FILETYPE config = FileBasics.FILETYPE.CONFIG;
defaultWorld.setup();
//CUSTOM WORLDS
try {
customWorlds.clear();
List<Map<?, ?>> 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<String> disabledWorlds() { public List<String> disabledWorlds() {
return disabledWorlds; return disabledWorlds;
} }

View File

@ -52,10 +52,10 @@ public class LangFile {
generateDefaults(pl); 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) { private void generateDefaults(Main pl) {
//Generate allLangs //Generate all language files
for (String yaml : defaultLangs) { for (String yaml : defaultLangs) {
if (yaml.equals(defaultLangs[0]) && config.getName().equals(defaultLangs[0])) if (yaml.equals(defaultLangs[0]) && config.getName().equals(defaultLangs[0]))
continue; continue;

View File

@ -155,7 +155,15 @@ public class Messages {
} }
public void getUsageEdit(CommandSender sendi, String cmd) { 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 // Not Found

View File

@ -43,4 +43,7 @@ Usage:
Player: '&cUsage&7: /%command% player <玩家> [世界] [生物群系1, 生物群系2]' Player: '&cUsage&7: /%command% player <玩家> [世界] [生物群系1, 生物群系2]'
World: '&cUsage&7: /%command% world <世界> [生物群系1, 生物群系2...]' World: '&cUsage&7: /%command% world <世界> [生物群系1, 生物群系2...]'
Biome: '&cUsage&7: /%command% biome <生物群系1, 生物群系2...>' Biome: '&cUsage&7: /%command% biome <生物群系1, 生物群系2...>'
Edit: '&cUsage&7: /%command% edit <default/world> [max/min/useworldborder/center]' Edit:
Base: '&cUsage&7: /%command% edit <default/world> [args...]'
Default: '&cUsage&7: /%command% edit default <max/min/useworldborder/center> <value>'
World: '&cUsage&7: /%command% edit world <world> <max/min/useworldborder/center> <value>'

View File

@ -43,4 +43,7 @@ Usage:
Player: '&cUsage&7: /%command% player <玩家> [世界] [生態域1, 生態域2]' Player: '&cUsage&7: /%command% player <玩家> [世界] [生態域1, 生態域2]'
World: '&cUsage&7: /%command% world <世界> [生態域1, 生態域2...]' World: '&cUsage&7: /%command% world <世界> [生態域1, 生態域2...]'
Biome: '&cUsage&7: /%command% biome <生態域1, 生態域2...>' Biome: '&cUsage&7: /%command% biome <生態域1, 生態域2...>'
Edit: '&cUsage&7: /%command% edit <default/world> [max/min/useworldborder/center]' Edit:
Base: '&cUsage&7: /%command% edit <default/world> [args...]'
Default: '&cUsage&7: /%command% edit default <max/min/useworldborder/center> <value>'
World: '&cUsage&7: /%command% edit world <world> <max/min/useworldborder/center> <value>'

View File

@ -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 <player> [world] [biome1, biome2...] &7- Random teleport een andere speler'
World: ' &7- &e/%command% world <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 <biome1, biome2...> &7- Random teleport in deze biome'
Reload: ' &7- &e/%command% reload &7- Herlaad de plugin'
Usage:
Player: '&cUsage&7: /%command% player <player> [world] [biome1, biome2]'
World: '&cUsage&7: /%command% world <world> [biome1, biome2...]'
Biome: '&cUsage&7: /%command% biome <biome1, biome2...>'
Edit:
Base: '&cUsage&7: /%command% edit <default/world> [args...]'
Default: '&cUsage&7: /%command% edit default <max/min/useworldborder/center> <value>'
World: '&cUsage&7: /%command% edit world <world> <max/min/useworldborder/center> <value>'

View File

@ -26,6 +26,10 @@ Messages:
NotExist: '&cLooks like the world &7%world% &cdoesn''t exist!' NotExist: '&cLooks like the world &7%world% &cdoesn''t exist!'
Already: '&cWhoops! &7Looks like you are already rtp''ing, have some patience!' Already: '&cWhoops! &7Looks like you are already rtp''ing, have some patience!'
Sign: '&7Command sign has been created! &7Command is... ''&f/rtp %command%&7''' 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: Help:
List: List:
@ -43,4 +47,7 @@ Usage:
Player: '&cUsage&7: /%command% player <player> [world] [biome1, biome2]' Player: '&cUsage&7: /%command% player <player> [world] [biome1, biome2]'
World: '&cUsage&7: /%command% world <world> [biome1, biome2...]' World: '&cUsage&7: /%command% world <world> [biome1, biome2...]'
Biome: '&cUsage&7: /%command% biome <biome1, biome2...>' Biome: '&cUsage&7: /%command% biome <biome1, biome2...>'
Edit: '&cUsage&7: /%command% edit <default/world> [max/min/useworldborder/center]' Edit:
Base: '&cUsage&7: /%command% edit <default/world> [args...]'
Default: '&cUsage&7: /%command% edit default <max/min/useworldborder/center> <value>'
World: '&cUsage&7: /%command% edit world <world> <max/min/useworldborder/center> <value>'

View File

@ -42,4 +42,7 @@ Usage:
Player: '&cUtilisation&7: /%command% player <joeur> [monde]' Player: '&cUtilisation&7: /%command% player <joeur> [monde]'
World: '&cUtilisation&7: /%command% world <monde>' World: '&cUtilisation&7: /%command% world <monde>'
Biome: '&cUtilisation&7: /%command% biome <biome1, biome2...>' Biome: '&cUtilisation&7: /%command% biome <biome1, biome2...>'
Edit: '&cUsage&7: /%command% edit <default/world> [max/min/useworldborder/center]' Edit:
Base: '&cUsage&7: /%command% edit <default/world> [args...]'
Default: '&cUsage&7: /%command% edit default <max/min/useworldborder/center> <value>'
World: '&cUsage&7: /%command% edit world <world> <max/min/useworldborder/center> <value>'

View File

@ -43,4 +43,7 @@ Usage:
Player: '&c使い方&7: /%command% player <プレイヤー> [ワールド]' Player: '&c使い方&7: /%command% player <プレイヤー> [ワールド]'
World: '&c使い方&7: /%command% world <ワールド>' World: '&c使い方&7: /%command% world <ワールド>'
Biome: '&cUsage&7: /%command% biome <biome1, biome2...>' Biome: '&cUsage&7: /%command% biome <biome1, biome2...>'
Edit: '&cUsage&7: /%command% edit <default/world> [max/min/useworldborder/center]' Edit:
Base: '&cUsage&7: /%command% edit <default/world> [args...]'
Default: '&cUsage&7: /%command% edit default <max/min/useworldborder/center> <value>'
World: '&cUsage&7: /%command% edit world <world> <max/min/useworldborder/center> <value>'

View File

@ -43,4 +43,7 @@ Usage:
Player: '&cИспользование&7: /%command% player <игрок> [мир]' Player: '&cИспользование&7: /%command% player <игрок> [мир]'
World: '&cИспользование&7: /%command% world <мир>' World: '&cИспользование&7: /%command% world <мир>'
Biome: '&cUsage&7: /%command% biome <biome1, biome2...>' Biome: '&cUsage&7: /%command% biome <biome1, biome2...>'
Edit: '&cUsage&7: /%command% edit <default/world> [max/min/useworldborder/center]' Edit:
Base: '&cUsage&7: /%command% edit <default/world> [args...]'
Default: '&cUsage&7: /%command% edit default <max/min/useworldborder/center> <value>'
World: '&cUsage&7: /%command% edit world <world> <max/min/useworldborder/center> <value>'