cn.nukkit.permission.Permission Java Examples
The following examples show how to use
cn.nukkit.permission.Permission.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PluginManager.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public void disablePlugin(Plugin plugin) { if (plugin.isEnabled()) { try { plugin.getPluginLoader().disablePlugin(plugin); } catch (Exception e) { MainLogger logger = this.server.getLogger(); if (logger != null) { logger.logException(e); } } this.server.getScheduler().cancelTask(plugin); HandlerList.unregisterAll(plugin); for (Permission permission : plugin.getDescription().getPermissions()) { this.removePermission(permission); } } }
Example #2
Source File: LuckPermsPermissionMap.java From LuckPerms with MIT License | 6 votes |
private Permission inject(Permission permission) { if (permission == null) { return null; } try { //noinspection unchecked Map<String, Boolean> children = (Map<String, Boolean>) PERMISSION_CHILDREN_FIELD.get(permission); while (children instanceof PermissionNotifyingChildrenMap) { children = ((PermissionNotifyingChildrenMap) children).delegate; } PermissionNotifyingChildrenMap notifyingChildren = new PermissionNotifyingChildrenMap(children); PERMISSION_CHILDREN_FIELD.set(permission, notifyingChildren); } catch (Exception e) { e.printStackTrace(); } return permission; }
Example #3
Source File: PluginManager.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public void enablePlugin(Plugin plugin) { if (!plugin.isEnabled()) { try { for (Permission permission : plugin.getDescription().getPermissions()) { this.addPermission(permission); } plugin.getPluginLoader().enablePlugin(plugin); } catch (Throwable e) { MainLogger logger = this.server.getLogger(); if (logger != null) { logger.logException(new RuntimeException(e)); } this.disablePlugin(plugin); } } }
Example #4
Source File: PluginManager.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public void disablePlugin(Plugin plugin) { if (plugin.isEnabled()) { try { plugin.getPluginLoader().disablePlugin(plugin); } catch (Exception e) { MainLogger logger = this.server.getLogger(); if (logger != null) { logger.logException(e); } } this.server.getScheduler().cancelTask(plugin); HandlerList.unregisterAll(plugin); for (Permission permission : plugin.getDescription().getPermissions()) { this.removePermission(permission); } } }
Example #5
Source File: LuckPermsPermissionMap.java From LuckPerms with MIT License | 6 votes |
private Permission uninject(Permission permission) { if (permission == null) { return null; } try { //noinspection unchecked Map<String, Boolean> children = (Map<String, Boolean>) PERMISSION_CHILDREN_FIELD.get(permission); while (children instanceof PermissionNotifyingChildrenMap) { children = ((PermissionNotifyingChildrenMap) children).delegate; } PERMISSION_CHILDREN_FIELD.set(permission, children); } catch (Exception e) { e.printStackTrace(); } return permission; }
Example #6
Source File: LuckPermsPermissionMap.java From LuckPerms with MIT License | 6 votes |
private void resolveChildren(Map<String, Boolean> accumulator, Map<String, Boolean> children, boolean invert) { // iterate through the current known children. // 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 (e == null || e.getKey() == null || e.getValue() == null) { continue; } if (accumulator.containsKey(e.getKey())) { continue; // Prevent infinite loops } // 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); } } }
Example #7
Source File: InjectorPermissionMap.java From LuckPerms with MIT License | 6 votes |
private LuckPermsPermissionMap 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 LuckPermsPermissionMap && ((LuckPermsPermissionMap) map).plugin == this.plugin) { return null; } //noinspection unchecked Map<String, Permission> castedMap = (Map<String, Permission>) map; // make a new map & inject it LuckPermsPermissionMap newMap = new LuckPermsPermissionMap(this.plugin, castedMap); PERMISSIONS_FIELD.set(pluginManager, newMap); return newMap; }
Example #8
Source File: PluginManager.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public void enablePlugin(Plugin plugin) { if (!plugin.isEnabled()) { try { for (Permission permission : plugin.getDescription().getPermissions()) { this.addPermission(permission); } plugin.getPluginLoader().enablePlugin(plugin); } catch (Throwable e) { MainLogger logger = this.server.getLogger(); if (logger != null) { logger.logException(new RuntimeException(e)); } this.disablePlugin(plugin); } } }
Example #9
Source File: PluginManager.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public void disablePlugin(Plugin plugin) { if (plugin.isEnabled()) { try { plugin.getPluginLoader().disablePlugin(plugin); } catch (Exception e) { MainLogger logger = this.server.getLogger(); if (logger != null) { logger.logException(e); } } this.server.getScheduler().cancelTask(plugin); HandlerList.unregisterAll(plugin); for (Permission permission : plugin.getDescription().getPermissions()) { this.removePermission(permission); } } }
Example #10
Source File: PluginManager.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public void enablePlugin(Plugin plugin) { if (!plugin.isEnabled()) { try { for (Permission permission : plugin.getDescription().getPermissions()) { this.addPermission(permission); } plugin.getPluginLoader().enablePlugin(plugin); } catch (Throwable e) { MainLogger logger = this.server.getLogger(); if (logger != null) { logger.logException(new RuntimeException(e)); } this.disablePlugin(plugin); } } }
Example #11
Source File: LuckPermsPermissible.java From LuckPerms with MIT License | 6 votes |
@Override public boolean hasPermission(Permission permission) { if (permission == null) { throw new NullPointerException("permission"); } QueryOptions queryOptions = this.queryOptionsSupplier.getQueryOptions(); TristateResult result = this.user.getCachedData().getPermissionData(queryOptions).checkPermission(permission.getName(), PermissionCheckEvent.Origin.PLATFORM_PERMISSION_CHECK); // override default op handling using the Permission class we have if (result.processorClass() == OpProcessor.class && this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS)) { // 'op == true' is implied by the presence of the OpProcessor class PermissionDefault def = PermissionDefault.fromPermission(permission); if (def != null) { return def.getValue(true); } } return result.result().asBoolean(); }
Example #12
Source File: LuckPermsPermissionMap.java From LuckPerms with MIT License | 5 votes |
@Override public Permission get(@Nullable Object key) { if (key == null) { return null; } return super.get(key); }
Example #13
Source File: PluginManager.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public Map<String, Permission> getDefaultPermissions(boolean op) { if (op) { return this.defaultPermsOp; } else { return this.defaultPerms; } }
Example #14
Source File: PluginManager.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public void recalculatePermissionDefaults(Permission permission) { if (this.permissions.containsKey(permission.getName())) { this.defaultPermsOp.remove(permission.getName()); this.defaultPerms.remove(permission.getName()); this.calculatePermissionDefault(permission); } }
Example #15
Source File: PluginManager.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public Map<String, Permission> getDefaultPermissions(boolean op) { if (op) { return this.defaultPermsOp; } else { return this.defaultPerms; } }
Example #16
Source File: PluginManager.java From Nukkit with GNU General Public License v3.0 | 5 votes |
private void calculatePermissionDefault(Permission permission) { Timings.permissionDefaultTimer.startTiming(); if (permission.getDefault().equals(Permission.DEFAULT_OP) || permission.getDefault().equals(Permission.DEFAULT_TRUE)) { this.defaultPermsOp.put(permission.getName(), permission); this.dirtyPermissibles(true); } if (permission.getDefault().equals(Permission.DEFAULT_NOT_OP) || permission.getDefault().equals(Permission.DEFAULT_TRUE)) { this.defaultPerms.put(permission.getName(), permission); this.dirtyPermissibles(false); } Timings.permissionDefaultTimer.startTiming(); }
Example #17
Source File: PluginManager.java From Jupiter with GNU General Public License v3.0 | 5 votes |
private void calculatePermissionDefault(Permission permission) { Timings.permissionDefaultTimer.startTiming(); if (permission.getDefault().equals(Permission.DEFAULT_OP) || permission.getDefault().equals(Permission.DEFAULT_TRUE)) { this.defaultPermsOp.put(permission.getName(), permission); this.dirtyPermissibles(true); } if (permission.getDefault().equals(Permission.DEFAULT_NOT_OP) || permission.getDefault().equals(Permission.DEFAULT_TRUE)) { this.defaultPerms.put(permission.getName(), permission); this.dirtyPermissibles(false); } Timings.permissionDefaultTimer.startTiming(); }
Example #18
Source File: PluginManager.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public boolean addPermission(Permission permission) { if (!this.permissions.containsKey(permission.getName())) { this.permissions.put(permission.getName(), permission); this.calculatePermissionDefault(permission); return true; } return false; }
Example #19
Source File: PluginManager.java From Nukkit with GNU General Public License v3.0 | 5 votes |
private void calculatePermissionDefault(Permission permission) { Timings.permissionDefaultTimer.startTiming(); if (permission.getDefault().equals(Permission.DEFAULT_OP) || permission.getDefault().equals(Permission.DEFAULT_TRUE)) { this.defaultPermsOp.put(permission.getName(), permission); this.dirtyPermissibles(true); } if (permission.getDefault().equals(Permission.DEFAULT_NOT_OP) || permission.getDefault().equals(Permission.DEFAULT_TRUE)) { this.defaultPerms.put(permission.getName(), permission); this.dirtyPermissibles(false); } Timings.permissionDefaultTimer.startTiming(); }
Example #20
Source File: PluginManager.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public void recalculatePermissionDefaults(Permission permission) { if (this.permissions.containsKey(permission.getName())) { this.defaultPermsOp.remove(permission.getName()); this.defaultPerms.remove(permission.getName()); this.calculatePermissionDefault(permission); } }
Example #21
Source File: PluginManager.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public void recalculatePermissionDefaults(Permission permission) { if (this.permissions.containsKey(permission.getName())) { this.defaultPermsOp.remove(permission.getName()); this.defaultPerms.remove(permission.getName()); this.calculatePermissionDefault(permission); } }
Example #22
Source File: PluginManager.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public boolean addPermission(Permission permission) { if (!this.permissions.containsKey(permission.getName())) { this.permissions.put(permission.getName(), permission); this.calculatePermissionDefault(permission); return true; } return false; }
Example #23
Source File: MonitoredPermissibleBase.java From LuckPerms with MIT License | 5 votes |
@Override public boolean hasPermission(Permission permission) { if (permission == null) { throw new NullPointerException("permission"); } final boolean result = this.delegate.hasPermission(permission); logCheck(PermissionCheckEvent.Origin.PLATFORM_PERMISSION_CHECK, permission.getName(), result); return result; }
Example #24
Source File: MonitoredPermissibleBase.java From LuckPerms with MIT License | 5 votes |
@Override public boolean isPermissionSet(Permission permission) { if (permission == null) { throw new NullPointerException("permission"); } final boolean result = this.delegate.isPermissionSet(permission); logCheck(PermissionCheckEvent.Origin.PLATFORM_LOOKUP_CHECK, permission.getName(), result); return result; }
Example #25
Source File: InjectorDefaultsMap.java From LuckPerms with MIT License | 5 votes |
private LuckPermsDefaultsMap 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 LuckPermsDefaultsMap.DefaultPermissionSet && ((LuckPermsDefaultsMap.DefaultPermissionSet) opMap).parent.plugin == this.plugin) { if (nonOpMap instanceof LuckPermsDefaultsMap.DefaultPermissionSet && ((LuckPermsDefaultsMap.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 LuckPermsDefaultsMap newMap = new LuckPermsDefaultsMap(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; }
Example #26
Source File: LuckPermsPermissible.java From LuckPerms with MIT License | 5 votes |
@Override public boolean isPermissionSet(Permission permission) { if (permission == null) { throw new NullPointerException("permission"); } return isPermissionSet(permission.getName()); }
Example #27
Source File: LuckPermsDefaultsMap.java From LuckPerms with MIT License | 5 votes |
@Override protected @NonNull Map<String, Boolean> supply() { Map<String, Boolean> builder = new HashMap<>(); for (Permission perm : LuckPermsDefaultsMap.this.get(this.op).values()) { String name = perm.getName().toLowerCase(); builder.put(name, true); for (Map.Entry<String, Boolean> child : LuckPermsDefaultsMap.this.plugin.getPermissionMap().getChildPermissions(name, true).entrySet()) { builder.putIfAbsent(child.getKey(), child.getValue()); } } return ImmutableMap.copyOf(builder); }
Example #28
Source File: LuckPermsPermissionMap.java From LuckPerms with MIT License | 5 votes |
@Override public Permission put(@NonNull String key, @NonNull Permission value) { Objects.requireNonNull(key, "key"); Objects.requireNonNull(value, "value"); this.plugin.getPermissionRegistry().insert(key); Permission ret = super.put(key, inject(value)); update(); return ret; }
Example #29
Source File: LuckPermsPermissionMap.java From LuckPerms with MIT License | 5 votes |
@Override public void putAll(@NonNull Map<? extends String, ? extends Permission> m) { for (Map.Entry<? extends String, ? extends Permission> e : m.entrySet()) { this.plugin.getPermissionRegistry().insert(e.getKey()); super.put(e.getKey(), inject(e.getValue())); } update(); }
Example #30
Source File: LuckPermsPermissionMap.java From LuckPerms with MIT License | 5 votes |
@Override public Permission remove(@Nullable Object object) { if (object == null) { return null; } return uninject(super.remove(object)); }