diff --git a/paper-server/patches/sources/net/minecraft/server/MinecraftServer.java.patch b/paper-server/patches/sources/net/minecraft/server/MinecraftServer.java.patch index d5225db86a7..a21f9c7f213 100644 --- a/paper-server/patches/sources/net/minecraft/server/MinecraftServer.java.patch +++ b/paper-server/patches/sources/net/minecraft/server/MinecraftServer.java.patch @@ -26,7 +26,7 @@ import net.minecraft.util.debugchart.RemoteDebugSampleType; import net.minecraft.util.debugchart.SampleLogger; import net.minecraft.util.debugchart.TpsDebugDimensions; -@@ -156,37 +146,73 @@ +@@ -156,37 +146,72 @@ import net.minecraft.world.level.biome.BiomeManager; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.FuelValues; @@ -94,7 +94,6 @@ +import org.bukkit.event.server.ServerLoadEvent; +// CraftBukkit end -+import org.bukkit.craftbukkit.SpigotTimings; // Spigot + public abstract class MinecraftServer extends ReentrantBlockableEventLoop implements ServerInfo, ChunkIOErrorReporter, CommandSource { @@ -108,7 +107,7 @@ private static final int OVERLOADED_TICKS_THRESHOLD = 20; private static final long OVERLOADED_WARNING_INTERVAL_NANOS = 10L * TimeUtil.NANOSECONDS_PER_SECOND; private static final int OVERLOADED_TICKS_WARNING_INTERVAL = 100; -@@ -232,8 +258,7 @@ +@@ -232,8 +257,7 @@ private boolean preventProxyConnections; private boolean pvp; private boolean allowFlight; @@ -118,7 +117,7 @@ private int playerIdleTimeout; private final long[] tickTimesNanos; private long aggregatedTickTimesNanos; -@@ -277,6 +302,26 @@ +@@ -277,6 +301,26 @@ private final SuppressedExceptionCollector suppressedExceptions; private final DiscontinuousFrame tickFrame; @@ -145,7 +144,7 @@ public static S spin(Function serverFactory) { AtomicReference atomicreference = new AtomicReference(); Thread thread = new Thread(() -> { -@@ -290,14 +335,14 @@ +@@ -290,14 +334,14 @@ thread.setPriority(8); } @@ -162,7 +161,7 @@ super("Server"); this.metricsRecorder = InactiveMetricsRecorder.INSTANCE; this.onMetricsRecordingStopped = (methodprofilerresults) -> { -@@ -319,36 +364,68 @@ +@@ -319,36 +363,68 @@ this.scoreboard = new ServerScoreboard(this); this.customBossEvents = new CustomBossEvents(); this.suppressedExceptions = new SuppressedExceptionCollector(); @@ -246,7 +245,7 @@ } private void readScoreboard(DimensionDataStorage persistentStateManager) { -@@ -357,7 +434,7 @@ +@@ -357,7 +433,7 @@ protected abstract boolean initServer() throws IOException; @@ -255,7 +254,7 @@ if (!JvmProfiler.INSTANCE.isRunning()) { ; } -@@ -365,12 +442,8 @@ +@@ -365,12 +441,8 @@ boolean flag = false; ProfiledDuration profiledduration = JvmProfiler.INSTANCE.onWorldLoadedStarted(); @@ -269,7 +268,7 @@ if (profiledduration != null) { profiledduration.finish(true); } -@@ -387,23 +460,218 @@ +@@ -387,23 +459,218 @@ protected void forceDifficulty() {} @@ -293,12 +292,12 @@ + Registry dimensions = iregistrycustom_dimension.lookupOrThrow(Registries.LEVEL_STEM); + for (LevelStem worldDimension : dimensions) { + ResourceKey dimensionKey = dimensions.getResourceKey(worldDimension).get(); ++ ++ ServerLevel world; ++ int dimension = 0; - this.readScoreboard(worldpersistentdata); - this.commandStorage = new CommandStorage(worldpersistentdata); -+ ServerLevel world; -+ int dimension = 0; -+ + if (dimensionKey == LevelStem.NETHER) { + if (this.server.getAllowNether()) { + dimension = -1; @@ -502,7 +501,7 @@ if (!iworlddataserver.isInitialized()) { try { -@@ -427,30 +695,8 @@ +@@ -427,30 +694,8 @@ iworlddataserver.setInitialized(true); } @@ -534,7 +533,7 @@ private static void setInitialSpawn(ServerLevel world, ServerLevelData worldProperties, boolean bonusChest, boolean debugWorld) { if (debugWorld) { -@@ -458,6 +704,21 @@ +@@ -458,6 +703,21 @@ } else { ServerChunkCache chunkproviderserver = world.getChunkSource(); ChunkPos chunkcoordintpair = new ChunkPos(chunkproviderserver.randomState().sampler().findSpawnPosition()); @@ -556,7 +555,7 @@ int i = chunkproviderserver.getGenerator().getSpawnHeight(world); if (i < world.getMinY()) { -@@ -516,31 +777,36 @@ +@@ -516,31 +776,36 @@ iworlddataserver.setGameType(GameType.SPECTATOR); } @@ -604,7 +603,7 @@ ForcedChunksSavedData forcedchunk = (ForcedChunksSavedData) worldserver1.getDataStorage().get(ForcedChunksSavedData.factory(), "chunks"); if (forcedchunk != null) { -@@ -555,10 +821,17 @@ +@@ -555,10 +820,17 @@ } } @@ -626,7 +625,7 @@ } public GameType getDefaultGameType() { -@@ -588,12 +861,16 @@ +@@ -588,12 +860,16 @@ worldserver.save((ProgressListener) null, flush, worldserver.noSave && !force); } @@ -645,7 +644,7 @@ if (flush) { Iterator iterator1 = this.getAllLevels().iterator(); -@@ -628,18 +905,41 @@ +@@ -628,18 +904,41 @@ this.stopServer(); } @@ -687,7 +686,7 @@ } MinecraftServer.LOGGER.info("Saving worlds"); -@@ -693,6 +993,15 @@ +@@ -693,6 +992,15 @@ } catch (IOException ioexception1) { MinecraftServer.LOGGER.error("Failed to unlock level {}", this.storageSource.getLevelId(), ioexception1); } @@ -703,7 +702,7 @@ } -@@ -715,10 +1024,68 @@ +@@ -715,10 +1023,68 @@ this.serverThread.join(); } catch (InterruptedException interruptedexception) { MinecraftServer.LOGGER.error("Error while shutting down", interruptedexception); @@ -744,9 +743,9 @@ + for (int i = 0; i < size; i++) { + this.samples[i] = dec(TPS); + this.times[i] = SEC_IN_NANO; -+ } -+ } -+ + } + } + + private static java.math.BigDecimal dec(long t) { + return new java.math.BigDecimal(t); + } @@ -759,9 +758,9 @@ + total = total.add(x.multiply(dec(t))); + if (++index == size) { + index = 0; - } - } - ++ } ++ } ++ + public double getAverage() { + return total.divide(dec(time), 30, java.math.RoundingMode.HALF_UP).doubleValue(); + } @@ -772,7 +771,7 @@ protected void runServer() { try { -@@ -727,9 +1094,15 @@ +@@ -727,9 +1093,15 @@ } this.nextTickTimeNanos = Util.getNanos(); @@ -789,7 +788,7 @@ while (this.running) { long i; -@@ -744,12 +1117,31 @@ +@@ -744,11 +1116,30 @@ if (j > MinecraftServer.OVERLOADED_THRESHOLD_NANOS + 20L * i && this.nextTickTimeNanos - this.lastOverloadWarningNanos >= MinecraftServer.OVERLOADED_WARNING_INTERVAL_NANOS + 100L * i) { long k = j / i; @@ -798,7 +797,7 @@ this.nextTickTimeNanos += k * i; this.lastOverloadWarningNanos = this.nextTickTimeNanos; } - } ++ } + // Spigot start + // Paper start - further improve server tick loop + currentTime = Util.getNanos(); @@ -808,20 +807,19 @@ + tps1.add(currentTps, diff); + tps5.add(currentTps, diff); + tps15.add(currentTps, diff); - ++ + // Backwards compat with bad plugins + this.recentTps[0] = tps1.getAverage(); + this.recentTps[1] = tps5.getAverage(); + this.recentTps[2] = tps15.getAverage(); + tickSection = currentTime; -+ } + } + // Paper end - further improve server tick loop + // Spigot end -+ + boolean flag = i == 0L; - if (this.debugCommandProfilerDelayStart) { -@@ -757,6 +1149,8 @@ +@@ -757,6 +1148,8 @@ this.debugCommandProfiler = new MinecraftServer.TimeProfiler(Util.getNanos(), this.tickCount); } @@ -830,7 +828,7 @@ this.nextTickTimeNanos += i; try { -@@ -830,6 +1224,13 @@ +@@ -830,6 +1223,13 @@ this.services.profileCache().clearExecutor(); } @@ -844,7 +842,7 @@ this.onServerExit(); } -@@ -889,9 +1290,16 @@ +@@ -889,9 +1289,16 @@ } private boolean haveTime() { @@ -862,7 +860,7 @@ public static boolean throwIfFatalException() { RuntimeException runtimeexception = (RuntimeException) MinecraftServer.fatalException.get(); -@@ -903,7 +1311,7 @@ +@@ -903,7 +1310,7 @@ } public static void setFatalException(RuntimeException exception) { @@ -871,7 +869,7 @@ } @Override -@@ -977,7 +1385,7 @@ +@@ -977,7 +1384,7 @@ } } @@ -880,7 +878,7 @@ Profiler.get().incrementCounter("runTask"); super.doRunTask(ticktask); } -@@ -1025,6 +1433,7 @@ +@@ -1025,6 +1432,7 @@ } public void tickServer(BooleanSupplier shouldKeepTicking) { @@ -888,7 +886,7 @@ long i = Util.getNanos(); int j = this.pauseWhileEmptySeconds() * 20; -@@ -1041,11 +1450,13 @@ +@@ -1041,6 +1449,7 @@ this.autoSave(); } @@ -896,13 +894,7 @@ this.tickConnection(); return; } - } - -+ SpigotTimings.serverTickTimer.startTiming(); // Spigot - ++this.tickCount; - this.tickRateManager.tick(); - this.tickChildren(shouldKeepTicking); -@@ -1055,7 +1466,7 @@ +@@ -1055,12 +1464,13 @@ } --this.ticksUntilAutosave; @@ -911,30 +903,22 @@ this.autoSave(); } -@@ -1071,10 +1482,13 @@ - this.smoothedTickTimeMillis = this.smoothedTickTimeMillis * 0.8F + (float) k / (float) TimeUtil.NANOSECONDS_PER_MILLISECOND * 0.19999999F; - this.logTickMethodTime(i); - gameprofilerfiller.pop(); -+ SpigotTimings.serverTickTimer.stopTiming(); // Spigot -+ org.spigotmc.CustomTimingsHandler.tick(); // Spigot + ProfilerFiller gameprofilerfiller = Profiler.get(); + ++ this.runAllTasks(); // Paper - move runAllTasks() into full server tick (previously for timings) + gameprofilerfiller.push("tallying"); + long k = Util.getNanos() - i; + int l = this.tickCount % 100; +@@ -1074,7 +1484,7 @@ } private void autoSave() { - this.ticksUntilAutosave = this.computeNextAutosaveInterval(); + this.ticksUntilAutosave = this.autosavePeriod; // CraftBukkit -+ SpigotTimings.worldSaveTimer.startTiming(); // Spigot MinecraftServer.LOGGER.debug("Autosave started"); ProfilerFiller gameprofilerfiller = Profiler.get(); -@@ -1082,6 +1496,7 @@ - this.saveEverything(true, false, false); - gameprofilerfiller.pop(); - MinecraftServer.LOGGER.debug("Autosave finished"); -+ SpigotTimings.worldSaveTimer.stopTiming(); // Spigot - } - - private void logTickMethodTime(long tickStartTime) { -@@ -1123,7 +1538,7 @@ +@@ -1123,7 +1533,7 @@ private ServerStatus buildServerStatus() { ServerStatus.Players serverping_serverpingplayersample = this.buildPlayerStatus(); @@ -943,30 +927,23 @@ } private ServerStatus.Players buildPlayerStatus() { -@@ -1154,11 +1569,35 @@ +@@ -1154,11 +1564,27 @@ this.getPlayerList().getPlayers().forEach((entityplayer) -> { entityplayer.connection.suspendFlushing(); }); -+ SpigotTimings.schedulerTimer.startTiming(); // Spigot + this.server.getScheduler().mainThreadHeartbeat(); // CraftBukkit -+ SpigotTimings.schedulerTimer.stopTiming(); // Spigot + io.papermc.paper.adventure.providers.ClickCallbackProviderImpl.CALLBACK_MANAGER.handleQueue(this.tickCount); // Paper gameprofilerfiller.push("commandFunctions"); -+ SpigotTimings.commandFunctionsTimer.startTiming(); // Spigot this.getFunctions().tick(); -+ SpigotTimings.commandFunctionsTimer.stopTiming(); // Spigot gameprofilerfiller.popPush("levels"); Iterator iterator = this.getAllLevels().iterator(); - ++ + // CraftBukkit start + // Run tasks that are waiting on processing -+ SpigotTimings.processQueueTimer.startTiming(); // Spigot + while (!this.processQueue.isEmpty()) { + this.processQueue.remove().run(); + } -+ SpigotTimings.processQueueTimer.stopTiming(); // Spigot -+ -+ SpigotTimings.timeUpdateTimer.startTiming(); // Spigot + + // Send time updates to everyone, it will get the right time from the world the player is in. + if (this.tickCount % 20 == 0) { + for (int i = 0; i < this.getPlayerList().players.size(); ++i) { @@ -974,12 +951,11 @@ + entityplayer.connection.send(new ClientboundSetTimePacket(entityplayer.level().getGameTime(), entityplayer.getPlayerTime(), entityplayer.serverLevel().getGameRules().getBoolean(GameRules.RULE_DAYLIGHT))); // Add support for per player time + } + } -+ SpigotTimings.timeUpdateTimer.stopTiming(); // Spigot + while (iterator.hasNext()) { ServerLevel worldserver = (ServerLevel) iterator.next(); -@@ -1167,16 +1606,20 @@ +@@ -1167,11 +1593,13 @@ return s + " " + String.valueOf(worldserver.dimension().location()); }); @@ -993,42 +969,12 @@ gameprofilerfiller.push("tick"); - try { -+ worldserver.timings.doTick.startTiming(); // Spigot - worldserver.tick(shouldKeepTicking); -+ worldserver.timings.doTick.stopTiming(); // Spigot - } catch (Throwable throwable) { - CrashReport crashreport = CrashReport.forThrowable(throwable, "Exception ticking world"); - -@@ -1189,18 +1632,24 @@ - } - - gameprofilerfiller.popPush("connection"); -+ SpigotTimings.connectionTimer.startTiming(); // Spigot - this.tickConnection(); -+ SpigotTimings.connectionTimer.stopTiming(); // Spigot - gameprofilerfiller.popPush("players"); -+ SpigotTimings.playerListTimer.startTiming(); // Spigot - this.playerList.tick(); -+ SpigotTimings.playerListTimer.stopTiming(); // Spigot - if (SharedConstants.IS_RUNNING_IN_IDE && this.tickRateManager.runsNormally()) { - GameTestTicker.SINGLETON.tick(); - } - - gameprofilerfiller.popPush("server gui refresh"); - -+ SpigotTimings.tickablesTimer.startTiming(); // Spigot - for (int i = 0; i < this.tickables.size(); ++i) { - ((Runnable) this.tickables.get(i)).run(); - } -+ SpigotTimings.tickablesTimer.stopTiming(); // Spigot - - gameprofilerfiller.popPush("send chunks"); - iterator = this.playerList.getPlayers().iterator(); -@@ -1267,6 +1716,22 @@ +@@ -1265,7 +1693,23 @@ + @Nullable + public ServerLevel getLevel(ResourceKey key) { return (ServerLevel) this.levels.get(key); - } - ++ } ++ + // CraftBukkit start + public void addLevel(ServerLevel level) { + Map, ServerLevel> oldLevels = this.levels; @@ -1042,13 +988,12 @@ + Map, ServerLevel> newLevels = Maps.newLinkedHashMap(oldLevels); + newLevels.remove(level.dimension()); + this.levels = Collections.unmodifiableMap(newLevels); -+ } + } + // CraftBukkit end -+ + public Set> levelKeys() { return this.levels.keySet(); - } -@@ -1296,7 +1761,7 @@ +@@ -1296,7 +1740,7 @@ @DontObfuscate public String getServerModName() { @@ -1057,7 +1002,7 @@ } public SystemReport fillSystemReport(SystemReport details) { -@@ -1347,7 +1812,7 @@ +@@ -1347,7 +1791,7 @@ @Override public void sendSystemMessage(Component message) { @@ -1066,7 +1011,7 @@ } public KeyPair getKeyPair() { -@@ -1481,10 +1946,20 @@ +@@ -1481,10 +1925,20 @@ @Override public String getMotd() { @@ -1088,7 +1033,7 @@ this.motd = motd; } -@@ -1507,7 +1982,7 @@ +@@ -1507,7 +1961,7 @@ } public ServerConnectionListener getConnection() { @@ -1097,7 +1042,7 @@ } public boolean isReady() { -@@ -1634,11 +2109,11 @@ +@@ -1634,11 +2088,11 @@ public CompletableFuture reloadResources(Collection dataPacks) { CompletableFuture completablefuture = CompletableFuture.supplyAsync(() -> { @@ -1111,7 +1056,7 @@ }, this).thenCompose((immutablelist) -> { MultiPackResourceManager resourcemanager = new MultiPackResourceManager(PackType.SERVER_DATA, immutablelist); List> list = TagLoader.loadTagsForExistingRegistries(resourcemanager, this.registries.compositeAccess()); -@@ -1654,6 +2129,7 @@ +@@ -1654,6 +2108,7 @@ }).thenAcceptAsync((minecraftserver_reloadableresources) -> { this.resources.close(); this.resources = minecraftserver_reloadableresources; @@ -1119,7 +1064,7 @@ this.packRepository.setSelected(dataPacks); WorldDataConfiguration worlddataconfiguration = new WorldDataConfiguration(MinecraftServer.getSelectedPacks(this.packRepository, true), this.worldData.enabledFeatures()); -@@ -1952,7 +2428,7 @@ +@@ -1952,7 +2407,7 @@ final List list = Lists.newArrayList(); final GameRules gamerules = this.getGameRules(); @@ -1128,7 +1073,7 @@ @Override public > void visit(GameRules.Key key, GameRules.Type type) { list.add(String.format(Locale.ROOT, "%s=%s\n", key.getId(), gamerules.getRule(key))); -@@ -2058,7 +2534,7 @@ +@@ -2058,7 +2513,7 @@ try { label51: { @@ -1137,13 +1082,10 @@ try { arraylist = Lists.newArrayList(NativeModuleLister.listModules()); -@@ -2105,8 +2581,24 @@ - if (bufferedwriter != null) { - bufferedwriter.close(); - } -+ -+ } -+ +@@ -2108,6 +2563,22 @@ + + } + + // CraftBukkit start + public boolean isDebugging() { + return false; @@ -1153,16 +1095,17 @@ + public static MinecraftServer getServer() { + return (Bukkit.getServer() instanceof CraftServer) ? ((CraftServer) Bukkit.getServer()).getServer() : null; + } - ++ + @Deprecated + public static RegistryAccess getDefaultRegistryAccess() { + return CraftRegistry.getMinecraftRegistry(); - } ++ } + // CraftBukkit end - ++ private ProfilerFiller createProfiler() { if (this.willStartRecordingMetrics) { -@@ -2225,18 +2717,24 @@ + this.metricsRecorder = ActiveMetricsRecorder.createStarted(new ServerMetricsSamplersProvider(Util.timeSource, this.isDedicatedServer()), Util.timeSource, Util.ioPool(), new MetricsPersister("server"), this.onMetricsRecordingStopped, (path) -> { +@@ -2225,18 +2696,24 @@ } public void logChatMessage(Component message, ChatType.Bound params, @Nullable String prefix) { diff --git a/paper-server/patches/sources/net/minecraft/server/dedicated/DedicatedServer.java.patch b/paper-server/patches/sources/net/minecraft/server/dedicated/DedicatedServer.java.patch index 4e7b412d60f..d7f98a278aa 100644 --- a/paper-server/patches/sources/net/minecraft/server/dedicated/DedicatedServer.java.patch +++ b/paper-server/patches/sources/net/minecraft/server/dedicated/DedicatedServer.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/server/dedicated/DedicatedServer.java +++ b/net/minecraft/server/dedicated/DedicatedServer.java -@@ -54,11 +54,23 @@ +@@ -54,11 +54,22 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.GameRules; import net.minecraft.world.level.GameType; @@ -15,7 +15,6 @@ +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.io.IoBuilder; +import org.bukkit.command.CommandSender; -+import org.bukkit.craftbukkit.SpigotTimings; // Spigot +import org.bukkit.craftbukkit.util.TerminalCompletionHandler; +import org.bukkit.craftbukkit.util.TerminalConsoleWriterThread; +import org.bukkit.event.server.ServerCommandEvent; @@ -25,7 +24,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface { static final Logger LOGGER = LogUtils.getLogger(); -@@ -67,7 +79,7 @@ +@@ -67,7 +78,7 @@ private final List consoleInput = Collections.synchronizedList(Lists.newArrayList()); @Nullable private QueryThreadGs4 queryThreadGs4; @@ -34,7 +33,7 @@ @Nullable private RconThread rconThread; public DedicatedServerSettings settings; -@@ -81,33 +93,99 @@ +@@ -81,33 +92,99 @@ private DebugSampleSubscriptionTracker debugSampleSubscriptionTracker; public ServerLinks serverLinks; @@ -143,7 +142,7 @@ thread.setDaemon(true); thread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(DedicatedServer.LOGGER)); thread.start(); -@@ -126,13 +204,25 @@ +@@ -126,13 +203,25 @@ this.setPreventProxyConnections(dedicatedserverproperties.preventProxyConnections); this.setLocalIp(dedicatedserverproperties.serverIp); } @@ -170,7 +169,7 @@ DedicatedServer.LOGGER.info("Default game type: {}", dedicatedserverproperties.gamemode); InetAddress inetaddress = null; -@@ -156,10 +246,23 @@ +@@ -156,10 +245,23 @@ return false; } @@ -195,7 +194,7 @@ DedicatedServer.LOGGER.warn("To change this, set \"online-mode\" to \"true\" in the server.properties file."); } -@@ -170,7 +273,7 @@ +@@ -170,7 +272,7 @@ if (!OldUsersConverter.serverReadyAfterUserconversion(this)) { return false; } else { @@ -204,7 +203,7 @@ this.debugSampleSubscriptionTracker = new DebugSampleSubscriptionTracker(this.getPlayerList()); this.tickTimeLogger = new RemoteSampleLogger(TpsDebugDimensions.values().length, this.debugSampleSubscriptionTracker, RemoteDebugSampleType.TICK_TIME); long i = Util.getNanos(); -@@ -178,13 +281,13 @@ +@@ -178,13 +280,13 @@ SkullBlockEntity.setup(this.services, this); GameProfileCache.setUsesAuthentication(this.usesAuthentication()); DedicatedServer.LOGGER.info("Preparing level \"{}\"", this.getLevelIdName()); @@ -220,7 +219,7 @@ } if (dedicatedserverproperties.enableQuery) { -@@ -197,7 +300,7 @@ +@@ -197,7 +299,7 @@ this.rconThread = RconThread.create(this); } @@ -229,20 +228,21 @@ Thread thread1 = new Thread(new ServerWatchdog(this)); thread1.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandlerWithName(DedicatedServer.LOGGER)); -@@ -215,6 +318,12 @@ - } - } +@@ -213,7 +315,13 @@ + return true; + } ++ } ++ + // Paper start + public java.io.File getPluginsFolder() { + return (java.io.File) this.options.valueOf("plugins"); -+ } + } + // Paper end -+ + @Override public boolean isSpawningMonsters() { - return this.settings.getProperties().spawnMonsters && super.isSpawningMonsters(); -@@ -293,6 +402,7 @@ +@@ -293,6 +401,7 @@ this.queryThreadGs4.stop(); } @@ -250,7 +250,7 @@ } @Override -@@ -302,8 +412,8 @@ +@@ -302,8 +411,8 @@ } @Override @@ -261,11 +261,7 @@ } public void handleConsoleInput(String command, CommandSourceStack commandSource) { -@@ -311,12 +421,22 @@ - } - - public void handleConsoleInputs() { -+ SpigotTimings.serverCommandTimer.startTiming(); // Spigot +@@ -314,7 +423,15 @@ while (!this.consoleInput.isEmpty()) { ConsoleInput servercommand = (ConsoleInput) this.consoleInput.remove(0); @@ -281,11 +277,8 @@ + // CraftBukkit end } -+ SpigotTimings.serverCommandTimer.stopTiming(); // Spigot } - - @Override -@@ -383,7 +503,7 @@ +@@ -383,7 +500,7 @@ @Override public boolean isUnderSpawnProtection(ServerLevel world, BlockPos pos, Player player) { @@ -294,7 +287,7 @@ return false; } else if (this.getPlayerList().getOps().isEmpty()) { return false; -@@ -541,16 +661,52 @@ +@@ -541,16 +658,52 @@ @Override public String getPluginNames() { @@ -351,7 +344,7 @@ } public void storeUsingWhiteList(boolean useWhitelist) { -@@ -660,4 +816,15 @@ +@@ -660,4 +813,15 @@ } } } diff --git a/paper-server/patches/sources/net/minecraft/server/level/ServerChunkCache.java.patch b/paper-server/patches/sources/net/minecraft/server/level/ServerChunkCache.java.patch index 99668816f47..388c9ec705f 100644 --- a/paper-server/patches/sources/net/minecraft/server/level/ServerChunkCache.java.patch +++ b/paper-server/patches/sources/net/minecraft/server/level/ServerChunkCache.java.patch @@ -79,7 +79,7 @@ @Override public ThreadedLevelLightEngine getLightEngine() { return this.lightEngine; -@@ -138,20 +203,22 @@ +@@ -138,7 +203,7 @@ if (k == this.lastChunkPos[l] && leastStatus == this.lastChunkStatus[l]) { ChunkAccess ichunkaccess = this.lastChunk[l]; @@ -88,23 +88,16 @@ return ichunkaccess; } } - } - - gameprofilerfiller.incrementCounter("getChunkCacheMiss"); -+ this.level.timings.syncChunkLoadTimer.startTiming(); // Spigot - CompletableFuture> completablefuture = this.getChunkFutureMainThread(x, z, leastStatus, create); - ServerChunkCache.MainThreadExecutor chunkproviderserver_b = this.mainThreadProcessor; - +@@ -151,7 +216,7 @@ Objects.requireNonNull(completablefuture); chunkproviderserver_b.managedBlock(completablefuture::isDone); -+ this.level.timings.syncChunkLoadTimer.stopTiming(); // Spigot ChunkResult chunkresult = (ChunkResult) completablefuture.join(); - ChunkAccess ichunkaccess1 = (ChunkAccess) chunkresult.orElse((Object) null); + ChunkAccess ichunkaccess1 = (ChunkAccess) chunkresult.orElse(null); // CraftBukkit - decompile error if (ichunkaccess1 == null && create) { throw (IllegalStateException) Util.pauseInIde(new IllegalStateException("Chunk not there when requested: " + chunkresult.getError())); -@@ -231,7 +298,15 @@ +@@ -231,7 +296,15 @@ int l = ChunkLevel.byStatus(leastStatus); ChunkHolder playerchunk = this.getVisibleChunkIfPresent(k); @@ -121,7 +114,7 @@ this.distanceManager.addTicket(TicketType.UNKNOWN, chunkcoordintpair, l, chunkcoordintpair); if (this.chunkAbsent(playerchunk, l)) { ProfilerFiller gameprofilerfiller = Profiler.get(); -@@ -250,7 +325,7 @@ +@@ -250,7 +323,7 @@ } private boolean chunkAbsent(@Nullable ChunkHolder holder, int maxLevel) { @@ -130,7 +123,7 @@ } @Override -@@ -279,7 +354,7 @@ +@@ -279,7 +352,7 @@ return this.mainThreadProcessor.pollTask(); } @@ -139,7 +132,7 @@ boolean flag = this.distanceManager.runAllUpdates(this.chunkMap); boolean flag1 = this.chunkMap.promoteChunkMap(); -@@ -309,30 +384,58 @@ +@@ -309,18 +382,40 @@ @Override public void close() throws IOException { @@ -156,8 +149,8 @@ this.dataStorage.close(); this.lightEngine.close(); this.chunkMap.close(); - } - ++ } ++ + // CraftBukkit start - modelled on below + public void purgeUnload() { + ProfilerFiller gameprofilerfiller = Profiler.get(); @@ -169,38 +162,20 @@ + this.chunkMap.tick(() -> true); + gameprofilerfiller.pop(); + this.clearCache(); -+ } + } + // CraftBukkit end -+ + @Override public void tick(BooleanSupplier shouldKeepTicking, boolean tickChunks) { ProfilerFiller gameprofilerfiller = Profiler.get(); gameprofilerfiller.push("purge"); - if (this.level.tickRateManager().runsNormally() || !tickChunks) { -+ this.level.timings.doChunkMap.startTiming(); // Spigot + if (this.level.tickRateManager().runsNormally() || !tickChunks || this.level.spigotConfig.unloadFrozenChunks) { // Spigot this.distanceManager.purgeStaleTickets(); } - this.runDistanceManagerUpdates(); -+ this.level.timings.doChunkMap.stopTiming(); // Spigot - gameprofilerfiller.popPush("chunks"); - if (tickChunks) { - this.tickChunks(); -+ this.level.timings.tracker.startTiming(); // Spigot - this.chunkMap.tick(); -+ this.level.timings.tracker.stopTiming(); // Spigot - } - -+ this.level.timings.doChunkUnload.startTiming(); // Spigot - gameprofilerfiller.popPush("unload"); - this.chunkMap.tick(shouldKeepTicking); -+ this.level.timings.doChunkUnload.stopTiming(); // Spigot - gameprofilerfiller.pop(); - this.clearCache(); - } -@@ -401,14 +504,14 @@ +@@ -401,14 +496,14 @@ this.lastSpawnState = spawnercreature_d; profiler.popPush("spawnAndTick"); @@ -218,7 +193,7 @@ } else { list1 = List.of(); } -@@ -420,12 +523,14 @@ +@@ -420,7 +515,7 @@ ChunkPos chunkcoordintpair = chunk.getPos(); chunk.incrementInhabitedTime(timeDelta); @@ -227,14 +202,7 @@ NaturalSpawner.spawnForChunk(this.level, chunk, spawnercreature_d, list1); } - if (this.level.shouldTickBlocksAt(chunkcoordintpair.toLong())) { -+ this.level.timings.doTickTiles.startTiming(); // Spigot - this.level.tickChunk(chunk, k); -+ this.level.timings.doTickTiles.stopTiming(); // Spigot - } - } - -@@ -541,10 +646,16 @@ +@@ -541,10 +636,16 @@ @Override public void setSpawnSettings(boolean spawnMonsters) { @@ -253,7 +221,7 @@ public String getChunkDebugData(ChunkPos pos) { return this.chunkMap.getChunkDebugData(pos); } -@@ -618,14 +729,20 @@ +@@ -618,14 +719,20 @@ } @Override diff --git a/paper-server/patches/sources/net/minecraft/server/level/ServerLevel.java.patch b/paper-server/patches/sources/net/minecraft/server/level/ServerLevel.java.patch index b9dfe92783a..a7dd223c0a1 100644 --- a/paper-server/patches/sources/net/minecraft/server/level/ServerLevel.java.patch +++ b/paper-server/patches/sources/net/minecraft/server/level/ServerLevel.java.patch @@ -35,13 +35,12 @@ import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.shapes.BooleanOp; -@@ -173,6 +175,17 @@ +@@ -173,6 +175,16 @@ import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.ticks.LevelTicks; import org.slf4j.Logger; +import org.bukkit.Bukkit; +import org.bukkit.WeatherType; -+import org.bukkit.craftbukkit.SpigotTimings; // Spigot +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.craftbukkit.generator.CustomWorldChunkManager; +import org.bukkit.craftbukkit.util.WorldUUID; @@ -53,7 +52,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLevel { -@@ -187,7 +200,7 @@ +@@ -187,7 +199,7 @@ final List players = Lists.newArrayList(); public final ServerChunkCache chunkSource; private final MinecraftServer server; @@ -62,7 +61,7 @@ private int lastSpawnChunkRadius; final EntityTickList entityTickList = new EntityTickList(); public final PersistentEntitySectionManager entityManager; -@@ -214,52 +227,184 @@ +@@ -214,52 +226,184 @@ private final boolean tickTime; private final RandomSequences randomSequences; @@ -79,7 +78,7 @@ + // CraftBukkit start + public final LevelStorageSource.LevelStorageAccess convertable; + public final UUID uuid; -+ + + public LevelChunk getChunkIfLoaded(int x, int z) { + return this.chunkSource.getChunk(x, z, false); + } @@ -200,7 +199,7 @@ + ChunkGenerator chunkgenerator = worlddimension.generator(); + // CraftBukkit start + this.serverLevelData.setWorld(this); - ++ + if (biomeProvider != null) { + BiomeSource worldChunkManager = new CustomWorldChunkManager(this.getWorld(), biomeProvider, this.server.registryAccess().lookupOrThrow(Registries.BIOME)); + if (chunkgenerator instanceof NoiseBasedChunkGenerator cga) { @@ -271,7 +270,7 @@ } /** @deprecated */ -@@ -305,12 +450,20 @@ +@@ -305,12 +449,20 @@ long j; if (this.sleepStatus.areEnoughSleeping(i) && this.sleepStatus.areEnoughDeepSleeping(i, this.players)) { @@ -295,30 +294,7 @@ if (this.getGameRules().getBoolean(GameRules.RULE_WEATHER_CYCLE) && this.isRaining()) { this.resetWeatherCycle(); } -@@ -322,6 +475,7 @@ - } - - gameprofilerfiller.push("tickPending"); -+ this.timings.doTickPending.startTiming(); // Spigot - if (!this.isDebug() && flag) { - j = this.getGameTime(); - gameprofilerfiller.push("blockTicks"); -@@ -330,6 +484,7 @@ - this.fluidTicks.tick(j, 65536, this::tickFluid); - gameprofilerfiller.pop(); - } -+ this.timings.doTickPending.stopTiming(); // Spigot - - gameprofilerfiller.popPush("raid"); - if (flag) { -@@ -340,12 +495,14 @@ - this.getChunkSource().tick(shouldKeepTicking, true); - gameprofilerfiller.popPush("blockEvents"); - if (flag) { -+ this.timings.doSounds.startTiming(); // Spigot - this.runBlockEvents(); -+ this.timings.doSounds.stopTiming(); // Spigot - } +@@ -345,7 +497,7 @@ this.handlingTick = false; gameprofilerfiller.pop(); @@ -327,32 +303,15 @@ if (flag1) { this.resetEmptyTime(); -@@ -353,12 +510,15 @@ - - if (flag1 || this.emptyTime++ < 300) { - gameprofilerfiller.push("entities"); -+ this.timings.tickEntities.startTiming(); // Spigot - if (this.dragonFight != null && flag) { - gameprofilerfiller.push("dragonFight"); - this.dragonFight.tick(); +@@ -359,6 +511,7 @@ gameprofilerfiller.pop(); } + org.spigotmc.ActivationRange.activateEntities(this); // Spigot -+ this.timings.entityTick.startTiming(); // Spigot this.entityTickList.forEach((entity) -> { if (!entity.isRemoved()) { if (!tickratemanager.isEntityFrozen(entity)) { -@@ -383,6 +543,8 @@ - } - } - }); -+ this.timings.entityTick.stopTiming(); // Spigot -+ this.timings.tickEntities.stopTiming(); // Spigot - gameprofilerfiller.pop(); - this.tickBlockEntities(); - } -@@ -429,7 +591,7 @@ +@@ -429,7 +582,7 @@ private void wakeUpAllPlayers() { this.sleepStatus.removeAllSleepers(); @@ -361,7 +320,7 @@ entityplayer.stopSleepInBed(false, false); }); } -@@ -442,7 +604,7 @@ +@@ -442,7 +595,7 @@ ProfilerFiller gameprofilerfiller = Profiler.get(); gameprofilerfiller.push("thunder"); @@ -370,7 +329,7 @@ BlockPos blockposition = this.findLightningTargetAround(this.getBlockRandomPos(j, 0, k, 15)); if (this.isRainingAt(blockposition)) { -@@ -456,7 +618,7 @@ +@@ -456,7 +609,7 @@ entityhorseskeleton.setTrap(true); entityhorseskeleton.setAge(0); entityhorseskeleton.setPos((double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ()); @@ -379,7 +338,7 @@ } } -@@ -465,7 +627,7 @@ +@@ -465,7 +618,7 @@ if (entitylightning != null) { entitylightning.moveTo(Vec3.atBottomCenterOf(blockposition)); entitylightning.setVisualOnly(flag1); @@ -388,7 +347,7 @@ } } } -@@ -521,7 +683,7 @@ +@@ -521,7 +674,7 @@ Biome biomebase = (Biome) this.getBiome(blockposition1).value(); if (biomebase.shouldFreeze(this, blockposition2)) { @@ -397,7 +356,7 @@ } if (this.isRaining()) { -@@ -537,10 +699,10 @@ +@@ -537,10 +690,10 @@ BlockState iblockdata1 = (BlockState) iblockdata.setValue(SnowLayerBlock.LAYERS, j + 1); Block.pushEntitiesUp(iblockdata, iblockdata1, this, blockposition1); @@ -410,7 +369,7 @@ } } -@@ -701,33 +863,67 @@ +@@ -701,33 +854,67 @@ this.rainLevel = Mth.clamp(this.rainLevel, 0.0F, 1.0F); } @@ -428,10 +387,9 @@ if (flag != this.isRaining()) { if (flag) { - this.server.getPlayerList().broadcastAll(new ClientboundGameEventPacket(ClientboundGameEventPacket.STOP_RAINING, 0.0F)); -- } else { -- this.server.getPlayerList().broadcastAll(new ClientboundGameEventPacket(ClientboundGameEventPacket.START_RAINING, 0.0F)); + this.server.getPlayerList().broadcastAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.STOP_RAINING, 0.0F)); -+ } else { + } else { +- this.server.getPlayerList().broadcastAll(new ClientboundGameEventPacket(ClientboundGameEventPacket.START_RAINING, 0.0F)); + this.server.getPlayerList().broadcastAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.START_RAINING, 0.0F)); } @@ -446,7 +404,7 @@ + ((ServerPlayer) this.players.get(idx)).tickWeather(); + } + } - ++ + if (flag != this.isRaining()) { + // Only send weather packets to those affected + for (int idx = 0; idx < this.players.size(); ++idx) { @@ -461,7 +419,7 @@ + } + } + // CraftBukkit end -+ + } @VisibleForTesting @@ -487,7 +445,7 @@ } public void resetEmptyTime() { -@@ -754,6 +950,14 @@ +@@ -754,6 +941,13 @@ } public void tickNonPassenger(Entity entity) { @@ -498,11 +456,10 @@ + return; + } + // Spigot end -+ entity.tickTimer.startTiming(); // Spigot entity.setOldPosAndRot(); ProfilerFiller gameprofilerfiller = Profiler.get(); -@@ -763,6 +967,7 @@ +@@ -763,6 +957,7 @@ }); gameprofilerfiller.incrementCounter("tickNonPassenger"); entity.tick(); @@ -510,15 +467,7 @@ gameprofilerfiller.pop(); Iterator iterator = entity.getPassengers().iterator(); -@@ -771,6 +976,7 @@ - - this.tickPassenger(entity, entity1); - } -+ entity.tickTimer.stopTiming(); // Spigot - - } - -@@ -786,6 +992,7 @@ +@@ -786,6 +981,7 @@ }); gameprofilerfiller.incrementCounter("tickPassenger"); passenger.rideTick(); @@ -526,7 +475,7 @@ gameprofilerfiller.pop(); Iterator iterator = passenger.getPassengers().iterator(); -@@ -810,6 +1017,7 @@ +@@ -810,6 +1006,7 @@ ServerChunkCache chunkproviderserver = this.getChunkSource(); if (!savingDisabled) { @@ -534,7 +483,7 @@ if (progressListener != null) { progressListener.progressStartNoAbort(Component.translatable("menu.savingLevel")); } -@@ -827,11 +1035,19 @@ +@@ -827,11 +1024,19 @@ } } @@ -555,7 +504,7 @@ } DimensionDataStorage worldpersistentdata = this.getChunkSource().getDataStorage(); -@@ -903,18 +1119,40 @@ +@@ -903,18 +1108,40 @@ @Override public boolean addFreshEntity(Entity entity) { @@ -599,7 +548,7 @@ } } -@@ -939,41 +1177,86 @@ +@@ -939,41 +1166,86 @@ this.entityManager.addNewEntity(player); } @@ -691,20 +640,20 @@ while (iterator.hasNext()) { ServerPlayer entityplayer = (ServerPlayer) iterator.next(); -@@ -981,6 +1264,12 @@ - double d0 = (double) pos.getX() - entityplayer.getX(); +@@ -982,6 +1254,12 @@ double d1 = (double) pos.getY() - entityplayer.getY(); double d2 = (double) pos.getZ() - entityplayer.getZ(); -+ + + // CraftBukkit start + if (entityhuman != null && !entityplayer.getBukkitEntity().canSee(entityhuman.getBukkitEntity())) { + continue; + } + // CraftBukkit end - ++ if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) { entityplayer.connection.send(new ClientboundBlockDestructionPacket(entityId, pos, progress)); -@@ -1060,7 +1349,18 @@ + } +@@ -1060,7 +1338,18 @@ Iterator iterator = this.navigatingMobs.iterator(); while (iterator.hasNext()) { @@ -724,7 +673,7 @@ PathNavigation navigationabstract = entityinsentient.getNavigation(); if (navigationabstract.shouldRecomputePath(pos)) { -@@ -1126,9 +1426,15 @@ +@@ -1126,9 +1415,15 @@ @Override public void explode(@Nullable Entity entity, @Nullable DamageSource damageSource, @Nullable ExplosionDamageCalculator behavior, double x, double y, double z, float power, boolean createFire, Level.ExplosionInteraction explosionSourceType, ParticleOptions smallParticle, ParticleOptions largeParticle, Holder soundEvent) { @@ -741,7 +690,7 @@ case NONE: explosion_effect = Explosion.BlockInteraction.KEEP; break; -@@ -1144,16 +1450,26 @@ +@@ -1144,16 +1439,26 @@ case TRIGGER: explosion_effect = Explosion.BlockInteraction.TRIGGER_BLOCK; break; @@ -771,7 +720,7 @@ Iterator iterator = this.players.iterator(); while (iterator.hasNext()) { -@@ -1162,10 +1478,11 @@ +@@ -1162,10 +1467,11 @@ if (entityplayer.distanceToSqr(vec3d) < 4096.0D) { Optional optional = Optional.ofNullable((Vec3) serverexplosion.getHitPlayers().get(entityplayer)); @@ -784,7 +733,7 @@ } private Explosion.BlockInteraction getDestroyType(GameRules.Key decayRule) { -@@ -1226,17 +1543,24 @@ +@@ -1226,17 +1532,24 @@ } public int sendParticles(T parameters, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ, double speed) { @@ -812,7 +761,7 @@ ++j; } } -@@ -1292,7 +1616,7 @@ +@@ -1292,7 +1605,7 @@ @Nullable public BlockPos findNearestMapStructure(TagKey structureTag, BlockPos pos, int radius, boolean skipReferencedStructures) { @@ -821,7 +770,7 @@ return null; } else { Optional> optional = this.registryAccess().lookupOrThrow(Registries.STRUCTURE).get(structureTag); -@@ -1334,11 +1658,22 @@ +@@ -1334,11 +1647,22 @@ @Nullable @Override public MapItemSavedData getMapData(MapId id) { @@ -845,7 +794,7 @@ this.getServer().overworld().getDataStorage().set(id.key(), state); } -@@ -1649,6 +1984,11 @@ +@@ -1649,6 +1973,11 @@ @Override public void blockUpdated(BlockPos pos, Block block) { if (!this.isDebug()) { @@ -857,7 +806,7 @@ this.updateNeighborsAt(pos, block); } -@@ -1668,12 +2008,12 @@ +@@ -1668,12 +1997,12 @@ } public boolean isFlat() { @@ -872,7 +821,7 @@ } @Nullable -@@ -1696,7 +2036,7 @@ +@@ -1696,7 +2025,7 @@ private static String getTypeCount(Iterable items, Function classifier) { try { Object2IntOpenHashMap object2intopenhashmap = new Object2IntOpenHashMap(); @@ -881,7 +830,7 @@ while (iterator.hasNext()) { T t0 = iterator.next(); -@@ -1705,7 +2045,7 @@ +@@ -1705,7 +2034,7 @@ object2intopenhashmap.addTo(s, 1); } @@ -890,7 +839,7 @@ String s1 = (String) entry.getKey(); return s1 + ":" + entry.getIntValue(); -@@ -1717,6 +2057,7 @@ +@@ -1717,6 +2046,7 @@ @Override public LevelEntityGetter getEntities() { @@ -898,7 +847,7 @@ return this.entityManager.getEntityGetter(); } -@@ -1836,6 +2177,7 @@ +@@ -1836,6 +2166,7 @@ } public void onTrackingStart(Entity entity) { @@ -906,7 +855,7 @@ ServerLevel.this.getChunkSource().addEntity(entity); if (entity instanceof ServerPlayer entityplayer) { ServerLevel.this.players.add(entityplayer); -@@ -1864,9 +2206,42 @@ +@@ -1864,9 +2195,42 @@ } entity.updateDynamicGameEventListener(DynamicGameEventListener::add); @@ -949,7 +898,7 @@ ServerLevel.this.getChunkSource().removeEntity(entity); if (entity instanceof ServerPlayer entityplayer) { ServerLevel.this.players.remove(entityplayer); -@@ -1895,6 +2270,14 @@ +@@ -1895,6 +2259,14 @@ } entity.updateDynamicGameEventListener(DynamicGameEventListener::remove); diff --git a/paper-server/patches/sources/net/minecraft/server/network/ServerGamePacketListenerImpl.java.patch b/paper-server/patches/sources/net/minecraft/server/network/ServerGamePacketListenerImpl.java.patch index 10cf9917959..2181df53c72 100644 --- a/paper-server/patches/sources/net/minecraft/server/network/ServerGamePacketListenerImpl.java.patch +++ b/paper-server/patches/sources/net/minecraft/server/network/ServerGamePacketListenerImpl.java.patch @@ -129,14 +129,14 @@ this.chunkSender = new PlayerChunkSender(connection.isMemoryConnection()); this.player = player; player.connection = this; -@@ -256,11 +320,28 @@ +@@ -256,8 +320,24 @@ Objects.requireNonNull(server); this.signedMessageDecoder = SignedMessageChain.Decoder.unsigned(uuid, server::enforceSecureProfile); - this.chatMessageChain = new FutureChain(server); + this.chatMessageChain = new FutureChain(server.chatExecutor); // CraftBukkit - async chat } - ++ + // CraftBukkit start - add fields and methods + private int lastTick = MinecraftServer.currentTick; + private int allowedPlayerTicks = 1; @@ -152,25 +152,18 @@ + private float lastYaw = Float.MAX_VALUE; + private boolean justTeleported = false; + // CraftBukkit end -+ + @Override public void tick() { -+ org.bukkit.craftbukkit.SpigotTimings.playerConnectionTimer.startTiming(); // Spigot - if (this.ackBlockChangesUpTo > -1) { - this.send(new ClientboundBlockChangedAckPacket(this.ackBlockChangesUpTo)); - this.ackBlockChangesUpTo = -1; -@@ -313,8 +394,10 @@ +@@ -313,6 +393,7 @@ this.chatSpamThrottler.tick(); this.dropSpamThrottler.tick(); if (this.player.getLastActionTime() > 0L && this.server.getPlayerIdleTimeout() > 0 && Util.getMillis() - this.player.getLastActionTime() > (long) this.server.getPlayerIdleTimeout() * 1000L * 60L) { + this.player.resetLastActionTime(); // CraftBukkit - SPIGOT-854 this.disconnect((Component) Component.translatable("multiplayer.disconnect.idling")); } -+ org.bukkit.craftbukkit.SpigotTimings.playerConnectionTimer.stopTiming(); // Spigot - } - -@@ -376,6 +459,12 @@ +@@ -376,6 +457,12 @@ @Override public void handlePlayerInput(ServerboundPlayerInputPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -183,7 +176,7 @@ this.player.setLastClientInput(packet.input()); } -@@ -401,6 +490,13 @@ +@@ -401,6 +488,13 @@ if (entity != this.player && entity.getControllingPassenger() == this.player && entity == this.lastVehicle) { ServerLevel worldserver = this.player.serverLevel(); @@ -197,7 +190,7 @@ double d0 = entity.getX(); double d1 = entity.getY(); double d2 = entity.getZ(); -@@ -415,7 +511,33 @@ +@@ -415,7 +509,33 @@ double d9 = entity.getDeltaMovement().lengthSqr(); double d10 = d6 * d6 + d7 * d7 + d8 * d8; @@ -232,7 +225,7 @@ ServerGamePacketListenerImpl.LOGGER.warn("{} (vehicle of {}) moved too quickly! {},{},{}", new Object[]{entity.getName().getString(), this.player.getName().getString(), d6, d7, d8}); this.send(ClientboundMoveVehiclePacket.fromEntity(entity)); return; -@@ -449,19 +571,72 @@ +@@ -449,20 +569,73 @@ d10 = d6 * d6 + d7 * d7 + d8 * d8; boolean flag2 = false; @@ -251,8 +244,8 @@ + this.player.absMoveTo(d0, d1, d2, this.player.getYRot(), this.player.getXRot()); // CraftBukkit this.send(ClientboundMoveVehiclePacket.fromEntity(entity)); return; -+ } -+ + } + + // CraftBukkit start - fire PlayerMoveEvent + Player player = this.getCraftPlayer(); + if (!this.hasMoved) { @@ -301,12 +294,13 @@ + this.justTeleported = false; + return; + } - } ++ } + // CraftBukkit end - ++ this.player.serverLevel().getChunkSource().move(this.player); entity.recordMovementThroughBlocks(new Vec3(d0, d1, d2), entity.position()); -@@ -499,6 +674,7 @@ + Vec3 vec3d = new Vec3(entity.getX() - d0, entity.getY() - d1, entity.getZ() - d2); +@@ -499,6 +672,7 @@ this.lastGoodZ = this.awaitingPositionFromClient.z; this.player.hasChangedDimension(); this.awaitingPositionFromClient = null; @@ -314,7 +308,7 @@ } } -@@ -528,6 +704,7 @@ +@@ -528,6 +702,7 @@ @Override public void handleRecipeBookChangeSettingsPacket(ServerboundRecipeBookChangeSettingsPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -322,7 +316,7 @@ this.player.getRecipeBook().setBookSetting(packet.getBookType(), packet.isOpen(), packet.isFiltering()); } -@@ -548,6 +725,12 @@ +@@ -548,6 +723,12 @@ @Override public void handleCustomCommandSuggestions(ServerboundCommandSuggestionPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -335,7 +329,7 @@ StringReader stringreader = new StringReader(packet.getCommand()); if (stringreader.canRead() && stringreader.peek() == '/') { -@@ -557,6 +740,7 @@ +@@ -557,6 +738,7 @@ ParseResults parseresults = this.server.getCommands().getDispatcher().parse(stringreader, this.player.createCommandSourceStack()); this.server.getCommands().getDispatcher().getCompletionSuggestions(parseresults).thenAccept((suggestions) -> { @@ -343,7 +337,7 @@ Suggestions suggestions1 = suggestions.getList().size() <= 1000 ? suggestions : new Suggestions(suggestions.getRange(), suggestions.getList().subList(0, 1000)); this.send(new ClientboundCommandSuggestionsPacket(packet.getId(), suggestions1)); -@@ -668,7 +852,7 @@ +@@ -668,7 +850,7 @@ ItemStack itemstack = iblockdata.getCloneItemStack(worldserver, blockposition, flag); if (!itemstack.isEmpty()) { @@ -352,7 +346,7 @@ ServerGamePacketListenerImpl.addBlockDataToItem(iblockdata, worldserver, blockposition, itemstack); } -@@ -866,6 +1050,13 @@ +@@ -866,6 +1048,13 @@ AbstractContainerMenu container = this.player.containerMenu; if (container instanceof MerchantMenu containermerchant) { @@ -366,7 +360,7 @@ if (!containermerchant.stillValid(this.player)) { ServerGamePacketListenerImpl.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, containermerchant); return; -@@ -879,6 +1070,13 @@ +@@ -879,6 +1068,13 @@ @Override public void handleEditBook(ServerboundEditBookPacket packet) { @@ -380,7 +374,7 @@ int i = packet.slot(); if (Inventory.isHotbarSlot(i) || i == 40) { -@@ -899,12 +1097,16 @@ +@@ -899,12 +1095,16 @@ } private void updateBookContents(List pages, int slotId) { @@ -398,7 +392,7 @@ } } -@@ -915,12 +1117,13 @@ +@@ -915,12 +1115,13 @@ ItemStack itemstack1 = itemstack.transmuteCopy(Items.WRITTEN_BOOK); itemstack1.remove(DataComponents.WRITABLE_BOOK_CONTENT); @@ -414,7 +408,7 @@ } } -@@ -982,7 +1185,7 @@ +@@ -982,7 +1183,7 @@ } else { ServerLevel worldserver = this.player.serverLevel(); @@ -423,7 +417,7 @@ if (this.tickCount == 0) { this.resetPosition(); } -@@ -997,7 +1200,15 @@ +@@ -997,7 +1198,15 @@ if (this.player.isPassenger()) { this.player.absMoveTo(this.player.getX(), this.player.getY(), this.player.getZ(), f, f1); this.player.serverLevel().getChunkSource().move(this.player); @@ -439,7 +433,7 @@ double d3 = this.player.getX(); double d4 = this.player.getY(); double d5 = this.player.getZ(); -@@ -1019,15 +1230,33 @@ +@@ -1019,15 +1228,33 @@ ++this.receivedMovePacketCount; int i = this.receivedMovePacketCount - this.knownMovePacketCount; @@ -475,7 +469,7 @@ ServerGamePacketListenerImpl.LOGGER.warn("{} moved too quickly! {},{},{}", new Object[]{this.player.getName().getString(), d6, d7, d8}); this.teleport(this.player.getX(), this.player.getY(), this.player.getZ(), this.player.getYRot(), this.player.getXRot()); return; -@@ -1049,6 +1278,7 @@ +@@ -1049,6 +1276,7 @@ boolean flag2 = this.player.verticalCollisionBelow; this.player.move(MoverType.PLAYER, new Vec3(d6, d7, d8)); @@ -483,7 +477,7 @@ double d11 = d7; d6 = d0 - this.player.getX(); -@@ -1061,15 +1291,81 @@ +@@ -1061,15 +1289,81 @@ d10 = d6 * d6 + d7 * d7 + d8 * d8; boolean flag3 = false; @@ -567,7 +561,7 @@ this.player.absMoveTo(d0, d1, d2, f, f1); boolean flag4 = this.player.isAutoSpinAttack(); -@@ -1119,6 +1415,7 @@ +@@ -1119,6 +1413,7 @@ this.awaitingTeleportTime = this.tickCount; this.teleport(this.awaitingPositionFromClient.x, this.awaitingPositionFromClient.y, this.awaitingPositionFromClient.z, this.player.getYRot(), this.player.getXRot()); } @@ -575,7 +569,7 @@ return true; } else { -@@ -1147,23 +1444,83 @@ +@@ -1147,23 +1442,83 @@ } public void teleport(double x, double y, double z, float yaw, float pitch) { @@ -662,7 +656,7 @@ if (this.player.hasClientLoaded()) { BlockPos blockposition = packet.getPos(); -@@ -1175,14 +1532,46 @@ +@@ -1175,14 +1530,46 @@ if (!this.player.isSpectator()) { ItemStack itemstack = this.player.getItemInHand(InteractionHand.OFF_HAND); @@ -711,7 +705,7 @@ this.player.drop(false); } -@@ -1218,9 +1607,30 @@ +@@ -1218,9 +1605,30 @@ } } @@ -742,7 +736,7 @@ if (this.player.hasClientLoaded()) { this.player.connection.ackBlockChangesUpTo(packet.getSequence()); ServerLevel worldserver = this.player.serverLevel(); -@@ -1244,6 +1654,7 @@ +@@ -1244,6 +1652,7 @@ if (blockposition.getY() <= i) { if (this.awaitingPositionFromClient == null && worldserver.mayInteract(this.player, blockposition)) { @@ -750,7 +744,7 @@ InteractionResult enuminteractionresult = this.player.gameMode.useItemOn(this.player, worldserver, itemstack, enumhand, movingobjectpositionblock); if (enuminteractionresult.consumesAction()) { -@@ -1281,6 +1692,8 @@ +@@ -1281,6 +1690,8 @@ @Override public void handleUseItem(ServerboundUseItemPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -759,10 +753,12 @@ if (this.player.hasClientLoaded()) { this.ackBlockChangesUpTo(packet.getSequence()); ServerLevel worldserver = this.player.serverLevel(); -@@ -1296,6 +1709,47 @@ - this.player.absRotateTo(f, f1); - } +@@ -1294,8 +1705,49 @@ + if (f1 != this.player.getXRot() || f != this.player.getYRot()) { + this.player.absRotateTo(f, f1); ++ } ++ + // CraftBukkit start + // Raytrace to look for 'rogue armswings' + double d0 = this.player.getX(); @@ -793,8 +789,8 @@ + cancelled = event.useItemInHand() == Event.Result.DENY; + } + this.player.gameMode.firedInteract = false; -+ } -+ + } + + if (cancelled) { + this.player.getBukkitEntity().updateInventory(); // SPIGOT-2524 + return; @@ -807,7 +803,7 @@ InteractionResult enuminteractionresult = this.player.gameMode.useItem(this.player, worldserver, itemstack, enumhand); if (enuminteractionresult instanceof InteractionResult.Success) { -@@ -1321,7 +1775,7 @@ +@@ -1321,7 +1773,7 @@ Entity entity = packet.getEntity(worldserver); if (entity != null) { @@ -816,7 +812,7 @@ return; } } -@@ -1342,6 +1796,13 @@ +@@ -1342,6 +1794,13 @@ @Override public void onDisconnect(DisconnectionDetails info) { @@ -830,7 +826,7 @@ ServerGamePacketListenerImpl.LOGGER.info("{} lost connection: {}", this.player.getName().getString(), info.reason().getString()); this.removePlayerFromWorld(); super.onDisconnect(info); -@@ -1349,10 +1810,20 @@ +@@ -1349,10 +1808,20 @@ private void removePlayerFromWorld() { this.chatMessageChain.close(); @@ -853,7 +849,7 @@ this.player.getTextFilter().leave(); } -@@ -1367,7 +1838,16 @@ +@@ -1367,7 +1836,16 @@ @Override public void handleSetCarriedItem(ServerboundSetCarriedItemPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -870,7 +866,7 @@ if (this.player.getInventory().selected != packet.getSlot() && this.player.getUsedItemHand() == InteractionHand.MAIN_HAND) { this.player.stopUsingItem(); } -@@ -1376,11 +1856,18 @@ +@@ -1376,11 +1854,18 @@ this.player.resetLastActionTime(); } else { ServerGamePacketListenerImpl.LOGGER.warn("{} tried to set an invalid carried item", this.player.getName().getString()); @@ -889,7 +885,7 @@ Optional optional = this.unpackAndApplyLastSeen(packet.lastSeenMessages()); if (!optional.isEmpty()) { -@@ -1394,27 +1881,44 @@ +@@ -1394,27 +1879,44 @@ return; } @@ -941,7 +937,7 @@ ParseResults parseresults = this.parseCommand(command); if (this.server.enforceSecureProfile() && SignableCommand.hasSignableArguments(parseresults)) { -@@ -1431,19 +1935,37 @@ +@@ -1431,19 +1933,37 @@ if (!optional.isEmpty()) { this.tryHandleChat(packet.command(), () -> { @@ -983,7 +979,7 @@ } catch (SignedMessageChain.DecodeException signedmessagechain_a) { this.handleMessageDecodeFailure(signedmessagechain_a); return; -@@ -1451,10 +1973,10 @@ +@@ -1451,10 +1971,10 @@ CommandSigningContext.SignedArguments commandsigningcontext_a = new CommandSigningContext.SignedArguments(map); @@ -996,7 +992,7 @@ } private void handleMessageDecodeFailure(SignedMessageChain.DecodeException exception) { -@@ -1530,14 +2052,20 @@ +@@ -1530,14 +2050,20 @@ return com_mojang_brigadier_commanddispatcher.parse(command, this.player.createCommandSourceStack()); } @@ -1021,10 +1017,12 @@ } } -@@ -1566,6 +2094,129 @@ - return false; - } +@@ -1564,8 +2090,128 @@ + } + return false; ++ } ++ + // CraftBukkit start - add method + public void chat(String s, PlayerChatMessage original, boolean async) { + if (s.isEmpty() || this.player.getChatVisibility() == ChatVisiblity.HIDDEN) { @@ -1117,10 +1115,9 @@ + this.server.console.sendMessage(s); + } + } -+ } -+ + } + + private void handleCommand(String s) { -+ org.bukkit.craftbukkit.SpigotTimings.playerCommandTimer.startTiming(); // Spigot + if ( org.spigotmc.SpigotConfig.logCommands ) // Spigot + this.LOGGER.info(this.player.getScoreboardName() + " issued server command: " + s); + @@ -1130,7 +1127,6 @@ + this.cserver.getPluginManager().callEvent(event); + + if (event.isCancelled()) { -+ org.bukkit.craftbukkit.SpigotTimings.playerCommandTimer.stopTiming(); // Spigot + return; + } + @@ -1143,7 +1139,6 @@ + java.util.logging.Logger.getLogger(ServerGamePacketListenerImpl.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + return; + } finally { -+ org.bukkit.craftbukkit.SpigotTimings.playerCommandTimer.stopTiming(); // Spigot + } + } + // CraftBukkit end @@ -1151,7 +1146,7 @@ private PlayerChatMessage getSignedMessage(ServerboundChatPacket packet, LastSeenMessages lastSeenMessages) throws SignedMessageChain.DecodeException { SignedMessageBody signedmessagebody = new SignedMessageBody(packet.message(), packet.timeStamp(), packet.salt(), lastSeenMessages); -@@ -1573,13 +2224,42 @@ +@@ -1573,13 +2219,42 @@ } private void broadcastChatMessage(PlayerChatMessage message) { @@ -1199,7 +1194,7 @@ this.disconnect((Component) Component.translatable("disconnect.spam")); } -@@ -1601,7 +2281,33 @@ +@@ -1601,7 +2276,33 @@ @Override public void handleAnimate(ServerboundSwingPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -1233,7 +1228,7 @@ this.player.swing(packet.getHand()); } -@@ -1609,6 +2315,29 @@ +@@ -1609,6 +2310,29 @@ public void handlePlayerCommand(ServerboundPlayerCommandPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); if (this.player.hasClientLoaded()) { @@ -1263,7 +1258,7 @@ this.player.resetLastActionTime(); Entity entity; PlayerRideableJumping ijumpable; -@@ -1691,6 +2420,12 @@ +@@ -1691,6 +2415,12 @@ } public void sendPlayerChatMessage(PlayerChatMessage message, ChatType.Bound params) { @@ -1276,7 +1271,7 @@ this.send(new ClientboundPlayerChatPacket(message.link().sender(), message.link().index(), message.signature(), message.signedBody().pack(this.messageSignatureCache), message.unsignedContent(), message.filterMask(), params)); this.addPendingMessage(message); } -@@ -1703,6 +2438,13 @@ +@@ -1703,6 +2433,13 @@ return this.connection.getRemoteAddress(); } @@ -1290,7 +1285,7 @@ public void switchToConfig() { this.waitingForSwitchToConfig = true; this.removePlayerFromWorld(); -@@ -1718,9 +2460,17 @@ +@@ -1718,9 +2455,17 @@ @Override public void handleInteract(ServerboundInteractPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -1308,7 +1303,7 @@ this.player.resetLastActionTime(); this.player.setShiftKeyDown(packet.isUsingSecondaryAction()); -@@ -1733,20 +2483,58 @@ +@@ -1733,20 +2478,58 @@ if (this.player.canInteractWithEntity(axisalignedbb, 3.0D)) { packet.dispatch(new ServerboundInteractPacket.Handler() { @@ -1324,7 +1319,7 @@ + ItemStack itemInHand = ServerGamePacketListenerImpl.this.player.getItemInHand(enumhand); + boolean triggerLeashUpdate = itemInHand != null && itemInHand.getItem() == Items.LEAD && entity instanceof Mob; + Item origItem = ServerGamePacketListenerImpl.this.player.getInventory().getSelected() == null ? null : ServerGamePacketListenerImpl.this.player.getInventory().getSelected().getItem(); -+ + + ServerGamePacketListenerImpl.this.cserver.getPluginManager().callEvent(event); + + // Entity in bucket - SPIGOT-4048 and SPIGOT-6859a @@ -1353,7 +1348,7 @@ + } + // CraftBukkit end + InteractionResult enuminteractionresult = playerconnection_a.run(ServerGamePacketListenerImpl.this.player, entity, enumhand); - ++ + // CraftBukkit start + if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) { + ServerGamePacketListenerImpl.this.player.containerMenu.sendAllDataToRemote(); @@ -1371,7 +1366,7 @@ } } -@@ -1755,19 +2543,20 @@ +@@ -1755,19 +2538,20 @@ @Override public void onInteraction(InteractionHand hand) { @@ -1395,7 +1390,7 @@ label23: { if (entity instanceof AbstractArrow) { -@@ -1785,6 +2574,11 @@ +@@ -1785,6 +2569,11 @@ } ServerGamePacketListenerImpl.this.player.attack(entity); @@ -1407,7 +1402,7 @@ return; } } -@@ -1809,7 +2603,7 @@ +@@ -1809,7 +2598,7 @@ case PERFORM_RESPAWN: if (this.player.wonGame) { this.player.wonGame = false; @@ -1416,7 +1411,7 @@ this.resetPosition(); CriteriaTriggers.CHANGED_DIMENSION.trigger(this.player, Level.END, Level.OVERWORLD); } else { -@@ -1817,11 +2611,11 @@ +@@ -1817,11 +2606,11 @@ return; } @@ -1430,7 +1425,7 @@ } } break; -@@ -1834,15 +2628,21 @@ +@@ -1834,15 +2623,21 @@ @Override public void handleContainerClose(ServerboundContainerClosePacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -1454,7 +1449,7 @@ this.player.containerMenu.sendAllDataToRemote(); } else if (!this.player.containerMenu.stillValid(this.player)) { ServerGamePacketListenerImpl.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, this.player.containerMenu); -@@ -1855,7 +2655,284 @@ +@@ -1855,7 +2650,284 @@ boolean flag = packet.getStateId() != this.player.containerMenu.getStateId(); this.player.containerMenu.suppressRemoteUpdates(); @@ -1740,7 +1735,7 @@ ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packet.getChangedSlots()).iterator(); while (objectiterator.hasNext()) { -@@ -1901,8 +2978,22 @@ +@@ -1901,8 +2973,22 @@ return; } @@ -1764,7 +1759,7 @@ if (containerrecipebook_a == RecipeBookMenu.PostPlaceAction.PLACE_GHOST_RECIPE) { this.player.connection.send(new ClientboundPlaceGhostRecipePacket(this.player.containerMenu.containerId, craftingmanager_d.display().display())); } -@@ -1917,6 +3008,7 @@ +@@ -1917,6 +3003,7 @@ @Override public void handleContainerButtonClick(ServerboundContainerButtonClickPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -1772,7 +1767,7 @@ this.player.resetLastActionTime(); if (this.player.containerMenu.containerId == packet.containerId() && !this.player.isSpectator()) { if (!this.player.containerMenu.stillValid(this.player)) { -@@ -1945,6 +3037,43 @@ +@@ -1945,6 +3032,43 @@ boolean flag1 = packet.slotNum() >= 1 && packet.slotNum() <= 45; boolean flag2 = itemstack.isEmpty() || itemstack.getCount() <= itemstack.getMaxStackSize(); @@ -1816,7 +1811,7 @@ if (flag1 && flag2) { this.player.inventoryMenu.getSlot(packet.slotNum()).setByPlayer(itemstack); -@@ -1972,6 +3101,7 @@ +@@ -1972,6 +3096,7 @@ } private void updateSignText(ServerboundSignUpdatePacket packet, List signText) { @@ -1824,7 +1819,7 @@ this.player.resetLastActionTime(); ServerLevel worldserver = this.player.serverLevel(); BlockPos blockposition = packet.getPos(); -@@ -1993,7 +3123,17 @@ +@@ -1993,7 +3118,17 @@ @Override public void handlePlayerAbilities(ServerboundPlayerAbilitiesPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -1843,7 +1838,7 @@ } @Override -@@ -2002,6 +3142,7 @@ +@@ -2002,6 +3137,7 @@ boolean flag = this.player.isModelPartShown(PlayerModelPart.HAT); this.player.updateOptions(packet.information()); @@ -1851,7 +1846,7 @@ if (this.player.isModelPartShown(PlayerModelPart.HAT) != flag) { this.server.getPlayerList().broadcastAll(new ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_HAT, this.player)); } -@@ -2058,7 +3199,7 @@ +@@ -2058,7 +3194,7 @@ if (!this.waitingForSwitchToConfig) { throw new IllegalStateException("Client acknowledged config, but none was requested"); } else { @@ -1860,7 +1855,7 @@ } } -@@ -2083,8 +3224,10 @@ +@@ -2083,8 +3219,10 @@ }); } diff --git a/paper-server/patches/sources/net/minecraft/world/entity/Entity.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/Entity.java.patch index 3e8d8fe1efc..58e250b6fd7 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/Entity.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/Entity.java.patch @@ -18,7 +18,7 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.FenceGateBlock; -@@ -138,9 +138,68 @@ +@@ -138,9 +138,67 @@ import net.minecraft.world.scores.ScoreHolder; import net.minecraft.world.scores.Team; import org.slf4j.Logger; @@ -33,7 +33,6 @@ +import org.bukkit.entity.Hanging; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Vehicle; -+import org.spigotmc.CustomTimingsHandler; // Spigot +import org.bukkit.event.entity.EntityCombustByEntityEvent; +import org.bukkit.event.hanging.HangingBreakByEntityEvent; +import org.bukkit.event.vehicle.VehicleBlockCollisionEvent; @@ -87,7 +86,7 @@ private static final Logger LOGGER = LogUtils.getLogger(); public static final String ID_TAG = "id"; public static final String PASSENGERS_TAG = "Passengers"; -@@ -224,7 +283,7 @@ +@@ -224,7 +282,7 @@ private static final EntityDataAccessor DATA_CUSTOM_NAME_VISIBLE = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.BOOLEAN); private static final EntityDataAccessor DATA_SILENT = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.BOOLEAN); private static final EntityDataAccessor DATA_NO_GRAVITY = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.BOOLEAN); @@ -96,7 +95,7 @@ private static final EntityDataAccessor DATA_TICKS_FROZEN = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.INT); private EntityInLevelCallback levelCallback; private final VecDeltaCodec packetPositionCodec; -@@ -253,6 +312,42 @@ +@@ -253,6 +311,41 @@ private final List movementThisTick; private final Set blocksInside; private final LongSet visitedBlocks; @@ -115,7 +114,6 @@ + // Marks an entity, that it was removed by a plugin via Entity#remove + // Main use case currently is for SPIGOT-7487, preventing dropping of leash when leash is removed + public boolean pluginRemoved = false; -+ public CustomTimingsHandler tickTimer = org.bukkit.craftbukkit.SpigotTimings.getEntityTimings(this); // Spigot + // Spigot start + public final org.spigotmc.ActivationRange.ActivationType activationType = org.spigotmc.ActivationRange.initializeEntityActivationType(this); + public final boolean defaultActivationState; @@ -139,7 +137,7 @@ public Entity(EntityType type, Level world) { this.id = Entity.ENTITY_COUNTER.incrementAndGet(); -@@ -284,6 +379,13 @@ +@@ -284,6 +377,13 @@ this.position = Vec3.ZERO; this.blockPosition = BlockPos.ZERO; this.chunkPosition = ChunkPos.ZERO; @@ -153,7 +151,7 @@ SynchedEntityData.Builder datawatcher_a = new SynchedEntityData.Builder(this); datawatcher_a.define(Entity.DATA_SHARED_FLAGS_ID, (byte) 0); -@@ -292,7 +394,7 @@ +@@ -292,7 +392,7 @@ datawatcher_a.define(Entity.DATA_CUSTOM_NAME, Optional.empty()); datawatcher_a.define(Entity.DATA_SILENT, false); datawatcher_a.define(Entity.DATA_NO_GRAVITY, false); @@ -162,7 +160,7 @@ datawatcher_a.define(Entity.DATA_TICKS_FROZEN, 0); this.defineSynchedData(datawatcher_a); this.entityData = datawatcher_a.build(); -@@ -362,20 +464,36 @@ +@@ -362,20 +462,36 @@ } public void kill(ServerLevel world) { @@ -201,7 +199,7 @@ public boolean equals(Object object) { return object instanceof Entity ? ((Entity) object).id == this.id : false; } -@@ -385,22 +503,34 @@ +@@ -385,22 +501,34 @@ } public void remove(Entity.RemovalReason reason) { @@ -241,7 +239,7 @@ return this.getPose() == pose; } -@@ -417,6 +547,33 @@ +@@ -417,6 +545,33 @@ } public void setRot(float yaw, float pitch) { @@ -275,7 +273,7 @@ this.setYRot(yaw % 360.0F); this.setXRot(pitch % 360.0F); } -@@ -462,6 +619,15 @@ +@@ -462,6 +617,15 @@ this.baseTick(); } @@ -291,7 +289,7 @@ public void baseTick() { ProfilerFiller gameprofilerfiller = Profiler.get(); -@@ -475,7 +641,7 @@ +@@ -475,7 +639,7 @@ --this.boardingCooldown; } @@ -300,7 +298,7 @@ if (this.canSpawnSprintParticle()) { this.spawnSprintParticle(); } -@@ -514,6 +680,10 @@ +@@ -514,6 +678,10 @@ if (this.isInLava()) { this.lavaHurt(); this.fallDistance *= 0.5F; @@ -311,7 +309,7 @@ } this.checkBelowWorld(); -@@ -525,7 +695,7 @@ +@@ -525,7 +693,7 @@ world = this.level(); if (world instanceof ServerLevel worldserver) { if (this instanceof Leashable) { @@ -320,7 +318,7 @@ } } -@@ -568,15 +738,32 @@ +@@ -568,15 +736,32 @@ public void lavaHurt() { if (!this.fireImmune()) { @@ -355,7 +353,7 @@ } } -@@ -587,9 +774,25 @@ +@@ -587,9 +772,25 @@ } public final void igniteForSeconds(float seconds) { @@ -382,7 +380,7 @@ public void igniteForTicks(int ticks) { if (this.remainingFireTicks < ticks) { this.setRemainingFireTicks(ticks); -@@ -610,7 +813,7 @@ +@@ -610,7 +811,7 @@ } protected void onBelowWorld() { @@ -391,21 +389,10 @@ } public boolean isFree(double offsetX, double offsetY, double offsetZ) { -@@ -672,6 +875,7 @@ - } +@@ -750,6 +951,28 @@ + } + } - public void move(MoverType type, Vec3 movement) { -+ org.bukkit.craftbukkit.SpigotTimings.entityMoveTimer.startTiming(); // Spigot - if (this.noPhysics) { - this.setPos(this.getX() + movement.x, this.getY() + movement.y, this.getZ() + movement.z); - } else { -@@ -747,8 +951,30 @@ - - if (movement.y != vec3d1.y) { - block.updateEntityMovementAfterFallOn(this.level(), this); -+ } -+ } -+ + // CraftBukkit start + if (this.horizontalCollision && this.getBukkitEntity() instanceof Vehicle) { + Vehicle vehicle = (Vehicle) this.getBukkitEntity(); @@ -419,26 +406,19 @@ + bl = bl.getRelative(BlockFace.SOUTH); + } else if (movement.z < vec3d1.z) { + bl = bl.getRelative(BlockFace.NORTH); - } ++ } + + if (!bl.getType().isAir()) { + VehicleBlockCollisionEvent event = new VehicleBlockCollisionEvent(vehicle, bl); + this.level.getCraftServer().getPluginManager().callEvent(event); + } - } ++ } + // CraftBukkit end - ++ if (!this.level().isClientSide() || this.isControlledByLocalInstance()) { Entity.MovementEmission entity_movementemission = this.getMovementEmission(); -@@ -764,6 +990,7 @@ - gameprofilerfiller.pop(); - } - } -+ org.bukkit.craftbukkit.SpigotTimings.entityMoveTimer.stopTiming(); // Spigot - } - private void applyMovementEmissionAndPlaySound(Entity.MovementEmission moveEffect, Vec3 movement, BlockPos landingPos, BlockState landingState) { -@@ -1133,6 +1360,20 @@ +@@ -1133,6 +1356,20 @@ return SoundEvents.GENERIC_SPLASH; } @@ -459,7 +439,7 @@ public void recordMovementThroughBlocks(Vec3 oldPos, Vec3 newPos) { this.movementThisTick.add(new Entity.Movement(oldPos, newPos)); } -@@ -1609,6 +1850,7 @@ +@@ -1609,6 +1846,7 @@ this.yo = y; this.zo = d4; this.setPos(d3, y, d4); @@ -467,7 +447,7 @@ } public void moveTo(Vec3 pos) { -@@ -1861,6 +2103,12 @@ +@@ -1861,6 +2099,12 @@ return false; } @@ -480,7 +460,7 @@ public void awardKillScore(Entity entityKilled, DamageSource damageSource) { if (entityKilled instanceof ServerPlayer) { CriteriaTriggers.ENTITY_KILLED_PLAYER.trigger((ServerPlayer) entityKilled, this, damageSource); -@@ -1889,16 +2137,22 @@ +@@ -1889,16 +2133,22 @@ } public boolean saveAsPassenger(CompoundTag nbt) { @@ -506,7 +486,7 @@ return true; } } -@@ -1909,54 +2163,98 @@ +@@ -1909,54 +2159,98 @@ } public CompoundTag saveWithoutId(CompoundTag nbt) { @@ -625,7 +605,7 @@ } ListTag nbttaglist; -@@ -1972,10 +2270,10 @@ +@@ -1972,10 +2266,10 @@ nbttaglist.add(StringTag.valueOf(s)); } @@ -638,7 +618,7 @@ if (this.isVehicle()) { nbttaglist = new ListTag(); iterator = this.getPassengers().iterator(); -@@ -1984,17 +2282,22 @@ +@@ -1984,17 +2278,22 @@ Entity entity = (Entity) iterator.next(); CompoundTag nbttagcompound1 = new CompoundTag(); @@ -664,10 +644,11 @@ } catch (Throwable throwable) { CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT"); CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being saved"); -@@ -2080,6 +2383,50 @@ +@@ -2079,7 +2378,51 @@ + } } else { throw new IllegalStateException("Entity has invalid position"); - } ++ } + + // CraftBukkit start + // Spigot start @@ -703,7 +684,7 @@ + } + + ((ServerPlayer) this).setLevel(bworld == null ? null : ((CraftWorld) bworld).getHandle()); -+ } + } + this.getBukkitEntity().readBukkitValues(nbt); + if (nbt.contains("Bukkit.invisible")) { + boolean bukkitInvisible = nbt.getBoolean("Bukkit.invisible"); @@ -715,7 +696,7 @@ } catch (Throwable throwable) { CrashReport crashreport = CrashReport.forThrowable(throwable, "Loading entity NBT"); CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being loaded"); -@@ -2101,6 +2448,12 @@ +@@ -2101,6 +2444,12 @@ return entitytypes.canSerialize() && minecraftkey != null ? minecraftkey.toString() : null; } @@ -728,7 +709,7 @@ protected abstract void readAdditionalSaveData(CompoundTag nbt); protected abstract void addAdditionalSaveData(CompoundTag nbt); -@@ -2153,9 +2506,22 @@ +@@ -2153,9 +2502,22 @@ if (stack.isEmpty()) { return null; } else { @@ -751,7 +732,7 @@ world.addFreshEntity(entityitem); return entityitem; } -@@ -2184,6 +2550,12 @@ +@@ -2184,6 +2546,12 @@ if (this.isAlive() && this instanceof Leashable leashable) { if (leashable.getLeashHolder() == player) { if (!this.level().isClientSide()) { @@ -764,7 +745,7 @@ if (player.hasInfiniteMaterials()) { leashable.removeLeash(); } else { -@@ -2200,6 +2572,13 @@ +@@ -2200,6 +2568,13 @@ if (itemstack.is(Items.LEAD) && leashable.canHaveALeashAttachedToIt()) { if (!this.level().isClientSide()) { @@ -778,7 +759,7 @@ leashable.setLeashedTo(player, true); } -@@ -2265,7 +2644,7 @@ +@@ -2265,7 +2640,7 @@ } public boolean showVehicleHealth() { @@ -787,7 +768,7 @@ } public boolean startRiding(Entity entity, boolean force) { -@@ -2273,7 +2652,7 @@ +@@ -2273,7 +2648,7 @@ return false; } else if (!entity.couldAcceptPassenger()) { return false; @@ -796,7 +777,7 @@ return false; } else { for (Entity entity1 = entity; entity1.vehicle != null; entity1 = entity1.vehicle) { -@@ -2285,11 +2664,32 @@ +@@ -2285,11 +2660,32 @@ if (!force && (!this.canRide(entity) || !entity.canAddPassenger(this))) { return false; } else { @@ -830,7 +811,7 @@ this.vehicle = entity; this.vehicle.addPassenger(this); entity.getIndirectPassengersStream().filter((entity2) -> { -@@ -2318,7 +2718,7 @@ +@@ -2318,7 +2714,7 @@ Entity entity = this.vehicle; this.vehicle = null; @@ -839,7 +820,7 @@ } } -@@ -2349,21 +2749,50 @@ +@@ -2349,21 +2745,50 @@ } } @@ -896,7 +877,7 @@ } protected boolean canAddPassenger(Entity passenger) { -@@ -2464,7 +2893,7 @@ +@@ -2464,7 +2889,7 @@ if (teleporttransition != null) { ServerLevel worldserver1 = teleporttransition.newLevel(); @@ -905,7 +886,7 @@ this.teleport(teleporttransition); } } -@@ -2547,7 +2976,7 @@ +@@ -2547,7 +2972,7 @@ } public boolean isCrouching() { @@ -914,7 +895,7 @@ } public boolean isSprinting() { -@@ -2563,7 +2992,7 @@ +@@ -2563,7 +2988,7 @@ } public boolean isVisuallySwimming() { @@ -923,7 +904,7 @@ } public boolean isVisuallyCrawling() { -@@ -2571,6 +3000,13 @@ +@@ -2571,6 +2996,13 @@ } public void setSwimming(boolean swimming) { @@ -937,7 +918,7 @@ this.setSharedFlag(4, swimming); } -@@ -2624,8 +3060,12 @@ +@@ -2624,8 +3056,12 @@ return this.getTeam() != null ? this.getTeam().isAlliedTo(team) : false; } @@ -951,7 +932,7 @@ } public boolean getSharedFlag(int index) { -@@ -2644,7 +3084,7 @@ +@@ -2644,7 +3080,7 @@ } public int getMaxAirSupply() { @@ -960,7 +941,7 @@ } public int getAirSupply() { -@@ -2652,7 +3092,18 @@ +@@ -2652,7 +3088,18 @@ } public void setAirSupply(int air) { @@ -980,7 +961,7 @@ } public int getTicksFrozen() { -@@ -2679,11 +3130,40 @@ +@@ -2679,11 +3126,40 @@ public void thunderHit(ServerLevel world, LightningBolt lightning) { this.setRemainingFireTicks(this.remainingFireTicks + 1); @@ -1023,7 +1004,7 @@ } public void onAboveBubbleCol(boolean drag) { -@@ -2713,7 +3193,7 @@ +@@ -2713,7 +3189,7 @@ this.resetFallDistance(); } @@ -1032,7 +1013,7 @@ return true; } -@@ -2852,6 +3332,18 @@ +@@ -2852,6 +3328,18 @@ if (world instanceof ServerLevel worldserver) { if (!this.isRemoved()) { @@ -1051,7 +1032,7 @@ ServerLevel worldserver1 = teleportTarget.newLevel(); boolean flag = worldserver1.dimension() != worldserver.dimension(); -@@ -2920,8 +3412,12 @@ +@@ -2920,8 +3408,12 @@ } else { entity.restoreFrom(this); this.removeAfterChangingDimensions(); @@ -1065,7 +1046,7 @@ Iterator iterator1 = list1.iterator(); while (iterator1.hasNext()) { -@@ -2947,7 +3443,7 @@ +@@ -2947,7 +3439,7 @@ } private void sendTeleportTransitionToRidingPlayers(TeleportTransition teleportTarget) { @@ -1074,7 +1055,7 @@ Iterator iterator = this.getIndirectPassengers().iterator(); while (iterator.hasNext()) { -@@ -2995,8 +3491,9 @@ +@@ -2995,8 +3487,9 @@ } protected void removeAfterChangingDimensions() { @@ -1085,7 +1066,7 @@ leashable.removeLeash(); } -@@ -3006,6 +3503,20 @@ +@@ -3006,6 +3499,20 @@ return PortalShape.getRelativePosition(portalRect, portalAxis, this.position(), this.getDimensions(this.getPose())); } @@ -1106,7 +1087,7 @@ public boolean canUsePortal(boolean allowVehicles) { return (allowVehicles || !this.isPassenger()) && this.isAlive(); } -@@ -3134,9 +3645,15 @@ +@@ -3134,10 +3641,16 @@ return (Boolean) this.entityData.get(Entity.DATA_CUSTOM_NAME_VISIBLE); } @@ -1117,15 +1098,16 @@ + public final boolean teleportTo(ServerLevel world, double destX, double destY, double destZ, Set flags, float yaw, float pitch, boolean resetCamera) { + return this.teleportTo(world, destX, destY, destZ, flags, yaw, pitch, resetCamera, PlayerTeleportEvent.TeleportCause.UNKNOWN); + } -+ + + public boolean teleportTo(ServerLevel worldserver, double d0, double d1, double d2, Set set, float f, float f1, boolean flag, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause) { + float f2 = Mth.clamp(f1, -90.0F, 90.0F); + Entity entity = this.teleport(new TeleportTransition(worldserver, new Vec3(d0, d1, d2), Vec3.ZERO, f, f2, set, TeleportTransition.DO_NOTHING, cause)); + // CraftBukkit end - ++ return entity != null; } -@@ -3187,7 +3704,7 @@ + +@@ -3187,7 +3700,7 @@ /** @deprecated */ @Deprecated protected void fixupDimensions() { @@ -1134,7 +1116,7 @@ EntityDimensions entitysize = this.getDimensions(entitypose); this.dimensions = entitysize; -@@ -3196,7 +3713,7 @@ +@@ -3196,7 +3709,7 @@ public void refreshDimensions() { EntityDimensions entitysize = this.dimensions; @@ -1143,7 +1125,7 @@ EntityDimensions entitysize1 = this.getDimensions(entitypose); this.dimensions = entitysize1; -@@ -3258,10 +3775,29 @@ +@@ -3258,10 +3771,29 @@ } public final void setBoundingBox(AABB boundingBox) { @@ -1175,7 +1157,7 @@ return this.getDimensions(pose).eyeHeight(); } -@@ -3335,7 +3871,7 @@ +@@ -3335,7 +3867,7 @@ } @Nullable @@ -1184,7 +1166,7 @@ return null; } -@@ -3435,7 +3971,7 @@ +@@ -3435,7 +3967,7 @@ } public boolean isControlledByLocalInstance() { @@ -1193,7 +1175,7 @@ if (entityliving instanceof Player entityhuman) { return entityhuman.isLocalPlayer(); -@@ -3445,7 +3981,7 @@ +@@ -3445,7 +3977,7 @@ } public boolean isControlledByClient() { @@ -1202,7 +1184,7 @@ return entityliving != null && entityliving.isControlledByClient(); } -@@ -3463,7 +3999,7 @@ +@@ -3463,7 +3995,7 @@ return new Vec3((double) f1 * d2 / (double) f3, 0.0D, (double) f2 * d2 / (double) f3); } @@ -1211,7 +1193,7 @@ return new Vec3(this.getX(), this.getBoundingBox().maxY, this.getZ()); } -@@ -3489,8 +4025,37 @@ +@@ -3489,8 +4021,37 @@ return 1; } @@ -1250,7 +1232,7 @@ } public void lookAt(EntityAnchorArgument.Anchor anchorPoint, Vec3 target) { -@@ -3550,7 +4115,12 @@ +@@ -3550,7 +4111,12 @@ vec3d = vec3d.add(vec3d1); ++k1; @@ -1263,7 +1245,7 @@ } } } -@@ -3613,7 +4183,7 @@ +@@ -3613,7 +4179,7 @@ return new ClientboundAddEntityPacket(this, entityTrackerEntry); } @@ -1272,7 +1254,7 @@ return this.type.getDimensions(); } -@@ -3818,8 +4388,16 @@ +@@ -3818,8 +4384,16 @@ @Override public final void setRemoved(Entity.RemovalReason reason) { @@ -1290,7 +1272,7 @@ } if (this.removalReason.shouldDestroy()) { -@@ -3827,8 +4405,8 @@ +@@ -3827,8 +4401,8 @@ } this.getPassengers().forEach(Entity::stopRiding); @@ -1301,7 +1283,7 @@ } public void unsetRemoved() { -@@ -3887,7 +4465,7 @@ +@@ -3887,7 +4461,7 @@ } public Vec3 getKnownMovement() { diff --git a/paper-server/patches/sources/net/minecraft/world/entity/LivingEntity.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/LivingEntity.java.patch index 6d0f489e930..6982e80b6ce 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/LivingEntity.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/LivingEntity.java.patch @@ -17,11 +17,10 @@ import net.minecraft.world.entity.projectile.AbstractArrow; import net.minecraft.world.entity.projectile.Projectile; import net.minecraft.world.item.AxeItem; -@@ -135,6 +136,32 @@ - import net.minecraft.world.scores.PlayerTeam; +@@ -136,6 +137,30 @@ import net.minecraft.world.scores.Scoreboard; import org.slf4j.Logger; -+ + +// CraftBukkit start +import java.util.ArrayList; +import java.util.HashSet; @@ -46,11 +45,10 @@ +import org.bukkit.event.player.PlayerItemConsumeEvent; +// CraftBukkit end + -+import org.bukkit.craftbukkit.SpigotTimings; // Spigot - public abstract class LivingEntity extends Entity implements Attackable { -@@ -174,7 +201,7 @@ + private static final Logger LOGGER = LogUtils.getLogger(); +@@ -174,7 +199,7 @@ public static final float DEFAULT_BABY_SCALE = 0.5F; public static final String ATTRIBUTES_FIELD = "attributes"; public static final Predicate PLAYER_NOT_WEARING_DISGUISE_ITEM = (entityliving) -> { @@ -59,7 +57,7 @@ ItemStack itemstack = entityhuman.getItemBySlot(EquipmentSlot.HEAD); return !itemstack.is(ItemTags.GAZE_DISGUISE_EQUIPMENT); -@@ -210,7 +237,7 @@ +@@ -210,7 +235,7 @@ public float yHeadRotO; public final ElytraAnimationState elytraAnimationState; @Nullable @@ -68,7 +66,7 @@ public int lastHurtByPlayerTime; protected boolean dead; protected int noActionTime; -@@ -260,6 +287,27 @@ +@@ -260,7 +285,28 @@ protected boolean skipDropExperience; private final EnumMap>> activeLocationDependentEnchantments; protected float appliedScale; @@ -80,7 +78,7 @@ + public Set collidableExemptions = new HashSet<>(); + public boolean bukkitPickUpLoot; + public org.bukkit.craftbukkit.entity.CraftLivingEntity getBukkitLivingEntity() { return (org.bukkit.craftbukkit.entity.CraftLivingEntity) super.getBukkitEntity(); } // Paper -+ + + @Override + public float getBukkitYaw() { + return this.getYHeadRot(); @@ -93,10 +91,11 @@ + ++this.noActionTime; // Above all the floats + } + // Spigot end - ++ protected LivingEntity(EntityType type, Level world) { super(type, world); -@@ -276,7 +324,9 @@ + this.lastHandItemStacks = NonNullList.withSize(2, ItemStack.EMPTY); +@@ -276,7 +322,9 @@ this.activeLocationDependentEnchantments = new EnumMap(EquipmentSlot.class); this.appliedScale = 1.0F; this.attributes = new AttributeMap(DefaultAttributes.getSupplier(type)); @@ -107,7 +106,7 @@ this.blocksBuilding = true; this.rotA = (float) ((Math.random() + 1.0D) * 0.009999999776482582D); this.reapplyPosition(); -@@ -356,7 +406,13 @@ +@@ -356,7 +404,13 @@ double d8 = Math.min((double) (0.2F + f / 15.0F), 2.5D); int i = (int) (150.0D * d8); @@ -122,7 +121,7 @@ } } } -@@ -402,7 +458,7 @@ +@@ -402,7 +456,7 @@ } if (this.isAlive()) { @@ -131,7 +130,7 @@ Level world1 = this.level(); ServerLevel worldserver1; double d0; -@@ -424,7 +480,7 @@ +@@ -424,7 +478,7 @@ } if (this.isEyeInFluid(FluidTags.WATER) && !this.level().getBlockState(BlockPos.containing(this.getX(), this.getEyeY(), this.getZ())).is(Blocks.BUBBLE_COLUMN)) { @@ -140,7 +139,7 @@ if (flag1) { this.setAirSupply(this.decreaseAirSupply(this.getAirSupply())); -@@ -573,7 +629,7 @@ +@@ -573,7 +627,7 @@ ++this.deathTime; if (this.deathTime >= 20 && !this.level().isClientSide() && !this.isRemoved()) { this.level().broadcastEntityEvent(this, (byte) 60); @@ -149,7 +148,7 @@ } } -@@ -629,7 +685,7 @@ +@@ -629,7 +683,7 @@ return this.lastHurtByMobTimestamp; } @@ -158,26 +157,25 @@ this.lastHurtByPlayer = attacking; this.lastHurtByPlayerTime = this.tickCount; } -@@ -679,17 +735,23 @@ +@@ -679,17 +733,23 @@ } public void onEquipItem(EquipmentSlot slot, ItemStack oldStack, ItemStack newStack) { - if (!this.level().isClientSide() && !this.isSpectator()) { - boolean flag = newStack.isEmpty() && oldStack.isEmpty(); -- -- if (!flag && !ItemStack.isSameItemSameComponents(oldStack, newStack) && !this.firstTick) { -- Equippable equippable = (Equippable) newStack.get(DataComponents.EQUIPPABLE); + // CraftBukkit start + this.onEquipItem(slot, oldStack, newStack, false); + } -- if (!this.isSilent() && equippable != null && slot == equippable.slot()) { -- this.level().playSeededSound((Player) null, this.getX(), this.getY(), this.getZ(), equippable.equipSound(), this.getSoundSource(), 1.0F, 1.0F, this.random.nextLong()); +- if (!flag && !ItemStack.isSameItemSameComponents(oldStack, newStack) && !this.firstTick) { +- Equippable equippable = (Equippable) newStack.get(DataComponents.EQUIPPABLE); + public void onEquipItem(EquipmentSlot enumitemslot, ItemStack itemstack, ItemStack itemstack1, boolean silent) { + // CraftBukkit end + if (!this.level().isClientSide() && !this.isSpectator()) { + boolean flag = itemstack1.isEmpty() && itemstack.isEmpty(); -+ + +- if (!this.isSilent() && equippable != null && slot == equippable.slot()) { +- this.level().playSeededSound((Player) null, this.getX(), this.getY(), this.getZ(), equippable.equipSound(), this.getSoundSource(), 1.0F, 1.0F, this.random.nextLong()); + if (!flag && !ItemStack.isSameItemSameComponents(itemstack, itemstack1) && !this.firstTick) { + Equippable equippable = (Equippable) itemstack1.get(DataComponents.EQUIPPABLE); + @@ -190,7 +188,7 @@ this.gameEvent(equippable != null ? GameEvent.EQUIP : GameEvent.UNEQUIP); } -@@ -699,17 +761,24 @@ +@@ -699,17 +759,24 @@ @Override public void remove(Entity.RemovalReason reason) { @@ -218,7 +216,7 @@ this.brain.clearMemories(); } -@@ -722,6 +791,7 @@ +@@ -722,6 +789,7 @@ mobeffect.onMobRemoved(world, this, reason); } @@ -226,7 +224,7 @@ this.activeEffects.clear(); } -@@ -781,6 +851,17 @@ +@@ -781,6 +849,17 @@ } } @@ -244,7 +242,7 @@ if (nbt.contains("Health", 99)) { this.setHealth(nbt.getFloat("Health")); } -@@ -819,9 +900,32 @@ +@@ -819,9 +898,32 @@ } @@ -277,7 +275,7 @@ try { while (iterator.hasNext()) { Holder holder = (Holder) iterator.next(); -@@ -831,6 +935,12 @@ +@@ -831,6 +933,12 @@ this.onEffectUpdated(mobeffect, true, (Entity) null); })) { if (!this.level().isClientSide) { @@ -290,7 +288,7 @@ iterator.remove(); this.onEffectsRemoved(List.of(mobeffect)); } -@@ -841,6 +951,17 @@ +@@ -841,6 +949,17 @@ } catch (ConcurrentModificationException concurrentmodificationexception) { ; } @@ -308,7 +306,7 @@ if (this.effectsDirty) { if (!this.level().isClientSide) { -@@ -921,7 +1042,7 @@ +@@ -921,7 +1040,7 @@ } public boolean canAttack(LivingEntity target) { @@ -317,7 +315,7 @@ } public boolean canBeSeenAsEnemy() { -@@ -952,17 +1073,36 @@ +@@ -952,17 +1071,36 @@ this.entityData.set(LivingEntity.DATA_EFFECT_PARTICLES, List.of()); } @@ -358,7 +356,7 @@ } } -@@ -987,24 +1127,55 @@ +@@ -987,24 +1125,55 @@ return this.addEffect(effect, (Entity) null); } @@ -422,7 +420,7 @@ return flag; } } -@@ -1031,14 +1202,40 @@ +@@ -1031,14 +1200,40 @@ return this.getType().is(EntityTypeTags.INVERTED_HEALING_AND_HARM); } @@ -465,7 +463,7 @@ if (mobeffect != null) { this.onEffectsRemoved(List.of(mobeffect)); return true; -@@ -1142,20 +1339,55 @@ +@@ -1142,20 +1337,55 @@ } @@ -522,7 +520,7 @@ this.entityData.set(LivingEntity.DATA_HEALTH_ID, Mth.clamp(health, 0.0F, this.getMaxHealth())); } -@@ -1167,7 +1399,7 @@ +@@ -1167,7 +1397,7 @@ public boolean hurtServer(ServerLevel world, DamageSource source, float amount) { if (this.isInvulnerableTo(world, source)) { return false; @@ -531,7 +529,7 @@ return false; } else if (source.is(DamageTypeTags.IS_FIRE) && this.hasEffect(MobEffects.FIRE_RESISTANCE)) { return false; -@@ -1182,10 +1414,11 @@ +@@ -1182,10 +1412,11 @@ } float f1 = amount; @@ -545,7 +543,7 @@ this.hurtCurrentlyUsedShield(amount); f2 = amount; amount = 0.0F; -@@ -1202,15 +1435,26 @@ +@@ -1202,15 +1433,26 @@ flag = true; } @@ -574,7 +572,7 @@ this.walkAnimation.setSpeed(1.5F); if (Float.isNaN(amount) || Float.isInfinite(amount)) { amount = Float.MAX_VALUE; -@@ -1218,18 +1462,27 @@ +@@ -1218,18 +1460,27 @@ boolean flag1 = true; @@ -606,7 +604,7 @@ this.hurtDuration = 10; this.hurtTime = this.hurtDuration; } -@@ -1243,7 +1496,7 @@ +@@ -1243,7 +1494,7 @@ world.broadcastDamageEvent(this, source); } @@ -615,7 +613,7 @@ this.markHurt(); } -@@ -1263,7 +1516,7 @@ +@@ -1263,7 +1514,7 @@ d1 = source.getSourcePosition().z() - this.getZ(); } @@ -624,7 +622,7 @@ if (!flag) { this.indicateDamage(d0, d1); } -@@ -1282,7 +1535,7 @@ +@@ -1282,7 +1533,7 @@ this.playHurtSound(source); } @@ -633,7 +631,7 @@ if (flag2) { this.lastDamageSource = source; -@@ -1329,10 +1582,10 @@ +@@ -1329,10 +1580,10 @@ } @Nullable @@ -646,7 +644,7 @@ this.lastHurtByPlayerTime = 100; this.lastHurtByPlayer = entityhuman; return entityhuman; -@@ -1342,8 +1595,8 @@ +@@ -1342,8 +1593,8 @@ this.lastHurtByPlayerTime = 100; LivingEntity entityliving = entitywolf.getOwner(); @@ -657,7 +655,7 @@ this.lastHurtByPlayer = entityhuman1; } else { -@@ -1363,7 +1616,7 @@ +@@ -1363,7 +1614,7 @@ } protected void blockedByShield(LivingEntity target) { @@ -666,7 +664,7 @@ } private boolean checkTotemDeathProtection(DamageSource source) { -@@ -1375,20 +1628,33 @@ +@@ -1375,20 +1626,33 @@ InteractionHand[] aenumhand = InteractionHand.values(); int i = aenumhand.length; @@ -704,7 +702,7 @@ ServerPlayer entityplayer = (ServerPlayer) this; entityplayer.awardStat(Stats.ITEM_USED.get(itemstack.getItem())); -@@ -1477,7 +1743,7 @@ +@@ -1477,7 +1741,7 @@ } if (!this.level().isClientSide && this.hasCustomName()) { @@ -713,7 +711,7 @@ } this.dead = true; -@@ -1512,14 +1778,22 @@ +@@ -1512,14 +1776,22 @@ BlockState iblockdata = Blocks.WITHER_ROSE.defaultBlockState(); if (this.level().getBlockState(blockposition).isAir() && iblockdata.canSurvive(this.level(), blockposition)) { @@ -738,7 +736,7 @@ this.level().addFreshEntity(entityitem); } } -@@ -1530,22 +1804,37 @@ +@@ -1530,24 +1802,39 @@ protected void dropAllDeathLoot(ServerLevel world, DamageSource damageSource) { boolean flag = this.lastHurtByPlayerTime > 0; @@ -768,8 +766,8 @@ } + return 0; // CraftBukkit -+ } -+ + } + + protected void dropExperience(ServerLevel world, @Nullable Entity attacker) { + // CraftBukkit start - Update getExpReward() above if the removed if() changes! + if (!(this instanceof net.minecraft.world.entity.boss.enderdragon.EnderDragon)) { // CraftBukkit - SPIGOT-2420: Special case ender dragon will drop the xp over time @@ -777,10 +775,12 @@ + this.expToDrop = 0; + } + // CraftBukkit end - } - ++ } ++ protected void dropCustomDeathLoot(ServerLevel world, DamageSource source, boolean causedByPlayer) {} -@@ -1612,19 +1901,31 @@ + + public long getLootTableSeed() { +@@ -1612,19 +1899,31 @@ } public void knockback(double strength, double x, double z) { @@ -819,7 +819,7 @@ } } -@@ -1683,6 +1984,20 @@ +@@ -1683,6 +1982,20 @@ return new LivingEntity.Fallsounds(SoundEvents.GENERIC_SMALL_FALL, SoundEvents.GENERIC_BIG_FALL); } @@ -840,7 +840,7 @@ public Optional getLastClimbablePos() { return this.lastClimbablePos; } -@@ -1757,9 +2072,14 @@ +@@ -1757,9 +2070,14 @@ int i = this.calculateFallDamage(fallDistance, damageMultiplier); if (i > 0) { @@ -856,7 +856,7 @@ return true; } else { return flag; -@@ -1830,7 +2150,7 @@ +@@ -1830,7 +2148,7 @@ protected float getDamageAfterArmorAbsorb(DamageSource source, float amount) { if (!source.is(DamageTypeTags.BYPASSES_ARMOR)) { @@ -865,7 +865,7 @@ amount = CombatRules.getDamageAfterAbsorb(this, amount, source, (float) this.getArmorValue(), (float) this.getAttributeValue(Attributes.ARMOR_TOUGHNESS)); } -@@ -1841,7 +2161,8 @@ +@@ -1841,7 +2159,8 @@ if (source.is(DamageTypeTags.BYPASSES_EFFECTS)) { return amount; } else { @@ -875,7 +875,7 @@ int i = (this.getEffect(MobEffects.DAMAGE_RESISTANCE).getAmplifier() + 1) * 5; int j = 25 - i; float f1 = amount * (float) j; -@@ -1884,18 +2205,144 @@ +@@ -1884,18 +2203,144 @@ } } @@ -902,7 +902,7 @@ + }; + float freezingModifier = freezing.apply((double) f).floatValue(); + f += freezingModifier; - ++ + com.google.common.base.Function hardHat = new com.google.common.base.Function() { + @Override + public Double apply(Double f) { @@ -923,7 +923,7 @@ + }; + float blockingModifier = blocking.apply((double) f).floatValue(); + f += blockingModifier; -+ + + com.google.common.base.Function armor = new com.google.common.base.Function() { + @Override + public Double apply(Double f) { @@ -1029,7 +1029,7 @@ if (entity instanceof ServerPlayer) { ServerPlayer entityplayer = (ServerPlayer) entity; -@@ -1904,13 +2351,48 @@ +@@ -1904,13 +2349,48 @@ } } @@ -1082,27 +1082,28 @@ } public CombatTracker getCombatTracker() { -@@ -1935,8 +2417,18 @@ +@@ -1935,9 +2415,19 @@ } public final void setArrowCount(int stuckArrowCount) { - this.entityData.set(LivingEntity.DATA_ARROW_COUNT_ID, stuckArrowCount); + // CraftBukkit start + this.setArrowCount(stuckArrowCount, false); -+ } -+ + } + + public final void setArrowCount(int i, boolean flag) { + ArrowBodyCountChangeEvent event = CraftEventFactory.callArrowBodyCountChangeEvent(this, this.getArrowCount(), i, flag); + if (event.isCancelled()) { + return; + } + this.entityData.set(LivingEntity.DATA_ARROW_COUNT_ID, event.getNewAmount()); - } ++ } + // CraftBukkit end - ++ public final int getStingerCount() { return (Integer) this.entityData.get(LivingEntity.DATA_STINGER_COUNT_ID); -@@ -1999,7 +2491,7 @@ + } +@@ -1999,7 +2489,7 @@ this.playSound(soundeffect, this.getSoundVolume(), (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F); } @@ -1111,7 +1112,7 @@ this.setHealth(0.0F); this.die(this.damageSources().generic()); } -@@ -2182,6 +2674,12 @@ +@@ -2182,6 +2672,12 @@ public abstract ItemStack getItemBySlot(EquipmentSlot slot); @@ -1124,7 +1125,7 @@ public abstract void setItemSlot(EquipmentSlot slot, ItemStack stack); public Iterable getHandSlots() { -@@ -2494,7 +2992,7 @@ +@@ -2494,7 +2990,7 @@ } @@ -1133,7 +1134,7 @@ Vec3 vec3d1 = this.getRiddenInput(controllingPlayer, movementInput); this.tickRidden(controllingPlayer, vec3d1); -@@ -2507,13 +3005,13 @@ +@@ -2507,13 +3003,13 @@ } @@ -1150,7 +1151,7 @@ return this.getSpeed(); } -@@ -2571,7 +3069,7 @@ +@@ -2571,7 +3067,7 @@ double d1 = Mth.clamp(motion.z, -0.15000000596046448D, 0.15000000596046448D); double d2 = Math.max(motion.y, -0.15000000596046448D); @@ -1159,7 +1160,7 @@ d2 = 0.0D; } -@@ -2586,7 +3084,7 @@ +@@ -2586,7 +3082,7 @@ } protected float getFlyingSpeed() { @@ -1168,15 +1169,7 @@ } public float getSpeed() { -@@ -2604,6 +3102,7 @@ - - @Override - public void tick() { -+ SpigotTimings.timerEntityBaseTick.startTiming(); // Spigot - super.tick(); - this.updatingUsingItem(); - this.updateSwimAmount(); -@@ -2634,7 +3133,7 @@ +@@ -2634,7 +3130,7 @@ } } @@ -1185,21 +1178,8 @@ if (this.tickCount % 20 == 0) { this.getCombatTracker().recheckStatus(); } -@@ -2645,7 +3144,9 @@ - } - - if (!this.isRemoved()) { -+ SpigotTimings.timerEntityBaseTick.stopTiming(); // Spigot - this.aiStep(); -+ SpigotTimings.timerEntityTickRest.startTiming(); // Spigot - } - - double d0 = this.getX() - this.xo; -@@ -2739,9 +3240,10 @@ - } - +@@ -2741,7 +3237,7 @@ this.elytraAnimationState.tick(); -+ SpigotTimings.timerEntityTickRest.stopTiming(); // Spigot } - public void detectEquipmentUpdates() { @@ -1207,28 +1187,7 @@ Map map = this.collectEquipmentChanges(); if (map != null) { -@@ -2945,6 +3447,7 @@ - ProfilerFiller gameprofilerfiller = Profiler.get(); - - gameprofilerfiller.push("ai"); -+ SpigotTimings.timerEntityAI.startTiming(); // Spigot - if (this.isImmobile()) { - this.jumping = false; - this.xxa = 0.0F; -@@ -2954,6 +3457,7 @@ - this.serverAiStep(); - gameprofilerfiller.pop(); - } -+ SpigotTimings.timerEntityAI.stopTiming(); // Spigot - - gameprofilerfiller.pop(); - gameprofilerfiller.push("jump"); -@@ -2996,11 +3500,12 @@ - this.resetFallDistance(); - } - -+ SpigotTimings.timerEntityAIMove.startTiming(); // Spigot - label112: +@@ -3000,7 +3496,7 @@ { LivingEntity entityliving = this.getControllingPassenger(); @@ -1237,25 +1196,7 @@ if (this.isAlive()) { this.travelRidden(entityhuman, vec3d1); break label112; -@@ -3009,6 +3514,7 @@ - - this.travel(vec3d1); - } -+ SpigotTimings.timerEntityAIMove.stopTiming(); // Spigot - - if (!this.level().isClientSide() || this.isControlledByLocalInstance()) { - this.applyEffectsFromBlocks(); -@@ -3044,7 +3550,9 @@ - this.checkAutoSpinAttack(axisalignedbb, this.getBoundingBox()); - } - -+ SpigotTimings.timerEntityAICollision.startTiming(); // Spigot - this.pushEntities(); -+ SpigotTimings.timerEntityAICollision.stopTiming(); // Spigot - gameprofilerfiller.pop(); - world = this.level(); - if (world instanceof ServerLevel worldserver) { -@@ -3063,6 +3571,7 @@ +@@ -3063,6 +3559,7 @@ this.checkSlowFallDistance(); if (!this.level().isClientSide) { if (!this.canGlide()) { @@ -1263,7 +1204,7 @@ this.setSharedFlag(7, false); return; } -@@ -3113,7 +3622,7 @@ +@@ -3113,7 +3610,7 @@ Level world = this.level(); if (!(world instanceof ServerLevel worldserver)) { @@ -1272,7 +1213,7 @@ } else { List list = this.level().getEntities((Entity) this, this.getBoundingBox(), EntitySelector.pushableBy(this)); -@@ -3305,15 +3814,22 @@ +@@ -3305,15 +3802,22 @@ @Override public boolean isPickable() { @@ -1297,7 +1238,7 @@ public float getYHeadRot() { return this.yHeadRot; } -@@ -3483,8 +3999,31 @@ +@@ -3483,8 +3987,31 @@ this.releaseUsingItem(); } else { if (!this.useItem.isEmpty() && this.isUsingItem()) { @@ -1309,7 +1250,7 @@ + org.bukkit.inventory.EquipmentSlot hand = org.bukkit.craftbukkit.CraftEquipmentSlot.getHand(enumhand); + PlayerItemConsumeEvent event = new PlayerItemConsumeEvent((Player) this.getBukkitEntity(), craftItem, hand); + this.level().getCraftServer().getPluginManager().callEvent(event); -+ + + if (event.isCancelled()) { + // Update client + Consumable consumable = this.useItem.get(DataComponents.CONSUMABLE); @@ -1320,7 +1261,7 @@ + entityPlayer.getBukkitEntity().updateScaledHealth(); + return; + } - ++ + itemstack = (craftItem.equals(event.getItem())) ? this.useItem.finishUsingItem(this.level(), this) : CraftItemStack.asNMSCopy(event.getItem()).finishUsingItem(this.level(), this); + } else { + itemstack = this.useItem.finishUsingItem(this.level(), this); @@ -1330,7 +1271,7 @@ if (itemstack != this.useItem) { this.setItemInHand(enumhand, itemstack); } -@@ -3568,12 +4107,18 @@ +@@ -3568,12 +4095,18 @@ } public boolean randomTeleport(double x, double y, double z, boolean particleEffects) { @@ -1351,7 +1292,7 @@ Level world = this.level(); if (world.hasChunkAt(blockposition)) { -@@ -3592,18 +4137,43 @@ +@@ -3592,18 +4125,43 @@ } if (flag2) { @@ -1399,7 +1340,7 @@ world.broadcastEntityEvent(this, (byte) 46); } -@@ -3613,7 +4183,7 @@ +@@ -3613,7 +4171,7 @@ entitycreature.getNavigation().stop(); } @@ -1408,7 +1349,7 @@ } } -@@ -3706,7 +4276,7 @@ +@@ -3706,7 +4264,7 @@ } public void stopSleeping() { @@ -1417,7 +1358,7 @@ Level world = this.level(); java.util.Objects.requireNonNull(world); -@@ -3718,9 +4288,9 @@ +@@ -3718,9 +4276,9 @@ this.level().setBlock(blockposition, (BlockState) iblockdata.setValue(BedBlock.OCCUPIED, false), 3); Vec3 vec3d = (Vec3) BedBlock.findStandUpPosition(this.getType(), this.level(), blockposition, enumdirection, this.getYRot()).orElseGet(() -> { @@ -1429,7 +1370,7 @@ }); Vec3 vec3d1 = Vec3.atBottomCenterOf(blockposition).subtract(vec3d).normalize(); float f = (float) Mth.wrapDegrees(Mth.atan2(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D); -@@ -3740,7 +4310,7 @@ +@@ -3740,7 +4298,7 @@ @Nullable public Direction getBedOrientation() { @@ -1438,7 +1379,7 @@ return blockposition != null ? BedBlock.getBedOrientation(this.level(), blockposition) : null; } -@@ -3905,7 +4475,7 @@ +@@ -3905,7 +4463,7 @@ public float maxUpStep() { float f = (float) this.getAttributeValue(Attributes.STEP_HEIGHT); diff --git a/paper-server/patches/sources/net/minecraft/world/level/Level.java.patch b/paper-server/patches/sources/net/minecraft/world/level/Level.java.patch index e5e0633fcb7..0252c7c6350 100644 --- a/paper-server/patches/sources/net/minecraft/world/level/Level.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/Level.java.patch @@ -31,7 +31,7 @@ import net.minecraft.world.level.entity.EntityTypeTest; import net.minecraft.world.level.entity.LevelEntityGetter; import net.minecraft.world.level.gameevent.GameEvent; -@@ -81,6 +85,26 @@ +@@ -81,6 +85,25 @@ import net.minecraft.world.phys.Vec3; import net.minecraft.world.scores.Scoreboard; @@ -46,7 +46,6 @@ +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.CraftWorld; -+import org.bukkit.craftbukkit.SpigotTimings; // Spigot +import org.bukkit.craftbukkit.block.CapturedBlockState; +import org.bukkit.craftbukkit.block.CraftBlockState; +import org.bukkit.craftbukkit.block.data.CraftBlockData; @@ -58,7 +57,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { public static final Codec> RESOURCE_KEY_CODEC = ResourceKey.codec(Registries.DIMENSION); -@@ -121,23 +145,73 @@ +@@ -121,23 +144,72 @@ private final DamageSources damageSources; private long subTickCount; @@ -89,7 +88,6 @@ + } + // Paper end - add paper world config + -+ public final SpigotTimings.WorldTimingsHandler timings; // Spigot + public static BlockPos lastPhysicsProblem; // Spigot + private org.spigotmc.TickLimiter entityLimiter; + private org.spigotmc.TickLimiter tileLimiter; @@ -141,7 +139,7 @@ } }; } else { -@@ -145,11 +219,50 @@ +@@ -145,11 +217,49 @@ } this.thread = Thread.currentThread(); @@ -191,13 +189,12 @@ + public void onBorderSetDamageSafeZOne(WorldBorder border, double safeZoneRadius) {} + }); + // CraftBukkit end -+ this.timings = new SpigotTimings.WorldTimingsHandler(this); // Spigot - code below can generate new world and access timings + this.entityLimiter = new org.spigotmc.TickLimiter(this.spigotConfig.entityMaxTickTime); + this.tileLimiter = new org.spigotmc.TickLimiter(this.spigotConfig.tileMaxTickTime); } @Override -@@ -163,6 +276,13 @@ +@@ -163,6 +273,13 @@ return null; } @@ -211,7 +208,7 @@ public boolean isInWorldBounds(BlockPos pos) { return !this.isOutsideBuildHeight(pos) && Level.isInWorldBoundsHorizontal(pos); } -@@ -179,18 +299,52 @@ +@@ -179,18 +296,52 @@ return y < -20000000 || y >= 20000000; } @@ -229,7 +226,7 @@ + // Paper start - if loaded @Nullable - @Override ++ @Override + public final ChunkAccess getChunkIfLoadedImmediately(int x, int z) { + return ((ServerLevel)this).chunkSource.getChunkAtIfLoadedImmediately(x, z); + } @@ -261,13 +258,13 @@ + return chunk == null ? null : chunk.getFluidState(blockposition); + } + -+ @Override + @Override public ChunkAccess getChunk(int chunkX, int chunkZ, ChunkStatus leastStatus, boolean create) { + // Paper end ChunkAccess ichunkaccess = this.getChunkSource().getChunk(chunkX, chunkZ, leastStatus, create); if (ichunkaccess == null && create) { -@@ -207,6 +361,18 @@ +@@ -207,6 +358,18 @@ @Override public boolean setBlock(BlockPos pos, BlockState state, int flags, int maxUpdateDepth) { @@ -286,7 +283,7 @@ if (this.isOutsideBuildHeight(pos)) { return false; } else if (!this.isClientSide && this.isDebug()) { -@@ -214,44 +380,123 @@ +@@ -214,44 +377,123 @@ } else { LevelChunk chunk = this.getChunkAt(pos); Block block = state.getBlock(); @@ -386,14 +383,14 @@ + + if ((i & 2) != 0 && (!this.isClientSide || (i & 4) == 0) && (this.isClientSide || chunk == null || (chunk.getFullStatus() != null && chunk.getFullStatus().isOrAfter(FullChunkStatus.BLOCK_TICKING)))) { // allow chunk to be null here as chunk.isReady() is false when we send our notification during block placement + this.sendBlockUpdated(blockposition, iblockdata1, iblockdata, i); -+ } + } + + if ((i & 1) != 0) { + this.blockUpdated(blockposition, iblockdata1.getBlock()); + if (!this.isClientSide && iblockdata.hasAnalogOutputSignal()) { + this.updateNeighbourForOutputSignal(blockposition, newBlock.getBlock()); + } - } ++ } + + if ((i & 16) == 0 && j > 0) { + int k = i & -34; @@ -425,7 +422,7 @@ public void onBlockStateChange(BlockPos pos, BlockState oldBlock, BlockState newBlock) {} -@@ -340,10 +585,18 @@ +@@ -340,10 +582,18 @@ @Override public BlockState getBlockState(BlockPos pos) { @@ -445,20 +442,11 @@ return chunk.getBlockState(pos); } -@@ -440,32 +693,48 @@ - ProfilerFiller gameprofilerfiller = Profiler.get(); - - gameprofilerfiller.push("blockEntities"); -+ this.timings.tileEntityPending.startTiming(); // Spigot - this.tickingBlockEntities = true; - if (!this.pendingBlockEntityTickers.isEmpty()) { - this.blockEntityTickers.addAll(this.pendingBlockEntityTickers); +@@ -446,14 +696,23 @@ this.pendingBlockEntityTickers.clear(); } -+ this.timings.tileEntityPending.stopTiming(); // Spigot - Iterator iterator = this.blockEntityTickers.iterator(); -+ this.timings.tileEntityTick.startTiming(); // Spigot + // Spigot start + // Iterator iterator = this.blockEntityTickers.iterator(); boolean flag = this.tickRateManager().runsNormally(); @@ -482,31 +470,23 @@ } else if (flag && this.shouldTickBlocksAt(tickingblockentity.getPos())) { tickingblockentity.tick(); } - } +@@ -461,6 +720,7 @@ -+ this.timings.tileEntityTick.stopTiming(); // Spigot this.tickingBlockEntities = false; gameprofilerfiller.pop(); + this.spigotConfig.currentPrimedTnt = 0; // Spigot } public void guardEntityTick(Consumer tickConsumer, T entity) { - try { -+ SpigotTimings.tickEntityTimer.startTiming(); // Spigot - tickConsumer.accept(entity); -+ SpigotTimings.tickEntityTimer.stopTiming(); // Spigot - } catch (Throwable throwable) { - CrashReport crashreport = CrashReport.forThrowable(throwable, "Ticking entity"); - CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being ticked"); -@@ -510,13 +779,29 @@ +@@ -510,13 +770,29 @@ @Nullable @Override public BlockEntity getBlockEntity(BlockPos pos) { - return this.isOutsideBuildHeight(pos) ? null : (!this.isClientSide && Thread.currentThread() != this.thread ? null : this.getChunkAt(pos).getBlockEntity(pos, LevelChunk.EntityCreationType.IMMEDIATE)); + // CraftBukkit start + return this.getBlockEntity(pos, true); - } - ++ } ++ + @Nullable + public BlockEntity getBlockEntity(BlockPos blockposition, boolean validate) { + if (this.capturedTileEntities.containsKey(blockposition)) { @@ -514,8 +494,8 @@ + } + // CraftBukkit end + return this.isOutsideBuildHeight(blockposition) ? null : (!this.isClientSide && Thread.currentThread() != this.thread ? null : this.getChunkAt(blockposition).getBlockEntity(blockposition, LevelChunk.EntityCreationType.IMMEDIATE)); -+ } -+ + } + public void setBlockEntity(BlockEntity blockEntity) { BlockPos blockposition = blockEntity.getBlockPos(); @@ -529,7 +509,7 @@ this.getChunkAt(blockposition).addAndRegisterBlockEntity(blockEntity); } } -@@ -643,7 +928,7 @@ +@@ -643,7 +919,7 @@ for (int k = 0; k < j; ++k) { EnderDragonPart entitycomplexpart = aentitycomplexpart[k]; @@ -538,7 +518,7 @@ if (t0 != null && predicate.test(t0)) { result.add(t0); -@@ -912,7 +1197,7 @@ +@@ -912,7 +1188,7 @@ public static enum ExplosionInteraction implements StringRepresentable { diff --git a/paper-server/patches/sources/net/minecraft/world/level/NaturalSpawner.java.patch b/paper-server/patches/sources/net/minecraft/world/level/NaturalSpawner.java.patch index 27f492774b8..f26460ed82f 100644 --- a/paper-server/patches/sources/net/minecraft/world/level/NaturalSpawner.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/NaturalSpawner.java.patch @@ -48,23 +48,7 @@ list.add(enumcreaturetype); } } -@@ -127,6 +148,7 @@ - ProfilerFiller gameprofilerfiller = Profiler.get(); - - gameprofilerfiller.push("spawner"); -+ world.timings.mobSpawn.startTiming(); // Spigot - Iterator iterator = spawnableGroups.iterator(); - - while (iterator.hasNext()) { -@@ -141,6 +163,7 @@ - } - } - -+ world.timings.mobSpawn.stopTiming(); // Spigot - gameprofilerfiller.pop(); - } - -@@ -217,10 +240,15 @@ +@@ -217,10 +238,15 @@ entityinsentient.moveTo(d0, (double) i, d1, world.random.nextFloat() * 360.0F, 0.0F); if (NaturalSpawner.isValidPositionForMob(world, entityinsentient, d2)) { groupdataentity = entityinsentient.finalizeSpawn(world, world.getCurrentDifficultyAt(entityinsentient.blockPosition()), EntitySpawnReason.NATURAL, groupdataentity); @@ -84,7 +68,7 @@ if (j >= entityinsentient.getMaxSpawnClusterSize()) { return; } -@@ -369,7 +397,7 @@ +@@ -369,7 +395,7 @@ if (entityinsentient.checkSpawnRules(world, EntitySpawnReason.CHUNK_GENERATION) && entityinsentient.checkSpawnObstruction(world)) { groupdataentity = entityinsentient.finalizeSpawn(world, world.getCurrentDifficultyAt(entityinsentient.blockPosition()), EntitySpawnReason.CHUNK_GENERATION, groupdataentity); @@ -93,7 +77,7 @@ flag = true; } } -@@ -482,10 +510,12 @@ +@@ -482,10 +508,12 @@ return this.unmodifiableMobCategoryCounts; } diff --git a/paper-server/patches/sources/net/minecraft/world/level/block/entity/BlockEntity.java.patch b/paper-server/patches/sources/net/minecraft/world/level/block/entity/BlockEntity.java.patch index b26f525fc6d..38f32457ea0 100644 --- a/paper-server/patches/sources/net/minecraft/world/level/block/entity/BlockEntity.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/block/entity/BlockEntity.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/entity/BlockEntity.java +++ b/net/minecraft/world/level/block/entity/BlockEntity.java -@@ -26,8 +26,21 @@ +@@ -26,8 +26,18 @@ import net.minecraft.world.level.block.state.BlockState; import org.slf4j.Logger; @@ -9,12 +9,9 @@ +import org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry; +import org.bukkit.inventory.InventoryHolder; +// CraftBukkit end -+ -+import org.spigotmc.CustomTimingsHandler; // Spigot + public abstract class BlockEntity { -+ public CustomTimingsHandler tickTimer = org.bukkit.craftbukkit.SpigotTimings.getTileEntityTimings(this); // Spigot + // CraftBukkit start - data containers + private static final CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new CraftPersistentDataTypeRegistry(); + public CraftPersistentDataContainer persistentDataContainer; @@ -22,7 +19,7 @@ private static final Logger LOGGER = LogUtils.getLogger(); private final BlockEntityType type; @Nullable -@@ -74,8 +87,17 @@ +@@ -74,8 +84,17 @@ return this.level != null; } @@ -41,7 +38,7 @@ public final void loadWithComponents(CompoundTag nbt, HolderLookup.Provider registries) { this.loadAdditional(nbt, registries); BlockEntity.ComponentHelper.COMPONENTS_CODEC.parse(registries.createSerializationContext(NbtOps.INSTANCE), nbt).resultOrPartial((s) -> { -@@ -114,6 +136,11 @@ +@@ -114,6 +133,11 @@ }).ifPresent((nbtbase) -> { nbttagcompound.merge((CompoundTag) nbtbase); }); @@ -53,7 +50,7 @@ return nbttagcompound; } -@@ -263,13 +290,19 @@ +@@ -263,13 +287,19 @@ } public final void applyComponents(DataComponentMap defaultComponents, DataComponentPatch components) { @@ -75,7 +72,7 @@ @Nullable @Override public T get(DataComponentType type) { -@@ -284,9 +317,13 @@ +@@ -284,9 +314,13 @@ } }); Objects.requireNonNull(set); @@ -90,7 +87,7 @@ } protected void collectImplicitComponents(DataComponentMap.Builder builder) {} -@@ -321,6 +358,15 @@ +@@ -321,6 +355,15 @@ } } diff --git a/paper-server/patches/sources/net/minecraft/world/level/chunk/LevelChunk.java.patch b/paper-server/patches/sources/net/minecraft/world/level/chunk/LevelChunk.java.patch index 8bae0ac8345..ee4f0e58830 100644 --- a/paper-server/patches/sources/net/minecraft/world/level/chunk/LevelChunk.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/chunk/LevelChunk.java.patch @@ -238,14 +238,10 @@ if (tileentity != null) { Level world = this.level; -@@ -549,9 +611,68 @@ - if (this.postLoad != null) { - this.postLoad.run(this); - this.postLoad = null; -+ } -+ -+ } -+ +@@ -553,6 +615,65 @@ + + } + + // CraftBukkit start + public void loadCallback() { + // Paper start @@ -283,9 +279,9 @@ + } + server.getPluginManager().callEvent(new org.bukkit.event.world.ChunkPopulateEvent(bukkitChunk)); + } - } ++ } + } - ++ + public void unloadCallback() { + org.bukkit.Server server = this.level.getCraftServer(); + org.bukkit.Chunk bukkitChunk = new org.bukkit.craftbukkit.CraftChunk(this); @@ -302,11 +298,12 @@ + @Override + public boolean isUnsaved() { + return super.isUnsaved() && !this.mustNotSave; - } ++ } + // CraftBukkit end - ++ public boolean isEmpty() { return false; + } @@ -750,7 +871,7 @@ private void updateBlockEntityTicker(T blockEntity) { @@ -325,22 +322,11 @@ this.ticker = blockentityticker; } -@@ -855,6 +976,7 @@ - ProfilerFiller gameprofilerfiller = Profiler.get(); - - gameprofilerfiller.push(this::getType); -+ this.blockEntity.tickTimer.startTiming(); // Spigot - BlockState iblockdata = LevelChunk.this.getBlockState(blockposition); - - if (this.blockEntity.getType().isValid(iblockdata)) { -@@ -872,6 +994,10 @@ +@@ -872,6 +993,7 @@ this.blockEntity.fillCrashReportCategory(crashreportsystemdetails); throw new ReportedException(crashreport); + // Spigot start -+ } finally { -+ this.blockEntity.tickTimer.stopTiming(); -+ // Spigot end } } } diff --git a/paper-server/patches/sources/net/minecraft/world/level/chunk/storage/SerializableChunkData.java.patch b/paper-server/patches/sources/net/minecraft/world/level/chunk/storage/SerializableChunkData.java.patch index 50f18dbd4f7..132fde3257e 100644 --- a/paper-server/patches/sources/net/minecraft/world/level/chunk/storage/SerializableChunkData.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/chunk/storage/SerializableChunkData.java.patch @@ -132,31 +132,7 @@ return nbttagcompound; } -@@ -550,12 +576,15 @@ - @Nullable - private static LevelChunk.PostLoadProcessor postLoadChunk(ServerLevel world, List entities, List blockEntities) { - return entities.isEmpty() && blockEntities.isEmpty() ? null : (chunk) -> { -+ world.timings.syncChunkLoadEntitiesTimer.startTiming(); // Spigot - if (!entities.isEmpty()) { - world.addLegacyChunkEntities(EntityType.loadEntitiesRecursive(entities, world, EntitySpawnReason.LOAD)); - } -+ world.timings.syncChunkLoadEntitiesTimer.stopTiming(); // Spigot - - Iterator iterator = blockEntities.iterator(); - -+ world.timings.syncChunkLoadTileEntitiesTimer.startTiming(); // Spigot - while (iterator.hasNext()) { - CompoundTag nbttagcompound = (CompoundTag) iterator.next(); - boolean flag = nbttagcompound.getBoolean("keepPacked"); -@@ -571,6 +600,7 @@ - } - } - } -+ world.timings.syncChunkLoadTileEntitiesTimer.stopTiming(); // Spigot - - }; - } -@@ -623,6 +653,12 @@ +@@ -623,6 +649,12 @@ StructureStart structurestart = StructureStart.loadStaticStart(context, nbttagcompound1.getCompound(s), worldSeed); if (structurestart != null) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java index c9920b60a53..4d80804c099 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -379,7 +379,6 @@ public final class CraftServer implements Server { this.saveCommandsConfig(); this.overrideAllCommandBlockCommands = this.commandsConfiguration.getStringList("command-block-overrides").contains("*"); this.ignoreVanillaPermissions = this.commandsConfiguration.getBoolean("ignore-vanilla-permissions"); - this.pluginManager.useTimings(this.configuration.getBoolean("settings.plugin-profiling")); this.overrideSpawnLimits(); console.autosavePeriod = this.configuration.getInt("ticks-per.autosave"); this.warningState = WarningState.value(this.configuration.getString("settings.deprecated-verbose")); @@ -2646,12 +2645,31 @@ public final class CraftServer implements Server { private final org.bukkit.Server.Spigot spigot = new org.bukkit.Server.Spigot() { + @Deprecated @Override public YamlConfiguration getConfig() { return org.spigotmc.SpigotConfig.config; } + @Override + public YamlConfiguration getBukkitConfig() + { + return configuration; + } + + @Override + public YamlConfiguration getSpigotConfig() + { + return org.spigotmc.SpigotConfig.config; + } + + @Override + public YamlConfiguration getPaperConfig() + { + return CraftServer.this.console.paperConfigurations.createLegacyObject(CraftServer.this.console); + } + @Override public void restart() { org.spigotmc.RestartCommand.restart(); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/SpigotTimings.java b/paper-server/src/main/java/org/bukkit/craftbukkit/SpigotTimings.java deleted file mode 100644 index b0ffa23faf6..00000000000 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/SpigotTimings.java +++ /dev/null @@ -1,163 +0,0 @@ -package org.bukkit.craftbukkit; - -import java.util.HashMap; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.storage.PrimaryLevelData; -import org.bukkit.craftbukkit.scheduler.CraftTask; -import org.bukkit.plugin.java.JavaPluginLoader; -import org.bukkit.scheduler.BukkitTask; -import org.spigotmc.CustomTimingsHandler; - -public class SpigotTimings { - - public static final CustomTimingsHandler serverTickTimer = new CustomTimingsHandler("** Full Server Tick"); - public static final CustomTimingsHandler playerListTimer = new CustomTimingsHandler("Player List"); - public static final CustomTimingsHandler commandFunctionsTimer = new CustomTimingsHandler("Command Functions"); - public static final CustomTimingsHandler connectionTimer = new CustomTimingsHandler("Connection Handler"); - public static final CustomTimingsHandler playerConnectionTimer = new CustomTimingsHandler("** PlayerConnection"); - public static final CustomTimingsHandler tickablesTimer = new CustomTimingsHandler("Tickables"); - public static final CustomTimingsHandler schedulerTimer = new CustomTimingsHandler("Scheduler"); - public static final CustomTimingsHandler timeUpdateTimer = new CustomTimingsHandler("Time Update"); - public static final CustomTimingsHandler serverCommandTimer = new CustomTimingsHandler("Server Command"); - public static final CustomTimingsHandler worldSaveTimer = new CustomTimingsHandler("World Save"); - - public static final CustomTimingsHandler entityMoveTimer = new CustomTimingsHandler("** entityMove"); - public static final CustomTimingsHandler tickEntityTimer = new CustomTimingsHandler("** tickEntity"); - public static final CustomTimingsHandler activatedEntityTimer = new CustomTimingsHandler("** activatedTickEntity"); - public static final CustomTimingsHandler tickTileEntityTimer = new CustomTimingsHandler("** tickTileEntity"); - - public static final CustomTimingsHandler timerEntityBaseTick = new CustomTimingsHandler("** livingEntityBaseTick"); - public static final CustomTimingsHandler timerEntityAI = new CustomTimingsHandler("** livingEntityAI"); - public static final CustomTimingsHandler timerEntityAICollision = new CustomTimingsHandler("** livingEntityAICollision"); - public static final CustomTimingsHandler timerEntityAIMove = new CustomTimingsHandler("** livingEntityAIMove"); - public static final CustomTimingsHandler timerEntityTickRest = new CustomTimingsHandler("** livingEntityTickRest"); - - public static final CustomTimingsHandler processQueueTimer = new CustomTimingsHandler("processQueue"); - public static final CustomTimingsHandler schedulerSyncTimer = new CustomTimingsHandler("** Scheduler - Sync Tasks", JavaPluginLoader.pluginParentTimer); - - public static final CustomTimingsHandler playerCommandTimer = new CustomTimingsHandler("** playerCommand"); - - public static final CustomTimingsHandler entityActivationCheckTimer = new CustomTimingsHandler("entityActivationCheck"); - public static final CustomTimingsHandler checkIfActiveTimer = new CustomTimingsHandler("** checkIfActive"); - - public static final HashMap entityTypeTimingMap = new HashMap(); - public static final HashMap tileEntityTypeTimingMap = new HashMap(); - public static final HashMap pluginTaskTimingMap = new HashMap(); - - /** - * Gets a timer associated with a plugins tasks. - * @param task - * @param period - * @return - */ - public static CustomTimingsHandler getPluginTaskTimings(BukkitTask task, long period) { - if (!task.isSync()) { - return null; - } - String plugin; - final CraftTask ctask = (CraftTask) task; - - if (task.getOwner() != null) { - plugin = task.getOwner().getDescription().getFullName(); - } else { - plugin = "Unknown"; - } - String taskname = ctask.getTaskName(); - - String name = "Task: " + plugin + " Runnable: " + taskname; - if (period > 0) { - name += "(interval:" + period + ")"; - } else { - name += "(Single)"; - } - CustomTimingsHandler result = SpigotTimings.pluginTaskTimingMap.get(name); - if (result == null) { - result = new CustomTimingsHandler(name, SpigotTimings.schedulerSyncTimer); - SpigotTimings.pluginTaskTimingMap.put(name, result); - } - return result; - } - - /** - * Get a named timer for the specified entity type to track type specific timings. - * @param entity - * @return - */ - public static CustomTimingsHandler getEntityTimings(Entity entity) { - String entityType = entity.getClass().getName(); - CustomTimingsHandler result = SpigotTimings.entityTypeTimingMap.get(entityType); - if (result == null) { - result = new CustomTimingsHandler("** tickEntity - " + entity.getClass().getSimpleName(), SpigotTimings.activatedEntityTimer); - SpigotTimings.entityTypeTimingMap.put(entityType, result); - } - return result; - } - - /** - * Get a named timer for the specified tile entity type to track type specific timings. - * @param entity - * @return - */ - public static CustomTimingsHandler getTileEntityTimings(BlockEntity entity) { - String entityType = entity.getClass().getName(); - CustomTimingsHandler result = SpigotTimings.tileEntityTypeTimingMap.get(entityType); - if (result == null) { - result = new CustomTimingsHandler("** tickTileEntity - " + entity.getClass().getSimpleName(), SpigotTimings.tickTileEntityTimer); - SpigotTimings.tileEntityTypeTimingMap.put(entityType, result); - } - return result; - } - - /** - * Set of timers per world, to track world specific timings. - */ - public static class WorldTimingsHandler { - public final CustomTimingsHandler mobSpawn; - public final CustomTimingsHandler doChunkUnload; - public final CustomTimingsHandler doTickPending; - public final CustomTimingsHandler doTickTiles; - public final CustomTimingsHandler doChunkMap; - public final CustomTimingsHandler doSounds; - public final CustomTimingsHandler entityTick; - public final CustomTimingsHandler tileEntityTick; - public final CustomTimingsHandler tileEntityPending; - public final CustomTimingsHandler tracker; - public final CustomTimingsHandler doTick; - public final CustomTimingsHandler tickEntities; - - public final CustomTimingsHandler syncChunkLoadTimer; - public final CustomTimingsHandler syncChunkLoadStructuresTimer; - public final CustomTimingsHandler syncChunkLoadEntitiesTimer; - public final CustomTimingsHandler syncChunkLoadTileEntitiesTimer; - public final CustomTimingsHandler syncChunkLoadTileTicksTimer; - public final CustomTimingsHandler syncChunkLoadPostTimer; - - public WorldTimingsHandler(Level server) { - String name = ((PrimaryLevelData) server.levelData).getLevelName() + " - "; - - this.mobSpawn = new CustomTimingsHandler("** " + name + "mobSpawn"); - this.doChunkUnload = new CustomTimingsHandler("** " + name + "doChunkUnload"); - this.doTickPending = new CustomTimingsHandler("** " + name + "doTickPending"); - this.doTickTiles = new CustomTimingsHandler("** " + name + "doTickTiles"); - this.doChunkMap = new CustomTimingsHandler("** " + name + "doChunkMap"); - this.doSounds = new CustomTimingsHandler("** " + name + "doSounds"); - this.entityTick = new CustomTimingsHandler("** " + name + "entityTick"); - this.tileEntityTick = new CustomTimingsHandler("** " + name + "tileEntityTick"); - this.tileEntityPending = new CustomTimingsHandler("** " + name + "tileEntityPending"); - - this.syncChunkLoadTimer = new CustomTimingsHandler("** " + name + "syncChunkLoad"); - this.syncChunkLoadStructuresTimer = new CustomTimingsHandler("** " + name + "chunkLoad - Structures"); - this.syncChunkLoadEntitiesTimer = new CustomTimingsHandler("** " + name + "chunkLoad - Entities"); - this.syncChunkLoadTileEntitiesTimer = new CustomTimingsHandler("** " + name + "chunkLoad - TileEntities"); - this.syncChunkLoadTileTicksTimer = new CustomTimingsHandler("** " + name + "chunkLoad - TileTicks"); - this.syncChunkLoadPostTimer = new CustomTimingsHandler("** " + name + "chunkLoad - Post"); - - - this.tracker = new CustomTimingsHandler(name + "tracker"); - this.doTick = new CustomTimingsHandler(name + "doTick"); - this.tickEntities = new CustomTimingsHandler(name + "tickEntities"); - } - } -} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 6172bce9368..a37e5d822e9 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -2794,6 +2794,14 @@ public class CraftPlayer extends CraftHumanEntity implements Player { CraftPlayer.this.getHandle().connection.send(new net.minecraft.network.protocol.game.ClientboundSystemChatPacket(components, position == net.md_5.bungee.api.ChatMessageType.ACTION_BAR)); } + + // Paper start + @Override + public int getPing() + { + return CraftPlayer.this.getPing(); + } + // Paper end }; public Player.Spigot spigot() diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java b/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java index a7b53187a24..0385aa1e5cc 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java @@ -413,9 +413,7 @@ public class CraftScheduler implements BukkitScheduler { if (task.isSync()) { this.currentTask = task; try { - task.timings.startTiming(); // Spigot task.run(); - task.timings.stopTiming(); // Spigot } catch (final Throwable throwable) { task.getOwner().getLogger().log( Level.WARNING, diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java b/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java index e4d1eb4a0ce..17680f112d0 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java @@ -1,13 +1,11 @@ package org.bukkit.craftbukkit.scheduler; import java.util.function.Consumer; + import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitTask; -import org.bukkit.craftbukkit.SpigotTimings; // Spigot -import org.spigotmc.CustomTimingsHandler; // Spigot - public class CraftTask implements BukkitTask, Runnable { // Spigot private volatile CraftTask next = null; @@ -26,13 +24,12 @@ public class CraftTask implements BukkitTask, Runnable { // Spigot */ private volatile long period; private long nextRun; - private final Runnable rTask; - private final Consumer cTask; + public final Runnable rTask; + public final Consumer cTask; private final Plugin plugin; private final int id; private final long createdAt = System.nanoTime(); - final CustomTimingsHandler timings; // Spigot CraftTask() { this(null, null, CraftTask.NO_REPEATING, CraftTask.NO_REPEATING); } @@ -58,7 +55,6 @@ public class CraftTask implements BukkitTask, Runnable { // Spigot } this.id = id; this.period = period; - this.timings = this.isSync() ? SpigotTimings.getPluginTaskTimings(this, period) : null; // Spigot } @Override @@ -137,9 +133,4 @@ public class CraftTask implements BukkitTask, Runnable { // Spigot return true; } - // Spigot start - public String getTaskName() { - return (this.getTaskClass() == null) ? "Unknown" : this.getTaskClass().getName(); - } - // Spigot end } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftIconCache.java b/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftIconCache.java index f97eccb6a17..dba31a2cbcf 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftIconCache.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftIconCache.java @@ -1,6 +1,7 @@ package org.bukkit.craftbukkit.util; import org.bukkit.util.CachedServerIcon; +import org.jetbrains.annotations.Nullable; public class CraftIconCache implements CachedServerIcon { public final byte[] value; @@ -8,4 +9,12 @@ public class CraftIconCache implements CachedServerIcon { public CraftIconCache(final byte[] value) { this.value = value; } + + @Override + public @Nullable String getData() { + if (this.value == null) { + return null; + } + return "data:image/png;base64," + new String(java.util.Base64.getEncoder().encode(this.value), java.nio.charset.StandardCharsets.UTF_8); + } } diff --git a/paper-server/src/main/java/org/spigotmc/ActivationRange.java b/paper-server/src/main/java/org/spigotmc/ActivationRange.java index 5baf68732cb..0338ceaddc1 100644 --- a/paper-server/src/main/java/org/spigotmc/ActivationRange.java +++ b/paper-server/src/main/java/org/spigotmc/ActivationRange.java @@ -28,7 +28,6 @@ import net.minecraft.world.entity.projectile.ThrownTrident; import net.minecraft.world.entity.raid.Raider; import net.minecraft.world.level.Level; import net.minecraft.world.phys.AABB; -import org.bukkit.craftbukkit.SpigotTimings; public class ActivationRange { @@ -111,7 +110,6 @@ public class ActivationRange */ public static void activateEntities(Level world) { - SpigotTimings.entityActivationCheckTimer.startTiming(); final int miscActivationRange = world.spigotConfig.miscActivationRange; final int raiderActivationRange = world.spigotConfig.raiderActivationRange; final int animalActivationRange = world.spigotConfig.animalActivationRange; @@ -138,7 +136,6 @@ public class ActivationRange world.getEntities().get(ActivationRange.maxBB, ActivationRange::activateEntity); } - SpigotTimings.entityActivationCheckTimer.stopTiming(); } /** @@ -233,10 +230,8 @@ public class ActivationRange */ public static boolean checkIfActive(Entity entity) { - SpigotTimings.checkIfActiveTimer.startTiming(); // Never safe to skip fireworks or item gravity if (entity instanceof FireworkRocketEntity || (entity instanceof ItemEntity && (entity.tickCount + entity.getId() + 1) % 4 == 0)) { - SpigotTimings.checkIfActiveTimer.stopTiming(); return true; } @@ -260,7 +255,6 @@ public class ActivationRange { isActive = false; } - SpigotTimings.checkIfActiveTimer.stopTiming(); return isActive; } }