From 185b6b4c592257114f03a5d870be72aae3aa9d6d Mon Sep 17 00:00:00 2001 From: Aikar Date: Sat, 21 Jul 2018 08:09:40 -0400 Subject: [PATCH 1/7] Create a symlink on not-windows to current minecraft decompile dir This is useful for project developers switching back and forth between 1.12.2 and 1.13 so we can have our IDE automatically use the current version we are working on for included mc-dev files. --- scripts/decompile.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/decompile.sh b/scripts/decompile.sh index f2c1754fdd..2018259c37 100755 --- a/scripts/decompile.sh +++ b/scripts/decompile.sh @@ -6,9 +6,9 @@ PS1="$" basedir="$(cd "$1" && pwd -P)" workdir="$basedir/work" minecraftversion=$(cat "$workdir/BuildData/info.json" | grep minecraftVersion | cut -d '"' -f 4) +windows="$([[ "$OSTYPE" == "cygwin" || "$OSTYPE" == "msys" ]] && echo "true" || echo "false")" decompiledir="$workdir/Minecraft/$minecraftversion" classdir="$decompiledir/classes" - echo "Extracting NMS classes..." if [ ! -d "$classdir" ]; then mkdir -p "$classdir" @@ -30,4 +30,13 @@ if [ ! -d "$decompiledir/net/minecraft/server" ]; then exit 1 fi fi + +# set a symlink to current +currentlink="$workdir/Minecraft/current" +if ([ ! -e "$currentlink" ] || [ -L "$currentlink" ]) && [ "$windows" == "false" ]; then + echo "Pointing $currentlink to $minecraftversion" + rm -rf "$currentlink" + ln -sfn "$minecraftversion" "$currentlink" +fi + ) From 33cf273156130024d6f98a7f68693cf7b9723f49 Mon Sep 17 00:00:00 2001 From: Aikar Date: Sat, 21 Jul 2018 09:03:10 -0400 Subject: [PATCH 2/7] Guard the Entity.SHARED_RANDOM from seed changes I don't clearly see any, but as a protection for future changes. --- .../Cap-Entity-Collisions.patch | 2 +- ...-allow-entities-to-ride-themselves-572.patch | 2 +- .../Don-t-let-fishinghooks-use-portals.patch | 2 +- .../Don-t-teleport-dead-entities.patch | 2 +- .../Entity-Tracking-Improvements.patch | 2 +- .../Entity-fromMobSpawner.patch | 2 +- .../Make-entities-look-for-hoppers.patch | 2 +- ...vanilla-per-world-scoreboard-coloring-.patch | 2 +- .../Optional-TNT-doesn-t-move-in-water.patch | 2 +- ...-remove-entities-on-dimension-teleport.patch | 6 +++--- .../Use-a-Shared-Random-for-Entities.patch | 17 +++++++++++++++-- .../Vanished-players-don-t-have-rights.patch | 2 +- .../Vehicle-Event-Cancellation-Changes.patch | 2 +- 13 files changed, 29 insertions(+), 16 deletions(-) diff --git a/Spigot-Server-Patches/Cap-Entity-Collisions.patch b/Spigot-Server-Patches/Cap-Entity-Collisions.patch index b7dcecc518..e519ae05cc 100644 --- a/Spigot-Server-Patches/Cap-Entity-Collisions.patch +++ b/Spigot-Server-Patches/Cap-Entity-Collisions.patch @@ -27,7 +27,7 @@ index 5f06d4e5e..29b4bdb47 100644 + } } diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java -index 20324deeb..b4233df5f 100644 +index 92b2bcb86..5a4de30fe 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -0,0 +0,0 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper diff --git a/Spigot-Server-Patches/Don-t-allow-entities-to-ride-themselves-572.patch b/Spigot-Server-Patches/Don-t-allow-entities-to-ride-themselves-572.patch index 218a3cfd6f..6c26b4e26b 100644 --- a/Spigot-Server-Patches/Don-t-allow-entities-to-ride-themselves-572.patch +++ b/Spigot-Server-Patches/Don-t-allow-entities-to-ride-themselves-572.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Don't allow entities to ride themselves - #572 diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java -index b6711dcfa..e7f63c927 100644 +index 6d1e61e23..92b2bcb86 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -0,0 +0,0 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper diff --git a/Spigot-Server-Patches/Don-t-let-fishinghooks-use-portals.patch b/Spigot-Server-Patches/Don-t-let-fishinghooks-use-portals.patch index e63387125b..dcd132001e 100644 --- a/Spigot-Server-Patches/Don-t-let-fishinghooks-use-portals.patch +++ b/Spigot-Server-Patches/Don-t-let-fishinghooks-use-portals.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Don't let fishinghooks use portals diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java -index c675a6e16..f71528b5f 100644 +index 0950c315f..d79844a98 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -0,0 +0,0 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper diff --git a/Spigot-Server-Patches/Don-t-teleport-dead-entities.patch b/Spigot-Server-Patches/Don-t-teleport-dead-entities.patch index 9a2a869adc..01e4686f72 100644 --- a/Spigot-Server-Patches/Don-t-teleport-dead-entities.patch +++ b/Spigot-Server-Patches/Don-t-teleport-dead-entities.patch @@ -7,7 +7,7 @@ Had some issue with this in past, and this is the vanilla logic. Potentially an old CB change that's no longer needed. diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java -index eb07d4233..e2202ed0c 100644 +index daf97bce3..87b82f908 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -0,0 +0,0 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper diff --git a/Spigot-Server-Patches/Entity-Tracking-Improvements.patch b/Spigot-Server-Patches/Entity-Tracking-Improvements.patch index 585cc4d692..25e88f6eef 100644 --- a/Spigot-Server-Patches/Entity-Tracking-Improvements.patch +++ b/Spigot-Server-Patches/Entity-Tracking-Improvements.patch @@ -7,7 +7,7 @@ If any part of a Vehicle/Passenger relationship is visible to a player, send all passenger/vehicles to the player in the chain. diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java -index d1f07bbbd..945f06c93 100644 +index a3e9ee052..9b01c23e0 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -0,0 +0,0 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper diff --git a/Spigot-Server-Patches/Entity-fromMobSpawner.patch b/Spigot-Server-Patches/Entity-fromMobSpawner.patch index fbf6f7a3ac..40037b9f05 100644 --- a/Spigot-Server-Patches/Entity-fromMobSpawner.patch +++ b/Spigot-Server-Patches/Entity-fromMobSpawner.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Entity#fromMobSpawner() diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java -index b4233df5f..00791faf2 100644 +index 5a4de30fe..2dbb88f2d 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -0,0 +0,0 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper diff --git a/Spigot-Server-Patches/Make-entities-look-for-hoppers.patch b/Spigot-Server-Patches/Make-entities-look-for-hoppers.patch index 9f786e9369..132a029e92 100644 --- a/Spigot-Server-Patches/Make-entities-look-for-hoppers.patch +++ b/Spigot-Server-Patches/Make-entities-look-for-hoppers.patch @@ -133,7 +133,7 @@ index 008ed206d..b3c1f550c 100644 this.b = i; this.c = j; diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java -index cb9ef622c..c675a6e16 100644 +index 0a62ebf4a..0950c315f 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -0,0 +0,0 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper diff --git a/Spigot-Server-Patches/Option-to-use-vanilla-per-world-scoreboard-coloring-.patch b/Spigot-Server-Patches/Option-to-use-vanilla-per-world-scoreboard-coloring-.patch index 3f6db273fb..de115b9a2c 100644 --- a/Spigot-Server-Patches/Option-to-use-vanilla-per-world-scoreboard-coloring-.patch +++ b/Spigot-Server-Patches/Option-to-use-vanilla-per-world-scoreboard-coloring-.patch @@ -19,7 +19,7 @@ index abc1aabdd..6ea608ba9 100644 + } } diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java -index e2202ed0c..88faa4601 100644 +index 87b82f908..fa9319aff 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -0,0 +0,0 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper diff --git a/Spigot-Server-Patches/Optional-TNT-doesn-t-move-in-water.patch b/Spigot-Server-Patches/Optional-TNT-doesn-t-move-in-water.patch index 8ed18760d8..60336912ac 100644 --- a/Spigot-Server-Patches/Optional-TNT-doesn-t-move-in-water.patch +++ b/Spigot-Server-Patches/Optional-TNT-doesn-t-move-in-water.patch @@ -32,7 +32,7 @@ index 067cb233e..06acdaaf0 100644 + } } diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java -index c105dd9b0..334441ed7 100644 +index 9b01c23e0..0a62ebf4a 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -0,0 +0,0 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper diff --git a/Spigot-Server-Patches/Properly-remove-entities-on-dimension-teleport.patch b/Spigot-Server-Patches/Properly-remove-entities-on-dimension-teleport.patch index 24aba42aba..62247100bb 100644 --- a/Spigot-Server-Patches/Properly-remove-entities-on-dimension-teleport.patch +++ b/Spigot-Server-Patches/Properly-remove-entities-on-dimension-teleport.patch @@ -22,7 +22,7 @@ requirement, but plugins (such as my own) use this method to trigger a "reload" of the entity on the client. diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java -index 7b17c32bb..d03e7c24f 100644 +index 2dbb88f2d..80ecdb282 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -0,0 +0,0 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper @@ -35,14 +35,14 @@ index 7b17c32bb..d03e7c24f 100644 this.world.methodProfiler.a("reposition"); /* CraftBukkit start - Handled in calculateTarget diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java -index 49019d54d..9fe5c4406 100644 +index 49019d54d..bba2e164f 100644 --- a/src/main/java/net/minecraft/server/WorldServer.java +++ b/src/main/java/net/minecraft/server/WorldServer.java @@ -0,0 +0,0 @@ public class WorldServer extends World implements IAsyncTaskHandler { } protected void c(Entity entity) { -+ if (!entity.valid) return; // Paper - Already removed, dont fire twice - this looks like it can happen even without our changes ++ if (!this.entitiesByUUID.containsKey(entity.getUniqueID()) && !entity.valid) return; // Paper - Already removed, dont fire twice - this looks like it can happen even without our changes super.c(entity); this.entitiesById.d(entity.getId()); this.entitiesByUUID.remove(entity.getUniqueID()); diff --git a/Spigot-Server-Patches/Use-a-Shared-Random-for-Entities.patch b/Spigot-Server-Patches/Use-a-Shared-Random-for-Entities.patch index 11e964da2c..236e260ec8 100644 --- a/Spigot-Server-Patches/Use-a-Shared-Random-for-Entities.patch +++ b/Spigot-Server-Patches/Use-a-Shared-Random-for-Entities.patch @@ -6,14 +6,27 @@ Subject: [PATCH] Use a Shared Random for Entities Reduces memory usage and provides ensures more randomness, Especially since a lot of garbage entity objects get created. diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java -index b4ad611fc..4a08db5ba 100644 +index f547dbfd0..daf97bce3 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -0,0 +0,0 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper // CraftBukkit start private static final int CURRENT_LEVEL = 2; -+ public static Random SHARED_RANDOM = new Random(); // Paper ++ // Paper start ++ public static Random SHARED_RANDOM = new Random() { ++ private boolean locked = false; ++ @Override ++ public synchronized void setSeed(long seed) { ++ if (locked) { ++ LogManager.getLogger().error("Ignoring setSeed on Entity.SHARED_RANDOM", new Throwable()); ++ } else { ++ super.setSeed(seed); ++ locked = true; ++ } ++ } ++ }; ++ // Paper end static boolean isLevelAtLeast(NBTTagCompound tag, int level) { return tag.hasKey("Bukkit.updateLevel") && tag.getInt("Bukkit.updateLevel") >= level; } diff --git a/Spigot-Server-Patches/Vanished-players-don-t-have-rights.patch b/Spigot-Server-Patches/Vanished-players-don-t-have-rights.patch index 03f4a5529c..d47c797797 100644 --- a/Spigot-Server-Patches/Vanished-players-don-t-have-rights.patch +++ b/Spigot-Server-Patches/Vanished-players-don-t-have-rights.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Vanished players don't have rights diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java -index f71528b5f..b13830e87 100644 +index d79844a98..6d1e61e23 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -0,0 +0,0 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper diff --git a/Spigot-Server-Patches/Vehicle-Event-Cancellation-Changes.patch b/Spigot-Server-Patches/Vehicle-Event-Cancellation-Changes.patch index ef41df90ca..1b392eecc5 100644 --- a/Spigot-Server-Patches/Vehicle-Event-Cancellation-Changes.patch +++ b/Spigot-Server-Patches/Vehicle-Event-Cancellation-Changes.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Vehicle Event Cancellation Changes diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java -index 88faa4601..aece54d26 100644 +index fa9319aff..a3e9ee052 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -0,0 +0,0 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper From 19cec888527af7bf5855c9be61bcc3e135f4af94 Mon Sep 17 00:00:00 2001 From: Aikar Date: Sat, 21 Jul 2018 10:29:14 -0400 Subject: [PATCH 3/7] Add Debug Entities option to debug dupe uuid issues Add -Ddebug.entities=true to your JVM flags to enable more logging --- ...ies-option-to-debug-dupe-uuid-issues.patch | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 Spigot-Server-Patches/Add-Debug-Entities-option-to-debug-dupe-uuid-issues.patch diff --git a/Spigot-Server-Patches/Add-Debug-Entities-option-to-debug-dupe-uuid-issues.patch b/Spigot-Server-Patches/Add-Debug-Entities-option-to-debug-dupe-uuid-issues.patch new file mode 100644 index 0000000000..dceaca58c0 --- /dev/null +++ b/Spigot-Server-Patches/Add-Debug-Entities-option-to-debug-dupe-uuid-issues.patch @@ -0,0 +1,93 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Aikar +Date: Sat, 21 Jul 2018 08:25:40 -0400 +Subject: [PATCH] Add Debug Entities option to debug dupe uuid issues + +Add -Ddebug.entities=true to your JVM flags to gain more information + +diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java +index f6b755863..108654d63 100644 +--- a/src/main/java/net/minecraft/server/Entity.java ++++ b/src/main/java/net/minecraft/server/Entity.java +@@ -0,0 +0,0 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper + } + return bukkitEntity; + } ++ Throwable addedToWorldStack; // Paper - entity debug + // CraftBukikt end + + private static final Logger a = LogManager.getLogger(); +diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java +index b16324e1a..994d4bbb8 100644 +--- a/src/main/java/net/minecraft/server/WorldServer.java ++++ b/src/main/java/net/minecraft/server/WorldServer.java +@@ -0,0 +0,0 @@ import com.google.common.util.concurrent.ListenableFuture; + import java.io.File; + import java.util.ArrayList; + import java.util.Collection; ++import java.util.Date; + import java.util.Iterator; + import java.util.List; + import java.util.Map; +@@ -0,0 +0,0 @@ public class WorldServer extends World implements IAsyncTaskHandler { + private final List W = Lists.newArrayList(); + + // CraftBukkit start ++ private static final boolean DEBUG_ENTITIES = Boolean.getBoolean("debug.entities"); // Paper ++ private static Throwable getAddToWorldStackTrace(Entity entity) { ++ return new Throwable(entity + " Added to world at " + new Date()); ++ } + public final int dimension; + + // Add env and gen to constructor +@@ -0,0 +0,0 @@ public class WorldServer extends World implements IAsyncTaskHandler { + private boolean j(Entity entity) { + if (entity.dead) { + WorldServer.a.warn("Tried to add entity {} but it was marked as removed already", EntityTypes.a(entity)); // CraftBukkit // Paper ++ if (DEBUG_ENTITIES) getAddToWorldStackTrace(entity).printStackTrace(); + return false; + } else { + UUID uuid = entity.getUniqueID(); +@@ -0,0 +0,0 @@ public class WorldServer extends World implements IAsyncTaskHandler { + this.f.remove(entity1); + } else { + if (!(entity instanceof EntityHuman)) { +- WorldServer.a.error("Keeping entity {} that already exists with UUID {} - " + entity1, EntityTypes.a(entity1), uuid.toString()); // CraftBukkit // Paper ++ WorldServer.a.error("Keeping entity {} that already exists with UUID {}", entity1, uuid.toString()); // CraftBukkit // Paper + WorldServer.a.error("Deleting duplicate entity {}", entity); // Paper ++ if (DEBUG_ENTITIES) { ++ if (entity1.addedToWorldStack != null) { ++ entity1.addedToWorldStack.printStackTrace(); ++ } ++ getAddToWorldStackTrace(entity).printStackTrace(); ++ } + return false; + } + +@@ -0,0 +0,0 @@ public class WorldServer extends World implements IAsyncTaskHandler { + protected void b(Entity entity) { + super.b(entity); + this.entitiesById.a(entity.getId(), entity); +- this.entitiesByUUID.put(entity.getUniqueID(), entity); ++ // Paper start ++ if (DEBUG_ENTITIES) { ++ entity.addedToWorldStack = getAddToWorldStackTrace(entity); ++ } ++ Entity old = this.entitiesByUUID.put(entity.getUniqueID(), entity); ++ if (old != null && old.getId() != entity.getId() && old.valid) { ++ Logger logger = LogManager.getLogger(); ++ logger.error("Overwrote an existing entity " + old + " with " + entity); ++ if (DEBUG_ENTITIES) { ++ if (old.addedToWorldStack != null) { ++ old.addedToWorldStack.printStackTrace(); ++ } else { ++ logger.error("Oddly, the old entity was not added to the world in the normal way. Plugins?"); ++ } ++ entity.addedToWorldStack.printStackTrace(); ++ } ++ } ++ // Paper end + Entity[] aentity = entity.bb(); + + if (aentity != null) { +-- \ No newline at end of file From f8af5faa43e8f661946932263defcb7ae36d4848 Mon Sep 17 00:00:00 2001 From: Aikar Date: Sat, 21 Jul 2018 10:29:37 -0400 Subject: [PATCH 4/7] Add more information to Entity.toString() --- ...patch => add-more-information-to-Entity.toString.patch} | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) rename Spigot-Server-Patches/{add-uuid-to-Entity.toString.patch => add-more-information-to-Entity.toString.patch} (65%) diff --git a/Spigot-Server-Patches/add-uuid-to-Entity.toString.patch b/Spigot-Server-Patches/add-more-information-to-Entity.toString.patch similarity index 65% rename from Spigot-Server-Patches/add-uuid-to-Entity.toString.patch rename to Spigot-Server-Patches/add-more-information-to-Entity.toString.patch index 386b4db556..0362c15512 100644 --- a/Spigot-Server-Patches/add-uuid-to-Entity.toString.patch +++ b/Spigot-Server-Patches/add-more-information-to-Entity.toString.patch @@ -1,11 +1,12 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Aikar Date: Thu, 19 Jul 2018 01:13:28 -0400 -Subject: [PATCH] add uuid to Entity.toString() +Subject: [PATCH] add more information to Entity.toString() +UUID, ticks lived, valid, dead diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java -index d03e7c24f..fe1ccba8d 100644 +index 80ecdb282..f6b755863 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -0,0 +0,0 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper @@ -13,7 +14,7 @@ index d03e7c24f..fe1ccba8d 100644 public String toString() { - return String.format("%s[\'%s\'/%d, l=\'%s\', x=%.2f, y=%.2f, z=%.2f]", new Object[] { this.getClass().getSimpleName(), this.getName(), Integer.valueOf(this.id), this.world == null ? "~NULL~" : this.world.getWorldData().getName(), Double.valueOf(this.locX), Double.valueOf(this.locY), Double.valueOf(this.locZ)}); -+ return String.format("%s[\'%s\'/%d, uuid=\'%s\', l=\'%s\', x=%.2f, y=%.2f, z=%.2f]", new Object[] { this.getClass().getSimpleName(), this.getName(), Integer.valueOf(this.id), this.uniqueID.toString(), this.world == null ? "~NULL~" : this.world.getWorldData().getName(), Double.valueOf(this.locX), Double.valueOf(this.locY), Double.valueOf(this.locZ)}); // Paper - add UUID ++ return String.format("%s[\'%s\'/%d, uuid=\'%s\', l=\'%s\', x=%.2f, y=%.2f, z=%.2f, tl=%d, v=%b, d=%b]", new Object[] { this.getClass().getSimpleName(), this.getName(), Integer.valueOf(this.id), this.uniqueID.toString(), this.world == null ? "~NULL~" : this.world.getWorldData().getName(), Double.valueOf(this.locX), Double.valueOf(this.locY), Double.valueOf(this.locZ), this.ticksLived, this.valid, this.dead}); // Paper - add more information } public boolean isInvulnerable(DamageSource damagesource) { From d291411d94792001825619717bec9502f19d5644 Mon Sep 17 00:00:00 2001 From: Aikar Date: Sat, 21 Jul 2018 12:07:33 -0400 Subject: [PATCH 5/7] change LAST_EDIT to PAPER_LAST_EDIT for edit commands LAST_EDIT is way too generic considering it pollutes the users global environment.... --- paper | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/paper b/paper index 24bc958b55..f80040c8f6 100755 --- a/paper +++ b/paper @@ -99,7 +99,7 @@ case "$1" in "e" | "edit") case "$2" in "s" | "server") - export LAST_EDIT="$basedir/Paper-Server" + export PAPER_LAST_EDIT="$basedir/Paper-Server" cd "$basedir/Paper-Server" ( set -e @@ -110,7 +110,7 @@ case "$1" in ) ;; "a" | "api") - export LAST_EDIT="$basedir/Paper-API" + export PAPER_LAST_EDIT="$basedir/Paper-API" cd "$basedir/Paper-API" ( set -e @@ -121,8 +121,8 @@ case "$1" in ) ;; "c" | "continue") - cd "$LAST_EDIT" - unset LAST_EDIT + cd "$PAPER_LAST_EDIT" + unset PAPER_LAST_EDIT ( set -e From 1b8cee45a020503cf2278e03a94add800620b62d Mon Sep 17 00:00:00 2001 From: Aikar Date: Sat, 21 Jul 2018 14:46:56 -0400 Subject: [PATCH 6/7] Add more information to Entity.toString --- .../add-more-information-to-Entity.toString.patch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Spigot-Server-Patches/add-more-information-to-Entity.toString.patch b/Spigot-Server-Patches/add-more-information-to-Entity.toString.patch index 0362c15512..188e517b86 100644 --- a/Spigot-Server-Patches/add-more-information-to-Entity.toString.patch +++ b/Spigot-Server-Patches/add-more-information-to-Entity.toString.patch @@ -6,7 +6,7 @@ Subject: [PATCH] add more information to Entity.toString() UUID, ticks lived, valid, dead diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java -index 80ecdb282..f6b755863 100644 +index 80ecdb282..99dac412f 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -0,0 +0,0 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper @@ -14,7 +14,7 @@ index 80ecdb282..f6b755863 100644 public String toString() { - return String.format("%s[\'%s\'/%d, l=\'%s\', x=%.2f, y=%.2f, z=%.2f]", new Object[] { this.getClass().getSimpleName(), this.getName(), Integer.valueOf(this.id), this.world == null ? "~NULL~" : this.world.getWorldData().getName(), Double.valueOf(this.locX), Double.valueOf(this.locY), Double.valueOf(this.locZ)}); -+ return String.format("%s[\'%s\'/%d, uuid=\'%s\', l=\'%s\', x=%.2f, y=%.2f, z=%.2f, tl=%d, v=%b, d=%b]", new Object[] { this.getClass().getSimpleName(), this.getName(), Integer.valueOf(this.id), this.uniqueID.toString(), this.world == null ? "~NULL~" : this.world.getWorldData().getName(), Double.valueOf(this.locX), Double.valueOf(this.locY), Double.valueOf(this.locZ), this.ticksLived, this.valid, this.dead}); // Paper - add more information ++ return String.format("%s[\'%s\'/%d, uuid=\'%s\', l=\'%s\', x=%.2f, y=%.2f, z=%.2f, cx=%d, cd=%d, tl=%d, v=%b, d=%b]", new Object[] { this.getClass().getSimpleName(), this.getName(), Integer.valueOf(this.id), this.uniqueID.toString(), this.world == null ? "~NULL~" : this.world.getWorldData().getName(), Double.valueOf(this.locX), Double.valueOf(this.locY), Double.valueOf(this.locZ), getChunkX(), getChunkZ(), this.ticksLived, this.valid, this.dead}); // Paper - add more information } public boolean isInvulnerable(DamageSource damagesource) { From 51f03d3579820615c62f37e8e6dd846f565278b4 Mon Sep 17 00:00:00 2001 From: Aikar Date: Sat, 21 Jul 2018 14:47:05 -0400 Subject: [PATCH 7/7] Duplicate UUID Resolve Option Due to a bug in https://github.com/PaperMC/Paper/commit/bd75ff8b5b715c3fdf587b6aa3c0f2ecc4bf3443 which was added all the way back in March of 2016, it was unknown (potentially not at the time) that an entity might actually change the seed of the random object. At some point, EntitySquid did start setting the seed. Due to this shared random, this caused every entity to use a Random object with a predictable seed. This has caused entities to potentially generate with the same UUID.... Over the years, servers have had entities disappear, but no sign of trouble because CraftBukkit removed the log lines indicating that something was wrong. We have fixed the root issue causing duplicate UUID's, however we now have chunk files full of entities that have the same UUID as another entity! When these chunks load, the 2nd entity will not be added to the world correctly. If that chunk loads in a different order in the future, then it will reverse and the missing one is now the one added to the world and not the other. This results in very inconsistent entity behavior. This change allows you to recover any duplicate entity by generating a new UUID for it. This also lets you delete them instead if you don't want to risk having new entities added to the world that you previously did not see. But for those who are ok with leaving this inconsistent behavior, you may use WARN or NOTHING options. It is recommended you regenerate the entities, as these were legit entities, and deserve your love. --- .../Additional-Paper-Config-options.patch | 35 +++ .../Duplicate-UUID-Resolve-Option.patch | 207 ++++++++++++++++++ 2 files changed, 242 insertions(+) create mode 100644 Spigot-Server-Patches/Additional-Paper-Config-options.patch create mode 100644 Spigot-Server-Patches/Duplicate-UUID-Resolve-Option.patch diff --git a/Spigot-Server-Patches/Additional-Paper-Config-options.patch b/Spigot-Server-Patches/Additional-Paper-Config-options.patch new file mode 100644 index 0000000000..11679c2eb1 --- /dev/null +++ b/Spigot-Server-Patches/Additional-Paper-Config-options.patch @@ -0,0 +1,35 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Aikar +Date: Sat, 21 Jul 2018 14:23:31 -0400 +Subject: [PATCH] Additional Paper Config options + +Have to keep as sep patch for now until 1.13, otherwise we can't merge :/ + +diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java +index 62bce1806..5a17ce3d2 100644 +--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java ++++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java +@@ -0,0 +0,0 @@ public class PaperConfig { + readConfig(PaperConfig.class, null); + } + ++ protected static void logError(String s) { ++ Bukkit.getLogger().severe(s); ++ } ++ + protected static void log(String s) { + if (verbose) { + Bukkit.getLogger().info(s); +diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java +index 50416f40a..14c8edeff 100644 +--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java ++++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java +@@ -0,0 +0,0 @@ import org.bukkit.configuration.file.YamlConfiguration; + import org.spigotmc.SpigotWorldConfig; + + import static com.destroystokyo.paper.PaperConfig.log; ++import static com.destroystokyo.paper.PaperConfig.logError; + + public class PaperWorldConfig { + +-- \ No newline at end of file diff --git a/Spigot-Server-Patches/Duplicate-UUID-Resolve-Option.patch b/Spigot-Server-Patches/Duplicate-UUID-Resolve-Option.patch new file mode 100644 index 0000000000..56262f7bc9 --- /dev/null +++ b/Spigot-Server-Patches/Duplicate-UUID-Resolve-Option.patch @@ -0,0 +1,207 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Aikar +Date: Sat, 21 Jul 2018 14:27:34 -0400 +Subject: [PATCH] Duplicate UUID Resolve Option + +Due to a bug in https://github.com/PaperMC/Paper/commit/2e29af3df05ec0a383f48be549d1c03200756d24 +which was added all the way back in March of 2016, it was unknown (potentially not at the time) +that an entity might actually change the seed of the random object. + +At some point, EntitySquid did start setting the seed. Due to this shared random, this caused +every entity to use a Random object with a predictable seed. + +This has caused entities to potentially generate with the same UUID.... + +Over the years, servers have had entities disappear, but no sign of trouble +because CraftBukkit removed the log lines indicating that something was wrong. + +We have fixed the root issue causing duplicate UUID's, however we now have chunk +files full of entities that have the same UUID as another entity! + +When these chunks load, the 2nd entity will not be added to the world correctly. + +If that chunk loads in a different order in the future, then it will reverse and the +missing one is now the one added to the world and not the other. This results in very +inconsistent entity behavior. + +This change allows you to recover any duplicate entity by generating a new UUID for it. +This also lets you delete them instead if you don't want to risk having new entities added to +the world that you previously did not see. + +But for those who are ok with leaving this inconsistent behavior, you may use WARN or NOTHING options. + +It is recommended you regenerate the entities, as these were legit entities, and deserve your love. + +diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java +index 14c8edeff..e3f6557e1 100644 +--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java ++++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java +@@ -0,0 +0,0 @@ public class PaperWorldConfig { + log("Bed Search Radius: " + bedSearchRadius); + } + } ++ ++ public enum DuplicateUUIDMode { ++ REGEN, DELETE, NOTHING, WARN ++ } ++ public DuplicateUUIDMode duplicateUUIDMode = DuplicateUUIDMode.REGEN; ++ public void repairDuplicateUUID() { ++ String desiredMode = getString("duplicate-uuid-resolver", "regenerate").toLowerCase().trim(); ++ switch (desiredMode.toLowerCase()) { ++ case "regen": ++ case "regenerate": ++ duplicateUUIDMode = DuplicateUUIDMode.REGEN; ++ log("Duplicate UUID Resolve: Regenerate New UUID"); ++ break; ++ case "remove": ++ case "delete": ++ duplicateUUIDMode = DuplicateUUIDMode.DELETE; ++ log("Duplicate UUID Resolve: Delete Entity"); ++ break; ++ case "silent": ++ case "nothing": ++ duplicateUUIDMode = DuplicateUUIDMode.NOTHING; ++ logError("Duplicate UUID Resolve: Do Nothing (no logs) - Warning, may lose indication of bad things happening"); ++ logError("PaperMC Strongly discourages use of this setting! Triggering these messages means SOMETHING IS WRONG!"); ++ break; ++ case "log": ++ case "warn": ++ duplicateUUIDMode = DuplicateUUIDMode.WARN; ++ log("Duplicate UUID Resolve: Warn (do nothing but log it happened, may be spammy)"); ++ break; ++ default: ++ duplicateUUIDMode = DuplicateUUIDMode.WARN; ++ logError("Warning: Invalidate duplicate-uuid-resolver config " + desiredMode + " - must be one of: regen, delete, nothing, warn"); ++ log("Duplicate UUID Resolve: Warn (do nothing but log it happened, may be spammy)"); ++ break; ++ } ++ } + } +diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java +index 04adf4e3c..ea9559583 100644 +--- a/src/main/java/net/minecraft/server/Chunk.java ++++ b/src/main/java/net/minecraft/server/Chunk.java +@@ -0,0 +0,0 @@ + package net.minecraft.server; + ++// Paper start ++import com.destroystokyo.paper.PaperWorldConfig.DuplicateUUIDMode; ++import java.util.HashMap; ++import java.util.UUID; ++// Paper end + import com.destroystokyo.paper.exception.ServerInternalException; + import com.google.common.base.Predicate; + import com.google.common.collect.Maps; +@@ -0,0 +0,0 @@ public class Chunk { + public final World world; + public final int[] heightMap; + public Long scheduledForUnload; // Paper - delay chunk unloads ++ private static final Logger logger = LogManager.getLogger(); // Paper + public final int locX; + public final int locZ; + private boolean m; +@@ -0,0 +0,0 @@ public class Chunk { + if (i != this.locX || j != this.locZ) { + Chunk.e.warn("Wrong location! ({}, {}) should be ({}, {}), {}", Integer.valueOf(i), Integer.valueOf(j), Integer.valueOf(this.locX), Integer.valueOf(this.locZ), entity); + entity.die(); ++ return; // Paper + } + + int k = MathHelper.floor(entity.locY / 16.0D); +@@ -0,0 +0,0 @@ public class Chunk { + + for (int j = 0; j < i; ++j) { + List entityslice = aentityslice[j]; // Spigot ++ // Paper start ++ DuplicateUUIDMode mode = world.paperConfig.duplicateUUIDMode; ++ if (mode == DuplicateUUIDMode.DELETE || mode == DuplicateUUIDMode.REGEN) { ++ Map thisChunk = new HashMap<>(); ++ for (Iterator iterator = ((List) entityslice).iterator(); iterator.hasNext(); ) { ++ Entity entity = iterator.next(); ++ Entity other = ((WorldServer) world).entitiesByUUID.get(entity.uniqueID); ++ if (other == null) { ++ other = thisChunk.get(entity.uniqueID); ++ } ++ if (other != null) { ++ switch (mode) { ++ case REGEN: { ++ entity.setUUID(UUID.randomUUID()); ++ logger.error("Duplicate UUID found used by " + other); ++ logger.error("Regenerated a new UUID for " + entity); ++ break; ++ } ++ case DELETE: { ++ logger.error("Duplicate UUID found used by " + other); ++ logger.error("Deleting duplicate entity " + entity); ++ entity.die(); ++ iterator.remove(); ++ break; ++ } ++ } ++ } ++ thisChunk.put(entity.uniqueID, entity); ++ } ++ } ++ // Paper end + + this.world.a((Collection) entityslice); + } +diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java +index 0d3af8cb7..7188d0c99 100644 +--- a/src/main/java/net/minecraft/server/Entity.java ++++ b/src/main/java/net/minecraft/server/Entity.java +@@ -0,0 +0,0 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper + }); + } + ++ public void setUUID(UUID uuid) { a(uuid); } // Paper - OBFHELPER + public void a(UUID uuid) { + this.uniqueID = uuid; + this.ar = this.uniqueID.toString(); +diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java +index 994d4bbb8..1244baf45 100644 +--- a/src/main/java/net/minecraft/server/WorldServer.java ++++ b/src/main/java/net/minecraft/server/WorldServer.java +@@ -0,0 +0,0 @@ public class WorldServer extends World implements IAsyncTaskHandler { + private final PlayerChunkMap manager; + // private final Set nextTickListHash = Sets.newHashSet(); + private final HashTreeSet nextTickList = new HashTreeSet(); // CraftBukkit - HashTreeSet +- private final Map entitiesByUUID = Maps.newHashMap(); ++ public final Map entitiesByUUID = Maps.newHashMap(); // Paper + public boolean savingDisabled; + private boolean Q; + private int emptyTime; +@@ -0,0 +0,0 @@ public class WorldServer extends World implements IAsyncTaskHandler { + this.f.remove(entity1); + } else { + if (!(entity instanceof EntityHuman)) { +- WorldServer.a.error("Keeping entity {} that already exists with UUID {}", entity1, uuid.toString()); // CraftBukkit // Paper +- WorldServer.a.error("Deleting duplicate entity {}", entity); // Paper +- if (DEBUG_ENTITIES) { +- if (entity1.addedToWorldStack != null) { +- entity1.addedToWorldStack.printStackTrace(); ++ if (entity.world.paperConfig.duplicateUUIDMode != com.destroystokyo.paper.PaperWorldConfig.DuplicateUUIDMode.NOTHING) { ++ WorldServer.a.error("Keeping entity {} that already exists with UUID {}", entity1, uuid.toString()); // CraftBukkit // Paper ++ WorldServer.a.error("Duplicate entity {} will not be added to the world. See paper.yml duplicate-uuid-resolver and set this to either regen, delete or nothing to get rid of this message", entity); // Paper ++ if (DEBUG_ENTITIES) { ++ if (entity1.addedToWorldStack != null) { ++ entity1.addedToWorldStack.printStackTrace(); ++ } ++ getAddToWorldStackTrace(entity).printStackTrace(); + } +- getAddToWorldStackTrace(entity).printStackTrace(); + } ++ + return false; + } + +@@ -0,0 +0,0 @@ public class WorldServer extends World implements IAsyncTaskHandler { + entity.addedToWorldStack = getAddToWorldStackTrace(entity); + } + Entity old = this.entitiesByUUID.put(entity.getUniqueID(), entity); +- if (old != null && old.getId() != entity.getId() && old.valid) { ++ if (old != null && old.getId() != entity.getId() && old.valid && entity.world.paperConfig.duplicateUUIDMode != com.destroystokyo.paper.PaperWorldConfig.DuplicateUUIDMode.NOTHING) { + Logger logger = LogManager.getLogger(); + logger.error("Overwrote an existing entity " + old + " with " + entity); + if (DEBUG_ENTITIES) { +-- \ No newline at end of file