org.bukkit.permissions.PermissibleBase Java Examples
The following examples show how to use
org.bukkit.permissions.PermissibleBase.
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: PermissibleMonitoringInjector.java From LuckPerms with MIT License | 6 votes |
private PermissibleBase transform(PermissibleBase permBase, String name) { Objects.requireNonNull(permBase, "permBase"); // don't bother injecting if already setup. if (this.mode == Mode.INJECT && permBase instanceof MonitoredPermissibleBase && ((MonitoredPermissibleBase) permBase).plugin == this.plugin) { return null; } // unwrap any previous injection if (permBase instanceof MonitoredPermissibleBase) { permBase = ((MonitoredPermissibleBase) permBase).getDelegate(); } // if the mode is uninject, just return the unwrapped PermissibleBase if (this.mode == Mode.UNINJECT) { return permBase; } // create a monitored instance which delegates to the previous PermissibleBase return new MonitoredPermissibleBase(this.plugin, permBase, name); }
Example #2
Source File: PermissibleMonitoringInjector.java From LuckPerms with MIT License | 6 votes |
private void injectConsole() throws Exception { ConsoleCommandSender consoleSender = this.plugin.getBootstrap().getServer().getConsoleSender(); // get the ServerCommandSender class Class<?> serverCommandSenderClass = CraftBukkitImplementation.obcClass("command.ServerCommandSender"); // get the perm field Field permField = serverCommandSenderClass.getDeclaredField("perm"); permField.setAccessible(true); // get the PermissibleBase instance PermissibleBase permBase = (PermissibleBase) permField.get(consoleSender); // create a new instance which delegates to the previous PermissibleBase PermissibleBase newPermBase = transform(permBase, "internal/console"); if (newPermBase == null) { return; } // inject the new instance permField.set(consoleSender, newPermBase); }
Example #3
Source File: PermissibleMonitoringInjector.java From LuckPerms with MIT License | 6 votes |
private void injectEntity() throws Exception { // get the CraftEntity class Class<?> entityClass = CraftBukkitImplementation.obcClass("entity.CraftEntity"); // get the method used to obtain a PermissibleBase // this method will initialise a new PB instance if one doesn't yet exist Method getPermissibleBaseMethod = entityClass.getDeclaredMethod("getPermissibleBase"); getPermissibleBaseMethod.setAccessible(true); // get the PermissibleBase instance PermissibleBase permBase = (PermissibleBase) getPermissibleBaseMethod.invoke(null); // get the perm field on CraftEntity Field permField = entityClass.getDeclaredField("perm"); permField.setAccessible(true); // create a new instance which delegates to the previous PermissibleBase PermissibleBase newPermBase = transform(permBase, "internal/entity"); if (newPermBase == null) { return; } // inject the new instance permField.set(null, newPermBase); }
Example #4
Source File: PermissibleInjector.java From LuckPerms with MIT License | 5 votes |
/** * Injects a {@link LuckPermsPermissible} into a {@link Player}. * * @param player the player to inject into * @param newPermissible the permissible to inject * @throws Exception propagates any exceptions which were thrown during injection */ public static void inject(Player player, LuckPermsPermissible newPermissible) throws Exception { // get the existing PermissibleBase held by the player PermissibleBase oldPermissible = (PermissibleBase) HUMAN_ENTITY_PERMISSIBLE_FIELD.get(player); // seems we have already injected into this player. if (oldPermissible instanceof LuckPermsPermissible) { throw new IllegalStateException("LPPermissible already injected into player " + player.toString()); } // Move attachments over from the old permissible //noinspection unchecked List<PermissionAttachment> attachments = (List<PermissionAttachment>) PERMISSIBLE_BASE_ATTACHMENTS_FIELD.get(oldPermissible); newPermissible.convertAndAddAttachments(attachments); attachments.clear(); oldPermissible.clearPermissions(); // Setup the new permissible newPermissible.getActive().set(true); newPermissible.setOldPermissible(oldPermissible); // inject the new instance HUMAN_ENTITY_PERMISSIBLE_FIELD.set(player, newPermissible); }
Example #5
Source File: DummyPermissibleBase.java From LuckPerms with MIT License | 5 votes |
public static void copyFields(PermissibleBase from, PermissibleBase to) { try { ATTACHMENTS_FIELD.set(to, ATTACHMENTS_FIELD.get(from)); PERMISSIONS_FIELD.set(to, PERMISSIONS_FIELD.get(from)); } catch (IllegalAccessException e) { throw new RuntimeException(e); } }
Example #6
Source File: MonitoredPermissibleBase.java From LuckPerms with MIT License | 5 votes |
public MonitoredPermissibleBase(LuckPermsPlugin plugin, PermissibleBase delegate, String name) { super(null); DummyPermissibleBase.copyFields(delegate, this); this.plugin = plugin; this.delegate = delegate; this.name = name; this.initialised = true; }
Example #7
Source File: BPPermissible.java From BungeePerms with GNU General Public License v3.0 | 5 votes |
@Override public synchronized void clearPermissions() { if (oldPermissible instanceof PermissibleBase) { PermissibleBase base = (PermissibleBase) oldPermissible; base.clearPermissions(); } }
Example #8
Source File: BPPermissible.java From BungeePerms with GNU General Public License v3.0 | 5 votes |
public void inject() { if (Injector.getPermissible(sender) == this) { return; } Statics.setField(PermissibleBase.class, oldPermissible, superperms, "permissions"); Statics.setField(PermissibleBase.class, this, permissions, "permissions"); Statics.setField(PermissibleBase.class, oldPermissible, opable, "opable"); Injector.inject(sender, this); recalculatePermissions(); }
Example #9
Source File: BPPermissible.java From BungeePerms with GNU General Public License v3.0 | 5 votes |
public void uninject() { if (Injector.getPermissible(sender) != this) { return; } Statics.setField(PermissibleBase.class, oldPermissible, new HashMap(), "permissions"); Statics.setField(PermissibleBase.class, oldPermissible, oldOpable, "opable"); Injector.inject(sender, oldPermissible); recalculatePermissions(); }
Example #10
Source File: LuckPermsPermissible.java From LuckPerms with MIT License | 4 votes |
PermissibleBase getOldPermissible() { return this.oldPermissible; }
Example #11
Source File: LuckPermsPermissible.java From LuckPerms with MIT License | 4 votes |
void setOldPermissible(PermissibleBase oldPermissible) { this.oldPermissible = oldPermissible; }
Example #12
Source File: MonitoredPermissibleBase.java From LuckPerms with MIT License | 4 votes |
PermissibleBase getDelegate() { return this.delegate; }
Example #13
Source File: BPPermissible.java From BungeePerms with GNU General Public License v3.0 | 4 votes |
public BPPermissible(CommandSender sender, User u, Permissible oldPermissible) { super(sender); this.sender = sender; this.oldPermissible = oldPermissible; permissions = new LinkedHashMap<String, PermissionAttachmentInfo>() { @Override public PermissionAttachmentInfo put(String k, PermissionAttachmentInfo v) { PermissionAttachmentInfo existing = this.get(k); if (existing != null) { return existing; } return super.put(k, v); } }; superperms = new LinkedHashMap<String, PermissionAttachmentInfo>() { @Override public PermissionAttachmentInfo put(String k, PermissionAttachmentInfo v) { PermissionAttachmentInfo existing = this.get(k); if (existing != null) { return existing; } return super.put(k, v); } }; //inject an opable oldOpable = Statics.getField(PermissibleBase.class, oldPermissible, ServerOperator.class, "opable"); opable = new ServerOperator() { @Override public boolean isOp() { BukkitConfig config = (BukkitConfig) BungeePerms.getInstance().getConfig(); if (opdisabled) { if (!config.isAllowops()) { return false; } } if (config.isDebug()) { BungeePerms.getLogger().info("op check: " + BPPermissible.this.sender.getName() + " has OP: " + oldOpable.isOp()); } return oldOpable.isOp(); } @Override public void setOp(boolean value) { oldOpable.setOp(value); } }; init = true; recalculatePermissions(); }