3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-12 22:20:08 +01:00

Moved WEPIF config to a global config file. Permissions configured per-plugin are not migrated to the global config.

Dieser Commit ist enthalten in:
zml2008 2011-08-06 00:35:40 -07:00
Ursprung 501c9fa482
Commit 266f272d88
2 geänderte Dateien mit 74 neuen und 7 gelöschten Zeilen

Datei anzeigen

@ -25,6 +25,7 @@ import java.util.Map;
import java.util.Set;
import java.util.HashMap;
import org.bukkit.util.config.Configuration;
import org.bukkit.util.config.ConfigurationNode;
public class ConfigurationPermissionsResolver implements PermissionsResolver {
private Configuration config;
@ -35,6 +36,16 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
public ConfigurationPermissionsResolver(Configuration config) {
this.config = config;
}
public static void generateDefaultPerms(Configuration config) {
config.setProperty("permissions.groups.default.permissions", new String[] {
"worldedit.reload",
"worldedit.selection.*",
"worlds.creative.worldedit.region.*"});
config.setProperty("permissions.groups.admins.permissions", new String[]{"*"});
config.setProperty("permissions.users.sk89q.permissions", new String[]{"worldedit.*"});
config.setProperty("permissions.users.sk89q.groups", new String[]{"admins"});
}
public void load() {
userGroups = new HashMap<String,Set<String>>();

Datei anzeigen

@ -19,34 +19,58 @@
package com.sk89q.bukkit.migration;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.logging.Logger;
import org.bukkit.Server;
import org.bukkit.plugin.Plugin;
import org.bukkit.util.config.Configuration;
public class PermissionsResolverManager implements PermissionsResolver {
private Configuration config;
private static final String CONFIG_HEADER = "#\r\n" +
"# WEPIF Configuration File\r\n" +
"#\r\n" +
"# This file handles permissions configuration for every plugin using WEPIF\r\n" +
"#\r\n" +
"# About editing this file:\r\n" +
"# - DO NOT USE TABS. You MUST use spaces or Bukkit will complain. If\r\n" +
"# you use an editor like Notepad++ (recommended for Windows users), you\r\n" +
"# must configure it to \"replace tabs with spaces.\" In Notepad++, this can\r\n" +
"# be changed in Settings > Preferences > Language Menu.\r\n" +
"# - Don't get rid of the indents. They are indented so some entries are\r\n" +
"# in categories (like \"enforce-single-session\" is in the \"protection\"\r\n" +
"# category.\r\n" +
"# - If you want to check the format of this file before putting it\r\n" +
"# into WEPIF, paste it into http://yaml-online-parser.appspot.com/\r\n" +
"# and see if it gives \"ERROR:\".\r\n" +
"# - Lines starting with # are comments and so they are ignored.\r\n" +
"#\r\n" +
"# About Configuration Permissions\r\n" +
"# - See http://wiki.sk89q.com/wiki/WorldEdit/Permissions/Bukkit\r\n" +
"# - Now with multiworld support (see example)\r\n" +
"\r\n";
private Server server;
private PermissionsResolver perms;
private Configuration permsConfig;
private String name;
private Logger logger;
public PermissionsResolverManager(Configuration config, Server server, String name, Logger logger) {
this.config = config;
this.server = server;
this.name = name;
this.logger = logger;
loadConfig(new File("wepif.yml")); // TODO: config migration, maybe
findResolver();
}
public void findResolver() {
if (tryDinnerPerms()) return;
if (tryPluginPermissionsResolver()) return;
if (tryNijiPermissions()) return;
if (tryFlatFilePermissions()) return;
perms = new ConfigurationPermissionsResolver(config);
perms = new ConfigurationPermissionsResolver(permsConfig);
logger.info(name + ": No known permissions plugin detected. Using configuration file for permissions.");
}
@ -85,7 +109,7 @@ public class PermissionsResolverManager implements PermissionsResolver {
}
private boolean tryDinnerPerms() {
if (!config.getBoolean("permissions.dinner-perms", true))
if (!permsConfig.getBoolean("dinnerperms", true))
return false;
perms = new DinnerPermsResolver(server);
logger.info(name + ": Using the Bukkit Permissions API.");
@ -123,4 +147,36 @@ public class PermissionsResolverManager implements PermissionsResolver {
return perms.getGroups(player);
}
private boolean loadConfig(File file) {
boolean isUpdated = false;
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
permsConfig = new Configuration(file);
permsConfig.load();
List<String> keys = permsConfig.getKeys();
permsConfig.setHeader(CONFIG_HEADER);
if (!keys.contains("dinnerperms")) {
permsConfig.setProperty("dinnerperms", permsConfig.getBoolean("dinner-perms", true));
isUpdated = true;
}
if (keys.contains("dinner-perms")) {
permsConfig.removeProperty("dinner-perms");
isUpdated = true;
}
if (!keys.contains("permissions")) {
ConfigurationPermissionsResolver.generateDefaultPerms(permsConfig);
isUpdated = true;
}
if (isUpdated) {
logger.info("WEPIF: Updated config file");
permsConfig.save();
}
return isUpdated;
}
}