mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-23 05:36:45 +01:00
experimental permission caching
This commit is contained in:
parent
9a41a989de
commit
28dcfaa849
@ -12,6 +12,7 @@ import com.intellectualcrafters.plot.BukkitMain;
|
||||
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.bukkit.BukkitPlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
|
||||
@ -23,6 +24,7 @@ public class PlayerEvents_1_8 extends PlotListener implements Listener {
|
||||
final Location l = BukkitUtil.getLocation(e.getRightClicked().getLocation());
|
||||
if (isPlotWorld(l)) {
|
||||
final Player p = e.getPlayer();
|
||||
PlotPlayer PlotPlayer = BukkitUtil.getPlayer(e.getPlayer());
|
||||
if (!isInPlot(l)) {
|
||||
if (!BukkitMain.hasPermission(p, "plots.admin.interact.road")) {
|
||||
BukkitPlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.interact.road");
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.intellectualcrafters.plot.object;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
@ -12,6 +13,9 @@ public class BukkitPlayer implements PlotPlayer {
|
||||
public final Player player;
|
||||
UUID uuid;
|
||||
String name;
|
||||
private HashSet<String> hasPerm;
|
||||
private HashSet<String> noPerm;
|
||||
private int op = 0;
|
||||
|
||||
|
||||
public BukkitPlayer(Player player, String name, UUID uuid) {
|
||||
@ -39,7 +43,19 @@ public class BukkitPlayer implements PlotPlayer {
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String perm) {
|
||||
return player.hasPermission(perm);
|
||||
if (noPerm.contains(perm)) {
|
||||
return false;
|
||||
}
|
||||
if (hasPerm.contains(perm)) {
|
||||
return true;
|
||||
}
|
||||
boolean result = player.hasPermission(perm);
|
||||
if (!result) {
|
||||
noPerm.add(perm);
|
||||
return false;
|
||||
}
|
||||
hasPerm.add(perm);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -55,7 +71,19 @@ public class BukkitPlayer implements PlotPlayer {
|
||||
|
||||
@Override
|
||||
public boolean isOp() {
|
||||
return this.player.isOp();
|
||||
if (this.op != 0) {
|
||||
if (this.op == 1) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
boolean result = this.player.isOp();
|
||||
if (!result) {
|
||||
this.op = 1;
|
||||
return false;
|
||||
}
|
||||
this.op = 2;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1022,8 +1022,8 @@ public class MainUtil {
|
||||
* @param p
|
||||
* @return
|
||||
*/
|
||||
public static int getAllowedPlots(final PlotPlayer p) {
|
||||
return Permissions.hasPermissionRange(p, "plots.plot", Settings.MAX_PLOTS);
|
||||
public static int getAllowedPlots(final PlotPlayer p, int current) {
|
||||
return Permissions.hasPermissionRange(p, "plots.plot", Settings.MAX_PLOTS, current);
|
||||
}
|
||||
|
||||
public static Plot getPlot(final Location loc) {
|
||||
|
@ -36,14 +36,14 @@ public class Permissions {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int hasPermissionRange(final PlotPlayer player, final String stub, final int range) {
|
||||
public static int hasPermissionRange(final PlotPlayer player, final String stub, final int range, final int min) {
|
||||
if ((player == null) || player.isOp() || player.hasPermission(ADMIN)) {
|
||||
return Byte.MAX_VALUE;
|
||||
}
|
||||
if (player.hasPermission(stub + ".*")) {
|
||||
return Byte.MAX_VALUE;
|
||||
}
|
||||
for (int i = range; i > 0; i--) {
|
||||
for (int i = min; i < range; i++) {
|
||||
if (player.hasPermission(stub + "." + i)) {
|
||||
return i;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user