diff --git a/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/LimitedCreativeCore.java b/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/LimitedCreativeCore.java index 58d05f6..ed0bf65 100644 --- a/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/LimitedCreativeCore.java +++ b/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/LimitedCreativeCore.java @@ -10,6 +10,8 @@ public class LimitedCreativeCore extends JavaPlugin { public Configuration config; public WorldGuardIntegration worldguard; public static LimitedCreativeCore plugin; + + public static boolean serializeFallBack = false; @Override public void onDisable() { @@ -20,6 +22,8 @@ public class LimitedCreativeCore extends JavaPlugin { public void onEnable() { plugin = this; + serializeFallBack = versionCompare(getServer().getBukkitVersion().replaceAll("-.*$", ""), "1.1") < 0; + config = new Configuration(this.getConfig()); Listener.register(this); Commands.register(this); @@ -32,4 +36,18 @@ public class LimitedCreativeCore extends JavaPlugin { PluginDescriptionFile df = this.getDescription(); logger.info("["+df.getName() + " v" + df.getVersion() + "] done loading."); } + + public static int versionCompare(String vers1, String vers2) { + String[] v1 = vers1.split("\\."); + String[] v2 = vers2.split("\\."); + int i = 0; + while (i < v1.length && i < v2.length && v1[i].equals(v2[i])) { + i++; + } + if (i < v1.length && i < v2.length) { + int diff = new Integer(v1[i]).compareTo(new Integer(v2[i])); + return diff < 0 ? -1 : (diff == 0 ? 0 : 1); + } + return v1.length < v2.length ? -1 : (v1.length == v2.length ? 0 : 1); + } } diff --git a/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/Listener.java b/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/Listener.java index 69d5654..9f8c1f6 100644 --- a/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/Listener.java +++ b/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/Listener.java @@ -65,7 +65,7 @@ public final class Listener { event.setCancelled(true); } if (plugin.config.getSignBlock() && block.getState() instanceof Sign) { - event.getPlayer().sendMessage("Access to interact with signs is not allowed in creative mode"); + event.getPlayer().sendMessage("To interact with signs is not allowed in creative mode"); event.setCancelled(true); } } diff --git a/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/serialize/Items.java b/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/serialize/Items.java index e694cf5..7457d69 100644 --- a/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/serialize/Items.java +++ b/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/serialize/Items.java @@ -1,8 +1,14 @@ package de.jaschastarke.minecraft.limitedcreative.serialize; +import java.util.Map; + +import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; +import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore; + public class Items implements Storeable { private PlayerInventory inv; public Items(PlayerInventory pi) { @@ -13,7 +19,7 @@ public class Items implements Storeable { public void store(ConfigurationSection section) { for (int i = 0; i < inv.getSize(); i++) { if (inv.getItem(i) != null && inv.getItem(i).getTypeId() != 0) - section.set(String.valueOf(i), inv.getItem(i)); + sectionSetItem(section, String.valueOf(i), inv.getItem(i)); } } @@ -21,10 +27,32 @@ public class Items implements Storeable { public void restore(ConfigurationSection section) { inv.clear(); for (int i = 0; i < inv.getSize(); i++) { - if (section.contains(String.valueOf(i))) { - inv.setItem(i, section.getItemStack(String.valueOf(i))); - } + if (section.contains(String.valueOf(i))) + inv.setItem(i, sectionGetItem(section, String.valueOf(i))); } } + public static void sectionSetItem(ConfigurationSection section, String path, ItemStack item) { + if (!LimitedCreativeCore.serializeFallBack) { + section.set(path, item); + } else { // compatibility fallback + Map serialize = item.serialize(); + if (serialize.containsKey("type") && serialize.get("type") instanceof Material) + serialize.put("type", serialize.get("type").toString()); + section.createSection(path, serialize); + }; + } + public static ItemStack sectionGetItem(ConfigurationSection section, String path) { + if (section.isItemStack(path)) { + return section.getItemStack(path); + } else { // compatibility fallback + ConfigurationSection s = section.getConfigurationSection(path); + Map serialize = s.getValues(false); + if (s.contains("enchantments")) + serialize.put("enchantments", s.getConfigurationSection("enchantments").getValues(false)); + if (s.contains("damage")) + serialize.put("damage", new Integer(s.getInt("damage")).shortValue()); + return ItemStack.deserialize(serialize); + } + } }