Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
AffectedArc07 committed Oct 31, 2024
2 parents 2093241 + e6cd9c1 commit 2d2e4c2
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class PermissionsManager implements Listener {
private PermissionsConfig config;
private HashMap<Player, PermissionAttachment> attachments;
private HashSet<Player> admins;
private boolean enabled;

public PermissionsManager(ParaUtilSpigot plugin, ConfigurationManager config) {
this.plugin = plugin;
Expand All @@ -32,22 +33,38 @@ public PermissionsManager(ParaUtilSpigot plugin, ConfigurationManager config) {
// ADD ALL PERMISSIONS THIS PLUGIN USES
Bukkit.getPluginManager().addPermission(new Permission("parautil.lookup"));

plugin.getLogger().info("[PermissionsManager] Loaded");
if (Bukkit.getPluginManager().getPlugin("PermissionsEx") != null) {
enabled = false;
plugin.getLogger().info("[PermissionsManager] PermissionsEx detected. Events disabled.");
} else {
enabled = true;
plugin.getLogger().info("[PermissionsManager] Loaded");
}

}

// Called from LoginMananger
public void grantAdminPermissions(Player player) {
if (!enabled) {
return;
}
admins.add(player);
}

// Called from the reload command
public void refreshAll() {
if (!enabled) {
return;
}
for (Player player : Bukkit.getOnlinePlayers()) {
refreshPermissions(player);
}
}

public void refreshPermissions(Player player) {
if (!enabled) {
return;
}
PermissionAttachment pa = attachments.get(player);
// Remove all old
for (String perm : pa.getPermissions().keySet()) {
Expand All @@ -74,12 +91,18 @@ public void refreshPermissions(Player player) {
}

public void addAttachment(Player player) {
if (!enabled) {
return;
}
PermissionAttachment pa = player.addAttachment(plugin);
attachments.put(player, pa);
}

@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
if (!enabled) {
return;
}
attachments.remove(event.getPlayer());
}

Expand Down

0 comments on commit 2d2e4c2

Please sign in to comment.