From 28dcfaa8499fb8325d78a125dbcf41a3dcab3615 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Sat, 21 Feb 2015 17:42:30 +1100 Subject: [PATCH] experimental permission caching --- .../plot/listeners/PlayerEvents_1_8.java | 2 ++ .../plot/object/BukkitPlayer.java | 32 +++++++++++++++++-- .../plot/util/MainUtil.java | 4 +-- .../plot/util/Permissions.java | 4 +-- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents_1_8.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents_1_8.java index 5301f9cdd..104d670f9 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents_1_8.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents_1_8.java @@ -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"); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java index f69742be5..f07945649 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java @@ -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 hasPerm; + private HashSet 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 diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index 14d23a3f1..6cc38eecc 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -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) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/Permissions.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/Permissions.java index bbb3bc475..9b3514a29 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/Permissions.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/Permissions.java @@ -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; }