diff options
16 files changed, 124 insertions, 68 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index 6af8e83e6..62f7ad04e 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -57,7 +57,7 @@ import org.bukkit.scheduler.BukkitScheduler; public class Essentials extends JavaPlugin implements IEssentials { - public static final int BUKKIT_VERSION = 1512; + public static final int BUKKIT_VERSION = 1518; private static final Logger LOGGER = Logger.getLogger("Minecraft"); private transient ISettings settings; private final transient TNTExplodeListener tntListener = new TNTExplodeListener(this); diff --git a/Essentials/src/com/earth2me/essentials/EssentialsConf.java b/Essentials/src/com/earth2me/essentials/EssentialsConf.java index 512b9c60a..5e6b7ca13 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsConf.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsConf.java @@ -2,7 +2,9 @@ package com.earth2me.essentials; import static com.earth2me.essentials.I18n._; import java.io.*; +import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; @@ -10,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; @@ -224,13 +227,25 @@ 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)/* + (short)getInt(path + ".damage", 0)); + List<String> enchants = getKeys(path + ".enchant"); + for (String enchant : enchants) + { + Enchantment enchantment = Enchantment.getByName(enchant); + if (enchantment == null) { + continue; + } + 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) @@ -239,6 +254,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(), entry.getValue()); + } + map.put("enchant", enchant); + } // getData().getData() is broken //map.put("data", stack.getDurability()); setProperty(path, map); diff --git a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java index 322d94d8f..214fc8c01 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java @@ -57,7 +57,8 @@ public class EssentialsEntityListener extends EntityListener ItemStack hand = player.getItemInHand(); if (hand != null && hand.getType() == Material.MILK_BUCKET) { ((Animals)eDefend).setAge(-24000); - player.setItemInHand(new ItemStack(Material.BUCKET, hand.getAmount())); + hand.setType(Material.BUCKET); + player.setItemInHand(hand); player.updateInventory(); event.setCancelled(true); } diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index 0ae77fbe5..206154e6f 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -1,6 +1,5 @@ package com.earth2me.essentials; -import com.earth2me.essentials.craftbukkit.BedLocationFix; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.textreader.IText; import com.earth2me.essentials.textreader.KeywordReplacer; @@ -17,7 +16,6 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Server; import org.bukkit.entity.Player; -import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerLoginEvent.Result; import org.bukkit.event.player.*; import org.bukkit.inventory.ItemStack; @@ -234,7 +232,7 @@ public class EssentialsPlayerListener extends PlayerListener { Location loc = user.getHome(user.getLocation()); if (loc == null) { - loc = BedLocationFix.getBedSpawnLocation(user); + loc = user.getBedSpawnLocation(); } if (loc != null) { user.setCompassTarget(loc); diff --git a/Essentials/src/com/earth2me/essentials/FakeInventory.java b/Essentials/src/com/earth2me/essentials/FakeInventory.java index fef6db7d0..32c653d86 100644 --- a/Essentials/src/com/earth2me/essentials/FakeInventory.java +++ b/Essentials/src/com/earth2me/essentials/FakeInventory.java @@ -20,6 +20,7 @@ public class FakeInventory implements Inventory continue; } this.items[i] = new ItemStack(items[i].getTypeId(), items[i].getAmount(), items[i].getDurability()); + this.items[i].addEnchantments(items[i].getEnchantments()); } } diff --git a/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java b/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java index 0470488b8..8b412e72f 100644 --- a/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java +++ b/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java @@ -34,7 +34,7 @@ public final class InventoryWorkaround { continue; } - if (item.getTypeId() == cItem.getTypeId() && (!forceAmount || item.getAmount() == cItem.getAmount()) && (!forceDurability || cItem.getDurability() == item.getDurability())) + if (item.getTypeId() == cItem.getTypeId() && (!forceAmount || item.getAmount() == cItem.getAmount()) && (!forceDurability || cItem.getDurability() == item.getDurability()) && cItem.getEnchantments().equals(item.getEnchantments())) { return i; } @@ -56,7 +56,7 @@ public final class InventoryWorkaround { continue; } - if (item.getTypeId() == cItem.getTypeId() && cItem.getAmount() < cItem.getType().getMaxStackSize() && (!forceDurability || cItem.getDurability() == item.getDurability())) + if (item.getTypeId() == cItem.getTypeId() && cItem.getAmount() < cItem.getType().getMaxStackSize() && (!forceDurability || cItem.getDurability() == item.getDurability()) && cItem.getEnchantments().equals(item.getEnchantments())) { return i; } @@ -102,9 +102,10 @@ public final class InventoryWorkaround if (combined[j] == null) { combined[j] = new ItemStack(items[i].getType(), items[i].getAmount(), items[i].getDurability()); + combined[j].addEnchantments(items[i].getEnchantments()); break; } - if (combined[j].getTypeId() == items[i].getTypeId() && (!forceDurability || combined[j].getDurability() == items[i].getDurability())) + if (combined[j].getTypeId() == items[i].getTypeId() && (!forceDurability || combined[j].getDurability() == items[i].getDurability()) && combined[j].getEnchantments().equals(items[i].getEnchantments())) { combined[j].setAmount(combined[j].getAmount() + items[i].getAmount()); break; @@ -143,7 +144,9 @@ public final class InventoryWorkaround // More than a single stack! if (item.getAmount() > item.getType().getMaxStackSize()) { - cinventory.setItem(firstFree, new ItemStack(item.getTypeId(), item.getType().getMaxStackSize(), item.getDurability())); + ItemStack stack = new ItemStack(item.getTypeId(), item.getType().getMaxStackSize(), item.getDurability()); + stack.addEnchantments(item.getEnchantments()); + cinventory.setItem(firstFree, stack); item.setAmount(item.getAmount() - item.getType().getMaxStackSize()); } else @@ -257,9 +260,10 @@ public final class InventoryWorkaround if (combined[j] == null) { combined[j] = new ItemStack(items[i].getType(), items[i].getAmount(), items[i].getDurability()); + combined[j].addEnchantments(items[i].getEnchantments()); break; } - if (combined[j].getTypeId() == items[i].getTypeId() && (!forceDurability || combined[j].getDurability() == items[i].getDurability())) + if (combined[j].getTypeId() == items[i].getTypeId() && (!forceDurability || combined[j].getDurability() == items[i].getDurability()) && combined[j].getEnchantments().equals(items[i].getEnchantments())) { combined[j].setAmount(combined[j].getAmount() + items[i].getAmount()); break; @@ -318,14 +322,18 @@ public final class InventoryWorkaround final int maxStackSize = itm.getType().getMaxStackSize(); final int stacks = itm.getAmount() / maxStackSize; final int leftover = itm.getAmount() % maxStackSize; - Item[] itemStacks = new Item[stacks + (leftover > 0 ? 1 : 0)]; + final Item[] itemStacks = new Item[stacks + (leftover > 0 ? 1 : 0)]; for (int i = 0; i < stacks; i++) { - itemStacks[i] = loc.getWorld().dropItem(loc, new ItemStack(itm.getType(), maxStackSize, itm.getDurability())); + final ItemStack stack = new ItemStack(itm.getType(), maxStackSize, itm.getDurability()); + stack.addEnchantments(itm.getEnchantments()); + itemStacks[i] = loc.getWorld().dropItem(loc, stack); } if (leftover > 0) { - itemStacks[stacks] = loc.getWorld().dropItem(loc, new ItemStack(itm.getType(), leftover, itm.getDurability())); + final ItemStack stack = new ItemStack(itm.getType(), leftover, itm.getDurability()); + stack.addEnchantments(itm.getEnchantments()); + itemStacks[stacks] = loc.getWorld().dropItem(loc, stack); } return itemStacks; } diff --git a/Essentials/src/com/earth2me/essentials/OfflinePlayer.java b/Essentials/src/com/earth2me/essentials/OfflinePlayer.java index d8c871b5b..deccf6516 100644 --- a/Essentials/src/com/earth2me/essentials/OfflinePlayer.java +++ b/Essentials/src/com/earth2me/essentials/OfflinePlayer.java @@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._; import java.net.InetSocketAddress; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.UUID; import lombok.Delegate; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java index 60b1d1147..090cebd4c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java @@ -4,7 +4,6 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; import com.earth2me.essentials.Util; -import com.earth2me.essentials.craftbukkit.BedLocationFix; import java.util.List; import java.util.Locale; import org.bukkit.Location; @@ -45,7 +44,7 @@ public class Commandhome extends EssentialsCommand try { if ("bed".equalsIgnoreCase(homeName)) { - final Location bed = BedLocationFix.getBedSpawnLocation(player); + final Location bed = player.getBedSpawnLocation(); if (bed != null) { user.getTeleport().teleport(bed, charge); @@ -58,7 +57,7 @@ public class Commandhome extends EssentialsCommand final List<String> homes = player.getHomes(); if (homes.isEmpty() && player.equals(user)) { - final Location loc = BedLocationFix.getBedSpawnLocation(player); + final Location loc = player.getBedSpawnLocation(); if (loc == null) { if (ess.getSettings().spawnIfNoHome()) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java index 9ca622aef..1639f5360 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java @@ -149,6 +149,7 @@ public class Commandsell extends EssentialsCommand } } + //TODO: Prices for Enchantments final ItemStack ris = new ItemStack(is.getType(), amount, is.getDurability()); InventoryWorkaround.removeItem(user.getInventory(), true, ris); user.updateInventory(); diff --git a/Essentials/src/com/earth2me/essentials/craftbukkit/BedLocationFix.java b/Essentials/src/com/earth2me/essentials/craftbukkit/BedLocationFix.java deleted file mode 100644 index dc4818284..000000000 --- a/Essentials/src/com/earth2me/essentials/craftbukkit/BedLocationFix.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.earth2me.essentials.craftbukkit; - -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.craftbukkit.entity.CraftPlayer; -import org.bukkit.entity.Player; - - -public class BedLocationFix -{ - /* - * Adds missing null pointer check to getHandle().getBed() - */ - public static Location getBedSpawnLocation(final Player player) - { - final CraftPlayer cplayer = (CraftPlayer)player; - final World world = player.getServer().getWorld(cplayer.getHandle().spawnWorld); - if (world != null && cplayer.getHandle().getBed() != null) - { - return new Location(world, cplayer.getHandle().getBed().x, cplayer.getHandle().getBed().y, cplayer.getHandle().getBed().z); - } - else - { - return null; - } - } -} diff --git a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java index c2f3eb8e4..28635796a 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java @@ -76,7 +76,9 @@ public class SignTrade extends EssentialsSign amount -= amount % trade.getItemStack().getAmount(); if (amount > 0) { - final Trade store = new Trade(new ItemStack(player.getItemInHand().getTypeId(), amount, player.getItemInHand().getDurability()), ess); + final ItemStack stack = new ItemStack(player.getItemInHand().getTypeId(), amount, player.getItemInHand().getDurability()); + stack.addEnchantments(player.getItemInHand().getEnchantments()); + final Trade store = new Trade(stack, ess); addAmount(sign, 2, store, ess); store.charge(player); return store; diff --git a/Essentials/src/com/earth2me/essentials/storage/BukkitConstructor.java b/Essentials/src/com/earth2me/essentials/storage/BukkitConstructor.java index 2656d183d..6d7066c58 100644 --- a/Essentials/src/com/earth2me/essentials/storage/BukkitConstructor.java +++ b/Essentials/src/com/earth2me/essentials/storage/BukkitConstructor.java @@ -1,10 +1,12 @@ package com.earth2me.essentials.storage; +import java.util.Locale; import java.util.regex.Pattern; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; import org.bukkit.material.MaterialData; import org.yaml.snakeyaml.constructor.Constructor; @@ -83,7 +85,7 @@ public class BukkitConstructor extends Constructor { return null; } - final String[] split1 = val.split("\\W", 2); + final String[] split1 = val.split("\\W"); if (split1.length == 0) { return null; @@ -109,11 +111,42 @@ public class BukkitConstructor extends Constructor data = Short.parseShort(split2[1]); } int size = mat.getMaxStackSize(); - if (split1.length == 2 && NUMPATTERN.matcher(split1[1]).matches()) + if (split1.length > 1 && NUMPATTERN.matcher(split1[1]).matches()) { size = Integer.parseInt(split1[1]); } - return new ItemStack(mat, size, data); + final ItemStack stack = new ItemStack(mat, size, data); + if (split1.length > 2) + { + for (int i = 2; i < split1.length; i++) + { + final String[] split3 = split1[0].split("[:+',;.]", 2); + if (split3.length != 2) + { + continue; + } + Enchantment enchantment; + if (NUMPATTERN.matcher(split3[0]).matches()) + { + final int enchantId = Integer.parseInt(split3[0]); + enchantment = Enchantment.getById(enchantId); + } + else + { + enchantment = Enchantment.getByName(split3[0].toUpperCase(Locale.ENGLISH)); + } + if (enchantment == null) { + continue; + } + int level = enchantment.getStartLevel(); + if (NUMPATTERN.matcher(split3[1]).matches()) + { + level = Integer.parseInt(split3[1]); + } + stack.addUnsafeEnchantment(enchantment, level); + } + } + return stack; } return super.construct(node); } diff --git a/Essentials/src/com/earth2me/essentials/storage/YamlStorageWriter.java b/Essentials/src/com/earth2me/essentials/storage/YamlStorageWriter.java index 048abe737..da636bf71 100644 --- a/Essentials/src/com/earth2me/essentials/storage/YamlStorageWriter.java +++ b/Essentials/src/com/earth2me/essentials/storage/YamlStorageWriter.java @@ -5,6 +5,7 @@ import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.Collection; import java.util.Collections; +import java.util.Locale; import java.util.Map; import java.util.Map.Entry; import java.util.logging.Level; @@ -12,6 +13,7 @@ import java.util.logging.Logger; import java.util.regex.Pattern; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; import org.bukkit.material.MaterialData; import org.yaml.snakeyaml.Yaml; @@ -22,12 +24,12 @@ public class YamlStorageWriter implements IStorageWriter private transient static final Pattern NON_WORD_PATTERN = Pattern.compile("\\W"); private transient final PrintWriter writer; private transient static final Yaml YAML = new Yaml(); - + public YamlStorageWriter(final PrintWriter writer) { this.writer = writer; } - + public void save(final StorageObject object) { try @@ -43,7 +45,7 @@ public class YamlStorageWriter implements IStorageWriter Logger.getLogger(YamlStorageWriter.class.getName()).log(Level.SEVERE, null, ex); } } - + private void writeToFile(final Object object, final int depth, final Class clazz) throws IllegalAccessException { for (Field field : clazz.getDeclaredFields()) @@ -52,7 +54,7 @@ public class YamlStorageWriter implements IStorageWriter if (Modifier.isPrivate(modifier) && !Modifier.isTransient(modifier) && !Modifier.isStatic(modifier)) { field.setAccessible(true); - + final Object data = field.get(object); if (writeKey(field, depth, data)) { @@ -83,7 +85,7 @@ public class YamlStorageWriter implements IStorageWriter } } } - + private boolean writeKey(final Field field, final int depth, final Object data) { final boolean commentPresent = writeComment(field, depth); @@ -107,7 +109,7 @@ public class YamlStorageWriter implements IStorageWriter } return false; } - + private boolean writeComment(final Field field, final int depth) { final boolean commentPresent = field.isAnnotationPresent(Comment.class); @@ -129,7 +131,7 @@ public class YamlStorageWriter implements IStorageWriter } return commentPresent; } - + private void writeCollection(final Collection<Object> data, final int depth) throws IllegalAccessException { writer.println(); @@ -160,7 +162,7 @@ public class YamlStorageWriter implements IStorageWriter } writer.println(); } - + private void writeMap(final Map<Object, Object> data, final int depth) throws IllegalArgumentException, IllegalAccessException { writer.println(); @@ -197,7 +199,7 @@ public class YamlStorageWriter implements IStorageWriter } } } - + private void writeIndention(final int depth) { for (int i = 0; i < depth; i++) @@ -205,7 +207,7 @@ public class YamlStorageWriter implements IStorageWriter writer.print(" "); } } - + private void writeScalar(final Object data) { if (data instanceof String || data instanceof Boolean || data instanceof Number) @@ -228,16 +230,29 @@ public class YamlStorageWriter implements IStorageWriter else if (data instanceof ItemStack) { final ItemStack itemStack = (ItemStack)data; - writer.println(itemStack.getType().toString().toLowerCase() - + (itemStack.getDurability() > 0 ? ":" + itemStack.getDurability() : "") - + " " + itemStack.getAmount()); + writer.print(itemStack.getType().toString().toLowerCase(Locale.ENGLISH)); + + if (itemStack.getDurability() > 0) + { + writer.print(':'); + writer.print(itemStack.getDurability()); + } + writer.print(' '); + writer.print(itemStack.getAmount()); + for (Entry<Enchantment, Integer> entry : itemStack.getEnchantments().entrySet()) + { + writer.print(' '); + writer.print(entry.getKey().getName().toLowerCase(Locale.ENGLISH)); + writer.print(':'); + writer.print(entry.getValue()); + } } else { throw new UnsupportedOperationException(); } } - + private void writeKey(final Object data) { if (data instanceof String || data instanceof Boolean || data instanceof Number) @@ -269,7 +284,7 @@ public class YamlStorageWriter implements IStorageWriter throw new UnsupportedOperationException(); } } - + private void writeLocation(final Location entry, final int depth) { writer.println(); diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java index a14f8bb71..57b842c82 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java @@ -3,7 +3,6 @@ package com.earth2me.essentials.spawn; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.User; -import com.earth2me.essentials.craftbukkit.BedLocationFix; import java.util.logging.Level; import java.util.logging.Logger; import org.bukkit.Location; @@ -32,7 +31,7 @@ public class EssentialsSpawnPlayerListener extends PlayerListener Location home = user.getHome(user.getLocation()); if (home == null) { - home = BedLocationFix.getBedSpawnLocation(user); + home = user.getBedSpawnLocation(); } if (home != null) { @@ -52,7 +51,7 @@ public class EssentialsSpawnPlayerListener extends PlayerListener { final User user = ess.getUser(event.getPlayer()); - if (!user.isNew() || BedLocationFix.getBedSpawnLocation(user) != null) + if (!user.isNew() || user.getBedSpawnLocation() != null) { return; } diff --git a/lib/bukkit-1.0.0-R1-SNAPSHOT.jar b/lib/bukkit-1.0.0-R1-SNAPSHOT.jar Binary files differindex dd15e3e2f..60939e166 100644 --- a/lib/bukkit-1.0.0-R1-SNAPSHOT.jar +++ b/lib/bukkit-1.0.0-R1-SNAPSHOT.jar diff --git a/lib/craftbukkit-1.0.0-SNAPSHOT.jar b/lib/craftbukkit-1.0.0-SNAPSHOT.jar Binary files differindex 62f18732e..9285ca484 100644 --- a/lib/craftbukkit-1.0.0-SNAPSHOT.jar +++ b/lib/craftbukkit-1.0.0-SNAPSHOT.jar |