From d33c06ead26d635d781753c936c408c3d420842f Mon Sep 17 00:00:00 2001 From: EvilSeph Date: Tue, 7 Jun 2011 04:21:33 -0400 Subject: [PATCH] Added UniqueId to entities. Thanks Afforess! --- src/main/java/net/minecraft/server/Entity.java | 15 +++++++++++++++ .../bukkit/craftbukkit/entity/CraftEntity.java | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java index cb23f89c3f..8e936c6096 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -4,6 +4,8 @@ import java.util.List; import java.util.Random; // CraftBukkit start +import java.util.UUID; + import org.bukkit.Bukkit; import org.bukkit.block.BlockFace; import org.bukkit.craftbukkit.entity.CraftVehicle; @@ -83,6 +85,7 @@ public abstract class Entity { public int bH; public int bI; public boolean bJ; + public UUID uniqueId = UUID.randomUUID(); // CraftBukkit public Entity(World world) { this.id = entityCount++; @@ -900,6 +903,8 @@ public abstract class Entity { nbttagcompound.a("Air", (short) this.airTicks); nbttagcompound.a("OnGround", this.onGround); nbttagcompound.setString("World", world.worldData.name); // CraftBukkit + nbttagcompound.a("UUIDLeast", this.uniqueId.getLeastSignificantBits()); // CraftBukkit + nbttagcompound.a("UUIDMost", this.uniqueId.getMostSignificantBits()); // CraftBukkit this.b(nbttagcompound); } @@ -933,6 +938,16 @@ public abstract class Entity { this.airTicks = nbttagcompound.d("Air"); this.onGround = nbttagcompound.m("OnGround"); this.setPosition(this.locX, this.locY, this.locZ); + + // CraftBukkit start + long least = nbttagcompound.f("UUIDLeast"); + long most = nbttagcompound.f("UUIDMost"); + + if (least != 0L && most != 0L) { + this.uniqueId = new UUID(most, least); + } + // CraftBukkit end + this.c(this.yaw, this.pitch); this.a(nbttagcompound); diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java index c77e0336ef..6f74777083 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java @@ -11,6 +11,7 @@ import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.util.Vector; import java.util.List; +import java.util.UUID; public abstract class CraftEntity implements org.bukkit.entity.Entity { protected final CraftServer server; @@ -264,4 +265,8 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { public EntityDamageEvent getLastDamageCause() { return lastDamageEvent; } + + public UUID getUniqueId() { + return getHandle().uniqueId; + } }