mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-29 16:46:45 +01:00
flag cmd
This commit is contained in:
parent
46e2b1344e
commit
9eb1b0f6f5
@ -37,6 +37,7 @@ import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
|
||||
public class FlagCmd extends SubCommand {
|
||||
public FlagCmd() {
|
||||
@ -53,102 +54,102 @@ public class FlagCmd extends SubCommand {
|
||||
* plot flag list
|
||||
*/
|
||||
if (args.length == 0) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.COMMAND_SYNTAX, "/plot flag <set|remove|add|list|info>");
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag <set|remove|add|list|info>");
|
||||
return false;
|
||||
}
|
||||
Location loc = player.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NOT_IN_PLOT);
|
||||
MainUtil.sendMessage(player, C.NOT_IN_PLOT);
|
||||
return false;
|
||||
}
|
||||
if (!plot.hasOwner()) {
|
||||
sendMessage(player, C.PLOT_NOT_CLAIMED);
|
||||
return false;
|
||||
}
|
||||
if (!plot.hasRights(player) && !Permissions.hasPermission(BukkitUtil.getPlayer(player), "plots.set.flag.other")) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NO_PERMISSION, "plots.set.flag.other");
|
||||
if (!plot.isAdded(player.getUUID()) && !Permissions.hasPermission(player, "plots.set.flag.other")) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag.other");
|
||||
return false;
|
||||
}
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "info": {
|
||||
if (!Permissions.hasPermission(BukkitUtil.getPlayer(player), "plots.set.flag")) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NO_PERMISSION, "plots.flag.info");
|
||||
if (!Permissions.hasPermission(player, "plots.set.flag")) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.info");
|
||||
return false;
|
||||
}
|
||||
if (args.length != 2) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.COMMAND_SYNTAX, "/plot flag info <flag>");
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info <flag>");
|
||||
return false;
|
||||
}
|
||||
final AbstractFlag af = FlagManager.getFlag(args[1]);
|
||||
if (af == null) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NOT_VALID_FLAG);
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.COMMAND_SYNTAX, "/plot flag info <flag>");
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info <flag>");
|
||||
return false;
|
||||
}
|
||||
// flag key
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.FLAG_KEY, af.getKey());
|
||||
MainUtil.sendMessage(player, C.FLAG_KEY, af.getKey());
|
||||
// flag type
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.FLAG_TYPE, af.value.getClass().getSimpleName());
|
||||
MainUtil.sendMessage(player, C.FLAG_TYPE, af.value.getClass().getSimpleName());
|
||||
// Flag type description
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.FLAG_DESC, af.getValueDesc());
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), "&cNot implemented.");
|
||||
MainUtil.sendMessage(player, C.FLAG_DESC, af.getValueDesc());
|
||||
MainUtil.sendMessage(player, "&cNot implemented.");
|
||||
}
|
||||
case "set": {
|
||||
if (!Permissions.hasPermission(BukkitUtil.getPlayer(player), "plots.set.flag")) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NO_PERMISSION, "plots.set.flag");
|
||||
if (!Permissions.hasPermission(player, "plots.set.flag")) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag");
|
||||
return false;
|
||||
}
|
||||
if (args.length < 3) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.COMMAND_SYNTAX, "/plot flag set <flag> <value>");
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag set <flag> <value>");
|
||||
return false;
|
||||
}
|
||||
final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
|
||||
if (af == null) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NOT_VALID_FLAG);
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.hasPermission(BukkitUtil.getPlayer(player), "plots.set.flag." + args[1].toLowerCase())) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
|
||||
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
|
||||
return false;
|
||||
}
|
||||
final String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " ");
|
||||
final Object parsed = af.parseValueRaw(value);
|
||||
if (parsed == null) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), "&c" + af.getValueDesc());
|
||||
MainUtil.sendMessage(player, "&c" + af.getValueDesc());
|
||||
return false;
|
||||
}
|
||||
final Flag flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed);
|
||||
final boolean result = FlagManager.addPlotFlag(plot, flag);
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.FLAG_NOT_ADDED);
|
||||
MainUtil.sendMessage(player, C.FLAG_NOT_ADDED);
|
||||
return false;
|
||||
}
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.FLAG_ADDED);
|
||||
MainUtil.sendMessage(player, C.FLAG_ADDED);
|
||||
PlotListener.plotEntry(player, plot);
|
||||
return true;
|
||||
}
|
||||
case "remove": {
|
||||
if (!Permissions.hasPermission(BukkitUtil.getPlayer(player), "plots.flag.remove")) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NO_PERMISSION, "plots.flag.remove");
|
||||
if (!Permissions.hasPermission(player, "plots.flag.remove")) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.remove");
|
||||
return false;
|
||||
}
|
||||
if ((args.length != 2) && (args.length != 3)) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.COMMAND_SYNTAX, "/plot flag remove <flag> [values]");
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag remove <flag> [values]");
|
||||
return false;
|
||||
}
|
||||
final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
|
||||
if (af == null) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NOT_VALID_FLAG);
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.hasPermission(BukkitUtil.getPlayer(player), "plots.set.flag." + args[1].toLowerCase())) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
|
||||
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
|
||||
return false;
|
||||
}
|
||||
final Flag flag = FlagManager.getPlotFlagAbs(plot, args[1].toLowerCase());
|
||||
if (flag == null) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.FLAG_NOT_IN_PLOT);
|
||||
MainUtil.sendMessage(player, C.FLAG_NOT_IN_PLOT);
|
||||
return false;
|
||||
}
|
||||
if ((args.length == 3) && flag.getAbstractFlag().isList()) {
|
||||
@ -158,36 +159,36 @@ public class FlagCmd extends SubCommand {
|
||||
} else {
|
||||
final boolean result = FlagManager.removePlotFlag(plot, flag.getKey());
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.FLAG_NOT_REMOVED);
|
||||
MainUtil.sendMessage(player, C.FLAG_NOT_REMOVED);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.FLAG_REMOVED);
|
||||
MainUtil.sendMessage(player, C.FLAG_REMOVED);
|
||||
PlotListener.plotEntry(player, plot);
|
||||
return true;
|
||||
}
|
||||
case "add": {
|
||||
if (!Permissions.hasPermission(BukkitUtil.getPlayer(player), "plots.flag.add")) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NO_PERMISSION, "plots.flag.add");
|
||||
if (!Permissions.hasPermission(player, "plots.flag.add")) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.add");
|
||||
return false;
|
||||
}
|
||||
if (args.length < 3) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.COMMAND_SYNTAX, "/plot flag add <flag> <values>");
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag add <flag> <values>");
|
||||
return false;
|
||||
}
|
||||
final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
|
||||
if (af == null) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NOT_VALID_FLAG);
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.hasPermission(BukkitUtil.getPlayer(player), "plots.set.flag." + args[1].toLowerCase())) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
|
||||
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
|
||||
return false;
|
||||
}
|
||||
final String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " ");
|
||||
final Object parsed = af.parseValueRaw(value);
|
||||
if (parsed == null) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), "&c" + af.getValueDesc());
|
||||
MainUtil.sendMessage(player, "&c" + af.getValueDesc());
|
||||
return false;
|
||||
}
|
||||
Flag flag = FlagManager.getPlotFlag(plot, args[1].toLowerCase());
|
||||
@ -198,21 +199,21 @@ public class FlagCmd extends SubCommand {
|
||||
}
|
||||
final boolean result = FlagManager.addPlotFlag(plot, flag);
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.FLAG_NOT_ADDED);
|
||||
MainUtil.sendMessage(player, C.FLAG_NOT_ADDED);
|
||||
return false;
|
||||
}
|
||||
DBFunc.setFlags(plot.world, plot, plot.settings.flags);
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.FLAG_ADDED);
|
||||
MainUtil.sendMessage(player, C.FLAG_ADDED);
|
||||
PlotListener.plotEntry(player, plot);
|
||||
return true;
|
||||
}
|
||||
case "list": {
|
||||
if (!Permissions.hasPermission(BukkitUtil.getPlayer(player), "plots.flag.list")) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NO_PERMISSION, "plots.flag.list");
|
||||
if (!Permissions.hasPermission(player, "plots.flag.list")) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.list");
|
||||
return false;
|
||||
}
|
||||
if (args.length != 1) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.COMMAND_SYNTAX, "/plot flag list");
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag list");
|
||||
return false;
|
||||
}
|
||||
final HashMap<String, ArrayList<String>> flags = new HashMap<>();
|
||||
@ -229,11 +230,11 @@ public class FlagCmd extends SubCommand {
|
||||
message += prefix + "&6" + flag + ": &7" + StringUtils.join(flags.get(flag), ", ");
|
||||
prefix = "\n";
|
||||
}
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), message);
|
||||
MainUtil.sendMessage(player, message);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.COMMAND_SYNTAX, "/plot flag <set|remove|add|list|info>");
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag <set|remove|add|list|info>");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -36,9 +36,11 @@ import com.intellectualcrafters.plot.events.PlayerEnterPlotEvent;
|
||||
import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.object.BukkitPlayer;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.titles.AbstractTitle;
|
||||
import com.intellectualcrafters.plot.util.ClusterManager;
|
||||
@ -149,6 +151,10 @@ public class PlotListener {
|
||||
}
|
||||
}
|
||||
|
||||
public static void plotEntry(final PlotPlayer player, final Plot plot) {
|
||||
plotEntry(((BukkitPlayer) player).player, plot);
|
||||
}
|
||||
|
||||
public static void plotEntry(final Player player, final Plot plot) {
|
||||
if (plot.hasOwner()) {
|
||||
final Flag gamemodeFlag = FlagManager.getPlotFlag(plot, "gamemode");
|
||||
|
Loading…
Reference in New Issue
Block a user