Register plugin permissions with Bukkit

This commit is contained in:
Esophose 2020-01-17 00:03:20 -07:00
parent dc020d5bf8
commit e994c49bb1
4 changed files with 113 additions and 55 deletions

View file

@ -2,10 +2,10 @@
* TODO: v7.0
* + Add ability to create/manage fixed effects from the GUI
* * Convert fixed effect ids into names
* + Add effect/style settings folder that lets you disable effects/style and edit style properties
*/
/*
* + Added effect/style settings folder that lets you disable effects/style and edit style properties
* + Added setting to disable particles while in combat
* * /ppo now uses your permissions instead of the player you are targetting
* + Added effect/style name customization through config files

View file

@ -7,11 +7,18 @@ import dev.esophose.playerparticles.particles.PPlayer;
import dev.esophose.playerparticles.particles.ParticleEffect;
import dev.esophose.playerparticles.styles.ParticleStyle;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permissible;
import org.bukkit.permissions.Permission;
import org.bukkit.plugin.PluginManager;
public class PermissionManager extends Manager {
@ -54,7 +61,7 @@ public class PermissionManager extends Manager {
/**
* Checks if a Permissible has a PlayerParticles permission with a sub-permission
*
* @param p The Permissibhle
* @param p The Permissible
* @param subPermission The sub-permission
* @return True if the Player has permission
*/
@ -66,6 +73,57 @@ public class PermissionManager extends Manager {
public PermissionManager(PlayerParticles playerParticles) {
super(playerParticles);
// Register plugin permissions to Bukkit
PluginManager pluginManager = Bukkit.getPluginManager();
Set<Permission> allPermissions = new HashSet<>();
// Effects
Map<String, Boolean> effectPermissions = new HashMap<>();
for (ParticleEffect effect : ParticleEffect.values()) {
Permission permission = new Permission("playerparticles.effect." + effect.getInternalName());
pluginManager.addPermission(permission);
effectPermissions.put(permission.getName(), true);
}
// Effects Wildcard
allPermissions.add(new Permission("playerparticles.effect.*", effectPermissions));
// Styles
List<ParticleStyle> styles = this.playerParticles.getManager(ParticleStyleManager.class).getStylesWithDisabled();
Map<String, Boolean> stylePermissions = new HashMap<>();
for (ParticleStyle style : styles) {
Permission permission = new Permission("playerparticles.style." + style.getInternalName());
pluginManager.addPermission(permission);
stylePermissions.put(permission.getName(), true);
}
// Styles Wildcard
allPermissions.add(new Permission("playerparticles.style.*", stylePermissions));
// Fixed
pluginManager.addPermission(new Permission("playerparticles.fixed"));
pluginManager.addPermission(new Permission("playerparticles.fixed.unlimited"));
pluginManager.addPermission(new Permission("playerparticles.fixed.clear"));
pluginManager.addPermission(new Permission("playerparticles.fixed.teleport"));
// Misc
pluginManager.addPermission(new Permission("playerparticles.reload"));
pluginManager.addPermission(new Permission("playerparticles.override"));
pluginManager.addPermission(new Permission("playerparticles.gui"));
pluginManager.addPermission(new Permission("playerparticles.particles.unlimited"));
pluginManager.addPermission(new Permission("playerparticles.groups.unlimited"));
// Register all non-child permissions
Map<String, Boolean> childPermissions = new HashMap<>();
for (Permission permission : allPermissions) {
pluginManager.addPermission(permission);
childPermissions.put(permission.getName(), true);
}
// Register all permissions as a child to the global plugin permission
pluginManager.addPermission(new Permission("playerparticles.*", childPermissions));
}
@Override

View file

@ -11,4 +11,4 @@ commands:
description: The main PlayerParticles command. By default, opens the GUI.
ppo:
description: Allows executing a /pp command for another player.
permission: playerparticles.other
permission: playerparticles.override