summaryrefslogtreecommitdiffstats
path: root/Essentials/src/com/earth2me/essentials/EssentialsConf.java
diff options
context:
space:
mode:
Diffstat (limited to 'Essentials/src/com/earth2me/essentials/EssentialsConf.java')
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsConf.java67
1 files changed, 46 insertions, 21 deletions
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsConf.java b/Essentials/src/com/earth2me/essentials/EssentialsConf.java
index c48f9f987..35252532f 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsConf.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsConf.java
@@ -1,13 +1,10 @@
package com.earth2me.essentials;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
+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;
import java.util.logging.Logger;
@@ -15,6 +12,7 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
+import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.config.Configuration;
@@ -44,7 +42,7 @@ public class EssentialsConf extends Configuration
{
if (!configFile.getParentFile().mkdirs())
{
- LOGGER.log(Level.SEVERE, Util.format("failedToCreateConfig", configFile.toString()));
+ LOGGER.log(Level.SEVERE, _("failedToCreateConfig", configFile.toString()));
}
}
// This will delete files where the first character is 0. In most cases they are broken.
@@ -87,22 +85,22 @@ public class EssentialsConf extends Configuration
{
if (templateName != null)
{
- LOGGER.log(Level.INFO, Util.format("creatingConfigFromTemplate", configFile.toString()));
+ LOGGER.log(Level.INFO, _("creatingConfigFromTemplate", configFile.toString()));
createFromTemplate();
}
else
{
try
{
- LOGGER.log(Level.INFO, Util.format("creatingEmptyConfig", configFile.toString()));
+ LOGGER.log(Level.INFO, _("creatingEmptyConfig", configFile.toString()));
if (!configFile.createNewFile())
{
- LOGGER.log(Level.SEVERE, Util.format("failedToCreateConfig", configFile.toString()));
+ LOGGER.log(Level.SEVERE, _("failedToCreateConfig", configFile.toString()));
}
}
catch (IOException ex)
{
- LOGGER.log(Level.SEVERE, Util.format("failedToCreateConfig", configFile.toString()), ex);
+ LOGGER.log(Level.SEVERE, _("failedToCreateConfig", configFile.toString()), ex);
}
}
}
@@ -113,7 +111,7 @@ public class EssentialsConf extends Configuration
}
catch (RuntimeException e)
{
- LOGGER.log(Level.INFO, "File: " + configFile.toString());
+ LOGGER.log(Level.SEVERE, "File broken: " + configFile.toString());
throw e;
}
@@ -132,7 +130,7 @@ public class EssentialsConf extends Configuration
istr = resourceClass.getResourceAsStream(templateName);
if (istr == null)
{
- LOGGER.log(Level.SEVERE, Util.format("couldNotFindTemplate", templateName));
+ LOGGER.log(Level.SEVERE, _("couldNotFindTemplate", templateName));
return;
}
ostr = new FileOutputStream(configFile);
@@ -147,8 +145,7 @@ public class EssentialsConf extends Configuration
}
catch (IOException ex)
{
- LOGGER.log(Level.SEVERE, Util.format("failedToWriteConfig", configFile.toString()), ex);
- return;
+ LOGGER.log(Level.SEVERE, _("failedToWriteConfig", configFile.toString()), ex);
}
finally
{
@@ -172,7 +169,7 @@ public class EssentialsConf extends Configuration
}
catch (IOException ex)
{
- LOGGER.log(Level.SEVERE, Util.format("failedToCloseConfig", configFile.toString()), ex);
+ LOGGER.log(Level.SEVERE, _("failedToCloseConfig", configFile.toString()), ex);
}
}
}
@@ -208,7 +205,7 @@ public class EssentialsConf extends Configuration
final World world = server.getWorld(worldName);
if (world == null)
{
- throw new Exception(Util.i18n("invalidWorld"));
+ throw new Exception(_("invalidWorld"));
}
return new Location(world,
getDouble((path == null ? "" : path + ".") + "x", 0),
@@ -230,11 +227,29 @@ public class EssentialsConf extends Configuration
public ItemStack getItemStack(final String path)
{
- return new ItemStack(
+ final ItemStack stack = new ItemStack(
Material.valueOf(getString(path + ".type", "AIR")),
getInt(path + ".amount", 1),
- (short)getInt(path + ".damage", 0)/*,
- (byte)getInt(path + ".data", 0)*/);
+ (short)getInt(path + ".damage", 0));
+ final List<String> enchants = getKeys(path + ".enchant");
+ if (enchants != null)
+ {
+ for (String enchant : enchants)
+ {
+ final Enchantment enchantment = Enchantment.getByName(enchant.toUpperCase(Locale.ENGLISH));
+ if (enchantment == null)
+ {
+ continue;
+ }
+ final int level = getInt(path + ".enchant." + enchant, enchantment.getStartLevel());
+ stack.addUnsafeEnchantment(enchantment, level);
+ }
+ }
+ return stack;
+ /*
+ * ,
+ * (byte)getInt(path + ".data", 0)
+ */
}
public void setProperty(final String path, final ItemStack stack)
@@ -243,6 +258,16 @@ public class EssentialsConf extends Configuration
map.put("type", stack.getType().toString());
map.put("amount", stack.getAmount());
map.put("damage", stack.getDurability());
+ Map<Enchantment, Integer> enchantments = stack.getEnchantments();
+ if (!enchantments.isEmpty())
+ {
+ Map<String, Integer> enchant = new HashMap<String, Integer>();
+ for (Map.Entry<Enchantment, Integer> entry : enchantments.entrySet())
+ {
+ enchant.put(entry.getKey().getName().toLowerCase(Locale.ENGLISH), entry.getValue());
+ }
+ map.put("enchant", enchant);
+ }
// getData().getData() is broken
//map.put("data", stack.getDurability());
setProperty(path, map);