From 4c38e10fe16a10ce8780b2fc707509d6d05b8b2f Mon Sep 17 00:00:00 2001 From: sk89q Date: Fri, 1 Apr 2011 23:31:28 -0700 Subject: [PATCH] Re-added /region save and /region load. --- .../bukkit/commands/RegionCommands.java | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/src/com/sk89q/worldguard/bukkit/commands/RegionCommands.java b/src/com/sk89q/worldguard/bukkit/commands/RegionCommands.java index 3a49eafb..0d4b76c8 100644 --- a/src/com/sk89q/worldguard/bukkit/commands/RegionCommands.java +++ b/src/com/sk89q/worldguard/bukkit/commands/RegionCommands.java @@ -468,4 +468,86 @@ public static void remove(CommandContext args, WorldGuardPlugin plugin, + e.getMessage()); } } + + @Command(aliases = {"load"}, + usage = "[world]", + desc = "Reload regions from file", + flags = "", min = 0, max = 1) + public static void load(CommandContext args, WorldGuardPlugin plugin, + CommandSender sender) throws CommandException { + + World world = null; + + if (args.argsLength() > 0) { + world = plugin.matchWorld(sender, args.getString(0)); + } + + if (world != null) { + RegionManager mgr = plugin.getGlobalRegionManager().get(world); + + try { + mgr.load(); + sender.sendMessage(ChatColor.YELLOW + + "Regions for '" + world.getName() + "' load."); + } catch (IOException e) { + throw new CommandException("Failed to read regions file: " + + e.getMessage()); + } + } else { + for (World w : plugin.getServer().getWorlds()) { + RegionManager mgr = plugin.getGlobalRegionManager().get(w); + + try { + mgr.load(); + } catch (IOException e) { + throw new CommandException("Failed to read regions file: " + + e.getMessage()); + } + } + + sender.sendMessage(ChatColor.YELLOW + + "Region databases loaded."); + } + } + + @Command(aliases = {"save", "write"}, + usage = "[world]", + desc = "Re-save regions to file", + flags = "", min = 0, max = 1) + public static void save(CommandContext args, WorldGuardPlugin plugin, + CommandSender sender) throws CommandException { + + World world = null; + + if (args.argsLength() > 0) { + world = plugin.matchWorld(sender, args.getString(0)); + } + + if (world != null) { + RegionManager mgr = plugin.getGlobalRegionManager().get(world); + + try { + mgr.save(); + sender.sendMessage(ChatColor.YELLOW + + "Regions for '" + world.getName() + "' saved."); + } catch (IOException e) { + throw new CommandException("Failed to write regions file: " + + e.getMessage()); + } + } else { + for (World w : plugin.getServer().getWorlds()) { + RegionManager mgr = plugin.getGlobalRegionManager().get(w); + + try { + mgr.save(); + } catch (IOException e) { + throw new CommandException("Failed to write regions file: " + + e.getMessage()); + } + } + + sender.sendMessage(ChatColor.YELLOW + + "Region databases saved."); + } + } }