This commit is contained in:
boy0001 2015-02-22 17:59:29 +11:00
parent 46e2b1344e
commit 9eb1b0f6f5
2 changed files with 52 additions and 45 deletions

View File

@ -37,6 +37,7 @@ import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
public class FlagCmd extends SubCommand { public class FlagCmd extends SubCommand {
public FlagCmd() { public FlagCmd() {
@ -53,102 +54,102 @@ public class FlagCmd extends SubCommand {
* plot flag list * plot flag list
*/ */
if (args.length == 0) { 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; return false;
} }
Location loc = player.getLocation(); Location loc = player.getLocation();
final Plot plot = MainUtil.getPlot(loc); final Plot plot = MainUtil.getPlot(loc);
if (plot == null) { if (plot == null) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NOT_IN_PLOT); MainUtil.sendMessage(player, C.NOT_IN_PLOT);
return false; return false;
} }
if (!plot.hasOwner()) { if (!plot.hasOwner()) {
sendMessage(player, C.PLOT_NOT_CLAIMED); sendMessage(player, C.PLOT_NOT_CLAIMED);
return false; return false;
} }
if (!plot.hasRights(player) && !Permissions.hasPermission(BukkitUtil.getPlayer(player), "plots.set.flag.other")) { if (!plot.isAdded(player.getUUID()) && !Permissions.hasPermission(player, "plots.set.flag.other")) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NO_PERMISSION, "plots.set.flag.other"); MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag.other");
return false; return false;
} }
switch (args[0].toLowerCase()) { switch (args[0].toLowerCase()) {
case "info": { case "info": {
if (!Permissions.hasPermission(BukkitUtil.getPlayer(player), "plots.set.flag")) { if (!Permissions.hasPermission(player, "plots.set.flag")) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NO_PERMISSION, "plots.flag.info"); MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.info");
return false; return false;
} }
if (args.length != 2) { 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; return false;
} }
final AbstractFlag af = FlagManager.getFlag(args[1]); final AbstractFlag af = FlagManager.getFlag(args[1]);
if (af == null) { if (af == null) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NOT_VALID_FLAG); MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.COMMAND_SYNTAX, "/plot flag info <flag>"); MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info <flag>");
return false; return false;
} }
// flag key // flag key
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.FLAG_KEY, af.getKey()); MainUtil.sendMessage(player, C.FLAG_KEY, af.getKey());
// flag type // 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 // Flag type description
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.FLAG_DESC, af.getValueDesc()); MainUtil.sendMessage(player, C.FLAG_DESC, af.getValueDesc());
MainUtil.sendMessage(BukkitUtil.getPlayer(player), "&cNot implemented."); MainUtil.sendMessage(player, "&cNot implemented.");
} }
case "set": { case "set": {
if (!Permissions.hasPermission(BukkitUtil.getPlayer(player), "plots.set.flag")) { if (!Permissions.hasPermission(player, "plots.set.flag")) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NO_PERMISSION, "plots.set.flag"); MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag");
return false; return false;
} }
if (args.length < 3) { 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; return false;
} }
final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase()); final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
if (af == null) { if (af == null) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NOT_VALID_FLAG); MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
return false; return false;
} }
if (!Permissions.hasPermission(BukkitUtil.getPlayer(player), "plots.set.flag." + args[1].toLowerCase())) { if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase()); MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
return false; return false;
} }
final String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " "); final String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " ");
final Object parsed = af.parseValueRaw(value); final Object parsed = af.parseValueRaw(value);
if (parsed == null) { if (parsed == null) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), "&c" + af.getValueDesc()); MainUtil.sendMessage(player, "&c" + af.getValueDesc());
return false; return false;
} }
final Flag flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed); final Flag flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed);
final boolean result = FlagManager.addPlotFlag(plot, flag); final boolean result = FlagManager.addPlotFlag(plot, flag);
if (!result) { if (!result) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.FLAG_NOT_ADDED); MainUtil.sendMessage(player, C.FLAG_NOT_ADDED);
return false; return false;
} }
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.FLAG_ADDED); MainUtil.sendMessage(player, C.FLAG_ADDED);
PlotListener.plotEntry(player, plot); PlotListener.plotEntry(player, plot);
return true; return true;
} }
case "remove": { case "remove": {
if (!Permissions.hasPermission(BukkitUtil.getPlayer(player), "plots.flag.remove")) { if (!Permissions.hasPermission(player, "plots.flag.remove")) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NO_PERMISSION, "plots.flag.remove"); MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.remove");
return false; return false;
} }
if ((args.length != 2) && (args.length != 3)) { 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; return false;
} }
final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase()); final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
if (af == null) { if (af == null) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NOT_VALID_FLAG); MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
return false; return false;
} }
if (!Permissions.hasPermission(BukkitUtil.getPlayer(player), "plots.set.flag." + args[1].toLowerCase())) { if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase()); MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
return false; return false;
} }
final Flag flag = FlagManager.getPlotFlagAbs(plot, args[1].toLowerCase()); final Flag flag = FlagManager.getPlotFlagAbs(plot, args[1].toLowerCase());
if (flag == null) { if (flag == null) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.FLAG_NOT_IN_PLOT); MainUtil.sendMessage(player, C.FLAG_NOT_IN_PLOT);
return false; return false;
} }
if ((args.length == 3) && flag.getAbstractFlag().isList()) { if ((args.length == 3) && flag.getAbstractFlag().isList()) {
@ -158,36 +159,36 @@ public class FlagCmd extends SubCommand {
} else { } else {
final boolean result = FlagManager.removePlotFlag(plot, flag.getKey()); final boolean result = FlagManager.removePlotFlag(plot, flag.getKey());
if (!result) { if (!result) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.FLAG_NOT_REMOVED); MainUtil.sendMessage(player, C.FLAG_NOT_REMOVED);
return false; return false;
} }
} }
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.FLAG_REMOVED); MainUtil.sendMessage(player, C.FLAG_REMOVED);
PlotListener.plotEntry(player, plot); PlotListener.plotEntry(player, plot);
return true; return true;
} }
case "add": { case "add": {
if (!Permissions.hasPermission(BukkitUtil.getPlayer(player), "plots.flag.add")) { if (!Permissions.hasPermission(player, "plots.flag.add")) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NO_PERMISSION, "plots.flag.add"); MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.add");
return false; return false;
} }
if (args.length < 3) { 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; return false;
} }
final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase()); final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
if (af == null) { if (af == null) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NOT_VALID_FLAG); MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
return false; return false;
} }
if (!Permissions.hasPermission(BukkitUtil.getPlayer(player), "plots.set.flag." + args[1].toLowerCase())) { if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase()); MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
return false; return false;
} }
final String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " "); final String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " ");
final Object parsed = af.parseValueRaw(value); final Object parsed = af.parseValueRaw(value);
if (parsed == null) { if (parsed == null) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), "&c" + af.getValueDesc()); MainUtil.sendMessage(player, "&c" + af.getValueDesc());
return false; return false;
} }
Flag flag = FlagManager.getPlotFlag(plot, args[1].toLowerCase()); Flag flag = FlagManager.getPlotFlag(plot, args[1].toLowerCase());
@ -198,21 +199,21 @@ public class FlagCmd extends SubCommand {
} }
final boolean result = FlagManager.addPlotFlag(plot, flag); final boolean result = FlagManager.addPlotFlag(plot, flag);
if (!result) { if (!result) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.FLAG_NOT_ADDED); MainUtil.sendMessage(player, C.FLAG_NOT_ADDED);
return false; return false;
} }
DBFunc.setFlags(plot.world, plot, plot.settings.flags); 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); PlotListener.plotEntry(player, plot);
return true; return true;
} }
case "list": { case "list": {
if (!Permissions.hasPermission(BukkitUtil.getPlayer(player), "plots.flag.list")) { if (!Permissions.hasPermission(player, "plots.flag.list")) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NO_PERMISSION, "plots.flag.list"); MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.list");
return false; return false;
} }
if (args.length != 1) { 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; return false;
} }
final HashMap<String, ArrayList<String>> flags = new HashMap<>(); 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), ", "); message += prefix + "&6" + flag + ": &7" + StringUtils.join(flags.get(flag), ", ");
prefix = "\n"; prefix = "\n";
} }
MainUtil.sendMessage(BukkitUtil.getPlayer(player), message); MainUtil.sendMessage(player, message);
return true; 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; return false;
} }
} }

View File

@ -36,9 +36,11 @@ import com.intellectualcrafters.plot.events.PlayerEnterPlotEvent;
import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent; import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.BukkitPlayer;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.titles.AbstractTitle; import com.intellectualcrafters.plot.titles.AbstractTitle;
import com.intellectualcrafters.plot.util.ClusterManager; 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) { public static void plotEntry(final Player player, final Plot plot) {
if (plot.hasOwner()) { if (plot.hasOwner()) {
final Flag gamemodeFlag = FlagManager.getPlotFlag(plot, "gamemode"); final Flag gamemodeFlag = FlagManager.getPlotFlag(plot, "gamemode");