org.bukkit.permissions.Permissible Java Examples
The following examples show how to use
org.bukkit.permissions.Permissible.
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: SuperPermsPreProcessor.java From BungeePerms with GNU General Public License v3.0 | 6 votes |
private List<String> getSuperPerms(Sender s) { BukkitSender bs = (BukkitSender) s; CommandSender sender = bs.getSender(); if (!(sender instanceof Player)) { return new ArrayList(); } Player p = (Player) sender; Permissible base = Injector.getPermissible(p); if (!(base instanceof BPPermissible)) { return new ArrayList(); } BPPermissible perm = (BPPermissible) base; List<String> l = new ArrayList(perm.getEffectiveSuperPerms().size()); for (PermissionAttachmentInfo e : perm.getEffectiveSuperPerms()) { l.add((e.getValue() ? "" : "-") + e.getPermission().toLowerCase()); } return l; }
Example #2
Source File: LuckPermsSubscriptionMap.java From LuckPerms with MIT License | 6 votes |
@Override public Map<Permissible, Boolean> get(Object key) { if (key == null || !(key instanceof String)) { return null; } String permission = ((String) key); LPSubscriptionValueMap result = (LPSubscriptionValueMap) super.get(key); if (result == null) { // calculate a new map - always! result = new LPSubscriptionValueMap(permission); super.put(permission, result); } return result; }
Example #3
Source File: Injector.java From BungeePerms with GNU General Public License v3.0 | 6 votes |
public static Permissible getPermissible(CommandSender sender) { try { Field perm = getPermField(sender); if (perm == null) { return null; } perm.setAccessible(true); Permissible permissible = (Permissible) perm.get(sender); return permissible; } catch (Exception e) { BungeePerms.getInstance().getDebug().log(e); } return null; }
Example #4
Source File: Injector.java From BungeePerms with GNU General Public License v3.0 | 6 votes |
public static void inject(CommandSender sender, Permissible newpermissible) { try { Field perm = getPermField(sender); if (perm == null) { return; } perm.setAccessible(true); perm.set(sender, newpermissible); } catch (Exception e) { BungeePerms.getInstance().getDebug().log(e); } }
Example #5
Source File: CraftServer.java From Kettle with GNU General Public License v3.0 | 6 votes |
@Override public int broadcast(String message, String permission) { Set<CommandSender> recipients = new HashSet<>(); for (Permissible permissible : getPluginManager().getPermissionSubscriptions(permission)) { if (permissible instanceof CommandSender && permissible.hasPermission(permission)) { recipients.add((CommandSender) permissible); } } BroadcastMessageEvent broadcastMessageEvent = new BroadcastMessageEvent(message, recipients); getPluginManager().callEvent(broadcastMessageEvent); if (broadcastMessageEvent.isCancelled()) { return 0; } message = broadcastMessageEvent.getMessage(); for (CommandSender recipient : recipients) { recipient.sendMessage(message); } return recipients.size(); }
Example #6
Source File: Host.java From SubServers-2 with Apache License 2.0 | 6 votes |
/** * Determine if an <i>object</i> can perform some action on this host using possible permissions * * @param object Object to check against * @param permissions Permissions to check (use <b>%</b> as a placeholder for the host name) * @return Permission Check Result */ public boolean permits(Permissible object, String... permissions) { if (Util.isNull(object)) throw new NullPointerException(); boolean permitted = false; for (int p = 0; !permitted && p < permissions.length; p++) { String perm = permissions[p]; if (perm != null) { // Check all proxies & individual proxies permission permitted = object.hasPermission(perm.replace("%", "*")) || object.hasPermission(perm.replace("%", this.getName().toLowerCase())); } } return permitted; }
Example #7
Source File: Proxy.java From SubServers-2 with Apache License 2.0 | 6 votes |
/** * Determine if an <i>object</i> can perform some action on this proxy using possible permissions * * @param object Object to check against * @param permissions Permissions to check (use <b>%</b> as a placeholder for the proxy name) * @return Permission Check Result */ public boolean permits(Permissible object, String... permissions) { if (Util.isNull(object)) throw new NullPointerException(); boolean permitted = false; for (int p = 0; !permitted && p < permissions.length; p++) { String perm = permissions[p]; if (perm != null) { // Check all proxies & individual proxies permission permitted = object.hasPermission(perm.replace("%", "*")) || object.hasPermission(perm.replace("%", this.getName().toLowerCase())); } } return permitted; }
Example #8
Source File: LuckPermsSubscriptionMap.java From LuckPerms with MIT License | 6 votes |
@Override public @NonNull Set<Permissible> keySet() { // start with the backing set Set<Permissible> set; synchronized (this.backing) { set = new HashSet<>(this.backing.keySet()); } // add any online players who meet requirements for (Player player : LuckPermsSubscriptionMap.this.plugin.getBootstrap().getServer().getOnlinePlayers()) { if (player.hasPermission(this.permission) || player.isPermissionSet(this.permission)) { set.add(player); } } return set; }
Example #9
Source File: Server.java From SubServers-2 with Apache License 2.0 | 5 votes |
/** * Determine if an <i>object</i> can perform some action on this server using possible permissions * * @param object Object to check against * @param permissions Permissions to check (use <b>%</b> as a placeholder for the server name) * @return Permission Check Result */ public boolean permits(Permissible object, String... permissions) { if (Util.isNull(object)) throw new NullPointerException(); boolean permitted = false; for (int p = 0; !permitted && p < permissions.length; p++) { String perm = permissions[p]; if (perm != null) { // Check all servers & individual servers permission permitted = object.hasPermission(perm.replace("%", "*")) || object.hasPermission(perm.replace("%", this.getName().toLowerCase())); // Check all hosts & individual hosts permission if (this instanceof SubServer) { permitted = permitted || object.hasPermission(perm.replace("%", "::*")) || object.hasPermission(perm.replace("%", "::" + ((SubServer) this).getHost().toLowerCase())); } // Check all groups & individual groups permission List<String> groups = this.getGroups(); if (groups.size() > 0) { permitted = permitted || object.hasPermission(perm.replace("%", ":*")); for (int g = 0; !permitted && g < groups.size(); g++) { permitted = object.hasPermission(perm.replace("%", ":" + groups.get(g).toLowerCase())); } } } } return permitted; }
Example #10
Source File: PermissionGroupListener.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
private void updateServer(@Nullable Server before, Server after) { boolean dirty = false; dirty |= updatePermission(Permissions.OBSERVER, before == null ? null : before.observer_permissions(), after.observer_permissions()); dirty |= updatePermission(Permissions.PARTICIPANT, before == null ? null : before.participant_permissions(), after.participant_permissions()); dirty |= updatePermission(Permissions.MAPMAKER, before == null ? null : before.mapmaker_permissions(), after.mapmaker_permissions()); if(dirty) { onlinePlayers.all().forEach(Permissible::recalculatePermissions); } }
Example #11
Source File: LuckPermsSubscriptionMap.java From LuckPerms with MIT License | 5 votes |
/** * Converts this map back to a standard HashMap * * @return a standard representation of this map */ public Map<String, Map<Permissible, Boolean>> detach() { Map<String, Map<Permissible, Boolean>> map = new HashMap<>(); for (Map.Entry<String, Map<Permissible, Boolean>> ent : entrySet()) { map.put(ent.getKey(), new WeakHashMap<>(((LPSubscriptionValueMap) ent.getValue()).backing)); } return map; }
Example #12
Source File: LuckPermsSubscriptionMap.java From LuckPerms with MIT License | 5 votes |
private LPSubscriptionValueMap(String permission, Map<Permissible, Boolean> backing) { this.permission = permission; this.backing = Collections.synchronizedMap(new WeakHashMap<>(backing)); // remove all players from the map this.backing.keySet().removeIf(p -> p instanceof Player); }
Example #13
Source File: LuckPermsSubscriptionMap.java From LuckPerms with MIT License | 5 votes |
@Override public Boolean put(Permissible key, Boolean value) { // don't allow players to be put into this map if (key instanceof Player) { return true; } return this.backing.put(key, value); }
Example #14
Source File: LuckPermsSubscriptionMap.java From LuckPerms with MIT License | 5 votes |
@Override public @NonNull Set<Entry<Permissible, Boolean>> entrySet() { return keySet().stream() .map(key -> { Boolean value = get(key); return value != null ? Maps.immutableEntry(key, value) : null; }) .filter(Objects::nonNull) .collect(ImmutableCollectors.toSet()); }
Example #15
Source File: InjectorSubscriptionMap.java From LuckPerms with MIT License | 5 votes |
private LuckPermsSubscriptionMap tryInject() throws Exception { Objects.requireNonNull(PERM_SUBS_FIELD, "PERM_SUBS_FIELD"); PluginManager pluginManager = this.plugin.getBootstrap().getServer().getPluginManager(); if (!(pluginManager instanceof SimplePluginManager)) { this.plugin.getLogger().severe("PluginManager instance is not a 'SimplePluginManager', instead: " + pluginManager.getClass()); this.plugin.getLogger().severe("Unable to inject LuckPerms Permission Subscription map."); return null; } Object map = PERM_SUBS_FIELD.get(pluginManager); if (map instanceof LuckPermsSubscriptionMap) { if (((LuckPermsSubscriptionMap) map).plugin == this.plugin) { return null; } map = ((LuckPermsSubscriptionMap) map).detach(); } //noinspection unchecked Map<String, Map<Permissible, Boolean>> castedMap = (Map<String, Map<Permissible, Boolean>>) map; // make a new subscription map & inject it LuckPermsSubscriptionMap newMap = new LuckPermsSubscriptionMap(this.plugin, castedMap); PERM_SUBS_FIELD.set(pluginManager, newMap); return newMap; }
Example #16
Source File: LuckPermsSubscriptionMap.java From LuckPerms with MIT License | 5 votes |
@Override public Map<Permissible, Boolean> put(String key, Map<Permissible, Boolean> value) { if (value == null) { throw new NullPointerException("Map value cannot be null"); } // ensure values are LP subscription maps if (!(value instanceof LPSubscriptionValueMap)) { value = new LPSubscriptionValueMap(key, value); } return super.put(key, value); }
Example #17
Source File: CraftServer.java From Thermos with GNU General Public License v3.0 | 5 votes |
@Override public int broadcast(String message, String permission) { int count = 0; Set<Permissible> permissibles = getPluginManager().getPermissionSubscriptions(permission); for (Permissible permissible : permissibles) { if (permissible instanceof CommandSender && permissible.hasPermission(permission)) { CommandSender user = (CommandSender) permissible; user.sendMessage(message); count++; } } return count; }
Example #18
Source File: Injector.java From BungeePerms with GNU General Public License v3.0 | 5 votes |
public static void uninject(CommandSender sender) { Permissible perm = getPermissible(sender); if (perm instanceof BPPermissible) { net.alpenblock.bungeeperms.platform.bukkit.BPPermissible p = (net.alpenblock.bungeeperms.platform.bukkit.BPPermissible) perm; p.uninject(); } }
Example #19
Source File: BukkitEventListener.java From BungeePerms with GNU General Public License v3.0 | 5 votes |
private void updateAttachment(Player p, User u) { Permissible base = Injector.getPermissible(p); if (!(base instanceof BPPermissible)) { return; } BPPermissible perm = (BPPermissible) base; perm.updateAttachment(u, ((BukkitConfig) BungeePerms.getInstance().getConfig()).getServername(), p.getWorld() == null ? null : p.getWorld().getName()); }
Example #20
Source File: Utils.java From Shopkeepers with GNU General Public License v3.0 | 5 votes |
/** * Performs a permissions check and logs debug information about it. * * @param permissible * @param permission * @return */ public static boolean hasPermission(Permissible permissible, String permission) { assert permissible != null; boolean hasPerm = permissible.hasPermission(permission); if (!hasPerm && (permissible instanceof Player)) { Log.debug("Player '" + ((Player) permissible).getName() + "' does not have permission '" + permission + "'."); } return hasPerm; }
Example #21
Source File: SimplePluginManager.java From Kettle with GNU General Public License v3.0 | 5 votes |
public void subscribeToDefaultPerms(boolean op, Permissible permissible) { Map<Permissible, Boolean> map = defSubs.get(op); if (map == null) { map = new WeakHashMap<Permissible, Boolean>(); defSubs.put(op, map); } map.put(permissible, true); }
Example #22
Source File: SimplePluginManager.java From Kettle with GNU General Public License v3.0 | 5 votes |
public void unsubscribeFromDefaultPerms(boolean op, Permissible permissible) { Map<Permissible, Boolean> map = defSubs.get(op); if (map != null) { map.remove(permissible); if (map.isEmpty()) { defSubs.remove(op); } } }
Example #23
Source File: SimplePluginManager.java From Kettle with GNU General Public License v3.0 | 5 votes |
public Set<Permissible> getDefaultPermSubscriptions(boolean op) { Map<Permissible, Boolean> map = defSubs.get(op); if (map == null) { return ImmutableSet.of(); } else { return ImmutableSet.copyOf(map.keySet()); } }
Example #24
Source File: Command.java From Kettle with GNU General Public License v3.0 | 5 votes |
public static void broadcastCommandMessage(CommandSender source, String message, boolean sendToSource) { String result = source.getName() + ": " + message; if (source instanceof BlockCommandSender) { BlockCommandSender blockCommandSender = (BlockCommandSender) source; if (blockCommandSender.getBlock().getWorld().getGameRuleValue("commandBlockOutput").equalsIgnoreCase("false")) { Bukkit.getConsoleSender().sendMessage(result); return; } } else if (source instanceof CommandMinecart) { CommandMinecart commandMinecart = (CommandMinecart) source; if (commandMinecart.getWorld().getGameRuleValue("commandBlockOutput").equalsIgnoreCase("false")) { Bukkit.getConsoleSender().sendMessage(result); return; } } Set<Permissible> users = Bukkit.getPluginManager().getPermissionSubscriptions(Server.BROADCAST_CHANNEL_ADMINISTRATIVE); String colored = ChatColor.GRAY + "" + ChatColor.ITALIC + "[" + result + ChatColor.GRAY + ChatColor.ITALIC + "]"; if (sendToSource && !(source instanceof ConsoleCommandSender)) { source.sendMessage(message); } for (Permissible user : users) { if (user instanceof CommandSender && user.hasPermission(Server.BROADCAST_CHANNEL_ADMINISTRATIVE)) { CommandSender target = (CommandSender) user; if (target instanceof ConsoleCommandSender) { target.sendMessage(result); } else if (target != source) { target.sendMessage(colored); } } } }
Example #25
Source File: SimplePluginManager.java From Kettle with GNU General Public License v3.0 | 5 votes |
public Set<Permissible> getPermissionSubscriptions(String permission) { String name = permission.toLowerCase(java.util.Locale.ENGLISH); Map<Permissible, Boolean> map = permSubs.get(name); if (map == null) { return ImmutableSet.of(); } else { return ImmutableSet.copyOf(map.keySet()); } }
Example #26
Source File: SimplePluginManager.java From Kettle with GNU General Public License v3.0 | 5 votes |
public void unsubscribeFromPermission(String permission, Permissible permissible) { String name = permission.toLowerCase(java.util.Locale.ENGLISH); Map<Permissible, Boolean> map = permSubs.get(name); if (map != null) { map.remove(permissible); if (map.isEmpty()) { permSubs.remove(name); } } }
Example #27
Source File: SimplePluginManager.java From Kettle with GNU General Public License v3.0 | 5 votes |
public void subscribeToPermission(String permission, Permissible permissible) { String name = permission.toLowerCase(java.util.Locale.ENGLISH); Map<Permissible, Boolean> map = permSubs.get(name); if (map == null) { map = new WeakHashMap<Permissible, Boolean>(); permSubs.put(name, map); } map.put(permissible, true); }
Example #28
Source File: SimplePluginManager.java From Kettle with GNU General Public License v3.0 | 5 votes |
private void dirtyPermissibles(boolean op) { Set<Permissible> permissibles = getDefaultPermSubscriptions(op); for (Permissible p : permissibles) { p.recalculatePermissions(); } }
Example #29
Source File: GamePermissionUtil.java From DiscordSRV with GNU General Public License v3.0 | 4 votes |
public static boolean hasPermission(Permissible sender, String permission) { return sender instanceof ConsoleCommandSender || sender.hasPermission(permission); }
Example #30
Source File: LuckPermsSubscriptionMap.java From LuckPerms with MIT License | 4 votes |
@Override public void putAll(@NonNull Map<? extends Permissible, ? extends Boolean> m) { this.backing.putAll(m); }