use of org.spongepowered.api.command.CommandResult in project SpongeCommon by SpongePowered.
the class SpongeCommandManager method process.
@Override
public CommandResult process(CommandSource source, String commandLine) {
final String[] argSplit = commandLine.split(" ", 2);
Sponge.getCauseStackManager().pushCause(source);
final SendCommandEvent event = SpongeEventFactory.createSendCommandEvent(Sponge.getCauseStackManager().getCurrentCause(), argSplit.length > 1 ? argSplit[1] : "", argSplit[0], CommandResult.empty());
Sponge.getGame().getEventManager().post(event);
Sponge.getCauseStackManager().popCause();
if (event.isCancelled()) {
return event.getResult();
}
// Only the first part of argSplit is used at the moment, do the other in the future if needed.
argSplit[0] = event.getCommand();
commandLine = event.getCommand();
if (!event.getArguments().isEmpty()) {
commandLine = commandLine + ' ' + event.getArguments();
}
try {
try (StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame();
// Since we know we are in the main thread, this is safe to do without a thread check
CommandPhaseContext context = GeneralPhase.State.COMMAND.createPhaseContext().source(source).addCaptures().addEntityDropCaptures().buildAndSwitch()) {
if (source instanceof EntityPlayer) {
// Enable player inventory capture
((IMixinInventoryPlayer) ((EntityPlayer) source).inventory).setCapture(true);
}
Sponge.getCauseStackManager().pushCause(source);
final CommandResult result = this.dispatcher.process(source, commandLine);
return result;
} catch (InvocationCommandException ex) {
if (ex.getCause() != null) {
throw ex.getCause();
}
} catch (CommandPermissionException ex) {
Text text = ex.getText();
if (text != null) {
source.sendMessage(error(text));
}
} catch (CommandException ex) {
Text text = ex.getText();
if (text != null) {
source.sendMessage(error(text));
}
if (ex.shouldIncludeUsage()) {
final Optional<CommandMapping> mapping = this.dispatcher.get(argSplit[0], source);
if (mapping.isPresent()) {
Text usage;
if (ex instanceof ArgumentParseException.WithUsage) {
usage = ((ArgumentParseException.WithUsage) ex).getUsage();
} else {
usage = mapping.get().getCallable().getUsage(source);
}
source.sendMessage(error(t("Usage: /%s %s", argSplit[0], usage)));
}
}
}
} catch (Throwable thr) {
Text.Builder excBuilder;
if (thr instanceof TextMessageException) {
Text text = ((TextMessageException) thr).getText();
excBuilder = text == null ? Text.builder("null") : Text.builder();
} else {
excBuilder = Text.builder(String.valueOf(thr.getMessage()));
}
if (source.hasPermission("sponge.debug.hover-stacktrace")) {
final StringWriter writer = new StringWriter();
thr.printStackTrace(new PrintWriter(writer));
excBuilder.onHover(TextActions.showText(Text.of(writer.toString().replace("\t", " ").replace("\r\n", "\n").replace("\r", // I mean I guess somebody could be running this on like OS 9?
"\n"))));
}
source.sendMessage(error(t("Error occurred while executing command: %s", excBuilder.build())));
this.logger.error(TextSerializers.PLAIN.serialize(t("Error occurred while executing command '%s' for source %s: %s", commandLine, source.toString(), String.valueOf(thr.getMessage()))), thr);
}
return CommandResult.empty();
}
use of org.spongepowered.api.command.CommandResult in project RedProtect by FabioZumbi12.
the class RPCommands method process.
@SuppressWarnings("deprecation")
public CommandResult process(CommandSource sender, String arguments) throws CommandException {
CommandResult cmdr = CommandResult.success();
String[] args = arguments.split(" ");
if (!(sender instanceof Player)) {
if (args.length == 1) {
if (args[0].equalsIgnoreCase("single-to-files")) {
RedProtect.get().logger.sucess("[" + RPUtil.SingleToFiles() + "]" + " regions converted to your own files with success");
return cmdr;
}
if (args[0].equalsIgnoreCase("files-to-single")) {
RedProtect.get().logger.sucess("[" + RPUtil.FilesToSingle() + "]" + " regions converted to unified world file with success");
return cmdr;
}
if (args[0].equalsIgnoreCase("fileToMysql")) {
try {
if (!RPUtil.fileToMysql()) {
RedProtect.get().logger.severe("ERROR: Check if your 'file-type' configuration is set to 'file' before convert from FILE to Mysql.");
return cmdr;
} else {
RedProtect.get().cfgs.setConfig("file-type", "mysql");
RedProtect.get().cfgs.save();
RedProtect.get().reload();
RedProtect.get().logger.sucess("Redprotect reloaded with Mysql as database! Ready to use!");
return cmdr;
}
} catch (Exception e) {
e.printStackTrace();
return cmdr;
}
}
if (args[0].equalsIgnoreCase("mysqlToFile")) {
try {
if (!RPUtil.mysqlToFile()) {
RedProtect.get().logger.severe("ERROR: Check if your 'file-type' configuration is set to 'mysql' before convert from MYSQL to File.");
return cmdr;
} else {
RedProtect.get().cfgs.setConfig("file-type", "file");
RedProtect.get().cfgs.save();
RedProtect.get().reload();
RedProtect.get().logger.sucess("Redprotect reloaded with File as database! Ready to use!");
return cmdr;
}
} catch (Exception e) {
e.printStackTrace();
return cmdr;
}
}
if (args[0].isEmpty()) {
sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "---------------- " + RedProtect.get().container.getName() + " ----------------"));
sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "Developed by &eFabioZumbi12" + RPLang.get("general.color") + "."));
sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "For more information about the commands, type [&e/rp ?" + RPLang.get("general.color") + "]."));
sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "For a tutorial, type [&e/rp tutorial" + RPLang.get("general.color") + "]."));
sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "---------------------------------------------------"));
return cmdr;
}
if (args[0].equalsIgnoreCase("list-all")) {
int total = 0;
for (Region r : RedProtect.get().rm.getAllRegions()) {
RedProtect.get().logger.info("&a[" + total + "]" + "Region: " + r.getName() + "&r | &3World: " + r.getWorld() + "&r");
total++;
}
RedProtect.get().logger.sucess(total + " regions for " + Sponge.getServer().getWorlds().size() + " worlds.");
return cmdr;
}
if (args[0].equalsIgnoreCase("save-all")) {
RedProtect.get().rm.saveAll();
RedProtect.get().logger.SaveLogs();
RedProtect.get().logger.sucess(RedProtect.get().rm.getAllRegions().size() + " regions saved with success!");
return cmdr;
}
if (args[0].equalsIgnoreCase("load-all")) {
RedProtect.get().rm.clearDB();
try {
RedProtect.get().rm.loadAll();
} catch (Exception e) {
RedProtect.get().logger.severe("Error on load all regions from database files:");
e.printStackTrace();
}
RedProtect.get().logger.sucess(RedProtect.get().rm.getAllRegions().size() + " regions has been loaded from database files!");
return cmdr;
}
if (checkCmd(args[0], "reload")) {
for (Player p : RedProtect.get().game.getServer().getOnlinePlayers()) {
RedProtect.get().getPVHelper().closeInventory(p);
}
RedProtect.get().reload();
RedProtect.get().logger.sucess("Redprotect reloaded with success!");
return cmdr;
}
if (args[0].equalsIgnoreCase("reload-config")) {
RedProtect.get().cfgs = new RPConfig();
RPLang.init();
RedProtect.get().logger.sucess("Redprotect Plus configs reloaded!");
return cmdr;
}
}
if (args.length == 2) {
// rp removeall <player>
if (checkCmd(args[0], "removeall")) {
int removed = RedProtect.get().rm.removeAll(args[1]);
if (removed <= 0) {
RPLang.sendMessage(sender, RPLang.get("cmdmanager.region.noneremoved"));
} else {
RPLang.sendMessage(sender, RPLang.get("cmdmanager.region.removed").replace("{regions}", removed + "").replace("{player}", args[1]));
}
return cmdr;
}
// rp regenall <player>
if (checkCmd(args[0], "regenall")) {
int regen = RedProtect.get().rm.regenAll(args[1]);
if (regen <= 0) {
RPLang.sendMessage(sender, RPLang.get("cmdmanager.region.noneregenerated"));
} else {
RPLang.sendMessage(sender, RPLang.get("cmdmanager.region.regenerated").replace("{regions}", regen + "").replace("{player}", args[1]));
}
return cmdr;
}
// rp regen stop
if (checkCmd(args[0], "regen") && args[1].equalsIgnoreCase("stop")) {
if (!RedProtect.get().WE) {
return cmdr;
}
RPUtil.stopRegen = true;
RPLang.sendMessage(sender, "&aRegen will stop now. To continue reload the plugin!");
return cmdr;
}
// rp list <player>
if (checkCmd(args[0], "list")) {
getRegionforList(sender, RPUtil.PlayerToUUID(args[1]), 1);
return cmdr;
}
// rp clamilimit player
if (checkCmd(args[0], "claimlimit")) {
User offp = RPUtil.getUser(args[1]);
if (offp == null) {
sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.noplayer.thisname").replace("{player}", args[1])));
return cmdr;
}
int limit = RedProtect.get().ph.getPlayerClaimLimit(offp);
if (limit < 0 || RedProtect.get().ph.hasPerm(offp, "redprotect.limit.claim.unlimited")) {
sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.nolimit")));
return cmdr;
}
int currentUsed = RedProtect.get().rm.getRegions(RPUtil.PlayerToUUID(offp.getName())).size();
sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.yourclaims") + currentUsed + RPLang.get("general.color") + "/&e" + limit + RPLang.get("general.color")));
return cmdr;
}
// rp limit player
if (checkCmd(args[0], "limit")) {
User offp = RPUtil.getUser(args[1]);
if (offp == null) {
sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.noplayer.thisname").replace("{player}", args[1])));
return cmdr;
}
int limit = RedProtect.get().ph.getPlayerBlockLimit(offp);
if (limit < 0 || RedProtect.get().ph.hasPerm(offp, "redprotect.limit.blocks.unlimited")) {
sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.nolimit")));
return cmdr;
}
int currentUsed = RedProtect.get().rm.getTotalRegionSize(RPUtil.PlayerToUUID(offp.getName()), offp.getPlayer().isPresent() ? offp.getPlayer().get().getWorld().getName() : null);
sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.yourarea") + currentUsed + RPLang.get("general.color") + "/&e" + limit + RPLang.get("general.color")));
return cmdr;
}
}
if (args.length == 3) {
// rp clamilimit player world
if (checkCmd(args[0], "claimlimit")) {
User offp = RPUtil.getUser(args[1]);
World w = null;
if (RedProtect.get().serv.getWorld(args[2]).isPresent()) {
w = RedProtect.get().serv.getWorld(args[2]).get();
}
if (offp == null) {
sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.noplayer.thisname").replace("{player}", args[1])));
return cmdr;
}
int limit = RedProtect.get().ph.getPlayerClaimLimit(offp);
if (limit < 0 || RedProtect.get().ph.hasPerm(offp, "redprotect.limit.claim.unlimited")) {
sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.nolimit")));
return cmdr;
}
if (w == null) {
sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.region.invalidworld")));
return cmdr;
}
int currentUsed = RedProtect.get().rm.getRegions(RPUtil.PlayerToUUID(offp.getName()), w).size();
sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.yourclaims") + currentUsed + RPLang.get("general.color") + "/&e" + limit + RPLang.get("general.color")));
return cmdr;
}
if (args[0].equalsIgnoreCase("setconfig")) {
if (args[1].contains("debug-messages") || args[1].contains("file-type")) {
Object from = RedProtect.get().cfgs.getObject(args[1]);
if (args[2].equals("true") || args[2].equals("false")) {
RedProtect.get().cfgs.setConfig(args[1], Boolean.parseBoolean(args[2]));
} else {
try {
int value = Integer.parseInt(args[2]);
RedProtect.get().cfgs.setConfig(args[1], value);
} catch (NumberFormatException ex) {
RedProtect.get().cfgs.setConfig(args[1], args[2]);
}
}
sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.configset") + " " + from + " > " + args[2]));
RedProtect.get().cfgs.save();
return cmdr;
} else {
sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.confignotset") + " " + args[1]));
return cmdr;
}
}
// rp info <region> <world>
if (checkCmd(args[0], "info")) {
if (Sponge.getServer().getWorld(args[2]).isPresent()) {
Region r = RedProtect.get().rm.getRegion(args[1], Sponge.getServer().getWorld(args[2]).get());
if (r != null) {
sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "-----------------------------------------"));
sender.sendMessage(r.info());
sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "-----------------------------------------"));
} else {
sender.sendMessage(RPUtil.toText(RPLang.get("correct.usage") + "&eInvalid region: " + args[1]));
}
} else {
sender.sendMessage(RPUtil.toText(RPLang.get("correct.usage") + " " + "&eInvalid World: " + args[2]));
}
return cmdr;
}
}
if (args.length == 4) {
if (checkCmd(args[0], "teleport")) {
// rp tp <player> <region> <world>
Player play = null;
if (RedProtect.get().serv.getPlayer(args[1]).isPresent()) {
play = RedProtect.get().serv.getPlayer(args[1]).get();
}
if (play != null) {
World w = null;
if (RedProtect.get().serv.getWorld(args[3]).isPresent()) {
w = RedProtect.get().serv.getWorld(args[3]).get();
}
if (w == null) {
sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.region.invalidworld")));
return cmdr;
}
Region region = RedProtect.get().rm.getRegion(args[2], w);
if (region == null) {
sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.region.doesntexist") + ": " + args[2]));
return cmdr;
}
Location<World> loc = null;
if (region.getTPPoint() != null) {
loc = new Location<>(w, region.getTPPoint().getBlockX() + 0.500, region.getTPPoint().getBlockY(), region.getTPPoint().getBlockZ() + 0.500);
} else {
int limit = 256;
if (w.getDimension().equals(DimensionTypes.NETHER)) {
limit = 124;
}
for (int i = limit; i > 0; i--) {
BlockType mat = new Location<>(w, region.getCenterX(), i, region.getCenterZ()).getBlockType();
BlockType mat1 = new Location<>(w, region.getCenterX(), i + 1, region.getCenterZ()).getBlockType();
BlockType mat2 = new Location<>(w, region.getCenterX(), i + 2, region.getCenterZ()).getBlockType();
if (!mat.equals(BlockTypes.LAVA) && !mat.equals(BlockTypes.AIR) && mat1.equals(BlockTypes.AIR) && mat2.equals(BlockTypes.AIR)) {
loc = new Location<>(w, region.getCenterX() + 0.500, i + 1, region.getCenterZ() + 0.500);
break;
}
}
}
play.setLocation(loc);
RPLang.sendMessage(play, RPLang.get("cmdmanager.region.tp") + " " + args[2]);
sender.sendMessage(RPUtil.toText("&3Player teleported to " + args[2]));
return cmdr;
} else {
sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.noplayer.thisname").replace("{player}", args[1])));
HandleHelPage(sender, 1);
return cmdr;
}
}
// rp flag info <region> <world>
if (checkCmd(args[0], "flag") && checkCmd(args[1], "info")) {
if (Sponge.getServer().getWorld(args[3]).isPresent()) {
Region r = RedProtect.get().rm.getRegion(args[2], Sponge.getServer().getWorld(args[3]).get());
if (r != null) {
sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "------------[" + RPLang.get("cmdmanager.region.flag.values") + "]------------"));
sender.sendMessage(r.getFlagInfo());
sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "------------------------------------"));
} else {
sender.sendMessage(RPUtil.toText(RPLang.get("correct.usage") + "&eInvalid region: " + args[2]));
}
} else {
sender.sendMessage(RPUtil.toText(RPLang.get("correct.usage") + "&eInvalid World: " + args[3]));
}
return cmdr;
}
}
if (args.length == 5) {
/*/rp flag <regionName> <flag> <value> <world>*/
if (checkCmd(args[0], "flag")) {
World w = null;
if (RedProtect.get().serv.getWorld(args[4]).isPresent()) {
w = RedProtect.get().serv.getWorld(args[4]).get();
}
if (w == null) {
sender.sendMessage(RPUtil.toText(RPLang.get("correct.usage") + "&e rp flag <regionName> <flag> <value> <world>"));
return cmdr;
}
Region r = RedProtect.get().rm.getRegion(args[1], w);
if (r != null && (RedProtect.get().cfgs.getDefFlags().contains(args[2]) || RedProtect.get().cfgs.AdminFlags.contains(args[2]))) {
Object objflag = RPUtil.parseObject(args[3]);
r.setFlag(args[2], objflag);
sender.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.region.flag.set").replace("{flag}", "'" + args[2] + "'") + " " + r.getFlagString(args[2])));
RedProtect.get().logger.addLog("Console changed flag " + args[2] + " to " + r.getFlagString(args[2]));
return cmdr;
}
}
}
HandleHelPage(sender, 1);
return cmdr;
}
// commands as player
final Player player = (Player) sender;
if (args.length == 1) {
// rp regen
if (checkCmd(args[0], "regen") && player.hasPermission("redprotect.regen")) {
if (!RedProtect.get().WE) {
return cmdr;
}
Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
if (r == null) {
RPLang.sendMessage(player, "cmdmanager.region.doesexists");
return cmdr;
}
WEListener.regenRegion(r, Sponge.getServer().getWorld(r.getWorld()).get(), r.getMaxLocation(), r.getMinLocation(), 0, sender, false);
return cmdr;
}
// rp undo
if (args[0].equalsIgnoreCase("undo") && player.hasPermission("redprotect.regen")) {
if (!RedProtect.get().WE) {
return cmdr;
}
Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
if (r == null) {
RPLang.sendMessage(player, "cmdmanager.region.doesexists");
return cmdr;
}
if (WEListener.undo(r.getID())) {
RPLang.sendMessage(sender, RPLang.get("cmdmanager.regen.undo.sucess").replace("{region}", r.getName()));
} else {
RPLang.sendMessage(sender, RPLang.get("cmdmanager.regen.undo.none").replace("{region}", r.getName()));
}
return cmdr;
}
String claimmode = RedProtect.get().cfgs.getWorldClaimType(player.getWorld().getName());
if (claimmode.equalsIgnoreCase("WAND") || claimmode.equalsIgnoreCase("BOTH") || RedProtect.get().ph.hasGenPerm(player, "redefine")) {
// rp pos1
if (checkCmd(args[0], "pos1")) {
Location<World> pl = player.getLocation();
RedProtect.get().firstLocationSelections.put(player, pl);
player.sendMessage(RPUtil.toText(RPLang.get("playerlistener.wand1") + RPLang.get("general.color") + " (&6" + pl.getBlockX() + RPLang.get("general.color") + ", &6" + pl.getBlockY() + RPLang.get("general.color") + ", &6" + pl.getBlockZ() + RPLang.get("general.color") + ")."));
// show preview border
if (RedProtect.get().firstLocationSelections.containsKey(player) && RedProtect.get().secondLocationSelections.containsKey(player)) {
Location<World> loc1 = RedProtect.get().firstLocationSelections.get(player);
Location<World> loc2 = RedProtect.get().secondLocationSelections.get(player);
if (loc1.getPosition().distanceSquared(loc2.getPosition()) > RedProtect.get().cfgs.getInt("region-settings.define-max-distance") && !player.hasPermission("redprotect.bypass.define-max-distance")) {
Double dist = loc1.getPosition().distanceSquared(loc2.getPosition());
RPLang.sendMessage(player, String.format(RPLang.get("regionbuilder.selection.maxdefine"), RedProtect.get().cfgs.getInt("region-settings.define-max-distance"), dist.intValue()));
} else {
RPUtil.addBorder(player, RPUtil.get4Points(loc1, loc2, player.getLocation().getBlockY()));
}
}
return cmdr;
} else // rp pos2
if (checkCmd(args[0], "pos2")) {
Location<World> pl = player.getLocation();
RedProtect.get().secondLocationSelections.put(player, pl);
player.sendMessage(RPUtil.toText(RPLang.get("playerlistener.wand2") + RPLang.get("general.color") + " (&6" + pl.getBlockX() + RPLang.get("general.color") + ", &6" + pl.getBlockY() + RPLang.get("general.color") + ", &6" + pl.getBlockZ() + RPLang.get("general.color") + ")."));
// show preview border
if (RedProtect.get().firstLocationSelections.containsKey(player) && RedProtect.get().secondLocationSelections.containsKey(player)) {
Location<World> loc1 = RedProtect.get().firstLocationSelections.get(player);
Location<World> loc2 = RedProtect.get().secondLocationSelections.get(player);
if (loc1.getPosition().distanceSquared(loc2.getPosition()) > RedProtect.get().cfgs.getInt("region-settings.define-max-distance") && !RedProtect.get().ph.hasPerm(player, "redprotect.bypass.define-max-distance")) {
Double dist = loc1.getPosition().distanceSquared(loc2.getPosition());
RPLang.sendMessage(player, String.format(RPLang.get("regionbuilder.selection.maxdefine"), RedProtect.get().cfgs.getInt("region-settings.define-max-distance"), dist.intValue()));
} else {
RPUtil.addBorder(player, RPUtil.get4Points(loc1, loc2, player.getLocation().getBlockY()));
}
}
return cmdr;
}
}
if (args[0].isEmpty()) {
sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "---------------- " + RedProtect.get().container.getName() + " ----------------"));
sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "Developed by &eFabioZumbi12" + RPLang.get("general.color") + "."));
sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "For more information about the commands, type [&e/rp ?" + RPLang.get("general.color") + "]."));
sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "For a tutorial, type [&e/rp tutorial" + RPLang.get("general.color") + "]."));
sender.sendMessage(RPUtil.toText(RPLang.get("general.color") + "---------------------------------------------------"));
return cmdr;
}
if (checkCmd(args[0], "laccept")) {
if (RedProtect.get().alWait.containsKey(player)) {
// info = region+world+pname
String info = RedProtect.get().alWait.get(player);
Player lsender = Sponge.getServer().getPlayer(info.split("@")[2]).get();
Region r = RedProtect.get().rm.getRegion(info.split("@")[0], info.split("@")[1]);
String VictimUUID = player.getName();
if (RedProtect.get().OnlineMode) {
VictimUUID = player.getUniqueId().toString();
}
if (r != null) {
if (RedProtect.get().ph.getPlayerClaimLimit(player) == (RedProtect.get().rm.getRegions(VictimUUID, r.getWorld()).size() + 1)) {
RPLang.sendMessage(player, "regionbuilder.claim.limit");
return cmdr;
}
r.addLeader(VictimUUID);
RPLang.sendMessage(player, RPLang.get("cmdmanager.region.leader.youadded").replace("{region}", r.getName()) + " " + lsender.getName());
if (lsender != null && lsender.isOnline()) {
RPLang.sendMessage(lsender, RPLang.get("cmdmanager.region.leader.accepted").replace("{region}", r.getName()).replace("{player}", player.getName()));
}
} else {
RPLang.sendMessage(player, "cmdmanager.region.doesexists");
}
RedProtect.get().alWait.remove(player);
return cmdr;
} else {
RPLang.sendMessage(player, "cmdmanager.norequests");
return cmdr;
}
}
if (checkCmd(args[0], "ldeny")) {
if (RedProtect.get().alWait.containsKey(player)) {
// info = region+world+pname
String info = RedProtect.get().alWait.get(player);
Player lsender = Sponge.getServer().getPlayer(info.split("@")[2]).get();
Region r = RedProtect.get().rm.getRegion(info.split("@")[0], info.split("@")[1]);
if (r != null) {
RPLang.sendMessage(player, RPLang.get("cmdmanager.region.leader.youdenied").replace("{region}", r.getName()).replace("{player}", lsender.getName()));
if (lsender != null && lsender.isOnline()) {
RPLang.sendMessage(lsender, RPLang.get("cmdmanager.region.leader.denied").replace("{region}", r.getName()).replace("{player}", player.getName()));
}
} else {
RPLang.sendMessage(player, "cmdmanager.region.doesexists");
}
RedProtect.get().alWait.remove(player);
return cmdr;
} else {
RPLang.sendMessage(player, "cmdmanager.norequests");
return cmdr;
}
}
if (checkCmd(args[0], "settp") && RedProtect.get().ph.hasGenPerm(player, "settp")) {
Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
if (r != null) {
if (RedProtect.get().ph.hasRegionPermLeader(player, "settp", r)) {
r.setTPPoint(player.getLocation());
RPLang.sendMessage(player, "cmdmanager.region.settp.ok");
return cmdr;
} else {
RPLang.sendMessage(player, "playerlistener.region.cantuse");
return cmdr;
}
} else {
RPLang.sendMessage(player, "cmdmanager.region.todo.that");
return cmdr;
}
}
if (checkCmd(args[0], "deltp") && RedProtect.get().ph.hasGenPerm(player, "settp")) {
Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
if (r != null) {
if (RedProtect.get().ph.hasRegionPermLeader(player, "settp", r)) {
r.setTPPoint(null);
RPLang.sendMessage(player, "cmdmanager.region.settp.removed");
return cmdr;
} else {
RPLang.sendMessage(player, "playerlistener.region.cantuse");
return cmdr;
}
} else {
RPLang.sendMessage(player, "cmdmanager.region.todo.that");
return cmdr;
}
}
if (checkCmd(args[0], "border") && RedProtect.get().ph.hasGenPerm(player, "border")) {
Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
if (r != null) {
RPUtil.addBorder(player, r.get4Points(player.getLocation().getBlockY()));
return cmdr;
} else {
RPLang.sendMessage(player, "cmdmanager.region.todo.that");
return cmdr;
}
}
if (checkCmd(args[0], "cancelbuy") && RedProtect.get().ph.hasGenPerm(player, "redprotect.eco.cancelbuy")) {
Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
if (r == null) {
RPLang.sendMessage(player, "cmdmanager.region.todo.that");
return cmdr;
}
if (r.isLeader(RPUtil.PlayerToUUID(player.getName()))) {
if (r.isForSale()) {
r.setFlag("for-sale", false);
r.setWelcome("");
if (r.leaderSize() == 0) {
if (RedProtect.get().cfgs.getEcoBool("rename-region")) {
RedProtect.get().rm.renameRegion(RPUtil.nameGen(player.getName(), r.getWorld()), r);
}
r.addLeader(RPUtil.PlayerToUUID(player.getName()));
} else {
if (RedProtect.get().cfgs.getEcoBool("rename-region")) {
RedProtect.get().rm.renameRegion(RPUtil.nameGen(RPUtil.UUIDtoPlayer(r.getLeaders().get(0)), r.getWorld()), r);
}
}
RPLang.sendMessage(player, "economy.region.cancelbuy");
RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + player.getName() + " cancelled buy stat of region " + r.getName());
return cmdr;
} else {
RPLang.sendMessage(player, "economy.region.buy.notforsale");
return cmdr;
}
} else {
RPLang.sendMessage(player, "economy.region.sell.own");
return cmdr;
}
}
if (checkCmd(args[0], "value") && RedProtect.get().ph.hasGenPerm(player, "value")) {
Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
if (r != null) {
if (RedProtect.get().ph.hasRegionPermLeader(player, "value", r)) {
if (r.getArea() < RedProtect.get().cfgs.getEcoInt("max-area-toget-value")) {
RPLang.sendMessage(player, RPLang.get("cmdmanager.value.is").replace("{value}", RPEconomy.getFormatted(RPEconomy.getRegionValue(r)) + " " + RedProtect.get().cfgs.getEcoString("economy-name")));
RedProtect.get().logger.debug("player", "Region Value: " + RPEconomy.getRegionValue(r));
return cmdr;
} else {
RPLang.sendMessage(player, RPLang.get("cmdmanager.value.areabig").replace("{maxarea}", RedProtect.get().cfgs.getEcoInt("max-area-toget-value").toString()));
return cmdr;
}
} else {
RPLang.sendMessage(player, "playerlistener.region.cantuse");
return cmdr;
}
} else {
RPLang.sendMessage(player, "cmdmanager.region.todo.that");
return cmdr;
}
}
if (args[0].equalsIgnoreCase("save-all")) {
if (RedProtect.get().ph.hasGenPerm(player, "save-all")) {
RedProtect.get().rm.saveAll();
RedProtect.get().logger.SaveLogs();
RPLang.sendMessage(player, "&a" + RedProtect.get().rm.getAllRegions().size() + " regions saved with success!");
return cmdr;
}
}
if (args[0].equalsIgnoreCase("load-all")) {
if (RedProtect.get().ph.hasGenPerm(player, "load-all")) {
RedProtect.get().rm.clearDB();
try {
RedProtect.get().rm.loadAll();
} catch (Exception e) {
RPLang.sendMessage(player, "Error on load all regions from database files:");
e.printStackTrace();
}
RPLang.sendMessage(player, "&a" + RedProtect.get().rm.getAllRegions().size() + " regions has been loaded from database files!");
return cmdr;
}
}
if (checkCmd(args[0], "define")) {
if (!RedProtect.get().ph.hasGenPerm(player, "define")) {
RPLang.sendMessage(player, "no.permission");
return cmdr;
}
String serverName = RedProtect.get().cfgs.getString("region-settings.default-leader");
String name = RPUtil.nameGen(serverName, player.getWorld().getName());
RegionBuilder rb2 = new DefineRegionBuilder(player, RedProtect.get().firstLocationSelections.get(player), RedProtect.get().secondLocationSelections.get(player), name, serverName, new LinkedList<>(), true);
if (rb2.ready()) {
Region r2 = rb2.build();
RPLang.sendMessage(player, RPLang.get("cmdmanager.region.created") + " " + r2.getName() + ".");
RedProtect.get().rm.add(r2, player.getWorld());
RedProtect.get().firstLocationSelections.remove(player);
RedProtect.get().secondLocationSelections.remove(player);
RedProtect.get().logger.addLog("(World " + r2.getWorld() + ") Player " + player.getName() + " DEFINED region " + r2.getName());
}
return cmdr;
}
// rp claim
if (checkCmd(args[0], "claim")) {
if ((!claimmode.equalsIgnoreCase("WAND") && !claimmode.equalsIgnoreCase("BOTH")) && !RedProtect.get().ph.hasGenPerm(player, "claim")) {
RPLang.sendMessage(player, "blocklistener.region.blockmode");
return cmdr;
}
String name = RPUtil.nameGen(player.getName(), player.getWorld().getName());
String leader = player.getUniqueId().toString();
if (!RedProtect.get().OnlineMode) {
leader = player.getName().toLowerCase();
}
RegionBuilder rb2 = new DefineRegionBuilder(player, RedProtect.get().firstLocationSelections.get(player), RedProtect.get().secondLocationSelections.get(player), name, leader, new LinkedList<>(), false);
if (rb2.ready()) {
Region r2 = rb2.build();
RPLang.sendMessage(player, RPLang.get("cmdmanager.region.created") + " " + r2.getName() + ".");
RedProtect.get().rm.add(r2, player.getWorld());
RedProtect.get().firstLocationSelections.remove(player);
RedProtect.get().secondLocationSelections.remove(player);
RedProtect.get().logger.addLog("(World " + r2.getWorld() + ") Player " + player.getName() + " CLAIMED region " + r2.getName());
}
return cmdr;
}
if (checkCmd(args[0], "reload") && RedProtect.get().ph.hasGenPerm(player, "reload")) {
for (Player p : RedProtect.get().game.getServer().getOnlinePlayers()) {
RedProtect.get().getPVHelper().closeInventory(p);
}
RedProtect.get().reload();
RPLang.sendMessage(player, "cmdmanager.reloaded");
return cmdr;
}
if (checkCmd(args[0], "wand") && player.hasPermission("redprotect.magicwand")) {
Inventory inv = player.getInventory();
ItemType mat = (ItemType) RPUtil.getRegistryFor(ItemType.class, RedProtect.get().cfgs.getString("wands.adminWandID"));
ItemStack item = ItemStack.of(mat, 1);
item.offer(Keys.ITEM_ENCHANTMENTS, new ArrayList<>());
Iterable<Slot> slotIter = player.getInventory().slots();
for (Slot slot : slotIter) {
if (slot.peek().isPresent()) {
ItemStack stack = slot.peek().get();
if (stack.getItem().equals(mat)) {
RPLang.sendMessage(player, RPLang.get("cmdmanager.wand.nospace").replace("{item}", mat.getName()));
return cmdr;
}
}
}
if (inv.query(Inventory.class).offer(item).getType().equals(Type.SUCCESS)) {
RPLang.sendMessage(player, RPLang.get("cmdmanager.wand.given").replace("{item}", mat.getName()));
} else {
RPLang.sendMessage(player, RPLang.get("cmdmanager.wand.nospace").replace("{item}", mat.getName()));
}
return cmdr;
}
if (checkCmd(args[0], "help")) {
HandleHelPage(sender, 1);
return cmdr;
}
if (checkCmd(args[0], "tutorial")) {
RPLang.sendMessage(player, "cmdmanager.tutorial");
RPLang.sendMessage(player, "cmdmanager.tutorial1");
RPLang.sendMessage(player, "cmdmanager.tutorial2");
RPLang.sendMessage(player, "cmdmanager.tutorial3");
RPLang.sendMessage(player, "cmdmanager.tutorial4");
RPLang.sendMessage(player, "cmdmanager.tutorial5");
return cmdr;
}
if (checkCmd(args[0], "near")) {
if (RedProtect.get().ph.hasUserPerm(player, "redprotect.near")) {
Set<Region> regions = RedProtect.get().rm.getRegionsNear(player, 60, player.getWorld());
if (regions.size() == 0) {
RPLang.sendMessage(player, "cmdmanager.noregions.nearby");
} else {
Iterator<Region> i = regions.iterator();
player.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.regionwith40")));
player.sendMessage(RPUtil.toText(RPLang.get("general.color") + "------------------------------------"));
while (i.hasNext()) {
Region r = i.next();
player.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.region.name") + r.getName() + RPLang.get("general.color") + " | " + RPLang.get("region.center") + " (&6X,Z" + RPLang.get("general.color") + "): &6" + r.getCenterX() + ", " + r.getCenterZ()));
}
player.sendMessage(RPUtil.toText(RPLang.get("general.color") + "------------------------------------"));
}
} else {
RPLang.sendMessage(player, "no.permission");
}
return cmdr;
}
if (checkCmd(args[0], "flag")) {
if (RedProtect.get().ph.hasUserPerm(player, "flaggui")) {
Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
if (r != null) {
if (r.isLeader(player) || r.isAdmin(player) || RedProtect.get().ph.hasAdminFlagPerm(player, "redprotect.admin.flaggui")) {
RPGui gui = new RPGui(r.getName(), player, r, RedProtect.get().cfgs.getGuiMaxSlot());
gui.open();
return cmdr;
} else {
sendNoPermissionMessage(player);
return cmdr;
}
} else {
RPLang.sendMessage(player, "cmdmanager.region.todo.that");
return cmdr;
}
}
}
// rp renew-rent
if (checkCmd(args[0], "renew-rent") && RedProtect.get().ph.hasGenPerm(player, "redprotect.rent.renew-rent")) {
Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
if (r == null) {
RPLang.sendMessage(player, "cmdmanager.region.doesexists");
return cmdr;
}
String puuid = RPUtil.PlayerToUUID(player.getName());
if (!r.isRentFor(puuid)) {
RPLang.sendMessage(player, "cmdmanager.rent.younotrented");
return cmdr;
}
if (RPUtil.getNowMillis() != r.getRentDateMillis(puuid) && !RedProtect.get().cfgs.getBool("region-settings.rent.renew-anytime")) {
RPLang.sendMessage(player, RPLang.get("cmdmanager.rent.cantrenewanytime").replace("{renew}", r.getRentDateFormated(puuid)));
return cmdr;
}
UniqueAccount acc = RedProtect.get().econ.getOrCreateAccount(player.getUniqueId()).get();
if (acc.getBalance(RedProtect.get().econ.getDefaultCurrency()).doubleValue() >= r.getRentValue(puuid)) {
Calendar cal = Calendar.getInstance();
String[] opts = RedProtect.get().cfgs.getString("region-settings.rent.command-renew-adds").split(":");
if (opts[1].equalsIgnoreCase("MONTH")) {
cal.add(Calendar.MONTH, Integer.valueOf(opts[0]));
} else if (opts[1].equalsIgnoreCase("DAY")) {
cal.add(Calendar.DAY_OF_MONTH, Integer.valueOf(opts[0]));
}
acc.withdraw(RedProtect.get().econ.getDefaultCurrency(), BigDecimal.valueOf(r.getRentValue(puuid)), RedProtect.get().getPVHelper().getCause(player));
r.setRent(puuid, cal.getTimeInMillis());
RPLang.sendMessage(player, RPLang.get("cmdmanager.rent.renewsuccess").replace("{region}", r.getName()).replace("{value}", RPEconomy.getFormatted(r.getRentValue(puuid))));
} else {
RPLang.sendMessage(player, "cmdmanager.rent.renewfail");
}
return cmdr;
}
}
if (args.length == 2) {
// rp removeall <player>
if (checkCmd(args[0], "removeall") && sender.hasPermission("redprotect.removeall")) {
if (!RedProtect.get().WE) {
return cmdr;
}
int removed = RedProtect.get().rm.removeAll(args[1]);
if (removed <= 0) {
RPLang.sendMessage(sender, RPLang.get("cmdmanager.region.noneremoved"));
} else {
RPLang.sendMessage(sender, RPLang.get("cmdmanager.region.removed").replace("{regions}", removed + "").replace("{player}", args[1]));
}
return cmdr;
}
// rp regenall <player>
if (checkCmd(args[0], "regenall") && sender.hasPermission("redprotect.regenall")) {
if (!RedProtect.get().WE) {
return cmdr;
}
int regen = RedProtect.get().rm.regenAll(args[1]);
if (regen <= 0) {
RPLang.sendMessage(sender, RPLang.get("cmdmanager.region.noneregenerated"));
} else {
RPLang.sendMessage(sender, RPLang.get("cmdmanager.region.regenerated").replace("{regions}", regen + "").replace("{player}", args[1]));
}
return cmdr;
}
// rp regen stop
if (checkCmd(args[0], "regen") && args[1].equalsIgnoreCase("stop") && player.hasPermission("redprotect.regen")) {
if (!RedProtect.get().WE) {
return cmdr;
}
RPUtil.stopRegen = true;
RPLang.sendMessage(player, "&aRegen will stop now. To continue reload the plugin!");
return cmdr;
}
if (checkCmd(args[0], "help")) {
try {
int page = Integer.parseInt(args[1]);
HandleHelPage(sender, page);
} catch (NumberFormatException e) {
RPLang.sendMessage(player, RPLang.get("correct.usage") + "&e/rp ? [page]");
}
return cmdr;
}
// rp define [nameOfRegion]
if (checkCmd(args[0], "define")) {
if (!RedProtect.get().ph.hasGenPerm(player, "define")) {
RPLang.sendMessage(player, "no.permission");
return cmdr;
}
String serverName = RedProtect.get().cfgs.getString("region-settings.default-leader");
String name = args[1].replace("/", "|");
RegionBuilder rb2 = new DefineRegionBuilder(player, RedProtect.get().firstLocationSelections.get(player), RedProtect.get().secondLocationSelections.get(player), name, serverName, new LinkedList<>(), true);
if (rb2.ready()) {
Region r2 = rb2.build();
RPLang.sendMessage(player, RPLang.get("cmdmanager.region.created") + " " + r2.getName() + ".");
RedProtect.get().rm.add(r2, player.getWorld());
RedProtect.get().firstLocationSelections.remove(player);
RedProtect.get().secondLocationSelections.remove(player);
RedProtect.get().logger.addLog("(World " + r2.getWorld() + ") Player " + player.getName() + " DEFINED region " + r2.getName());
}
return cmdr;
}
// rp claim [nameOfRegion]
if (checkCmd(args[0], "claim")) {
String claimmode = RedProtect.get().cfgs.getWorldClaimType(player.getWorld().getName());
if ((!claimmode.equalsIgnoreCase("WAND") && !claimmode.equalsIgnoreCase("BOTH")) && !player.hasPermission("redprotect.admin.claim")) {
RPLang.sendMessage(player, "blocklistener.region.blockmode");
return cmdr;
}
String name = args[1].replace("/", "|");
String leader = player.getUniqueId().toString();
if (!RedProtect.get().OnlineMode) {
leader = player.getName().toLowerCase();
}
RegionBuilder rb2 = new DefineRegionBuilder(player, RedProtect.get().firstLocationSelections.get(player), RedProtect.get().secondLocationSelections.get(player), name, leader, new LinkedList<>(), false);
if (rb2.ready()) {
Region r2 = rb2.build();
RPLang.sendMessage(player, RPLang.get("cmdmanager.region.created") + " " + r2.getName() + ".");
RedProtect.get().rm.add(r2, player.getWorld());
RedProtect.get().firstLocationSelections.remove(player);
RedProtect.get().secondLocationSelections.remove(player);
RedProtect.get().logger.addLog("(World " + r2.getWorld() + ") Player " + player.getName() + " CLAIMED region " + r2.getName());
}
return cmdr;
}
if (checkCmd(args[0], "redefine")) {
Region oldRect = RedProtect.get().rm.getRegion(args[1], player.getWorld());
if (oldRect == null) {
RPLang.sendMessage(player, RPLang.get("cmdmanager.region.doesntexist") + ": " + args[1]);
return cmdr;
}
if (!RedProtect.get().ph.hasRegionPermLeader(player, "redefine", oldRect)) {
RPLang.sendMessage(player, "no.permission");
return cmdr;
}
RedefineRegionBuilder rb = new RedefineRegionBuilder(player, oldRect, RedProtect.get().firstLocationSelections.get(player), RedProtect.get().secondLocationSelections.get(player));
if (rb.ready()) {
Region r2 = rb.build();
RPLang.sendMessage(player, RPLang.get("cmdmanager.region.redefined") + " " + r2.getName() + ".");
RedProtect.get().rm.add(r2, player.getWorld());
RedProtect.get().firstLocationSelections.remove(player);
RedProtect.get().secondLocationSelections.remove(player);
RedProtect.get().logger.addLog("(World " + r2.getWorld() + ") Player " + player.getName() + " REDEFINED region " + r2.getName());
}
return cmdr;
}
// rp del-rent <player>
if (checkCmd(args[0], "del-rent") && RedProtect.get().ph.hasUserPerm(player, "del-rent")) {
Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
if (r == null) {
RPLang.sendMessage(player, "cmdmanager.region.todo.that");
return cmdr;
}
if (!r.isLeader(player) && !RedProtect.get().ph.hasGenPerm(player, "redprotect.rent.others")) {
sendNoPermissionMessage(player);
return cmdr;
}
if (r.isRentFor(RPUtil.PlayerToUUID(args[1]))) {
r.removeRent(RPUtil.PlayerToUUID(args[1]));
RPLang.sendMessage(player, RPLang.get("cmdmanager.rent.playerremoved").replace("{region}", r.getName()));
} else {
RPLang.sendMessage(player, RPLang.get("cmdmanager.rent.noplayerrented"));
}
return cmdr;
}
}
if (args.length == 3) {
// rp regen <region> <world>
if (checkCmd(args[0], "regen") && player.hasPermission("redprotect.regen")) {
if (!RedProtect.get().WE) {
return cmdr;
}
World w = RedProtect.get().serv.getWorld(args[2]).get();
if (w == null) {
RPLang.sendMessage(sender, RPLang.get("cmdmanager.region.invalidworld"));
return cmdr;
}
Region r = RedProtect.get().rm.getRegion(args[1], w);
if (r == null) {
RPLang.sendMessage(sender, RPLang.get("correct.usage") + " &eInvalid region: " + args[1]);
return cmdr;
}
WEListener.regenRegion(r, Sponge.getServer().getWorld(r.getWorld()).get(), r.getMaxLocation(), r.getMinLocation(), 0, sender, false);
return cmdr;
}
// rp undo <region> <world>
if (args[0].equalsIgnoreCase("undo") && player.hasPermission("redprotect.regen")) {
if (!RedProtect.get().WE) {
return cmdr;
}
World w = RedProtect.get().serv.getWorld(args[2]).get();
if (w == null) {
RPLang.sendMessage(sender, RPLang.get("cmdmanager.region.invalidworld"));
return cmdr;
}
Region r = RedProtect.get().rm.getRegion(args[1], w);
if (r == null) {
RPLang.sendMessage(sender, RPLang.get("correct.usage") + " &eInvalid region: " + args[1]);
return cmdr;
}
if (WEListener.undo(r.getID())) {
RPLang.sendMessage(sender, RPLang.get("cmdmanager.regen.undo.sucess").replace("{region}", r.getName()));
} else {
RPLang.sendMessage(sender, RPLang.get("cmdmanager.regen.undo.none").replace("{region}", r.getName()));
}
return cmdr;
}
// rp edit-rent <player> <valor/date>
if (checkCmd(args[0], "edit-rent") && RedProtect.get().ph.hasUserPerm(player, "edit-rent")) {
Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
if (r == null) {
RPLang.sendMessage(player, "cmdmanager.region.todo.that");
return cmdr;
}
if (!r.isLeader(player) && !RedProtect.get().ph.hasUserPerm(player, "rent.others")) {
sendNoPermissionMessage(player);
return cmdr;
}
if (!r.isRentFor(RPUtil.PlayerToUUID(args[1]))) {
RPLang.sendMessage(player, "cmdmanager.rent.playernotrented");
return cmdr;
}
try {
int value = Integer.valueOf(args[2]);
r.setRent(RPUtil.PlayerToUUID(args[1]), value);
RPLang.sendMessage(player, RPLang.get("cmdmanager.rent.renteditok").replace("{player}", args[1]).replace("{value}", args[2]));
return cmdr;
} catch (NumberFormatException ex) {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(RedProtect.get().cfgs.getString("region-settings.date-format"));
try {
cal.setTime(sdf.parse(args[2]));
r.setRent(RPUtil.PlayerToUUID(args[1]), cal.getTimeInMillis());
RPLang.sendMessage(player, RPLang.get("cmdmanager.rent.renteditok").replace("{player}", args[1]).replace("{value}", args[2]));
return cmdr;
} catch (ParseException ignored) {
}
}
}
// rp claim [regionName] [leader]
if (checkCmd(args[0], "claim")) {
String claimmode = RedProtect.get().cfgs.getWorldClaimType(player.getWorld().getName());
if ((!claimmode.equalsIgnoreCase("WAND") && !claimmode.equalsIgnoreCase("BOTH")) && !player.hasPermission("redprotect.admin.claim")) {
RPLang.sendMessage(player, "blocklistener.region.blockmode");
return cmdr;
}
String name = args[1].replace("/", "|");
String leader = player.getUniqueId().toString();
List<String> addedAdmins = new ArrayList<>();
addedAdmins.add(RPUtil.PlayerToUUID(args[2]));
if (!RedProtect.get().OnlineMode) {
leader = player.getName().toLowerCase();
}
RegionBuilder rb2 = new DefineRegionBuilder(player, RedProtect.get().firstLocationSelections.get(player), RedProtect.get().secondLocationSelections.get(player), name, leader, addedAdmins, false);
if (rb2.ready()) {
Region r2 = rb2.build();
RPLang.sendMessage(player, RPLang.get("cmdmanager.region.created") + " " + r2.getName() + ".");
RedProtect.get().rm.add(r2, player.getWorld());
RedProtect.get().firstLocationSelections.remove(player);
RedProtect.get().secondLocationSelections.remove(player);
RedProtect.get().logger.addLog("(World " + r2.getWorld() + ") Player " + player.getName() + " CLAIMED region " + r2.getName());
}
return cmdr;
}
// - /rp copyflag from to
if (checkCmd(args[0], "copyflag")) {
if (!RedProtect.get().ph.hasGenPerm(player, "copyflag")) {
RPLang.sendMessage(player, "no.permission");
return cmdr;
}
World w = player.getWorld();
Region from = RedProtect.get().rm.getRegion(args[1], w);
Region to = RedProtect.get().rm.getRegion(args[2], w);
if (from == null) {
RPLang.sendMessage(player, RPLang.get("cmdmanager.region.doesntexist") + ": " + args[1]);
return cmdr;
}
if (to == null) {
RPLang.sendMessage(player, RPLang.get("cmdmanager.region.doesntexist") + ": " + args[2]);
return cmdr;
}
for (String key : from.flags.keySet()) {
to.setFlag(key, from.flags.get(key));
}
RPLang.sendMessage(player, RPLang.get("cmdmanager.region.flag.copied") + args[1] + " > " + args[2]);
RedProtect.get().logger.addLog("Player " + player.getName() + " Copied FLAGS from " + args[1] + " to " + args[2]);
return cmdr;
}
}
if (args.length == 4 || args.length == 5) {
// rp add-rent <player> <valor> <date>
if (checkCmd(args[0], "add-rent") && player.hasPermission("redprotect.add-rent")) {
Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
if (r == null) {
RPLang.sendMessage(player, "cmdmanager.region.todo.that");
return cmdr;
}
if (!r.isLeader(player) && !player.hasPermission("redprotect.rent.others")) {
sendNoPermissionMessage(player);
return cmdr;
}
int value = 0;
long renewal = 0;
try {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(RedProtect.get().cfgs.getString("region-settings.date-format"));
cal.setTime(sdf.parse(args[3]));
renewal = cal.getTimeInMillis();
value = Integer.valueOf(args[2]);
} catch (Exception ex) {
RPLang.sendMessage(player, RPLang.get("correct.command") + " &b/rp " + getCmd("help"));
ex.printStackTrace();
return cmdr;
}
String play = RPUtil.PlayerToUUID(args[1]);
if (args.length == 4) {
r.addrent(play, value, renewal, RedProtect.get().cfgs.getString("region-settings.rent.default-level"));
} else if (args.length == 5) {
if (args[4].equalsIgnoreCase("member") || args[4].equalsIgnoreCase("admin") || args[4].equalsIgnoreCase("leader")) {
r.addrent(play, value, renewal, args[4]);
} else {
RPLang.sendMessage(player, RPLang.get("cmdmanager.rent.validranks").replace("{ranks}", "member, admin, leader"));
return cmdr;
}
}
RPLang.sendMessage(player, RPLang.get("cmdmanager.rent.addedrent").replace("{player}", args[1]).replace("{date}", args[3]).replace("{cost}", args[2]));
if (RedProtect.get().serv.getPlayer(args[1]).isPresent()) {
RPLang.sendMessage(RedProtect.get().serv.getPlayer(args[1]).get(), RPLang.get("cmdmanager.rent.playeraddedrent").replace("{region}", r.getName()).replace("{date}", args[3]).replace("{cost}", args[2]));
}
return cmdr;
}
}
// rp expand-vert [region] [world]
if (checkCmd(args[0], "expand-vert")) {
if (!RedProtect.get().ph.hasGenPerm(player, "expandvert")) {
RPLang.sendMessage(player, "no.permission");
return cmdr;
}
Region r = null;
// rp expand-vert
if (args.length == 1) {
r = RedProtect.get().rm.getTopRegion(player.getLocation());
if (r == null) {
RPLang.sendMessage(player, "cmdmanager.region.todo.that");
return cmdr;
}
} else // rp expand-vert [region]
if (args.length == 2) {
r = RedProtect.get().rm.getRegion(args[1], player.getWorld());
if (r == null) {
RPLang.sendMessage(player, RPLang.get("cmdmanager.region.doesntexist") + ": " + args[1]);
return cmdr;
}
} else // rp expand-vert [region] [world]
if (args.length == 3) {
if (!Sponge.getServer().getWorld(args[2]).isPresent()) {
RPLang.sendMessage(player, "cmdmanager.region.invalidworld");
return cmdr;
}
r = RedProtect.get().rm.getRegion(args[1], Sponge.getServer().getWorld(args[2]).get());
if (r == null) {
RPLang.sendMessage(player, RPLang.get("cmdmanager.region.doesntexist") + ": " + args[1]);
return cmdr;
}
} else {
RPLang.sendMessage(player, RPLang.get("cmdmanager.help.expandvert").replace("{cmd}", getCmd("expandvert")).replace("{alias}", getCmdAlias("expandvert")));
return cmdr;
}
r.setMaxY(256);
r.setMinY(0);
RPLang.sendMessage(player, RPLang.get("cmdmanager.region.expandvert.success").replace("{region}", r.getName()).replace("{miny}", String.valueOf(r.getMinY())).replace("{maxy}", String.valueOf(r.getMaxY())));
return cmdr;
}
// rp setmaxy <size> [region] [world]
if (checkCmd(args[0], "setmaxy")) {
if (!RedProtect.get().ph.hasGenPerm(player, "setmaxy")) {
RPLang.sendMessage(player, "no.permission");
return cmdr;
}
Region r = null;
// rp setmaxy <size>
switch(args.length) {
case 2:
r = RedProtect.get().rm.getTopRegion(player.getLocation());
if (r == null) {
RPLang.sendMessage(player, "cmdmanager.region.todo.that");
return cmdr;
}
break;
// rp setmaxy <size> [region]
case 3:
r = RedProtect.get().rm.getRegion(args[2], player.getWorld());
if (r == null) {
RPLang.sendMessage(player, RPLang.get("cmdmanager.region.doesntexist") + ": " + args[2]);
return cmdr;
}
break;
// rp setmaxy <size> [region] [world]
case 4:
if (!Sponge.getServer().getWorld(args[3]).isPresent()) {
RPLang.sendMessage(player, "cmdmanager.region.invalidworld");
return cmdr;
}
r = RedProtect.get().rm.getRegion(args[2], Sponge.getServer().getWorld(args[3]).get());
if (r == null) {
RPLang.sendMessage(player, RPLang.get("cmdmanager.region.doesntexist") + ": " + args[2]);
return cmdr;
}
break;
default:
RPLang.sendMessage(player, RPLang.get("cmdmanager.help.setmaxy").replace("{cmd}", getCmd("setmaxy")).replace("{alias}", getCmdAlias("setmaxy")));
return cmdr;
}
String from = String.valueOf(r.getMaxY());
try {
int size = Integer.parseInt(args[1]);
if ((size - r.getMinY()) <= 1) {
RPLang.sendMessage(player, "cmdmanager.region.ysiszesmatch");
return cmdr;
}
r.setMaxY(size);
RPLang.sendMessage(player, RPLang.get("cmdmanager.region.setmaxy.success").replace("{region}", r.getName()).replace("{fromsize}", from).replace("{size}", String.valueOf(size)));
RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + player.getName() + " SETMAXY of region " + r.getName() + " to " + args[1]);
return cmdr;
} catch (NumberFormatException e) {
RPLang.sendMessage(player, "cmdmanager.region.invalid.number");
return cmdr;
}
}
// rp setmaxy <size> [region] [world]
if (checkCmd(args[0], "setminy")) {
if (!RedProtect.get().ph.hasGenPerm(player, "setminy")) {
RPLang.sendMessage(player, "no.permission");
return cmdr;
}
Region r = null;
// rp setmaxy <size>
switch(args.length) {
case 2:
r = RedProtect.get().rm.getTopRegion(player.getLocation());
if (r == null) {
RPLang.sendMessage(player, "cmdmanager.region.todo.that");
return cmdr;
}
break;
// rp setmaxy <size> [region]
case 3:
r = RedProtect.get().rm.getRegion(args[2], player.getWorld());
if (r == null) {
RPLang.sendMessage(player, RPLang.get("cmdmanager.region.doesntexist") + ": " + args[2]);
return cmdr;
}
break;
// rp setmaxy <size> [region] [world]
case 4:
if (!Sponge.getServer().getWorld(args[3]).isPresent()) {
RPLang.sendMessage(player, "cmdmanager.region.invalidworld");
return cmdr;
}
r = RedProtect.get().rm.getRegion(args[2], Sponge.getServer().getWorld(args[3]).get());
if (r == null) {
RPLang.sendMessage(player, RPLang.get("cmdmanager.region.doesntexist") + ": " + args[2]);
return cmdr;
}
break;
default:
RPLang.sendMessage(player, RPLang.get("cmdmanager.help.setminy").replace("{cmd}", getCmd("setminy")).replace("{alias}", getCmdAlias("setminy")));
return cmdr;
}
String from = String.valueOf(r.getMinY());
try {
int size = Integer.parseInt(args[1]);
if ((r.getMaxY() - size) <= 1) {
RPLang.sendMessage(player, "cmdmanager.region.ysiszesmatch");
return cmdr;
}
r.setMinY(size);
RPLang.sendMessage(player, RPLang.get("cmdmanager.region.setminy.success").replace("{region}", r.getName()).replace("{fromsize}", from).replace("{size}", String.valueOf(size)));
RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + player.getName() + " SETMINY of region " + r.getName() + " to " + args[1]);
return cmdr;
} catch (NumberFormatException e) {
RPLang.sendMessage(player, "cmdmanager.region.invalid.number");
return cmdr;
}
}
if (checkCmd(args[0], "buy") && RedProtect.get().ph.hasGenPerm(player, "redprotect.eco.buy")) {
Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
if (r == null) {
RPLang.sendMessage(player, "cmdmanager.region.todo.that");
return cmdr;
}
if (!r.isForSale()) {
RPLang.sendMessage(player, "economy.region.buy.notforsale");
return cmdr;
}
if (args.length == 1) {
buyHandler(player, r.getValue(), r);
RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + player.getName() + " BUY region " + r.getName() + " for " + r.getValue());
return cmdr;
}
}
if (checkCmd(args[0], "sell") && RedProtect.get().ph.hasGenPerm(player, "redprotect.eco.sell")) {
Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
if (r == null) {
RPLang.sendMessage(player, "cmdmanager.region.todo.that");
return cmdr;
}
if (r.isForSale()) {
RPLang.sendMessage(player, "economy.region.sell.already");
return cmdr;
}
if (args.length == 1) {
r.setValue(RPEconomy.getRegionValue(r));
if (r.isLeader(player)) {
sellHandler(r, player, RPUtil.PlayerToUUID(player.getName()), r.getValue());
} else {
sellHandler(r, player, r.getLeaders().get(0), r.getValue());
}
RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + player.getName() + " SELL region " + r.getName() + " for " + r.getValue());
return cmdr;
}
if (args.length == 2) {
// rp sell <value/player>
try {
long value = Long.valueOf(args[1]);
if (RedProtect.get().ph.hasGenPerm(player, "redprotect.eco.setvalue")) {
r.setValue(value);
if (r.isLeader(player)) {
sellHandler(r, player, RPUtil.PlayerToUUID(player.getName()), r.getValue());
} else {
sellHandler(r, player, r.getLeaders().get(0), r.getValue());
}
RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + player.getName() + " SELL region " + r.getName() + " for " + r.getValue());
return cmdr;
}
} catch (NumberFormatException e) {
if (RedProtect.get().ph.hasGenPerm(player, "redprotect.eco.others")) {
r.setValue(RPEconomy.getRegionValue(r));
sellHandler(r, player, RPUtil.PlayerToUUID(args[1]), r.getValue());
RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + player.getName() + " SELL region " + r.getName() + " in name of player " + args[1] + " for " + r.getValue());
return cmdr;
}
}
}
if (args.length == 3) {
// rp sell player value
try {
long value = Long.valueOf(args[2]);
if (RedProtect.get().ph.hasGenPerm(player, "redprotect.eco.setvalue")) {
r.setValue(value);
sellHandler(r, player, RPUtil.PlayerToUUID(args[1]), value);
RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + player.getName() + " SELL region " + r.getName() + " in name of player " + args[1] + " for " + value);
return cmdr;
}
} catch (NumberFormatException e) {
RPLang.sendMessage(player, "cmdmanager.eco.notdouble");
return cmdr;
}
}
}
if (checkCmd(args[0], "teleport")) {
if (args.length == 1) {
RPLang.sendMessage(player, RPLang.get("cmdmanager.help.teleport").replace("{cmd}", getCmd("teleport")).replace("{alias}", getCmdAlias("teleport")));
return cmdr;
}
if (args.length == 2) {
handletp(player, args[1], player.getWorld().getName(), null);
return cmdr;
}
if (args.length == 3) {
handletp(player, args[1], args[2], null);
return cmdr;
}
if (args.length == 4) {
// /rp tp <player> <region> <world>
Player play = null;
if (Sponge.getServer().getPlayer(args[1]).isPresent()) {
play = Sponge.getServer().getPlayer(args[1]).get();
}
if (play != null) {
handletp(player, args[2], args[3], play);
return cmdr;
} else {
RPLang.sendMessage(player, RPLang.get("cmdmanager.noplayer.thisname").replace("{player}", args[1]));
RPLang.sendMessage(player, RPLang.get("cmdmanager.help.teleport").replace("{cmd}", getCmd("teleport")).replace("{alias}", getCmdAlias("teleport")));
return cmdr;
}
}
}
if (checkCmd(args[0], "limit")) {
if (!RedProtect.get().ph.hasUserPerm(player, "limit")) {
RPLang.sendMessage(player, "no.permission");
return cmdr;
}
if (args.length == 1) {
int limit = RedProtect.get().ph.getPlayerBlockLimit(player);
if (limit < 0 || RedProtect.get().ph.hasPerm(player, "redprotect.limit.blocks.unlimited")) {
RPLang.sendMessage(player, "cmdmanager.nolimit");
return cmdr;
}
String uuid = player.getUniqueId().toString();
if (!RedProtect.get().OnlineMode) {
uuid = player.getName().toLowerCase();
}
int currentUsed = RedProtect.get().rm.getTotalRegionSize(uuid, player.getPlayer().isPresent() ? player.getPlayer().get().getWorld().getName() : null);
RPLang.sendMessage(player, RPLang.get("cmdmanager.yourarea") + currentUsed + RPLang.get("general.color") + "/&e" + limit + RPLang.get("general.color"));
return cmdr;
}
if (!RedProtect.get().ph.hasPerm(player, "redprotect.other.limit")) {
RPLang.sendMessage(player, "no.permission");
return cmdr;
}
if (args.length == 2) {
User offp = RPUtil.getUser(args[1]);
if (offp == null) {
RPLang.sendMessage(player, RPLang.get("cmdmanager.noplayer.thisname").replace("{player}", args[1]));
return cmdr;
}
int limit = RedProtect.get().ph.getPlayerBlockLimit(offp);
if (limit < 0 || RedProtect.get().ph.hasPerm(offp, "redprotect.limit.blocks.unlimited")) {
RPLang.sendMessage(player, "cmdmanager.nolimit");
return cmdr;
}
int currentUsed = RedProtect.get().rm.getTotalRegionSize(RPUtil.PlayerToUUID(offp.getName()), offp.getPlayer().isPresent() ? offp.getPlayer().get().getWorld().getName() : null);
RPLang.sendMessage(player, RPLang.get("cmdmanager.yourarea") + currentUsed + RPLang.get("general.color") + "/&e" + limit + RPLang.get("general.color"));
return cmdr;
}
RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.limit").replace("{cmd}", getCmd("limit")).replace("{alias}", getCmdAlias("limit")));
return cmdr;
}
if (checkCmd(args[0], "claimlimit")) {
if (!RedProtect.get().ph.hasUserPerm(player, "claimlimit")) {
RPLang.sendMessage(player, "no.permission");
return cmdr;
}
if (args.length == 1) {
int limit = RedProtect.get().ph.getPlayerClaimLimit(player);
if (limit < 0 || RedProtect.get().ph.hasPerm(player, "redprotect.claimunlimited")) {
RPLang.sendMessage(player, "cmdmanager.nolimit");
return cmdr;
}
int currentUsed = RedProtect.get().rm.getRegions(RPUtil.PlayerToUUID(player.getName()), player.getWorld()).size();
RPLang.sendMessage(player, RPLang.get("cmdmanager.yourclaims") + currentUsed + RPLang.get("general.color") + "/&e" + limit + RPLang.get("general.color"));
return cmdr;
}
if (!RedProtect.get().ph.hasPerm(player, "redprotect.other.claimlimit")) {
RPLang.sendMessage(player, "no.permission");
return cmdr;
}
if (args.length == 2) {
User offp = RPUtil.getUser(args[1]);
if (offp == null) {
RPLang.sendMessage(player, RPLang.get("cmdmanager.noplayer.thisname").replace("{player}", args[1]));
return cmdr;
}
int limit = RedProtect.get().ph.getPlayerClaimLimit(offp);
if (limit < 0 || RedProtect.get().ph.hasPerm(offp, "redprotect.limit.claim.unlimited")) {
RPLang.sendMessage(player, "cmdmanager.nolimit");
return cmdr;
}
int currentUsed = RedProtect.get().rm.getRegions(RPUtil.PlayerToUUID(offp.getName()), player.getWorld()).size();
RPLang.sendMessage(player, RPLang.get("cmdmanager.yourclaims") + currentUsed + RPLang.get("general.color") + "/&e" + limit + RPLang.get("general.color"));
return cmdr;
}
RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.claimlimit").replace("{cmd}", getCmd("claimlimit")).replace("{alias}", getCmdAlias("claimlimit")));
return cmdr;
}
if (checkCmd(args[0], "welcome")) {
if (args.length >= 2) {
String wMessage = "";
if (args[1].equals("off")) {
handleWelcome(player, wMessage);
return cmdr;
} else {
for (int i = 1; i < args.length; i++) {
wMessage = wMessage + args[i] + " ";
}
handleWelcome(player, wMessage);
return cmdr;
}
}
RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.welcome").replace("{cmd}", getCmd("welcome")).replace("{alias}", getCmdAlias("welcome")));
return cmdr;
}
if (checkCmd(args[0], "priority")) {
int prior = 0;
if (args.length == 2) {
try {
prior = Integer.parseInt(args[1]);
} catch (NumberFormatException e) {
RPLang.sendMessage(player, "cmdmanager.region.notnumber");
return cmdr;
}
handlePriority(player, prior);
return cmdr;
}
if (args.length == 3) {
try {
prior = Integer.parseInt(args[2]);
} catch (NumberFormatException e) {
RPLang.sendMessage(player, "cmdmanager.region.notnumber");
return cmdr;
}
handlePrioritySingle(player, prior, args[1]);
return cmdr;
}
RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.priority").replace("{cmd}", getCmd("priority")).replace("{alias}", getCmdAlias("priority")));
return cmdr;
}
if (checkCmd(args[0], "delete")) {
// rp del [region] [world]
if (args.length == 1) {
handleDelete(player);
return cmdr;
}
if (args.length == 2) {
handleDeleteName(player, args[1], "");
return cmdr;
}
if (args.length == 3) {
handleDeleteName(player, args[1], args[2]);
return cmdr;
}
RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.delete").replace("{cmd}", getCmd("delete")).replace("{alias}", getCmdAlias("delete")));
return cmdr;
}
if (checkCmd(args[0], "info")) {
// rp info [region] [world]
if (args.length == 1) {
handleInfoTop(player);
return cmdr;
}
if (args.length == 2) {
handleInfo(player, args[1], "");
return cmdr;
}
if (args.length == 3) {
handleInfo(player, args[1], args[2]);
return cmdr;
}
RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.info").replace("{cmd}", getCmd("info")).replace("{alias}", getCmdAlias("info")));
return cmdr;
}
if (checkCmd(args[0], "addmember")) {
if (args.length == 2) {
handleAddMember(player, args[1]);
return cmdr;
}
RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.addmember").replace("{cmd}", getCmd("addmember")).replace("{alias}", getCmdAlias("addmember")));
return cmdr;
}
if (checkCmd(args[0], "addadmin")) {
if (args.length == 2) {
handleAddAdmin(player, args[1]);
return cmdr;
}
RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.addadmin").replace("{cmd}", getCmd("addadmin")).replace("{alias}", getCmdAlias("addadmin")));
return cmdr;
}
if (checkCmd(args[0], "addleader")) {
if (args.length == 2) {
handleAddLeader(player, args[1]);
return cmdr;
}
RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.addleader").replace("{cmd}", getCmd("addleader")).replace("{alias}", getCmdAlias("addleader")));
return cmdr;
}
if (checkCmd(args[0], "removemember")) {
if (args.length == 2) {
handleRemoveMember(player, args[1]);
return cmdr;
}
RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.removemember").replace("{cmd}", getCmd("removemember")).replace("{alias}", getCmdAlias("removemember")));
return cmdr;
}
if (checkCmd(args[0], "removeadmin")) {
if (args.length == 2) {
handleRemoveAdmin(player, args[1]);
return cmdr;
}
RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.removeadmin").replace("{cmd}", getCmd("removeadmin")).replace("{alias}", getCmdAlias("removeadmin")));
return cmdr;
}
if (checkCmd(args[0], "removeleader")) {
if (args.length == 2) {
handleRemoveLeader(player, args[1]);
return cmdr;
}
RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.removeleader").replace("{cmd}", getCmd("removeleader")).replace("{alias}", getCmdAlias("removeleader")));
return cmdr;
}
if (checkCmd(args[0], "rename")) {
if (args.length == 2) {
handleRename(player, args[1]);
return cmdr;
}
RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.rename").replace("{cmd}", getCmd("rename")).replace("{alias}", getCmdAlias("rename")));
return cmdr;
}
if (checkCmd(args[0], "flag")) {
Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
if (r == null) {
RPLang.sendMessage(player, "cmdmanager.region.todo.that");
return cmdr;
}
if (args.length == 2) {
if (RedProtect.get().cfgs.getBool("flags-configuration.change-flag-delay.enable")) {
if (RedProtect.get().cfgs.getStringList("flags-configuration.change-flag-delay.flags").contains(args[1])) {
if (!RedProtect.get().changeWait.contains(r.getName() + args[1])) {
RPUtil.startFlagChanger(r.getName(), args[1], player);
handleFlag(player, args[1], "", r);
return cmdr;
} else {
RPLang.sendMessage(player, RPLang.get("gui.needwait.tochange").replace("{seconds}", RedProtect.get().cfgs.getString("flags-configuration.change-flag-delay.seconds")));
return cmdr;
}
}
}
handleFlag(player, args[1], "", r);
return cmdr;
}
if (args.length >= 3) {
String text = "";
for (int i = 2; i < args.length; i++) {
text = text + " " + args[i];
}
if (RedProtect.get().cfgs.getBool("flags-configuration.change-flag-delay.enable")) {
if (RedProtect.get().cfgs.getStringList("flags-configuration.change-flag-delay.flags").contains(args[1])) {
if (!RedProtect.get().changeWait.contains(r.getName() + args[1])) {
RPUtil.startFlagChanger(r.getName(), args[1], player);
handleFlag(player, args[1], text.substring(1), r);
return cmdr;
} else {
RPLang.sendMessage(player, RPLang.get("gui.needwait.tochange").replace("{seconds}", RedProtect.get().cfgs.getString("flags-configuration.change-flag-delay.seconds")));
return cmdr;
}
}
}
handleFlag(player, args[1], text.substring(1), r);
return cmdr;
}
RPLang.sendMessage(player, RPLang.get("correct.usage") + " " + RPLang.get("cmdmanager.help.flag").replace("{cmd}", getCmd("flag")).replace("{alias}", getCmdAlias("flag")));
return cmdr;
}
if (checkCmd(args[0], "list")) {
// rp list
if (args.length == 1) {
handleList(player, RPUtil.PlayerToUUID(player.getName()), 1);
return cmdr;
}
// rp list [player]
if (args.length == 2) {
handleList(player, RPUtil.PlayerToUUID(args[1]), 1);
return cmdr;
}
// rp list [player] [page]
if (args.length == 3) {
try {
int Page = Integer.parseInt(args[2]);
handleList(player, RPUtil.PlayerToUUID(args[1]), Page);
return cmdr;
} catch (NumberFormatException e) {
RPLang.sendMessage(player, "cmdmanager.region.listpage.error");
return cmdr;
}
}
}
RPLang.sendMessage(player, RPLang.get("correct.command") + " &e/rp " + getCmd("help"));
return cmdr;
}
use of org.spongepowered.api.command.CommandResult in project LanternServer by LanternPowered.
the class LanternCommandManager method process.
@Override
public CommandResult process(CommandSource source, String commandLine) {
checkNotNull(source, "source");
final String[] argSplit = commandLine.split(" ", 2);
final CauseStack causeStack = CauseStack.currentOrEmpty();
try (CauseStack.Frame frame = causeStack.pushCauseFrame()) {
frame.pushCause(source);
final SendCommandEvent event = SpongeEventFactory.createSendCommandEvent(frame.getCurrentCause(), argSplit.length > 1 ? argSplit[1] : "", argSplit[0], CommandResult.empty());
Sponge.getGame().getEventManager().post(event);
if (event.isCancelled()) {
return event.getResult();
}
// Only the first part of argSplit is used at the moment, do the other in the future if needed.
argSplit[0] = event.getCommand();
commandLine = event.getCommand();
if (!event.getArguments().isEmpty()) {
commandLine = commandLine + ' ' + event.getArguments();
}
try {
return this.dispatcher.process(source, commandLine);
} catch (InvocationCommandException ex) {
if (ex.getCause() != null) {
throw ex.getCause();
}
} catch (CommandPermissionException ex) {
Text text = ex.getText();
if (text != null) {
source.sendMessage(error(text));
}
} catch (CommandException ex) {
Text text = ex.getText();
if (text != null) {
source.sendMessage(error(text));
}
if (ex.shouldIncludeUsage()) {
final Optional<CommandMapping> mapping = this.dispatcher.get(argSplit[0], source);
mapping.ifPresent(commandMapping -> source.sendMessage(error(t("commands.generic.usage", t("/%s %s", argSplit[0], commandMapping.getCallable().getUsage(source))))));
}
}
} catch (Throwable thr) {
final Text.Builder excBuilder;
if (thr instanceof TextMessageException) {
final Text text = ((TextMessageException) thr).getText();
excBuilder = text == null ? Text.builder("null") : Text.builder().append(text);
} else {
excBuilder = Text.builder(String.valueOf(thr.getMessage()));
}
if (source.hasPermission("sponge.debug.hover-stacktrace")) {
final StringWriter writer = new StringWriter();
thr.printStackTrace(new PrintWriter(writer));
excBuilder.onHover(TextActions.showText(Text.of(writer.toString().replace("\t", " ").replace("\r\n", "\n").replace("\r", // I mean I guess somebody could be running this on like OS 9?
"\n"))));
}
source.sendMessage(error(t("Error occurred while executing command: %s", excBuilder.build())));
this.logger.error(LanternTexts.toLegacy(t("Error occurred while executing command '%s' for source %s: %s", commandLine, source.toString(), String.valueOf(thr.getMessage()))), thr);
}
return CommandResult.empty();
}
use of org.spongepowered.api.command.CommandResult in project CatClearLag by Time6628.
the class EntitiesCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
List<Chunk> chunksToSort = (List<Chunk>) ((Player) src).getWorld().getLoadedChunks();
TreeMap<Chunk, Integer> sortedChunks = new TreeMap<>((o1, o2) -> Integer.compare(o2.getEntities().size(), o1.getEntities().size()));
for (Chunk chunk : chunksToSort) {
sortedChunks.put(chunk, chunk.getEntities().size());
}
List<Text> texts = new ArrayList<>();
sortedChunks.forEach(((chunk, integer) -> texts.add(Text.builder().append(Text.of(chunk.getPosition().getX() + "," + chunk.getPosition().getZ() + " contains " + integer + " entities.")).onClick(callback(chunk)).build())));
plugin.getPaginationService().builder().contents((texts)).title(Text.builder().color(TextColors.LIGHT_PURPLE).append(Text.of("Laggy Chunks")).build()).sendTo(src);
return CommandResult.success();
}
use of org.spongepowered.api.command.CommandResult in project CatClearLag by Time6628.
the class TilesCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
List<Chunk> chunksToSort = (List<Chunk>) ((Player) src).getWorld().getLoadedChunks();
TreeMap<Chunk, Integer> sortedChunks = new TreeMap<>((o1, o2) -> Integer.compare(o2.getTileEntities().size(), o1.getTileEntities().size()));
for (Chunk chunk : chunksToSort) {
sortedChunks.put(chunk, chunk.getTileEntities().size());
}
List<Text> texts = new ArrayList<>();
sortedChunks.forEach(((chunk, integer) -> texts.add(Text.builder().append(Text.of(chunk.getPosition().getX() + "," + chunk.getPosition().getZ() + " contains " + integer + " tiles.")).onClick(callback(chunk)).build())));
plugin.getPaginationService().builder().contents((texts)).title(Text.builder().color(TextColors.LIGHT_PURPLE).append(Text.of("Laggy Chunks")).build()).sendTo(src);
return CommandResult.success();
}
Aggregations