mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2025-08-18 09:35:50 +00:00
edit command update + world type not set warning message
This commit is contained in:
parent
e53ed64614
commit
d3d9867d9f
@ -4,6 +4,7 @@ import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
|||||||
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommandHelpable;
|
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommandHelpable;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
|
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
|
||||||
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommand;
|
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommand;
|
||||||
|
import me.SuperRonanCraft.BetterRTP.references.worlds.WORLD_TYPE;
|
||||||
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;
|
||||||
@ -29,9 +30,9 @@ public class CmdEdit implements RTPCommand, RTPCommandHelpable { //Edit a worlds
|
|||||||
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 sub_cmd : RTP_CMD_EDIT_SUB.values())
|
||||||
if (cmde.name().toLowerCase().startsWith(args[3].toLowerCase())) {
|
if (isAllowedAccess(cmd, sub_cmd) && sub_cmd.name().toLowerCase().startsWith(args[3].toLowerCase())) {
|
||||||
editWorld(sendi, cmde, args[4], args[2]);
|
editWorld(sendi, sub_cmd, args[4], args[2]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
usage(sendi, label, cmd);
|
usage(sendi, label, cmd);
|
||||||
@ -44,9 +45,9 @@ public class CmdEdit implements RTPCommand, RTPCommandHelpable { //Edit a worlds
|
|||||||
usage(sendi, label, cmd);
|
usage(sendi, label, cmd);
|
||||||
return;
|
return;
|
||||||
case DEFAULT:
|
case DEFAULT:
|
||||||
for (RTP_CMD_EDIT_SUB cmde : RTP_CMD_EDIT_SUB.values())
|
for (RTP_CMD_EDIT_SUB sub_cmd : RTP_CMD_EDIT_SUB.values())
|
||||||
if (cmde.name().toLowerCase().startsWith(args[2].toLowerCase())) {
|
if (isAllowedAccess(cmd, sub_cmd) && sub_cmd.name().toLowerCase().startsWith(args[2].toLowerCase())) {
|
||||||
editDefault(sendi, cmde, args[3]);
|
editDefault(sendi, sub_cmd, args[3]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
usage(sendi, label, cmd);
|
usage(sendi, label, cmd);
|
||||||
@ -141,7 +142,7 @@ public class CmdEdit implements RTPCommand, RTPCommandHelpable { //Edit a worlds
|
|||||||
for (RTP_CMD_EDIT cmd : RTP_CMD_EDIT.values())
|
for (RTP_CMD_EDIT cmd : RTP_CMD_EDIT.values())
|
||||||
if (cmd.name().toLowerCase().startsWith(args[1].toLowerCase()))
|
if (cmd.name().toLowerCase().startsWith(args[1].toLowerCase()))
|
||||||
list.add(cmd.name().toLowerCase());
|
list.add(cmd.name().toLowerCase());
|
||||||
} else if (args.length == 3) {
|
} else if (args.length == 3) { //rtp edit <sub_cmd> <type>
|
||||||
for (RTP_CMD_EDIT cmd : RTP_CMD_EDIT.values())
|
for (RTP_CMD_EDIT cmd : RTP_CMD_EDIT.values())
|
||||||
if (cmd.name().equalsIgnoreCase(args[1])) {
|
if (cmd.name().equalsIgnoreCase(args[1])) {
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
@ -151,7 +152,7 @@ public class CmdEdit implements RTPCommand, RTPCommandHelpable { //Edit a worlds
|
|||||||
list.add(world.getName());
|
list.add(world.getName());
|
||||||
break;
|
break;
|
||||||
case DEFAULT:
|
case DEFAULT:
|
||||||
list.addAll(tabCompleteSub(args));
|
list.addAll(tabCompleteSub(args, cmd));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (args.length == 4) {
|
} else if (args.length == 4) {
|
||||||
@ -159,7 +160,7 @@ public class CmdEdit implements RTPCommand, RTPCommandHelpable { //Edit a worlds
|
|||||||
if (cmd.name().equalsIgnoreCase(args[1]))
|
if (cmd.name().equalsIgnoreCase(args[1]))
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case WORLD:
|
case WORLD:
|
||||||
list.addAll(tabCompleteSub(args)); break;
|
list.addAll(tabCompleteSub(args, cmd)); break;
|
||||||
case DEFAULT:
|
case DEFAULT:
|
||||||
if (args[2].equalsIgnoreCase(RTP_CMD_EDIT_SUB.CENTER_X.name()))
|
if (args[2].equalsIgnoreCase(RTP_CMD_EDIT_SUB.CENTER_X.name()))
|
||||||
list.add(String.valueOf(((Player) sendi).getLocation().getBlockX()));
|
list.add(String.valueOf(((Player) sendi).getLocation().getBlockX()));
|
||||||
@ -180,15 +181,24 @@ public class CmdEdit implements RTPCommand, RTPCommandHelpable { //Edit a worlds
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> tabCompleteSub(String[] args) {
|
private List<String> tabCompleteSub(String[] args, RTP_CMD_EDIT cmd) {
|
||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
for (RTP_CMD_EDIT_SUB cmd : RTP_CMD_EDIT_SUB.values()) {
|
for (RTP_CMD_EDIT_SUB sub_cmd : RTP_CMD_EDIT_SUB.values()) {
|
||||||
if (cmd.name().toLowerCase().startsWith(args[args.length - 1].toLowerCase()))
|
|
||||||
list.add(cmd.name().toLowerCase());
|
if (isAllowedAccess(cmd, sub_cmd) && sub_cmd.name().toLowerCase().startsWith(args[args.length - 1].toLowerCase()))
|
||||||
|
list.add(sub_cmd.name().toLowerCase());
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isAllowedAccess(RTP_CMD_EDIT cmd, RTP_CMD_EDIT_SUB sub) {
|
||||||
|
//Check if this sub command is allowed
|
||||||
|
for (RTP_CMD_EDIT cmd_checking : sub.getAllowed())
|
||||||
|
if (cmd_checking == cmd)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean permission(CommandSender sendi) {
|
public boolean permission(CommandSender sendi) {
|
||||||
return BetterRTP.getInstance().getPerms().getEdit(sendi);
|
return BetterRTP.getInstance().getPerms().getEdit(sendi);
|
||||||
@ -212,22 +222,25 @@ public class CmdEdit implements RTPCommand, RTPCommandHelpable { //Edit a worlds
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum RTP_CMD_EDIT {
|
enum RTP_CMD_EDIT {
|
||||||
WORLD, DEFAULT
|
WORLD, DEFAULT, WORLD_TYPE
|
||||||
}
|
}
|
||||||
|
|
||||||
enum RTP_CMD_EDIT_SUB {
|
enum RTP_CMD_EDIT_SUB {
|
||||||
CENTER_X("CenterX", "INT"),
|
CENTER_X("CenterX", "INT", null),
|
||||||
CENTER_Z("CenterZ", "INT"),
|
CENTER_Z("CenterZ", "INT", null),
|
||||||
MAX("MaxRadius", "INT"),
|
MAX("MaxRadius", "INT", null),
|
||||||
MIN("MinRadius", "INT"),
|
MIN("MinRadius", "INT", null),
|
||||||
USEWORLDBORDER("UseWorldBorder", "BOL");
|
USEWORLDBORDER("UseWorldBorder", "BOL", null),
|
||||||
|
WORLDTYPE("WorldType", "WORLDTYPE", new RTP_CMD_EDIT[]{RTP_CMD_EDIT.WORLD_TYPE});
|
||||||
|
|
||||||
private String type;
|
private final String type;
|
||||||
private String str;
|
private final String str;
|
||||||
|
private final RTP_CMD_EDIT[] allowed;
|
||||||
|
|
||||||
RTP_CMD_EDIT_SUB(String str, String type) {
|
RTP_CMD_EDIT_SUB(String str, String type, RTP_CMD_EDIT[] allowed_cmds) {
|
||||||
this.str = str;
|
this.str = str;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
this.allowed = allowed_cmds;
|
||||||
}
|
}
|
||||||
|
|
||||||
String get() {
|
String get() {
|
||||||
@ -239,7 +252,15 @@ public class CmdEdit implements RTPCommand, RTPCommandHelpable { //Edit a worlds
|
|||||||
return Integer.parseInt(input);
|
return Integer.parseInt(input);
|
||||||
else if (this.type.equalsIgnoreCase("BOL"))
|
else if (this.type.equalsIgnoreCase("BOL"))
|
||||||
return Boolean.valueOf(input);
|
return Boolean.valueOf(input);
|
||||||
|
else if (this.type.equalsIgnoreCase("WORLDTYPE")) //WILL CAUSE ERROR IF INCORRECT
|
||||||
|
return WORLD_TYPE.valueOf(input).name();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RTP_CMD_EDIT[] getAllowed() {
|
||||||
|
if (this.allowed == null)
|
||||||
|
return new RTP_CMD_EDIT[]{RTP_CMD_EDIT.WORLD, RTP_CMD_EDIT.DEFAULT};
|
||||||
|
return allowed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -129,9 +129,16 @@ public class RTP {
|
|||||||
} else
|
} else
|
||||||
pWorld.setup(defaultWorld, biomes, personal);
|
pWorld.setup(defaultWorld, biomes, personal);
|
||||||
//World type
|
//World type
|
||||||
WORLD_TYPE world_type = WORLD_TYPE.NORMAL; //World rtp type
|
WORLD_TYPE world_type; //World rtp type
|
||||||
if (this.world_type.containsKey(world_name))
|
if (this.world_type.containsKey(world_name))
|
||||||
world_type = this.world_type.get(world_name);
|
world_type = this.world_type.get(world_name);
|
||||||
|
else {
|
||||||
|
world_type = WORLD_TYPE.NORMAL;
|
||||||
|
this.world_type.put(world_name, world_type); //Defaults this so the error message isn't spammed
|
||||||
|
getPl().getLogger().warning("Seems like the world `" + world_name + "` does not have a `WorldType` declared. " +
|
||||||
|
"Please add/fix this in the config.yml file! " +
|
||||||
|
"This world will be treated as an overworld!");
|
||||||
|
}
|
||||||
pWorld.setWorldtype(world_type);
|
pWorld.setWorldtype(world_type);
|
||||||
return pWorld;
|
return pWorld;
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,10 @@ package me.SuperRonanCraft.BetterRTP.player.rtp;
|
|||||||
import com.comphenix.protocol.PacketType;
|
import com.comphenix.protocol.PacketType;
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
import com.comphenix.protocol.ProtocolManager;
|
import com.comphenix.protocol.ProtocolManager;
|
||||||
import com.comphenix.protocol.wrappers.BlockPosition;
|
|
||||||
import com.comphenix.protocol.wrappers.WrappedBlockData;
|
|
||||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||||
import me.SuperRonanCraft.BetterRTP.player.rtp.packets.WrapperPlayServerNamedSoundEffect;
|
import me.SuperRonanCraft.BetterRTP.player.rtp.packets.WrapperPlayServerNamedSoundEffect;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
|
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user