This commit is contained in:
Jesse Boyd 2016-05-19 18:53:07 +10:00
parent 7873bcf592
commit 6bad640cec
10 changed files with 197 additions and 310 deletions

View File

@ -8,9 +8,10 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
import java.util.Iterator;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
@CommandDeclaration( @CommandDeclaration(
@ -42,32 +43,35 @@ public class Add extends SubCommand {
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS); MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return true; return true;
} }
UUID uuid; Set<UUID> uuids = MainUtil.getUUIDsFromString(args[0]);
if (args[0].equalsIgnoreCase("*") && (Permissions.hasPermission(plr, "plots.add.everyone") || Permissions.hasPermission(plr, "plots.admin.command.add"))) { if (uuids == null || uuids.isEmpty()) {
uuid = DBFunc.everyone;
} else {
// TODO have a runnable for fetch
uuid = UUIDHandler.getUUID(args[0], null);
}
if (uuid == null) {
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]); MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false; return false;
} }
if (plot.isOwner(uuid)) { Iterator<UUID> iter = uuids.iterator();
MainUtil.sendMessage(plr, C.ALREADY_OWNER); while (iter.hasNext()) {
return false; UUID uuid = iter.next();
if (uuid == DBFunc.everyone && !(Permissions.hasPermission(plr, "plots.add.everyone") || Permissions.hasPermission(plr, "plots.admin.command.add"))) {
MainUtil.sendMessage(plr, C.INVALID_PLAYER, MainUtil.getName(uuid));
continue;
}
if (plot.isOwner(uuid)) {
MainUtil.sendMessage(plr, C.ALREADY_OWNER, MainUtil.getName(uuid));
iter.remove();
continue;
} }
if (plot.getMembers().contains(uuid)) { if (plot.getMembers().contains(uuid)) {
MainUtil.sendMessage(plr, C.ALREADY_ADDED); MainUtil.sendMessage(plr, C.ALREADY_ADDED, MainUtil.getName(uuid));
return false; iter.remove();
continue;
} }
if (plot.removeTrusted(uuid)) { if (plot.removeTrusted(uuid)) {
plot.addMember(uuid); plot.addMember(uuid);
} else { } else {
if ((plot.getMembers().size() + plot.getTrusted().size()) >= plot.getArea().MAX_PLOT_MEMBERS) { if ((plot.getMembers().size() + plot.getTrusted().size()) >= plot.getArea().MAX_PLOT_MEMBERS) {
MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS); MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS);
return false; iter.remove();
continue;
} }
if (plot.getDenied().contains(uuid)) { if (plot.getDenied().contains(uuid)) {
plot.removeDenied(uuid); plot.removeDenied(uuid);
@ -75,7 +79,10 @@ public class Add extends SubCommand {
plot.addMember(uuid); plot.addMember(uuid);
} }
EventUtil.manager.callMember(plr, plot, uuid, true); EventUtil.manager.callMember(plr, plot, uuid, true);
}
if (!uuids.isEmpty()) {
MainUtil.sendMessage(plr, C.MEMBER_ADDED); MainUtil.sendMessage(plr, C.MEMBER_ADDED);
}
return true; return true;
} }
} }

View File

@ -14,7 +14,8 @@ import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
import java.util.UUID; import java.util.*;
import java.util.Set;
@CommandDeclaration(command = "deny", @CommandDeclaration(command = "deny",
aliases = {"d", "ban"}, aliases = {"d", "ban"},
@ -44,30 +45,31 @@ public class Deny extends SubCommand {
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS); MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return true; return true;
} }
UUID uuid; Set<UUID> uuids = MainUtil.getUUIDsFromString(args[0]);
if (args[0].equalsIgnoreCase("*")) { if (uuids == null || uuids.isEmpty()) {
uuid = DBFunc.everyone;
} else {
uuid = UUIDHandler.getUUID(args[0], null);
}
if (uuid == null) {
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]); MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false; return false;
} }
Iterator<UUID> iter = uuids.iterator();
while (iter.hasNext()) {
UUID uuid = iter.next();
if (uuid == DBFunc.everyone && !(Permissions.hasPermission(plr, "plots.deny.everyone") || Permissions.hasPermission(plr, "plots.admin.command.deny"))) {
MainUtil.sendMessage(plr, C.INVALID_PLAYER, MainUtil.getName(uuid));
continue;
}
if (plot.isOwner(uuid)) { if (plot.isOwner(uuid)) {
MainUtil.sendMessage(plr, C.ALREADY_OWNER); MainUtil.sendMessage(plr, C.ALREADY_OWNER, MainUtil.getName(uuid));
return false; return false;
} }
if (plot.getDenied().contains(uuid)) { if (plot.getDenied().contains(uuid)) {
MainUtil.sendMessage(plr, C.ALREADY_ADDED); MainUtil.sendMessage(plr, C.ALREADY_ADDED, MainUtil.getName(uuid));
return false; return false;
} }
plot.removeMember(uuid); plot.removeMember(uuid);
plot.removeTrusted(uuid); plot.removeTrusted(uuid);
plot.addDenied(uuid); plot.addDenied(uuid);
EventUtil.manager.callDenied(plr, plot, uuid, true); EventUtil.manager.callDenied(plr, plot, uuid, true);
MainUtil.sendMessage(plr, C.DENIED_ADDED);
if (!uuid.equals(DBFunc.everyone)) { if (!uuid.equals(DBFunc.everyone)) {
handleKick(UUIDHandler.getPlayer(uuid), plot); handleKick(UUIDHandler.getPlayer(uuid), plot);
} else { } else {
@ -75,6 +77,10 @@ public class Deny extends SubCommand {
handleKick(pp, plot); handleKick(pp, plot);
} }
} }
}
if (!uuids.isEmpty()) {
MainUtil.sendMessage(plr, C.DENIED_ADDED);
}
return true; return true;
} }

View File

@ -1,6 +1,7 @@
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc;
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.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
@ -10,6 +11,9 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.WorldUtil; import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
@CommandDeclaration(command = "kick", @CommandDeclaration(command = "kick",
aliases = {"k"}, aliases = {"k"},
@ -35,11 +39,28 @@ public class Kick extends SubCommand {
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS); MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false; return false;
} }
PlotPlayer player = UUIDHandler.getPlayer(args[0]); Set<UUID> uuids = MainUtil.getUUIDsFromString(args[0]);
if (player == null) { if (uuids == null) {
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]); MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false; return false;
} }
Set<PlotPlayer> players = new HashSet<>();
for (UUID uuid : uuids) {
if (uuid == DBFunc.everyone) {
players.addAll(plot.getPlayersInPlot());
break;
}
PlotPlayer pp = UUIDHandler.getPlayer(uuid);
if (pp != null) {
players.add(pp);
}
}
players.remove(plr); // Don't ever kick the calling player
if (players.isEmpty()) {
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false;
}
for (PlotPlayer player : players) {
Location location2 = player.getLocation(); Location location2 = player.getLocation();
if (!plr.getLocation().getWorld().equals(location2.getWorld()) || !plot.equals(location2.getPlot())) { if (!plr.getLocation().getWorld().equals(location2.getWorld()) || !plot.equals(location2.getPlot())) {
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]); MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
@ -62,6 +83,7 @@ public class Kick extends SubCommand {
} else { } else {
player.teleport(spawn); player.teleport(spawn);
} }
}
return true; return true;
} }
} }

View File

@ -61,9 +61,7 @@ public class MainCommand extends Command {
new Trust(); new Trust();
new Add(); new Add();
new Deny(); new Deny();
new Untrust();
new Remove(); new Remove();
new Undeny();
new Info(); new Info();
new ListCmd(); new ListCmd();
new Debug(); new Debug();

View File

@ -10,13 +10,12 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
import java.util.ArrayList; import java.util.*;
import java.util.HashSet; import java.util.Set;
import java.util.UUID;
@CommandDeclaration( @CommandDeclaration(
command = "remove", command = "remove",
aliases = {"r"}, aliases = {"r","untrust", "ut", "undeny", "ud"},
description = "Remove a player from a plot", description = "Remove a player from a plot",
usage = "/plot remove <player>", usage = "/plot remove <player>",
category = CommandCategory.SETTINGS, category = CommandCategory.SETTINGS,
@ -64,25 +63,10 @@ public class Remove extends SubCommand {
} }
break; break;
} }
case "*":
ArrayList<UUID> toRemove = new ArrayList<>();
HashSet<UUID> all = new HashSet<>();
all.addAll(plot.getMembers());
all.addAll(plot.getTrusted());
all.addAll(plot.getDenied());
for (UUID uuid : all) {
toRemove.add(uuid);
count++;
}
for (UUID uuid : toRemove) {
plot.removeDenied(uuid);
plot.removeTrusted(uuid);
plot.removeMember(uuid);
}
break;
default: default:
UUID uuid = UUIDHandler.getUUID(args[0], null); Set<UUID> uuids = MainUtil.getUUIDsFromString(args[0]);
if (uuid != null) { if (uuids != null) {
for (UUID uuid : uuids) {
if (plot.getTrusted().contains(uuid)) { if (plot.getTrusted().contains(uuid)) {
if (plot.removeTrusted(uuid)) { if (plot.removeTrusted(uuid)) {
count++; count++;
@ -97,6 +81,7 @@ public class Remove extends SubCommand {
} }
} }
} }
}
break; break;
} }
if (count == 0) { if (count == 0) {

View File

@ -8,10 +8,10 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
import java.util.UUID; import java.util.*;
import java.util.Set;
@CommandDeclaration( @CommandDeclaration(
command = "trust", command = "trust",
@ -41,30 +41,32 @@ public class Trust extends SubCommand {
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS); MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return true; return true;
} }
UUID uuid; Set<UUID> uuids = MainUtil.getUUIDsFromString(args[0]);
if (args[0].equalsIgnoreCase("*") && (Permissions.hasPermission(plr, "plots.trust.everyone") || Permissions.hasPermission(plr, "plots.admin.command.trust"))) { if (uuids == null || uuids.isEmpty()) {
uuid = DBFunc.everyone;
} else {
uuid = UUIDHandler.getUUID(args[0], null);
}
if (uuid == null) {
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]); MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false; return false;
} }
Iterator<UUID> iter = uuids.iterator();
while (iter.hasNext()) {
UUID uuid = iter.next();
if (uuid == DBFunc.everyone && !(Permissions.hasPermission(plr, "plots.trust.everyone") || Permissions.hasPermission(plr, "plots.admin.command.trust"))) {
MainUtil.sendMessage(plr, C.INVALID_PLAYER, MainUtil.getName(uuid));
continue;
}
if (plot.isOwner(uuid)) { if (plot.isOwner(uuid)) {
MainUtil.sendMessage(plr, C.ALREADY_OWNER); MainUtil.sendMessage(plr, C.ALREADY_OWNER, MainUtil.getName(uuid));
return false; continue;
} }
if (plot.getTrusted().contains(uuid)) { if (plot.getTrusted().contains(uuid)) {
MainUtil.sendMessage(plr, C.ALREADY_ADDED); MainUtil.sendMessage(plr, C.ALREADY_ADDED, MainUtil.getName(uuid));
return false; continue;
} }
if (plot.removeMember(uuid)) { if (plot.removeMember(uuid)) {
plot.addTrusted(uuid); plot.addTrusted(uuid);
} else { } else {
if ((plot.getMembers().size() + plot.getTrusted().size()) >= plot.getArea().MAX_PLOT_MEMBERS) { if ((plot.getMembers().size() + plot.getTrusted().size()) >= plot.getArea().MAX_PLOT_MEMBERS) {
MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS); MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS);
return false; continue;
} }
if (plot.getDenied().contains(uuid)) { if (plot.getDenied().contains(uuid)) {
plot.removeDenied(uuid); plot.removeDenied(uuid);
@ -72,7 +74,10 @@ public class Trust extends SubCommand {
plot.addTrusted(uuid); plot.addTrusted(uuid);
} }
EventUtil.manager.callTrusted(plr, plot, uuid, true); EventUtil.manager.callTrusted(plr, plot, uuid, true);
}
if (!uuids.isEmpty()) {
MainUtil.sendMessage(plr, C.TRUSTED_ADDED); MainUtil.sendMessage(plr, C.TRUSTED_ADDED);
}
return true; return true;
} }
} }

View File

@ -1,82 +0,0 @@
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C;
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;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
import java.util.ArrayList;
import java.util.UUID;
@CommandDeclaration(
command = "undeny",
aliases = {"ud"},
description = "Remove a denied user from a plot",
usage = "/plot undeny <player>",
requiredType = RequiredType.PLAYER,
category = CommandCategory.SETTINGS)
public class Undeny extends SubCommand {
public Undeny() {
super(Argument.PlayerName);
}
@Override
public boolean onCommand(PlotPlayer plr, String[] args) {
Location loc = plr.getLocation();
Plot plot = loc.getPlotAbs();
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if (!plot.hasOwner()) {
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.undeny")) {
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return true;
}
int count = 0;
switch (args[0]) {
case "unknown":
ArrayList<UUID> toRemove = new ArrayList<>();
for (UUID uuid : plot.getDenied()) {
if (UUIDHandler.getName(uuid) == null) {
toRemove.add(uuid);
}
}
for (UUID uuid : toRemove) {
plot.removeDenied(uuid);
count++;
}
break;
case "*":
for (UUID uuid : new ArrayList<>(plot.getDenied())) {
plot.removeDenied(uuid);
count++;
}
break;
default:
UUID uuid = UUIDHandler.getUUID(args[0], null);
if (uuid != null) {
if (plot.removeDenied(uuid)) {
count++;
}
}
break;
}
if (count == 0) {
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false;
} else {
MainUtil.sendMessage(plr, C.REMOVED_PLAYERS, count + "");
}
return true;
}
}

View File

@ -1,84 +0,0 @@
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C;
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;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
import java.util.ArrayList;
import java.util.UUID;
// UNTRUST("untrust", "ut"),
@CommandDeclaration(
command = "untrust",
aliases = {"ut"},
permission = "plots.untrust",
description = "Remove a trusted user from a plot",
usage = "/plot untrust <player>",
requiredType = RequiredType.PLAYER,
category = CommandCategory.SETTINGS)
public class Untrust extends SubCommand {
public Untrust() {
super(Argument.PlayerName);
}
@Override
public boolean onCommand(PlotPlayer plr, String[] args) {
Location loc = plr.getLocation();
Plot plot = loc.getPlotAbs();
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if (!plot.hasOwner()) {
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.untrust")) {
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return true;
}
int count = 0;
switch (args[0]) {
case "unknown":
ArrayList<UUID> toRemove = new ArrayList<>();
for (UUID uuid : plot.getTrusted()) {
if (UUIDHandler.getName(uuid) == null) {
toRemove.add(uuid);
}
}
for (UUID uuid : toRemove) {
plot.removeTrusted(uuid);
count++;
}
break;
case "*":
for (UUID uuid : new ArrayList<>(plot.getTrusted())) {
plot.removeTrusted(uuid);
count++;
}
break;
default:
UUID uuid = UUIDHandler.getUUID(args[0], null);
if (uuid != null) {
if (plot.removeTrusted(uuid)) {
count++;
}
}
break;
}
if (count == 0) {
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false;
} else {
MainUtil.sendMessage(plr, C.REMOVED_PLAYERS, count + "");
}
return true;
}
}

View File

@ -574,8 +574,8 @@ public enum C {
* Member * Member
*/ */
REMOVED_PLAYERS("$2Removed %s players from this plot.", "Member"), REMOVED_PLAYERS("$2Removed %s players from this plot.", "Member"),
ALREADY_OWNER("$2That user is already the plot owner.", "Member"), ALREADY_OWNER("$2That user is already the plot owner: %s0", "Member"),
ALREADY_ADDED("$2That user is already added to that category.", "Member"), ALREADY_ADDED("$2That user is already added to that category: %s0", "Member"),
MEMBER_ADDED("$4That user can now build while the plot owner is online", "Member"), MEMBER_ADDED("$4That user can now build while the plot owner is online", "Member"),
MEMBER_REMOVED("$1You successfully removed a user from the plot", "Member"), MEMBER_REMOVED("$1You successfully removed a user from the plot", "Member"),
MEMBER_WAS_NOT_ADDED("$2That player was not added as a user on this plot", "Member"), MEMBER_WAS_NOT_ADDED("$2That player was not added as a user on this plot", "Member"),

View File

@ -19,7 +19,6 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.RunnableVal;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
@ -35,9 +34,11 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -692,6 +693,35 @@ public class MainUtil {
return ratings; return ratings;
} }
public static Set<UUID> getUUIDsFromString(String list) {
String[] split = list.split(",");
HashSet<UUID> result = new HashSet<UUID>();
for (String name : split) {
if (name.length() == 0) {
// Invalid
return null;
}
if (name.equals("*")) {
result.add(DBFunc.everyone);
continue;
}
if (name.length() > 16) {
try {
result.add(UUID.fromString(name));
continue;
} catch (IllegalArgumentException e) {
return null;
}
}
UUID uuid = UUIDHandler.getUUID(name, null);
if (uuid == null) {
return null;
}
result.add(uuid);
}
return result;
}
/** /**
* Format a string with plot information. * Format a string with plot information.
* @param info * @param info