mirror of
https://github.com/PaperMC/Paper.git
synced 2025-09-03 05:43:52 -07:00
Some small fixes to permissions to register the correct Permissible in base and more accurate reverse lookups
By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
@@ -15,12 +15,19 @@ import org.bukkit.plugin.Plugin;
|
||||
*/
|
||||
public class PermissibleBase implements Permissible {
|
||||
private ServerOperator opable = null;
|
||||
private Permissible parent = this;
|
||||
private final List<PermissionAttachment> attachments = new LinkedList<PermissionAttachment>();
|
||||
private final Map<String, PermissionAttachmentInfo> permissions = new HashMap<String, PermissionAttachmentInfo>();
|
||||
private boolean dirtyPermissions = true;
|
||||
|
||||
public PermissibleBase(ServerOperator opable) {
|
||||
this.opable = opable;
|
||||
|
||||
if (opable instanceof Permissible) {
|
||||
this.parent = (Permissible)opable;
|
||||
}
|
||||
|
||||
calculatePermissions();
|
||||
}
|
||||
|
||||
public boolean isOp() {
|
||||
@@ -121,7 +128,7 @@ public class PermissibleBase implements Permissible {
|
||||
throw new IllegalArgumentException("Plugin " + plugin.getDescription().getFullName() + " is disabled");
|
||||
}
|
||||
|
||||
PermissionAttachment result = new PermissionAttachment(plugin, this);
|
||||
PermissionAttachment result = new PermissionAttachment(plugin, parent);
|
||||
|
||||
attachments.add(result);
|
||||
recalculatePermissions();
|
||||
@@ -144,7 +151,7 @@ public class PermissibleBase implements Permissible {
|
||||
|
||||
recalculatePermissions();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Given attachment is not part of Permissible object " + this);
|
||||
throw new IllegalArgumentException("Given attachment is not part of Permissible object " + parent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,12 +163,12 @@ public class PermissibleBase implements Permissible {
|
||||
if (dirtyPermissions) {
|
||||
clearPermissions();
|
||||
Set<Permission> defaults = Bukkit.getServer().getPluginManager().getDefaultPermissions(isOp());
|
||||
Bukkit.getServer().getPluginManager().subscribeToDefaultPerms(isOp(), this);
|
||||
Bukkit.getServer().getPluginManager().subscribeToDefaultPerms(isOp(), parent);
|
||||
|
||||
for (Permission perm : defaults) {
|
||||
String name = perm.getName().toLowerCase();
|
||||
permissions.put(name, new PermissionAttachmentInfo(this, name, null, true));
|
||||
Bukkit.getServer().getPluginManager().subscribeToPermission(name, this);
|
||||
permissions.put(name, new PermissionAttachmentInfo(parent, name, null, true));
|
||||
Bukkit.getServer().getPluginManager().subscribeToPermission(name, parent);
|
||||
calculateChildPermissions(perm.getChildren(), false, null);
|
||||
}
|
||||
|
||||
@@ -177,10 +184,10 @@ public class PermissibleBase implements Permissible {
|
||||
Set<String> perms = permissions.keySet();
|
||||
|
||||
for (String name : perms) {
|
||||
Bukkit.getServer().getPluginManager().unsubscribeFromPermission(name, this);
|
||||
Bukkit.getServer().getPluginManager().unsubscribeFromPermission(name, parent);
|
||||
}
|
||||
|
||||
Bukkit.getServer().getPluginManager().unsubscribeFromDefaultPerms(isOp(), this);
|
||||
Bukkit.getServer().getPluginManager().unsubscribeFromDefaultPerms(isOp(), parent);
|
||||
|
||||
permissions.clear();
|
||||
}
|
||||
@@ -193,8 +200,8 @@ public class PermissibleBase implements Permissible {
|
||||
boolean value = children.get(name) ^ invert;
|
||||
String lname = name.toLowerCase();
|
||||
|
||||
permissions.put(lname, new PermissionAttachmentInfo(this, lname, attachment, value));
|
||||
Bukkit.getServer().getPluginManager().subscribeToPermission(name, this);
|
||||
permissions.put(lname, new PermissionAttachmentInfo(parent, lname, attachment, value));
|
||||
Bukkit.getServer().getPluginManager().subscribeToPermission(name, parent);
|
||||
|
||||
if (perm != null) {
|
||||
calculateChildPermissions(perm.getChildren(), !value, attachment);
|
||||
@@ -230,7 +237,7 @@ public class PermissibleBase implements Permissible {
|
||||
PermissionAttachment result = addAttachment(plugin);
|
||||
|
||||
if (Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new RemoveAttachmentRunnable(result), ticks) == -1) {
|
||||
Bukkit.getServer().getLogger().log(Level.WARNING, "Could not add PermissionAttachment to " + this + " for plugin " + plugin.getDescription().getFullName() + ": Scheduler returned -1");
|
||||
Bukkit.getServer().getLogger().log(Level.WARNING, "Could not add PermissionAttachment to " + parent + " for plugin " + plugin.getDescription().getFullName() + ": Scheduler returned -1");
|
||||
result.remove();
|
||||
return null;
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user