mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-02 13:07:06 +01:00
Refactored default permission registration. Added "craftbukkit" and "craftbukkit.command" parent perms, and fixed whitelist adding
This commit is contained in:
parent
26bd45c233
commit
90d1afb748
4 changed files with 183 additions and 110 deletions
|
@ -70,7 +70,7 @@ import org.bukkit.craftbukkit.command.ServerCommandListener;
|
|||
import org.bukkit.craftbukkit.map.CraftMapView;
|
||||
import org.bukkit.scheduler.BukkitWorker;
|
||||
import org.bukkit.craftbukkit.scheduler.CraftScheduler;
|
||||
import org.bukkit.craftbukkit.util.DefaultPermissions;
|
||||
import org.bukkit.craftbukkit.util.permissions.DefaultPermissions;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.world.WorldInitEvent;
|
||||
import org.bukkit.permissions.Permission;
|
||||
|
@ -165,7 +165,7 @@ public final class CraftServer implements Server {
|
|||
if (type == PluginLoadOrder.POSTWORLD) {
|
||||
commandMap.registerServerAliases();
|
||||
loadCustomPermissions();
|
||||
DefaultPermissions.registerCorePermissions(pluginManager);
|
||||
DefaultPermissions.registerCorePermissions();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,108 +0,0 @@
|
|||
|
||||
package org.bukkit.craftbukkit.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
public final class DefaultPermissions {
|
||||
private DefaultPermissions() {}
|
||||
|
||||
private static void registerPermission(PluginManager manager, Permission perm) {
|
||||
try {
|
||||
manager.addPermission(perm);
|
||||
} catch (IllegalArgumentException ex) {}
|
||||
}
|
||||
|
||||
private static void registerWhitelist(PluginManager manager) {
|
||||
Map<String, Boolean> whitelist = new HashMap<String, Boolean>();
|
||||
whitelist.put("craftbukkit.command.whitelist.remove", true);
|
||||
whitelist.put("craftbukkit.command.whitelist.reload", true);
|
||||
whitelist.put("craftbukkit.command.whitelist.enable", true);
|
||||
whitelist.put("craftbukkit.command.whitelist.disable", true);
|
||||
whitelist.put("craftbukkit.command.whitelist.list", true);
|
||||
|
||||
registerPermission(manager, new Permission("craftbukkit.command.whitelist.add", "Allows the user to add a player to the server whitelist"));
|
||||
registerPermission(manager, new Permission("craftbukkit.command.whitelist.remove", "Allows the user to remove a player from the server whitelist"));
|
||||
registerPermission(manager, new Permission("craftbukkit.command.whitelist.reload", "Allows the user to reload the server whitelist"));
|
||||
registerPermission(manager, new Permission("craftbukkit.command.whitelist.enable", "Allows the user to enable the server whitelist"));
|
||||
registerPermission(manager, new Permission("craftbukkit.command.whitelist.disable", "Allows the user to disable the server whitelist"));
|
||||
registerPermission(manager, new Permission("craftbukkit.command.whitelist.list", "Allows the user to list all the users on the server whitelist"));
|
||||
registerPermission(manager, new Permission("craftbukkit.command.whitelist", "Allows the user to modify the server whitelist", PermissionDefault.OP, whitelist));
|
||||
}
|
||||
|
||||
private static void registerBan(PluginManager manager) {
|
||||
Map<String, Boolean> ban = new HashMap<String, Boolean>();
|
||||
ban.put("craftbukkit.command.ban.player", true);
|
||||
ban.put("craftbukkit.command.ban.ip", true);
|
||||
|
||||
registerPermission(manager, new Permission("craftbukkit.command.ban.player", "Allows the user to ban players"));
|
||||
registerPermission(manager, new Permission("craftbukkit.command.ban.ip", "Allows the user to ban IP addresses"));
|
||||
registerPermission(manager, new Permission("craftbukkit.command.ban", "Allows the user to ban people", PermissionDefault.OP, ban));
|
||||
}
|
||||
|
||||
private static void registerUnban(PluginManager manager) {
|
||||
Map<String, Boolean> unban = new HashMap<String, Boolean>();
|
||||
unban.put("craftbukkit.command.unban.player", true);
|
||||
unban.put("craftbukkit.command.unban.ip", true);
|
||||
|
||||
registerPermission(manager, new Permission("craftbukkit.command.unban.player", "Allows the user to unban players"));
|
||||
registerPermission(manager, new Permission("craftbukkit.command.unban.ip", "Allows the user to unban IP addresses"));
|
||||
registerPermission(manager, new Permission("craftbukkit.command.unban", "Allows the user to unban people", PermissionDefault.OP, unban));
|
||||
}
|
||||
|
||||
private static void registerOp(PluginManager manager) {
|
||||
Map<String, Boolean> op = new HashMap<String, Boolean>();
|
||||
op.put("craftbukkit.command.op.give", true);
|
||||
op.put("craftbukkit.command.op.take", true);
|
||||
|
||||
registerPermission(manager, new Permission("craftbukkit.command.op.give", "Allows the user to give a player operator status"));
|
||||
registerPermission(manager, new Permission("craftbukkit.command.op.take", "Allows the user to take a players operator status"));
|
||||
registerPermission(manager, new Permission("craftbukkit.command.op", "Allows the user to change operators", PermissionDefault.OP, op));
|
||||
}
|
||||
|
||||
private static void registerSave(PluginManager manager) {
|
||||
Map<String, Boolean> save = new HashMap<String, Boolean>();
|
||||
save.put("craftbukkit.command.save.enable", true);
|
||||
save.put("craftbukkit.command.save.disable", true);
|
||||
save.put("craftbukkit.command.save.perform", true);
|
||||
|
||||
registerPermission(manager, new Permission("craftbukkit.command.save.enable", "Allows the user to enable automatic saving"));
|
||||
registerPermission(manager, new Permission("craftbukkit.command.save.disable", "Allows the user to disable automatic saving"));
|
||||
registerPermission(manager, new Permission("craftbukkit.command.save.perform", "Allows the user to perform a manual save"));
|
||||
registerPermission(manager, new Permission("craftbukkit.command.save", "Allows the user to save the worlds", PermissionDefault.OP, save));
|
||||
}
|
||||
|
||||
private static void registerTime(PluginManager manager) {
|
||||
Map<String, Boolean> time = new HashMap<String, Boolean>();
|
||||
time.put("craftbukkit.command.time.add", true);
|
||||
time.put("craftbukkit.command.time.set", true);
|
||||
|
||||
registerPermission(manager, new Permission("craftbukkit.command.time.add", "Allows the user to fast-forward time"));
|
||||
registerPermission(manager, new Permission("craftbukkit.command.time.set", "Allows the user to change the time"));
|
||||
registerPermission(manager, new Permission("craftbukkit.command.time", "Allows the user to alter the time", PermissionDefault.OP, time));
|
||||
}
|
||||
|
||||
public static void registerCorePermissions(PluginManager manager) {
|
||||
registerWhitelist(manager);
|
||||
registerBan(manager);
|
||||
registerUnban(manager);
|
||||
registerOp(manager);
|
||||
registerSave(manager);
|
||||
registerTime(manager);
|
||||
|
||||
registerPermission(manager, new Permission("craftbukkit.command.kill", "Allows the user to commit suicide", PermissionDefault.TRUE));
|
||||
registerPermission(manager, new Permission("craftbukkit.command.me", "Allows the user to perform a chat action", PermissionDefault.TRUE));
|
||||
registerPermission(manager, new Permission("craftbukkit.command.tell", "Allows the user to privately message another player", PermissionDefault.TRUE));
|
||||
registerPermission(manager, new Permission("craftbukkit.command.say", "Allows the user to talk as the console", PermissionDefault.OP));
|
||||
registerPermission(manager, new Permission("craftbukkit.command.give", "Allows the user to give items to players", PermissionDefault.OP));
|
||||
registerPermission(manager, new Permission("craftbukkit.command.teleport", "Allows the user to teleport players", PermissionDefault.OP));
|
||||
registerPermission(manager, new Permission("craftbukkit.command.kick", "Allows the user to kick players", PermissionDefault.OP));
|
||||
registerPermission(manager, new Permission("craftbukkit.command.stop", "Allows the user to stop the server", PermissionDefault.OP));
|
||||
registerPermission(manager, new Permission("craftbukkit.command.list", "Allows the user to list all online players", PermissionDefault.OP));
|
||||
registerPermission(manager, new Permission("craftbukkit.command.help", "Allows the user to view the vanilla help menu", PermissionDefault.OP));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
package org.bukkit.craftbukkit.util.permissions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
public class CommandPermissions {
|
||||
private static final String ROOT = "craftbukkit.command";
|
||||
private static final String PREFIX = ROOT + ".";
|
||||
|
||||
private CommandPermissions() {}
|
||||
|
||||
private static Permission registerWhitelist(Permission parent) {
|
||||
Permission whitelist = DefaultPermissions.registerPermission(PREFIX + "whitelist", "Allows the user to modify the server whitelist", PermissionDefault.OP, parent);
|
||||
|
||||
DefaultPermissions.registerPermission(PREFIX + "whitelist.add", "Allows the user to add a player to the server whitelist", whitelist);
|
||||
DefaultPermissions.registerPermission(PREFIX + "whitelist.remove", "Allows the user to remove a player from the server whitelist", whitelist);
|
||||
DefaultPermissions.registerPermission(PREFIX + "whitelist.reload", "Allows the user to reload the server whitelist", whitelist);
|
||||
DefaultPermissions.registerPermission(PREFIX + "whitelist.enable", "Allows the user to enable the server whitelist", whitelist);
|
||||
DefaultPermissions.registerPermission(PREFIX + "whitelist.disable", "Allows the user to disable the server whitelist", whitelist);
|
||||
DefaultPermissions.registerPermission(PREFIX + "whitelist.list", "Allows the user to list all the users on the server whitelist", whitelist);
|
||||
|
||||
whitelist.recalculatePermissibles();
|
||||
|
||||
return whitelist;
|
||||
}
|
||||
|
||||
private static Permission registerBan(Permission parent) {
|
||||
Permission ban = DefaultPermissions.registerPermission(PREFIX + "ban", "Allows the user to ban people", PermissionDefault.OP, parent);
|
||||
|
||||
DefaultPermissions.registerPermission(PREFIX + "ban.player", "Allows the user to ban players", ban);
|
||||
DefaultPermissions.registerPermission(PREFIX + "ban.ip", "Allows the user to ban IP addresses", ban);
|
||||
|
||||
ban.recalculatePermissibles();
|
||||
|
||||
return ban;
|
||||
}
|
||||
|
||||
private static Permission registerUnban(Permission parent) {
|
||||
Permission unban = DefaultPermissions.registerPermission(PREFIX + "unban", "Allows the user to unban people", PermissionDefault.OP, parent);
|
||||
|
||||
DefaultPermissions.registerPermission(PREFIX + "unban.player", "Allows the user to unban players", unban);
|
||||
DefaultPermissions.registerPermission(PREFIX + "unban.ip", "Allows the user to unban IP addresses", unban);
|
||||
|
||||
unban.recalculatePermissibles();
|
||||
|
||||
return unban;
|
||||
}
|
||||
|
||||
private static Permission registerOp(Permission parent) {
|
||||
Permission op = DefaultPermissions.registerPermission(PREFIX + "op", "Allows the user to change operators", PermissionDefault.OP, parent);
|
||||
|
||||
DefaultPermissions.registerPermission(PREFIX + "op.give", "Allows the user to give a player operator status", op);
|
||||
DefaultPermissions.registerPermission(PREFIX + "op.take", "Allows the user to take a players operator status", op);
|
||||
|
||||
op.recalculatePermissibles();
|
||||
|
||||
return op;
|
||||
}
|
||||
|
||||
private static Permission registerSave(Permission parent) {
|
||||
Permission save = DefaultPermissions.registerPermission(PREFIX + "save", "Allows the user to save the worlds", PermissionDefault.OP, parent);
|
||||
|
||||
DefaultPermissions.registerPermission(PREFIX + "save.enable", "Allows the user to enable automatic saving", save);
|
||||
DefaultPermissions.registerPermission(PREFIX + "save.disable", "Allows the user to disable automatic saving", save);
|
||||
DefaultPermissions.registerPermission(PREFIX + "save.perform", "Allows the user to perform a manual save", save);
|
||||
|
||||
save.recalculatePermissibles();
|
||||
|
||||
return save;
|
||||
}
|
||||
|
||||
private static Permission registerTime(Permission parent) {
|
||||
Permission time = DefaultPermissions.registerPermission(PREFIX + "time", "Allows the user to alter the time", PermissionDefault.OP, parent);
|
||||
|
||||
DefaultPermissions.registerPermission(PREFIX + "time.add", "Allows the user to fast-forward time", time);
|
||||
DefaultPermissions.registerPermission(PREFIX + "time.set", "Allows the user to change the time", time);
|
||||
|
||||
time.recalculatePermissibles();
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
public static Permission registerPermissions(Permission parent) {
|
||||
Permission commands = DefaultPermissions.registerPermission(ROOT, "Gives the user the ability to use all Craftbukkit commands", parent);
|
||||
|
||||
registerWhitelist(commands);
|
||||
registerBan(commands);
|
||||
registerUnban(commands);
|
||||
registerOp(commands);
|
||||
registerSave(commands);
|
||||
registerTime(commands);
|
||||
|
||||
DefaultPermissions.registerPermission(PREFIX + "kill", "Allows the user to commit suicide", PermissionDefault.TRUE, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "me", "Allows the user to perform a chat action", PermissionDefault.TRUE, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "tell", "Allows the user to privately message another player", PermissionDefault.TRUE, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "say", "Allows the user to talk as the console", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "give", "Allows the user to give items to players", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "teleport", "Allows the user to teleport players", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "kick", "Allows the user to kick players", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "stop", "Allows the user to stop the server", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "list", "Allows the user to list all online players", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "help", "Allows the user to view the vanilla help menu", PermissionDefault.OP, commands);
|
||||
|
||||
commands.recalculatePermissibles();
|
||||
|
||||
return commands;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package org.bukkit.craftbukkit.util.permissions;
|
||||
|
||||
import java.util.Map;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
public final class DefaultPermissions {
|
||||
private static final String ROOT = "craftbukkit";
|
||||
private static final String PREFIX = ROOT + ".";
|
||||
|
||||
private DefaultPermissions() {}
|
||||
|
||||
public static Permission registerPermission(Permission perm) {
|
||||
try {
|
||||
Bukkit.getPluginManager().addPermission(perm);
|
||||
return perm;
|
||||
} catch (IllegalArgumentException ex) {
|
||||
return Bukkit.getPluginManager().getPermission(perm.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public static Permission registerPermission(Permission perm, Permission parent) {
|
||||
parent.getChildren().put(perm.getName(), true);
|
||||
return registerPermission(perm);
|
||||
}
|
||||
|
||||
public static Permission registerPermission(String name, String desc) {
|
||||
Permission perm = registerPermission(new Permission(name, desc));
|
||||
return perm;
|
||||
}
|
||||
|
||||
public static Permission registerPermission(String name, String desc, Permission parent) {
|
||||
Permission perm = registerPermission(name, desc);
|
||||
parent.getChildren().put(perm.getName(), true);
|
||||
return perm;
|
||||
}
|
||||
|
||||
public static Permission registerPermission(String name, String desc, PermissionDefault def) {
|
||||
Permission perm = registerPermission(new Permission(name, desc, def));
|
||||
return perm;
|
||||
}
|
||||
|
||||
public static Permission registerPermission(String name, String desc, PermissionDefault def, Permission parent) {
|
||||
Permission perm = registerPermission(name, desc, def);
|
||||
parent.getChildren().put(perm.getName(), true);
|
||||
return perm;
|
||||
}
|
||||
|
||||
public static Permission registerPermission(String name, String desc, PermissionDefault def, Map<String, Boolean> children) {
|
||||
Permission perm = registerPermission(new Permission(name, desc, def, children));
|
||||
return perm;
|
||||
}
|
||||
|
||||
public static Permission registerPermission(String name, String desc, PermissionDefault def, Map<String, Boolean> children, Permission parent) {
|
||||
Permission perm = registerPermission(name, desc, def, children);
|
||||
parent.getChildren().put(perm.getName(), true);
|
||||
return perm;
|
||||
}
|
||||
|
||||
public static void registerCorePermissions() {
|
||||
Permission parent = registerPermission(ROOT, "Gives the user the ability to use all Craftbukkit utilities and commands");
|
||||
|
||||
CommandPermissions.registerPermissions(parent);
|
||||
|
||||
parent.recalculatePermissibles();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue