summaryrefslogtreecommitdiffstats
path: root/Essentials2Compat
diff options
context:
space:
mode:
Diffstat (limited to 'Essentials2Compat')
-rw-r--r--Essentials2Compat/src/com/earth2me/essentials/EssentialsConf.java81
-rw-r--r--Essentials2Compat/src/com/earth2me/essentials/EssentialsUpgrade.java9
2 files changed, 58 insertions, 32 deletions
diff --git a/Essentials2Compat/src/com/earth2me/essentials/EssentialsConf.java b/Essentials2Compat/src/com/earth2me/essentials/EssentialsConf.java
index 4b509206d..0e8004895 100644
--- a/Essentials2Compat/src/com/earth2me/essentials/EssentialsConf.java
+++ b/Essentials2Compat/src/com/earth2me/essentials/EssentialsConf.java
@@ -3,7 +3,6 @@ package com.earth2me.essentials;
import static com.earth2me.essentials.I18n._;
import java.io.*;
import java.util.HashMap;
-import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.logging.Level;
@@ -12,13 +11,15 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.configuration.InvalidConfigurationException;
+import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
-import org.bukkit.util.config.Configuration;
@Deprecated
-public class EssentialsConf extends Configuration
+public class EssentialsConf extends YamlConfiguration
{
private static final Logger LOGGER = Logger.getLogger("Minecraft");
private transient File configFile;
@@ -27,15 +28,10 @@ public class EssentialsConf extends Configuration
public EssentialsConf(final File configFile)
{
- super(configFile);
+ super();
this.configFile = configFile;
- if (this.root == null)
- {
- this.root = new HashMap<String, Object>();
- }
}
- @Override
public void load()
{
configFile = configFile.getAbsoluteFile();
@@ -106,19 +102,24 @@ public class EssentialsConf extends Configuration
}
}
+
try
{
- super.load();
+ super.load(configFile);
}
- catch (RuntimeException e)
+ catch (FileNotFoundException ex)
{
- LOGGER.log(Level.SEVERE, "File broken: " + configFile.toString());
- throw e;
+ LOGGER.log(Level.SEVERE, null, ex);
}
-
- if (this.root == null)
+ catch (IOException ex)
+ {
+ LOGGER.log(Level.SEVERE, null, ex);
+ }
+ catch (InvalidConfigurationException ex)
{
- this.root = new HashMap<String, Object>();
+ File broken = new File(configFile.getAbsolutePath() + ".broken." + System.currentTimeMillis());
+ configFile.renameTo(broken);
+ LOGGER.log(Level.SEVERE, "The file " + configFile.toString() + " is broken, it has been renamed to " + broken.toString(), ex.getCause());
}
}
@@ -193,7 +194,7 @@ public class EssentialsConf extends Configuration
public boolean hasProperty(final String path)
{
- return getProperty(path) != null;
+ return isSet(path);
}
public Location getLocation(final String path, final Server server) throws Exception
@@ -218,24 +219,25 @@ public class EssentialsConf extends Configuration
public void setProperty(final String path, final Location loc)
{
- setProperty((path == null ? "" : path + ".") + "world", loc.getWorld().getName());
- setProperty((path == null ? "" : path + ".") + "x", loc.getX());
- setProperty((path == null ? "" : path + ".") + "y", loc.getY());
- setProperty((path == null ? "" : path + ".") + "z", loc.getZ());
- setProperty((path == null ? "" : path + ".") + "yaw", loc.getYaw());
- setProperty((path == null ? "" : path + ".") + "pitch", loc.getPitch());
+ set((path == null ? "" : path + ".") + "world", loc.getWorld().getName());
+ set((path == null ? "" : path + ".") + "x", loc.getX());
+ set((path == null ? "" : path + ".") + "y", loc.getY());
+ set((path == null ? "" : path + ".") + "z", loc.getZ());
+ set((path == null ? "" : path + ".") + "yaw", loc.getYaw());
+ set((path == null ? "" : path + ".") + "pitch", loc.getPitch());
}
+ @Override
public ItemStack getItemStack(final String path)
{
final ItemStack stack = new ItemStack(
Material.valueOf(getString(path + ".type", "AIR")),
getInt(path + ".amount", 1),
(short)getInt(path + ".damage", 0));
- final List<String> enchants = getKeys(path + ".enchant");
+ final ConfigurationSection enchants = getConfigurationSection(path + ".enchant");
if (enchants != null)
{
- for (String enchant : enchants)
+ for (String enchant : enchants.getKeys(false))
{
final Enchantment enchantment = Enchantment.getByName(enchant.toUpperCase(Locale.ENGLISH));
if (enchantment == null)
@@ -271,14 +273,14 @@ public class EssentialsConf extends Configuration
}
// getData().getData() is broken
//map.put("data", stack.getDurability());
- setProperty(path, map);
+ set(path, map);
}
public long getLong(final String path, final long def)
{
try
{
- final Number num = (Number)getProperty(path);
+ final Number num = (Number)get(path);
return num == null ? def : num.longValue();
}
catch (ClassCastException ex)
@@ -292,7 +294,7 @@ public class EssentialsConf extends Configuration
{
try
{
- Number num = (Number)getProperty(path);
+ Number num = (Number)get(path);
return num == null ? def : num.doubleValue();
}
catch (ClassCastException ex)
@@ -300,4 +302,27 @@ public class EssentialsConf extends Configuration
return def;
}
}
+
+ public void save() {
+ try
+ {
+ save(configFile);
+ }
+ catch (IOException ex)
+ {
+ LOGGER.log(Level.SEVERE, null, ex);
+ }
+ }
+
+ public Object getProperty(String path) {
+ return get(path);
+ }
+
+ public void setProperty(String path, Object object) {
+ set(path, object);
+ }
+
+ public void removeProperty(String path) {
+ set(path, null);
+ }
}
diff --git a/Essentials2Compat/src/com/earth2me/essentials/EssentialsUpgrade.java b/Essentials2Compat/src/com/earth2me/essentials/EssentialsUpgrade.java
index 9bb5a2ec8..9338559cb 100644
--- a/Essentials2Compat/src/com/earth2me/essentials/EssentialsUpgrade.java
+++ b/Essentials2Compat/src/com/earth2me/essentials/EssentialsUpgrade.java
@@ -96,7 +96,7 @@ public class EssentialsUpgrade
}
final EssentialsConf conf = new EssentialsConf(configFile);
conf.load();
- List<String> lines = conf.getStringList(name, null);
+ List<String> lines = conf.getStringList(name);
if (lines != null && !lines.isEmpty())
{
if (!file.createNewFile())
@@ -329,7 +329,7 @@ public class EssentialsUpgrade
config.setProperty("homes.home", defloc);
}
- List<String> worlds = config.getKeys("home.worlds");
+ Set<String> worlds = config.getConfigurationSection("home.worlds").getKeys(false);
Location loc;
String worldName;
@@ -384,6 +384,7 @@ public class EssentialsUpgrade
* ((Number)vals.get(4)).floatValue())); } } } } usersFile.renameTo(new File(usersFile.getAbsolutePath() + ".old"));
* }
*/
+
private void convertWarps()
{
final File warpsFolder = new File(ess.getDataFolder(), "warps");
@@ -610,7 +611,7 @@ public class EssentialsUpgrade
if (!config.hasProperty("spawns"))
{
final Spawns spawns = new Spawns();
- List<String> keys = config.getKeys();
+ Set<String> keys = config.getKeys(false);
for (String group : keys)
{
Location loc = getFakeLocation(config, group);
@@ -657,7 +658,7 @@ public class EssentialsUpgrade
if (!config.hasProperty("jails"))
{
final com.earth2me.essentials.settings.Jails jails = new com.earth2me.essentials.settings.Jails();
- List<String> keys = config.getKeys();
+ Set<String> keys = config.getKeys(false);
for (String jailName : keys)
{
Location loc = getFakeLocation(config, jailName);