@@ -6,6 +6,10 @@ import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.constructor.SafeConstructor;
|
||||
|
||||
@@ -25,6 +29,7 @@ public final class PluginDescriptionFile {
|
||||
private String website = null;
|
||||
private boolean database = false;
|
||||
private PluginLoadOrder order = PluginLoadOrder.POSTWORLD;
|
||||
private ArrayList<Permission> permissions = new ArrayList<Permission>();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public PluginDescriptionFile(final InputStream stream) throws InvalidDescriptionException {
|
||||
@@ -138,6 +143,10 @@ public final class PluginDescriptionFile {
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
public ArrayList<Permission> getPermissions() {
|
||||
return permissions;
|
||||
}
|
||||
|
||||
private void loadMap(Map<String, Object> map) throws InvalidDescriptionException {
|
||||
try {
|
||||
name = map.get("name").toString();
|
||||
@@ -247,6 +256,16 @@ public final class PluginDescriptionFile {
|
||||
throw new InvalidDescriptionException(ex, "authors are of wrong type");
|
||||
}
|
||||
}
|
||||
|
||||
if (map.containsKey("permissions")) {
|
||||
try {
|
||||
Map<String, Map<String, Object>> perms = (Map<String, Map<String, Object>>) map.get("permissions");
|
||||
|
||||
loadPermissions(perms);
|
||||
} catch (ClassCastException ex) {
|
||||
throw new InvalidDescriptionException(ex, "permissions are of wrong type");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> saveMap() {
|
||||
@@ -282,4 +301,16 @@ 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