mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-12-18 23:27:35 +01:00
Removed JSON database support. Restored flag loading support to the CSV database so that they can be ported over to the new format.
This commit is contained in:
parent
94f0acf9f3
commit
056f8a57c7
@ -15,7 +15,6 @@
|
|||||||
<include name="WorldEdit.jar" />
|
<include name="WorldEdit.jar" />
|
||||||
<include name="iConomy.jar" />
|
<include name="iConomy.jar" />
|
||||||
<include name="prtree.jar" />
|
<include name="prtree.jar" />
|
||||||
<include name="gson-1.7-SNAPSHOT.jar" />
|
|
||||||
</fileset>
|
</fileset>
|
||||||
|
|
||||||
<target name="init">
|
<target name="init">
|
||||||
@ -50,7 +49,6 @@
|
|||||||
<copy tofile="${build.dir}/defaults/blacklist.txt" file="blacklist.txt"/>
|
<copy tofile="${build.dir}/defaults/blacklist.txt" file="blacklist.txt"/>
|
||||||
<jar jarfile="${dist.dir}/WorldGuard.jar" basedir="${build.dir}" manifest="manifest.mf">
|
<jar jarfile="${dist.dir}/WorldGuard.jar" basedir="${build.dir}" manifest="manifest.mf">
|
||||||
<zipgroupfileset dir="lib" includes="prtree.jar" />
|
<zipgroupfileset dir="lib" includes="prtree.jar" />
|
||||||
<zipgroupfileset dir="lib" includes="gson-1.7-SNAPSHOT.jar" />
|
|
||||||
</jar>
|
</jar>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
|
Binary file not shown.
@ -350,7 +350,7 @@ public static void flag(CommandContext args, WorldGuardPlugin plugin,
|
|||||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||||
|
|
||||||
String id = args.getString(0);
|
String id = args.getString(0);
|
||||||
String flagName = args.getString(0);
|
String flagName = args.getString(1);
|
||||||
String value = null;
|
String value = null;
|
||||||
|
|
||||||
if (args.argsLength() >= 3) {
|
if (args.argsLength() >= 3) {
|
||||||
@ -377,15 +377,27 @@ public static void flag(CommandContext args, WorldGuardPlugin plugin,
|
|||||||
// Now time to find the flag!
|
// Now time to find the flag!
|
||||||
for (Flag<?> flag : DefaultFlag.getFlags()) {
|
for (Flag<?> flag : DefaultFlag.getFlags()) {
|
||||||
// Try to detect the flag
|
// Try to detect the flag
|
||||||
if (flag.getName().replace("-", "").equalsIgnoreCase(flagName.replace("-", ""))
|
if (flag.getName().replace("-", "").equalsIgnoreCase(flagName.replace("-", ""))) {
|
||||||
|| flagName.equals(flag.getLegacyCode())) {
|
|
||||||
foundFlag = flag;
|
foundFlag = flag;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foundFlag == null) {
|
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) {
|
if (value != null) {
|
||||||
|
@ -138,6 +138,9 @@ public void load(World world) {
|
|||||||
managers.put(name, manager);
|
managers.put(name, manager);
|
||||||
manager.load();
|
manager.load();
|
||||||
|
|
||||||
|
logger.warning("WorldGuard: " + manager.getRegions().size() + " "
|
||||||
|
+ " regions loaded for '" + name + "'");
|
||||||
|
|
||||||
// Store the last modification date so we can track changes
|
// Store the last modification date so we can track changes
|
||||||
lastModified.put(name, file.lastModified());
|
lastModified.put(name, file.lastModified());
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
|
|
||||||
package com.sk89q.worldguard.protection.databases;
|
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.managers.RegionManager;
|
||||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -29,7 +32,6 @@
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import au.com.bytecode.opencsv.CSVReader;
|
import au.com.bytecode.opencsv.CSVReader;
|
||||||
import au.com.bytecode.opencsv.CSVWriter;
|
|
||||||
import com.sk89q.worldedit.BlockVector;
|
import com.sk89q.worldedit.BlockVector;
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||||
@ -69,44 +71,7 @@ public CSVDatabase(File file) {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void save() throws IOException {
|
public void save() throws IOException {
|
||||||
CSVWriter writer = new CSVWriter(new FileWriter(file));
|
throw new UnsupportedOperationException("CSV format is no longer implemented");
|
||||||
|
|
||||||
try {
|
|
||||||
for (Map.Entry<String,ProtectedRegion> 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) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -154,12 +119,12 @@ public void load() throws IOException {
|
|||||||
|
|
||||||
int priority = entries.get(8) == null ? 0 : Integer.parseInt(entries.get(8));
|
int priority = entries.get(8) == null ? 0 : Integer.parseInt(entries.get(8));
|
||||||
String ownersData = entries.get(9);
|
String ownersData = entries.get(9);
|
||||||
/*String flagsData = entries.get(10);
|
String flagsData = entries.get(10);
|
||||||
String enterMessage = nullEmptyString(entries.get(11));*/
|
//String enterMessage = nullEmptyString(entries.get(11));
|
||||||
|
|
||||||
ProtectedRegion region = new ProtectedCuboidRegion(id, min, max);
|
ProtectedRegion region = new ProtectedCuboidRegion(id, min, max);
|
||||||
region.setPriority(priority);
|
region.setPriority(priority);
|
||||||
//region.setFlags(parseFlags(flagsData));
|
parseFlags(region, flagsData);
|
||||||
region.setOwners(this.parseDomains(ownersData));
|
region.setOwners(this.parseDomains(ownersData));
|
||||||
regions.put(id, region);
|
regions.put(id, region);
|
||||||
} else if (type.equalsIgnoreCase("cuboid.2")) {
|
} else if (type.equalsIgnoreCase("cuboid.2")) {
|
||||||
@ -179,13 +144,13 @@ public void load() throws IOException {
|
|||||||
String parentId = entries.get(9);
|
String parentId = entries.get(9);
|
||||||
String ownersData = entries.get(10);
|
String ownersData = entries.get(10);
|
||||||
String membersData = entries.get(11);
|
String membersData = entries.get(11);
|
||||||
/*String flagsData = entries.get(12);
|
String flagsData = entries.get(12);
|
||||||
String enterMessage = nullEmptyString(entries.get(13));
|
//String enterMessage = nullEmptyString(entries.get(13));
|
||||||
String leaveMessage = nullEmptyString(entries.get(14));*/
|
//String leaveMessage = nullEmptyString(entries.get(14));
|
||||||
|
|
||||||
ProtectedRegion region = new ProtectedCuboidRegion(id, min, max);
|
ProtectedRegion region = new ProtectedCuboidRegion(id, min, max);
|
||||||
region.setPriority(priority);
|
region.setPriority(priority);
|
||||||
//region.setFlags(parseFlags(flagsData));
|
parseFlags(region, flagsData);
|
||||||
region.setOwners(this.parseDomains(ownersData));
|
region.setOwners(this.parseDomains(ownersData));
|
||||||
region.setMembers(this.parseDomains(membersData));
|
region.setMembers(this.parseDomains(membersData));
|
||||||
regions.put(id, region);
|
regions.put(id, region);
|
||||||
@ -287,15 +252,12 @@ private DefaultDomain parseDomains(String data) {
|
|||||||
* Used to parse the list of flags.
|
* Used to parse the list of flags.
|
||||||
*
|
*
|
||||||
* @param data
|
* @param data
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
/*
|
private void parseFlags(ProtectedRegion region, String data) {
|
||||||
private AreaFlags parseFlags(String data) {
|
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
return new AreaFlags();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AreaFlags flags = new AreaFlags();
|
|
||||||
State curState = State.ALLOW;
|
State curState = State.ALLOW;
|
||||||
|
|
||||||
for (int i = 0; i < data.length(); i++) {
|
for (int i = 0; i < data.length(); i++) {
|
||||||
@ -305,24 +267,26 @@ private AreaFlags parseFlags(String data) {
|
|||||||
} else if (k == '-') {
|
} else if (k == '-') {
|
||||||
curState = State.DENY;
|
curState = State.DENY;
|
||||||
} else {
|
} else {
|
||||||
String flag;
|
String flagStr;
|
||||||
if (k == '_') {
|
if (k == '_') {
|
||||||
if (i == data.length() - 1) {
|
if (i == data.length() - 1) {
|
||||||
logger.warning("_ read ahead fail");
|
logger.warning("_ read ahead fail");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
flag = "_" + data.charAt(i + 1);
|
flagStr = "_" + data.charAt(i + 1);
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
|
logger.warning("_? custom flags are no longer supported");
|
||||||
|
continue;
|
||||||
} else {
|
} 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.
|
* Used to write the list of domains.
|
||||||
@ -330,7 +294,7 @@ private AreaFlags parseFlags(String data) {
|
|||||||
* @param domain
|
* @param domain
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private String writeDomains(DefaultDomain domain) {
|
/* private String writeDomains(DefaultDomain domain) {
|
||||||
StringBuilder str = new StringBuilder();
|
StringBuilder str = new StringBuilder();
|
||||||
|
|
||||||
for (String player : domain.getPlayers()) {
|
for (String player : domain.getPlayers()) {
|
||||||
@ -343,7 +307,7 @@ private String writeDomains(DefaultDomain domain) {
|
|||||||
|
|
||||||
return str.length() > 0 ?
|
return str.length() > 0 ?
|
||||||
str.toString().substring(0, str.length() - 1) : "";
|
str.toString().substring(0, str.length() - 1) : "";
|
||||||
}
|
}*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to prepend '+' or '-' in front of a flag according
|
* Helper method to prepend '+' or '-' in front of a flag according
|
||||||
@ -380,22 +344,7 @@ protected String nullEmptyString(String str) {
|
|||||||
return 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<String, State> entry : flags.entrySet()) {
|
|
||||||
str.append(writeFlag(entry.getValue(), entry.getKey()));
|
|
||||||
}
|
|
||||||
return str.toString();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
/**
|
/**
|
||||||
* Get a list of protected regions.
|
* Get a list of protected regions.
|
||||||
*
|
*
|
||||||
|
@ -1,95 +0,0 @@
|
|||||||
// $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.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<String, ProtectedCuboidRegion> cRegions;
|
|
||||||
private HashMap<String, ProtectedPolygonalRegion> pRegions;
|
|
||||||
|
|
||||||
public JSONContainer(Map<String, ProtectedRegion> regions) {
|
|
||||||
|
|
||||||
this.cRegions = new HashMap<String, ProtectedCuboidRegion>();
|
|
||||||
this.pRegions = new HashMap<String, ProtectedPolygonalRegion>();
|
|
||||||
|
|
||||||
for (Map.Entry<String, ProtectedRegion> 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<String, ProtectedRegion> getRegions() {
|
|
||||||
HashMap<String, ProtectedRegion> ret = new HashMap<String, ProtectedRegion>();
|
|
||||||
ret.putAll(this.cRegions);
|
|
||||||
ret.putAll(this.pRegions);
|
|
||||||
|
|
||||||
for (Map.Entry<String, ProtectedRegion> 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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,176 +0,0 @@
|
|||||||
// $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.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<String, ProtectedRegion> 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<String, ProtectedRegion> getRegions() {
|
|
||||||
return regions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of protected regions.
|
|
||||||
*/
|
|
||||||
public void setRegions(Map<String, ProtectedRegion> regions) {
|
|
||||||
this.regions = regions;
|
|
||||||
}
|
|
||||||
}
|
|
@ -65,4 +65,20 @@ private DefaultFlag() {
|
|||||||
public static Flag<?>[] getFlags() {
|
public static Flag<?>[] getFlags() {
|
||||||
return flagsList;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user