summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTravis Watkins <amaranth@ubuntu.com>2014-04-17 14:04:12 -0500
committerTravis Watkins <amaranth@ubuntu.com>2014-04-17 14:09:53 -0500
commita81f26716d47643af0f7b090be6b739599312eea (patch)
treebff1e19dbe22bca36b158d8e83a186360df85f57 /src
parent7e54acc8bd267a64902fbf260422c984bc7846c0 (diff)
downloadcraftbukkit-a81f26716d47643af0f7b090be6b739599312eea.tar
craftbukkit-a81f26716d47643af0f7b090be6b739599312eea.tar.gz
craftbukkit-a81f26716d47643af0f7b090be6b739599312eea.tar.lz
craftbukkit-a81f26716d47643af0f7b090be6b739599312eea.tar.xz
craftbukkit-a81f26716d47643af0f7b090be6b739599312eea.zip
Handle profiles in SkullMeta, they don't store a string anymore.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java36
-rw-r--r--src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java4
2 files changed, 27 insertions, 13 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
index 41efa552..15e114df 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
@@ -2,14 +2,16 @@ package org.bukkit.craftbukkit.inventory;
import java.util.Map;
+import net.minecraft.server.GameProfileSerializer;
+import net.minecraft.server.MinecraftServer;
import net.minecraft.server.NBTTagCompound;
+import net.minecraft.util.com.mojang.authlib.GameProfile;
import org.bukkit.Material;
import org.bukkit.configuration.serialization.DelegateDeserialization;
import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta;
import org.bukkit.inventory.meta.SkullMeta;
-import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap.Builder;
@DelegateDeserialization(SerializableMeta.class)
@@ -17,7 +19,7 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
static final ItemMetaKey SKULL_OWNER = new ItemMetaKey("SkullOwner", "skull-owner");
static final int MAX_OWNER_LENGTH = 16;
- private String player;
+ private GameProfile profile;
CraftMetaSkull(CraftMetaItem meta) {
super(meta);
@@ -25,14 +27,16 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
return;
}
CraftMetaSkull skullMeta = (CraftMetaSkull) meta;
- this.player = skullMeta.player;
+ this.profile = skullMeta.profile;
}
CraftMetaSkull(NBTTagCompound tag) {
super(tag);
- if (tag.hasKey(SKULL_OWNER.NBT)) {
- player = tag.getString(SKULL_OWNER.NBT);
+ if (tag.hasKeyOfType(SKULL_OWNER.NBT, 10)) {
+ profile = GameProfileSerializer.a(tag.getCompound(SKULL_OWNER.NBT));
+ } else if (tag.hasKeyOfType(SKULL_OWNER.NBT, 8)) {
+ profile = MinecraftServer.getServer().getUserCache().a(tag.getString(SKULL_OWNER.NBT));
}
}
@@ -46,7 +50,9 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
super.applyToItem(tag);
if (hasOwner()) {
- tag.setString(SKULL_OWNER.NBT, player);
+ NBTTagCompound owner = new NBTTagCompound();
+ GameProfileSerializer.a(owner, profile);
+ tag.set(SKULL_OWNER.NBT, owner);
}
}
@@ -75,18 +81,24 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
}
public boolean hasOwner() {
- return !Strings.isNullOrEmpty(player);
+ return profile != null;
}
public String getOwner() {
- return player;
+ return hasOwner() ? profile.getName() : null;
}
public boolean setOwner(String name) {
if (name != null && name.length() > MAX_OWNER_LENGTH) {
return false;
}
- player = name;
+
+ GameProfile profile = MinecraftServer.getServer().getUserCache().a(name);
+ if (profile == null) {
+ return false;
+ }
+
+ this.profile = profile;
return true;
}
@@ -95,7 +107,7 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
final int original;
int hash = original = super.applyHash();
if (hasOwner()) {
- hash = 61 * hash + player.hashCode();
+ hash = 61 * hash + profile.hashCode();
}
return original != hash ? CraftMetaSkull.class.hashCode() ^ hash : hash;
}
@@ -108,7 +120,7 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
if (meta instanceof CraftMetaSkull) {
CraftMetaSkull that = (CraftMetaSkull) meta;
- return (this.hasOwner() ? that.hasOwner() && this.player.equals(that.player) : !that.hasOwner());
+ return (this.hasOwner() ? that.hasOwner() && this.profile.equals(that.profile) : !that.hasOwner());
}
return true;
}
@@ -122,7 +134,7 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
Builder<String, Object> serialize(Builder<String, Object> builder) {
super.serialize(builder);
if (hasOwner()) {
- return builder.put(SKULL_OWNER.BUKKIT, this.player);
+ return builder.put(SKULL_OWNER.BUKKIT, this.profile.getName());
}
return builder;
}
diff --git a/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java b/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java
index abf84ed6..2331c180 100644
--- a/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java
+++ b/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java
@@ -135,6 +135,7 @@ public class ItemMetaTest extends AbstractTestingBase {
return cleanStack;
}
},
+ /* Skulls rely on a running server instance
new StackProvider(Material.SKULL_ITEM) {
@Override ItemStack operate(final ItemStack cleanStack) {
final SkullMeta meta = (SkullMeta) cleanStack.getItemMeta();
@@ -143,6 +144,7 @@ public class ItemMetaTest extends AbstractTestingBase {
return cleanStack;
}
},
+ */
new StackProvider(Material.MAP) {
@Override ItemStack operate(final ItemStack cleanStack) {
final MapMeta meta = (MapMeta) cleanStack.getItemMeta();
@@ -193,7 +195,7 @@ public class ItemMetaTest extends AbstractTestingBase {
}
);
- assertThat("Forgotten test?", providers, hasSize(ItemStackTest.COMPOUND_MATERIALS.length - 1 /* Normal item meta */));
+ assertThat("Forgotten test?", providers, hasSize(ItemStackTest.COMPOUND_MATERIALS.length - 2 /* Normal item meta and skulls */));
for (final StackProvider provider : providers) {
downCastTest(new BukkitWrapper(provider));