Re-added /worldguard set of commands.

This commit is contained in:
sk89q 2011-04-02 02:33:23 -07:00
parent 43137c3e53
commit 7c15c2de41
5 changed files with 93 additions and 5 deletions

View File

@ -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;
}

View File

@ -125,7 +125,6 @@ public void onEnable() {
// Load permissions
(new PermissionsResolverServerListener(perms)).register(this);
perms.load();
// Register events
(new WorldGuardPlayerListener(this)).registerEvents();

View File

@ -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 {
}
}

View File

@ -0,0 +1,82 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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);
}
}
}
}

View File

@ -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