Implemented temporary permissions.

This commit is contained in:
sk89q 2011-01-16 12:56:17 -08:00
parent 30d9978412
commit 36db436fa3
2 changed files with 54 additions and 2 deletions

View File

@ -22,6 +22,8 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bukkit.*;
@ -308,6 +310,28 @@ public boolean handleCommand(PlayerChatEvent event) {
System.arraycopy(split, 1, args, 0, split.length - 1);
handleRegionCommand(player, action, args);
} else if (split[0].equalsIgnoreCase("/reload")
&& plugin.hasPermission(player, "/reload")
&& split.length > 1) {
if (split[1].equalsIgnoreCase("WorldGuard")) {
LoggerToChatHandler handler = new LoggerToChatHandler(player);
handler.setLevel(Level.ALL);
Logger minecraftLogger = Logger.getLogger("Minecraft");
minecraftLogger.addHandler(handler);
try {
plugin.loadConfiguration();
plugin.postReload();
player.sendMessage("WorldGuard configuration reloaded.");
} catch (Throwable t) {
player.sendMessage("Error while reloading: "
+ t.getMessage());
} finally {
minecraftLogger.removeHandler(handler);
}
return true;
}
} else {
return false;
}

View File

@ -37,6 +37,7 @@
import org.bukkit.plugin.PluginLoader;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.config.Configuration;
import com.sk89q.bukkit.migration.ConfigurationPermissionsResolver;
import com.sk89q.worldguard.blacklist.Blacklist;
import com.sk89q.worldguard.blacklist.BlacklistLogger;
import com.sk89q.worldguard.blacklist.loggers.*;
@ -56,6 +57,7 @@ public class WorldGuardPlugin extends JavaPlugin {
new WorldGuardBlockListener(this);
private final WorldGuardEntityListener entityListener =
new WorldGuardEntityListener(this);
private final ConfigurationPermissionsResolver perms;
Blacklist blacklist;
@ -115,7 +117,9 @@ public WorldGuardPlugin(PluginLoader pluginLoader, Server instance,
folder.mkdirs();
regionLoader = new CSVDatabase(new File(folder, "regions.txt"));
perms = new ConfigurationPermissionsResolver(getConfiguration());
loadConfiguration();
postReload();
registerEvents();
}
@ -278,14 +282,38 @@ public void loadConfiguration() {
}
}
}
// Temporary
perms.load();
}
/**
* Populates various lists.
*/
public void postReload() {
invinciblePlayers.clear();
amphibiousPlayers.clear();
try {
for (Player player : getServer().getOnlinePlayers()) {
if (inGroup(player, "wg-invincible")) {
invinciblePlayers.add(player.getName());
}
if (inGroup(player, "wg-amphibious")) {
amphibiousPlayers.add(player.getName());
}
}
} catch (NullPointerException e) { // Thrown if loaded too early
}
}
boolean inGroup(Player player, String group) {
return true;
return perms.inGroup(player.getName(), group);
}
boolean hasPermission(Player player, String perm) {
return perm.equals("/regionclaim") || perm.equals("/regionload") || perm.equals("/regionsave");
return perms.hasPermission(player.getName(), perm);
}
List<String> getGroups(Player player) {