/** * Get the maximum value of a numerical perm setting * @param player - the player to check * @param perm - the start of the perm, e.g., bskyblock.maxhomes * @param permValue - the default value - the result may be higher or lower than this * @return */ public static int getPermValue(Player player, String perm, int permValue) { for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) { if (perms.getPermission().startsWith(perm + ".")) { // Get the max value should there be more than one if (perms.getPermission().contains(perm + ".*")) { return permValue; } else { String[] spl = perms.getPermission().split(perm + "."); if (spl.length > 1) { if (!NumberUtils.isDigits(spl[1])) { plugin.getLogger().severe("Player " + player.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring..."); } else { permValue = Math.max(permValue, Integer.valueOf(spl[1])); } } } } // Do some sanity checking if (permValue < 1) { permValue = 1; } } return permValue; }
public static int getMaxPermission(Player p, String node) { int maxLimit = 0; for (PermissionAttachmentInfo perm : p.getEffectivePermissions()) { String permission = perm.getPermission(); if (!permission.toLowerCase().startsWith(node.toLowerCase())) { continue; } String[] split = permission.split("\\."); try { int number = Integer.parseInt(split[split.length - 1]); if (number > maxLimit) { maxLimit = number; } } catch (NumberFormatException ignore) { } } return maxLimit; }
public static void assignRanks(Player p, int tsDbId){ //Permissions for(PermissionAttachmentInfo pai : p.getEffectivePermissions()) { String perms = pai.getPermission(); if(UltimateTs.main().getConfig().get("perms."+perms) != null){ int gTs = UltimateTs.main().getConfig().getInt("perms."+perms); BotManager.getBot().addClientToServerGroup(gTs, tsDbId); } } //Default Ranks int groupToAssign = UltimateTs.main().getConfig().getInt("config.assignWhenRegister"); if(groupToAssign > 0){ BotManager.getBot().addClientToServerGroup(groupToAssign, tsDbId); } }
public int getVaultCapacity(Player p) { int capacity = getVaultCapacity(); if(isVaultCapacityPermissionControl()) { for(PermissionAttachmentInfo pai : p.getEffectivePermissions()) { String per = pai.getPermission(); if(!per.toLowerCase().startsWith("wowsuchcleaner.vault.capacity.")) continue; String capacityString = per.split("\\.")[3]; capacity = Integer.parseInt(capacityString); continue; } } return capacity; }
private int LimitHandler(Player p){ int limit = RPConfig.getInt("region-settings.limit-amount"); List<Integer> limits = new ArrayList<>(); Set<PermissionAttachmentInfo> perms = p.getEffectivePermissions(); if (limit > 0){ if (!p.hasPermission("redprotect.limit.blocks.unlimited")){ for (PermissionAttachmentInfo perm:perms){ if (perm.getPermission().startsWith("redprotect.limit.blocks.")){ String pStr = perm.getPermission().replaceAll("[^-?0-9]+", ""); if (!pStr.isEmpty()){ limits.add(Integer.parseInt(pStr)); } } } } else { return -1; } } if (limits.size() > 0){ limit = Collections.max(limits); } return limit; }
private int ClaimLimitHandler(Player p){ int limit = RPConfig.getInt("region-settings.claim-amount"); List<Integer> limits = new ArrayList<>(); Set<PermissionAttachmentInfo> perms = p.getEffectivePermissions(); if (limit > 0){ if (!p.hasPermission("redprotect.limit.claim.unlimited")){ for (PermissionAttachmentInfo perm:perms){ if (perm.getPermission().startsWith("redprotect.limit.claim.")){ String pStr = perm.getPermission().replaceAll("[^-?0-9]+", ""); if (!pStr.isEmpty()){ limits.add(Integer.parseInt(pStr)); } } } } else { return -1; } } if (limits.size() > 0){ limit = Collections.max(limits); } return limit; }
/** * Returns the maximum number of greenhouses this player can make * @param player * @return number of greenhouses or -1 to indicate unlimited */ public int getMaxGreenhouses(Player player) { // -1 is unimited int maxGreenhouses = Settings.maxGreenhouses; for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) { if (perms.getPermission().startsWith("greenhouses.limit")) { logger(2,"Permission is = " + perms.getPermission()); try { int max = Integer.valueOf(perms.getPermission().split("greenhouses.limit.")[1]); if (max > maxGreenhouses) { maxGreenhouses = max; } } catch (Exception e) {} // Do nothing } // Do some sanity checking if (maxGreenhouses < 0) { maxGreenhouses = -1; } } return maxGreenhouses; }
/** * Superperms has no group support, but we fake it (this is slow and stupid * since it has to iterate through ALL permissions a player has). But if * you're attached to superperms and not using a nice plugin like bPerms * and Vault then this is as good as it gets. * * @param player * @return the group name or null */ private String getSuperpermsGroup(Player player) { if( player == null ) return null; String group = null; // this code shamelessly adapted from WorldEdit's WEPIF support for superperms Permissible perms = getPermissible(player); if (perms != null) { for (PermissionAttachmentInfo permAttach : perms.getEffectivePermissions()) { String perm = permAttach.getPermission(); if (!(perm.startsWith(GROUP_PREFIX) && permAttach.getValue())) { continue; } // we just grab the first "group.X" permission we can find group = perm.substring(GROUP_PREFIX.length(), perm.length()); break; } } return group; }
/** * Update all permissions and op state of the provided permissible. * * @param permissible the permissible */ private void updatePermissible(final CommandSender permissible) { final boolean isPlayer = permissible instanceof Player; if (isPlayer && !((Player)permissible).isOnline()) { this.forgetPlayer((Player)permissible); } else { final String name = (isPlayer ? "" : "_") + permissible.getName(); if (permissible.isOp()) { this.ops.add(name); } else { this.ops.remove(name); } Set<String> perms = this.permissions.get(name); if (perms == null) { perms = new HashSet<>(); } else { perms.clear(); } for (final PermissionAttachmentInfo perm : permissible.getEffectivePermissions()) { if (perm.getValue()) { perms.add(perm.getPermission()); } } this.permissions.put(name, perms); } }
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; }
@Override public boolean playerAddTransient(String world, String player, String permission) { if (world != null) { throw new UnsupportedOperationException(getName() + " does not support World based transient permissions!"); } Player p = plugin.getServer().getPlayer(player); if (p == null) { throw new UnsupportedOperationException(getName() + " does not support offline player transient permissions!"); } for (PermissionAttachmentInfo paInfo : p.getEffectivePermissions()) { if (paInfo.getAttachment().getPlugin().equals(plugin)) { paInfo.getAttachment().setPermission(permission, true); return true; } } PermissionAttachment attach = p.addAttachment(plugin); attach.setPermission(permission, true); return true; }
@Override public boolean playerRemoveTransient(String world, String player, String permission) { if (world != null) { throw new UnsupportedOperationException(getName() + " does not support World based transient permissions!"); } Player p = plugin.getServer().getPlayer(player); if (p == null) { throw new UnsupportedOperationException(getName() + " does not support offline player transient permissions!"); } for (PermissionAttachmentInfo paInfo : p.getEffectivePermissions()) { if (paInfo.getAttachment().getPlugin().equals(plugin)) { return paInfo.getAttachment().getPermissions().remove(permission); } } return false; }
/** * List all effective permissions for this player. * * @param player * @return List<String> of permissions */ public List<String> listPerms(Player player) { List<String> perms = new ArrayList<String>(); /* * // All permissions registered with Bukkit for this player * PermissionAttachment attachment = this.attachments.get(player); * * // List perms for this player perms.add("Attachment Permissions:"); * for(Map.Entry<String, Boolean> entry : * attachment.getPermissions().entrySet()){ perms.add(" " + * entry.getKey() + " = " + entry.getValue()); } */ perms.add("Effective Permissions:"); for (PermissionAttachmentInfo info : player.getEffectivePermissions()) { if (info.getValue() == true) { perms.add(" " + info.getPermission() + " = " + info.getValue()); } } return perms; }
@EventHandler(priority = EventPriority.HIGHEST) public void join(final PlayerJoinEvent event) { Player player = event.getPlayer(); resetPlayer(player); event.getPlayer().addAttachment(lobby, Permissions.OBSERVER, true); if (player.hasPermission("lobby.overhead-news")) { final String datacenter = minecraftService.getLocalServer().datacenter(); final Component news = new Component(ChatColor.GREEN) .extra(new TranslatableComponent( "lobby.news", new Component(ChatColor.GOLD, ChatColor.BOLD).extra(generalFormatter.publicHostname()) )); final BossBar bar = bossBarFactory.createBossBar(renderer.render(news, player), BarColor.BLUE, BarStyle.SOLID); bar.setProgress(1); bar.addPlayer(player); bar.show(); } if(!player.hasPermission("lobby.disabled-permissions-exempt")) { for(PermissionAttachmentInfo attachment : player.getEffectivePermissions()) { if(config.getDisabledPermissions().contains(attachment.getPermission())) { attachment.getAttachment().setPermission(attachment.getPermission(), false); } } } int count = lobby.getServer().getOnlinePlayers().size(); if(!lobby.getServer().getOnlinePlayers().contains(event.getPlayer())) count++; minecraftService.updateLocalServer(new SignUpdate(count)); }
@Command( aliases = {"list"}, desc = "List all permissions", usage = "[player] [prefix]", min = 0, max = 2 ) public void list(CommandContext args, CommandSender sender) throws CommandException { CommandSender player = CommandUtils.getCommandSenderOrSelf(args, sender, 0); String prefix = args.getString(1, ""); sender.sendMessage(ChatColor.WHITE + "Permissions for " + player.getName() + ":"); List<PermissionAttachmentInfo> perms = new ArrayList<>(player.getEffectivePermissions()); Collections.sort(perms, new Comparator<PermissionAttachmentInfo>() { @Override public int compare(PermissionAttachmentInfo a, PermissionAttachmentInfo b) { return a.getPermission().compareTo(b.getPermission()); } }); for(PermissionAttachmentInfo perm : perms) { if(perm.getPermission().startsWith(prefix)) { sender.sendMessage((perm.getValue() ? ChatColor.GREEN : ChatColor.RED) + " " + perm.getPermission() + (perm.getAttachment() == null ? "" : " (" + perm.getAttachment().getPlugin().getName() + ")")); } } }
public Permissible(CommandSender sender, PermissionEntity entity) { super(sender); this.sender = sender; this.entity = entity; 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); } }; try { Field permissionsField = PermissibleBase.class.getField("permissions"); Reflection.setField(permissionsField, this, permissions); } catch (NoSuchFieldException e) { e.printStackTrace(); } }
@Override public Set<PermissionAttachmentInfo> getEffectivePermissions() { if (oldpermissible == null) { return super.getEffectivePermissions(); } return new LinkedHashSet<>(permissions.values()); }
@Override public Set<PermissionAttachmentInfo> getEffectivePermissions() { Set<Map.Entry<String, Boolean>> permissions = this.user.getCachedData().getPermissionData(calculateContexts()).getImmutableBacking().entrySet(); Set<PermissionAttachmentInfo> ret = new HashSet<>(permissions.size()); for (Map.Entry<String, Boolean> entry : permissions) { ret.add(new PermissionAttachmentInfo(this.player, entry.getKey(), null, entry.getValue())); } return ret; }
@Override public Set<PermissionAttachmentInfo> getEffectivePermissions() { Set<PermissionAttachmentInfo> output = new HashSet<>(); for (String permission : permissionsPlayer.getPermissionsInEffect()) { if (permission.startsWith("-")) output.add(new PermissionAttachmentInfo(this, permission.substring(1), null, false)); else output.add(new PermissionAttachmentInfo(this, permission, null, true)); } return output; }
public void loadMultiplier(Player p){ int id=1,ip=1; for (PermissionAttachmentInfo perms : p.getEffectivePermissions()) { String perm = perms.getPermission(); if (perm.toLowerCase().startsWith("pickupmoney.multiply.")) { String[] spl = perm.split("\\."); int num = Integer.parseInt(spl[3]); if(spl[2].equals("drop") && id<num) id = num; else if(spl[2].equals("pickup") && ip<num) ip = num; } } dropMulti.put(p.getUniqueId(),id); pickupMulti.put(p.getUniqueId(),ip); }
/** * Get the shop limits of a player * @param p Player, whose shop limits should be returned * @return The shop limits of the given player */ public int getShopLimit(Player p) { int limit = 0; boolean useDefault = true; for (PermissionAttachmentInfo permInfo : p.getEffectivePermissions()) { if (permInfo.getPermission().startsWith("shopchest.limit.") && p.hasPermission(permInfo.getPermission())) { if (permInfo.getPermission().equalsIgnoreCase(Permissions.NO_LIMIT)) { limit = -1; useDefault = false; break; } else { String[] spl = permInfo.getPermission().split("shopchest.limit."); if (spl.length > 1) { try { int newLimit = Integer.valueOf(spl[1]); if (newLimit < 0) { limit = -1; break; } limit = Math.max(limit, newLimit); useDefault = false; } catch (NumberFormatException ignored) { /* Ignore and continue */ } } } } } if (limit < -1) limit = -1; return (useDefault ? plugin.getShopChestConfig().default_limit : limit); }
@Operation(aliases = {"giveperm"}) public static Parameter givePermissionOperation(org.bukkit.entity.Player pent, Context ctx, StringParameter v) { if ( v == null ) fizzle("What permission where you lookin for ?"); PermissionAttachment target = null; for ( PermissionAttachmentInfo pi : pent.getEffectivePermissions() ) { if ( pi.getPermissible() == pent && pi.getAttachment() != null && pi.getAttachment().getPlugin() == ParchmentPluginLite.instance() ) { target = pi.getAttachment(); break; } } if ( target == null ) target = new PermissionAttachment(ParchmentPluginLite.instance(), pent); target.setPermission(v.asString(ctx), true); return Parameter.from(pent.hasPermission(v.asString(ctx))); }
@Operation(aliases = {"takeperm", "delperm"}) public static Parameter removePermissionOperation(org.bukkit.entity.Player pent, Context ctx, StringParameter v) { if ( v == null ) fizzle("What permission where you lookin for ?"); PermissionAttachment target = null; for ( PermissionAttachmentInfo pi : pent.getEffectivePermissions() ) { if ( pi.getPermissible() == pent.getPlayer() && pi.getAttachment().getPlugin() == ParchmentPluginLite.instance() ) { target = pi.getAttachment(); break; } } if ( target == null ) target = new PermissionAttachment(ParchmentPluginLite.instance(), pent); target.setPermission(v.asString(ctx), false); return Parameter.from(pent.hasPermission(v.asString(ctx))); }
@Operation(aliases = {"perms"}) public static Parameter permissionsOperation(org.bukkit.entity.Player pent, Context ctx) { ArrayList<Parameter> list = new ArrayList<Parameter>(); for ( PermissionAttachmentInfo i : pent.getEffectivePermissions() ) { list.add(Parameter.from(i.getPermission())); } return ListParameter.from(list); }
/** * Add transient permission to a player. * This operation adds a permission onto the player object in bukkit via Bukkit's permission interface. * * @param player Player Object * @param permission Permission node * @return Success or Failure */ public boolean playerAddTransient(Player player, String permission) { for (PermissionAttachmentInfo paInfo : player.getEffectivePermissions()) { if (paInfo.getAttachment() != null && paInfo.getAttachment().getPlugin().equals(plugin)) { paInfo.getAttachment().setPermission(permission, true); return true; } } PermissionAttachment attach = player.addAttachment(plugin); attach.setPermission(permission, true); return true; }
/** * Remove transient permission from a player. * * @param player Player Object * @param permission Permission node * @return Success or Failure */ public boolean playerRemoveTransient(Player player, String permission) { for (PermissionAttachmentInfo paInfo : player.getEffectivePermissions()) { if (paInfo.getAttachment() != null && paInfo.getAttachment().getPlugin().equals(plugin)) { paInfo.getAttachment().unsetPermission(permission); return true; } } return false; }
private List<PermissionAttachmentInfo> addChildPerms(List<String> perms) { Map<String, Boolean> map = new LinkedHashMap(); for (String perm : perms) { map.put(perm.startsWith("-") ? perm.substring(1) : perm, !perm.startsWith("-")); } return addChildPerms(map); }
private List<PermissionAttachmentInfo> addChildPerms(Map<String, Boolean> perms) { List<PermissionAttachmentInfo> permlist = new LinkedList(); for (Map.Entry<String, Boolean> perm : perms.entrySet()) { PermissionAttachmentInfo pai = new PermissionAttachmentInfo(oldPermissible, perm.getKey().toLowerCase(), null, perm.getValue()); permlist.add(pai); Permission permission = Bukkit.getPluginManager().getPermission(pai.getPermission()); if (permission != null && !permission.getChildren().isEmpty()) { permlist.addAll(addChildPerms(permission.getChildren())); } } return permlist; }
public void uninject() { if (Injector.getPermissible(sender) != this) { return; } Statics.setField(PermissibleBase.class, oldPermissible, new HashMap<String, PermissionAttachmentInfo>(), "permissions"); Statics.setField(PermissibleBase.class, oldPermissible, oldOpable, "opable"); Injector.inject(sender, oldPermissible); recalculatePermissions(); }
/** * Add transient permission to a player. * This operation adds a world-unspecific permission onto the player object in bukkit via Bukkit's permission interface. * * @param player Player Object * @param permission Permission node * @return Success or Failure */ public boolean playerAddTransient(Player player, String permission) { for (PermissionAttachmentInfo paInfo : player.getEffectivePermissions()) { if (paInfo.getAttachment() != null && paInfo.getAttachment().getPlugin().equals(plugin)) { paInfo.getAttachment().setPermission(permission, true); return true; } } PermissionAttachment attach = player.addAttachment(plugin); attach.setPermission(permission, true); return true; }
public void clearPermissions() { for(PermissionAttachmentInfo a: this.pl.getServer().getPlayerExact(this.p).getEffectivePermissions()) { if(a.getAttachment() == null) return; this.pl.getServer().getPlayerExact(this.p).removeAttachment(a.getAttachment()); } }
public Set<PermissionAttachmentInfo> getEffectivePermissions() { return perm.getEffectivePermissions(); }
@Override public Set<PermissionAttachmentInfo> getEffectivePermissions() { return perm.getEffectivePermissions(); }
@Override public Set<PermissionAttachmentInfo> getEffectivePermissions() { return Collections.emptySet(); }
@Override public PermissionAttachmentInfo getEffectivePermission(String name) { return null; }
@Override public Collection<PermissionAttachmentInfo> getAttachments() { return Collections.emptyList(); }
@Override public Collection<PermissionAttachmentInfo> getAttachments(Plugin plugin) { return Collections.emptyList(); }