summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2013-01-12 19:30:06 +0000
committerKHobbits <rob@khobbits.co.uk>2013-01-12 19:30:06 +0000
commitef1492a2a286876eeff767e72a88854646c36532 (patch)
treeb7d23278bf1c14ea6785b5fa5938e81aca1ee284
parent298ab846c126cb5a3a76ac883c614498cc4aaace (diff)
downloadEssentials-ef1492a2a286876eeff767e72a88854646c36532.tar
Essentials-ef1492a2a286876eeff767e72a88854646c36532.tar.gz
Essentials-ef1492a2a286876eeff767e72a88854646c36532.tar.lz
Essentials-ef1492a2a286876eeff767e72a88854646c36532.tar.xz
Essentials-ef1492a2a286876eeff767e72a88854646c36532.zip
Clean up userdata saving, to prevent CMI
Also update config section code to use newer bukkit methods
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsConf.java163
-rw-r--r--Essentials/src/com/earth2me/essentials/UserData.java27
2 files changed, 92 insertions, 98 deletions
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsConf.java b/Essentials/src/com/earth2me/essentials/EssentialsConf.java
index 70e683da4..175afb110 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsConf.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsConf.java
@@ -221,6 +221,69 @@ public class EssentialsConf extends YamlConfiguration
this.resourceClass = resClass;
}
+ public void save()
+ {
+ try
+ {
+ save(configFile);
+ }
+ catch (IOException ex)
+ {
+ LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
+ }
+ }
+
+ public void saveWithError() throws IOException
+ {
+ save(configFile);
+ }
+
+ @Override
+ public synchronized void save(final File file) throws IOException
+ {
+ if (file == null)
+ {
+ throw new IllegalArgumentException("File cannot be null");
+ }
+
+ Files.createParentDirs(file);
+
+ final String data = saveToString();
+
+ if (data.length() == 0)
+ {
+ return;
+ }
+
+ if (!configFile.exists())
+ {
+ try
+ {
+ LOGGER.log(Level.INFO, _("creatingEmptyConfig", configFile.toString()));
+ if (!configFile.createNewFile())
+ {
+ LOGGER.log(Level.SEVERE, _("failedToCreateConfig", configFile.toString()));
+ }
+ }
+ catch (IOException ex)
+ {
+ LOGGER.log(Level.SEVERE, _("failedToCreateConfig", configFile.toString()), ex);
+ }
+ }
+
+
+ final OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), UTF8);
+
+ try
+ {
+ writer.write(data);
+ }
+ finally
+ {
+ writer.close();
+ }
+ }
+
public boolean hasProperty(final String path)
{
return isSet(path);
@@ -305,94 +368,14 @@ public class EssentialsConf extends YamlConfiguration
set(path, map);
}
- public long getLong(final String path, final long def)
+ public void setProperty(String path, List object)
{
- try
- {
- final Number num = (Number)get(path);
- return num == null ? def : num.longValue();
- }
- catch (ClassCastException ex)
- {
- return def;
- }
+ set(path, new ArrayList(object));
}
- @Override
- public double getDouble(final String path, final double def)
+ public void setProperty(String path, Map object)
{
- try
- {
- Number num = (Number)get(path);
- return num == null ? def : num.doubleValue();
- }
- catch (ClassCastException ex)
- {
- return def;
- }
- }
-
- public void save()
- {
- try
- {
- save(configFile);
- }
- catch (IOException ex)
- {
- LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
- }
- }
-
- public void saveWithError() throws IOException
- {
- save(configFile);
- }
-
- @Override
- public synchronized void save(final File file) throws IOException
- {
- if (file == null)
- {
- throw new IllegalArgumentException("File cannot be null");
- }
-
- Files.createParentDirs(file);
-
- final String data = saveToString();
-
- if (data.length() == 0)
- {
- return;
- }
-
- if (!configFile.exists())
- {
- try
- {
- LOGGER.log(Level.INFO, _("creatingEmptyConfig", configFile.toString()));
- if (!configFile.createNewFile())
- {
- LOGGER.log(Level.SEVERE, _("failedToCreateConfig", configFile.toString()));
- }
- }
- catch (IOException ex)
- {
- LOGGER.log(Level.SEVERE, _("failedToCreateConfig", configFile.toString()), ex);
- }
- }
-
-
- final OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), UTF8);
-
- try
- {
- writer.write(data);
- }
- finally
- {
- writer.close();
- }
+ set(path, new LinkedHashMap(object));
}
public Object getProperty(String path)
@@ -465,6 +448,12 @@ public class EssentialsConf extends YamlConfiguration
}
@Override
+ public synchronized double getDouble(final String path, final double def)
+ {
+ return super.getDouble(path, def);
+ }
+
+ @Override
public synchronized List<Double> getDoubleList(String path)
{
return super.getDoubleList(path);
@@ -525,6 +514,12 @@ public class EssentialsConf extends YamlConfiguration
}
@Override
+ public synchronized long getLong(final String path, final long def)
+ {
+ return super.getLong(path, def);
+ }
+
+ @Override
public synchronized List<Long> getLongList(String path)
{
return super.getLongList(path);
diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java
index 94b1631f5..930a9c913 100644
--- a/Essentials/src/com/earth2me/essentials/UserData.java
+++ b/Essentials/src/com/earth2me/essentials/UserData.java
@@ -5,7 +5,6 @@ import java.io.File;
import java.util.*;
import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection;
-import org.bukkit.configuration.MemoryConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@@ -794,44 +793,44 @@ public abstract class UserData extends PlayerExtension implements IConf
{
return config.getBoolean("powertoolsenabled", true);
}
- private ConfigurationSection kitTimestamps;
-
- private ConfigurationSection _getKitTimestamps()
+ private Map<String, Long> kitTimestamps;
+
+ private Map<String, Long> _getKitTimestamps()
{
-
+
if (config.isConfigurationSection("timestamps.kits"))
{
final ConfigurationSection section = config.getConfigurationSection("timestamps.kits");
- final ConfigurationSection newSection = new MemoryConfiguration();
+ final Map<String, Long> timestamps = new HashMap<String, Long>();
for (String command : section.getKeys(false))
{
if (section.isLong(command))
{
- newSection.set(command.toLowerCase(Locale.ENGLISH), section.getLong(command));
+ timestamps.put(command.toLowerCase(Locale.ENGLISH), section.getLong(command));
}
else if (section.isInt(command))
{
- newSection.set(command.toLowerCase(Locale.ENGLISH), (long)section.getInt(command));
+ timestamps.put(command.toLowerCase(Locale.ENGLISH), (long)section.getInt(command));
}
}
- return newSection;
+ return timestamps;
}
- return new MemoryConfiguration();
+ return new HashMap<String, Long>();
}
-
+
public long getKitTimestamp(String name)
{
name = name.replace('.', '_').replace('/', '_');
- if (kitTimestamps != null)
+ if (kitTimestamps != null && kitTimestamps.containsKey(name))
{
- return kitTimestamps.getLong(name, 0l);
+ return kitTimestamps.get(name);
}
return 0l;
}
public void setKitTimestamp(final String name, final long time)
{
- kitTimestamps.set(name.toLowerCase(Locale.ENGLISH), time);
+ kitTimestamps.put(name.toLowerCase(Locale.ENGLISH), time);
config.setProperty("timestamps.kits", kitTimestamps);
config.save();
}