use of cn.nukkit.permission.Permission in project LuckPerms by lucko.
the class InjectorDefaultsMap method inject.
private LPDefaultsMap inject() throws Exception {
Objects.requireNonNull(OP_DEFAULT_PERMISSIONS_FIELD, "OP_DEFAULT_PERMISSIONS_FIELD");
Objects.requireNonNull(NON_OP_DEFAULT_PERMISSIONS_FIELD, "NON_OP_DEFAULT_PERMISSIONS_FIELD");
PluginManager pluginManager = this.plugin.getBootstrap().getServer().getPluginManager();
Object opMap = OP_DEFAULT_PERMISSIONS_FIELD.get(pluginManager);
Object nonOpMap = NON_OP_DEFAULT_PERMISSIONS_FIELD.get(pluginManager);
if (opMap instanceof LPDefaultsMap.DefaultPermissionSet && ((LPDefaultsMap.DefaultPermissionSet) opMap).parent.plugin == this.plugin) {
if (nonOpMap instanceof LPDefaultsMap.DefaultPermissionSet && ((LPDefaultsMap.DefaultPermissionSet) nonOpMap).parent.plugin == this.plugin) {
return null;
}
}
// noinspection unchecked
Map<String, Permission> castedOpMap = (Map<String, Permission>) opMap;
// noinspection unchecked
Map<String, Permission> castedNonOpMap = (Map<String, Permission>) nonOpMap;
// make a new map & inject it
LPDefaultsMap newMap = new LPDefaultsMap(this.plugin, ImmutableMap.of(true, castedOpMap, false, castedNonOpMap));
OP_DEFAULT_PERMISSIONS_FIELD.set(pluginManager, newMap.getOpPermissions());
NON_OP_DEFAULT_PERMISSIONS_FIELD.set(pluginManager, newMap.getNonOpPermissions());
return newMap;
}
use of cn.nukkit.permission.Permission in project LuckPerms by lucko.
the class LPPermissionMap method resolveChildren.
private void resolveChildren(Map<String, Boolean> accumulator, Map<String, Boolean> children, boolean invert) {
// the first time this method is called for a given permission, the children map will contain only the permission itself.
for (Map.Entry<String, Boolean> e : children.entrySet()) {
if (accumulator.containsKey(e.getKey())) {
// Prevent infinite loops
continue;
}
// xor the value using the parent (nukkit logic, not mine)
boolean value = e.getValue() ^ invert;
accumulator.put(e.getKey().toLowerCase(), value);
// lookup any deeper children & resolve if present
Permission perm = this.delegate.get(e.getKey());
if (perm != null) {
resolveChildren(accumulator, perm.getChildren(), !value);
}
}
}
use of cn.nukkit.permission.Permission in project LuckPerms by lucko.
the class LPPermissionMap method putIfAbsent.
@Override
public Permission putIfAbsent(String key, Permission value) {
this.plugin.getPermissionVault().offer(key);
Permission ret = super.putIfAbsent(key, value);
update();
return ret;
}
use of cn.nukkit.permission.Permission in project LuckPerms by lucko.
the class InjectorPermissionMap method inject.
private LPPermissionMap inject() throws Exception {
Objects.requireNonNull(PERMISSIONS_FIELD, "PERMISSIONS_FIELD");
PluginManager pluginManager = this.plugin.getBootstrap().getServer().getPluginManager();
Object map = PERMISSIONS_FIELD.get(pluginManager);
if (map instanceof LPPermissionMap && ((LPPermissionMap) map).plugin == this.plugin) {
return null;
}
// noinspection unchecked
Map<String, Permission> castedMap = (Map<String, Permission>) map;
// make a new map & inject it
LPPermissionMap newMap = new LPPermissionMap(this.plugin, castedMap);
PERMISSIONS_FIELD.set(pluginManager, newMap);
return newMap;
}
use of cn.nukkit.permission.Permission in project LuckPerms by lucko.
the class LPDefaultsMap method refreshOp.
/**
* Refreshes the op data in this provider.
*/
private void refreshOp() {
Map<String, Boolean> builder = new HashMap<>();
for (Permission perm : getOpPermissions().values()) {
String name = perm.getName().toLowerCase();
builder.put(name, true);
for (Map.Entry<String, Boolean> child : this.plugin.getPermissionMap().getChildPermissions(name, true).entrySet()) {
builder.putIfAbsent(child.getKey(), child.getValue());
}
}
this.resolvedOpDefaults = ImmutableMap.copyOf(builder);
}
Aggregations