Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-15 12:30:06 +01:00
27c7749f42
- Re-removes Bukkit#getServerName - This was (hopefully?) only added back for Timings v2. It should be kept in that scope. - Intend to let PlayerViewDistance API slip. Given the scope of the changes in this area it seems best to let this slip past initial release. It can be re-added when there is additional time to focus on it and the changed systems it relies on. If it is fixed prior to release this is implemented as a single shim patch that can be dropped.
104 Zeilen
5.4 KiB
Diff
104 Zeilen
5.4 KiB
Diff
From faab98f0277620b2a58857119f013b3b06e6a313 Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Sun, 24 Mar 2019 00:24:52 -0400
|
|
Subject: [PATCH] Entity#getEntitySpawnReason
|
|
|
|
Allows you to return the SpawnReason for why an Entity Spawned
|
|
|
|
Pre existing entities will return NATURAL if it was a non
|
|
persistenting Living Entity, SPAWNER for spawners,
|
|
or DEFAULT since data was not stored.
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
|
|
index 1cb96685a..23f910187 100644
|
|
--- a/src/main/java/net/minecraft/server/Entity.java
|
|
+++ b/src/main/java/net/minecraft/server/Entity.java
|
|
@@ -68,6 +68,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
|
|
}
|
|
};
|
|
List<Entity> entitySlice = null;
|
|
+ public org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason;
|
|
// Paper end
|
|
static boolean isLevelAtLeast(NBTTagCompound tag, int level) {
|
|
return tag.hasKey("Bukkit.updateLevel") && tag.getInt("Bukkit.updateLevel") >= level;
|
|
@@ -1594,6 +1595,9 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
|
|
if (this.origin != null) {
|
|
nbttagcompound.set("Paper.Origin", this.createList(origin.getX(), origin.getY(), origin.getZ()));
|
|
}
|
|
+ if (spawnReason != null) {
|
|
+ nbttagcompound.setString("Paper.SpawnReason", spawnReason.name());
|
|
+ }
|
|
// Save entity's from mob spawner status
|
|
if (spawnedViaMobSpawner) {
|
|
nbttagcompound.setBoolean("Paper.FromMobSpawner", true);
|
|
@@ -1727,6 +1731,26 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
|
|
}
|
|
|
|
spawnedViaMobSpawner = nbttagcompound.getBoolean("Paper.FromMobSpawner"); // Restore entity's from mob spawner status
|
|
+ if (nbttagcompound.hasKey("Paper.SpawnReason")) {
|
|
+ String spawnReasonName = nbttagcompound.getString("Paper.SpawnReason");
|
|
+ try {
|
|
+ spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.valueOf(spawnReasonName);
|
|
+ } catch (Exception ignored) {
|
|
+ LogManager.getLogger().error("Unknown SpawnReason " + spawnReasonName + " for " + this);
|
|
+ }
|
|
+ }
|
|
+ if (spawnReason == null) {
|
|
+ if (spawnedViaMobSpawner) {
|
|
+ spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER;
|
|
+ } else if (this instanceof EntityInsentient && (this instanceof EntityAnimal || this instanceof EntityFish) && !((EntityInsentient) this).isTypeNotPersistent(0.0)) {
|
|
+ if (!nbttagcompound.getBoolean("PersistenceRequired")) {
|
|
+ spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ if (spawnReason == null) {
|
|
+ spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT;
|
|
+ }
|
|
// Paper end
|
|
|
|
} catch (Throwable throwable) {
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
|
|
index 51272a51b..4bc465ef4 100644
|
|
--- a/src/main/java/net/minecraft/server/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/PlayerList.java
|
|
@@ -249,7 +249,7 @@ public abstract class PlayerList {
|
|
// CraftBukkit start
|
|
WorldServer finalWorldServer = worldserver;
|
|
Entity entity = EntityTypes.a(nbttagcompound1.getCompound("Entity"), finalWorldServer, (entity1) -> {
|
|
- return !finalWorldServer.addEntitySerialized(entity1) ? null : entity1;
|
|
+ return !finalWorldServer.addEntitySerialized(entity1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.MOUNT) ? null : entity1; // Paper
|
|
// CraftBukkit end
|
|
});
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
|
|
index a1f5f7b07..bfc3432a8 100644
|
|
--- a/src/main/java/net/minecraft/server/WorldServer.java
|
|
+++ b/src/main/java/net/minecraft/server/WorldServer.java
|
|
@@ -939,6 +939,7 @@ public class WorldServer extends World {
|
|
// CraftBukkit start
|
|
private boolean addEntity0(Entity entity, CreatureSpawnEvent.SpawnReason spawnReason) {
|
|
org.spigotmc.AsyncCatcher.catchOp( "entity add"); // Spigot
|
|
+ if (entity.spawnReason == null) entity.spawnReason = spawnReason; // Paper
|
|
if (entity.valid) { MinecraftServer.LOGGER.error("Attempted Double World add on " + entity, new Throwable()); return true; } // Paper
|
|
if (entity.dead) {
|
|
// Paper start
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
index af0fc9bd7..f1938695d 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
@@ -1053,5 +1053,10 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
|
public boolean fromMobSpawner() {
|
|
return getHandle().spawnedViaMobSpawner;
|
|
}
|
|
+
|
|
+ @Override
|
|
+ public org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason getEntitySpawnReason() {
|
|
+ return getHandle().spawnReason;
|
|
+ }
|
|
// Paper end
|
|
}
|
|
--
|
|
2.21.0
|
|
|