Add an attempt at backwards compatability for (broken) NMS plugins. Also set negative no entry values as these cannot occur.
cc @aadnk
This commit is contained in:
parent
7899e58d02
commit
0e03c0defe
1 changed files with 44 additions and 25 deletions
|
@ -1,4 +1,4 @@
|
|||
From 5121839a20fa4b458f7a22946b40923405568734 Mon Sep 17 00:00:00 2001
|
||||
From 6a093e7e3993c3c1aa92c2fcc1b33ccf19638993 Mon Sep 17 00:00:00 2001
|
||||
From: md_5 <git@md-5.net>
|
||||
Date: Fri, 13 Dec 2013 11:45:47 +1100
|
||||
Subject: [PATCH] Optimize DataWatcher
|
||||
|
@ -6,66 +6,85 @@ Subject: [PATCH] Optimize DataWatcher
|
|||
Use primitive orientated collections, as well as more effective copies across collections.
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/DataWatcher.java b/src/main/java/net/minecraft/server/DataWatcher.java
|
||||
index 90a2a80..5402e5c 100644
|
||||
index 90a2a80..adc1bb2 100644
|
||||
--- a/src/main/java/net/minecraft/server/DataWatcher.java
|
||||
+++ b/src/main/java/net/minecraft/server/DataWatcher.java
|
||||
@@ -14,8 +14,8 @@ public class DataWatcher {
|
||||
@@ -14,8 +14,13 @@ public class DataWatcher {
|
||||
|
||||
private final Entity a;
|
||||
private boolean b = true;
|
||||
- private static final HashMap c = new HashMap();
|
||||
- private final Map d = new HashMap();
|
||||
+ private static final gnu.trove.map.TObjectIntMap c = new gnu.trove.map.hash.TObjectIntHashMap(); // Spigot
|
||||
+ private final gnu.trove.map.TIntObjectMap d = new gnu.trove.map.hash.TIntObjectHashMap(); // Spigot
|
||||
+ // Spigot Start
|
||||
+ private static final gnu.trove.map.TObjectIntMap classToId = new gnu.trove.map.hash.TObjectIntHashMap( 10, 0.5f, -1 );
|
||||
+ private final gnu.trove.map.TIntObjectMap dataValues = new gnu.trove.map.hash.TIntObjectHashMap( 10, 0.5f, -1 );
|
||||
+ // These exist as an attempt at backwards compatability for (broken) NMS plugins
|
||||
+ private static final Map c = gnu.trove.TDecorators.wrap( classToId );
|
||||
+ private final Map d = gnu.trove.TDecorators.wrap( dataValues );
|
||||
+ // Spigot End
|
||||
private boolean e;
|
||||
private ReadWriteLock f = new ReentrantReadWriteLock();
|
||||
|
||||
@@ -36,7 +36,7 @@ public class DataWatcher {
|
||||
@@ -24,19 +29,19 @@ public class DataWatcher {
|
||||
}
|
||||
|
||||
public void a(int i, Object object) {
|
||||
- Integer integer = (Integer) c.get(object.getClass());
|
||||
+ Integer integer = (Integer) classToId.get(object.getClass()); // Spigot
|
||||
|
||||
if (integer == null) {
|
||||
throw new IllegalArgumentException("Unknown data type: " + object.getClass());
|
||||
} else if (i > 31) {
|
||||
throw new IllegalArgumentException("Data value id is too big with " + i + "! (Max is " + 31 + ")");
|
||||
- } else if (this.d.containsKey(Integer.valueOf(i))) {
|
||||
+ } else if (this.dataValues.containsKey(i)) { // Spigot
|
||||
throw new IllegalArgumentException("Duplicate id value for " + i + "!");
|
||||
} else {
|
||||
WatchableObject watchableobject = new WatchableObject(integer.intValue(), i, object);
|
||||
|
||||
this.f.writeLock().lock();
|
||||
- this.d.put(Integer.valueOf(i), watchableobject);
|
||||
+ this.d.put(i, watchableobject); // Spigot
|
||||
+ this.dataValues.put(i, watchableobject); // Spigot
|
||||
this.f.writeLock().unlock();
|
||||
this.b = false;
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public class DataWatcher {
|
||||
@@ -46,7 +51,7 @@ public class DataWatcher {
|
||||
WatchableObject watchableobject = new WatchableObject(j, i, null);
|
||||
|
||||
this.f.writeLock().lock();
|
||||
- this.d.put(Integer.valueOf(i), watchableobject);
|
||||
+ this.d.put(i, watchableobject); // Spigot
|
||||
+ this.dataValues.put(i, watchableobject); // Spigot
|
||||
this.f.writeLock().unlock();
|
||||
this.b = false;
|
||||
}
|
||||
@@ -81,7 +81,7 @@ public class DataWatcher {
|
||||
@@ -81,7 +86,7 @@ public class DataWatcher {
|
||||
WatchableObject watchableobject;
|
||||
|
||||
try {
|
||||
- watchableobject = (WatchableObject) this.d.get(Integer.valueOf(i));
|
||||
+ watchableobject = (WatchableObject) this.d.get(i); // Spigot
|
||||
+ watchableobject = (WatchableObject) this.dataValues.get(i); // Spigot
|
||||
} catch (Throwable throwable) {
|
||||
CrashReport crashreport = CrashReport.a(throwable, "Getting synched entity data");
|
||||
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Synched entity data");
|
||||
@@ -133,7 +133,7 @@ public class DataWatcher {
|
||||
@@ -133,7 +138,7 @@ public class DataWatcher {
|
||||
|
||||
if (this.e) {
|
||||
this.f.readLock().lock();
|
||||
- Iterator iterator = this.d.values().iterator();
|
||||
+ Iterator iterator = this.d.valueCollection().iterator(); // Spigot
|
||||
+ Iterator iterator = this.dataValues.valueCollection().iterator(); // Spigot
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
WatchableObject watchableobject = (WatchableObject) iterator.next();
|
||||
@@ -157,7 +157,7 @@ public class DataWatcher {
|
||||
@@ -157,7 +162,7 @@ public class DataWatcher {
|
||||
|
||||
public void a(PacketDataSerializer packetdataserializer) {
|
||||
this.f.readLock().lock();
|
||||
- Iterator iterator = this.d.values().iterator();
|
||||
+ Iterator iterator = this.d.valueCollection().iterator(); // Spigot
|
||||
+ Iterator iterator = this.dataValues.valueCollection().iterator(); // Spigot
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
WatchableObject watchableobject = (WatchableObject) iterator.next();
|
||||
@@ -170,18 +170,11 @@ public class DataWatcher {
|
||||
@@ -170,18 +175,11 @@ public class DataWatcher {
|
||||
}
|
||||
|
||||
public List c() {
|
||||
|
@ -82,11 +101,11 @@ index 90a2a80..5402e5c 100644
|
|||
- arraylist = new ArrayList();
|
||||
- }
|
||||
- }
|
||||
+ arraylist.addAll(this.d.valueCollection()); // Spigot
|
||||
+ arraylist.addAll(this.dataValues.valueCollection()); // Spigot
|
||||
|
||||
this.f.readLock().unlock();
|
||||
return arraylist;
|
||||
@@ -295,12 +288,14 @@ public class DataWatcher {
|
||||
@@ -295,12 +293,14 @@ public class DataWatcher {
|
||||
}
|
||||
|
||||
static {
|
||||
|
@ -98,13 +117,13 @@ index 90a2a80..5402e5c 100644
|
|||
- c.put(ItemStack.class, Integer.valueOf(5));
|
||||
- c.put(ChunkCoordinates.class, Integer.valueOf(6));
|
||||
+ // Spigot Start - remove valueOf
|
||||
+ c.put(Byte.class, 0);
|
||||
+ c.put(Short.class, 1);
|
||||
+ c.put(Integer.class, 2);
|
||||
+ c.put(Float.class, 3);
|
||||
+ c.put(String.class, 4);
|
||||
+ c.put(ItemStack.class, 5);
|
||||
+ c.put(ChunkCoordinates.class, 6);
|
||||
+ classToId.put(Byte.class, 0);
|
||||
+ classToId.put(Short.class, 1);
|
||||
+ classToId.put(Integer.class, 2);
|
||||
+ classToId.put(Float.class, 3);
|
||||
+ classToId.put(String.class, 4);
|
||||
+ classToId.put(ItemStack.class, 5);
|
||||
+ classToId.put(ChunkCoordinates.class, 6);
|
||||
+ // Spigot End
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue