mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-02 08:50:17 +01:00
Fixes #1952
This commit is contained in:
parent
4ffc4e67ab
commit
550df7f232
@ -1,14 +1,12 @@
|
||||
package com.plotsquared.bukkit.object;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
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.intellectualcrafters.plot.util.*;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.WeatherType;
|
||||
@ -18,6 +16,8 @@ import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.plugin.RegisteredListener;
|
||||
|
||||
public class BukkitPlayer extends PlotPlayer {
|
||||
@ -102,6 +102,40 @@ public class BukkitPlayer extends PlotPlayer {
|
||||
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
|
||||
public boolean isPermissionSet(String permission) {
|
||||
return this.player.isPermissionSet(permission);
|
||||
|
@ -10,11 +10,7 @@ import com.intellectualcrafters.plot.flag.ListFlag;
|
||||
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.PlotWeather;
|
||||
import com.intellectualcrafters.plot.util.StringComparison;
|
||||
import com.intellectualcrafters.plot.util.StringMan;
|
||||
import com.intellectualcrafters.plot.util.*;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -33,6 +29,21 @@ import java.util.Map;
|
||||
permission = "plots.flag")
|
||||
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
|
||||
public boolean onCommand(PlotPlayer player, String[] args) {
|
||||
|
||||
@ -108,7 +119,7 @@ public class FlagCmd extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
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()));
|
||||
return false;
|
||||
}
|
||||
@ -140,7 +151,7 @@ public class FlagCmd extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
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));
|
||||
return false;
|
||||
}
|
||||
@ -185,7 +196,7 @@ public class FlagCmd extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
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));
|
||||
return false;
|
||||
}
|
||||
|
@ -135,6 +135,31 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
|
||||
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.
|
||||
*
|
||||
|
@ -116,27 +116,6 @@ public class Permissions {
|
||||
* @return The highest permission they have within that range
|
||||
*/
|
||||
public static int hasPermissionRange(PlotPlayer player, String stub, int range) {
|
||||
if (player.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 (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;
|
||||
return player.hasPermissionRange(stub, range);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user