Improvement PermissionCache & Remove tracking for Piston Retractions

Signed-off-by: Jadon Fowler <j@jadon.io>
This commit is contained in:
Jadon Fowler 2019-04-16 16:51:33 -04:00
parent f4f9d91f5c
commit 713bfb8f73
No known key found for this signature in database
GPG Key ID: C7FF05F3C377725C
3 changed files with 19 additions and 9 deletions

View File

@ -18,9 +18,19 @@ public class PermissionCacheCommand extends BaseCommand {
try {
boolean value = Boolean.parseBoolean(args[1]);
if (value) {
PermissionCache.init();
if (!PermissionCache.INITIALIZED) {
PermissionCache.init();
sender.sendMessage("Permission cache is on");
} else {
sender.sendMessage("Permission cache wasn't off?");
}
} else {
PermissionCache.close();
if (PermissionCache.INITIALIZED) {
PermissionCache.close();
sender.sendMessage("Permission cache is off");
} else {
sender.sendMessage("Permission cache wasn't on?");
}
}
} catch (Exception e) {
sender.sendMessage("There was an error: " + e.getMessage());

View File

@ -34,6 +34,7 @@ public class BlockChangeListener implements Listener {
public static long F_MOVABLE_IGNORE = BlockProperties.F_LIQUID;
/** These blocks might be pushed or pulled. */
public static long F_MOVABLE = BlockProperties.F_GROUND | BlockProperties.F_SOLID;
public static boolean PISTON_TRACKING = false; // Archon: We don't need to track this
private final BlockChangeTracker tracker;
private final boolean retractHasBlocks;
@ -99,17 +100,17 @@ public class BlockChangeListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPistonExtend(final BlockPistonExtendEvent event) {
if (!enabled) {
if (!enabled || !PISTON_TRACKING) {
return;
}
final BlockFace direction = event.getDirection();
//DebugUtil.debug("EXTEND event=" + event.getDirection() + " piston=" + getDirection(event.getBlock()));
//tracker.addPistonBlocks(event.getBlock().getRelative(direction), direction, event.getBlocks());
tracker.addPistonBlocks(event.getBlock().getRelative(direction), direction, event.getBlocks());
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPistonRetract(final BlockPistonRetractEvent event) {
if (!enabled) {
if (!enabled || !PISTON_TRACKING) {
return;
}
final List<Block> blocks;

View File

@ -5,7 +5,6 @@ import fr.neatmonster.nocheatplus.config.ConfigManager;
import org.bukkit.entity.Player;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
* Cache for permission checks
@ -15,13 +14,13 @@ import java.util.concurrent.ConcurrentHashMap;
*/
public class PermissionCache {
private static boolean INITIALIZED = false;
public static boolean INITIALIZED = false;
private static Set<String> PERMISSION_GROUPS;
private static Map<PermissionInfo, Boolean> PERMISSION_CACHE;
public static void init() {
INITIALIZED = true;
PERMISSION_CACHE = new ConcurrentHashMap<PermissionInfo, Boolean>();
PERMISSION_CACHE = new HashMap<>();
List<String> permissionPolicies = ConfigManager.getConfigFile().getStringList("permission-policy");
PERMISSION_GROUPS = new HashSet<>();
PERMISSION_GROUPS.addAll(permissionPolicies);
@ -35,7 +34,7 @@ public class PermissionCache {
public static boolean hasPermission(Player player, String permission) {
for (String permissionGroup : PERMISSION_GROUPS) {
if (permission.startsWith(permissionGroup)) {
PermissionInfo info = new PermissionInfo(player.getUniqueId(), permission);
PermissionInfo info = new PermissionInfo(player.getUniqueId(), permissionGroup);
return PERMISSION_CACHE.computeIfAbsent(info, (i) -> player.hasPermission(permission));
}
}