From 7c15c2de4198ba3851136186efa3b6c9c7b72fef Mon Sep 17 00:00:00 2001 From: sk89q Date: Sat, 2 Apr 2011 02:33:23 -0700 Subject: [PATCH] Re-added /worldguard set of commands. --- .../bukkit/LoggerToChatHandler.java | 6 +- .../worldguard/bukkit/WorldGuardPlugin.java | 1 - .../bukkit/commands/ProtectionCommands.java | 7 ++ .../bukkit/commands/WorldGuardCommands.java | 82 +++++++++++++++++++ .../protection/GlobalRegionManager.java | 2 +- 5 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 src/com/sk89q/worldguard/bukkit/commands/WorldGuardCommands.java diff --git a/src/com/sk89q/worldguard/bukkit/LoggerToChatHandler.java b/src/com/sk89q/worldguard/bukkit/LoggerToChatHandler.java index de0eb304..29eca0d2 100644 --- a/src/com/sk89q/worldguard/bukkit/LoggerToChatHandler.java +++ b/src/com/sk89q/worldguard/bukkit/LoggerToChatHandler.java @@ -22,7 +22,7 @@ import java.util.logging.Handler; import java.util.logging.LogRecord; import org.bukkit.ChatColor; -import org.bukkit.entity.Player; +import org.bukkit.command.CommandSender; /** * Sends all logger messages to a player. @@ -33,14 +33,14 @@ public class LoggerToChatHandler extends Handler { /** * Player. */ - private Player player; + private CommandSender player; /** * Construct the object. * * @param player */ - public LoggerToChatHandler(Player player) { + public LoggerToChatHandler(CommandSender player) { this.player = player; } diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java b/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java index 2083a768..9e793dd2 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java +++ b/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java @@ -125,7 +125,6 @@ public void onEnable() { // Load permissions (new PermissionsResolverServerListener(perms)).register(this); - perms.load(); // Register events (new WorldGuardPlayerListener(this)).registerEvents(); diff --git a/src/com/sk89q/worldguard/bukkit/commands/ProtectionCommands.java b/src/com/sk89q/worldguard/bukkit/commands/ProtectionCommands.java index ecad9f95..ee3fe27e 100644 --- a/src/com/sk89q/worldguard/bukkit/commands/ProtectionCommands.java +++ b/src/com/sk89q/worldguard/bukkit/commands/ProtectionCommands.java @@ -30,4 +30,11 @@ public class ProtectionCommands { public static void region(CommandContext args, WorldGuardPlugin plugin, CommandSender sender) throws CommandException { } + + @Command(aliases = {"worldguard"}, + desc = "WorldGuard commands") + @NestedCommand({WorldGuardCommands.class}) + public static void worldGuard(CommandContext args, WorldGuardPlugin plugin, + CommandSender sender) throws CommandException { + } } diff --git a/src/com/sk89q/worldguard/bukkit/commands/WorldGuardCommands.java b/src/com/sk89q/worldguard/bukkit/commands/WorldGuardCommands.java new file mode 100644 index 00000000..823170f6 --- /dev/null +++ b/src/com/sk89q/worldguard/bukkit/commands/WorldGuardCommands.java @@ -0,0 +1,82 @@ +// $Id$ +/* + * WorldGuard + * Copyright (C) 2010 sk89q + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package com.sk89q.worldguard.bukkit.commands; + +import java.util.logging.Level; +import java.util.logging.Logger; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import com.sk89q.minecraft.util.commands.Command; +import com.sk89q.minecraft.util.commands.CommandContext; +import com.sk89q.minecraft.util.commands.CommandException; +import com.sk89q.minecraft.util.commands.CommandPermissions; +import com.sk89q.worldguard.bukkit.LoggerToChatHandler; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; + +public class WorldGuardCommands { + + @Command(aliases = {"version"}, + usage = "", + desc = "Get the WorldGuard version", + flags = "", min = 0, max = 0) + public static void version(CommandContext args, WorldGuardPlugin plugin, + CommandSender sender) throws CommandException { + sender.sendMessage(ChatColor.YELLOW + + "WorldGuard " + plugin.getDescription().getVersion()); + sender.sendMessage(ChatColor.YELLOW + + "http://www.sk89q.com"); + } + + @Command(aliases = {"reload"}, + usage = "", + desc = "Reload WorldGuard configuration", + flags = "", min = 0, max = 0) + @CommandPermissions({"worldguard.reload"}) + public static void relload(CommandContext args, WorldGuardPlugin plugin, + CommandSender sender) throws CommandException { + + LoggerToChatHandler handler = null; + Logger minecraftLogger = null; + + if (sender instanceof Player) { + handler = new LoggerToChatHandler(sender); + handler.setLevel(Level.ALL); + minecraftLogger = Logger.getLogger("Minecraft"); + minecraftLogger.addHandler(handler); + } + + try { + plugin.getGlobalConfiguration().unload(); + plugin.getGlobalRegionManager().unload(); + plugin.getGlobalConfiguration().load(); + plugin.getGlobalRegionManager().preload(); + sender.sendMessage("WorldGuard configuration reloaded."); + } catch (Throwable t) { + sender.sendMessage("Error while reloading: " + + t.getMessage()); + } finally { + if (minecraftLogger != null) { + minecraftLogger.removeHandler(handler); + } + } + + } +} diff --git a/src/com/sk89q/worldguard/protection/GlobalRegionManager.java b/src/com/sk89q/worldguard/protection/GlobalRegionManager.java index 2f8f02f2..8f9b90c9 100644 --- a/src/com/sk89q/worldguard/protection/GlobalRegionManager.java +++ b/src/com/sk89q/worldguard/protection/GlobalRegionManager.java @@ -138,7 +138,7 @@ public void load(World world) { managers.put(name, manager); manager.load(); - logger.warning("WorldGuard: " + manager.getRegions().size() + logger.info("WorldGuard: " + manager.getRegions().size() + " regions loaded for '" + name + "'"); // Store the last modification date so we can track changes