From 34d3b656a126162608e51c789982efe5de9e0c13 Mon Sep 17 00:00:00 2001 From: SuperRonanCraft Date: Thu, 13 Aug 2020 12:00:58 -0400 Subject: [PATCH] New `edit` command --- .../player/commands/CommandTypes.java | 1 + .../player/commands/types/CmdEdit.java | 142 ++++++++++++++++++ .../BetterRTP/references/Permissions.java | 4 + .../BetterRTP/references/file/FileBasics.java | 12 +- .../BetterRTP/references/file/Messages.java | 13 +- src/main/resources/config.yml | 2 +- src/main/resources/effects.yml | 4 +- src/main/resources/lang/chn.yml | 3 +- src/main/resources/lang/cht.yml | 1 + src/main/resources/lang/en.yml | 3 +- src/main/resources/lang/fr.yml | 3 +- src/main/resources/lang/ja.yml | 3 +- src/main/resources/lang/ru.yml | 3 +- src/main/resources/plugin.yml | 3 + 14 files changed, 176 insertions(+), 21 deletions(-) create mode 100644 src/main/java/me/SuperRonanCraft/BetterRTP/player/commands/types/CmdEdit.java diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/player/commands/CommandTypes.java b/src/main/java/me/SuperRonanCraft/BetterRTP/player/commands/CommandTypes.java index 42a7717..eea1d2a 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/player/commands/CommandTypes.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/player/commands/CommandTypes.java @@ -11,6 +11,7 @@ public enum CommandTypes { //SETTINGS(new CmdSettings(), true), VERSION(new CmdVersion()), WORLD(new CmdWorld()), + EDIT(new CmdEdit()), TEST(new CmdTest(), true); //Only gets added if debugger enabled private final RTPCommand cmd; 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 new file mode 100644 index 0000000..2cbf0b3 --- /dev/null +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/player/commands/types/CmdEdit.java @@ -0,0 +1,142 @@ +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; + +public class CmdEdit implements RTPCommand { //Edit a worlds properties + + @Override + public void execute(CommandSender sendi, String label, String[] args) { + if (args.length >= 4) { + for (RTP_CMD_EDIT cmd : RTP_CMD_EDIT.values()) + if (cmd.name().toLowerCase().startsWith(args[1].toLowerCase())) { + switch (cmd) { + case WORLD: + if (args.length >= 5) { + 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], world); + return; + } + usage(sendi, label); + return; + } + Main.getInstance().getText().getNotExist(sendi, label); + } else + usage(sendi, label); + break; + 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; + } + } + } else + usage(sendi, label); + } + + private void editWorld(CommandSender sendi, RTP_CMD_EDIT_SUB cmd, String value, World world) { + FileBasics.FILETYPE file = FileBasics.FILETYPE.CONFIG; + YamlConfiguration config = file.getConfig(); + + HashMap> map = (HashMap>) config.getMapList("CustomWorlds"); + + if (map.containsKey()) + + config.set("CustomWorlds", customWorlds); + + try { + config.save(file.getFile()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private void editDefault(CommandSender sendi, RTP_CMD_EDIT_SUB cmd, String value) { + FileBasics.FILETYPE file = FileBasics.FILETYPE.CONFIG; + YamlConfiguration config = file.getConfig(); + + + + try { + config.save(file.getFile()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + //rtp edit default + //rtp edit world [] + @Override + public List tabComplete(CommandSender sendi, String[] args) { + List list = new ArrayList<>(); + if (args.length == 2) { + for (RTP_CMD_EDIT cmd : RTP_CMD_EDIT.values()) + if (cmd.name().toLowerCase().startsWith(args[1].toLowerCase())) + list.add(cmd.name().toLowerCase()); + } else if (args.length == 3) { + for (RTP_CMD_EDIT cmd : RTP_CMD_EDIT.values()) + if (cmd.name().toLowerCase().startsWith(args[1].toLowerCase())) { + switch (cmd) { + case WORLD: //List all worlds + for (World world : Bukkit.getWorlds()) + if (world.getName().toLowerCase().startsWith(args[2].toLowerCase())) + list.add(world.getName()); + break; + case DEFAULT: + list.addAll(tabCompleteSub(args)); + } + } + } else if (args.length == 4) { + for (RTP_CMD_EDIT cmd : RTP_CMD_EDIT.values()) + if (cmd.name().toLowerCase().startsWith(args[1].toLowerCase())) + if (cmd == RTP_CMD_EDIT.WORLD) + list.addAll(tabCompleteSub(args)); + } + return list; + } + + private List tabCompleteSub(String[] args) { + List list = new ArrayList<>(); + for (RTP_CMD_EDIT_SUB cmd : RTP_CMD_EDIT_SUB.values()) { + if (cmd.name().toLowerCase().startsWith(args[args.length - 1].toLowerCase())) + list.add(cmd.name().toLowerCase()); + } + return list; + } + + @Override + public boolean permission(CommandSender sendi) { + return Main.getInstance().getPerms().getEdit(sendi); + } + + private void usage(CommandSender sendi, String label) { + Main.getInstance().getText().getUsageEdit(sendi, label); + } + + enum RTP_CMD_EDIT { + WORLD, DEFAULT + } + + enum RTP_CMD_EDIT_SUB { + CENTER, MAX, MIN, USEWORLDBORDER + } +} \ No newline at end of file diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/references/Permissions.java b/src/main/java/me/SuperRonanCraft/BetterRTP/references/Permissions.java index f7c47b1..d00692d 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/references/Permissions.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/references/Permissions.java @@ -79,6 +79,10 @@ public class Permissions { return false; } + public boolean getEdit(CommandSender sendi) { + return perm(pre + "edit", sendi); + } + private boolean perm(String str, CommandSender sendi) { return depPerms.hasPerm(str, sendi); } diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/references/file/FileBasics.java b/src/main/java/me/SuperRonanCraft/BetterRTP/references/file/FileBasics.java index 44e158f..fb1faf0 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/references/file/FileBasics.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/references/file/FileBasics.java @@ -28,9 +28,11 @@ public class FileBasics { private String fileName; private YamlConfiguration config = new YamlConfiguration(); + private File file; FILETYPE(String str) { this.fileName = str + ".yml"; + this.file = new File(Main.getInstance().getDataFolder(), fileName); } //PUBLIC @@ -71,20 +73,22 @@ public class FileBasics { return config.getMapList(path); } - public YamlConfiguration getFile() { + public YamlConfiguration getConfig() { return config; } + public File getFile() { + return file; + } + public void setValue(String path, Object value) { config.set(path, value); } //PROCCESSING private void load() { - Main pl = Main.getInstance(); - File file = new File(pl.getDataFolder(), fileName); if (!file.exists()) - pl.saveResource(fileName, false); + Main.getInstance().saveResource(fileName, false); try { config.load(file); final InputStream defConfigStream = Main.getInstance().getResource(fileName); 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 beb7d8e..1907158 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/references/file/Messages.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/references/file/Messages.java @@ -153,15 +153,10 @@ public class Messages { public void getUsageBiome(CommandSender sendi, String cmd) { sms(sendi, getLang().getString(preU + "Biome").replaceAll("%command%", cmd)); } - /* - * public int getFadeIn() { return getLang().getInt("Titles.Time.FadeIn"); - * } - * - * public int getStay() { return getLang().getInt("Titles.Time.Stay"); } - * - * public int getFadeOut() { return - * getLang().getInt("Titles.Time.FadeOut"); } - */ + + public void getUsageEdit(CommandSender sendi, String cmd) { + sms(sendi, getLang().getString(preU + "Edit").replaceAll("%command%", cmd)); + } // Not Found public void error(CommandSender sendi) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 94bbbfe..35713ef 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -66,7 +66,7 @@ DisabledWorlds: CustomWorlds: - custom_world_1: UseWorldBorder: false - ## If UseWorldBorder is true, everything will be ignored EXEPT "MinRadius"! + ## If UseWorldBorder is true, everything will be ignored EXCEPT "MinRadius"! MaxRadius: 1000 MinRadius: 100 CenterX: 0 diff --git a/src/main/resources/effects.yml b/src/main/resources/effects.yml index c3d57fb..1aeee3b 100644 --- a/src/main/resources/effects.yml +++ b/src/main/resources/effects.yml @@ -24,8 +24,8 @@ Titles: SendMessage: true # Allow the loading message in chat Particles: #Use `rtp info particles` for a list of particles Enabled: true - Type: 'REVERSE_PORTAL' #list of particle types at https://github.com/ByteZ1337/ParticleLib/blob/master/src/main/java/xyz/xenondevs/particle/ParticleEffect.java - Shape: 'SCAN' #Types available are "Scan, Teleport and Explode", or use `/rtp info shapes` for a list of shapes + Type: 'EXPLOSION_NORMAL' #list of particle types at https://github.com/ByteZ1337/ParticleLib/blob/master/src/main/java/xyz/xenondevs/particle/ParticleEffect.java + Shape: 'EXPLODE' #Types available are "Scan, Teleport and Explode", or use `/rtp info shapes` for a list of shapes Invincible: #Amount of time a player should not take damage for Enabled: true Seconds: 5 diff --git a/src/main/resources/lang/chn.yml b/src/main/resources/lang/chn.yml index 253bbdc..a3f5f18 100644 --- a/src/main/resources/lang/chn.yml +++ b/src/main/resources/lang/chn.yml @@ -42,4 +42,5 @@ Help: Usage: Player: '&cUsage&7: /%command% player <玩家> [世界] [生物群系1, 生物群系2]' World: '&cUsage&7: /%command% world <世界> [生物群系1, 生物群系2...]' - Biome: '&cUsage&7: /%command% biome <生物群系1, 生物群系2...>' \ No newline at end of file + Biome: '&cUsage&7: /%command% biome <生物群系1, 生物群系2...>' + Edit: '&cUsage&7: /%command% edit [max/min/useworldborder/center]' \ No newline at end of file diff --git a/src/main/resources/lang/cht.yml b/src/main/resources/lang/cht.yml index cd5788f..d12c929 100644 --- a/src/main/resources/lang/cht.yml +++ b/src/main/resources/lang/cht.yml @@ -43,3 +43,4 @@ 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 diff --git a/src/main/resources/lang/en.yml b/src/main/resources/lang/en.yml index 4c3c193..cdf1615 100644 --- a/src/main/resources/lang/en.yml +++ b/src/main/resources/lang/en.yml @@ -42,4 +42,5 @@ Help: Usage: Player: '&cUsage&7: /%command% player [world] [biome1, biome2]' World: '&cUsage&7: /%command% world [biome1, biome2...]' - Biome: '&cUsage&7: /%command% biome ' \ No newline at end of file + Biome: '&cUsage&7: /%command% biome ' + Edit: '&cUsage&7: /%command% edit [max/min/useworldborder/center]' \ No newline at end of file diff --git a/src/main/resources/lang/fr.yml b/src/main/resources/lang/fr.yml index 42ec916..f64f8ca 100644 --- a/src/main/resources/lang/fr.yml +++ b/src/main/resources/lang/fr.yml @@ -41,4 +41,5 @@ Help: Usage: Player: '&cUtilisation&7: /%command% player [monde]' World: '&cUtilisation&7: /%command% world ' - Biome: '&cUtilisation&7: /%command% biome ' \ No newline at end of file + Biome: '&cUtilisation&7: /%command% biome ' + Edit: '&cUsage&7: /%command% edit [max/min/useworldborder/center]' \ No newline at end of file diff --git a/src/main/resources/lang/ja.yml b/src/main/resources/lang/ja.yml index 49dc60c..f40decb 100644 --- a/src/main/resources/lang/ja.yml +++ b/src/main/resources/lang/ja.yml @@ -42,4 +42,5 @@ Help: Usage: Player: '&c使い方&7: /%command% player <プレイヤー> [ワールド]' World: '&c使い方&7: /%command% world <ワールド>' - Biome: '&cUsage&7: /%command% biome ' \ No newline at end of file + Biome: '&cUsage&7: /%command% biome ' + Edit: '&cUsage&7: /%command% edit [max/min/useworldborder/center]' \ No newline at end of file diff --git a/src/main/resources/lang/ru.yml b/src/main/resources/lang/ru.yml index 7f23f30..d88839c 100644 --- a/src/main/resources/lang/ru.yml +++ b/src/main/resources/lang/ru.yml @@ -42,4 +42,5 @@ Help: Usage: Player: '&cИспользование&7: /%command% player <игрок> [мир]' World: '&cИспользование&7: /%command% world <мир>' - Biome: '&cUsage&7: /%command% biome ' \ No newline at end of file + Biome: '&cUsage&7: /%command% biome ' + Edit: '&cUsage&7: /%command% edit [max/min/useworldborder/center]' \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 16c8735..ec745a0 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -55,4 +55,7 @@ permissions: default: op betterrtp.test: description: While debugger enabled, be able to test particles, potion effects and sounds + default: op + betterrtp.edit: + description: Edit a custom/default world rtp center/radius default: op \ No newline at end of file