world locations loading implementation + edit command now supports shapes and price

This commit is contained in:
SuperRonanCraft 2021-03-22 00:11:20 -04:00
parent 123569adbb
commit 2da1210578
7 changed files with 679 additions and 42 deletions

View File

@ -1,13 +1,16 @@
package me.SuperRonanCraft.BetterRTP.player.commands.types;
import com.bekvon.bukkit.residence.containers.cmd;
import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommandHelpable;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP_SHAPE;
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommand;
import me.SuperRonanCraft.BetterRTP.references.worlds.WORLD_TYPE;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
@ -34,7 +37,7 @@ public class CmdEdit implements RTPCommand, RTPCommandHelpable { //Edit a worlds
if (world.getName().startsWith(args[2])) {
for (RTP_CMD_EDIT_SUB sub_cmd : RTP_CMD_EDIT_SUB.values())
if (sub_cmd.name().toLowerCase().startsWith(args[3].toLowerCase())) {
editWorld(sendi, sub_cmd, args[4], args[2]);
editWorld(sendi, sub_cmd, args[2], args[4]);
return;
}
usage(sendi, label, cmd);
@ -94,7 +97,7 @@ public class CmdEdit implements RTPCommand, RTPCommandHelpable { //Edit a worlds
usage(sendi, label, null);
}
private void editWorld(CommandSender sendi, RTP_CMD_EDIT_SUB cmd, String val, String world) {
private void editWorld(CommandSender sendi, RTP_CMD_EDIT_SUB cmd, String world, String val) {
Object value;
try {
value = cmd.getResult(val);
@ -104,6 +107,11 @@ public class CmdEdit implements RTPCommand, RTPCommandHelpable { //Edit a worlds
return;
}
if (value == null) {
BetterRTP.getInstance().getText().getEditError(sendi);
return;
}
FileBasics.FILETYPE file = FileBasics.FILETYPE.CONFIG;
YamlConfiguration config = file.getConfig();
@ -115,7 +123,6 @@ public class CmdEdit implements RTPCommand, RTPCommandHelpable { //Edit a worlds
for (Object map2 : m.values()) {
Map<Object, Object> values = (Map<Object, Object>) map2;
values.put(cmd.get(), value);
BetterRTP.getInstance().getText().getEditSet(sendi, cmd.get(), val);
}
break;
@ -133,7 +140,7 @@ public class CmdEdit implements RTPCommand, RTPCommandHelpable { //Edit a worlds
try {
config.save(file.getFile());
BetterRTP.getInstance().getRTP().loadWorldSettings();
BetterRTP.getInstance().getRTP().loadCustomWorlds();
} catch (IOException e) {
e.printStackTrace();
}
@ -149,6 +156,11 @@ public class CmdEdit implements RTPCommand, RTPCommandHelpable { //Edit a worlds
return;
}
if (value == null) {
BetterRTP.getInstance().getText().getEditError(sendi);
return;
}
FileBasics.FILETYPE file = FileBasics.FILETYPE.CONFIG;
YamlConfiguration config = file.getConfig();
@ -156,7 +168,7 @@ public class CmdEdit implements RTPCommand, RTPCommandHelpable { //Edit a worlds
try {
config.save(file.getFile());
BetterRTP.getInstance().getRTP().loadWorldSettings();
BetterRTP.getInstance().getRTP().loadCustomWorlds();
BetterRTP.getInstance().getText().getEditSet(sendi, cmd.get(), val);
} catch (IOException e) {
e.printStackTrace();
@ -340,6 +352,14 @@ public class CmdEdit implements RTPCommand, RTPCommandHelpable { //Edit a worlds
list.add(String.valueOf(((Player) sendi).getLocation().getBlockX()));
else if (args[3].equalsIgnoreCase(RTP_CMD_EDIT_SUB.CENTER_Z.name()))
list.add(String.valueOf(((Player) sendi).getLocation().getBlockZ()));
else if (args[3].equalsIgnoreCase(RTP_CMD_EDIT_SUB.SHAPE.name()))
for (RTP_SHAPE shape : RTP_SHAPE.values())
list.add(shape.name().toLowerCase());
/*else if (args[3].equalsIgnoreCase(RTP_CMD_EDIT_SUB.BIOME_ADD.name()))
for (Biome biome : Biome.values()) {
if (biome.name().toLowerCase().startsWith(args[4].toLowerCase()) && list.size() < 20)
list.add(biome.name());
}*/
}
}
return list;
@ -387,11 +407,14 @@ public class CmdEdit implements RTPCommand, RTPCommandHelpable { //Edit a worlds
WORLD, DEFAULT, WORLD_TYPE, OVERRIDE, BLACKLISTEDBLOCKS
}
enum RTP_CMD_EDIT_SUB {
enum RTP_CMD_EDIT_SUB { //Only for World and Default
CENTER_X("CenterX", "INT"),
CENTER_Z("CenterZ", "INT"),
MAX("MaxRadius", "INT"),
MIN("MinRadius", "INT"),
PRICE("Price", "INT"),
SHAPE("Shape", "SHAPE"),
//BIOME_ADD("Biomes", "STR"),
USEWORLDBORDER("UseWorldBorder", "BOL");
private final String type;
@ -411,8 +434,15 @@ public class CmdEdit implements RTPCommand, RTPCommandHelpable { //Edit a worlds
return Integer.parseInt(input);
else if (this.type.equalsIgnoreCase("BOL"))
return Boolean.valueOf(input);
else if (this.type.equalsIgnoreCase("WORLDTYPE")) //WILL CAUSE ERROR IF INCORRECT
return WORLD_TYPE.valueOf(input).name();
else if (this.type.equalsIgnoreCase("STR"))
return Collections.singletonList(input);
else if (this.type.equalsIgnoreCase("SHAPE")) {
try {
return RTP_SHAPE.valueOf(input.toUpperCase()).name();
} catch (IllegalArgumentException e) {
return null;
}
}
return null;
}
}

View File

@ -32,7 +32,9 @@ public class CmdInfo implements RTPCommand, RTPCommandHelpable {
else if (args[1].equalsIgnoreCase(CmdInfoSub.POTION_EFFECTS.name()))
infoEffects(sendi);
else if (args[1].equalsIgnoreCase(CmdInfoSub.WORLD.name())) {
if (sendi instanceof Player) { //Personalize with permission groups
if (args.length > 2 && Bukkit.getWorld(args[2]) != null) {
sendInfoWorld(sendi, infoGetWorld(sendi, Bukkit.getWorld(args[2]), false));
} else if (sendi instanceof Player) { //Personalize with permission groups
World world = null;
boolean personal = false;
if (args.length > 2) {
@ -121,23 +123,22 @@ public class CmdInfo implements RTPCommand, RTPCommandHelpable {
else {
info.add("&7- &6Disabled: " + _false);
if (pl.getRTP().overriden.containsKey(w.getName()))
info.add("&7- &6Overriden: " + _true + " &7(" + pl.getRTP().overriden.get(w.getName()) + ")");
info.add("&7- &6Overriden: " + _true + " &7 target world `" + pl.getRTP().overriden.get(w.getName()) + "`");
else {
info.add("&7- &6WorldType: &f" + pl.getRTP().world_type.getOrDefault(w.getName(), WORLD_TYPE.NORMAL).name());
info.add("&7- &6Overriden: " + _false);
info.add("&7- &6Overriden&7: " + _false);
WorldPlayer _rtpworld = BetterRTP.getInstance().getRTP().getPlayerWorld(sendi, w.getName(), null, personal);
WorldDefault worldDefault = BetterRTP.getInstance().getRTP().defaultWorld;
info.add("&7- &6Custom: " + (BetterRTP.getInstance().getRTP().customWorlds.containsKey(w.getName()) ? _true : _false));
info.add("&7- &6UseWorldBorder: " + (_rtpworld.getUseWorldborder() ? _true : _false));
info.add("&7- &6Permission Group: " + (_rtpworld.getConfig() != null ? "&e" + _rtpworld.getConfig().name : "&cN/A"));
info.add("&7- &6Center X: &f" + _rtpworld.getCenterX() + getInfo(_rtpworld, worldDefault, "centerx"));
info.add("&7- &6Center Z: &f" + _rtpworld.getCenterZ() + getInfo(_rtpworld, worldDefault, "centerz"));
info.add("&7- &6MaxRad: &f" + _rtpworld.getMaxRad() + getInfo(_rtpworld, worldDefault, "max"));
info.add("&7- &6MinRad: &f" + _rtpworld.getMinRad() + getInfo(_rtpworld, worldDefault, "min"));
info.add("&7- &6Price: &f" + _rtpworld.getPrice() + getInfo(_rtpworld, worldDefault, "price"));
info.add("&7- &6World Type: &f" + _rtpworld.getWorldtype().name());
info.add("&7- &6Biomes: &f" + _rtpworld.getBiomes().toString());
info.add("&7- &6Shape: &f" + _rtpworld.getShape().toString());
info.add("&7- &6Custom World&7: " + (BetterRTP.getInstance().getRTP().customWorlds.containsKey(w.getName()) ? _true : _false + " &8(using defaults)"));
info.add("&7- &6Use World Border&7: " + (_rtpworld.getUseWorldborder() ? _true : _false));
info.add("&7- &6Permission Group&7: " + (_rtpworld.getConfig() != null ? "&e" + _rtpworld.getConfig().name : "&cN/A"));
info.add("&7- &6Center X&7: &f" + _rtpworld.getCenterX() + getInfo(_rtpworld, worldDefault, "centerx"));
info.add("&7- &6Center Z&7: &f" + _rtpworld.getCenterZ() + getInfo(_rtpworld, worldDefault, "centerz"));
info.add("&7- &6Maximum Radius&7: &f" + _rtpworld.getMaxRad() + getInfo(_rtpworld, worldDefault, "max"));
info.add("&7- &6Minimum Radius&7: &f" + _rtpworld.getMinRad() + getInfo(_rtpworld, worldDefault, "min"));
info.add("&7- &6Price&7: &f" + _rtpworld.getPrice() + getInfo(_rtpworld, worldDefault, "price"));
info.add("&7- &6World Type&7: &f" + _rtpworld.getWorldtype().name());
info.add("&7- &6Biomes&7: &f" + _rtpworld.getBiomes().toString());
info.add("&7- &6Shape&7: &f" + _rtpworld.getShape().toString());
}
}
return info;
@ -188,6 +189,9 @@ public class CmdInfo implements RTPCommand, RTPCommandHelpable {
if (p.getName().toLowerCase().startsWith(args[2].toLowerCase()))
info.add(p.getName());
}
for (World world : Bukkit.getWorlds())
if (world.getName().toLowerCase().startsWith(args[2].toLowerCase()))
info.add(world.getName());
}
}
return info;

View File

@ -0,0 +1,421 @@
package me.SuperRonanCraft.BetterRTP.player.commands.types;
import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommand;
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommandHelpable;
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
import me.SuperRonanCraft.BetterRTP.references.worlds.WORLD_TYPE;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class CmdLocation implements RTPCommand, RTPCommandHelpable { //Edit a worlds properties
public String getName() {
return "edit";
}
@Override
public void execute(CommandSender sendi, String label, String[] args) {
if (args.length >= 4) {
for (RTP_CMD_LOCATION cmd : RTP_CMD_LOCATION.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().startsWith(args[2])) {
for (RTP_CMD_LOCATION_SUB sub_cmd : RTP_CMD_LOCATION_SUB.values())
if (sub_cmd.name().toLowerCase().startsWith(args[3].toLowerCase())) {
editWorld(sendi, sub_cmd, args[4], args[2]);
return;
}
usage(sendi, label, cmd);
return;
}
}
BetterRTP.getInstance().getText().getNotExist(sendi, args[2]);
return;
}
usage(sendi, label, cmd);
return;
case DEFAULT:
for (RTP_CMD_LOCATION_SUB sub_cmd : RTP_CMD_LOCATION_SUB.values())
if (sub_cmd.name().toLowerCase().startsWith(args[2].toLowerCase())) {
editDefault(sendi, sub_cmd, args[3]);
return;
}
usage(sendi, label, cmd);
return;
case WORLD_TYPE:
for (World world : Bukkit.getWorlds()) {
if (world.getName().startsWith(args[2])) {
editWorldtype(sendi, args[2], args[3]);
//usage(sendi, label, cmd);
return;
}
}
BetterRTP.getInstance().getText().getNotExist(sendi, args[2]);
return;
case OVERRIDE:
for (World world : Bukkit.getWorlds()) {
if (world.getName().startsWith(args[2])) {
editOverride(sendi, args[2], args[3]);
//usage(sendi, label, cmd);
return;
}
}
BetterRTP.getInstance().getText().getNotExist(sendi, args[2]);
return;
case BLACKLISTEDBLOCKS:
if (args[2].equalsIgnoreCase("add")) {
editBlacklisted(sendi, args[3], true);
} else if (args[2].equalsIgnoreCase("remove")) {
editBlacklisted(sendi, args[3], false);
} else
usage(sendi, label, cmd);
return;
}
}
} else if (args.length >= 2) {
for (RTP_CMD_LOCATION cmd : RTP_CMD_LOCATION.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_LOCATION_SUB cmd, String val, String world) {
Object value;
try {
value = cmd.getResult(val);
} catch (Exception e) {
e.printStackTrace();
BetterRTP.getInstance().getText().getEditError(sendi);
return;
}
FileBasics.FILETYPE file = FileBasics.FILETYPE.CONFIG;
YamlConfiguration config = file.getConfig();
List<Map<?, ?>> map = config.getMapList("CustomWorlds");
boolean found = false;
for (Map<?, ?> m : map) {
if (m.keySet().toArray()[0].equals(world)) {
found = true;
for (Object map2 : m.values()) {
Map<Object, Object> values = (Map<Object, Object>) map2;
values.put(cmd.get(), value);
BetterRTP.getInstance().getText().getEditSet(sendi, cmd.get(), val);
}
break;
}
}
if (!found) {
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);
try {
config.save(file.getFile());
BetterRTP.getInstance().getRTP().loadCustomWorlds();
} catch (IOException e) {
e.printStackTrace();
}
}
private void editDefault(CommandSender sendi, RTP_CMD_LOCATION_SUB cmd, String val) {
Object value;
try {
value = cmd.getResult(val);
} catch (Exception e) {
e.printStackTrace();
BetterRTP.getInstance().getText().getEditError(sendi);
return;
}
FileBasics.FILETYPE file = FileBasics.FILETYPE.CONFIG;
YamlConfiguration config = file.getConfig();
config.set("Default." + cmd.get(), value);
try {
config.save(file.getFile());
BetterRTP.getInstance().getRTP().loadCustomWorlds();
BetterRTP.getInstance().getText().getEditSet(sendi, cmd.get(), val);
} catch (IOException e) {
e.printStackTrace();
}
}
private void editWorldtype(CommandSender sendi, String world, String val) {
//sendi.sendMessage("Editting worldtype for world " + world + " to " + val);
WORLD_TYPE type;
try {
type = WORLD_TYPE.valueOf(val.toUpperCase());
} catch (Exception e) {
//e.printStackTrace();
BetterRTP.getInstance().getText().getEditError(sendi);
return;
}
FileBasics.FILETYPE file = FileBasics.FILETYPE.CONFIG;
YamlConfiguration config = file.getConfig();
List<Map<?, ?>> world_map = config.getMapList("WorldType");
List<Map<?, ?>> removeList = new ArrayList<>();
for (Map<?, ?> m : world_map) {
for (Map.Entry<?, ?> entry : m.entrySet()) {
if (entry.getKey().equals(world))
removeList.add(m);
}
}
for (Map<?, ?> o : removeList)
world_map.remove(o);
Map<String, String> newIndex = new HashMap<>();
newIndex.put(world, type.name());
world_map.add(newIndex);
config.set("WorldType", world_map);
try {
config.save(file.getFile());
BetterRTP.getInstance().getRTP().load();
BetterRTP.getInstance().getText().getEditSet(sendi, RTP_CMD_LOCATION.WORLD_TYPE.name(), val);
} catch (IOException e) {
e.printStackTrace();
}
}
private void editOverride(CommandSender sendi, String world, String val) {
FileBasics.FILETYPE file = FileBasics.FILETYPE.CONFIG;
YamlConfiguration config = file.getConfig();
List<Map<?, ?>> world_map = config.getMapList("Overrides");
List<Map<?, ?>> removeList = new ArrayList<>();
for (Map<?, ?> m : world_map) {
for (Map.Entry<?, ?> entry : m.entrySet()) {
if (entry.getKey().equals(world))
removeList.add(m);
}
}
for (Map<?, ?> o : removeList)
world_map.remove(o);
if (!val.equals("REMOVE_OVERRIDE")) {
Map<String, String> newIndex = new HashMap<>();
newIndex.put(world, val);
world_map.add(newIndex);
} else {
val = "(removed override)";
}
config.set("Overrides", world_map);
try {
config.save(file.getFile());
BetterRTP.getInstance().getRTP().load();
BetterRTP.getInstance().getText().getEditSet(sendi, RTP_CMD_LOCATION.OVERRIDE.name(), val);
} catch (IOException e) {
e.printStackTrace();
}
}
private void editBlacklisted(CommandSender sendi, String block, boolean add) {
FileBasics.FILETYPE file = FileBasics.FILETYPE.CONFIG;
YamlConfiguration config = file.getConfig();
List<String> world_map = config.getStringList("BlacklistedBlocks");
List<String> removeList = new ArrayList<>();
for (String m : world_map) {
if (m.equals(block)) {
removeList.add(m);
}
}
for (String o : removeList)
world_map.remove(o);
if (add) {
world_map.add(block);
} else {
block = "(removed " + block + ")";
}
config.set("BlacklistedBlocks", world_map);
try {
config.save(file.getFile());
BetterRTP.getInstance().getRTP().load();
BetterRTP.getInstance().getText().getEditSet(sendi, RTP_CMD_LOCATION.BLACKLISTEDBLOCKS.name(), block);
} catch (IOException e) {
e.printStackTrace();
}
}
//rtp edit default <max/min/center/useworldborder> <value>
//rtp edit world [<world>] <max/min/center/useworldborder> <value>
//rtp edit worldtype <world> <value>
@Override
public List<String> tabComplete(CommandSender sendi, String[] args) {
List<String> list = new ArrayList<>();
if (args.length == 2) {
for (RTP_CMD_LOCATION cmd : RTP_CMD_LOCATION.values())
if (cmd.name().toLowerCase().startsWith(args[1].toLowerCase()))
list.add(cmd.name().toLowerCase());
} else if (args.length == 3) { //rtp edit <sub_cmd> <type>
for (RTP_CMD_LOCATION cmd : RTP_CMD_LOCATION.values())
if (cmd.name().equalsIgnoreCase(args[1])) {
switch (cmd) {
case WORLD_TYPE:
case OVERRIDE:
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, cmd));
break;
case BLACKLISTEDBLOCKS:
list.add("add");
list.add("remove");
break;
}
}
} else if (args.length == 4) {
for (RTP_CMD_LOCATION cmd : RTP_CMD_LOCATION.values())
if (cmd.name().equalsIgnoreCase(args[1]))
switch (cmd) {
case WORLD:
list.addAll(tabCompleteSub(args, cmd)); break;
case DEFAULT:
if (args[2].equalsIgnoreCase(RTP_CMD_LOCATION_SUB.CENTER_X.name()))
list.add(String.valueOf(((Player) sendi).getLocation().getBlockX()));
else if (args[2].equalsIgnoreCase(RTP_CMD_LOCATION_SUB.CENTER_Z.name()))
list.add(String.valueOf(((Player) sendi).getLocation().getBlockZ()));
break;
case WORLD_TYPE:
for (WORLD_TYPE _type : WORLD_TYPE.values())
list.add(_type.name());
break;
case OVERRIDE:
for (World world : Bukkit.getWorlds())
if (world.getName().toLowerCase().startsWith(args[2].toLowerCase()))
list.add(world.getName());
list.add("REMOVE_OVERRIDE");
break;
case BLACKLISTEDBLOCKS:
if (args[2].equalsIgnoreCase("add")) {
for (Material block : Material.values()) {
if (list.size() > 20)
break;
if (block.name().startsWith(args[3].toUpperCase()))
list.add(block.name());
}
} else if (args[2].equalsIgnoreCase("remove")) {
for (String block : BetterRTP.getInstance().getRTP().blockList) {
if (block.startsWith(args[3]))
list.add(block);
}
}
break;
}
} else if (args.length == 5) {
for (RTP_CMD_LOCATION cmd : RTP_CMD_LOCATION.values())
if (cmd.name().equalsIgnoreCase(args[1]))
if (cmd == RTP_CMD_LOCATION.WORLD) {
if (args[3].equalsIgnoreCase(RTP_CMD_LOCATION_SUB.CENTER_X.name()))
list.add(String.valueOf(((Player) sendi).getLocation().getBlockX()));
else if (args[3].equalsIgnoreCase(RTP_CMD_LOCATION_SUB.CENTER_Z.name()))
list.add(String.valueOf(((Player) sendi).getLocation().getBlockZ()));
}
}
return list;
}
private List<String> tabCompleteSub(String[] args, RTP_CMD_LOCATION cmd) {
List<String> list = new ArrayList<>();
for (RTP_CMD_LOCATION_SUB sub_cmd : RTP_CMD_LOCATION_SUB.values()) {
if (sub_cmd.name().toLowerCase().startsWith(args[args.length - 1].toLowerCase()))
list.add(sub_cmd.name().toLowerCase());
}
return list;
}
@Override
public boolean permission(CommandSender sendi) {
return BetterRTP.getInstance().getPerms().getEdit(sendi);
}
private void usage(CommandSender sendi, String label, RTP_CMD_LOCATION type) {
if (type != null)
switch (type) {
case DEFAULT:
BetterRTP.getInstance().getText().getUsageEditDefault(sendi, label); break;
case WORLD:
BetterRTP.getInstance().getText().getUsageEditWorld(sendi, label); break;
case WORLD_TYPE:
BetterRTP.getInstance().getText().getUsageWorldtype(sendi, label); break;
case OVERRIDE:
BetterRTP.getInstance().getText().getUsageOverride(sendi, label); break;
case BLACKLISTEDBLOCKS:
BetterRTP.getInstance().getText().getUsageBlacklistedBlocks(sendi, label); break;
}
else
BetterRTP.getInstance().getText().getUsageEdit(sendi, label);
}
@Override
public String getHelp() {
return BetterRTP.getInstance().getText().getHelpEdit();
}
enum RTP_CMD_LOCATION {
WORLD, DEFAULT, WORLD_TYPE, OVERRIDE, BLACKLISTEDBLOCKS
}
enum RTP_CMD_LOCATION_SUB {
CENTER_X("CenterX", "INT"),
CENTER_Z("CenterZ", "INT"),
MAX("MaxRadius", "INT"),
MIN("MinRadius", "INT"),
USEWORLDBORDER("UseWorldBorder", "BOL");
private final String type;
private final String str;
RTP_CMD_LOCATION_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);
else if (this.type.equalsIgnoreCase("WORLDTYPE")) //WILL CAUSE ERROR IF INCORRECT
return WORLD_TYPE.valueOf(input).name();
return null;
}
}
}

View File

@ -27,6 +27,7 @@ public class RTP {
int maxAttempts, delayTime;
boolean cancelOnMove, cancelOnDamage;
public HashMap<String, WORLD_TYPE> world_type = new HashMap<>();
private HashMap<String, WorldLocations> worldLocations = new HashMap<>();
public RTPTeleport getTeleport() {
return teleport;
@ -40,9 +41,22 @@ public class RTP {
cancelOnMove = config.getBoolean("Settings.Delay.CancelOnMove");
cancelOnDamage = config.getBoolean("Settings.Delay.CancelOnDamage");
blockList = config.getStringList("BlacklistedBlocks");
//OVER-RIDES
//Overrides
loadOverrides();
//WorldType
loadWorldTypes();
//CustomWorlds
loadCustomWorlds();
//Locations
loadWorldLocations();
teleport.load(); //Load teleporting stuff
permConfig.load(); //Load permission configs
}
private void loadOverrides() {
overriden.clear();
try {
overriden.clear();
FileBasics.FILETYPE config = FileBasics.FILETYPE.CONFIG;
List<Map<?, ?>> override_map = config.getMapList("Overrides");
for (Map<?, ?> m : override_map)
for (Map.Entry<?, ?> entry : m.entrySet()) {
@ -55,9 +69,12 @@ public class RTP {
} catch (Exception e) {
//No Overrides
}
}
private void loadWorldTypes() {
world_type.clear();
try {
world_type.clear();
FileBasics.FILETYPE config = FileBasics.FILETYPE.CONFIG;
for (World world : Bukkit.getWorlds())
world_type.put(world.getName(), WORLD_TYPE.NORMAL);
List<Map<?, ?>> world_map = config.getMapList("WorldType");
@ -88,18 +105,13 @@ public class RTP {
e.printStackTrace();
//No World Types
}
loadWorldSettings();
teleport.load(); //Load teleporting stuff
permConfig.load(); //Load permission configs
}
public void loadWorldSettings() {
FileBasics.FILETYPE config = FileBasics.FILETYPE.CONFIG;
public void loadCustomWorlds() {
defaultWorld.setup();
//CUSTOM WORLDS
customWorlds.clear();
try {
customWorlds.clear();
FileBasics.FILETYPE config = FileBasics.FILETYPE.CONFIG;
List<Map<?, ?>> map = config.getMapList("CustomWorlds");
for (Map<?, ?> m : map)
for (Map.Entry<?, ?> entry : m.entrySet()) {
@ -112,6 +124,23 @@ public class RTP {
}
}
public void loadWorldLocations() {
FileBasics.FILETYPE config = FileBasics.FILETYPE.LOCATIONS;
worldLocations.clear();
if (!config.getBoolean("Settings.Enabled"))
return;
List<Map<?, ?>> map = config.getMapList("Locations");
for (Map<?, ?> m : map)
for (Map.Entry<?, ?> entry : m.entrySet()) {
WorldLocations location = new WorldLocations(entry.getKey().toString());
if (location.isValid()) {
worldLocations.put(entry.getKey().toString(), location);
if (getPl().getSettings().debug)
BetterRTP.debug("- Location '" + entry.getKey() + "' registered");
}
}
}
public List<String> disabledWorlds() {
return disabledWorlds;
}

View File

@ -22,7 +22,7 @@ public class FileBasics {
}
public enum FILETYPE {
CONFIG("config"), ECO("economy"), SIGNS("signs"), EFFECTS("effects");
CONFIG("config"), ECO("economy"), SIGNS("signs"), EFFECTS("effects"), LOCATIONS("locations");
private final String fileName;
private final YamlConfiguration config = new YamlConfiguration();

View File

@ -0,0 +1,153 @@
package me.SuperRonanCraft.BetterRTP.references.worlds;
import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTPPermissionGroup;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP_SHAPE;
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldBorder;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
public class WorldLocations implements RTPWorld {
private boolean useWorldborder;
private int CenterX, CenterZ, maxBorderRad, minBorderRad, price;
private List<String> Biomes;
private String world;
private RTP_SHAPE shape;
public WorldLocations(String location_name) {
FileBasics.FILETYPE config = BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.LOCATIONS);
List<Map<?, ?>> map = config.getMapList("Locations");
WorldDefault worldDefault = BetterRTP.getInstance().getRTP().defaultWorld;
//Find Location and cache its values
for (Map<?, ?> m : map) {
for (Map.Entry<?, ?> entry : m.entrySet()) {
String key = entry.getKey().toString();
if (!key.equals(location_name))
continue;
Map<?, ?> test = ((Map<?, ?>) m.get(key));
if (test == null)
continue;
if (test.get("World") != null) {
if (test.get("World").getClass() == String.class)
world = test.get("World").toString();
} else {
BetterRTP.getInstance().getLogger().warning("Location `" + location_name + "` does NOT have a World specified!");
return;
}
if (test.get("UseWorldBorder") != null) {
if (test.get("UseWorldBorder").getClass() == Boolean.class)
useWorldborder = Boolean.parseBoolean(test.get("UseWorldBorder").toString());
}
if (test.get("CenterX") != null) {
if (test.get("CenterX").getClass() == Integer.class)
CenterX = Integer.parseInt((test.get("CenterX")).toString());
}
if (test.get("CenterZ") != null) {
if (test.get("CenterZ").getClass() == Integer.class) {
CenterZ = Integer.parseInt((test.get("CenterZ")).toString());
}
}
if (test.get("MaxRadius") != null) {
if (test.get("MaxRadius").getClass() == Integer.class)
maxBorderRad = Integer.parseInt((test.get("MaxRadius")).toString());
if (maxBorderRad <= 0) {
BetterRTP.getInstance().getText().sms(Bukkit.getConsoleSender(),
"WARNING! Location '" + location_name + "' Maximum radius of '" + maxBorderRad + "' is not allowed! Set to default value!");
maxBorderRad = BetterRTP.getInstance().getRTP().defaultWorld.getMaxRad();
}
}
if (test.get("MinRadius") != null) {
if (test.get("MinRadius").getClass() == Integer.class)
minBorderRad = Integer.parseInt((test.get("MinRadius")).toString());
if (minBorderRad < 0 || minBorderRad >= maxBorderRad) {
BetterRTP.getInstance().getText().sms(Bukkit.getConsoleSender(),
"WARNING! Location '" + location_name + "' Minimum radius of '" + minBorderRad + "' is not allowed! Set to default value!");
minBorderRad = BetterRTP.getInstance().getRTP().defaultWorld.getMinRad();
if (minBorderRad >= maxBorderRad)
maxBorderRad = BetterRTP.getInstance().getRTP().defaultWorld.getMaxRad();
}
}
if (test.get("Biomes") != null) {
if (test.get("Biomes").getClass() == ArrayList.class)
this.Biomes = new ArrayList<String>((ArrayList) test.get("Biomes"));
}
if (BetterRTP.getInstance().getFiles().getType(FileBasics.FILETYPE.ECO).getBoolean("Economy.Enabled"))
if (test.get("Price") != null) {
if (test.get("Price").getClass() == Integer.class)
this.price = Integer.parseInt(test.get("Price").toString());
else
price = worldDefault.getPrice(world);
} else
price = worldDefault.getPrice(world);
if (test.get("Shape") != null) {
if (test.get("Shape").getClass() == String.class) {
try {
this.shape = RTP_SHAPE.valueOf(test.get("Shape").toString().toUpperCase());
} catch (Exception e) {
//Invalid shape
}
}
}
}
}
}
public boolean isValid() {
return world != null;
}
@Override
public World getWorld() {
return Bukkit.getWorld(world);
}
@Override
public boolean getUseWorldborder() {
return useWorldborder;
}
@Override
public int getCenterX() {
return CenterX;
}
@Override
public int getCenterZ() {
return CenterZ;
}
@Override
public int getMaxRad() {
return maxBorderRad;
}
@Override
public int getMinRad() {
return minBorderRad;
}
@Override
public int getPrice() {
return price;
}
@Override
public List<String> getBiomes() {
return Biomes;
}
@Override
public RTP_SHAPE getShape() {
return shape;
}
}

View File

@ -8,11 +8,11 @@
# MinRadius: 5
Settings:
Enabled: false
RandomLocations: true #When rtp'ing, a random location will be selected, else the nearest will be selected
Locations:
main_loc:
World: world
CenterX: 100
CenterY: 150
MaxRadius: 100
MinRadius: 5
- main_loc:
World: world
CenterX: 100
CenterY: 150
MaxRadius: 100 #optional
MinRadius: 5 #optional
Shape: square #optional