Added enchantment support

This commit is contained in:
zml2008 2011-11-27 15:29:51 -08:00
parent 51dd7a0c9c
commit 255e342353
3 changed files with 25 additions and 3 deletions

View File

@ -41,7 +41,7 @@
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId> <artifactId>bukkit</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>1.0.0-R1-SNAPSHOT</version>
</dependency> </dependency>
<!-- Archive reading library for snapshots --> <!-- Archive reading library for snapshots -->

View File

@ -19,6 +19,9 @@
package com.sk89q.worldedit.blocks; package com.sk89q.worldedit.blocks;
import java.util.HashMap;
import java.util.Map;
/** /**
* Represents an item. * Represents an item.
* *
@ -34,6 +37,8 @@ public class BaseItem {
*/ */
private short damage; private short damage;
private Map<Integer, Integer> enchantments = new HashMap<Integer, Integer>();
/** /**
* Construct the object. * Construct the object.
* *
@ -82,4 +87,8 @@ public class BaseItem {
public void setDamage(short damage) { public void setDamage(short damage) {
this.damage = damage; this.damage = damage;
} }
public Map<Integer, Integer> getEnchantments() {
return enchantments;
}
} }

View File

@ -24,12 +24,14 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.block.Furnace; import org.bukkit.block.Furnace;
import org.bukkit.block.CreatureSpawner; import org.bukkit.block.CreatureSpawner;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Arrow; import org.bukkit.entity.Arrow;
import org.bukkit.entity.Boat; import org.bukkit.entity.Boat;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -660,6 +662,11 @@ public class BukkitWorld extends LocalWorld {
bukkitStack.getTypeId(), bukkitStack.getTypeId(),
bukkitStack.getAmount(), bukkitStack.getAmount(),
bukkitStack.getDurability()); bukkitStack.getDurability());
try {
for (Map.Entry<Enchantment, Integer> entry : bukkitStack.getEnchantments().entrySet()) {
contents[i].getEnchantments().put(entry.getKey().getId(), entry.getValue());
}
} catch (Throwable ignore) {}
} }
} }
@ -693,9 +700,15 @@ public class BukkitWorld extends LocalWorld {
} }
if (contents[i] != null) { if (contents[i] != null) {
inven.setItem(i, new ItemStack(contents[i].getType(), ItemStack toAdd = new ItemStack(contents[i].getType(),
contents[i].getAmount(), contents[i].getAmount(),
(byte) contents[i].getDamage())); (byte) contents[i].getDamage());
try {
for (Map.Entry<Integer, Integer> entry : contents[i].getEnchantments().entrySet()) {
toAdd.addEnchantment(Enchantment.getById(entry.getKey()), entry.getValue());
}
} catch (Throwable ignore) {}
inven.setItem(i, toAdd);
} else { } else {
inven.setItem(i, null); inven.setItem(i, null);
} }