summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/bukkit/craftbukkit
diff options
context:
space:
mode:
authorh31ix <effectsdude@gmail.com>2012-10-31 00:59:06 -0400
committerWesley Wolfe <weswolf@aol.com>2012-10-31 01:18:59 -0500
commit63eaf74d44aef155b90cce2d25d9be96b4249702 (patch)
treeb4cd0b688845c3e5d4cb790e828ee60a39bda369 /src/main/java/org/bukkit/craftbukkit
parent02ca9be079c3bc2f391cf4fc0c71031b92cd4b0d (diff)
downloadcraftbukkit-63eaf74d44aef155b90cce2d25d9be96b4249702.tar
craftbukkit-63eaf74d44aef155b90cce2d25d9be96b4249702.tar.gz
craftbukkit-63eaf74d44aef155b90cce2d25d9be96b4249702.tar.lz
craftbukkit-63eaf74d44aef155b90cce2d25d9be96b4249702.tar.xz
craftbukkit-63eaf74d44aef155b90cce2d25d9be96b4249702.zip
Implement the API for ItemFrames. Adds BUKKIT-2668
Diffstat (limited to 'src/main/java/org/bukkit/craftbukkit')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/entity/CraftItemFrame.java63
1 files changed, 62 insertions, 1 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftItemFrame.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftItemFrame.java
index b03bb679..94c4a12e 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftItemFrame.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftItemFrame.java
@@ -1,7 +1,13 @@
package org.bukkit.craftbukkit.entity;
import net.minecraft.server.EntityItemFrame;
+import net.minecraft.server.ItemStack;
+
+import org.apache.commons.lang.Validate;
+import org.bukkit.Material;
+import org.bukkit.Rotation;
import org.bukkit.craftbukkit.CraftServer;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ItemFrame;
@@ -10,6 +16,61 @@ public class CraftItemFrame extends CraftHanging implements ItemFrame {
super(server, entity);
}
+ public void setItem(org.bukkit.inventory.ItemStack item) {
+ if (item == null || item.getTypeId() == 0) {
+ getHandle().getDataWatcher().a(2, 5);
+ getHandle().getDataWatcher().h(2);
+ } else {
+ getHandle().a(CraftItemStack.createNMSItemStack(item));
+ }
+ }
+
+ public org.bukkit.inventory.ItemStack getItem() {
+ ItemStack i = getHandle().i();
+ return i == null ? new org.bukkit.inventory.ItemStack(Material.AIR) : new CraftItemStack(i);
+ }
+
+ public Rotation getRotation() {
+ return toBukkitRotation(getHandle().j());
+ }
+
+ Rotation toBukkitRotation(int value) {
+ // Translate NMS rotation integer to Bukkit API
+ switch (value) {
+ case 0:
+ return Rotation.NONE;
+ case 1:
+ return Rotation.CLOCKWISE;
+ case 2:
+ return Rotation.FLIPPED;
+ case 3:
+ return Rotation.COUNTER_CLOCKWISE;
+ default:
+ throw new AssertionError("Unknown rotation " + getHandle().j() + " for " + getHandle());
+ }
+ }
+
+ public void setRotation(Rotation rotation) {
+ Validate.notNull(rotation, "Rotation cannot be null");
+ getHandle().g(toInteger(rotation));
+ }
+
+ static int toInteger(Rotation rotation) {
+ // Translate Bukkit API rotation to NMS integer
+ switch (rotation) {
+ case NONE:
+ return 0;
+ case CLOCKWISE:
+ return 1;
+ case FLIPPED:
+ return 2;
+ case COUNTER_CLOCKWISE:
+ return 3;
+ default:
+ throw new IllegalArgumentException(rotation + " is not applicable to an ItemFrame");
+ }
+ }
+
@Override
public EntityItemFrame getHandle() {
return (EntityItemFrame) entity;
@@ -17,7 +78,7 @@ public class CraftItemFrame extends CraftHanging implements ItemFrame {
@Override
public String toString() {
- return "CraftItemFrame";
+ return "CraftItemFrame{item=" + getItem() + ", rotation=" + getRotation() + "}";
}
public EntityType getType() {