Paper/Spigot-Server-Patches/0005-Add-MinecraftKey-Information-to-Objects.patch
Aikar 8175ec916f
Relookup Entity Save ID if was null during precache
Should fix #1280

Citizens hijacks entity map, and im guessing under the right conditions
the result might actually be null during entity creation

Pre the cache patch, the id is looked up on save, so it was fine.

Now, if its null and the save ID is requested, we will try to look
it up again and cache it if found.
2018-07-26 23:57:31 -04:00

112 lines
4.1 KiB
Diff

From de17c631c117b92a3cb3256819347d169ed0225b Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Wed, 4 Jul 2018 01:40:13 -0400
Subject: [PATCH] Add MinecraftKey Information to Objects
Stores the reference to the objects respective MinecraftKey
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index ed39b122ec..06c72b95f3 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -41,7 +41,7 @@ import org.bukkit.event.entity.EntityPortalEvent;
import org.bukkit.plugin.PluginManager;
// CraftBukkit end
-public abstract class Entity implements ICommandListener {
+public abstract class Entity implements ICommandListener, KeyedObject { // Paper
// CraftBukkit start
private static final int CURRENT_LEVEL = 2;
@@ -1702,11 +1702,28 @@ public abstract class Entity implements ICommandListener {
return true;
}
+ // Paper start
+ private String entityKeyString = null;
+ private MinecraftKey entityKey = getMinecraftKey();
+
+ @Override
+ public MinecraftKey getMinecraftKey() {
+ if (entityKey == null) {
+ entityKey = EntityTypes.getKey(this);
+ entityKeyString = entityKey != null ? entityKey.toString() : null;
+ }
+ return entityKey;
+ }
+
+ @Override
+ public String getMinecraftKeyString() {
+ getMinecraftKey(); // Try to load if it doesn't exists. see: https://github.com/PaperMC/Paper/issues/1280
+ return entityKeyString;
+ }
@Nullable
public final String getSaveID() {
- MinecraftKey minecraftkey = EntityTypes.a(this);
-
- return minecraftkey == null ? null : minecraftkey.toString();
+ return getMinecraftKeyString();
+ // Paper end
}
protected abstract void a(NBTTagCompound nbttagcompound);
diff --git a/src/main/java/net/minecraft/server/KeyedObject.java b/src/main/java/net/minecraft/server/KeyedObject.java
new file mode 100644
index 0000000000..61c2b993c9
--- /dev/null
+++ b/src/main/java/net/minecraft/server/KeyedObject.java
@@ -0,0 +1,8 @@
+package net.minecraft.server;
+
+public interface KeyedObject {
+ MinecraftKey getMinecraftKey();
+ default String getMinecraftKeyString() {
+ return getMinecraftKey().toString();
+ }
+}
diff --git a/src/main/java/net/minecraft/server/TileEntity.java b/src/main/java/net/minecraft/server/TileEntity.java
index 5a5a588e7c..0176ca530c 100644
--- a/src/main/java/net/minecraft/server/TileEntity.java
+++ b/src/main/java/net/minecraft/server/TileEntity.java
@@ -7,7 +7,7 @@ import org.apache.logging.log4j.Logger;
import org.spigotmc.CustomTimingsHandler; // Spigot
import org.bukkit.inventory.InventoryHolder; // CraftBukkit
-public abstract class TileEntity {
+public abstract class TileEntity implements KeyedObject {
public CustomTimingsHandler tickTimer = org.bukkit.craftbukkit.SpigotTimings.getTileEntityTimings(this); // Spigot
private static final Logger a = LogManager.getLogger();
@@ -27,8 +27,26 @@ public abstract class TileEntity {
TileEntity.f.a(new MinecraftKey(s), oclass);
}
- @Nullable
- public static MinecraftKey a(Class<? extends TileEntity> oclass) {
+ // Paper start
+ private String tileEntityKeyString = null;
+ private MinecraftKey tileEntityKey = getMinecraftKey();
+
+ @Override
+ public MinecraftKey getMinecraftKey() {
+ if (tileEntityKey == null) {
+ tileEntityKey = getKey(this.getClass());
+ tileEntityKeyString = tileEntityKey != null ? tileEntityKey.toString() : null;
+ }
+ return tileEntityKey;
+ }
+
+ @Override
+ public String getMinecraftKeyString() {
+ getMinecraftKey(); // Try to load if it doesn't exists.
+ return tileEntityKeyString;
+ }
+ @Nullable public static MinecraftKey getKey(Class<? extends TileEntity> oclass) { return a(oclass); } // Paper - OBFHELPER
+ @Nullable public static MinecraftKey a(Class<? extends TileEntity> oclass) {
return (MinecraftKey) TileEntity.f.b(oclass);
}
--
2.18.0