experimental permission caching

This commit is contained in:
boy0001 2015-02-21 17:42:30 +11:00
parent 9a41a989de
commit 28dcfaa849
4 changed files with 36 additions and 6 deletions

View File

@ -12,6 +12,7 @@ import com.intellectualcrafters.plot.BukkitMain;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
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.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.bukkit.BukkitPlayerFunctions; import com.intellectualcrafters.plot.util.bukkit.BukkitPlayerFunctions;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; 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()); final Location l = BukkitUtil.getLocation(e.getRightClicked().getLocation());
if (isPlotWorld(l)) { if (isPlotWorld(l)) {
final Player p = e.getPlayer(); final Player p = e.getPlayer();
PlotPlayer PlotPlayer = BukkitUtil.getPlayer(e.getPlayer());
if (!isInPlot(l)) { if (!isInPlot(l)) {
if (!BukkitMain.hasPermission(p, "plots.admin.interact.road")) { if (!BukkitMain.hasPermission(p, "plots.admin.interact.road")) {
BukkitPlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.interact.road"); BukkitPlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.interact.road");

View File

@ -1,5 +1,6 @@
package com.intellectualcrafters.plot.object; package com.intellectualcrafters.plot.object;
import java.util.HashSet;
import java.util.UUID; import java.util.UUID;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -12,6 +13,9 @@ public class BukkitPlayer implements PlotPlayer {
public final Player player; public final Player player;
UUID uuid; UUID uuid;
String name; String name;
private HashSet<String> hasPerm;
private HashSet<String> noPerm;
private int op = 0;
public BukkitPlayer(Player player, String name, UUID uuid) { public BukkitPlayer(Player player, String name, UUID uuid) {
@ -39,7 +43,19 @@ public class BukkitPlayer implements PlotPlayer {
@Override @Override
public boolean hasPermission(String perm) { 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 @Override
@ -55,7 +71,19 @@ public class BukkitPlayer implements PlotPlayer {
@Override @Override
public boolean isOp() { 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 @Override

View File

@ -1022,8 +1022,8 @@ public class MainUtil {
* @param p * @param p
* @return * @return
*/ */
public static int getAllowedPlots(final PlotPlayer p) { public static int getAllowedPlots(final PlotPlayer p, int current) {
return Permissions.hasPermissionRange(p, "plots.plot", Settings.MAX_PLOTS); return Permissions.hasPermissionRange(p, "plots.plot", Settings.MAX_PLOTS, current);
} }
public static Plot getPlot(final Location loc) { public static Plot getPlot(final Location loc) {

View File

@ -36,14 +36,14 @@ public class Permissions {
return false; 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)) { if ((player == null) || player.isOp() || player.hasPermission(ADMIN)) {
return Byte.MAX_VALUE; return Byte.MAX_VALUE;
} }
if (player.hasPermission(stub + ".*")) { if (player.hasPermission(stub + ".*")) {
return Byte.MAX_VALUE; return Byte.MAX_VALUE;
} }
for (int i = range; i > 0; i--) { for (int i = min; i < range; i++) {
if (player.hasPermission(stub + "." + i)) { if (player.hasPermission(stub + "." + i)) {
return i; return i;
} }