This commit is contained in:
Jesse Boyd 2018-05-17 17:46:54 +10:00
parent 4ffc4e67ab
commit 550df7f232
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
4 changed files with 84 additions and 35 deletions

View File

@ -1,14 +1,12 @@
package com.plotsquared.bukkit.object; package com.plotsquared.bukkit.object;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.*;
import com.intellectualcrafters.plot.util.PlotGameMode;
import com.intellectualcrafters.plot.util.PlotWeather;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.BukkitUtil;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Effect; import org.bukkit.Effect;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.WeatherType; import org.bukkit.WeatherType;
@ -18,6 +16,8 @@ import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import java.util.UUID; import java.util.UUID;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.RegisteredListener; import org.bukkit.plugin.RegisteredListener;
public class BukkitPlayer extends PlotPlayer { public class BukkitPlayer extends PlotPlayer {
@ -102,6 +102,40 @@ public class BukkitPlayer extends PlotPlayer {
return this.player.hasPermission(permission); return this.player.hasPermission(permission);
} }
@Override
public int hasPermissionRange(String stub, int range) {
if (hasPermission(C.PERMISSION_ADMIN.s())) {
return Integer.MAX_VALUE;
}
String[] nodes = stub.split("\\.");
StringBuilder n = new StringBuilder();
for (int i = 0; i < (nodes.length - 1); i++) {
n.append(nodes[i]).append(".");
if (!stub.equals(n + C.PERMISSION_STAR.s())) {
if (hasPermission(n + C.PERMISSION_STAR.s())) {
return Integer.MAX_VALUE;
}
}
}
if (hasPermission(stub + ".*")) {
return Integer.MAX_VALUE;
}
int max = 0;
String stubPlus = stub + ".";
for (PermissionAttachmentInfo attach : player.getEffectivePermissions()) {
String perm = attach.getPermission();
if (perm.startsWith(stubPlus)) {
String end = perm.substring(stubPlus.length());
if (MathMan.isInteger(end)) {
int val = Integer.parseInt(end);
if (val > range) return val;
if (val > max) max = val;
}
}
}
return max;
}
@Override @Override
public boolean isPermissionSet(String permission) { public boolean isPermissionSet(String permission) {
return this.player.isPermissionSet(permission); return this.player.isPermissionSet(permission);

View File

@ -10,11 +10,7 @@ import com.intellectualcrafters.plot.flag.ListFlag;
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;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.*;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.PlotWeather;
import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.StringMan;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
import java.util.ArrayList; import java.util.ArrayList;
@ -33,6 +29,21 @@ import java.util.Map;
permission = "plots.flag") permission = "plots.flag")
public class FlagCmd extends SubCommand { public class FlagCmd extends SubCommand {
private boolean checkPermValue(PlotPlayer player, String key, String value) {
key = key.toLowerCase();
value = value.toLowerCase();
String perm = C.PERMISSION_SET_FLAG_KEY_VALUE.f(key.toLowerCase(), value.toLowerCase());
if (MathMan.isInteger(value)) {
try {
int numeric = Integer.parseInt(value);
perm.substring(0, perm.length() - value.length() - 1);
return player.hasPermissionRange(perm, numeric) >= numeric;
} catch (NumberFormatException ignore) {}
}
return Permissions.hasPermission(player, perm);
}
@Override @Override
public boolean onCommand(PlotPlayer player, String[] args) { public boolean onCommand(PlotPlayer player, String[] args) {
@ -108,7 +119,7 @@ public class FlagCmd extends SubCommand {
return false; return false;
} }
String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " "); String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
if (!Permissions.hasPermission(player, C.PERMISSION_SET_FLAG_KEY_VALUE.f(args[1].toLowerCase(), value.toLowerCase()))) { if (!checkPermValue(player, args[1], value)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_SET_FLAG_KEY_VALUE.f(args[1].toLowerCase(), value.toLowerCase())); MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_SET_FLAG_KEY_VALUE.f(args[1].toLowerCase(), value.toLowerCase()));
return false; return false;
} }
@ -140,7 +151,7 @@ public class FlagCmd extends SubCommand {
return false; return false;
} }
for (String entry : args[2].split(",")) { for (String entry : args[2].split(",")) {
if (!Permissions.hasPermission(player, C.PERMISSION_SET_FLAG_KEY_VALUE.f(args[1].toLowerCase(), entry))) { if (!checkPermValue(player, args[1], entry)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_SET_FLAG_KEY_VALUE.f(args[1].toLowerCase(), entry)); MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_SET_FLAG_KEY_VALUE.f(args[1].toLowerCase(), entry));
return false; return false;
} }
@ -185,7 +196,7 @@ public class FlagCmd extends SubCommand {
return false; return false;
} }
for (String entry : args[2].split(",")) { for (String entry : args[2].split(",")) {
if (!Permissions.hasPermission(player, C.PERMISSION_SET_FLAG_KEY_VALUE.f(args[1].toLowerCase(), entry))) { if (!checkPermValue(player, args[1], entry)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_SET_FLAG_KEY_VALUE.f(args[1].toLowerCase(), entry)); MainUtil.sendMessage(player, C.NO_PERMISSION, C.PERMISSION_SET_FLAG_KEY_VALUE.f(args[1].toLowerCase(), entry));
return false; return false;
} }

View File

@ -135,6 +135,31 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
return Permissions.hasPermissionRange(this, "plots.cluster", Settings.Limit.MAX_PLOTS); return Permissions.hasPermissionRange(this, "plots.cluster", Settings.Limit.MAX_PLOTS);
} }
public int hasPermissionRange(String stub, int range) {
if (hasPermission(C.PERMISSION_ADMIN.s())) {
return Integer.MAX_VALUE;
}
String[] nodes = stub.split("\\.");
StringBuilder n = new StringBuilder();
for (int i = 0; i < (nodes.length - 1); i++) {
n.append(nodes[i]).append(".");
if (!stub.equals(n + C.PERMISSION_STAR.s())) {
if (hasPermission(n + C.PERMISSION_STAR.s())) {
return Integer.MAX_VALUE;
}
}
}
if (hasPermission(stub + ".*")) {
return Integer.MAX_VALUE;
}
for (int i = range; i > 0; i--) {
if (hasPermission(stub + "." + i)) {
return i;
}
}
return 0;
}
/** /**
* Get the number of plots this player owns. * Get the number of plots this player owns.
* *

View File

@ -116,27 +116,6 @@ public class Permissions {
* @return The highest permission they have within that range * @return The highest permission they have within that range
*/ */
public static int hasPermissionRange(PlotPlayer player, String stub, int range) { public static int hasPermissionRange(PlotPlayer player, String stub, int range) {
if (player.hasPermission(C.PERMISSION_ADMIN.s())) { return player.hasPermissionRange(stub, range);
return Integer.MAX_VALUE;
}
String[] nodes = stub.split("\\.");
StringBuilder n = new StringBuilder();
for (int i = 0; i < (nodes.length - 1); i++) {
n.append(nodes[i]).append(".");
if (!stub.equals(n + C.PERMISSION_STAR.s())) {
if (player.hasPermission(n + C.PERMISSION_STAR.s())) {
return Integer.MAX_VALUE;
}
}
}
if (player.hasPermission(stub + ".*")) {
return Integer.MAX_VALUE;
}
for (int i = range; i > 0; i--) {
if (player.hasPermission(stub + "." + i)) {
return i;
}
}
return 0;
} }
} }