diff --git a/build.xml b/build.xml index 71f692c8..8fe74621 100644 --- a/build.xml +++ b/build.xml @@ -15,7 +15,6 @@ - @@ -50,7 +49,6 @@ - diff --git a/lib/gson-1.7-SNAPSHOT.jar b/lib/gson-1.7-SNAPSHOT.jar deleted file mode 100644 index 1ae52779..00000000 Binary files a/lib/gson-1.7-SNAPSHOT.jar and /dev/null differ diff --git a/src/com/sk89q/worldguard/bukkit/commands/RegionCommands.java b/src/com/sk89q/worldguard/bukkit/commands/RegionCommands.java index 0cf88acc..505f1e9a 100644 --- a/src/com/sk89q/worldguard/bukkit/commands/RegionCommands.java +++ b/src/com/sk89q/worldguard/bukkit/commands/RegionCommands.java @@ -350,7 +350,7 @@ public static void flag(CommandContext args, WorldGuardPlugin plugin, LocalPlayer localPlayer = plugin.wrapPlayer(player); String id = args.getString(0); - String flagName = args.getString(0); + String flagName = args.getString(1); String value = null; if (args.argsLength() >= 3) { @@ -377,15 +377,27 @@ public static void flag(CommandContext args, WorldGuardPlugin plugin, // Now time to find the flag! for (Flag flag : DefaultFlag.getFlags()) { // Try to detect the flag - if (flag.getName().replace("-", "").equalsIgnoreCase(flagName.replace("-", "")) - || flagName.equals(flag.getLegacyCode())) { + if (flag.getName().replace("-", "").equalsIgnoreCase(flagName.replace("-", ""))) { foundFlag = flag; break; } } if (foundFlag == null) { - throw new CommandException("Unknown flag specified: " + flagName); + StringBuilder list = new StringBuilder(); + + // Need to build a list + for (Flag flag : DefaultFlag.getFlags()) { + if (list.length() > 0) { + list.append(", "); + } + + list.append(flag.getName()); + } + + player.sendMessage(ChatColor.RED + "Unknown flag specified: " + flagName); + player.sendMessage(ChatColor.RED + "Available flags: " + list); + return; } if (value != null) { diff --git a/src/com/sk89q/worldguard/protection/GlobalRegionManager.java b/src/com/sk89q/worldguard/protection/GlobalRegionManager.java index e3857901..84d94782 100644 --- a/src/com/sk89q/worldguard/protection/GlobalRegionManager.java +++ b/src/com/sk89q/worldguard/protection/GlobalRegionManager.java @@ -138,6 +138,9 @@ public void load(World world) { managers.put(name, manager); manager.load(); + logger.warning("WorldGuard: " + manager.getRegions().size() + " " + + " regions loaded for '" + name + "'"); + // Store the last modification date so we can track changes lastModified.put(name, file.lastModified()); } catch (FileNotFoundException e) { diff --git a/src/com/sk89q/worldguard/protection/databases/CSVDatabase.java b/src/com/sk89q/worldguard/protection/databases/CSVDatabase.java index 4ff8beae..b1c93c05 100644 --- a/src/com/sk89q/worldguard/protection/databases/CSVDatabase.java +++ b/src/com/sk89q/worldguard/protection/databases/CSVDatabase.java @@ -19,6 +19,9 @@ package com.sk89q.worldguard.protection.databases; +import com.sk89q.worldguard.protection.flags.DefaultFlag; +import com.sk89q.worldguard.protection.flags.StateFlag; +import com.sk89q.worldguard.protection.flags.StateFlag.State; import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; import java.util.HashMap; @@ -29,7 +32,6 @@ import java.util.regex.Pattern; import java.io.*; import au.com.bytecode.opencsv.CSVReader; -import au.com.bytecode.opencsv.CSVWriter; import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.Vector; import com.sk89q.worldguard.domains.DefaultDomain; @@ -69,44 +71,7 @@ public CSVDatabase(File file) { */ @Override public void save() throws IOException { - CSVWriter writer = new CSVWriter(new FileWriter(file)); - - try { - for (Map.Entry entry : regions.entrySet()) { - String id = entry.getKey(); - ProtectedRegion region = entry.getValue(); - - if (!(region instanceof ProtectedCuboidRegion)) { - logger.warning("The CSV database only supports cuboid regions."); - continue; - } - - ProtectedCuboidRegion cuboid = (ProtectedCuboidRegion)region; - BlockVector min = cuboid.getMinimumPoint(); - BlockVector max = cuboid.getMaximumPoint(); - - writer.writeNext(new String[] { - id, - "cuboid.2", - String.valueOf(min.getBlockX()), - String.valueOf(min.getBlockY()), - String.valueOf(min.getBlockZ()), - String.valueOf(max.getBlockX()), - String.valueOf(max.getBlockY()), - String.valueOf(max.getBlockZ()), - String.valueOf(cuboid.getPriority()), - cuboid.getParent() != null ? cuboid.getParent().getId() : "", - writeDomains(cuboid.getOwners()), - writeDomains(cuboid.getMembers()), - //writeFlags(cuboid.getFlags()), - }); - } - } finally { - try { - writer.close(); - } catch (IOException e) { - } - } + throw new UnsupportedOperationException("CSV format is no longer implemented"); } /** @@ -154,12 +119,12 @@ public void load() throws IOException { int priority = entries.get(8) == null ? 0 : Integer.parseInt(entries.get(8)); String ownersData = entries.get(9); - /*String flagsData = entries.get(10); - String enterMessage = nullEmptyString(entries.get(11));*/ + String flagsData = entries.get(10); + //String enterMessage = nullEmptyString(entries.get(11)); ProtectedRegion region = new ProtectedCuboidRegion(id, min, max); region.setPriority(priority); - //region.setFlags(parseFlags(flagsData)); + parseFlags(region, flagsData); region.setOwners(this.parseDomains(ownersData)); regions.put(id, region); } else if (type.equalsIgnoreCase("cuboid.2")) { @@ -179,13 +144,13 @@ public void load() throws IOException { String parentId = entries.get(9); String ownersData = entries.get(10); String membersData = entries.get(11); - /*String flagsData = entries.get(12); - String enterMessage = nullEmptyString(entries.get(13)); - String leaveMessage = nullEmptyString(entries.get(14));*/ + String flagsData = entries.get(12); + //String enterMessage = nullEmptyString(entries.get(13)); + //String leaveMessage = nullEmptyString(entries.get(14)); ProtectedRegion region = new ProtectedCuboidRegion(id, min, max); region.setPriority(priority); - //region.setFlags(parseFlags(flagsData)); + parseFlags(region, flagsData); region.setOwners(this.parseDomains(ownersData)); region.setMembers(this.parseDomains(membersData)); regions.put(id, region); @@ -287,15 +252,12 @@ private DefaultDomain parseDomains(String data) { * Used to parse the list of flags. * * @param data - * @return */ -/* - private AreaFlags parseFlags(String data) { + private void parseFlags(ProtectedRegion region, String data) { if (data == null) { - return new AreaFlags(); + return; } - AreaFlags flags = new AreaFlags(); State curState = State.ALLOW; for (int i = 0; i < data.length(); i++) { @@ -305,24 +267,26 @@ private AreaFlags parseFlags(String data) { } else if (k == '-') { curState = State.DENY; } else { - String flag; + String flagStr; if (k == '_') { if (i == data.length() - 1) { logger.warning("_ read ahead fail"); break; } - flag = "_" + data.charAt(i + 1); + flagStr = "_" + data.charAt(i + 1); i++; + + logger.warning("_? custom flags are no longer supported"); + continue; } else { - flag = String.valueOf(k); + flagStr = String.valueOf(k); } - flags.setFlag(flag, curState); + + StateFlag flag = DefaultFlag.getLegacyFlag(flagStr); + region.setFlag(flag, curState); } } - - return flags; } -*/ /** * Used to write the list of domains. @@ -330,7 +294,7 @@ private AreaFlags parseFlags(String data) { * @param domain * @return */ - private String writeDomains(DefaultDomain domain) { +/* private String writeDomains(DefaultDomain domain) { StringBuilder str = new StringBuilder(); for (String player : domain.getPlayers()) { @@ -343,7 +307,7 @@ private String writeDomains(DefaultDomain domain) { return str.length() > 0 ? str.toString().substring(0, str.length() - 1) : ""; - } + }*/ /** * Helper method to prepend '+' or '-' in front of a flag according @@ -380,22 +344,7 @@ protected String nullEmptyString(String str) { return str; } } - - /** - * Used to write the list of flags. - * - * @param flags - * @return - */ -/* - private String writeFlags(AreaFlags flags) { - StringBuilder str = new StringBuilder(); - for (Map.Entry entry : flags.entrySet()) { - str.append(writeFlag(entry.getValue(), entry.getKey())); - } - return str.toString(); - } -*/ + /** * Get a list of protected regions. * diff --git a/src/com/sk89q/worldguard/protection/databases/JSONContainer.java b/src/com/sk89q/worldguard/protection/databases/JSONContainer.java deleted file mode 100644 index 38a4b14d..00000000 --- a/src/com/sk89q/worldguard/protection/databases/JSONContainer.java +++ /dev/null @@ -1,95 +0,0 @@ -// $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.protection.databases; - -import com.sk89q.worldguard.domains.DefaultDomain; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion; -import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; -import com.sk89q.worldguard.protection.regions.ProtectedRegion.CircularInheritanceException; -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Logger; - -/** - * - * @author Redecouverte - */ -public class JSONContainer { - - private static Logger logger = Logger.getLogger("Minecraft.WorldGuard"); - - private HashMap cRegions; - private HashMap pRegions; - - public JSONContainer(Map regions) { - - this.cRegions = new HashMap(); - this.pRegions = new HashMap(); - - for (Map.Entry entry : regions.entrySet()) { - String id = entry.getKey(); - ProtectedRegion region = entry.getValue(); - region.setParentId(); - - if (region instanceof ProtectedCuboidRegion) { - cRegions.put(id, (ProtectedCuboidRegion) region); - } else if (region instanceof ProtectedPolygonalRegion) { - pRegions.put(id, (ProtectedPolygonalRegion) region); - } else { - logger.info("regions of type '" + region.getClass().toString() - + "' are not supported for saving, yet."); - } - } - - } - - public Map getRegions() { - HashMap ret = new HashMap(); - ret.putAll(this.cRegions); - ret.putAll(this.pRegions); - - for (Map.Entry entry : ret.entrySet()) { - ProtectedRegion region = entry.getValue(); - - String parentId = region.getParentId(); - if (parentId != null) { - try { - region.setParent(ret.get(parentId)); - } catch (CircularInheritanceException ex) { - } - } else { - try { - region.setParent(null); - } catch (CircularInheritanceException ex) { - } - } - - if (region.getOwners() == null) { - region.setOwners(new DefaultDomain()); - } else if (region.getMembers() == null) { - region.setMembers(new DefaultDomain()); - } - - } - - return ret; - } -} diff --git a/src/com/sk89q/worldguard/protection/databases/JSONDatabase.java b/src/com/sk89q/worldguard/protection/databases/JSONDatabase.java deleted file mode 100644 index 11dd850a..00000000 --- a/src/com/sk89q/worldguard/protection/databases/JSONDatabase.java +++ /dev/null @@ -1,176 +0,0 @@ -// $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.protection.databases; - -import com.sk89q.worldguard.protection.managers.RegionManager; -import com.google.gson.Gson; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import java.io.BufferedInputStream; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.util.Map; -import java.util.logging.Logger; - -/** - * Represents a protected area database that uses JSON files. - * - * @author Redecouverte - */ -public class JSONDatabase implements ProtectionDatabase { - protected static Logger logger = Logger.getLogger("Minecraft.WorldGuard"); - - /** - * References the json db folder. - */ - private File file; - - /** - * Holds the list of regions. - */ - private Map regions; - - /** - * Construct the database with a path to a file. No file is read or written - * at this time. - * - * @param file - */ - public JSONDatabase(File file) { - this.file = file; - } - - /** - * Helper function to read a file into a String - */ - private static String readFileAsString(File file) - throws java.io.IOException { - byte[] buffer = new byte[(int) file.length()]; - BufferedInputStream f = null; - try { - f = new BufferedInputStream(new FileInputStream( - file.getAbsolutePath())); - f.read(buffer); - } finally { - if (f != null) { - try { - f.close(); - } catch (IOException ignored) { - } - } - } - - for (int i = 0; i < buffer.length; i++) { - if (buffer[i] < 0x20 || buffer[i] > 0x126) { - buffer[i] = 0x20; - } - } - - return new String(buffer); - } - - /** - * Load the database from file. - */ - public void load() throws IOException { - - Gson gson = new Gson(); - JSONContainer jContainer = gson.fromJson(readFileAsString(file), - JSONContainer.class); - this.regions = jContainer.getRegions(); - } - - /** - * Saves the database. - */ - public void save() throws IOException { - - Gson gson = new Gson(); - String jsonData = gson.toJson(new JSONContainer(this.regions), - JSONContainer.class); - writeStringToFile(jsonData, this.file); - } - - /** - * Writes a String to a file. - * - * @param string - * @param file - * @throws IOException - */ - public static void writeStringToFile(String string, File file) - throws IOException { - FileOutputStream output = null; - - try { - output = new FileOutputStream(file); - OutputStreamWriter streamWriter = new OutputStreamWriter(output, "utf-8"); - BufferedWriter writer = new BufferedWriter(streamWriter); - writer.write(string); - writer.close(); - } finally { - if (output != null) { - try { - output.close(); - } catch (IOException e) { - } - } - } - } - - /** - * Load the list of regions into a region manager. - * - * @throws IOException - */ - public void load(RegionManager manager) throws IOException { - load(); - manager.setRegions(regions); - } - - /** - * Save the list of regions from a region manager. - * - * @throws IOException - */ - public void save(RegionManager manager) throws IOException { - regions = manager.getRegions(); - save(); - } - - /** - * Get a list of protected regions. - * - * @return - */ - public Map getRegions() { - return regions; - } - - /** - * Get a list of protected regions. - */ - public void setRegions(Map regions) { - this.regions = regions; - } -} diff --git a/src/com/sk89q/worldguard/protection/flags/DefaultFlag.java b/src/com/sk89q/worldguard/protection/flags/DefaultFlag.java index 469128ab..d8bbd5fa 100644 --- a/src/com/sk89q/worldguard/protection/flags/DefaultFlag.java +++ b/src/com/sk89q/worldguard/protection/flags/DefaultFlag.java @@ -65,4 +65,20 @@ private DefaultFlag() { public static Flag[] getFlags() { return flagsList; } + + /** + * Get the legacy flag. + * + * @param flagString + * @return null if not found + */ + public static StateFlag getLegacyFlag(String flagString) { + for (Flag flag : flagsList) { + if (flag instanceof StateFlag && flagString.equals(flag.getLegacyCode())) { + return (StateFlag) flag; + } + } + + return null; + } }