From 471ff10805ee8ef1b93d19bd05a91b9f372417c9 Mon Sep 17 00:00:00 2001 From: Aikar 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 ed39b122e..3a8902bf1 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,23 @@ public abstract class Entity implements ICommandListener { return true; } + // Paper start + public final MinecraftKey entityKey = EntityTypes.getKey(this); + public final String entityKeyString = entityKey != null ? entityKey.toString() : null; + + @Override + public MinecraftKey getMinecraftKey() { + return entityKey; + } + + @Override + public String getMinecraftKeyString() { + return entityKeyString; + } @Nullable public final String getSaveID() { - MinecraftKey minecraftkey = EntityTypes.a(this); - - return minecraftkey == null ? null : minecraftkey.toString(); + return entityKeyString; + // 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 000000000..61c2b993c --- /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 5a5a588e7..672ba3134 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,21 @@ public abstract class TileEntity { TileEntity.f.a(new MinecraftKey(s), oclass); } - @Nullable - public static MinecraftKey a(Class oclass) { + // Paper start + public final MinecraftKey tileEntityKey = getKey(this.getClass()); + public final String tileEntityKeyString = tileEntityKey != null ? tileEntityKey.toString() : null; + + @Override + public MinecraftKey getMinecraftKey() { + return tileEntityKey; + } + + @Override + public String getMinecraftKeyString() { + return tileEntityKeyString; + } + @Nullable public static MinecraftKey getKey(Class oclass) { return a(oclass); } // Paper - OBFHELPER + @Nullable public static MinecraftKey a(Class oclass) { return (MinecraftKey) TileEntity.f.b(oclass); } -- 2.18.0