aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0006-Add-MinecraftKey-Information-to-Objects.patch
blob: f059c867287e73c945735b598b49fe3e391ea920 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
From 0000000000000000000000000000000000000000 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/com/destroystokyo/paper/PaperCommand.java b/src/main/java/com/destroystokyo/paper/PaperCommand.java
index b8868b86338ce0e89bc74eccccf714b910d7a4fe..9cb2f3b31921870ddba044840e99eb04babe26bb 100644
--- a/src/main/java/com/destroystokyo/paper/PaperCommand.java
+++ b/src/main/java/com/destroystokyo/paper/PaperCommand.java
@@ -178,7 +178,7 @@ public class PaperCommand extends Command {
 
                 Collection<Entity> entities = world.entitiesById.values();
                 entities.forEach(e -> {
-                    MinecraftKey key = new MinecraftKey(""); // TODO: update in next patch
+                    MinecraftKey key = e.getMinecraftKey();
 
                     MutablePair<Integer, Map<ChunkCoordIntPair, Integer>> info = list.computeIfAbsent(key, k -> MutablePair.of(0, Maps.newHashMap()));
                     ChunkCoordIntPair chunk = new ChunkCoordIntPair(e.chunkX, e.chunkZ);
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index c6466b16926a368a4f149cedd3f2dc90ec86290d..2b1d674474cce96c02e5cdf71bc2c796447be59c 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -49,7 +49,7 @@ import org.bukkit.event.player.PlayerTeleportEvent;
 import org.bukkit.plugin.PluginManager;
 // CraftBukkit end
 
-public abstract class Entity implements INamableTileEntity, ICommandListener {
+public abstract class Entity implements INamableTileEntity, ICommandListener, KeyedObject { // Paper
 
     // CraftBukkit start
     private static final int CURRENT_LEVEL = 2;
@@ -1670,12 +1670,31 @@ public abstract class Entity implements INamableTileEntity, ICommandListener {
         return true;
     }
 
+    // Paper start
+    private MinecraftKey entityKey;
+    private String entityKeyString;
+
+    @Override
+    public MinecraftKey getMinecraftKey() {
+        if (entityKey == null) {
+            this.entityKey = EntityTypes.getName(this.getEntityType());
+            this.entityKeyString = this.entityKey != null ? this.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() {
         EntityTypes<?> entitytypes = this.getEntityType();
         MinecraftKey minecraftkey = EntityTypes.getName(entitytypes);
 
-        return entitytypes.a() && minecraftkey != null ? minecraftkey.toString() : null;
+        return entitytypes != null && entitytypes.isPersistable() ? getMinecraftKeyString() : null;
+        // Paper end
     }
 
     protected abstract void loadData(NBTTagCompound nbttagcompound);
diff --git a/src/main/java/net/minecraft/server/EntityTypes.java b/src/main/java/net/minecraft/server/EntityTypes.java
index 9a772e40ad8f9858e6278b99d9d1ff5dc54513cb..b9fe08301409bc1f0d61a7566c26e720ff720d80 100644
--- a/src/main/java/net/minecraft/server/EntityTypes.java
+++ b/src/main/java/net/minecraft/server/EntityTypes.java
@@ -248,6 +248,7 @@ public class EntityTypes<T extends Entity> {
         }
     }
 
+    public boolean isPersistable() { return a(); } // Paper - OBFHELPER
     public boolean a() {
         return this.bh;
     }
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 0000000000000000000000000000000000000000..743142d0303fa25fe48a2abb07040d1228d04402
--- /dev/null
+++ b/src/main/java/net/minecraft/server/KeyedObject.java
@@ -0,0 +1,9 @@
+package net.minecraft.server;
+
+public interface KeyedObject {
+    MinecraftKey getMinecraftKey();
+    default String getMinecraftKeyString() {
+        MinecraftKey key = getMinecraftKey();
+        return key != null ? key.toString() : null;
+    }
+}
diff --git a/src/main/java/net/minecraft/server/TileEntity.java b/src/main/java/net/minecraft/server/TileEntity.java
index 6d06812f5fb6366ccd2673e9155be869b9bc0f6d..3cae7ef750371cee741c2f27799c1bb5864a278a 100644
--- a/src/main/java/net/minecraft/server/TileEntity.java
+++ b/src/main/java/net/minecraft/server/TileEntity.java
@@ -11,7 +11,7 @@ import org.bukkit.inventory.InventoryHolder;
 // CraftBukkit end
 import org.spigotmc.CustomTimingsHandler; // Spigot
 
-public abstract class TileEntity {
+public abstract class TileEntity implements KeyedObject { // Paper
 
     public CustomTimingsHandler tickTimer = org.bukkit.craftbukkit.SpigotTimings.getTileEntityTimings(this); // Spigot
     // CraftBukkit start - data containers
@@ -19,7 +19,7 @@ public abstract class TileEntity {
     public CraftPersistentDataContainer persistentDataContainer;
     // CraftBukkit end
     private static final Logger LOGGER = LogManager.getLogger();
-    private final TileEntityTypes<?> tileType;
+    private final TileEntityTypes<?> tileType; public TileEntityTypes getTileEntityType() { return tileType; } // Paper - OBFHELPER
     @Nullable
     protected World world;
     protected BlockPosition position;
@@ -33,6 +33,26 @@ public abstract class TileEntity {
         this.tileType = tileentitytypes;
     }
 
+    // Paper start
+    private String tileEntityKeyString = null;
+    private MinecraftKey tileEntityKey = null;
+
+    @Override
+    public MinecraftKey getMinecraftKey() {
+        if (tileEntityKey == null) {
+            tileEntityKey = TileEntityTypes.a(this.getTileEntityType());
+            tileEntityKeyString = tileEntityKey != null ? tileEntityKey.toString() : null;
+        }
+        return tileEntityKey;
+    }
+
+    @Override
+    public String getMinecraftKeyString() {
+        getMinecraftKey(); // Try to load if it doesn't exists.
+        return tileEntityKeyString;
+    }
+    // Paper end
+
     @Nullable
     public World getWorld() {
         return this.world;