New edit command

This commit is contained in:
SuperRonanCraft 2020-08-13 12:00:58 -04:00
parent d2c9b14d75
commit 34d3b656a1
14 changed files with 176 additions and 21 deletions

View File

@ -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;

View File

@ -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<String, List<String>> map = (HashMap<String, List<String>>) 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 <max/min/center/useworldborder> <value>
//rtp edit world [<world>] <max/min/center/useworldborder> <value>
@Override
public List<String> tabComplete(CommandSender sendi, String[] args) {
List<String> 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<String> tabCompleteSub(String[] args) {
List<String> 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
}
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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) {

View File

@ -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

View File

@ -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

View File

@ -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...>'
Biome: '&cUsage&7: /%command% biome <生物群系1, 生物群系2...>'
Edit: '&cUsage&7: /%command% edit <default/world> [max/min/useworldborder/center]'

View File

@ -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 <default/world> [max/min/useworldborder/center]'

View File

@ -42,4 +42,5 @@ Help:
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...>'
Biome: '&cUsage&7: /%command% biome <biome1, biome2...>'
Edit: '&cUsage&7: /%command% edit <default/world> [max/min/useworldborder/center]'

View File

@ -41,4 +41,5 @@ Help:
Usage:
Player: '&cUtilisation&7: /%command% player <joeur> [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]'

View File

@ -42,4 +42,5 @@ Help:
Usage:
Player: '&c使い方&7: /%command% player <プレイヤー> [ワールド]'
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]'

View File

@ -42,4 +42,5 @@ Help:
Usage:
Player: '&cИспользование&7: /%command% player <игрок> [мир]'
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]'

View File

@ -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