Stop player skull's name being incorrectly set to the profiles's toString

By: Thinkofdeath <thethinkofdeath@gmail.com>
This commit is contained in:
Spigot 2014-04-17 13:02:29 +01:00
parent 9e7add3195
commit 6bbb74e114
3 changed files with 405 additions and 2 deletions

View file

@ -1,4 +1,4 @@
From 3b1f422c789b9404a7b7e185dc479ac12dafb624 Mon Sep 17 00:00:00 2001
From 889d5efb0e10f4111b4ecda5b2e42e6ee82f641e Mon Sep 17 00:00:00 2001
From: md_5 <md_5@live.com.au>
Date: Sun, 1 Dec 2013 15:10:48 +1100
Subject: [PATCH] mc-dev imports
@ -1526,6 +1526,343 @@ index 0000000..3eeed3e
+ return this.data;
+ }
+}
diff --git a/src/main/java/net/minecraft/server/NBTTagCompound.java b/src/main/java/net/minecraft/server/NBTTagCompound.java
new file mode 100644
index 0000000..5b8842f
--- /dev/null
+++ b/src/main/java/net/minecraft/server/NBTTagCompound.java
@@ -0,0 +1,331 @@
+package net.minecraft.server;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.Callable;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+public class NBTTagCompound extends NBTBase {
+
+ private static final Logger b = LogManager.getLogger();
+ private Map map = new HashMap();
+
+ public NBTTagCompound() {}
+
+ void write(DataOutput dataoutput) throws IOException
+ {
+ Iterator iterator = this.map.keySet().iterator();
+
+ while (iterator.hasNext()) {
+ String s = (String) iterator.next();
+ NBTBase nbtbase = (NBTBase) this.map.get(s);
+
+ a(s, nbtbase, dataoutput);
+ }
+
+ dataoutput.writeByte(0);
+ }
+
+ void load(DataInput datainput, int i, NBTReadLimiter nbtreadlimiter) throws IOException
+ {
+ if (i > 512) {
+ throw new RuntimeException("Tried to read NBT tag with too high complexity, depth > 512");
+ } else {
+ this.map.clear();
+
+ byte b0;
+
+ while ((b0 = a(datainput, nbtreadlimiter)) != 0) {
+ String s = b(datainput, nbtreadlimiter);
+
+ nbtreadlimiter.a((long) (16 * s.length()));
+ NBTBase nbtbase = a(b0, s, datainput, i + 1, nbtreadlimiter);
+
+ this.map.put(s, nbtbase);
+ }
+ }
+ }
+
+ public Set c() {
+ return this.map.keySet();
+ }
+
+ public byte getTypeId() {
+ return (byte) 10;
+ }
+
+ public void set(String s, NBTBase nbtbase) {
+ this.map.put(s, nbtbase);
+ }
+
+ public void setByte(String s, byte b0) {
+ this.map.put(s, new NBTTagByte(b0));
+ }
+
+ public void setShort(String s, short short1) {
+ this.map.put(s, new NBTTagShort(short1));
+ }
+
+ public void setInt(String s, int i) {
+ this.map.put(s, new NBTTagInt(i));
+ }
+
+ public void setLong(String s, long i) {
+ this.map.put(s, new NBTTagLong(i));
+ }
+
+ public void setFloat(String s, float f) {
+ this.map.put(s, new NBTTagFloat(f));
+ }
+
+ public void setDouble(String s, double d0) {
+ this.map.put(s, new NBTTagDouble(d0));
+ }
+
+ public void setString(String s, String s1) {
+ this.map.put(s, new NBTTagString(s1));
+ }
+
+ public void setByteArray(String s, byte[] abyte) {
+ this.map.put(s, new NBTTagByteArray(abyte));
+ }
+
+ public void setIntArray(String s, int[] aint) {
+ this.map.put(s, new NBTTagIntArray(aint));
+ }
+
+ public void setBoolean(String s, boolean flag) {
+ this.setByte(s, (byte) (flag ? 1 : 0));
+ }
+
+ public NBTBase get(String s) {
+ return (NBTBase) this.map.get(s);
+ }
+
+ public byte b(String s) {
+ NBTBase nbtbase = (NBTBase) this.map.get(s);
+
+ return nbtbase != null ? nbtbase.getTypeId() : 0;
+ }
+
+ public boolean hasKey(String s) {
+ return this.map.containsKey(s);
+ }
+
+ public boolean hasKeyOfType(String s, int i) {
+ byte b0 = this.b(s);
+
+ if (b0 == i) {
+ return true;
+ } else if (i != 99) {
+ if (b0 > 0) {
+ b.warn("NBT tag {} was of wrong type; expected {}, found {}", new Object[] { s, getTagName(i), getTagName(b0)});
+ }
+
+ return false;
+ } else {
+ return b0 == 1 || b0 == 2 || b0 == 3 || b0 == 4 || b0 == 5 || b0 == 6;
+ }
+ }
+
+ public byte getByte(String s) {
+ try {
+ return !this.map.containsKey(s) ? 0 : ((NBTNumber) this.map.get(s)).f();
+ } catch (ClassCastException classcastexception) {
+ return (byte) 0;
+ }
+ }
+
+ public short getShort(String s) {
+ try {
+ return !this.map.containsKey(s) ? 0 : ((NBTNumber) this.map.get(s)).e();
+ } catch (ClassCastException classcastexception) {
+ return (short) 0;
+ }
+ }
+
+ public int getInt(String s) {
+ try {
+ return !this.map.containsKey(s) ? 0 : ((NBTNumber) this.map.get(s)).d();
+ } catch (ClassCastException classcastexception) {
+ return 0;
+ }
+ }
+
+ public long getLong(String s) {
+ try {
+ return !this.map.containsKey(s) ? 0L : ((NBTNumber) this.map.get(s)).c();
+ } catch (ClassCastException classcastexception) {
+ return 0L;
+ }
+ }
+
+ public float getFloat(String s) {
+ try {
+ return !this.map.containsKey(s) ? 0.0F : ((NBTNumber) this.map.get(s)).h();
+ } catch (ClassCastException classcastexception) {
+ return 0.0F;
+ }
+ }
+
+ public double getDouble(String s) {
+ try {
+ return !this.map.containsKey(s) ? 0.0D : ((NBTNumber) this.map.get(s)).g();
+ } catch (ClassCastException classcastexception) {
+ return 0.0D;
+ }
+ }
+
+ public String getString(String s) {
+ try {
+ return !this.map.containsKey(s) ? "" : ((NBTBase) this.map.get(s)).a_();
+ } catch (ClassCastException classcastexception) {
+ return "";
+ }
+ }
+
+ public byte[] getByteArray(String s) {
+ try {
+ return !this.map.containsKey(s) ? new byte[0] : ((NBTTagByteArray) this.map.get(s)).c();
+ } catch (ClassCastException classcastexception) {
+ throw new ReportedException(this.a(s, 7, classcastexception));
+ }
+ }
+
+ public int[] getIntArray(String s) {
+ try {
+ return !this.map.containsKey(s) ? new int[0] : ((NBTTagIntArray) this.map.get(s)).c();
+ } catch (ClassCastException classcastexception) {
+ throw new ReportedException(this.a(s, 11, classcastexception));
+ }
+ }
+
+ public NBTTagCompound getCompound(String s) {
+ try {
+ return !this.map.containsKey(s) ? new NBTTagCompound() : (NBTTagCompound) this.map.get(s);
+ } catch (ClassCastException classcastexception) {
+ throw new ReportedException(this.a(s, 10, classcastexception));
+ }
+ }
+
+ public NBTTagList getList(String s, int i) {
+ try {
+ if (this.b(s) != 9) {
+ return new NBTTagList();
+ } else {
+ NBTTagList nbttaglist = (NBTTagList) this.map.get(s);
+
+ return nbttaglist.size() > 0 && nbttaglist.d() != i ? new NBTTagList() : nbttaglist;
+ }
+ } catch (ClassCastException classcastexception) {
+ throw new ReportedException(this.a(s, 9, classcastexception));
+ }
+ }
+
+ public boolean getBoolean(String s) {
+ return this.getByte(s) != 0;
+ }
+
+ public void remove(String s) {
+ this.map.remove(s);
+ }
+
+ public String toString() {
+ String s = "{";
+
+ String s1;
+
+ for (Iterator iterator = this.map.keySet().iterator(); iterator.hasNext(); s = s + s1 + ':' + this.map.get(s1) + ',') {
+ s1 = (String) iterator.next();
+ }
+
+ return s + "}";
+ }
+
+ public boolean isEmpty() {
+ return this.map.isEmpty();
+ }
+
+ private CrashReport a(String s, int i, ClassCastException classcastexception) {
+ CrashReport crashreport = CrashReport.a(classcastexception, "Reading NBT data");
+ CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Corrupt NBT tag", 1);
+
+ crashreportsystemdetails.a("Tag type found", (Callable) (new CrashReportCorruptNBTTag(this, s)));
+ crashreportsystemdetails.a("Tag type expected", (Callable) (new CrashReportCorruptNBTTag2(this, i)));
+ crashreportsystemdetails.a("Tag name", s);
+ return crashreport;
+ }
+
+ public NBTBase clone() {
+ NBTTagCompound nbttagcompound = new NBTTagCompound();
+ Iterator iterator = this.map.keySet().iterator();
+
+ while (iterator.hasNext()) {
+ String s = (String) iterator.next();
+
+ nbttagcompound.set(s, ((NBTBase) this.map.get(s)).clone());
+ }
+
+ return nbttagcompound;
+ }
+
+ public boolean equals(Object object) {
+ if (super.equals(object)) {
+ NBTTagCompound nbttagcompound = (NBTTagCompound) object;
+
+ return this.map.entrySet().equals(nbttagcompound.map.entrySet());
+ } else {
+ return false;
+ }
+ }
+
+ public int hashCode() {
+ return super.hashCode() ^ this.map.hashCode();
+ }
+
+ private static void a(String s, NBTBase nbtbase, DataOutput dataoutput) throws IOException
+ {
+ dataoutput.writeByte(nbtbase.getTypeId());
+ if (nbtbase.getTypeId() != 0) {
+ dataoutput.writeUTF(s);
+ nbtbase.write(dataoutput);
+ }
+ }
+
+ private static byte a(DataInput datainput, NBTReadLimiter nbtreadlimiter) throws IOException
+ {
+ return datainput.readByte();
+ }
+
+ private static String b(DataInput datainput, NBTReadLimiter nbtreadlimiter) throws IOException
+ {
+ return datainput.readUTF();
+ }
+
+ static NBTBase a(byte b0, String s, DataInput datainput, int i, NBTReadLimiter nbtreadlimiter) {
+ NBTBase nbtbase = NBTBase.createTag(b0);
+
+ try {
+ nbtbase.load(datainput, i, nbtreadlimiter);
+ return nbtbase;
+ } catch (IOException ioexception) {
+ CrashReport crashreport = CrashReport.a(ioexception, "Loading NBT data");
+ CrashReportSystemDetails crashreportsystemdetails = crashreport.a("NBT Tag");
+
+ crashreportsystemdetails.a("Tag name", s);
+ crashreportsystemdetails.a("Tag type", Byte.valueOf(b0));
+ throw new ReportedException(crashreport);
+ }
+ }
+
+ static Map a(NBTTagCompound nbttagcompound) {
+ return nbttagcompound.map;
+ }
+}
diff --git a/src/main/java/net/minecraft/server/NBTTagIntArray.java b/src/main/java/net/minecraft/server/NBTTagIntArray.java
new file mode 100644
index 0000000..c7cea7f
@ -3211,5 +3548,5 @@ index 0000000..c0db754
+ }
+}
--
1.8.3.2
1.8.5.2.msysgit.0

View file

@ -0,0 +1,37 @@
From 9311ebaaee26e191601040dc2636073ed58b4245 Mon Sep 17 00:00:00 2001
From: Thinkofdeath <thethinkofdeath@gmail.com>
Date: Thu, 17 Apr 2014 12:58:08 +0100
Subject: [PATCH] Add quiet option to hasKeyOfType
diff --git a/src/main/java/net/minecraft/server/NBTTagCompound.java b/src/main/java/net/minecraft/server/NBTTagCompound.java
index 5b8842f..7931c4a 100644
--- a/src/main/java/net/minecraft/server/NBTTagCompound.java
+++ b/src/main/java/net/minecraft/server/NBTTagCompound.java
@@ -119,13 +119,21 @@ public class NBTTagCompound extends NBTBase {
return this.map.containsKey(s);
}
- public boolean hasKeyOfType(String s, int i) {
+ // Spigot start - Add quiet option
+ public boolean hasKeyOfType(String s, int i)
+ {
+ return hasKeyOfType( s, i, false );
+ }
+
+ public boolean hasKeyOfType(String s, int i, boolean quiet)
+ {
byte b0 = this.b(s);
if (b0 == i) {
return true;
} else if (i != 99) {
- if (b0 > 0) {
+ if (b0 > 0 && !quiet) {
+ // Spigot end
b.warn("NBT tag {} was of wrong type; expected {}, found {}", new Object[] { s, getTagName(i), getTagName(b0)});
}
--
1.8.5.2.msysgit.0

View file

@ -0,0 +1,29 @@
From 3f29564abde66be189515e902fba65c95615cf91 Mon Sep 17 00:00:00 2001
From: Thinkofdeath <thethinkofdeath@gmail.com>
Date: Thu, 17 Apr 2014 13:00:05 +0100
Subject: [PATCH] Stop player skull's name being incorrectly set to the
profiles's toString
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
index 41efa55..c484c57 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
@@ -32,7 +32,13 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
super(tag);
if (tag.hasKey(SKULL_OWNER.NBT)) {
- player = tag.getString(SKULL_OWNER.NBT);
+ if ( tag.hasKeyOfType( SKULL_OWNER.NBT, 10, true ) )
+ {
+ player = net.minecraft.server.GameProfileSerializer.a( tag.getCompound( SKULL_OWNER.NBT ) ).getName();
+ } else if ( tag.hasKeyOfType( SKULL_OWNER.NBT, 8 ) )
+ {
+ player = tag.getString( SKULL_OWNER.NBT );
+ }
}
}
--
1.8.5.2.msysgit.0