/src/main/java/com/sk89q/worldguard/bukkit/commands/WorldGuardCommands.java
Java | 147 lines | 107 code | 20 blank | 20 comment | 9 complexity | b3a2101970667af2ebb6dd93b2d4c46d MD5 | raw file
- // $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.io.File;
- import java.io.IOException;
- 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.ReportWriter;
- import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
- import com.sk89q.worldguard.util.PastebinPoster;
- import com.sk89q.worldguard.util.PastebinPoster.PasteCallback;
-
- 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.getGlobalStateManager().unload();
- plugin.getGlobalRegionManager().unload();
- plugin.getGlobalStateManager().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);
- }
- }
- }
-
- @Command(aliases = {"report"},
- usage = "",
- desc = "Writes a report on WorldGuard",
- flags = "p", min = 0, max = 0)
- @CommandPermissions({"worldguard.report"})
- public static void report(CommandContext args, WorldGuardPlugin plugin,
- final CommandSender sender) throws CommandException {
-
- File dest = new File(plugin.getDataFolder(), "report.txt");
- ReportWriter report = new ReportWriter(plugin);
-
- try {
- report.write(dest);
- sender.sendMessage(ChatColor.YELLOW + "WorldGuard report written to "
- + dest.getAbsolutePath());
- } catch (IOException e) {
- throw new CommandException("Failed to write report: " + e.getMessage());
- }
-
- if (args.hasFlag('p')) {
- plugin.checkPermission(sender, "worldguard.report.pastebin");
-
- sender.sendMessage(ChatColor.YELLOW + "Now uploading to Pastebin...");
- PastebinPoster.paste(report.toString(), new PasteCallback() {
-
- public void handleSuccess(String url) {
- // Hope we don't have a thread safety issue here
- sender.sendMessage(ChatColor.YELLOW + "WorldGuard report (1 hour): " + url);
- }
-
- public void handleError(String err) {
- // Hope we don't have a thread safety issue here
- sender.sendMessage(ChatColor.YELLOW + "WorldGuard report pastebin error: " + err);
- }
- });
- }
-
- }
-
- @Command(aliases = {"flushstates", "clearstates"},
- usage = "[player]",
- desc = "Flush the state manager",
- flags = "", min = 0, max = 1)
- @CommandPermissions("worldguard.flushstates")
- public static void flushStates(CommandContext args, WorldGuardPlugin plugin,
- CommandSender sender) throws CommandException {
- if (args.argsLength() == 0) {
- plugin.getFlagStateManager().forgetAll();
- sender.sendMessage("Cleared all states.");
- } else {
- Player player = plugin.getServer().getPlayer(args.getString(0));
- if (player != null) {
- plugin.getFlagStateManager().forget(player);
- sender.sendMessage("Cleared states for player \"" + player.getName() + "\".");
- }
- }
- }
-
- }