9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-27 02:49:19 +00:00

Gale paper server patches work

This commit is contained in:
Dreeam
2025-03-28 05:02:44 -04:00
parent fc7cabdd1b
commit 893ab16248
37 changed files with 94 additions and 843 deletions

View File

@@ -0,0 +1,41 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Wed, 12 Oct 2022 10:42:15 -0400
Subject: [PATCH] Leaf config
Leaf Config v3
including load config, backup old or outdated config, and add config to spark profiler automatically.
TODO - Dreeam:
Add per world config
Add config reload
diff --git a/net/minecraft/server/Main.java b/net/minecraft/server/Main.java
index 58be6e1d1607a3af5e28f851718b82321f2feb25..a5aa3d415486ef262383ab738eb7dd80b3fecb5e 100644
--- a/net/minecraft/server/Main.java
+++ b/net/minecraft/server/Main.java
@@ -108,10 +108,12 @@ public class Main {
JvmProfiler.INSTANCE.start(Environment.SERVER);
}
+ org.dreeam.leaf.config.LeafConfig.loadConfig(); // Leaf - Leaf config
io.papermc.paper.plugin.PluginInitializerManager.load(optionSet); // Paper
Bootstrap.bootStrap();
Bootstrap.validate();
Util.startTimerHackThread();
+ org.dreeam.leaf.config.ConfigModules.loadAfterBootstrap(); // Leaf - Leaf config - post load
Path path1 = Paths.get("server.properties");
DedicatedServerSettings dedicatedServerSettings = new DedicatedServerSettings(optionSet); // CraftBukkit - CLI argument support
dedicatedServerSettings.forceSave();
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 5bb1b96390671fb4eb59a8d795a97e8fb061cc0d..ba5962b04a61e21ae81c2c212de6945585981ddd 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1102,6 +1102,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
org.spigotmc.WatchdogThread.tick();
// Paper end
org.spigotmc.WatchdogThread.hasStarted = true; // Paper
+ org.dreeam.leaf.config.LeafConfig.regSparkExtraConfig(); // Leaf - Leaf config
Arrays.fill(this.recentTps, 20);
// Paper start - further improve server tick loop
long tickSection = Util.getNanos();

View File

@@ -0,0 +1,31 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Mon, 4 Nov 2024 23:07:27 -0500
Subject: [PATCH] Leaf Commands
Currently the config reload is just a simple poc,
if necessary, I will add @DoNotLoad feature in the future, like Luminol
TODOs:
Leaf status command
Leaf config command
Leaf version command enhanced (ability to show the list of new commits based on current version) (optional)
Leaf config
Leaf config only get config value (TODO: check whether work, and whether need to set config value back to keep the key in the config file)
Leaf config convert from toml to yaml
Leaf config v3 move to new key
...
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
index c697b3adeabd4f913e9e5e0b90c620a2a642f35d..c2ed1b0b67e62434292ebf3edd70c74af0c0d9af 100644
--- a/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
@@ -185,6 +185,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
org.spigotmc.WatchdogThread.doStart(org.spigotmc.SpigotConfig.timeoutTime, org.spigotmc.SpigotConfig.restartOnCrash); // Paper - start watchdog thread
thread.start(); // Paper - Enhance console tab completions for brigadier commands; start console thread after MinecraftServer.console & PaperConfig are initialized
io.papermc.paper.command.PaperCommands.registerCommands(this); // Paper - setup /paper command
+ org.dreeam.leaf.command.LeafCommands.registerCommands(this); // Leaf - Leaf commands
this.server.spark.registerCommandBeforePlugins(this.server); // Paper - spark
com.destroystokyo.paper.Metrics.PaperMetrics.startMetrics(); // Paper - start metrics
com.destroystokyo.paper.VersionHistoryManager.INSTANCE.getClass(); // Paper - load version history now

View File

@@ -169,7 +169,7 @@ index 18071dcc69cc28471dddb7de94e803ec1e5fc2e4..e30bb9c4046200c1a6e4e917d15b205f
}
}
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 5bb1b96390671fb4eb59a8d795a97e8fb061cc0d..c1a411c21ad3eed6412a7fc4d1c348854d8d35d9 100644
index ba5962b04a61e21ae81c2c212de6945585981ddd..5ba734fc868a9658ac39d9b22e91e48abc6b3ddb 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -113,19 +113,8 @@ import net.minecraft.util.TimeUtil;
@@ -216,7 +216,7 @@ index 5bb1b96390671fb4eb59a8d795a97e8fb061cc0d..c1a411c21ad3eed6412a7fc4d1c34885
LOGGER.info("Stopping server");
Commands.COMMAND_SENDING_POOL.shutdownNow(); // Paper - Perf: Async command map building; Shutdown and don't bother finishing
@@ -1155,22 +1134,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1156,22 +1135,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// Spigot end
boolean flag = l == 0L;
@@ -239,7 +239,7 @@ index 5bb1b96390671fb4eb59a8d795a97e8fb061cc0d..c1a411c21ad3eed6412a7fc4d1c34885
this.mayHaveDelayedTasks = true;
this.delayedTasksMaxNextTickTimeNanos = Math.max(Util.getNanos() + l, this.nextTickTimeNanos);
this.startMeasuringTaskExecutionTime();
@@ -1180,11 +1151,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1181,11 +1152,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.tickRateManager.endTickWork();
}
@@ -251,7 +251,7 @@ index 5bb1b96390671fb4eb59a8d795a97e8fb061cc0d..c1a411c21ad3eed6412a7fc4d1c34885
this.isReady = true;
JvmProfiler.INSTANCE.onServerTick(this.smoothedTickTimeMillis);
@@ -1356,7 +1323,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1357,7 +1324,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@Override
public void doRunTask(TickTask task) {
@@ -259,7 +259,7 @@ index 5bb1b96390671fb4eb59a8d795a97e8fb061cc0d..c1a411c21ad3eed6412a7fc4d1c34885
super.doRunTask(task);
}
@@ -1449,7 +1415,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1450,7 +1416,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.autoSave();
}
@@ -267,7 +267,7 @@ index 5bb1b96390671fb4eb59a8d795a97e8fb061cc0d..c1a411c21ad3eed6412a7fc4d1c34885
this.runAllTasks(); // Paper - move runAllTasks() into full server tick (previously for timings)
this.server.spark.executeMainThreadTasks(); // Paper - spark
// Paper start - Server Tick Events
@@ -1458,7 +1423,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1459,7 +1424,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
new com.destroystokyo.paper.event.server.ServerTickEndEvent(this.tickCount, ((double)(endTime - lastTick) / 1000000D), remaining).callEvent();
// Paper end - Server Tick Events
this.server.spark.tickEnd(((double)(endTime - lastTick) / 1000000D)); // Paper - spark
@@ -275,7 +275,7 @@ index 5bb1b96390671fb4eb59a8d795a97e8fb061cc0d..c1a411c21ad3eed6412a7fc4d1c34885
long l = Util.getNanos() - nanos;
int i1 = this.tickCount % 100;
this.aggregatedTickTimesNanos = this.aggregatedTickTimesNanos - this.tickTimesNanos[i1];
@@ -1471,16 +1435,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1472,16 +1436,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.tickTimes60s.add(this.tickCount, l);
// Paper end - Add tick times API and /mspt command
this.logTickMethodTime(nanos);
@@ -292,7 +292,7 @@ index 5bb1b96390671fb4eb59a8d795a97e8fb061cc0d..c1a411c21ad3eed6412a7fc4d1c34885
LOGGER.debug("Autosave finished");
}
@@ -1546,7 +1506,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1547,7 +1507,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
protected void tickChildren(BooleanSupplier hasTimeLeft) {
@@ -300,7 +300,7 @@ index 5bb1b96390671fb4eb59a8d795a97e8fb061cc0d..c1a411c21ad3eed6412a7fc4d1c34885
this.getPlayerList().getPlayers().forEach(serverPlayer1 -> serverPlayer1.connection.suspendFlushing());
this.server.getScheduler().mainThreadHeartbeat(); // CraftBukkit
// Paper start - Folia scheduler API
@@ -1564,9 +1523,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1565,9 +1524,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
});
// Paper end - Folia scheduler API
io.papermc.paper.adventure.providers.ClickCallbackProviderImpl.CALLBACK_MANAGER.handleQueue(this.tickCount); // Paper
@@ -310,7 +310,7 @@ index 5bb1b96390671fb4eb59a8d795a97e8fb061cc0d..c1a411c21ad3eed6412a7fc4d1c34885
// CraftBukkit start
// Run tasks that are waiting on processing
@@ -1600,7 +1557,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1601,7 +1558,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
serverLevel.hasPhysicsEvent = org.bukkit.event.block.BlockPhysicsEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - BlockPhysicsEvent
serverLevel.hasEntityMoveEvent = io.papermc.paper.event.entity.EntityMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - Add EntityMoveEvent
serverLevel.updateLagCompensationTick(); // Paper - lag compensation
@@ -318,7 +318,7 @@ index 5bb1b96390671fb4eb59a8d795a97e8fb061cc0d..c1a411c21ad3eed6412a7fc4d1c34885
/* Drop global time updates
if (this.tickCount % 20 == 0) {
profilerFiller.push("timeSync");
@@ -1609,8 +1565,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1610,8 +1566,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
// CraftBukkit end */
@@ -327,7 +327,7 @@ index 5bb1b96390671fb4eb59a8d795a97e8fb061cc0d..c1a411c21ad3eed6412a7fc4d1c34885
try {
serverLevel.tick(hasTimeLeft);
} catch (Throwable var7) {
@@ -1619,34 +1573,24 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1620,34 +1574,24 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
throw new ReportedException(crashReport);
}
@@ -362,7 +362,7 @@ index 5bb1b96390671fb4eb59a8d795a97e8fb061cc0d..c1a411c21ad3eed6412a7fc4d1c34885
}
public void tickConnection() {
@@ -1662,14 +1606,9 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1663,14 +1607,9 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
public void forceTimeSynchronization() {
@@ -377,7 +377,7 @@ index 5bb1b96390671fb4eb59a8d795a97e8fb061cc0d..c1a411c21ad3eed6412a7fc4d1c34885
}
public boolean isLevelEnabled(Level level) {
@@ -2484,55 +2423,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -2485,55 +2424,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
// CraftBukkit end
@@ -433,7 +433,7 @@ index 5bb1b96390671fb4eb59a8d795a97e8fb061cc0d..c1a411c21ad3eed6412a7fc4d1c34885
public Path getWorldPath(LevelResource levelResource) {
return this.storageSource.getLevelPath(levelResource);
}
@@ -2582,24 +2472,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -2583,24 +2473,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
return this.isSaving;
}
@@ -458,7 +458,7 @@ index 5bb1b96390671fb4eb59a8d795a97e8fb061cc0d..c1a411c21ad3eed6412a7fc4d1c34885
public int getMaxChainedNeighborUpdates() {
return 1000000;
}
@@ -2705,55 +2577,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -2706,55 +2578,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
public record ServerResourcePackInfo(UUID id, String url, String hash, boolean isRequired, @Nullable Component prompt) {
}
@@ -660,10 +660,10 @@ index a3192400b37274620977e5a40d4283bfec3ab9b3..f23b17416eadc0e800ca34918ac78c03
String string = String.format(
Locale.ROOT, "%s-%s-%s", Util.getFilenameFormattedDateTime(), server.getWorldData().getLevelName(), SharedConstants.getCurrentVersion().getId()
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
index c697b3adeabd4f913e9e5e0b90c620a2a642f35d..f63758938361f6b866b38bac98fcfb2dd15b4b81 100644
index c2ed1b0b67e62434292ebf3edd70c74af0c0d9af..c71034e9077280ccd7b4d7a9986eb6ec1536472a 100644
--- a/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
@@ -731,12 +731,6 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@@ -732,12 +732,6 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
return this.settings.getProperties().serverResourcePackInfo;
}

View File

@@ -0,0 +1,92 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Thu, 24 Nov 2022 12:00:55 +0100
Subject: [PATCH] Reduce projectile chunk loading
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
This patch is based on the following patch:
"Reduce projectile chunk loading"
By: Paul Sauve <paul@technove.co>
As part of: Airplane (https://github.com/TECHNOVE/Airplane)
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
* Airplane copyright *
Airplane
Copyright (C) 2020 Technove LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
diff --git a/net/minecraft/world/entity/projectile/Projectile.java b/net/minecraft/world/entity/projectile/Projectile.java
index 4487c03183d20a187d391dd124abb7b926508b5b..84c846d2ef4990befb2891631ac5ae16d881401b 100644
--- a/net/minecraft/world/entity/projectile/Projectile.java
+++ b/net/minecraft/world/entity/projectile/Projectile.java
@@ -53,6 +53,55 @@ public abstract class Projectile extends Entity implements TraceableEntity {
super(entityType, level);
}
+ // Gale start - Airplane - reduce projectile chunk loading
+ private static int chunksLoadedThisTick = 0;
+ private static int chunksLoadedInTick;
+ private int chunksLoadedByProjectile = 0;
+
+ @Override
+ public void setPos(double x, double y, double z) {
+ int currentTick = net.minecraft.server.MinecraftServer.currentTick;
+
+ if (chunksLoadedInTick != currentTick) {
+ chunksLoadedInTick = currentTick;
+ chunksLoadedThisTick = 0;
+ }
+
+ int previousX = Mth.floor(this.getX()) >> 4, previousZ = Mth.floor(this.getZ()) >> 4;
+ int newX = Mth.floor(x) >> 4, newZ = Mth.floor(z) >> 4;
+
+ if (previousX != newX || previousZ != newZ) {
+ boolean isLoaded = ((net.minecraft.server.level.ServerChunkCache) this.level().getChunkSource()).getChunkAtIfLoadedImmediately(newX, newZ) != null;
+
+ if (!isLoaded) {
+ var maxProjectileChunkLoadsConfig = this.level().galeConfig().smallOptimizations.maxProjectileChunkLoads;
+ int maxChunkLoadsPerTick = maxProjectileChunkLoadsConfig.perTick;
+
+ if (maxChunkLoadsPerTick >= 0 && chunksLoadedThisTick > maxChunkLoadsPerTick) {
+ return;
+ }
+
+ int maxChunkLoadsPerProjectile = maxProjectileChunkLoadsConfig.perProjectile.max;
+
+ if (maxChunkLoadsPerProjectile >= 0 && this.chunksLoadedByProjectile >= maxChunkLoadsPerProjectile) {
+ if (maxProjectileChunkLoadsConfig.perProjectile.removeFromWorldAfterReachLimit) {
+ this.discard();
+ } else if (maxProjectileChunkLoadsConfig.perProjectile.resetMovementAfterReachLimit) {
+ this.setDeltaMovement(0, this.getDeltaMovement().y, 0);
+ }
+
+ return;
+ }
+
+ chunksLoadedThisTick++;
+ this.chunksLoadedByProjectile++;
+ }
+ }
+
+ super.setPos(x, y, z);
+ }
+ // Gale end - Airplane - reduce projectile chunk loading
+
public void setOwner(@Nullable Entity owner) {
if (owner != null) {
this.ownerUUID = owner.getUUID();

View File

@@ -0,0 +1,83 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Wed, 23 Nov 2022 16:29:01 +0100
Subject: [PATCH] Predict Halloween
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
diff --git a/net/minecraft/world/entity/ambient/Bat.java b/net/minecraft/world/entity/ambient/Bat.java
index eb9fb57440f498079182030a46034008d3f6b5e8..65a9ea8d4a208f447b5e78b58b10a0917e35e4f2 100644
--- a/net/minecraft/world/entity/ambient/Bat.java
+++ b/net/minecraft/world/entity/ambient/Bat.java
@@ -244,11 +244,66 @@ public class Bat extends AmbientCreature {
}
}
+ // Gale start - predict Halloween
+ /**
+ * The 1-indexed month of the year that Halloween starts (inclusive).
+ */
+ private static final int halloweenStartMonthOfYear = 10;
+
+ /**
+ * The 1-indexed day of the month that Halloween starts (inclusive).
+ */
+ private static final int halloweenStartDayOfMonth = 20;
+
+ /**
+ * The 1-indexed month of the year that Halloween ends (exclusive).
+ */
+ private static final int halloweenEndMonthOfYear = 11;
+
+ /**
+ * The 1-indexed day of the month that Halloween ends (exclusive).
+ */
+ private static final int halloweenEndDayOfMonth = 4;
+
+ /**
+ * The next start of Halloween, given as milliseconds since the Unix epoch.
+ * Will be 0 while not computed yet.
+ */
+ private static long nextHalloweenStart = 0;
+
+ /**
+ * The next end of Halloween, given as milliseconds since the Unix epoch.
+ * Will be 0 while not computed yet.
+ */
+ private static long nextHalloweenEnd = 0;
+
+ // The Halloween begins at 10/20 0:00, and end with 11/04 0:00
+ // Only when the current Halloween period ends, the `nextHalloweenStart`
+ // and `nextHalloweenEnd` will adjust to the epoch ms of date of next year
+ // These two fields will not change during current Halloween period.
private static boolean isHalloween() {
- LocalDate localDate = LocalDate.now();
- int i = localDate.get(ChronoField.DAY_OF_MONTH);
- int i1 = localDate.get(ChronoField.MONTH_OF_YEAR);
- return i1 == 10 && i >= 20 || i1 == 11 && i <= 3;
+ long currentEpochMillis = System.currentTimeMillis();
+
+ if (currentEpochMillis > nextHalloweenEnd) {
+ // Update prediction
+
+ java.time.OffsetDateTime currentDate = java.time.OffsetDateTime.now();
+ int currentMonthOfYear = currentDate.getMonth().getValue();
+ int currentDayOfMonth = currentDate.getDayOfMonth();
+
+ java.time.OffsetDateTime nextHalloweenStartDate = currentDate.withMonth(halloweenStartMonthOfYear).withDayOfMonth(halloweenStartDayOfMonth)
+ .withHour(0).withMinute(0).withSecond(0).withNano(0); // Adjust to directly start or end at zero o'clock
+
+ if (currentMonthOfYear >= halloweenEndMonthOfYear && currentDayOfMonth >= halloweenEndDayOfMonth) {
+ nextHalloweenStartDate = nextHalloweenStartDate.plusYears(1);
+ }
+
+ nextHalloweenStart = nextHalloweenStartDate.toInstant().toEpochMilli();
+ nextHalloweenEnd = nextHalloweenStartDate.withMonth(halloweenEndMonthOfYear).withDayOfMonth(halloweenEndDayOfMonth).toInstant().toEpochMilli();
+ }
+
+ return currentEpochMillis >= nextHalloweenStart;
+ // Gale end - predict Halloween
}
private void setupAnimationStates() {

View File

@@ -0,0 +1,58 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Wed, 23 Nov 2022 19:53:35 +0100
Subject: [PATCH] Reduce enderman teleport chunk lookups
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
This patch is based on the following patch:
"Reduce chunk loading & lookups"
By: Paul Sauve <paul@technove.co>
As part of: Airplane (https://github.com/TECHNOVE/Airplane)
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
* Airplane copyright *
Airplane
Copyright (C) 2020 Technove LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
diff --git a/net/minecraft/world/entity/monster/EnderMan.java b/net/minecraft/world/entity/monster/EnderMan.java
index ab7f7846d3fc0252c6f71277b3e67d7a785a96b5..6c2bfad0ad7a5c20cd6eeba9fdc713c85c357ef4 100644
--- a/net/minecraft/world/entity/monster/EnderMan.java
+++ b/net/minecraft/world/entity/monster/EnderMan.java
@@ -300,11 +300,19 @@ public class EnderMan extends Monster implements NeutralMob {
private boolean teleport(double x, double y, double z) {
BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos(x, y, z);
- while (mutableBlockPos.getY() > this.level().getMinY() && !this.level().getBlockState(mutableBlockPos).blocksMotion()) {
+ // Gale start - Airplane - single chunk lookup
+ net.minecraft.world.level.chunk.LevelChunk chunk = this.level().getChunkIfLoaded(mutableBlockPos);
+
+ if (chunk == null) {
+ return false;
+ }
+
+ while (mutableBlockPos.getY() > this.level().getMinY() && !chunk.getBlockState(mutableBlockPos).blocksMotion()) {
+ // Gale end - Airplane - single chunk lookup
mutableBlockPos.move(Direction.DOWN);
}
- BlockState blockState = this.level().getBlockState(mutableBlockPos);
+ BlockState blockState = chunk.getBlockState(mutableBlockPos); // Gale - Airplane - single chunk lookup
boolean flag = blockState.blocksMotion();
boolean isWater = blockState.getFluidState().is(FluidTags.WATER);
if (flag && !isWater) {

View File

@@ -0,0 +1,65 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Wed, 23 Nov 2022 20:12:48 +0100
Subject: [PATCH] Reduce acquire POI for stuck entities
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
This patch is based on the following patch:
"Skip POI finding if stuck in vehicle"
By: Paul Sauve <paul@technove.co>
As part of: Airplane (https://github.com/TECHNOVE/Airplane)
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
* Airplane copyright *
Airplane
Copyright (C) 2020 Technove LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
diff --git a/net/minecraft/world/entity/ai/behavior/AcquirePoi.java b/net/minecraft/world/entity/ai/behavior/AcquirePoi.java
index 9de13a78b2a8be181c02ab330bfa9abb936a83db..7470150b5c613ae31d94170d9f5eedac67add63d 100644
--- a/net/minecraft/world/entity/ai/behavior/AcquirePoi.java
+++ b/net/minecraft/world/entity/ai/behavior/AcquirePoi.java
@@ -28,6 +28,13 @@ import org.apache.commons.lang3.mutable.MutableLong;
public class AcquirePoi {
public static final int SCAN_RANGE = 48;
+ // Gale start - Airplane - reduce acquire POI for stuck entities
+ private static void addAdditionalTimeToMutableLongIfMobIsStuck(MutableLong mutableLong, net.minecraft.server.level.ServerLevel level, PathfinderMob mob) {
+ long stuckEntityAdditionalWaitTime = level.galeConfig().smallOptimizations.reducedIntervals.acquirePoiForStuckEntity;
+ mutableLong.add(stuckEntityAdditionalWaitTime <= 0L ? 0L : mob.getNavigation().isStuck() ? stuckEntityAdditionalWaitTime : 0L);
+ }
+ // Gale end - Airplane - reduce acquire POI for stuck entities
+
public static BehaviorControl<PathfinderMob> create(
Predicate<Holder<PoiType>> acquirablePois,
MemoryModuleType<GlobalPos> acquiringMemory,
@@ -65,12 +72,13 @@ public class AcquirePoi {
return false;
} else if (mutableLong.getValue() == 0L) {
mutableLong.setValue(level.getGameTime() + level.random.nextInt(20));
+ addAdditionalTimeToMutableLongIfMobIsStuck(mutableLong, level, mob); // Gale - Airplane - reduce acquire POI for stuck entities
return false;
} else if (level.getGameTime() < mutableLong.getValue()) {
return false;
} else {
mutableLong.setValue(time + 20L + level.getRandom().nextInt(20));
- if (mob.getNavigation().isStuck()) mutableLong.add(200); // Paper - Perf: Wait an additional 10s to check again if they're stuck // TODO Modifies Vanilla behavior, add config option
+ addAdditionalTimeToMutableLongIfMobIsStuck(mutableLong, level, mob); // Paper - Perf: Wait an additional 10s to check again if they're stuck // TODO Modifies Vanilla behavior, add config option // Gale - Airplane - reduce acquire POI for stuck entities
PoiManager poiManager = level.getPoiManager();
map.long2ObjectEntrySet().removeIf(entry -> !entry.getValue().isStillValid(time));
Predicate<BlockPos> predicate1 = pos -> {

View File

@@ -0,0 +1,57 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Wed, 23 Nov 2022 20:21:06 +0100
Subject: [PATCH] Check targeting range before getting visibility
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
This patch is based on the following patch:
"Early return optimization for target finding"
By: Paul Sauve <paul@technove.co>
As part of: Airplane (https://github.com/TECHNOVE/Airplane)
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
* Airplane copyright *
Airplane
Copyright (C) 2020 Technove LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
diff --git a/net/minecraft/world/entity/ai/targeting/TargetingConditions.java b/net/minecraft/world/entity/ai/targeting/TargetingConditions.java
index 2f8920d8ee765d057a22d76f24f7d7dc1b0b17ca..17a08a3af468093668a41f154c2beb69c6617efa 100644
--- a/net/minecraft/world/entity/ai/targeting/TargetingConditions.java
+++ b/net/minecraft/world/entity/ai/targeting/TargetingConditions.java
@@ -75,9 +75,18 @@ public class TargetingConditions {
}
if (this.range > 0.0) {
- double d = this.testInvisible ? target.getVisibilityPercent(entity) : 1.0;
- double max = Math.max(this.range * d, 2.0);
+ // Gale start - Airplane - check targeting range before getting visibility
+ // d = invisibility percent, max = follow range adjusted for invisibility, d1 = distance
double d1 = entity.distanceToSqr(target.getX(), target.getY(), target.getZ());
+ double followRangeRaw = this.range;
+
+ if (d1 > followRangeRaw * followRangeRaw) { // the actual follow range will always be this value or smaller, so if the distance is larger then it never will return true after getting invis
+ return false;
+ }
+
+ double d = this.testInvisible ? target.getVisibilityPercent(entity) : 1.0;
+ double max = Math.max(followRangeRaw * d, 2.0);
+ // Gale end - Airplane - check targeting range before getting visibility
if (d1 > max * max) {
return false;
}

View File

@@ -0,0 +1,71 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Wed, 23 Nov 2022 20:40:40 +0100
Subject: [PATCH] Cache on climbable check
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
This patch is based on the following patch:
"Cache climbing check for activation"
By: Paul Sauve <paul@technove.co>
As part of: Airplane (https://github.com/TECHNOVE/Airplane)
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
* Airplane copyright *
Airplane
Copyright (C) 2020 Technove LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
diff --git a/io/papermc/paper/entity/activation/ActivationRange.java b/io/papermc/paper/entity/activation/ActivationRange.java
index 2ebee223085fe7926c7f3e555df19ae69f36157e..602ed4c5556723e54a80ccc3481af31109d5a0a6 100644
--- a/io/papermc/paper/entity/activation/ActivationRange.java
+++ b/io/papermc/paper/entity/activation/ActivationRange.java
@@ -215,7 +215,7 @@ public final class ActivationRange {
}
// special cases.
if (entity instanceof final LivingEntity living) {
- if (living.onClimbable() || living.jumping || living.hurtTime > 0 || !living.activeEffects.isEmpty() || living.isFreezing()) {
+ if (living.onClimbableCached() || living.jumping || living.hurtTime > 0 || !living.activeEffects.isEmpty() || living.isFreezing()) { // Gale - Airplane - cache on climbable check - use cached
return 1;
}
if (entity instanceof final Mob mob && mob.getTarget() != null) {
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
index 07df62b79a4ee9c9da77cac8615fad5463628204..bb687f048be9edfde75d13354dd3265593e83e9f 100644
--- a/net/minecraft/world/entity/LivingEntity.java
+++ b/net/minecraft/world/entity/LivingEntity.java
@@ -2083,6 +2083,21 @@ public abstract class LivingEntity extends Entity implements Attackable {
return this.lastClimbablePos;
}
+
+ // Gale start - Airplane - cache on climbable check
+ private boolean cachedOnClimbable = false;
+ private BlockPos lastClimbingPosition = null;
+
+ public boolean onClimbableCached() {
+ if (!this.blockPosition().equals(this.lastClimbingPosition)) {
+ this.cachedOnClimbable = this.onClimbable();
+ this.lastClimbingPosition = this.blockPosition();
+ }
+
+ return this.cachedOnClimbable;
+ }
+ // Gale end - Airplane - cache on climbable check
+
public boolean onClimbable() {
if (this.isSpectator()) {
return false;

View File

@@ -0,0 +1,350 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Mon, 26 Dec 2022 13:47:57 +0100
Subject: [PATCH] Gale metrics
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
diff --git a/src/main/java/ca/spottedleaf/moonrise/common/util/MoonriseCommon.java b/src/main/java/ca/spottedleaf/moonrise/common/util/MoonriseCommon.java
index 632920e04686d8a0fd0a60e87348be1fe7862a3c..ba0dd850f90564fab3a5b922bb28d24490180417 100644
--- a/src/main/java/ca/spottedleaf/moonrise/common/util/MoonriseCommon.java
+++ b/src/main/java/ca/spottedleaf/moonrise/common/util/MoonriseCommon.java
@@ -11,6 +11,10 @@ import java.util.function.Consumer;
public final class MoonriseCommon {
private static final Logger LOGGER = LogUtils.getClassLogger();
+ // Gale start - metrics - chunk system IO threads
+ public static int chunkSystemIOThreads;
+ public static int chunkSystemWorkerThreads;
+ // Gale end - metrics - chunk system IO threads
public static final PrioritisedThreadPool WORKER_POOL = new PrioritisedThreadPool(
new Consumer<>() {
@@ -54,6 +58,11 @@ public final class MoonriseCommon {
final int ioThreads = Math.max(1, configIoThreads);
+ // Gale start - metrics - chunk system IO threads
+ chunkSystemIOThreads = ioThreads;
+ chunkSystemWorkerThreads = workerThreads;
+ // Gale end - metrics - chunk system IO threads
+
WORKER_POOL.adjustThreadCount(workerThreads);
IO_POOL.adjustThreadCount(ioThreads);
diff --git a/src/main/java/com/destroystokyo/paper/Metrics.java b/src/main/java/com/destroystokyo/paper/Metrics.java
index 6abc57669e87f7f98f3b76af3c0e50825fea6eb1..d561202169d6f19c1e9ad8009415af9eaa707b96 100644
--- a/src/main/java/com/destroystokyo/paper/Metrics.java
+++ b/src/main/java/com/destroystokyo/paper/Metrics.java
@@ -593,7 +593,7 @@ public class Metrics {
boolean logFailedRequests = config.getBoolean("logFailedRequests", false);
// Only start Metrics, if it's enabled in the config
if (config.getBoolean("enabled", true)) {
- Metrics metrics = new Metrics("Paper", serverUUID, logFailedRequests, Bukkit.getLogger());
+ Metrics metrics = new Metrics("Gale", serverUUID, logFailedRequests, Bukkit.getLogger()); // Gale - branding changes - metrics
metrics.addCustomChart(new Metrics.SimplePie("minecraft_version", () -> {
String minecraftVersion = Bukkit.getVersion();
@@ -603,20 +603,20 @@ public class Metrics {
metrics.addCustomChart(new Metrics.SingleLineChart("players", () -> Bukkit.getOnlinePlayers().size()));
metrics.addCustomChart(new Metrics.SimplePie("online_mode", () -> Bukkit.getOnlineMode() ? "online" : "offline"));
- final String paperVersion;
+ final String galeVersion; // Gale - branding changes - metrics
final String implVersion = org.bukkit.craftbukkit.Main.class.getPackage().getImplementationVersion();
if (implVersion != null) {
final String buildOrHash = implVersion.substring(implVersion.lastIndexOf('-') + 1);
- paperVersion = "git-Paper-%s-%s".formatted(Bukkit.getServer().getMinecraftVersion(), buildOrHash);
+ galeVersion = "git-Gale-%s-%s".formatted(Bukkit.getServer().getMinecraftVersion(), buildOrHash); // Gale - branding changes - metrics
} else {
- paperVersion = "unknown";
+ galeVersion = "unknown"; // Gale - branding changes - metrics
}
- metrics.addCustomChart(new Metrics.SimplePie("paper_version", () -> paperVersion));
+ metrics.addCustomChart(new Metrics.SimplePie("gale_version", () -> galeVersion)); // Gale - branding changes - metrics
metrics.addCustomChart(new Metrics.DrilldownPie("java_version", () -> {
- Map<String, Map<String, Integer>> map = new HashMap<>();
+ Map<String, Map<String, Integer>> map = new HashMap<>(2); // Gale - metrics - reduce HashMap capacity
String javaVersion = System.getProperty("java.version");
- Map<String, Integer> entry = new HashMap<>();
+ Map<String, Integer> entry = new HashMap<>(2); // Gale - metrics - reduce HashMap capacity
entry.put(javaVersion, 1);
// http://openjdk.java.net/jeps/223
@@ -645,7 +645,7 @@ public class Metrics {
}));
metrics.addCustomChart(new Metrics.DrilldownPie("legacy_plugins", () -> {
- Map<String, Map<String, Integer>> map = new HashMap<>();
+ Map<String, Map<String, Integer>> map = new HashMap<>(2); // Gale - metrics - reduce HashMap capacity
// count legacy plugins
int legacy = 0;
@@ -656,7 +656,7 @@ public class Metrics {
}
// insert real value as lower dimension
- Map<String, Integer> entry = new HashMap<>();
+ Map<String, Integer> entry = new HashMap<>(2); // Gale - metrics - reduce HashMap capacity
entry.put(String.valueOf(legacy), 1);
// create buckets as higher dimension
@@ -676,6 +676,256 @@ public class Metrics {
return map;
}));
+
+ // Gale start - metrics - proxy
+ metrics.addCustomChart(new Metrics.DrilldownPie("proxy", () -> {
+ String type;
+ boolean onlineMode;
+ var proxiesConfig = io.papermc.paper.configuration.GlobalConfiguration.get().proxies;
+ if (proxiesConfig.velocity.enabled) {
+ type = "Velocity";
+ onlineMode = proxiesConfig.velocity.onlineMode;
+ } else if (org.spigotmc.SpigotConfig.bungee) {
+ type = "BungeeCord";
+ onlineMode = proxiesConfig.bungeeCord.onlineMode;
+ } else {
+ type = "none";
+ onlineMode = Bukkit.getOnlineMode();
+ }
+
+ Map<String, Map<String, Integer>> map = new HashMap<>(2);
+
+ // insert type and online mode as lower dimension
+ Map<String, Integer> entry = new HashMap<>(2);
+ entry.put(type + " (" + (onlineMode ? "online" : "offline") + ")", 1);
+
+ // create type as higher dimension
+ map.put(type, entry);
+
+ return map;
+ }));
+ // Gale end - metrics - proxy
+
+ // Gale start - metrics - Java VM
+ Map<String, Map<String, Integer>> javaVirtualMachineMap = new HashMap<>(2);
+ {
+ Map<String, Integer> entry = new HashMap<>(2);
+ String vmVendor = null;
+ try {
+ vmVendor = System.getProperty("java.vm.vendor");
+ } catch (Exception ignored) {}
+ entry.put(vmVendor == null ? "Unknown" : vmVendor, 1);
+ String vmName = null;
+ try {
+ vmName = System.getProperty("java.vm.name");
+ } catch (Exception ignored) {}
+ javaVirtualMachineMap.put(vmName == null ? "Unknown" : vmName, entry);
+ }
+ metrics.addCustomChart(new Metrics.DrilldownPie("java_virtual_machine", () -> javaVirtualMachineMap));
+ // Gale end - metrics - Java VM
+
+ // Gale start - metrics - per-server player count
+ metrics.addCustomChart(new Metrics.DrilldownPie("per_server_player_count", () -> {
+ Map<String, Map<String, Integer>> map = new HashMap<>(2);
+
+ // count players
+ int playerCount = Bukkit.getOnlinePlayers().size();
+
+ // insert real value as lower dimension
+ Map<String, Integer> entry = new HashMap<>(2);
+ entry.put(String.valueOf(playerCount), 1);
+
+ // create buckets as higher dimension
+ if (playerCount <= 5) {
+ map.put(String.valueOf(playerCount), entry);
+ } else if (playerCount > 1000) {
+ map.put("> 1000", entry);
+ } else {
+ int divisor;
+ if (playerCount <= 50) {
+ divisor = 5;
+ } else if (playerCount <= 100) {
+ divisor = 10;
+ } else if (playerCount <= 250) {
+ divisor = 25;
+ } else if (playerCount <= 500) {
+ divisor = 50;
+ } else {
+ divisor = 100;
+ }
+ int start = (playerCount - 1) / divisor * divisor + 1;
+ int end = start + divisor - 1;
+ map.put(start + "-" + end, entry);
+ }
+
+ return map;
+ }));
+ // Gale end - metrics - per-server player count
+
+ // Gale start - metrics - plugin count
+ metrics.addCustomChart(new Metrics.DrilldownPie("plugin_count", () -> {
+ Map<String, Map<String, Integer>> map = new HashMap<>(2);
+
+ // count plugins
+ int pluginCount = Bukkit.getPluginManager().getPlugins().length;
+
+ // insert real value as lower dimension
+ Map<String, Integer> entry = new HashMap<>(2);
+ entry.put(String.valueOf(pluginCount), 1);
+
+ // create buckets as higher dimension
+ if (pluginCount <= 5) {
+ map.put(String.valueOf(pluginCount), entry);
+ } else if (pluginCount > 1000) {
+ map.put("> 1000", entry);
+ } else {
+ int divisor;
+ if (pluginCount <= 50) {
+ divisor = 5;
+ } else if (pluginCount <= 100) {
+ divisor = 10;
+ } else if (pluginCount <= 250) {
+ divisor = 25;
+ } else if (pluginCount <= 500) {
+ divisor = 50;
+ } else {
+ divisor = 100;
+ }
+ int start = (pluginCount - 1) / divisor * divisor + 1;
+ int end = start + divisor - 1;
+ map.put(start + "-" + end, entry);
+ }
+
+ return map;
+ }));
+ // Gale end - metrics - plugin count
+
+ // Gale start - metrics - netty threads
+ metrics.addCustomChart(new Metrics.SimplePie("netty_thread_count", () -> {
+ // Try to get the number of Netty threads from the system property
+ try {
+ return System.getProperty("io.netty.eventLoopThreads");
+ } catch (Exception ignored) {}
+ // Otherwise, we fall back to nothing currently (reading from the Spigot configuration causes a re-read which is undesirable)
+ return null;
+ }));
+ // Gale end - metrics - netty threads
+
+ // Gale start - metrics - chunk system threads
+ metrics.addCustomChart(new Metrics.SimplePie("chunk_system_io_thread_count", () -> String.valueOf(ca.spottedleaf.moonrise.common.util.MoonriseCommon.chunkSystemIOThreads)));
+ metrics.addCustomChart(new Metrics.SimplePie("chunk_system_worker_thread_count", () -> String.valueOf(ca.spottedleaf.moonrise.common.util.MoonriseCommon.chunkSystemWorkerThreads)));
+ // Gale end - metrics - chunk system threads
+
+ // Gale start - metrics - physical cores
+ metrics.addCustomChart(new Metrics.SimplePie("physical_core_count", () -> {
+ try {
+ int physicalProcessorCount = new oshi.SystemInfo().getHardware().getProcessor().getPhysicalProcessorCount();
+ if (physicalProcessorCount > 0) {
+ return String.valueOf(physicalProcessorCount);
+ }
+ } catch (Exception ignored) {}
+ return null;
+ }));
+ // Gale end - metrics - physical cores
+
+ // Gale start - metrics - processor frequency
+ metrics.addCustomChart(new Metrics.DrilldownPie("processor_frequency", () -> {
+ try {
+ long processorFrequency = new oshi.SystemInfo().getHardware().getProcessor().getProcessorIdentifier().getVendorFreq();
+ if (processorFrequency > 0) {
+
+ Map<String, Map<String, Integer>> map = new HashMap<>(2);
+
+ // use MHz as lower dimension
+ var flooredMHz = processorFrequency / 1_000_000L;
+ Map<String, Integer> entry = new HashMap<>(2);
+ if (flooredMHz < 1) {
+ entry.put("< 1 MHz", 1);
+ } else if (flooredMHz < 1000) {
+ entry.put(flooredMHz + " MHz", 1);
+ } else {
+ // Add a comma
+ StringBuilder flooredMHzAfterComma = new StringBuilder(String.valueOf(flooredMHz % 1000));
+ while (flooredMHzAfterComma.length() < 3) {
+ flooredMHzAfterComma.insert(0, "0");
+ }
+ entry.put((flooredMHz / 1000) + "," + flooredMHzAfterComma + " MHz", 1);
+ }
+
+ // use tenth of GHz as higher dimension
+ long flooredTenthGHz = processorFrequency / 100_000_000L;
+ if (flooredTenthGHz < 1) {
+ map.put("< 0.1 GHz", entry);
+ } else {
+ // Add a dot
+ map.put((flooredTenthGHz / 10) + "." + (flooredTenthGHz % 10) + " GHz", entry);
+ }
+
+ return map;
+
+ }
+ } catch (Exception ignored) {}
+ return null;
+ }));
+ // Gale end - metrics - processor frequency
+
+ // Gale start - metrics - physical memory
+ metrics.addCustomChart(new Metrics.DrilldownPie("physical_memory_total", () -> {
+ try {
+ long physicalMemory = new oshi.SystemInfo().getHardware().getMemory().getTotal();
+ if (physicalMemory > 0) {
+
+ Map<String, Map<String, Integer>> map = new HashMap<>(2);
+
+ // use floored MB as lower dimension
+ var flooredMB = physicalMemory / (1L << 20);
+ Map<String, Integer> entry = new HashMap<>(2);
+ entry.put(flooredMB < 1 ? "< 1 MB" : flooredMB + " MB", 1);
+
+ // use floored GB as higher dimension
+ var flooredGB = physicalMemory / (1L << 30);
+ map.put(flooredGB < 1 ? "< 1 GB" : flooredGB + " GB", entry);
+
+ return map;
+
+ }
+ } catch (Exception ignored) {}
+ return null;
+ }));
+ // Gale end - metrics - physical memory
+
+ // Gale start - metrics - runtime max memory
+ metrics.addCustomChart(new Metrics.DrilldownPie("runtime_max_memory", () -> {
+
+ // get memory limit
+ long maxMemory = Runtime.getRuntime().maxMemory();
+ if (maxMemory <= 0) {
+ return null;
+ }
+
+ Map<String, Map<String, Integer>> map = new HashMap<>(2);
+
+ // in the case of no limit
+ if (maxMemory == Long.MAX_VALUE) {
+ Map<String, Integer> entry = new HashMap<>(2);
+ entry.put("no limit", 1);
+ map.put("no limit", entry);
+ return map;
+ }
+
+ // use floored MB as lower dimension
+ var flooredMB = maxMemory / (1L << 20);
+ Map<String, Integer> entry = new HashMap<>(2);
+ entry.put(flooredMB < 1 ? "< 1 MB" : flooredMB + " MB", 1);
+
+ // use floored GB as higher dimension
+ var flooredGB = maxMemory / (1L << 30);
+ map.put(flooredGB < 1 ? "< 1 GB" : flooredGB + " GB", entry);
+
+ return map;
+ }));
+ // Gale end - metrics - runtime max memory
+
}
}

View File

@@ -0,0 +1,29 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Wed, 9 Aug 2023 19:04:22 +0200
Subject: [PATCH] Gale semantic version
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
diff --git a/src/main/java/com/destroystokyo/paper/Metrics.java b/src/main/java/com/destroystokyo/paper/Metrics.java
index d561202169d6f19c1e9ad8009415af9eaa707b96..612eacf43f8b6b92354fa43479bd0ead728dd7b9 100644
--- a/src/main/java/com/destroystokyo/paper/Metrics.java
+++ b/src/main/java/com/destroystokyo/paper/Metrics.java
@@ -926,6 +926,16 @@ public class Metrics {
}));
// Gale end - metrics - runtime max memory
+ // Gale start - semantic version - include in metrics
+ Map<String, Map<String, Integer>> semanticVersionMap = new HashMap<>(2);
+ {
+ Map<String, Integer> entry = new HashMap<>(2);
+ entry.put(org.galemc.gale.version.GaleSemanticVersion.version, 1);
+ semanticVersionMap.put(org.galemc.gale.version.GaleSemanticVersion.majorMinorVersion, entry);
+ }
+ metrics.addCustomChart(new Metrics.DrilldownPie("gale_semantic_version", () -> semanticVersionMap));
+ // Gale end - semantic version - include in metrics
+
}
}

View File

@@ -0,0 +1,172 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Wed, 23 Nov 2022 21:05:47 +0100
Subject: [PATCH] Gale configuration
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
This patch is based on the following patch:
"Paper config files"
By: Jake Potrebic <jake.m.potrebic@gmail.com>
As part of: Paper (https://github.com/PaperMC/Paper)
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
diff --git a/src/main/java/io/papermc/paper/configuration/Configurations.java b/src/main/java/io/papermc/paper/configuration/Configurations.java
index 4a9258b62db3a9d1150f0dfbe916fa549b596686..7c2f3b46f94989e532694ce3fbba90489caceb7f 100644
--- a/src/main/java/io/papermc/paper/configuration/Configurations.java
+++ b/src/main/java/io/papermc/paper/configuration/Configurations.java
@@ -94,7 +94,7 @@ public abstract class Configurations<G, W> {
};
}
- static <T> CheckedFunction<ConfigurationNode, T, SerializationException> reloader(Class<T> type, T instance) {
+ public static <T> CheckedFunction<ConfigurationNode, T, SerializationException> reloader(Class<T> type, T instance) { // Gale - Gale configuration
return node -> {
ObjectMapper.Factory factory = (ObjectMapper.Factory) Objects.requireNonNull(node.options().serializers().get(type));
ObjectMapper.Mutable<T> mutable = (ObjectMapper.Mutable<T>) factory.get(type);
@@ -168,7 +168,7 @@ public abstract class Configurations<G, W> {
final YamlConfigurationLoader loader = result.loader();
final ConfigurationNode node = loader.load();
if (result.isNewFile()) { // add version to new files
- node.node(Configuration.VERSION_FIELD).raw(this.worldConfigVersion());
+ node.node(Configuration.VERSION_FIELD).raw(getWorldConfigurationCurrentVersion()); // Gale - Gale configuration
} else {
this.verifyWorldConfigVersion(contextMap, node);
}
@@ -230,7 +230,7 @@ public abstract class Configurations<G, W> {
.build();
final ConfigurationNode worldNode = worldLoader.load();
if (newFile) { // set the version field if new file
- worldNode.node(Configuration.VERSION_FIELD).set(this.worldConfigVersion());
+ worldNode.node(Configuration.VERSION_FIELD).set(getWorldConfigurationCurrentVersion()); // Gale - Gale configuration
} else {
this.verifyWorldConfigVersion(contextMap, worldNode);
}
@@ -356,4 +356,25 @@ public abstract class Configurations<G, W> {
return "ContextKey{" + this.name + "}";
}
}
+
+ // Gale start - Gale configuration
+
+ public static final String legacyWorldsSectionKey = "__________WORLDS__________";
+ public static final String legacyWorldDefaultsSectionKey = "__defaults__";
+
+ @Deprecated
+ public org.bukkit.configuration.file.YamlConfiguration createLegacyObject(final net.minecraft.server.MinecraftServer server) {
+ org.bukkit.configuration.file.YamlConfiguration global = org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(this.globalFolder.resolve(this.globalConfigFileName).toFile());
+ org.bukkit.configuration.ConfigurationSection worlds = global.createSection(legacyWorldsSectionKey);
+ worlds.set(legacyWorldDefaultsSectionKey, org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(this.globalFolder.resolve(this.defaultWorldConfigFileName).toFile()));
+ for (ServerLevel level : server.getAllLevels()) {
+ worlds.set(level.getWorld().getName(), org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(getWorldConfigFile(level).toFile()));
+ }
+ return global;
+ }
+
+ public abstract int getWorldConfigurationCurrentVersion();
+
+ // Gale end - Gale configuration
+
}
diff --git a/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java b/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java
index e48fa405d92fab221fa8331b65c8f324e801d439..352d62385e56d5805510596ec9424e5d14336861 100644
--- a/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java
+++ b/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java
@@ -330,7 +330,7 @@ public class PaperConfigurations extends Configurations<GlobalConfiguration, Wor
}
}
- private static ContextMap createWorldContextMap(ServerLevel level) {
+ public static ContextMap createWorldContextMap(ServerLevel level) { // Gale - Gale configuration
return createWorldContextMap(level.levelStorageAccess.levelDirectory.path(), level.serverLevelData.getLevelName(), level.dimension().location(), level.spigotConfig, level.registryAccess(), level.getGameRules());
}
@@ -433,17 +433,6 @@ public class PaperConfigurations extends Configurations<GlobalConfiguration, Wor
return Files.exists(legacyConfig) && Files.isRegularFile(legacyConfig);
}
- @Deprecated
- public YamlConfiguration createLegacyObject(final MinecraftServer server) {
- YamlConfiguration global = YamlConfiguration.loadConfiguration(this.globalFolder.resolve(this.globalConfigFileName).toFile());
- ConfigurationSection worlds = global.createSection("__________WORLDS__________");
- worlds.set("__defaults__", YamlConfiguration.loadConfiguration(this.globalFolder.resolve(this.defaultWorldConfigFileName).toFile()));
- for (ServerLevel level : server.getAllLevels()) {
- worlds.set(level.getWorld().getName(), YamlConfiguration.loadConfiguration(getWorldConfigFile(level).toFile()));
- }
- return global;
- }
-
@Deprecated
public static YamlConfiguration loadLegacyConfigFile(File configFile) throws Exception {
YamlConfiguration config = new YamlConfiguration();
@@ -466,9 +455,16 @@ public class PaperConfigurations extends Configurations<GlobalConfiguration, Wor
}
// Symlinks are not correctly checked in createDirectories
- static void createDirectoriesSymlinkAware(Path path) throws IOException {
+ public static void createDirectoriesSymlinkAware(Path path) throws IOException { // Gale - Gale configuration
if (!Files.isDirectory(path)) {
Files.createDirectories(path);
}
}
+
+ // Gale start - Gale configuration
+ @Override
+ public int getWorldConfigurationCurrentVersion() {
+ return WorldConfiguration.CURRENT_VERSION;
+ }
+ // Gale end - Gale configuration
}
diff --git a/src/main/java/io/papermc/paper/configuration/mapping/InnerClassFieldDiscoverer.java b/src/main/java/io/papermc/paper/configuration/mapping/InnerClassFieldDiscoverer.java
index 05339a176083af667c16f77d76dc1878dafce3f0..9ca55cba185b9de566f911b08d671bee50bca075 100644
--- a/src/main/java/io/papermc/paper/configuration/mapping/InnerClassFieldDiscoverer.java
+++ b/src/main/java/io/papermc/paper/configuration/mapping/InnerClassFieldDiscoverer.java
@@ -46,7 +46,19 @@ public final class InnerClassFieldDiscoverer implements FieldDiscoverer<Map<Fiel
return new InnerClassFieldDiscoverer(overrides);
}
- public static FieldDiscoverer<?> globalConfig() {
+ // Gale start - Gale configuration
+ public static FieldDiscoverer<?> galeWorldConfig(io.papermc.paper.configuration.Configurations.ContextMap contextMap) {
+ final Map<Class<?>, Object> overrides = Map.of(
+ org.galemc.gale.configuration.GaleWorldConfiguration.class, new org.galemc.gale.configuration.GaleWorldConfiguration(
+ contextMap.require(io.papermc.paper.configuration.PaperConfigurations.SPIGOT_WORLD_CONFIG_CONTEXT_KEY).get(),
+ contextMap.require(io.papermc.paper.configuration.Configurations.WORLD_KEY)
+ )
+ );
+ return new InnerClassFieldDiscoverer(overrides);
+ }
+ // Gale end - Gale configuration
+
+ public static FieldDiscoverer<?> globalConfig() { // Gale - Gale configuration
return new InnerClassFieldDiscoverer(Collections.emptyMap());
}
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 676e2b789ff598f6d6430249c9a7395224715c35..10560d5caa5a53410eb759cc43dde9d470a3de45 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -1064,6 +1064,7 @@ public final class CraftServer implements Server {
org.spigotmc.SpigotConfig.init((File) this.console.options.valueOf("spigot-settings")); // Spigot
this.console.paperConfigurations.reloadConfigs(this.console);
+ this.console.galeConfigurations.reloadConfigs(this.console); // Gale - Gale configuration
for (ServerLevel world : this.console.getAllLevels()) {
// world.serverLevelData.setDifficulty(config.difficulty); // Paper - per level difficulty
world.setSpawnSettings(world.serverLevelData.getDifficulty() != Difficulty.PEACEFUL && config.spawnMonsters); // Paper - per level difficulty (from MinecraftServer#setDifficulty(ServerLevel, Difficulty, boolean))
@@ -2942,6 +2943,14 @@ public final class CraftServer implements Server {
return CraftServer.this.console.paperConfigurations.createLegacyObject(CraftServer.this.console);
}
+ // Gale start - Gale configuration - API
+ @Override
+ public YamlConfiguration getGaleConfig()
+ {
+ return CraftServer.this.console.galeConfigurations.createLegacyObject(CraftServer.this.console);
+ }
+ // Gale end - Gale configuration - API
+
@Override
public void restart() {
CraftServer.this.restart();

View File

@@ -0,0 +1,26 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Sat, 26 Nov 2022 10:47:56 +0100
Subject: [PATCH] Gale commands
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
This patch is based on the following patch:
"Paper command"
By: Zach Brown <zach.brown@destroystokyo.com>
As part of: Paper (https://github.com/PaperMC/Paper)
Licensed under: MIT (https://opensource.org/licenses/MIT)
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 10560d5caa5a53410eb759cc43dde9d470a3de45..2675f1a11a8a7f27a1b7151d88e2fb1e45fc659d 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -1096,6 +1096,7 @@ public final class CraftServer implements Server {
this.reloadData();
org.spigotmc.SpigotConfig.registerCommands(); // Spigot
io.papermc.paper.command.PaperCommands.registerCommands(this.console); // Paper
+ org.galemc.gale.command.GaleCommands.registerCommands(this.console); // Gale - Gale commands - register commands
this.spark.registerCommandBeforePlugins(this); // Paper - spark
this.overrideAllCommandBlockCommands = this.commandsConfiguration.getStringList("command-block-overrides").contains("*");
this.ignoreVanillaPermissions = this.commandsConfiguration.getBoolean("ignore-vanilla-permissions");

View File

@@ -0,0 +1,20 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Fri, 25 Nov 2022 18:42:45 +0100
Subject: [PATCH] Set Gale permissions root
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
diff --git a/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java b/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java
index 7ad31b059c1c7a1a2fae1fa7a3359da5343e217d..11c857e6d42f23994dbded70fbe052e15db2dc4b 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java
@@ -5,6 +5,7 @@ import org.bukkit.util.permissions.DefaultPermissions;
public final class CraftDefaultPermissions {
private static final String ROOT = "minecraft";
+ public static final String GALE_ROOT = "gale"; // Gale - set Gale permissions root
private CraftDefaultPermissions() {}

View File

@@ -0,0 +1,20 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Wed, 31 Jul 2024 22:05:21 +0800
Subject: [PATCH] Leaf Bootstrap
org.bukkit.craftbukkit.Main#main -> LeafBootstrap -> PaperBootstrap -> ...
diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java
index a11fc64b4933a5abce0182ba46f1da22043eb0d8..e89c906dc07e52ea8d661e005d8531128ce4d080 100644
--- a/src/main/java/org/bukkit/craftbukkit/Main.java
+++ b/src/main/java/org/bukkit/craftbukkit/Main.java
@@ -240,7 +240,7 @@ public class Main {
System.setProperty("library.jansi.version", "Paper"); // Paper - set meaningless jansi version to prevent git builds from crashing on Windows
System.setProperty("jdk.console", "java.base"); // Paper - revert default console provider back to java.base so we can have our own jline
- io.papermc.paper.PaperBootstrap.boot(options);
+ org.dreeam.leaf.LeafBootstrap.boot(options); // Leaf - Leaf Boostrap
} catch (Throwable t) {
t.printStackTrace();
}

View File

@@ -0,0 +1,18 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Mon, 4 Nov 2024 23:07:27 -0500
Subject: [PATCH] Leaf Commands
diff --git a/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java b/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java
index 11c857e6d42f23994dbded70fbe052e15db2dc4b..ed275123642d929b51b93f7f2ea825858411a921 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java
@@ -6,6 +6,7 @@ import org.bukkit.util.permissions.DefaultPermissions;
public final class CraftDefaultPermissions {
private static final String ROOT = "minecraft";
public static final String GALE_ROOT = "gale"; // Gale - set Gale permissions root
+ public static final String LEAF_ROOT = "leaf"; // Leaf - Leaf commands
private CraftDefaultPermissions() {}

View File

@@ -0,0 +1,50 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Wed, 23 Nov 2022 16:22:47 +0100
Subject: [PATCH] Simpler ShapelessRecipe comparison for vanilla
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
This patch is based on the following patch:
"Simpler ShapelessRecipes comparison for Vanilla"
By: Paul Sauve <paul@technove.co>
As part of: Airplane (https://github.com/TECHNOVE/Airplane)
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
* Airplane description *
Paper added a fancy sorting comparison due to Bukkit recipes breaking
the vanilla one, however this is far more advanced than what you need
for all the vanilla recipes.
* Airplane copyright *
Airplane
Copyright (C) 2020 Technove LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java
index 7c989318dc7ad89bb0d9143fcaac1e4bba6f5907..a90b294a99072ab576e61ddacb60a036cb7f0f5a 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java
@@ -44,6 +44,6 @@ public class CraftShapelessRecipe extends ShapelessRecipe implements CraftRecipe
data.add(this.toNMS(i, true));
}
- MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.ShapelessRecipe(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), CraftItemStack.asNMSCopy(this.getResult()), data)));
+ MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.ShapelessRecipe(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), CraftItemStack.asNMSCopy(this.getResult()), data, true))); // Gale - Airplane - simpler ShapelessRecipe comparison for vanilla
}
}

View File

@@ -0,0 +1,50 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Wed, 23 Nov 2022 20:28:07 +0100
Subject: [PATCH] Print stack trace for plugins not shutting down tasks
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
This patch is based on the following patch:
"More debug for plugins not shutting down tasks"
By: Paul Sauve <paul@technove.co>
As part of: Airplane (https://github.com/TECHNOVE/Airplane)
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
* Airplane copyright *
Airplane
Copyright (C) 2020 Technove LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 2675f1a11a8a7f27a1b7151d88e2fb1e45fc659d..e2e7e09ca154ca1ccf38bb97c03caadef5048541 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -1159,6 +1159,13 @@ public final class CraftServer implements Server {
plugin.getPluginMeta().getDisplayName(),
"This plugin is not properly shutting down its async tasks when it is being shut down. This task may throw errors during the final shutdown logs and might not complete before process dies."
));
+ // Gale start - Airplane - print stack trace for plugins not shutting down tasks
+ getLogger().log(Level.SEVERE, String.format("%s Stacktrace", worker.getThread().getName()));
+
+ for (StackTraceElement element : worker.getThread().getStackTrace()) {
+ getLogger().log(Level.SEVERE, " " + element);
+ }
+ // Gale end - Airplane - print stack trace for plugins not shutting down tasks
if (console.isDebugging()) io.papermc.paper.util.TraceUtil.dumpTraceForThread(worker.getThread(), "still running"); // Paper - Debugging
}
}

View File

@@ -0,0 +1,65 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Thu, 24 Nov 2022 01:19:12 +0100
Subject: [PATCH] SIMD support
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
This patch is based on the following patch:
"Add SIMD utilities"
By: Kevin Raneri <kevin.raneri@gmail.com>
As part of: Pufferfish (https://github.com/pufferfish-gg/Pufferfish)
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
diff --git a/src/main/java/com/destroystokyo/paper/Metrics.java b/src/main/java/com/destroystokyo/paper/Metrics.java
index 612eacf43f8b6b92354fa43479bd0ead728dd7b9..a35c0af0c53bab4c1b3623e903d3057c816e5d3b 100644
--- a/src/main/java/com/destroystokyo/paper/Metrics.java
+++ b/src/main/java/com/destroystokyo/paper/Metrics.java
@@ -936,6 +936,46 @@ public class Metrics {
metrics.addCustomChart(new Metrics.DrilldownPie("gale_semantic_version", () -> semanticVersionMap));
// Gale end - semantic version - include in metrics
+ // Gale start - SIMD support - include in metrics
+ Map<String, Map<String, Integer>> simdSupportMap = new HashMap<>(2); // Empty until initialized
+ metrics.addCustomChart(new Metrics.DrilldownPie("simd_support", () -> {
+ if (!gg.pufferfish.pufferfish.simd.SIMDDetection.isInitialized()) {
+ return null;
+ }
+ if (simdSupportMap.isEmpty()) {
+ // Initialize
+ boolean isEnabled = gg.pufferfish.pufferfish.simd.SIMDDetection.isEnabled();
+
+ // use details as lower dimension
+ Map<String, Integer> entry = new HashMap<>(2);
+ String details;
+ if (isEnabled) {
+ details = "int " + gg.pufferfish.pufferfish.simd.SIMDDetection.intVectorBitSize() + "*" + gg.pufferfish.pufferfish.simd.SIMDDetection.intElementSize() + ", float " + gg.pufferfish.pufferfish.simd.SIMDDetection.floatVectorBitSize() + "*" + gg.pufferfish.pufferfish.simd.SIMDDetection.floatElementSize();
+ } else {
+ if (!gg.pufferfish.pufferfish.simd.SIMDDetection.supportingJavaVersion()) {
+ details = "unsupported Java";
+ try {
+ var javaVersion = gg.pufferfish.pufferfish.simd.SIMDDetection.getJavaVersion();
+ details += " (" + javaVersion + ")";
+ } catch (Throwable ignored) {}
+ } else if (!gg.pufferfish.pufferfish.simd.SIMDDetection.testRunCompleted()) {
+ details = "test failed";
+ } else if (gg.pufferfish.pufferfish.simd.SIMDDetection.unsupportingLaneSize()) {
+ details = "no supporting lane size";
+ } else {
+ details = "other reason";
+ }
+ }
+ entry.put(details, 1);
+
+ // use enabled or not as higher dimension
+ simdSupportMap.put(String.valueOf(isEnabled), entry);
+
+ }
+ return simdSupportMap;
+ }));
+ // Gale end - SIMD support - include in metrics
+
}
}

View File

@@ -0,0 +1,44 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Mon, 26 Dec 2022 02:11:29 +0100
Subject: [PATCH] Make book writing configurable
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
This patch is based on the following patch:
"Add option to disable books"
By: Kevin Raneri <kevin.raneri@gmail.com>
As part of: Pufferfish (https://github.com/pufferfish-gg/Pufferfish)
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
* Pufferfish description *
Books are commonly the target of duping-related exploits. If you
anticipate that your server will be an early target of duping attacks in
the event that new exploits are found, you may want to consider removing
the ability for non-privileged players to edit books. This patch allows
you to easily disable books, should you want to preemptively remove this
functionality before additional exploits are found.
diff --git a/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java b/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java
index ed275123642d929b51b93f7f2ea825858411a921..66b80378f8b383e1388cf6b7b0e9ed0f8bc08a63 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java
@@ -8,6 +8,8 @@ public final class CraftDefaultPermissions {
public static final String GALE_ROOT = "gale"; // Gale - set Gale permissions root
public static final String LEAF_ROOT = "leaf"; // Leaf - Leaf commands
+ public static final String writeBooks = GALE_ROOT + ".writebooks"; // Gale - Pufferfish - make book writing configurable
+
private CraftDefaultPermissions() {}
public static void registerCorePermissions() {
@@ -18,6 +20,7 @@ public final class CraftDefaultPermissions {
DefaultPermissions.registerPermission(CraftDefaultPermissions.ROOT + ".debugstick", "Gives the user the ability to use the debug stick in creative", org.bukkit.permissions.PermissionDefault.OP, parent);
DefaultPermissions.registerPermission(CraftDefaultPermissions.ROOT + ".debugstick.always", "Gives the user the ability to use the debug stick in all game modes", org.bukkit.permissions.PermissionDefault.FALSE/* , parent */); // Paper - should not have this parent, as it's not a "vanilla" utility
DefaultPermissions.registerPermission(CraftDefaultPermissions.ROOT + ".commandblock", "Gives the user the ability to use command blocks.", org.bukkit.permissions.PermissionDefault.OP, parent); // Paper
+ DefaultPermissions.registerPermission(writeBooks, "Gives the user the ability to write books even when writing books is disabled in the Gale configuration", org.bukkit.permissions.PermissionDefault.OP); // Gale - Pufferfish - make book writing configurable
parent.recalculatePermissibles();
}
}

View File

@@ -0,0 +1,36 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Wed, 23 Nov 2022 23:32:51 +0100
Subject: [PATCH] Optimize entity coordinate key
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
This patch is based on the following patch:
"Optimize entity coordinate key"
By: Kevin Raneri <kevin.raneri@gmail.com>
As part of: Pufferfish (https://github.com/pufferfish-gg/Pufferfish)
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
* Pufferfish description *
When executing getCoordinateKey for entities (a hotpath), the JVM is
required to repeatedly cast doubles to longs. The performance impact of
this depends on the CPU architecture, but generally switching between
FPU and ALU incurs a significant performance hit. The casted/rounded
data is already available in the blockPosition struct, so we use that
instead of re-doing the casting.
diff --git a/src/main/java/ca/spottedleaf/moonrise/common/util/CoordinateUtils.java b/src/main/java/ca/spottedleaf/moonrise/common/util/CoordinateUtils.java
index 31b92bd48828cbea25b44a9f0f96886347aa1ae6..036c1a287db04c0191e5f84b027ea68d31447cbc 100644
--- a/src/main/java/ca/spottedleaf/moonrise/common/util/CoordinateUtils.java
+++ b/src/main/java/ca/spottedleaf/moonrise/common/util/CoordinateUtils.java
@@ -16,7 +16,7 @@ public final class CoordinateUtils {
}
public static long getChunkKey(final Entity entity) {
- return ((Mth.lfloor(entity.getZ()) >> 4) << 32) | ((Mth.lfloor(entity.getX()) >> 4) & 0xFFFFFFFFL);
+ return ((long) (entity.blockPosition.getZ() >> 4) << 32) | ((entity.blockPosition.getX() >> 4) & 0xFFFFFFFFL); // Gale - Pufferfish - optimize entity coordinate key - eliminate double->long cast in hotpath
}
public static long getChunkKey(final ChunkPos pos) {

View File

@@ -0,0 +1,51 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Fri, 25 Nov 2022 15:03:50 +0100
Subject: [PATCH] Do not log legacy Material initialization
License: MIT (https://opensource.org/licenses/MIT)
Gale - https://galemc.org
This patch is based on the following patch:
"Logger settings (suppressing pointless logs)"
By: William Blake Galbreath <blake.galbreath@gmail.com>
As part of: Purpur (https://github.com/PurpurMC/Purpur)
Licensed under: MIT (https://opensource.org/licenses/MIT)
* Purpur copyright *
MIT License
Copyright (c) 2019-2022 PurpurMC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
diff --git a/src/main/java/org/bukkit/craftbukkit/legacy/CraftLegacy.java b/src/main/java/org/bukkit/craftbukkit/legacy/CraftLegacy.java
index 0b9b29753984bebaf01e2edc6d325cd5df6c689d..a5c8701974acd4639b9475434a7ebf73cbf496d7 100644
--- a/src/main/java/org/bukkit/craftbukkit/legacy/CraftLegacy.java
+++ b/src/main/java/org/bukkit/craftbukkit/legacy/CraftLegacy.java
@@ -260,7 +260,7 @@ public final class CraftLegacy {
}
static {
- LOGGER.warn("Initializing Legacy Material Support. Unless you have legacy plugins and/or data this is a bug!"); // Paper - Improve logging and errors; doesn't need to be an error
+ if (org.galemc.gale.configuration.GaleGlobalConfiguration.get().logToConsole.legacyMaterialInitialization) LOGGER.warn("Initializing Legacy Material Support. Unless you have legacy plugins and/or data this is a bug!"); // Paper - Improve logging and errors; doesn't need to be an error // Gale - Purpur - do not log legacy Material initialization
if (MinecraftServer.getServer() != null && MinecraftServer.getServer().isDebugging()) {
new Exception().printStackTrace();
}

View File

@@ -0,0 +1,21 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Fri, 25 Nov 2022 15:13:38 +0100
Subject: [PATCH] Do not log Not Secure marker
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
diff --git a/src/main/java/io/papermc/paper/adventure/ChatProcessor.java b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
index f6266b3ca9c031ef9e96df23e0413c7db5211bd8..7cb9622b88d9ef1ae5cae00485bb9995c87e206f 100644
--- a/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
+++ b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
@@ -317,7 +317,7 @@ public final class ChatProcessor {
private void sendToServer(final ChatType.Bound chatType, final @Nullable Function<Audience, net.minecraft.network.chat.Component> msgFunction) {
final PlayerChatMessage toConsoleMessage = msgFunction == null ? ChatProcessor.this.message : ChatProcessor.this.message.withUnsignedContent(msgFunction.apply(ChatProcessor.this.server.console));
- ChatProcessor.this.server.logChatMessage(toConsoleMessage.decoratedContent(), chatType, ChatProcessor.this.server.getPlayerList().verifyChatTrusted(toConsoleMessage) ? null : "Not Secure");
+ ChatProcessor.this.server.logChatMessage(toConsoleMessage.decoratedContent(), chatType, !org.galemc.gale.configuration.GaleGlobalConfiguration.get().logToConsole.chat.notSecureMarker || ChatProcessor.this.server.getPlayerList().verifyChatTrusted(toConsoleMessage) ? null : "Not Secure"); // Gale - do not log Not Secure marker
}
}

View File

@@ -0,0 +1,151 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Sat, 26 Nov 2022 11:25:45 +0100
Subject: [PATCH] Reduce array allocations
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
This patch is based on the following patch:
"reduce allocs"
By: Simon Gardling <titaniumtown@gmail.com>
As part of: JettPack (https://gitlab.com/Titaniumtown/JettPack)
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
diff --git a/src/main/java/ca/spottedleaf/moonrise/common/list/EntityList.java b/src/main/java/ca/spottedleaf/moonrise/common/list/EntityList.java
index 7fed43a1e7bcf35c4d7fd3224837a47fedd59860..adc47f1ca3580a6968d145239ae830734a0ebe4a 100644
--- a/src/main/java/ca/spottedleaf/moonrise/common/list/EntityList.java
+++ b/src/main/java/ca/spottedleaf/moonrise/common/list/EntityList.java
@@ -18,9 +18,7 @@ public final class EntityList implements Iterable<Entity> {
this.entityToIndex.defaultReturnValue(Integer.MIN_VALUE);
}
- private static final Entity[] EMPTY_LIST = new Entity[0];
-
- private Entity[] entities = EMPTY_LIST;
+ private Entity[] entities = me.titaniumtown.ArrayConstants.emptyEntityArray; // Gale - JettPack - reduce array allocations
private int count;
public int size() {
diff --git a/src/main/java/ca/spottedleaf/moonrise/common/list/IntList.java b/src/main/java/ca/spottedleaf/moonrise/common/list/IntList.java
index 9f3b25bb2439f283f878db93973a02fcdcd14eed..4eb7bf187276f07f807fe181b303dda8e1b9196d 100644
--- a/src/main/java/ca/spottedleaf/moonrise/common/list/IntList.java
+++ b/src/main/java/ca/spottedleaf/moonrise/common/list/IntList.java
@@ -10,9 +10,7 @@ public final class IntList {
this.map.defaultReturnValue(Integer.MIN_VALUE);
}
- private static final int[] EMPTY_LIST = new int[0];
-
- private int[] byIndex = EMPTY_LIST;
+ private int[] byIndex = me.titaniumtown.ArrayConstants.emptyIntArray; // Gale - JettPack - reduce array allocations
private int count;
public int size() {
diff --git a/src/main/java/ca/spottedleaf/moonrise/common/list/ReferenceList.java b/src/main/java/ca/spottedleaf/moonrise/common/list/ReferenceList.java
index 2e876b918672e8ef3b5197b7e6b1597247fdeaa1..8df9406b77eb3c225ebf88bf76a7adb666452f3b 100644
--- a/src/main/java/ca/spottedleaf/moonrise/common/list/ReferenceList.java
+++ b/src/main/java/ca/spottedleaf/moonrise/common/list/ReferenceList.java
@@ -7,14 +7,12 @@ import java.util.NoSuchElementException;
public final class ReferenceList<E> implements Iterable<E> {
- private static final Object[] EMPTY_LIST = new Object[0];
-
private final Reference2IntOpenHashMap<E> referenceToIndex;
private E[] references;
private int count;
public ReferenceList() {
- this((E[])EMPTY_LIST);
+ this((E[]) me.titaniumtown.ArrayConstants.emptyObjectArray); // Gale - JettPack - reduce array allocations
}
public ReferenceList(final E[] referenceArray) {
diff --git a/src/main/java/ca/spottedleaf/moonrise/common/list/ShortList.java b/src/main/java/ca/spottedleaf/moonrise/common/list/ShortList.java
index 2bae9949ef325d0001aa638150fbbdf968367e75..a72d5db6f6a8667c5c839016033bba4d0f16cf13 100644
--- a/src/main/java/ca/spottedleaf/moonrise/common/list/ShortList.java
+++ b/src/main/java/ca/spottedleaf/moonrise/common/list/ShortList.java
@@ -10,9 +10,7 @@ public final class ShortList {
this.map.defaultReturnValue(Short.MIN_VALUE);
}
- private static final short[] EMPTY_LIST = new short[0];
-
- private short[] byIndex = EMPTY_LIST;
+ private short[] byIndex = me.titaniumtown.ArrayConstants.emptyShortArray; // Gale - JettPack - reduce array allocations
private short count;
public int size() {
diff --git a/src/main/java/ca/spottedleaf/moonrise/common/list/SortedList.java b/src/main/java/ca/spottedleaf/moonrise/common/list/SortedList.java
index db92261a6cb3758391108361096417c61bc82cdc..1a14fddb36ca3c14d243304db629d0c5aac3906c 100644
--- a/src/main/java/ca/spottedleaf/moonrise/common/list/SortedList.java
+++ b/src/main/java/ca/spottedleaf/moonrise/common/list/SortedList.java
@@ -6,14 +6,12 @@ import java.util.Comparator;
public final class SortedList<E> {
- private static final Object[] EMPTY_LIST = new Object[0];
-
private Comparator<? super E> comparator;
private E[] elements;
private int count;
public SortedList(final Comparator<? super E> comparator) {
- this((E[])EMPTY_LIST, comparator);
+ this((E[]) me.titaniumtown.ArrayConstants.emptyObjectArray, comparator); // Gale - JettPack - reduce array allocations
}
public SortedList(final E[] elements, final Comparator<? super E> comparator) {
diff --git a/src/main/java/io/papermc/paper/command/brigadier/PaperCommands.java b/src/main/java/io/papermc/paper/command/brigadier/PaperCommands.java
index 4b6d845423ca845cb8780499757d627773c688da..9c2864675bc0b13ba088ba699be3c5692c2fa0a4 100644
--- a/src/main/java/io/papermc/paper/command/brigadier/PaperCommands.java
+++ b/src/main/java/io/papermc/paper/command/brigadier/PaperCommands.java
@@ -175,7 +175,7 @@ public class PaperCommands implements Commands, PaperRegistrar<LifecycleEventOwn
})
)
.executes((stack) -> {
- basicCommand.execute(stack.getSource(), new String[0]);
+ basicCommand.execute(stack.getSource(), me.titaniumtown.ArrayConstants.emptyStringArray); // Gale - JettPack - reduce array allocations
return com.mojang.brigadier.Command.SINGLE_SUCCESS;
});
diff --git a/src/main/java/io/papermc/paper/command/subcommands/VersionCommand.java b/src/main/java/io/papermc/paper/command/subcommands/VersionCommand.java
index 58ca24715eafd1ac3cc9657b1cc235049d69bb59..acb764b71bb3e8f159a758002f7d1077637d188d 100644
--- a/src/main/java/io/papermc/paper/command/subcommands/VersionCommand.java
+++ b/src/main/java/io/papermc/paper/command/subcommands/VersionCommand.java
@@ -14,7 +14,7 @@ public final class VersionCommand implements PaperSubcommand {
public boolean execute(final CommandSender sender, final String subCommand, final String[] args) {
final @Nullable Command redirect = MinecraftServer.getServer().server.getCommandMap().getCommand("version");
if (redirect != null) {
- redirect.execute(sender, "paper", new String[0]);
+ redirect.execute(sender, "paper", me.titaniumtown.ArrayConstants.emptyStringArray); // Gale - JettPack - reduce array allocations
}
return true;
}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftEntityEquipment.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftEntityEquipment.java
index 4abe58077fae4e68cceda9624fed013bca1d6f22..72aa906ccf64dd9be085728a897f323ab0822eba 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftEntityEquipment.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftEntityEquipment.java
@@ -165,7 +165,7 @@ public class CraftEntityEquipment implements EntityEquipment {
@Override
public void clear() {
- for (net.minecraft.world.entity.EquipmentSlot slot : net.minecraft.world.entity.EquipmentSlot.values()) {
+ for (net.minecraft.world.entity.EquipmentSlot slot : net.minecraft.world.entity.EquipmentSlot.VALUES) { // Gale - JettPack - reduce array allocations
this.setEquipment(slot, null, false);
}
}
diff --git a/src/main/java/org/bukkit/craftbukkit/util/WeakCollection.java b/src/main/java/org/bukkit/craftbukkit/util/WeakCollection.java
index 306ca8db11d16a03ce73b9a5a8be7efc11ee4b57..444e57a87acb653275d1cadbd0698815f6dc049d 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/WeakCollection.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/WeakCollection.java
@@ -164,7 +164,7 @@ public final class WeakCollection<E> implements Collection<E> {
@Override
public Object[] toArray() {
- return this.toArray(new Object[0]);
+ return this.toArray(me.titaniumtown.ArrayConstants.emptyObjectArray); // Gale - JettPack - reduce array allocations
}
@Override

View File

@@ -0,0 +1,56 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Sat, 24 Dec 2022 13:09:34 +0100
Subject: [PATCH] CraftBukkit UUID to world map
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
This patch is based on the following patch:
"Optimize CraftServer.getWorld(UUID)"
By: PureGero <puregero@gmail.com>
As part of: MultiPaper (https://github.com/MultiPaper/MultiPaper)
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index e2e7e09ca154ca1ccf38bb97c03caadef5048541..5b210cbcc8f889ecfe8e6b9dc924876855c2feb9 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -282,6 +282,7 @@ public final class CraftServer implements Server {
final DedicatedServer console;
private final DedicatedPlayerList playerList;
private final Map<String, World> worlds = new LinkedHashMap<>();
+ private final it.unimi.dsi.fastutil.objects.Object2ObjectMap<UUID, World> worldsByUUID = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>(); // Gale - MultiPaper - CraftBukkit UUID to world map
private YamlConfiguration configuration;
private YamlConfiguration commandsConfiguration;
private final Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions()));
@@ -1487,6 +1488,7 @@ public final class CraftServer implements Server {
this.getLogger().log(Level.SEVERE, null, ex);
}
+ this.worldsByUUID.remove(world.getUID()); // Gale - MultiPaper - CraftBukkit UUID to world map
this.worlds.remove(world.getName().toLowerCase(Locale.ROOT));
this.console.removeLevel(handle);
return true;
@@ -1505,12 +1507,7 @@ public final class CraftServer implements Server {
@Override
public World getWorld(UUID uid) {
- for (World world : this.worlds.values()) {
- if (world.getUID().equals(uid)) {
- return world;
- }
- }
- return null;
+ return this.worldsByUUID.get(uid); // Gale - MultiPaper - CraftBukkit UUID to world map
}
@Override
@@ -1526,6 +1523,7 @@ public final class CraftServer implements Server {
System.out.println("World " + world.getName() + " is a duplicate of another world and has been prevented from loading. Please delete the uid.dat file from " + world.getName() + "'s world directory if you want to be able to load the duplicate world.");
return;
}
+ this.worldsByUUID.put(world.getUID(), world); // Gale - MultiPaper - CraftBukkit UUID to world map
this.worlds.put(world.getName().toLowerCase(Locale.ROOT), world);
}

View File

@@ -0,0 +1,36 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Wed, 30 Nov 2022 12:56:43 +0100
Subject: [PATCH] Specific interval TPS API
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 5b210cbcc8f889ecfe8e6b9dc924876855c2feb9..a913beb575cf9bb9c614bae48432f16d33a891bd 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -2995,6 +2995,23 @@ public final class CraftServer implements Server {
};
}
+ // Gale start - specific interval TPS API
+ @Override
+ public double get1MinuteTPSAverage() {
+ return net.minecraft.server.MinecraftServer.getServer().tps1.getAverage();
+ }
+
+ @Override
+ public double get5MinuteTPSAverage() {
+ return net.minecraft.server.MinecraftServer.getServer().tps5.getAverage();
+ }
+
+ @Override
+ public double get15MinuteTPSAverage() {
+ return net.minecraft.server.MinecraftServer.getServer().tps15.getAverage();
+ }
+ // Gale end - specific interval TPS API
+
@Override
public void playSound(final net.kyori.adventure.sound.Sound sound) {
if (sound.seed().isEmpty()) org.spigotmc.AsyncCatcher.catchOp("play sound; cannot generate seed with world random");

View File

@@ -0,0 +1,112 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Wed, 30 Nov 2022 12:42:32 +0100
Subject: [PATCH] 5 second TPS average
License: MIT (https://opensource.org/licenses/MIT)
Gale - https://galemc.org
This patch is based on the following patch:
"Add 5 second tps average in /tps"
By: William Blake Galbreath <blake.galbreath@gmail.com>
As part of: Purpur (https://github.com/PurpurMC/Purpur)
Licensed under: MIT (https://opensource.org/licenses/MIT)
* Purpur copyright *
MIT License
Copyright (c) 2019-2022 PurpurMC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
diff --git a/src/main/java/com/destroystokyo/paper/gui/RAMDetails.java b/src/main/java/com/destroystokyo/paper/gui/RAMDetails.java
index 12b327eea95e0de9e9c39b7d039badee8ec46508..6178f0212214a2a075cea60c758dca793a61951b 100644
--- a/src/main/java/com/destroystokyo/paper/gui/RAMDetails.java
+++ b/src/main/java/com/destroystokyo/paper/gui/RAMDetails.java
@@ -61,6 +61,7 @@ public class RAMDetails extends JList<String> {
// Follows CraftServer#getTPS
double[] tps = new double[] {
+ server.tps5s.getAverage(), // Gale - Purpur - 5 second TPS average
server.tps1.getAverage(),
server.tps5.getAverage(),
server.tps15.getAverage()
@@ -73,7 +74,7 @@ public class RAMDetails extends JList<String> {
vector.add("Memory use: " + (data.getUsedMem() / 1024L / 1024L) + " mb (" + (data.getFree() * 100L / data.getMax()) + "% free)");
vector.add("Heap: " + (data.getTotal() / 1024L / 1024L) + " / " + (data.getMax() / 1024L / 1024L) + " mb");
vector.add("Avg tick: " + DECIMAL_FORMAT.format((double)this.server.getAverageTickTimeNanos() / (double) TimeUtil.NANOSECONDS_PER_MILLISECOND) + " ms");
- vector.add("TPS from last 1m, 5m, 15m: " + String.join(", ", tpsAvg));
+ vector.add("TPS from last 5s, 1m, 5m, 15m: " + String.join(", ", tpsAvg)); // Gale - Purpur - 5 second TPS average
setListData(vector);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index a913beb575cf9bb9c614bae48432f16d33a891bd..b7175131c81036a244b9274252d11b009e4d31bb 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -2995,7 +2995,26 @@ public final class CraftServer implements Server {
};
}
+ // Gale start - Purpur - 5 second TPS average
+ @Override
+ public double[] getTPSIncluding5SecondAverage() {
+ return new double[] {
+ net.minecraft.server.MinecraftServer.getServer().tps5s.getAverage(),
+ net.minecraft.server.MinecraftServer.getServer().tps1.getAverage(),
+ net.minecraft.server.MinecraftServer.getServer().tps5.getAverage(),
+ net.minecraft.server.MinecraftServer.getServer().tps15.getAverage()
+ };
+ }
+ // Gale end - Purpur - 5 second TPS average
+
// Gale start - specific interval TPS API
+ // Gale start - Purpur - 5 second TPS average
+ @Override
+ public double get5SecondTPSAverage() {
+ return net.minecraft.server.MinecraftServer.getServer().tps5s.getAverage();
+ }
+ // Gale end - Purpur - 5 second TPS average
+
@Override
public double get1MinuteTPSAverage() {
return net.minecraft.server.MinecraftServer.getServer().tps1.getAverage();
diff --git a/src/main/java/org/spigotmc/TicksPerSecondCommand.java b/src/main/java/org/spigotmc/TicksPerSecondCommand.java
index 6d4851aa8c53793bfaf650f399fc5e2a98dbbb24..d336b27ee314366fe44760db6fdb68370ab3995a 100644
--- a/src/main/java/org/spigotmc/TicksPerSecondCommand.java
+++ b/src/main/java/org/spigotmc/TicksPerSecondCommand.java
@@ -35,7 +35,7 @@ public class TicksPerSecondCommand extends Command {
}
// Paper start - Further improve tick handling
- double[] tps = org.bukkit.Bukkit.getTPS();
+ double[] tps = org.bukkit.Bukkit.getTPSIncluding5SecondAverage(); // Gale - Purpur - 5 second TPS average
Component[] tpsAvg = new Component[tps.length];
for (int i = 0; i < tps.length; i++) {
@@ -43,7 +43,7 @@ public class TicksPerSecondCommand extends Command {
}
TextComponent.Builder builder = text();
- builder.append(text("TPS from last 1m, 5m, 15m: ", NamedTextColor.GOLD));
+ builder.append(text("TPS from last 5s, 1m, 5m, 15m: ", NamedTextColor.GOLD)); // Gale - Purpur - 5 second TPS average
builder.append(Component.join(JoinConfiguration.commas(true), tpsAvg));
sender.sendMessage(builder.asComponent());
if (args.length > 0 && args[0].equals("mem") && sender.hasPermission("bukkit.command.tpsmemory")) {

View File

@@ -0,0 +1,50 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Sat, 26 Nov 2022 17:12:08 +0100
Subject: [PATCH] Last tick time API
License: MIT (https://opensource.org/licenses/MIT)
Gale - https://galemc.org
This patch is based on the following patch:
"Add getLastTickMs api"
By: tr7zw <tr7zw@live.de>
As part of: YAPFA (https://github.com/tr7zw/YAPFA)
Licensed under: MIT (https://opensource.org/licenses/MIT)
* YAPFA copyright *
Copyright 2020 tr7zw
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index b7175131c81036a244b9274252d11b009e4d31bb..d8cfddc1641868692e045bc13bac61a21c64ffcc 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -3232,4 +3232,21 @@ public final class CraftServer implements Server {
public void allowPausing(final Plugin plugin, final boolean value) {
this.console.addPluginAllowingSleep(plugin.getName(), value);
}
+
+ // Gale start - YAPFA - last tick time - API
+ @Override
+ public long getLastTickTotalTime() {
+ return MinecraftServer.lastTickProperTime + MinecraftServer.lastTickOversleepTime;
+ }
+
+ @Override
+ public long getLastTickProperTime() {
+ return MinecraftServer.lastTickProperTime;
+ }
+
+ @Override
+ public long getLastTickOversleepTime() {
+ return MinecraftServer.lastTickOversleepTime;
+ }
+ // Gale end - YAPFA - last tick time - API
}

View File

@@ -0,0 +1,70 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Sat, 26 Nov 2022 21:02:58 +0100
Subject: [PATCH] Show last tick time in /tps command
License: MIT (https://opensource.org/licenses/MIT)
Gale - https://galemc.org
This patch is based on the following patch:
"Add getLastTickMs api"
By: tr7zw <tr7zw@live.de>
As part of: YAPFA (https://github.com/tr7zw/YAPFA)
Licensed under: MIT (https://opensource.org/licenses/MIT)
* YAPFA copyright *
Copyright 2020 tr7zw
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/src/main/java/org/spigotmc/TicksPerSecondCommand.java b/src/main/java/org/spigotmc/TicksPerSecondCommand.java
index d336b27ee314366fe44760db6fdb68370ab3995a..e1532490b14d15fd5687f242137d470d5b82ea12 100644
--- a/src/main/java/org/spigotmc/TicksPerSecondCommand.java
+++ b/src/main/java/org/spigotmc/TicksPerSecondCommand.java
@@ -46,6 +46,24 @@ public class TicksPerSecondCommand extends Command {
builder.append(text("TPS from last 5s, 1m, 5m, 15m: ", NamedTextColor.GOLD)); // Gale - Purpur - 5 second TPS average
builder.append(Component.join(JoinConfiguration.commas(true), tpsAvg));
sender.sendMessage(builder.asComponent());
+ // Gale start - YAPFA - last tick time - in TPS command
+ if (org.galemc.gale.configuration.GaleGlobalConfiguration.get().misc.lastTickTimeInTpsCommand.enabled) {
+ long lastTickProperTime = net.minecraft.server.MinecraftServer.lastTickProperTime;
+ long lastTickOversleepTime = net.minecraft.server.MinecraftServer.lastTickOversleepTime;
+ var lastTickTimeMessage = text("Last tick: ")
+ .append(formatTickTimeDuration(lastTickProperTime, 44, 50, 51));
+
+ if (org.galemc.gale.configuration.GaleGlobalConfiguration.get().misc.lastTickTimeInTpsCommand.addOversleep) {
+ lastTickTimeMessage = lastTickTimeMessage.append(text(" self + "))
+ .append(formatTickTimeDuration(lastTickOversleepTime, Math.max(1, 51 - lastTickProperTime), Math.max(2, 52 - lastTickProperTime), Math.max(3, 53 - lastTickProperTime)))
+ .append(text(" oversleep = "))
+ .append(formatTickTimeDuration(lastTickProperTime + lastTickOversleepTime, 51, 52, 53));
+ }
+
+ lastTickTimeMessage = lastTickTimeMessage.color(NamedTextColor.GOLD);
+ sender.sendMessage(lastTickTimeMessage);
+ }
+ // Gale end - YAPFA - last tick time - in TPS command
if (args.length > 0 && args[0].equals("mem") && sender.hasPermission("bukkit.command.tpsmemory")) {
sender.sendMessage(text()
.append(text("Current Memory Usage: ", NamedTextColor.GOLD))
@@ -68,4 +86,16 @@ public class TicksPerSecondCommand extends Command {
return text(amount, color);
// Paper end
}
+
+ // Gale start - YAPFA - last tick time - in TPS command
+ private static final TextColor safeColor = NamedTextColor.GREEN;
+ private static final TextColor closeColor = NamedTextColor.YELLOW;
+ private static final TextColor problematicColor = TextColor.color(0xf77c1e);
+ private static final TextColor severeColor = NamedTextColor.RED;
+
+ private static Component formatTickTimeDuration(long ms, long safeLimit, long closeLimit, long nonSevereLimit) {
+ return text(ms + " ", ms <= safeLimit ? safeColor : ms <= closeLimit ? closeColor : ms <= nonSevereLimit ? problematicColor : severeColor)
+ .append(text("ms", NamedTextColor.GOLD));
+ }
+ // Gale end - YAPFA - last tick time - in TPS command
}

View File

@@ -0,0 +1,187 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Mon, 21 Aug 2023 21:46:10 +0200
Subject: [PATCH] Pre-compute VarLong sizes
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
This patch is based on the following commit:
"Reapply "Optimize varint writing""
By: Andrew Steinborn <git@steinborn.me>
As part of: Velocity (https://github.com/PaperMC/Velocity)
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
* Velocity description *
Inspired by the approach described at the bottom of https://richardstartin.github.io/posts/dont-use-protobuf-for-telemetry
Given that we do a lot of varint writing as well, this should provide a small performance boost for larger/complex packets whilst not regressing hard on smaller packets.
This includes a test to ensure that the behavior is as expected and fixes the initialization loop so that the correct results will be given. Much thanks to @octylFractal for acting as my duck while trying to figure this out.
diff --git a/src/test/java/net/minecraft/network/VarIntLongTest.java b/src/test/java/net/minecraft/network/VarIntLongTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..bbea09ffc2180c3c62e15d7dff51f8c220425bfe
--- /dev/null
+++ b/src/test/java/net/minecraft/network/VarIntLongTest.java
@@ -0,0 +1,159 @@
+// Gale - Velocity - VarInt and VarLong optimizations
+
+package net.minecraft.network;
+
+import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
+import it.unimi.dsi.fastutil.ints.IntSet;
+import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
+import it.unimi.dsi.fastutil.longs.LongSet;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class VarIntLongTest {
+
+ private static String padStringWithLeadingZeros(String string, int length) {
+ if (string.length() >= length) {
+ return string;
+ }
+ return "0".repeat(length - string.length()) + string;
+ }
+
+ private static final IntSet integerCases;
+ static {
+ integerCases = new IntOpenHashSet();
+ {
+ integerCases.add(0);
+ integerCases.add(-1);
+ }
+ {
+ for (int i = 0; i < 32; i++) {
+ integerCases.add(1 << i);
+ }
+ }
+ {
+ for (int factor = 1; factor <= 7; factor++) {
+ int all = 0;
+ for (int i = 0; i <= 4; i++) {
+ int shifted = 1 << (i * factor);
+ all |= shifted;
+ integerCases.add(shifted);
+ integerCases.add(shifted - 1);
+ integerCases.add(~shifted);
+ integerCases.add(-shifted);
+ integerCases.add((~shifted) & (0x80000000));
+ integerCases.add(all);
+ integerCases.add(all - 1);
+ integerCases.add(~all);
+ integerCases.add(-all);
+ integerCases.add((~all) & (0x80000000));
+ }
+ }
+ }
+ {
+ var newCases = new IntOpenHashSet();
+ for (int shiftSize = 2; shiftSize <= 6; shiftSize++) {
+ for (int offset = 0; offset < shiftSize; offset++) {
+ int striped = 0;
+ for (int i = offset; i < 32; i += shiftSize) {
+ striped |= 1 << i;
+ }
+ final var finalStriped = striped;
+ integerCases.forEach(existing -> {
+ newCases.add(existing | finalStriped);
+ newCases.add(existing | (~finalStriped));
+ newCases.add(existing & finalStriped);
+ newCases.add(existing & (~finalStriped));
+ newCases.add(existing - finalStriped);
+ newCases.add(existing - (~finalStriped));
+ });
+ }
+ }
+ integerCases.addAll(newCases);
+ }
+ }
+
+ private static final LongSet longCases;
+ static {
+ longCases = new LongOpenHashSet();
+ {
+ longCases.add(0);
+ longCases.add(-1);
+ }
+ {
+ for (int i = 0; i < 64; i++) {
+ longCases.add(1L << i);
+ }
+ }
+ {
+ for (int factor = 1; factor <= 7; factor++) {
+ long all = 0;
+ for (int i = 0; i <= 9; i++) {
+ long shifted = 1L << (i * factor);
+ all |= shifted;
+ longCases.add(shifted);
+ longCases.add(shifted - 1);
+ longCases.add(~shifted);
+ longCases.add(-shifted);
+ longCases.add((~shifted) & (0x8000000000000000L));
+ longCases.add(all);
+ longCases.add(all - 1);
+ longCases.add(~all);
+ longCases.add(-all);
+ longCases.add((~all) & (0x8000000000000000L));
+ }
+ }
+ }
+ {
+ var newCases = new LongOpenHashSet();
+ for (int shiftSize = 2; shiftSize <= 6; shiftSize++) {
+ for (int offset = 0; offset < shiftSize; offset++) {
+ long striped = 0;
+ for (int i = offset; i < 64; i += shiftSize) {
+ striped |= 1L << i;
+ }
+ final var finalStriped = striped;
+ longCases.forEach(existing -> {
+ newCases.add(existing | finalStriped);
+ newCases.add(existing | (~finalStriped));
+ newCases.add(existing & finalStriped);
+ newCases.add(existing & (~finalStriped));
+ newCases.add(existing - finalStriped);
+ newCases.add(existing - (~finalStriped));
+ });
+ }
+ }
+ longCases.addAll(newCases);
+ }
+ }
+
+ // Gale start - Velocity - pre-compute VarInt and VarLong sizes
+ @Test
+ public void testGetVarIntSizeComparedToOld() {
+ integerCases.forEach(value -> {
+ // given
+ int originalSize = VarInt.getByteSizeOld(value);
+
+ // when
+ int size = VarInt.getByteSize(value);
+
+ // then
+ Assertions.assertEquals(originalSize, size, "Optimized size (" + size + ") is not equal to original size (" + originalSize + ") for test case value " + value + " (binary: " + padStringWithLeadingZeros(Integer.toBinaryString(value), 32) + ")");
+ });
+ }
+
+ @Test
+ public void testGetVarLongSizeComparedToOld() {
+ longCases.forEach(value -> {
+ // given
+ int originalSize = VarLong.getByteSizeOld(value);
+
+ // when
+ int size = VarLong.getByteSize(value);
+
+ // then
+ Assertions.assertEquals(originalSize, size, "Optimized size (" + size + ") is not equal to original size (" + originalSize + ") for test case value " + value + " (binary: " + padStringWithLeadingZeros(Long.toBinaryString(value), 64) + ")");
+ });
+ }
+ // Gale end - Velocity - pre-compute VarInt and VarLong sizes
+
+}

View File

@@ -0,0 +1,81 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Tue, 22 Aug 2023 21:38:37 +0200
Subject: [PATCH] Optimize VarInt#write and VarLong#write
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
This patch is based on the following commit:
"Reapply "Optimize varint writing""
By: Andrew Steinborn <git@steinborn.me>
As part of: Velocity (https://github.com/PaperMC/Velocity)
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
* Velocity description *
Inspired by the approach described at the bottom of https://richardstartin.github.io/posts/dont-use-protobuf-for-telemetry
Given that we do a lot of varint writing as well, this should provide a small performance boost for larger/complex packets whilst not regressing hard on smaller packets.
This includes a test to ensure that the behavior is as expected and fixes the initialization loop so that the correct results will be given. Much thanks to @octylFractal for acting as my duck while trying to figure this out.
diff --git a/src/test/java/net/minecraft/network/VarIntLongTest.java b/src/test/java/net/minecraft/network/VarIntLongTest.java
index bbea09ffc2180c3c62e15d7dff51f8c220425bfe..0c11670d8d7307307a7cd12be5d0dca40155829d 100644
--- a/src/test/java/net/minecraft/network/VarIntLongTest.java
+++ b/src/test/java/net/minecraft/network/VarIntLongTest.java
@@ -2,6 +2,7 @@
package net.minecraft.network;
+import io.netty.buffer.Unpooled;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
@@ -156,4 +157,46 @@ public class VarIntLongTest {
}
// Gale end - Velocity - pre-compute VarInt and VarLong sizes
+ // Gale - Velocity - optimized VarInt#write and VarLong#write
+ @Test
+ public void testWriteVarIntComparedToOld() {
+ integerCases.forEach(value -> {
+ // given
+ int capacity = 5;
+ FriendlyByteBuf buf1 = new FriendlyByteBuf(Unpooled.buffer(capacity));
+ FriendlyByteBuf buf2 = new FriendlyByteBuf(Unpooled.buffer(capacity));
+ VarInt.writeOld(buf1, value);
+
+ // when
+ buf2.writeVarInt(value);
+
+ // then
+ Assertions.assertEquals(buf1.writerIndex(), buf2.writerIndex(), "Writer index of optimized buffer (" + buf2.writerIndex() + ") is not equal to writer index of original buffer (" + buf1.writerIndex() + ") for test case value " + value + " (binary: " + padStringWithLeadingZeros(Integer.toBinaryString(value), 32) + ")");
+ for (int i = 0; i < capacity; i++) {
+ Assertions.assertEquals(buf1.getByte(i), buf2.getByte(i), "Buffer byte (at index " + i + ") in optimized buffer (" + buf2.getByte(i) + " (binary: " + padStringWithLeadingZeros(Integer.toBinaryString(Byte.toUnsignedInt(buf2.getByte(i))), 8) + ")) is not equal to the same byte in original buffer (" + buf1.getByte(i) + " (binary: " + padStringWithLeadingZeros(Integer.toBinaryString(Byte.toUnsignedInt(buf1.getByte(i))), 8) + ")) for test case value " + value + " (binary: " + padStringWithLeadingZeros(Integer.toBinaryString(value), 32) + ")");
+ }
+ });
+ }
+
+ @Test
+ public void testWriteVarLongComparedToOld() {
+ longCases.forEach(value -> {
+ // given
+ int capacity = 10;
+ FriendlyByteBuf buf1 = new FriendlyByteBuf(Unpooled.buffer(capacity));
+ FriendlyByteBuf buf2 = new FriendlyByteBuf(Unpooled.buffer(capacity));
+ VarLong.writeOld(buf1, value);
+
+ // when
+ buf2.writeVarLong(value);
+
+ // then
+ Assertions.assertEquals(buf1.writerIndex(), buf2.writerIndex(), "Writer index of optimized buffer (" + buf2.writerIndex() + ") is not equal to writer index of original buffer (" + buf1.writerIndex() + ") for test case value " + value + " (binary: " + padStringWithLeadingZeros(Long.toBinaryString(value), 64) + ")");
+ for (int i = 0; i < capacity; i++) {
+ Assertions.assertEquals(buf1.getByte(i), buf2.getByte(i), "Buffer byte (at index " + i + ") in optimized buffer (" + buf2.getByte(i) + " (binary: " + padStringWithLeadingZeros(Integer.toBinaryString(Byte.toUnsignedInt(buf2.getByte(i))), 8) + ")) is not equal to the same byte in original buffer (" + buf1.getByte(i) + " (binary: " + padStringWithLeadingZeros(Integer.toBinaryString(Byte.toUnsignedInt(buf1.getByte(i))), 8) + ")) for test case value " + value + " (binary: " + padStringWithLeadingZeros(Long.toBinaryString(value), 64) + ")");
+ }
+ });
+ }
+ // Gale end - Velocity - optimized VarInt#write and VarLong#write
+
}

View File

@@ -0,0 +1,35 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Wed, 9 Aug 2023 15:04:56 +0200
Subject: [PATCH] Virtual thread support
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
diff --git a/src/main/java/com/destroystokyo/paper/Metrics.java b/src/main/java/com/destroystokyo/paper/Metrics.java
index a35c0af0c53bab4c1b3623e903d3057c816e5d3b..3e9bbe0dae0cd1bdb390f68612dbf824b6ed4df7 100644
--- a/src/main/java/com/destroystokyo/paper/Metrics.java
+++ b/src/main/java/com/destroystokyo/paper/Metrics.java
@@ -976,6 +976,22 @@ public class Metrics {
}));
// Gale end - SIMD support - include in metrics
+ // Gale start - virtual thread support - include in metrics
+ Map<String, Map<String, Integer>> virtualThreadSupportMap = new HashMap<>(2);
+ {
+ Map<String, Integer> entry = new HashMap<>(2);
+ boolean isSupported = org.galemc.gale.virtualthread.VirtualThreadService.isSupported();
+ try {
+ int javaMajorVersion = org.galemc.gale.virtualthread.VirtualThreadService.getJavaMajorVersion();
+ entry.put(isSupported + " (Java " + javaMajorVersion + ")", 1);
+ } catch (Exception ignored) {
+ entry.put(String.valueOf(isSupported), 1);
+ }
+ virtualThreadSupportMap.put(String.valueOf(isSupported), entry);
+ }
+ metrics.addCustomChart(new Metrics.DrilldownPie("virtual_thread_support", () -> virtualThreadSupportMap));
+ // Gale end - virtual thread support - include in metrics
+
}
}