Remove usage of the now-redundant ExtractedContexts class, other misc cleanup

This commit is contained in:
Luck
2017-10-15 14:23:51 +01:00
Unverified
parent 28961b1cfa
commit b26fc69e73
56 changed files with 443 additions and 487 deletions
@@ -59,7 +59,7 @@ public class LPBukkitScheduler implements LuckPermsScheduler {
@Setter
private boolean useBukkitAsync = false;
private Set<BukkitTask> tasks = ConcurrentHashMap.newKeySet();
private final Set<BukkitTask> tasks = ConcurrentHashMap.newKeySet();
public LPBukkitScheduler(LPBukkitPlugin plugin) {
this.plugin = plugin;
@@ -55,15 +55,17 @@ public class Injector {
*
* This field is where the permissible is stored on a HumanEntity.
*/
private static Field humanEntityPermissibleField;
private static final Field HUMAN_ENTITY_PERMISSIBLE_FIELD;
/**
* The field where attachments are stored on a permissible base.
*/
private static Field permissibleBaseAttachmentsField;
private static final Field PERMISSIBLE_BASE_ATTACHMENTS_FIELD;
private static Throwable cachedThrowable = null;
static {
Field humanEntityPermissibleField;
Field permissibleBaseAttachmentsField;
try {
// Catch all. If this setup doesn't fully complete without
// exceptions, then the Injector will not work.
@@ -85,9 +87,11 @@ public class Injector {
permissibleBaseAttachmentsField.setAccessible(true);
} catch (Throwable t) {
cachedThrowable = t;
t.printStackTrace();
throw new RuntimeException("Injector did not init successfully.", t);
}
HUMAN_ENTITY_PERMISSIBLE_FIELD = humanEntityPermissibleField;
PERMISSIBLE_BASE_ATTACHMENTS_FIELD = permissibleBaseAttachmentsField;
}
/**
@@ -99,13 +103,8 @@ public class Injector {
*/
public static void inject(Player player, LPPermissible newPermissible) throws Exception {
// make sure the class inited without errors, otherwise, print a trace
if (cachedThrowable != null) {
throw new RuntimeException("Injector did not init successfully.", cachedThrowable);
}
// get the existing PermissibleBase held by the player
PermissibleBase oldPermissible = (PermissibleBase) humanEntityPermissibleField.get(player);
PermissibleBase oldPermissible = (PermissibleBase) HUMAN_ENTITY_PERMISSIBLE_FIELD.get(player);
// seems we have already injected into this player.
if (oldPermissible instanceof LPPermissible) {
@@ -115,7 +114,7 @@ public class Injector {
// Move attachments over from the old permissible
//noinspection unchecked
List<PermissionAttachment> attachments = (List<PermissionAttachment>) permissibleBaseAttachmentsField.get(oldPermissible);
List<PermissionAttachment> attachments = (List<PermissionAttachment>) PERMISSIBLE_BASE_ATTACHMENTS_FIELD.get(oldPermissible);
newPermissible.addAttachments(attachments);
attachments.clear();
@@ -128,7 +127,7 @@ public class Injector {
newPermissible.updateSubscriptionsAsync();
// inject the new instance
humanEntityPermissibleField.set(player, newPermissible);
HUMAN_ENTITY_PERMISSIBLE_FIELD.set(player, newPermissible);
// register the injection with the map
INJECTED_PERMISSIBLES.put(player.getUniqueId(), newPermissible);
@@ -143,13 +142,9 @@ public class Injector {
* @throws Exception propagates any exceptions which were thrown during uninjection
*/
public static void unInject(Player player, boolean dummy, boolean unsubscribe) throws Exception {
// make sure the class inited without errors, otherwise, print a trace
if (cachedThrowable != null) {
throw new RuntimeException("Injector did not init successfully.", cachedThrowable);
}
// gets the players current permissible.
PermissibleBase permissible = (PermissibleBase) humanEntityPermissibleField.get(player);
PermissibleBase permissible = (PermissibleBase) HUMAN_ENTITY_PERMISSIBLE_FIELD.get(player);
// only uninject if the permissible was a luckperms one.
if (permissible instanceof LPPermissible) {
@@ -169,7 +164,7 @@ public class Injector {
// handle the replacement permissible.
if (dummy) {
// just inject a dummy class. this is used when we know the player is about to quit the server.
humanEntityPermissibleField.set(player, new DummyPermissibleBase());
HUMAN_ENTITY_PERMISSIBLE_FIELD.set(player, new DummyPermissibleBase());
} else {
// otherwise, inject the permissible they had when we first injected.
@@ -182,11 +177,11 @@ public class Injector {
}
//noinspection unchecked
List<PermissionAttachment> newPbAttachments = (List<PermissionAttachment>) permissibleBaseAttachmentsField.get(newPb);
List<PermissionAttachment> newPbAttachments = (List<PermissionAttachment>) PERMISSIBLE_BASE_ATTACHMENTS_FIELD.get(newPb);
newPbAttachments.addAll(lpAttachments);
lpAttachments.clear();
humanEntityPermissibleField.set(player, newPb);
HUMAN_ENTITY_PERMISSIBLE_FIELD.set(player, newPb);
}
}
@@ -41,7 +41,7 @@ import java.util.concurrent.ConcurrentHashMap;
@RequiredArgsConstructor
public class ChildProcessor implements PermissionProcessor {
private final ChildPermissionProvider provider;
private Map<String, Boolean> childPermissions = new ConcurrentHashMap<>();
private final Map<String, Boolean> childPermissions = new ConcurrentHashMap<>();
@Override
public Tristate hasPermission(String permission) {
@@ -32,7 +32,6 @@ import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.api.caching.MetaData;
import me.lucko.luckperms.common.caching.MetaAccumulator;
import me.lucko.luckperms.common.contexts.ExtractedContexts;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.model.User;
@@ -284,7 +283,7 @@ public class VaultChatHook extends Chat {
holder.removeIf(type::matches);
// find the max inherited priority & add 10
MetaAccumulator metaAccumulator = holder.accumulateMeta(null, null, ExtractedContexts.generate(perms.createContextForWorldSet(finalWorld)));
MetaAccumulator metaAccumulator = holder.accumulateMeta(null, null, perms.createContextForWorldSet(finalWorld));
int priority = (type == ChatMetaType.PREFIX ? metaAccumulator.getPrefixes() : metaAccumulator.getSuffixes()).keySet().stream()
.mapToInt(e -> e).max().orElse(0) + 10;
@@ -355,8 +354,8 @@ public class VaultChatHook extends Chat {
int priority = Integer.MIN_VALUE;
String meta = null;
ExtractedContexts ec = ExtractedContexts.generate(Contexts.of(perms.createContextForWorldLookup(world).getContexts(), perms.isIncludeGlobal(), true, true, true, true, false));
for (Node n : group.getAllNodes(ec)) {
Contexts contexts = Contexts.of(perms.createContextForWorldLookup(world).getContexts(), perms.isIncludeGlobal(), true, true, true, true, false);
for (Node n : group.getAllNodes(contexts)) {
if (!n.getValuePrimitive()) continue;
if (type.shouldIgnore(n)) continue;
if (!n.shouldApplyWithContext(perms.createContextForWorldLookup(world).getContexts())) continue;
@@ -37,7 +37,6 @@ import me.lucko.luckperms.api.context.MutableContextSet;
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
import me.lucko.luckperms.common.caching.PermissionCache;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.contexts.ExtractedContexts;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.model.User;
@@ -226,7 +225,7 @@ public class VaultPermissionHook extends Permission {
if (group == null) return false;
// This is a nasty call. Groups aren't cached. :(
Map<String, Boolean> permissions = group.exportNodesAndShorthand(ExtractedContexts.generate(createContextForWorldLookup(world)), true);
Map<String, Boolean> permissions = group.exportNodesAndShorthand(createContextForWorldLookup(world), true);
return permissions.containsKey(permission.toLowerCase()) && permissions.get(permission.toLowerCase());
}