mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-15 20:23:53 -07:00
Permission registration in plugin.yml can now be easier, see https://gist.github.com/32dca3e937c1c42a4ed2 - also added "default-permission" option.
By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
@@ -5,11 +5,13 @@ import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.constructor.SafeConstructor;
|
||||
|
||||
@@ -29,7 +31,8 @@ public final class PluginDescriptionFile {
|
||||
private String website = null;
|
||||
private boolean database = false;
|
||||
private PluginLoadOrder order = PluginLoadOrder.POSTWORLD;
|
||||
private ArrayList<Permission> permissions = new ArrayList<Permission>();
|
||||
private List<Permission> permissions = new ArrayList<Permission>();
|
||||
private PermissionDefault defaultPerm = PermissionDefault.OP;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public PluginDescriptionFile(final InputStream stream) throws InvalidDescriptionException {
|
||||
@@ -143,10 +146,14 @@ public final class PluginDescriptionFile {
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
public ArrayList<Permission> getPermissions() {
|
||||
public List<Permission> getPermissions() {
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public PermissionDefault getPermissionDefault() {
|
||||
return defaultPerm;
|
||||
}
|
||||
|
||||
private void loadMap(Map<String, Object> map) throws InvalidDescriptionException {
|
||||
try {
|
||||
name = map.get("name").toString();
|
||||
@@ -257,11 +264,21 @@ public final class PluginDescriptionFile {
|
||||
}
|
||||
}
|
||||
|
||||
if (map.containsKey("default-permission")) {
|
||||
try {
|
||||
defaultPerm = defaultPerm.getByName((String)map.get("default-permission"));
|
||||
} catch (ClassCastException ex) {
|
||||
throw new InvalidDescriptionException(ex, "default-permission is of wrong type");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
throw new InvalidDescriptionException(ex, "default-permission is not a valid choice");
|
||||
}
|
||||
}
|
||||
|
||||
if (map.containsKey("permissions")) {
|
||||
try {
|
||||
Map<String, Map<String, Object>> perms = (Map<String, Map<String, Object>>) map.get("permissions");
|
||||
|
||||
loadPermissions(perms);
|
||||
permissions = Permission.loadPermissions(perms, "Permission node '%s' in plugin description file for " + getFullName() + " is invalid", defaultPerm);
|
||||
} catch (ClassCastException ex) {
|
||||
throw new InvalidDescriptionException(ex, "permissions are of wrong type");
|
||||
}
|
||||
@@ -276,6 +293,7 @@ public final class PluginDescriptionFile {
|
||||
map.put("version", version);
|
||||
map.put("database", database);
|
||||
map.put("order", order.toString());
|
||||
map.put("default-permission", defaultPerm.toString());
|
||||
|
||||
if (commands != null) {
|
||||
map.put("command", commands);
|
||||
@@ -301,16 +319,4 @@ public final class PluginDescriptionFile {
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
private void loadPermissions(Map<String, Map<String, Object>> perms) {
|
||||
Set<String> keys = perms.keySet();
|
||||
|
||||
for (String name : keys) {
|
||||
try {
|
||||
permissions.add(Permission.loadPermission(name, perms.get(name)));
|
||||
} catch (Throwable ex) {
|
||||
Bukkit.getServer().getLogger().log(Level.SEVERE, "Permission node '" + name + "' in plugin description file for " + getFullName() + " is invalid", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user