mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 12:35:15 +01:00
Workaround for effective permission check
This commit is contained in:
parent
ea26ec628d
commit
406dd22703
@ -7,6 +7,7 @@ import com.github.intellectualsites.plotsquared.plot.object.Location;
|
|||||||
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
|
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
|
||||||
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.*;
|
import com.github.intellectualsites.plotsquared.plot.util.*;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
@ -16,8 +17,13 @@ import org.bukkit.event.Event;
|
|||||||
import org.bukkit.event.EventException;
|
import org.bukkit.event.EventException;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||||
|
import org.bukkit.permissions.Permissible;
|
||||||
|
import org.bukkit.permissions.Permission;
|
||||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||||
|
import org.bukkit.permissions.PermissionDefault;
|
||||||
import org.bukkit.plugin.RegisteredListener;
|
import org.bukkit.plugin.RegisteredListener;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -99,6 +105,8 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
return this.player.hasPermission(permission);
|
return this.player.hasPermission(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean CHECK_EFFECTIVE = true;
|
||||||
|
|
||||||
@Override public int hasPermissionRange(String stub, int range) {
|
@Override public int hasPermissionRange(String stub, int range) {
|
||||||
if (hasPermission(Captions.PERMISSION_ADMIN.s())) {
|
if (hasPermission(Captions.PERMISSION_ADMIN.s())) {
|
||||||
return Integer.MAX_VALUE;
|
return Integer.MAX_VALUE;
|
||||||
@ -117,29 +125,43 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
return Integer.MAX_VALUE;
|
return Integer.MAX_VALUE;
|
||||||
}
|
}
|
||||||
int max = 0;
|
int max = 0;
|
||||||
String stubPlus = stub + ".";
|
if (CHECK_EFFECTIVE) {
|
||||||
Set<PermissionAttachmentInfo> effective = player.getEffectivePermissions();
|
boolean hasAny = false;
|
||||||
if (!effective.isEmpty()) {
|
String stubPlus = stub + ".";
|
||||||
for (PermissionAttachmentInfo attach : effective) {
|
Set<PermissionAttachmentInfo> effective = player.getEffectivePermissions();
|
||||||
String perm = attach.getPermission();
|
if (!effective.isEmpty()) {
|
||||||
if (perm.startsWith(stubPlus)) {
|
for (PermissionAttachmentInfo attach : effective) {
|
||||||
String end = perm.substring(stubPlus.length());
|
String permStr = attach.getPermission();
|
||||||
if (MathMan.isInteger(end)) {
|
if (permStr.startsWith(stubPlus)) {
|
||||||
int val = Integer.parseInt(end);
|
hasAny = true;
|
||||||
if (val > range) {
|
String end = permStr.substring(stubPlus.length());
|
||||||
return val;
|
if (MathMan.isInteger(end)) {
|
||||||
}
|
int val = Integer.parseInt(end);
|
||||||
if (val > max) {
|
if (val > range) {
|
||||||
max = val;
|
return val;
|
||||||
|
}
|
||||||
|
if (val > max) {
|
||||||
|
max = val;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (hasAny) {
|
||||||
} else {
|
return max;
|
||||||
for (int i = range; i > 0; i--) {
|
|
||||||
if (hasPermission(stub + "." + i)) {
|
|
||||||
return i;
|
|
||||||
}
|
}
|
||||||
|
// Workaround
|
||||||
|
for (PermissionAttachmentInfo attach : effective) {
|
||||||
|
String permStr = attach.getPermission();
|
||||||
|
Permission perm = Bukkit.getPluginManager().getPermission(permStr);
|
||||||
|
@NotNull PermissionDefault def = perm.getDefault();
|
||||||
|
if (!def.getValue(false)) return max;
|
||||||
|
}
|
||||||
|
CHECK_EFFECTIVE = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = range; i > 0; i--) {
|
||||||
|
if (hasPermission(stub + "." + i)) {
|
||||||
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return max;
|
return max;
|
||||||
|
Loading…
Reference in New Issue
Block a user