Remove Spigot timings

This commit is contained in:
Aikar
2016-03-03 04:00:11 -06:00
parent a371d5fefe
commit 770ee3eebd
19 changed files with 475 additions and 926 deletions

View File

@@ -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<TickTask> 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 extends MinecraftServer> S spin(Function<Thread, S> serverFactory) {
AtomicReference<S> 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<LevelStem> dimensions = iregistrycustom_dimension.lookupOrThrow(Registries.LEVEL_STEM);
+ for (LevelStem worldDimension : dimensions) {
+ ResourceKey<LevelStem> 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<Level> key) {
return (ServerLevel) this.levels.get(key);
}
+ }
+
+ // CraftBukkit start
+ public void addLevel(ServerLevel level) {
+ Map<ResourceKey<Level>, ServerLevel> oldLevels = this.levels;
@@ -1042,13 +988,12 @@
+ Map<ResourceKey<Level>, ServerLevel> newLevels = Maps.newLinkedHashMap(oldLevels);
+ newLevels.remove(level.dimension());
+ this.levels = Collections.unmodifiableMap(newLevels);
+ }
}
+ // CraftBukkit end
+
public Set<ResourceKey<Level>> 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<Void> reloadResources(Collection<String> dataPacks) {
CompletableFuture<Void> completablefuture = CompletableFuture.supplyAsync(() -> {
@@ -1111,7 +1056,7 @@
}, this).thenCompose((immutablelist) -> {
MultiPackResourceManager resourcemanager = new MultiPackResourceManager(PackType.SERVER_DATA, immutablelist);
List<Registry.PendingTags<?>> 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<String> list = Lists.newArrayList();
final GameRules gamerules = this.getGameRules();
@@ -1128,7 +1073,7 @@
@Override
public <T extends GameRules.Value<T>> void visit(GameRules.Key<T> key, GameRules.Type<T> 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) {

View File

@@ -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> 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 @@
}
}
}

View File

@@ -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<ChunkResult<ChunkAccess>> 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<ChunkAccess> 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

View File

@@ -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<ServerPlayer> 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<Entity> 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> 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<Vec3> optional = Optional.ofNullable((Vec3) serverexplosion.getHitPlayers().get(entityplayer));
@@ -784,7 +733,7 @@
}
private Explosion.BlockInteraction getDestroyType(GameRules.Key<GameRules.BooleanValue> decayRule) {
@@ -1226,17 +1543,24 @@
@@ -1226,17 +1532,24 @@
}
public <T extends ParticleOptions> 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<Structure> structureTag, BlockPos pos, int radius, boolean skipReferencedStructures) {
@@ -821,7 +770,7 @@
return null;
} else {
Optional<HolderSet.Named<Structure>> 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 <T> String getTypeCount(Iterable<T> items, Function<T, String> classifier) {
try {
Object2IntOpenHashMap<String> 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<Entity> 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);

View File

@@ -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<CommandSourceStack> 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<FilteredText> 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<LastSeenMessages> optional = this.unpackAndApplyLastSeen(packet.lastSeenMessages());
if (!optional.isEmpty()) {
@@ -1394,27 +1881,44 @@
@@ -1394,27 +1879,44 @@
return;
}
@@ -941,7 +937,7 @@
ParseResults<CommandSourceStack> 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<FilteredText> 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 @@
});
}