From dc136446fbe1f855933c217a2ea332926903df57 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Thu, 18 Jul 2024 16:50:16 +0200 Subject: [PATCH] Even more cleanup of mcutil patch --- .../server/Add-Lifecycle-Event-system.patch | 16 - .../Add-debug-for-sync-chunk-loads.patch | 6 +- .../Add-exception-reporting-event.patch | 23 +- patches/server/Basic-PlayerProfile-API.patch | 31 - .../server/Entity-Activation-Range-2.0.patch | 7 +- .../Fix-SpawnEggMeta-get-setSpawnedType.patch | 4 +- patches/server/MC-Utils.patch | 838 +----------------- patches/server/Mob-Pathfinding-API.patch | 2 +- .../Moonrise-optimisation-patches.patch | 92 +- patches/server/Paper-Plugins.patch | 17 - .../server/ProfileWhitelistVerifyEvent.patch | 3 +- patches/server/Timings-v2.patch | 25 +- 12 files changed, 96 insertions(+), 968 deletions(-) diff --git a/patches/server/Add-Lifecycle-Event-system.patch b/patches/server/Add-Lifecycle-Event-system.patch index 886493cebd..99c6e0f131 100644 --- a/patches/server/Add-Lifecycle-Event-system.patch +++ b/patches/server/Add-Lifecycle-Event-system.patch @@ -734,22 +734,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 org.spigotmc.WatchdogThread.hasStarted = false; // Paper - Disable watchdog early timeout on reload this.reloadCount++; this.configuration = YamlConfiguration.loadConfiguration(this.getConfigFile()); -diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/MinecraftInternalPlugin.java b/src/main/java/org/bukkit/craftbukkit/scheduler/MinecraftInternalPlugin.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/org/bukkit/craftbukkit/scheduler/MinecraftInternalPlugin.java -+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/MinecraftInternalPlugin.java -@@ -0,0 +0,0 @@ public class MinecraftInternalPlugin extends PluginBase { - public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { - throw new UnsupportedOperationException("Not supported."); - } -+ -+ // Paper start - lifecycle events -+ @Override -+ public @NotNull io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager getLifecycleManager() { -+ throw new UnsupportedOperationException("Not supported."); -+ } -+ // Paper end - lifecycle events - } diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java diff --git a/patches/server/Add-debug-for-sync-chunk-loads.patch b/patches/server/Add-debug-for-sync-chunk-loads.patch index ecef4523f2..51b2fee7c4 100644 --- a/patches/server/Add-debug-for-sync-chunk-loads.patch +++ b/patches/server/Add-debug-for-sync-chunk-loads.patch @@ -31,6 +31,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +import java.util.List; +import java.util.Map; +import java.util.WeakHashMap; ++import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.Level; + +public class SyncLoadFinder { @@ -69,7 +70,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + ++valueInMap.times; + -+ valueInMap.coordinateTimes.compute(io.papermc.paper.util.MCUtil.getCoordinateKey(chunkX, chunkZ), (Long keyInMap1, Integer valueInMap1) -> { ++ valueInMap.coordinateTimes.compute(ChunkPos.asLong(chunkX, chunkZ), (Long keyInMap1, Integer valueInMap1) -> { + return valueInMap1 == null ? Integer.valueOf(1) : Integer.valueOf(valueInMap1.intValue() + 1); + }); + @@ -122,7 +123,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + for (Long2IntMap.Entry coordinate : pair.getSecond().coordinateTimes.long2IntEntrySet()) { + final long key = coordinate.getLongKey(); + final int times = coordinate.getIntValue(); -+ coordinates.add("(" + io.papermc.paper.util.MCUtil.getCoordinateX(key) + "," + io.papermc.paper.util.MCUtil.getCoordinateZ(key) + "): " + times); ++ final ChunkPos chunkPos = new ChunkPos(key); ++ coordinates.add("(" + chunkPos.x + "," + chunkPos.z + "): " + times); + } + + stacktrace.add("coordinates", coordinates); diff --git a/patches/server/Add-exception-reporting-event.patch b/patches/server/Add-exception-reporting-event.patch index 1cede25cef..81a7c6fc63 100644 --- a/patches/server/Add-exception-reporting-event.patch +++ b/patches/server/Add-exception-reporting-event.patch @@ -175,15 +175,28 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java +++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java @@ -0,0 +0,0 @@ public class CraftScheduler implements BukkitScheduler { - msg, + try { + task.run(); + } catch (final Throwable throwable) { ++ // Paper start ++ final String logMessage = String.format( ++ "Task #%s for %s generated an exception", ++ task.getTaskId(), ++ task.getOwner().getDescription().getFullName()); + task.getOwner().getLogger().log( + Level.WARNING, +- String.format( +- "Task #%s for %s generated an exception", +- task.getTaskId(), +- task.getOwner().getDescription().getFullName()), ++ logMessage, throwable); - } + org.bukkit.Bukkit.getServer().getPluginManager().callEvent( -+ new com.destroystokyo.paper.event.server.ServerExceptionEvent(new com.destroystokyo.paper.exception.ServerSchedulerException(msg, throwable, task))); - // Paper end ++ new com.destroystokyo.paper.event.server.ServerExceptionEvent(new com.destroystokyo.paper.exception.ServerSchedulerException(logMessage, throwable, task))); ++ // Paper end } finally { this.currentTask = null; -@@ -0,0 +0,0 @@ public class CraftScheduler implements BukkitScheduler { + } this.parsePending(); } else { this.debugTail = this.debugTail.setNext(new CraftAsyncDebugger(currentTick + CraftScheduler.RECENT_TICKS, task.getOwner(), task.getTaskClass())); diff --git a/patches/server/Basic-PlayerProfile-API.patch b/patches/server/Basic-PlayerProfile-API.patch index 29226ee836..7d561dad2b 100644 --- a/patches/server/Basic-PlayerProfile-API.patch +++ b/patches/server/Basic-PlayerProfile-API.patch @@ -558,37 +558,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + @NotNull GameProfile buildGameProfile(); +} -diff --git a/src/main/java/io/papermc/paper/util/MCUtil.java b/src/main/java/io/papermc/paper/util/MCUtil.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/io/papermc/paper/util/MCUtil.java -+++ b/src/main/java/io/papermc/paper/util/MCUtil.java -@@ -0,0 +0,0 @@ - package io.papermc.paper.util; - -+import com.destroystokyo.paper.profile.CraftPlayerProfile; -+import com.destroystokyo.paper.profile.PlayerProfile; - import com.google.common.collect.ImmutableList; - import com.google.common.util.concurrent.ThreadFactoryBuilder; - import io.papermc.paper.math.BlockPosition; -@@ -0,0 +0,0 @@ import net.minecraft.world.level.ClipContext; - import net.minecraft.world.level.Level; - import net.minecraft.world.phys.Vec3; - import org.apache.commons.lang.exception.ExceptionUtils; -+import com.mojang.authlib.GameProfile; - import org.bukkit.Location; - import org.bukkit.block.BlockFace; - import org.bukkit.craftbukkit.CraftWorld; -@@ -0,0 +0,0 @@ public final class MCUtil { - return run.get(); - } - -+ public static PlayerProfile toBukkit(GameProfile profile) { -+ return CraftPlayerProfile.asBukkitMirror(profile); -+ } -+ - /** - * Calculates distance between 2 entities - * @param e1 diff --git a/src/main/java/net/minecraft/server/Main.java b/src/main/java/net/minecraft/server/Main.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/Main.java diff --git a/patches/server/Entity-Activation-Range-2.0.patch b/patches/server/Entity-Activation-Range-2.0.patch index c520ffd0b3..c2d3864405 100644 --- a/patches/server/Entity-Activation-Range-2.0.patch +++ b/patches/server/Entity-Activation-Range-2.0.patch @@ -175,13 +175,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/net/minecraft/world/entity/PathfinderMob.java +++ b/src/main/java/net/minecraft/world/entity/PathfinderMob.java @@ -0,0 +0,0 @@ public abstract class PathfinderMob extends Mob { + super(type, world); } - public org.bukkit.craftbukkit.entity.CraftCreature getBukkitCreature() { return (org.bukkit.craftbukkit.entity.CraftCreature) super.getBukkitEntity(); } // Paper -+ public BlockPos movingTarget = null; public BlockPos getMovingTarget() { return movingTarget; } // Paper - ++ public BlockPos movingTarget; public BlockPos getMovingTarget() { return movingTarget; } // Paper ++ public float getWalkTargetValue(BlockPos pos) { return this.getWalkTargetValue(pos, this.level()); + } diff --git a/src/main/java/net/minecraft/world/entity/ai/goal/GoalSelector.java b/src/main/java/net/minecraft/world/entity/ai/goal/GoalSelector.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/ai/goal/GoalSelector.java diff --git a/patches/server/Fix-SpawnEggMeta-get-setSpawnedType.patch b/patches/server/Fix-SpawnEggMeta-get-setSpawnedType.patch index 87808178a4..ad3b35bcb6 100644 --- a/patches/server/Fix-SpawnEggMeta-get-setSpawnedType.patch +++ b/patches/server/Fix-SpawnEggMeta-get-setSpawnedType.patch @@ -17,8 +17,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + public EntityType getCustomSpawnedType() { + return java.util.Optional.ofNullable(this.entityTag) + .map(tag -> tag.getString(ENTITY_ID.NBT)) -+ .flatMap(net.minecraft.world.entity.EntityType::byString) -+ .map(org.bukkit.craftbukkit.util.CraftMagicNumbers::getEntityType) ++ .map(net.minecraft.resources.ResourceLocation::tryParse) ++ .map(key -> key.getNamespace().equals("minecraft") ? EntityType.fromName(key.getPath()) : null) + .orElse(null); + } + diff --git a/patches/server/MC-Utils.patch b/patches/server/MC-Utils.patch index cbae094205..1f136fe3bb 100644 --- a/patches/server/MC-Utils.patch +++ b/patches/server/MC-Utils.patch @@ -4083,48 +4083,36 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 @@ -0,0 +0,0 @@ +package io.papermc.paper.util; + -+import com.google.common.collect.ImmutableList; +import com.google.common.util.concurrent.ThreadFactoryBuilder; +import io.papermc.paper.math.BlockPosition; +import io.papermc.paper.math.FinePosition; +import io.papermc.paper.math.Position; -+import it.unimi.dsi.fastutil.objects.ObjectRBTreeSet; -+import java.lang.ref.Cleaner; -+import net.minecraft.core.BlockPos; -+import net.minecraft.core.Direction; -+import net.minecraft.core.Vec3i; -+import net.minecraft.server.MinecraftServer; -+import net.minecraft.server.level.ServerLevel; -+import net.minecraft.world.entity.Entity; -+import net.minecraft.world.level.ChunkPos; -+import net.minecraft.world.level.ClipContext; -+import net.minecraft.world.level.Level; -+import net.minecraft.world.phys.Vec3; -+import org.apache.commons.lang.exception.ExceptionUtils; -+import org.bukkit.Location; -+import org.bukkit.block.BlockFace; -+import org.bukkit.craftbukkit.CraftWorld; -+import org.bukkit.craftbukkit.util.Waitable; -+import org.jetbrains.annotations.NotNull; -+import org.spigotmc.AsyncCatcher; -+ -+import javax.annotation.Nonnull; -+import javax.annotation.Nullable; +import java.util.List; -+import java.util.Queue; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; -+import java.util.concurrent.TimeoutException; -+import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.BiConsumer; +import java.util.function.Consumer; -+import java.util.function.Predicate; +import java.util.function.Supplier; ++import net.minecraft.core.BlockPos; ++import net.minecraft.core.Vec3i; ++import net.minecraft.server.MinecraftServer; ++import net.minecraft.world.level.ChunkPos; ++import net.minecraft.world.level.Level; ++import net.minecraft.world.phys.Vec3; ++import org.bukkit.Location; ++import org.bukkit.craftbukkit.util.Waitable; + +public final class MCUtil { ++ public static final java.util.concurrent.Executor MAIN_EXECUTOR = (run) -> { ++ if (!isMainThread()) { ++ MinecraftServer.getServer().execute(run); ++ } else { ++ run.run(); ++ } ++ }; + public static final ThreadPoolExecutor asyncExecutor = new ThreadPoolExecutor( + 0, 2, 60L, TimeUnit.SECONDS, + new LinkedBlockingQueue<>(), @@ -4133,79 +4121,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + .setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(MinecraftServer.LOGGER)) + .build() + ); -+ public static final ThreadPoolExecutor cleanerExecutor = new ThreadPoolExecutor( -+ 1, 1, 0L, TimeUnit.SECONDS, -+ new LinkedBlockingQueue<>(), -+ new ThreadFactoryBuilder() -+ .setNameFormat("Paper Object Cleaner") -+ .setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(MinecraftServer.LOGGER)) -+ .build() -+ ); + -+ public static final long INVALID_CHUNK_KEY = getCoordinateKey(Integer.MAX_VALUE, Integer.MAX_VALUE); -+ -+ -+ public static Runnable once(Runnable run) { -+ AtomicBoolean ran = new AtomicBoolean(false); -+ return () -> { -+ if (ran.compareAndSet(false, true)) { -+ run.run(); -+ } -+ }; -+ } -+ -+ public static Runnable once(List list, Consumer cb) { -+ return once(() -> { -+ list.forEach(cb); -+ }); -+ } -+ -+ private static Runnable makeCleanerCallback(Runnable run) { -+ return once(() -> cleanerExecutor.execute(run)); -+ } -+ -+ /** -+ * DANGER WILL ROBINSON: Be sure you do not use a lambda that lives in the object being monitored, or leaky leaky! -+ * @param obj -+ * @param run -+ * @return -+ */ -+ public static Runnable registerCleaner(Object obj, Runnable run) { -+ // Wrap callback in its own method above or the lambda will leak object -+ Runnable cleaner = makeCleanerCallback(run); -+ CleanerHolder.CLEANER.register(obj, cleaner); -+ return cleaner; -+ } -+ -+ private static final class CleanerHolder { -+ private static final Cleaner CLEANER = Cleaner.create(); -+ } -+ -+ /** -+ * DANGER WILL ROBINSON: Be sure you do not use a lambda that lives in the object being monitored, or leaky leaky! -+ * @param obj -+ * @param list -+ * @param cleaner -+ * @param -+ * @return -+ */ -+ public static Runnable registerListCleaner(Object obj, List list, Consumer cleaner) { -+ return registerCleaner(obj, () -> { -+ list.forEach(cleaner); -+ list.clear(); -+ }); -+ } -+ -+ /** -+ * DANGER WILL ROBINSON: Be sure you do not use a lambda that lives in the object being monitored, or leaky leaky! -+ * @param obj -+ * @param resource -+ * @param cleaner -+ * @param -+ * @return -+ */ -+ public static Runnable registerCleaner(Object obj, T resource, java.util.function.Consumer cleaner) { -+ return registerCleaner(obj, () -> cleaner.accept(resource)); ++ private MCUtil() { + } + + public static List getSpiralOutChunks(BlockPos blockposition, int radius) { @@ -4231,115 +4148,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + return list; + } + -+ public static int fastFloor(double x) { -+ int truncated = (int)x; -+ return x < (double)truncated ? truncated - 1 : truncated; -+ } -+ -+ public static int fastFloor(float x) { -+ int truncated = (int)x; -+ return x < (double)truncated ? truncated - 1 : truncated; -+ } -+ -+ public static float normalizeYaw(float f) { -+ float f1 = f % 360.0F; -+ -+ if (f1 >= 180.0F) { -+ f1 -= 360.0F; -+ } -+ -+ if (f1 < -180.0F) { -+ f1 += 360.0F; -+ } -+ -+ return f1; -+ } -+ -+ /** -+ * Quickly generate a stack trace for current location -+ * -+ * @return Stacktrace -+ */ -+ public static String stack() { -+ return ExceptionUtils.getFullStackTrace(new Throwable()); -+ } -+ -+ /** -+ * Quickly generate a stack trace for current location with message -+ * -+ * @param str -+ * @return Stacktrace -+ */ -+ public static String stack(String str) { -+ return ExceptionUtils.getFullStackTrace(new Throwable(str)); -+ } -+ -+ public static long getCoordinateKey(final BlockPos blockPos) { -+ return ((long)(blockPos.getZ() >> 4) << 32) | ((blockPos.getX() >> 4) & 0xFFFFFFFFL); -+ } -+ -+ public static long getCoordinateKey(final Entity entity) { -+ return ((long)(MCUtil.fastFloor(entity.getZ()) >> 4) << 32) | ((MCUtil.fastFloor(entity.getX()) >> 4) & 0xFFFFFFFFL); -+ } -+ -+ public static long getCoordinateKey(final ChunkPos pair) { -+ return ((long)pair.z << 32) | (pair.x & 0xFFFFFFFFL); -+ } -+ -+ public static long getCoordinateKey(final int x, final int z) { -+ return ((long)z << 32) | (x & 0xFFFFFFFFL); -+ } -+ -+ public static int getCoordinateX(final long key) { -+ return (int)key; -+ } -+ -+ public static int getCoordinateZ(final long key) { -+ return (int)(key >>> 32); -+ } -+ -+ public static int getChunkCoordinate(final double coordinate) { -+ return MCUtil.fastFloor(coordinate) >> 4; -+ } -+ -+ public static int getBlockCoordinate(final double coordinate) { -+ return MCUtil.fastFloor(coordinate); -+ } -+ -+ public static long getBlockKey(final int x, final int y, final int z) { -+ return ((long)x & 0x7FFFFFF) | (((long)z & 0x7FFFFFF) << 27) | ((long)y << 54); -+ } -+ -+ public static long getBlockKey(final BlockPos pos) { -+ return ((long)pos.getX() & 0x7FFFFFF) | (((long)pos.getZ() & 0x7FFFFFF) << 27) | ((long)pos.getY() << 54); -+ } -+ -+ public static long getBlockKey(final Entity entity) { -+ return getBlockKey(getBlockCoordinate(entity.getX()), getBlockCoordinate(entity.getY()), getBlockCoordinate(entity.getZ())); -+ } -+ -+ // assumes the sets have the same comparator, and if this comparator is null then assume T is Comparable -+ public static void mergeSortedSets(final java.util.function.Consumer consumer, final java.util.Comparator comparator, final java.util.SortedSet...sets) { -+ final ObjectRBTreeSet all = new ObjectRBTreeSet<>(comparator); -+ // note: this is done in log(n!) ~ nlogn time. It could be improved if it were to mimic what mergesort does. -+ for (java.util.SortedSet set : sets) { -+ if (set != null) { -+ all.addAll(set); -+ } -+ } -+ all.forEach(consumer); -+ } -+ -+ private MCUtil() {} -+ -+ public static final java.util.concurrent.Executor MAIN_EXECUTOR = (run) -> { -+ if (!isMainThread()) { -+ MinecraftServer.getServer().execute(run); -+ } else { -+ run.run(); -+ } -+ }; -+ + public static CompletableFuture ensureMain(CompletableFuture future) { + return future.thenApplyAsync(r -> r, MAIN_EXECUTOR); + } @@ -4347,6 +4155,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + public static void thenOnMain(CompletableFuture future, Consumer consumer) { + future.thenAcceptAsync(consumer, MAIN_EXECUTOR); + } ++ + public static void thenOnMain(CompletableFuture future, BiConsumer consumer) { + future.whenCompleteAsync(consumer, MAIN_EXECUTOR); + } @@ -4355,87 +4164,43 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + return MinecraftServer.getServer().isSameThread(); + } + -+ public static org.bukkit.scheduler.BukkitTask scheduleTask(int ticks, Runnable runnable) { -+ return scheduleTask(ticks, runnable, null); -+ } -+ -+ public static org.bukkit.scheduler.BukkitTask scheduleTask(int ticks, Runnable runnable, String taskName) { -+ return MinecraftServer.getServer().server.getScheduler().scheduleInternalTask(runnable, ticks, taskName); -+ } -+ -+ public static void processQueue() { -+ Runnable runnable; -+ Queue processQueue = getProcessQueue(); -+ while ((runnable = processQueue.poll()) != null) { -+ try { -+ runnable.run(); -+ } catch (Exception e) { -+ MinecraftServer.LOGGER.error("Error executing task", e); -+ } -+ } -+ } -+ public static T processQueueWhileWaiting(CompletableFuture future) { -+ try { -+ if (isMainThread()) { -+ while (!future.isDone()) { -+ try { -+ return future.get(1, TimeUnit.MILLISECONDS); -+ } catch (TimeoutException ignored) { -+ processQueue(); -+ } -+ } -+ } -+ return future.get(); -+ } catch (Exception e) { -+ throw new RuntimeException(e); -+ } -+ } -+ + public static void ensureMain(Runnable run) { + ensureMain(null, run); + } ++ + /** -+ * Ensures the target code is running on the main thread -+ * @param reason -+ * @param run ++ * Ensures the target code is running on the main thread. + */ + public static void ensureMain(String reason, Runnable run) { + if (!isMainThread()) { + if (reason != null) { + MinecraftServer.LOGGER.warn("Asynchronous " + reason + "!", new IllegalStateException()); + } -+ getProcessQueue().add(run); ++ MinecraftServer.getServer().processQueue.add(run); + return; + } + run.run(); + } + -+ private static Queue getProcessQueue() { -+ return MinecraftServer.getServer().processQueue; -+ } -+ + public static T ensureMain(Supplier run) { + return ensureMain(null, run); + } ++ + /** -+ * Ensures the target code is running on the main thread -+ * @param reason -+ * @param run -+ * @param -+ * @return ++ * Ensures the target code is running on the main thread. + */ + public static T ensureMain(String reason, Supplier run) { + if (!isMainThread()) { + if (reason != null) { + MinecraftServer.LOGGER.warn("Asynchronous " + reason + "! Blocking thread until it returns ", new IllegalStateException()); + } -+ Waitable wait = new Waitable() { ++ Waitable wait = new Waitable<>() { + @Override + protected T evaluate() { + return run.get(); + } + }; -+ getProcessQueue().add(wait); ++ MinecraftServer.getServer().processQueue.add(wait); + try { + return wait.get(); + } catch (InterruptedException | ExecutionException e) { @@ -4446,106 +4211,22 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + return run.get(); + } + -+ /** -+ * Calculates distance between 2 entities -+ * @param e1 -+ * @param e2 -+ * @return -+ */ -+ public static double distance(Entity e1, Entity e2) { -+ return Math.sqrt(distanceSq(e1, e2)); -+ } -+ -+ -+ /** -+ * Calculates distance between 2 block positions -+ * @param e1 -+ * @param e2 -+ * @return -+ */ -+ public static double distance(BlockPos e1, BlockPos e2) { -+ return Math.sqrt(distanceSq(e1, e2)); -+ } -+ -+ /** -+ * Gets the distance between 2 positions -+ * @param x1 -+ * @param y1 -+ * @param z1 -+ * @param x2 -+ * @param y2 -+ * @param z2 -+ * @return -+ */ + public static double distance(double x1, double y1, double z1, double x2, double y2, double z2) { + return Math.sqrt(distanceSq(x1, y1, z1, x2, y2, z2)); + } + -+ /** -+ * Get's the distance squared between 2 entities -+ * @param e1 -+ * @param e2 -+ * @return -+ */ -+ public static double distanceSq(Entity e1, Entity e2) { -+ return distanceSq(e1.getX(),e1.getY(),e1.getZ(), e2.getX(),e2.getY(),e2.getZ()); -+ } -+ -+ /** -+ * Gets the distance sqaured between 2 block positions -+ * @param pos1 -+ * @param pos2 -+ * @return -+ */ -+ public static double distanceSq(BlockPos pos1, BlockPos pos2) { -+ return distanceSq(pos1.getX(), pos1.getY(), pos1.getZ(), pos2.getX(), pos2.getY(), pos2.getZ()); -+ } -+ -+ /** -+ * Gets the distance squared between 2 positions -+ * @param x1 -+ * @param y1 -+ * @param z1 -+ * @param x2 -+ * @param y2 -+ * @param z2 -+ * @return -+ */ + public static double distanceSq(double x1, double y1, double z1, double x2, double y2, double z2) { + return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2); + } + -+ /** -+ * Converts a NMS World/BlockPosition to Bukkit Location -+ * @param world -+ * @param x -+ * @param y -+ * @param z -+ * @return -+ */ + public static Location toLocation(Level world, double x, double y, double z) { + return new Location(world.getWorld(), x, y, z); + } + -+ /** -+ * Converts a NMS World/BlockPosition to Bukkit Location -+ * @param world -+ * @param pos -+ * @return -+ */ + public static Location toLocation(Level world, BlockPos pos) { + return new Location(world.getWorld(), pos.getX(), pos.getY(), pos.getZ()); + } + -+ /** -+ * Converts an NMS entity's current location to a Bukkit Location -+ * @param entity -+ * @return -+ */ -+ public static Location toLocation(Entity entity) { -+ return new Location(entity.getCommandSenderWorld().getWorld(), entity.getX(), entity.getY(), entity.getZ()); -+ } -+ + public static BlockPos toBlockPosition(Location loc) { + return new BlockPos(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); + } @@ -4572,64 +4253,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + return (modX == 0 || modX == 15 || modZ == 0 || modZ == 15); + } + -+ /** -+ * Posts a task to be executed asynchronously -+ * @param run -+ */ + public static void scheduleAsyncTask(Runnable run) { + asyncExecutor.execute(run); + } -+ -+ @Nonnull -+ public static ServerLevel getNMSWorld(@Nonnull org.bukkit.World world) { -+ return ((CraftWorld) world).getHandle(); -+ } -+ -+ public static ServerLevel getNMSWorld(@Nonnull org.bukkit.entity.Entity entity) { -+ return getNMSWorld(entity.getWorld()); -+ } -+ -+ public static BlockFace toBukkitBlockFace(Direction enumDirection) { -+ switch (enumDirection) { -+ case DOWN: -+ return BlockFace.DOWN; -+ case UP: -+ return BlockFace.UP; -+ case NORTH: -+ return BlockFace.NORTH; -+ case SOUTH: -+ return BlockFace.SOUTH; -+ case WEST: -+ return BlockFace.WEST; -+ case EAST: -+ return BlockFace.EAST; -+ default: -+ return null; -+ } -+ } -+ -+ @NotNull -+ public static List copyListAndAdd(@NotNull final List original, -+ @NotNull final T newElement) { -+ return ImmutableList.builderWithExpectedSize(original.size() + 1) -+ .addAll(original) -+ .add(newElement) -+ .build(); -+ } -+ -+ @NotNull -+ public static List copyListAndRemoveIf(@NotNull final List original, -+ @NotNull final Predicate removalPredicate) { -+ final ImmutableList.Builder builder = ImmutableList.builderWithExpectedSize(original.size()); -+ for (int i = 0; i < original.size(); i++) { -+ final T value = original.get(i); -+ if (removalPredicate.test(value)) continue; -+ -+ builder.add(value); -+ } -+ -+ return builder.build(); -+ } +} diff --git a/src/main/java/io/papermc/paper/util/StackWalkerUtil.java b/src/main/java/io/papermc/paper/util/StackWalkerUtil.java new file mode 100644 @@ -4678,15 +4304,6 @@ diff --git a/src/main/java/net/minecraft/nbt/CompoundTag.java b/src/main/java/ne index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/nbt/CompoundTag.java +++ b/src/main/java/net/minecraft/nbt/CompoundTag.java -@@ -0,0 +0,0 @@ public class CompoundTag implements Tag { - return "TAG_Compound"; - } - }; -- private final Map tags; -+ public final Map tags; // Paper - - protected CompoundTag(Map entries) { - this.tags = entries; @@ -0,0 +0,0 @@ public class CompoundTag implements Tag { this.tags.put(key, NbtUtils.createUUID(value)); } @@ -4944,25 +4561,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 this.entityTickingChunkFuture = ChunkHolder.UNLOADED_LEVEL_CHUNK_FUTURE; } -@@ -0,0 +0,0 @@ public class ChunkHolder extends GenerationChunkHolder { - - List getPlayers(ChunkPos chunkPos, boolean onlyOnWatchDistanceEdge); - } -+ -+ // Paper start -+ public final boolean isEntityTickingReady() { -+ return this.isEntityTickingReady; -+ } -+ -+ public final boolean isTickingReady() { -+ return this.isTickingReady; -+ } -+ -+ public final boolean isFullChunkReady() { -+ return this.isFullChunkReady; -+ } -+ // Paper end - } diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/level/ChunkMap.java @@ -5135,34 +4733,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + public class ChunkDistanceManager extends DistanceManager { // Paper - public protected ChunkDistanceManager(final Executor workerExecutor, final Executor mainThreadExecutor) { -- super(workerExecutor, mainThreadExecutor); -+ super(workerExecutor, mainThreadExecutor, ChunkMap.this); // Paper - } - - @Override + super(workerExecutor, mainThreadExecutor); diff --git a/src/main/java/net/minecraft/server/level/DistanceManager.java b/src/main/java/net/minecraft/server/level/DistanceManager.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/level/DistanceManager.java +++ b/src/main/java/net/minecraft/server/level/DistanceManager.java -@@ -0,0 +0,0 @@ public abstract class DistanceManager { - final Executor mainThreadExecutor; - private long ticketTickCounter; - public int simulationDistance = 10; -+ private final ChunkMap chunkMap; // Paper - -- protected DistanceManager(Executor workerExecutor, Executor mainThreadExecutor) { -+ protected DistanceManager(Executor workerExecutor, Executor mainThreadExecutor, ChunkMap chunkMap) { - Objects.requireNonNull(mainThreadExecutor); - ProcessorHandle mailbox = ProcessorHandle.of("player ticket throttler", mainThreadExecutor::execute); - ChunkTaskPriorityQueueSorter chunktaskqueuesorter = new ChunkTaskPriorityQueueSorter(ImmutableList.of(mailbox), workerExecutor, 4); -@@ -0,0 +0,0 @@ public abstract class DistanceManager { - this.ticketThrottlerInput = chunktaskqueuesorter.getProcessor(mailbox, true); - this.ticketThrottlerReleaser = chunktaskqueuesorter.getReleaseProcessor(mailbox); - this.mainThreadExecutor = mainThreadExecutor; -+ this.chunkMap = chunkMap; // Paper - } - - protected void purgeStaleTickets() { @@ -0,0 +0,0 @@ public abstract class DistanceManager { } @@ -5451,10 +5026,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } } + // Paper start -+ public void scheduleOnMain(Runnable r0) { ++ public void scheduleOnMain(Runnable runnable) { + // postToMainThread does not work the same as older versions of mc + // This method is actually used to create a TickTask, which can then be posted onto main -+ this.tell(this.wrapRunnable(r0)); ++ this.tell(this.wrapRunnable(runnable)); + } + // Paper end @@ -5488,44 +5063,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 @Override public float getBukkitYaw() { -diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/net/minecraft/world/entity/Mob.java -+++ b/src/main/java/net/minecraft/world/entity/Mob.java -@@ -0,0 +0,0 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab - return this.target; - } - -+ public org.bukkit.craftbukkit.entity.CraftMob getBukkitMob() { return (org.bukkit.craftbukkit.entity.CraftMob) super.getBukkitEntity(); } // Paper -+ - @Nullable - protected final LivingEntity getTargetFromBrain() { - return (LivingEntity) this.getBrain().getMemory(MemoryModuleType.ATTACK_TARGET).orElse(null); // CraftBukkit - decompile error -diff --git a/src/main/java/net/minecraft/world/entity/PathfinderMob.java b/src/main/java/net/minecraft/world/entity/PathfinderMob.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/net/minecraft/world/entity/PathfinderMob.java -+++ b/src/main/java/net/minecraft/world/entity/PathfinderMob.java -@@ -0,0 +0,0 @@ public abstract class PathfinderMob extends Mob { - super(type, world); - } - -+ public org.bukkit.craftbukkit.entity.CraftCreature getBukkitCreature() { return (org.bukkit.craftbukkit.entity.CraftCreature) super.getBukkitEntity(); } // Paper -+ - public float getWalkTargetValue(BlockPos pos) { - return this.getWalkTargetValue(pos, this.level()); - } -diff --git a/src/main/java/net/minecraft/world/entity/monster/Monster.java b/src/main/java/net/minecraft/world/entity/monster/Monster.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/net/minecraft/world/entity/monster/Monster.java -+++ b/src/main/java/net/minecraft/world/entity/monster/Monster.java -@@ -0,0 +0,0 @@ import net.minecraft.world.level.ServerLevelAccessor; - import net.minecraft.world.level.dimension.DimensionType; - - public abstract class Monster extends PathfinderMob implements Enemy { -+ public org.bukkit.craftbukkit.entity.CraftMonster getBukkitMonster() { return (org.bukkit.craftbukkit.entity.CraftMonster) super.getBukkitEntity(); } // Paper - protected Monster(EntityType type, Level world) { - super(type, world); - this.xpReward = 5; diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/item/ItemStack.java @@ -5821,13 +5358,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } } -+ // Paper start -+ protected boolean shapeExceedsCube = true; -+ public final boolean shapeExceedsCube() { -+ return this.shapeExceedsCube; -+ } -+ // Paper end -+ ++ protected boolean shapeExceedsCube = true; // Paper - moved from actual method to here public void initCache() { this.fluidState = ((Block) this.owner).getFluidState(this.asState()); this.isRandomlyTicking = ((Block) this.owner).isRandomlyTicking(this.asState()); @@ -6189,265 +5720,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 public static net.minecraft.world.item.ItemStack asNMSCopy(ItemStack original) { if (original instanceof CraftItemStack) { CraftItemStack stack = (CraftItemStack) original; -diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java -+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java -@@ -0,0 +0,0 @@ import org.bukkit.scheduler.BukkitWorker; - */ - public class CraftScheduler implements BukkitScheduler { - -+ static Plugin MINECRAFT = new MinecraftInternalPlugin(); - /** - * The start ID for the counter. - */ -@@ -0,0 +0,0 @@ public class CraftScheduler implements BukkitScheduler { - this.runTaskTimer(plugin, (Object) task, delay, period); - } - -+ public BukkitTask scheduleInternalTask(Runnable run, int delay, String taskName) { -+ final CraftTask task = new CraftTask(run, nextId(), taskName); -+ return handle(task, delay); -+ } -+ - public BukkitTask runTaskTimer(Plugin plugin, Object runnable, long delay, long period) { - CraftScheduler.validate(plugin, runnable); - if (delay < 0L) { -@@ -0,0 +0,0 @@ public class CraftScheduler implements BukkitScheduler { - task.run(); - task.timings.stopTiming(); // Spigot - } catch (final Throwable throwable) { -- task.getOwner().getLogger().log( -+ // Paper start -+ String msg = String.format( -+ "Task #%s for %s generated an exception", -+ task.getTaskId(), -+ task.getOwner().getDescription().getFullName()); -+ if (task.getOwner() == MINECRAFT) { -+ net.minecraft.server.MinecraftServer.LOGGER.error(msg, throwable); -+ } else { -+ task.getOwner().getLogger().log( - Level.WARNING, -- String.format( -- "Task #%s for %s generated an exception", -- task.getTaskId(), -- task.getOwner().getDescription().getFullName()), -+ msg, - throwable); -+ } -+ // Paper end - } finally { - this.currentTask = null; - } -diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java -+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java -@@ -0,0 +0,0 @@ public class CraftTask implements BukkitTask, Runnable { // Spigot - CraftTask(final Object task) { - this(null, task, CraftTask.NO_REPEATING, CraftTask.NO_REPEATING); - } -+ // Paper start -+ public String taskName = null; -+ boolean internal = false; -+ CraftTask(final Object task, int id, String taskName) { -+ this.rTask = (Runnable) task; -+ this.cTask = null; -+ this.plugin = CraftScheduler.MINECRAFT; -+ this.taskName = taskName; -+ this.internal = true; -+ this.id = id; -+ this.period = CraftTask.NO_REPEATING; -+ this.taskName = taskName; -+ this.timings = null; // Will be changed in later patch -+ } -+ // Paper end - - CraftTask(final Plugin plugin, final Object task, final int id, final long period) { - this.plugin = plugin; -diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/MinecraftInternalPlugin.java b/src/main/java/org/bukkit/craftbukkit/scheduler/MinecraftInternalPlugin.java -new file mode 100644 -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 ---- /dev/null -+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/MinecraftInternalPlugin.java -@@ -0,0 +0,0 @@ -+package org.bukkit.craftbukkit.scheduler; -+ -+ -+import org.bukkit.Server; -+import org.bukkit.command.Command; -+import org.bukkit.command.CommandSender; -+import org.bukkit.configuration.file.FileConfiguration; -+import org.bukkit.generator.BiomeProvider; -+import org.bukkit.generator.ChunkGenerator; -+import org.bukkit.plugin.PluginBase; -+import org.bukkit.plugin.PluginDescriptionFile; -+import org.bukkit.plugin.PluginLoader; -+import org.bukkit.plugin.PluginLogger; -+import org.jetbrains.annotations.NotNull; -+import org.jetbrains.annotations.Nullable; -+ -+import java.io.File; -+import java.io.InputStream; -+import java.util.List; -+ -+public class MinecraftInternalPlugin extends PluginBase { -+ private boolean enabled = true; -+ -+ private final String pluginName; -+ private PluginDescriptionFile pdf; -+ -+ public MinecraftInternalPlugin() { -+ this.pluginName = "Minecraft"; -+ pdf = new PluginDescriptionFile(pluginName, "1.0", "nms"); -+ } -+ -+ public void setEnabled(boolean enabled) { -+ this.enabled = enabled; -+ } -+ -+ @Override -+ public File getDataFolder() { -+ throw new UnsupportedOperationException("Not supported."); -+ } -+ -+ @Override -+ public PluginDescriptionFile getDescription() { -+ return pdf; -+ } -+ -+ @Override -+ public FileConfiguration getConfig() { -+ throw new UnsupportedOperationException("Not supported."); -+ } -+ -+ @Override -+ public InputStream getResource(String filename) { -+ throw new UnsupportedOperationException("Not supported."); -+ } -+ -+ @Override -+ public void saveConfig() { -+ throw new UnsupportedOperationException("Not supported."); -+ } -+ -+ @Override -+ public void saveDefaultConfig() { -+ throw new UnsupportedOperationException("Not supported."); -+ } -+ -+ @Override -+ public void saveResource(String resourcePath, boolean replace) { -+ throw new UnsupportedOperationException("Not supported."); -+ } -+ -+ @Override -+ public void reloadConfig() { -+ throw new UnsupportedOperationException("Not supported."); -+ } -+ -+ @Override -+ public PluginLogger getLogger() { -+ throw new UnsupportedOperationException("Not supported."); -+ } -+ -+ @Override -+ public PluginLoader getPluginLoader() { -+ throw new UnsupportedOperationException("Not supported."); -+ } -+ -+ @Override -+ public Server getServer() { -+ throw new UnsupportedOperationException("Not supported."); -+ } -+ -+ @Override -+ public boolean isEnabled() { -+ return enabled; -+ } -+ -+ @Override -+ public void onDisable() { -+ throw new UnsupportedOperationException("Not supported."); -+ } -+ -+ @Override -+ public void onLoad() { -+ throw new UnsupportedOperationException("Not supported."); -+ } -+ -+ @Override -+ public void onEnable() { -+ throw new UnsupportedOperationException("Not supported."); -+ } -+ -+ @Override -+ public boolean isNaggable() { -+ throw new UnsupportedOperationException("Not supported."); -+ } -+ -+ @Override -+ public void setNaggable(boolean canNag) { -+ throw new UnsupportedOperationException("Not supported."); -+ } -+ -+ @Override -+ public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) { -+ throw new UnsupportedOperationException("Not supported."); -+ } -+ -+ @Override -+ public @Nullable BiomeProvider getDefaultBiomeProvider(@NotNull String worldName, @Nullable String id) { -+ throw new UnsupportedOperationException("Not supported."); -+ } -+ -+ @Override -+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { -+ throw new UnsupportedOperationException("Not supported."); -+ } -+ -+ @Override -+ public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { -+ throw new UnsupportedOperationException("Not supported."); -+ } -+} -diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -@@ -0,0 +0,0 @@ public final class CraftMagicNumbers implements UnsafeValues { - private static final Map ITEM_MATERIAL = new HashMap<>(); - private static final Map MATERIAL_ITEM = new HashMap<>(); - private static final Map MATERIAL_BLOCK = new HashMap<>(); -+ // Paper start -+ private static final Map> ENTITY_TYPE_ENTITY_TYPES = new HashMap<>(); -+ private static final Map, org.bukkit.entity.EntityType> ENTITY_TYPES_ENTITY_TYPE = new HashMap<>(); - - static { -+ for (org.bukkit.entity.EntityType type : org.bukkit.entity.EntityType.values()) { -+ if (type == org.bukkit.entity.EntityType.UNKNOWN) continue; -+ ENTITY_TYPE_ENTITY_TYPES.put(type, BuiltInRegistries.ENTITY_TYPE.get(CraftNamespacedKey.toMinecraft(type.getKey()))); -+ ENTITY_TYPES_ENTITY_TYPE.put(BuiltInRegistries.ENTITY_TYPE.get(CraftNamespacedKey.toMinecraft(type.getKey())), type); -+ } -+ // Paper end - for (Block block : BuiltInRegistries.BLOCK) { - BLOCK_MATERIAL.put(block, Material.getMaterial(BuiltInRegistries.BLOCK.getKey(block).getPath().toUpperCase(Locale.ROOT))); - } -@@ -0,0 +0,0 @@ public final class CraftMagicNumbers implements UnsafeValues { - public static ResourceLocation key(Material mat) { - return CraftNamespacedKey.toMinecraft(mat.getKey()); - } -+ // Paper start -+ public static net.minecraft.world.entity.EntityType getEntityTypes(org.bukkit.entity.EntityType type) { -+ return ENTITY_TYPE_ENTITY_TYPES.get(type); -+ } -+ public static org.bukkit.entity.EntityType getEntityType(net.minecraft.world.entity.EntityType entityTypes) { -+ return ENTITY_TYPES_ENTITY_TYPE.get(entityTypes); -+ } -+ // Paper end - // ======================================================================== - - public static byte toLegacyData(BlockState data) { diff --git a/src/main/java/org/bukkit/craftbukkit/util/DelegatedGeneratorAccess.java b/src/main/java/org/bukkit/craftbukkit/util/DelegatedGeneratorAccess.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/DelegatedGeneratorAccess.java @@ -6513,43 +5785,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 @Override public WorldBorder getWorldBorder() { throw new UnsupportedOperationException("Not supported yet."); -diff --git a/src/main/java/org/bukkit/craftbukkit/util/UnsafeList.java b/src/main/java/org/bukkit/craftbukkit/util/UnsafeList.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/org/bukkit/craftbukkit/util/UnsafeList.java -+++ b/src/main/java/org/bukkit/craftbukkit/util/UnsafeList.java -@@ -0,0 +0,0 @@ public class UnsafeList extends AbstractList implements List, RandomAcc - return this.indexOf(o) >= 0; - } - -+ // Paper start -+ protected transient int maxSize; -+ public void setSize(int size) { -+ if (this.maxSize < this.size) { -+ this.maxSize = this.size; -+ } -+ this.size = size; -+ } -+ -+ public void completeReset() { -+ if (this.data != null) { -+ Arrays.fill(this.data, 0, Math.max(this.size, this.maxSize), null); -+ } -+ this.size = 0; -+ this.maxSize = 0; -+ if (this.iterPool != null) { -+ for (Iterator temp : this.iterPool) { -+ if (temp == null) { -+ continue; -+ } -+ ((Itr)temp).valid = false; -+ } -+ } -+ } -+ // Paper end -+ - @Override - public void clear() { - // Create new array to reset memory usage to initial capacity diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/spigotmc/ActivationRange.java @@ -6564,20 +5799,3 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 MONSTER, ANIMAL, RAIDER, -diff --git a/src/main/java/org/spigotmc/SpigotConfig.java b/src/main/java/org/spigotmc/SpigotConfig.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/org/spigotmc/SpigotConfig.java -+++ b/src/main/java/org/spigotmc/SpigotConfig.java -@@ -0,0 +0,0 @@ public class SpigotConfig - } - } - } -- -+ // Paper start -+ SpigotConfig.save(); -+ } -+ public static void save() { -+ // Paper end - try - { - SpigotConfig.config.save( SpigotConfig.CONFIG_FILE ); diff --git a/patches/server/Mob-Pathfinding-API.patch b/patches/server/Mob-Pathfinding-API.patch index a63143736f..1065619495 100644 --- a/patches/server/Mob-Pathfinding-API.patch +++ b/patches/server/Mob-Pathfinding-API.patch @@ -40,7 +40,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + @Override + public Mob getEntity() { -+ return entity.getBukkitMob(); ++ return (Mob) entity.getBukkitEntity(); + } + + public void setHandle(net.minecraft.world.entity.Mob entity) { diff --git a/patches/server/Moonrise-optimisation-patches.patch b/patches/server/Moonrise-optimisation-patches.patch index c23a7632c0..281511d097 100644 --- a/patches/server/Moonrise-optimisation-patches.patch +++ b/patches/server/Moonrise-optimisation-patches.patch @@ -23167,25 +23167,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } @FunctionalInterface -@@ -0,0 +0,0 @@ public class ChunkHolder extends GenerationChunkHolder { - - // Paper start - public final boolean isEntityTickingReady() { -- return this.isEntityTickingReady; -+ throw new UnsupportedOperationException(); // Paper - rewrite chunk system - } - - public final boolean isTickingReady() { -- return this.isTickingReady; -+ throw new UnsupportedOperationException(); // Paper - rewrite chunk system - } - - public final boolean isFullChunkReady() { -- return this.isFullChunkReady; -+ throw new UnsupportedOperationException(); // Paper - rewrite chunk system - } - // Paper end - } diff --git a/src/main/java/net/minecraft/server/level/ChunkLevel.java b/src/main/java/net/minecraft/server/level/ChunkLevel.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/level/ChunkLevel.java @@ -24206,7 +24187,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + public class ChunkDistanceManager extends DistanceManager implements ca.spottedleaf.moonrise.patches.chunk_system.level.chunk.ChunkSystemDistanceManager { // Paper - public // Paper - rewrite chunk system protected ChunkDistanceManager(final Executor workerExecutor, final Executor mainThreadExecutor) { - super(workerExecutor, mainThreadExecutor, ChunkMap.this); // Paper + super(workerExecutor, mainThreadExecutor); } + // Paper start - rewrite chunk system @@ -24349,39 +24330,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 private long ticketTickCounter; - public int simulationDistance = 10; + // Paper - rewrite chunk system - private final ChunkMap chunkMap; // Paper -+ // Paper start - rewrite chunk system -+ public ca.spottedleaf.moonrise.patches.chunk_system.scheduling.ChunkHolderManager getChunkHolderManager() { -+ return ((ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemServerLevel)this.moonrise$getChunkMap().level).moonrise$getChunkTaskScheduler().chunkHolderManager; -+ } -+ // Paper end - rewrite chunk system -+ // Paper start - chunk tick iteration optimisation -+ private final ca.spottedleaf.moonrise.common.misc.PositionCountingAreaMap spawnChunkTracker = new ca.spottedleaf.moonrise.common.misc.PositionCountingAreaMap<>(); -+ -+ @Override -+ public final void moonrise$addPlayer(final ServerPlayer player, final SectionPos pos) { -+ this.spawnChunkTracker.add(player, pos.x(), pos.z(), ca.spottedleaf.moonrise.patches.chunk_tick_iteration.ChunkTickConstants.PLAYER_SPAWN_TRACK_RANGE); -+ } -+ -+ @Override -+ public final void moonrise$removePlayer(final ServerPlayer player, final SectionPos pos) { -+ this.spawnChunkTracker.remove(player); -+ } -+ -+ @Override -+ public final void moonrise$updatePlayer(final ServerPlayer player, -+ final SectionPos oldPos, final SectionPos newPos, -+ final boolean oldIgnore, final boolean newIgnore) { -+ if (newIgnore) { -+ this.spawnChunkTracker.remove(player); -+ } else { -+ this.spawnChunkTracker.addOrUpdate(player, newPos.x(), newPos.z(), ca.spottedleaf.moonrise.patches.chunk_tick_iteration.ChunkTickConstants.PLAYER_SPAWN_TRACK_RANGE); -+ } -+ } -+ // Paper end - chunk tick iteration optimisation -+ - protected DistanceManager(Executor workerExecutor, Executor mainThreadExecutor, ChunkMap chunkMap) { + protected DistanceManager(Executor workerExecutor, Executor mainThreadExecutor) { Objects.requireNonNull(mainThreadExecutor); ProcessorHandle mailbox = ProcessorHandle.of("player ticket throttler", mainThreadExecutor::execute); ChunkTaskPriorityQueueSorter chunktaskqueuesorter = new ChunkTaskPriorityQueueSorter(ImmutableList.of(mailbox), workerExecutor, 4); @@ -24391,10 +24341,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 - this.ticketThrottlerReleaser = chunktaskqueuesorter.getReleaseProcessor(mailbox); - this.mainThreadExecutor = mainThreadExecutor; + // Paper - rewrite chunk system - this.chunkMap = chunkMap; // Paper } - protected void purgeStaleTickets() { +- protected void purgeStaleTickets() { - ++this.ticketTickCounter; - ObjectIterator>>> objectiterator = this.tickets.long2ObjectEntrySet().fastIterator(); - @@ -24405,22 +24354,49 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 - - while (iterator.hasNext()) { - Ticket ticket = (Ticket) iterator.next(); -- ++ // Paper start - rewrite chunk system ++ public ca.spottedleaf.moonrise.patches.chunk_system.scheduling.ChunkHolderManager getChunkHolderManager() { ++ return ((ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemServerLevel)this.moonrise$getChunkMap().level).moonrise$getChunkTaskScheduler().chunkHolderManager; ++ } ++ // Paper end - rewrite chunk system ++ // Paper start - chunk tick iteration optimisation ++ private final ca.spottedleaf.moonrise.common.misc.PositionCountingAreaMap spawnChunkTracker = new ca.spottedleaf.moonrise.common.misc.PositionCountingAreaMap<>(); + - if (ticket.timedOut(this.ticketTickCounter)) { - iterator.remove(); - flag = true; - this.tickingTicketsTracker.removeTicket(entry.getLongKey(), ticket); - } - } -- ++ @Override ++ public final void moonrise$addPlayer(final ServerPlayer player, final SectionPos pos) { ++ this.spawnChunkTracker.add(player, pos.x(), pos.z(), ca.spottedleaf.moonrise.patches.chunk_tick_iteration.ChunkTickConstants.PLAYER_SPAWN_TRACK_RANGE); ++ } + - if (flag) { - this.ticketTracker.update(entry.getLongKey(), DistanceManager.getTicketLevelAt((SortedArraySet) entry.getValue()), false); - } -- ++ @Override ++ public final void moonrise$removePlayer(final ServerPlayer player, final SectionPos pos) { ++ this.spawnChunkTracker.remove(player); ++ } + - if (((SortedArraySet) entry.getValue()).isEmpty()) { - objectiterator.remove(); - } -- } ++ @Override ++ public final void moonrise$updatePlayer(final ServerPlayer player, ++ final SectionPos oldPos, final SectionPos newPos, ++ final boolean oldIgnore, final boolean newIgnore) { ++ if (newIgnore) { ++ this.spawnChunkTracker.remove(player); ++ } else { ++ this.spawnChunkTracker.addOrUpdate(player, newPos.x(), newPos.z(), ca.spottedleaf.moonrise.patches.chunk_tick_iteration.ChunkTickConstants.PLAYER_SPAWN_TRACK_RANGE); + } ++ } ++ // Paper end - chunk tick iteration optimisation ++ ++ protected void purgeStaleTickets() { + this.getChunkHolderManager().tick(); // Paper - rewrite chunk system } diff --git a/patches/server/Paper-Plugins.patch b/patches/server/Paper-Plugins.patch index 88c2036916..aaa187576d 100644 --- a/patches/server/Paper-Plugins.patch +++ b/patches/server/Paper-Plugins.patch @@ -7328,23 +7328,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 this.loadPlugins(); this.enablePlugins(PluginLoadOrder.STARTUP); this.enablePlugins(PluginLoadOrder.POSTWORLD); -diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/MinecraftInternalPlugin.java b/src/main/java/org/bukkit/craftbukkit/scheduler/MinecraftInternalPlugin.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/org/bukkit/craftbukkit/scheduler/MinecraftInternalPlugin.java -+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/MinecraftInternalPlugin.java -@@ -0,0 +0,0 @@ public class MinecraftInternalPlugin extends PluginBase { - public PluginDescriptionFile getDescription() { - return pdf; - } -+ // Paper start -+ @Override -+ public io.papermc.paper.plugin.configuration.PluginMeta getPluginMeta() { -+ return pdf; -+ } -+ // Paper end - - @Override - public FileConfiguration getConfig() { diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java diff --git a/patches/server/ProfileWhitelistVerifyEvent.patch b/patches/server/ProfileWhitelistVerifyEvent.patch index f838bdb8e1..b47d90dc49 100644 --- a/patches/server/ProfileWhitelistVerifyEvent.patch +++ b/patches/server/ProfileWhitelistVerifyEvent.patch @@ -33,7 +33,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + boolean isOp = this.ops.contains(gameprofile); + boolean isWhitelisted = !this.doWhiteList || isOp || this.whitelist.contains(gameprofile); + final com.destroystokyo.paper.event.profile.ProfileWhitelistVerifyEvent event; -+ event = new com.destroystokyo.paper.event.profile.ProfileWhitelistVerifyEvent(io.papermc.paper.util.MCUtil.toBukkit(gameprofile), this.doWhiteList, isWhitelisted, isOp, org.spigotmc.SpigotConfig.whitelistMessage); ++ ++ event = new com.destroystokyo.paper.event.profile.ProfileWhitelistVerifyEvent(com.destroystokyo.paper.profile.CraftPlayerProfile.asBukkitMirror(gameprofile), this.doWhiteList, isWhitelisted, isOp, org.spigotmc.SpigotConfig.whitelistMessage); + event.callEvent(); + if (!event.isWhitelisted()) { + if (loginEvent != null) { diff --git a/patches/server/Timings-v2.patch b/patches/server/Timings-v2.patch index c6f041727a..bbc594b29b 100644 --- a/patches/server/Timings-v2.patch +++ b/patches/server/Timings-v2.patch @@ -1833,16 +1833,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 import com.google.common.base.Preconditions; import com.google.common.util.concurrent.ThreadFactoryBuilder; import java.util.ArrayList; -@@ -0,0 +0,0 @@ public class CraftScheduler implements BukkitScheduler { - } - - public BukkitTask scheduleInternalTask(Runnable run, int delay, String taskName) { -- final CraftTask task = new CraftTask(run, nextId(), taskName); -+ final CraftTask task = new CraftTask(run, nextId(), "Internal - " + (taskName != null ? taskName : "Unknown")); -+ task.internal = true; - return handle(task, delay); - } - @@ -0,0 +0,0 @@ public class CraftScheduler implements BukkitScheduler { } return false; @@ -1869,8 +1859,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 task.run(); - task.timings.stopTiming(); // Spigot } catch (final Throwable throwable) { - // Paper start - String msg = String.format( + task.getOwner().getLogger().log( + Level.WARNING, @@ -0,0 +0,0 @@ public class CraftScheduler implements BukkitScheduler { this.runners.remove(task.getTaskId()); } @@ -1936,15 +1926,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 CraftTask() { this(null, null, CraftTask.NO_REPEATING, CraftTask.NO_REPEATING); } -@@ -0,0 +0,0 @@ public class CraftTask implements BukkitTask, Runnable { // Spigot - this.id = id; - this.period = CraftTask.NO_REPEATING; - this.taskName = taskName; -- this.timings = null; // Will be changed in later patch -+ this.timings = MinecraftTimings.getInternalTaskName(taskName); - } - // Paper end - @@ -0,0 +0,0 @@ public class CraftTask implements BukkitTask, Runnable { // Spigot } this.id = id; @@ -2008,8 +1989,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java @@ -0,0 +0,0 @@ public final class CraftMagicNumbers implements UnsafeValues { + return CraftNamespacedKey.toMinecraft(mat.getKey()); } - // Paper end // ======================================================================== + // Paper start + @Override