Java Code Examples for org.bukkit.entity.Player#getEffectivePermissions()

The following examples show how to use org.bukkit.entity.Player#getEffectivePermissions() . 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: PermissionHandler.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
public int getPurgeLimit(Player player) {
    int limit = RedProtect.get().config.configRoot().purge.canpurge_limit;
    List<Integer> limits = new ArrayList<>();
    Set<PermissionAttachmentInfo> perms = player.getEffectivePermissions();
    if (limit > 0) {
        for (PermissionAttachmentInfo perm : perms) {
            if (perm.getPermission().startsWith("redprotect.canpurge-limit.")) {
                String pStr = perm.getPermission().replaceAll("[^-?0-9]+", "");
                if (!pStr.isEmpty()) {
                    limits.add(Integer.parseInt(pStr));
                }
            }
        }
    }
    if (limits.size() > 0) {
        limit = Collections.max(limits);
    }
    return limit;
}
 
Example 2
Source File: PermissionHandler.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
private int getBlockLimit(Player player) {
    int limit = RedProtect.get().config.configRoot().region_settings.limit_amount;
    List<Integer> limits = new ArrayList<>();
    Set<PermissionAttachmentInfo> perms = player.getEffectivePermissions();
    if (limit > 0) {
        if (!hasVaultPerm(player, "redprotect.limits.blocks.unlimited")) {
            for (PermissionAttachmentInfo perm : perms) {
                if (perm.getPermission().startsWith("redprotect.limits.blocks.")) {
                    if (RedProtect.get().config.configRoot().region_settings.blocklimit_per_world && !hasVaultPerm(player, perm.getPermission()))
                        continue;
                    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;
}
 
Example 3
Source File: PermissionHandler.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
private int getClaimLimit(Player player) {
    int limit = RedProtect.get().config.configRoot().region_settings.claim.amount_per_player;
    List<Integer> limits = new ArrayList<>();
    Set<PermissionAttachmentInfo> perms = player.getEffectivePermissions();
    if (limit > 0) {
        if (!hasVaultPerm(player, "redprotect.limits.claim.unlimited")) {
            for (PermissionAttachmentInfo perm : perms) {
                if (perm.getPermission().startsWith("redprotect.limits.claim.")) {
                    if (RedProtect.get().config.configRoot().region_settings.claim.claimlimit_per_world && !hasVaultPerm(player, perm.getPermission()))
                        continue;
                    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;
}
 
Example 4
Source File: VaultPermissions.java    From Modern-LWC with MIT License 5 votes vote down vote up
@Override
public List<String> getGroups(Player player) {
    RegisteredServiceProvider<Permission> serviceProvider = Bukkit.getServer().getServicesManager()
            .getRegistration(Permission.class);
    groupPrefix = LWC.getInstance().getConfiguration().getString("core.groupPrefix", "group.");
    if (serviceProvider == null) {
        return super.getGroups(player);
    }

    Permission perm = serviceProvider.getProvider();

    try {
        // the player's groups
        String[] groups = perm.getPlayerGroups(player);

        // fallback to superperms if it appears that they have no groups
        if (groups == null || groups.length == 0) {
            return super.getGroups(player);
        }

        List<String> groupss = Arrays.asList(groups);

        for (PermissionAttachmentInfo pai : player.getEffectivePermissions()) {
            if (pai.getPermission().startsWith(groupPrefix)) {
                groupss.add(pai.getPermission().substring(groupPrefix.length()));
            }
        }

        return groupss;
    } catch (UnsupportedOperationException e) {
        // Can be thrown by vault or asList. Thrown by Vault when using SuperPerms -
        // getPlayerGroups() will throw it :-(
        return super.getGroups(player);
    }
}
 
Example 5
Source File: SuperPermsPermissions.java    From Modern-LWC with MIT License 5 votes vote down vote up
@Override
public List<String> getGroups(Player player) {
    LWC.getInstance();
    List<String> groups = new ArrayList<>();

    for (PermissionAttachmentInfo pai : player.getEffectivePermissions()) {
        if (pai.getPermission().startsWith(groupPrefix)) {
            groups.add(pai.getPermission().substring(groupPrefix.length()));
        }
    }

    return groups;
}
 
Example 6
Source File: LimitsModule.java    From Modern-LWC with MIT License 5 votes vote down vote up
/**
 * Search the player's permissions for a permission and return it
 * Depending on this is used, this can become O(scary)
 *
 * @param player
 * @param prefix
 * @return
 */
public PermissionAttachmentInfo searchPermissions(Player player, String prefix) {
    for (PermissionAttachmentInfo attachment : player.getEffectivePermissions()) {
        String permission = attachment.getPermission();

        // check for the perm node
        if (attachment.getValue() && permission.startsWith(prefix)) {
            // Bingo!
            return attachment;
        }
    }

    return null;
}
 
Example 7
Source File: PlayerListener.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@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));
}
 
Example 8
Source File: ExprPermissions.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
protected String[] get(Event e) {
	final Set<String> permissions = new HashSet<>();
	for (Player player : players.getArray(e))
		for (final PermissionAttachmentInfo permission : player.getEffectivePermissions())
			permissions.add(permission.getPermission());
	return permissions.toArray(new String[permissions.size()]);
}
 
Example 9
Source File: ShopUtils.java    From ShopChest with MIT License 5 votes vote down vote up
/**
 * 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 ?Config.defaultLimit : limit);
}
 
Example 10
Source File: Permission.java    From VaultAPI with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
   * 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;
  }
 
Example 11
Source File: Permission.java    From VaultAPI with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
   * 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;
  }
 
Example 12
Source File: LimitsV2.java    From Modern-LWC with MIT License 4 votes vote down vote up
/**
 * Find limits that are attached to the player via permissions (e.g
 * lwc.protect.*.10 = 10 of any protection)
 *
 * @param player
 * @return
 */
private List<Limit> findLimitsViaPermissions(Player player) {
    List<Limit> limits = new LinkedList<>();

    for (PermissionAttachmentInfo pai : player.getEffectivePermissions()) {
        String permission = pai.getPermission();
        boolean value = pai.getValue();

        if (!value || !permission.startsWith("lwc.protect.")) {
            continue;
        }

        String[] split = permission.substring("lwc.protect.".length()).split(".");

        if (split.length != 2) {
            continue;
        }

        String matchName = split[0];
        String strCount = split[1];

        int count;
        try {
            count = Integer.parseInt(strCount);
        } catch (NumberFormatException e) {
            continue;
        }

        if (matchName.equals("*")) {
            limits.add(new DefaultLimit(count));
        } else if (matchName.equals("sign")) {
            limits.add(new SignLimit(count));
        } else if (!matchName.equals("*") && !matchName.equals("sign")) {
            Material material = materialCache.get(matchName);

            if (material == null) {
                continue;
            }

            limits.add(new BlockLimit(material, count));
        } else if (EntityType.valueOf(matchName.toUpperCase()) != null) {
            limits.add(new EntityLimit(EntityType.valueOf(matchName.toUpperCase()), count));
        }
    }

    return limits;
}
 
Example 13
Source File: LevelCalcByChunk.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
private void tidyUp() {
    // Cancel
    task.cancel();
    // Finalize calculations
    result.rawBlockCount += (long)(result.underWaterBlockCount * Settings.underWaterMultiplier);
    // Set the death penalty
    result.deathHandicap = plugin.getPlayers().getDeaths(island.getOwner());
    // Set final score
    result.score = (result.rawBlockCount / Settings.levelCost) - result.deathHandicap - island.getLevelHandicap();
    // Run any modifications
    // Get the permission multiplier if it is available
    int levelMultiplier = 1;
    Player player = plugin.getServer().getPlayer(targetPlayer);
    if (player != null) {
        // Get permission multiplier
        for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
            if (perms.getPermission().startsWith(Settings.PERMPREFIX + "island.multiplier.")) {
                String spl[] = perms.getPermission().split(Settings.PERMPREFIX + "island.multiplier.");
                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 {
                        // Get the max value should there be more than one
                        levelMultiplier = Math.max(levelMultiplier, Integer.valueOf(spl[1]));
                    }
                }
            }
            // Do some sanity checking
            if (levelMultiplier < 1) {
                levelMultiplier = 1;
            }
        }
    }
    // Calculate how many points are required to get to the next level
    long pointsToNextLevel = (Settings.levelCost * (result.score + 1 + island.getLevelHandicap())) - ((result.rawBlockCount * levelMultiplier) - (result.deathHandicap * Settings.deathpenalty));
    // Sometimes it will return 0, so calculate again to make sure it will display a good value
    if(pointsToNextLevel == 0) pointsToNextLevel = (Settings.levelCost * (result.score + 2 + island.getLevelHandicap()) - ((result.rawBlockCount * levelMultiplier) - (result.deathHandicap * Settings.deathpenalty)));

    // All done.
    informPlayers(saveLevel(island, targetPlayer, pointsToNextLevel));

}