Skip to content

Commit

Permalink
some works
Browse files Browse the repository at this point in the history
  • Loading branch information
MC-XiaoHei committed Aug 10, 2024
1 parent 7748446 commit 1bed64d
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 76 deletions.
4 changes: 2 additions & 2 deletions patches/server/0003-Command-API-support.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1812,15 +1812,15 @@ index cc40d3e69a3635ca7895876159f2821091c14a9a..f16e1ee682415cf1b49aeba2fb3f879b
this.server.loadPlugins();
diff --git a/src/main/java/org/bukkit/plugin/java/CommandAPIPluginFactory.java b/src/main/java/org/bukkit/plugin/java/CommandAPIPluginFactory.java
new file mode 100644
index 0000000000000000000000000000000000000000..8afd999c0e4453df6b3b0c52cd6521758cd786b0
index 0000000000000000000000000000000000000000..6b01831f249081e591bfcede7ff56e8f6554cf1e
--- /dev/null
+++ b/src/main/java/org/bukkit/plugin/java/CommandAPIPluginFactory.java
@@ -0,0 +1,7 @@
+package org.bukkit.plugin.java;
+
+public class CommandAPIPluginFactory {
+ public static JavaPlugin create() {
+ return new JavaPlugin(null) {};
+ return new JavaPlugin("CommandAPI") {};
+ }
+}
\ No newline at end of file
Expand Down
31 changes: 5 additions & 26 deletions patches/server/0005-Lumina-server-config-and-command.patch
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,6 @@ index f01863e33b7407c14e8bcd2a44e63bed01afe838..a37c35fd271ac815bd67a40ceaca95ff
// CraftBukkit start
// this.setPlayerList(new DedicatedPlayerList(this, this.registries(), this.playerDataStorage)); // Spigot - moved up
this.server.loadPlugins();
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/MinecraftInternalPlugin.java b/src/main/java/org/bukkit/craftbukkit/scheduler/MinecraftInternalPlugin.java
index 66bdac50130f523f9dc4379b103b7a469f9ca36b..fef188c644ea1974cc5cd4b7044b6f9502965273 100644
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/MinecraftInternalPlugin.java
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/MinecraftInternalPlugin.java
@@ -24,10 +24,16 @@ public class MinecraftInternalPlugin extends PluginBase {
private final String pluginName;
private PluginDescriptionFile pdf;

+ // Lumina start
public MinecraftInternalPlugin() {
- this.pluginName = "Minecraft";
+ this("MinecraftInternalPlugin");
+ }
+
+ public MinecraftInternalPlugin(String pluginName) {
+ this.pluginName = pluginName;
pdf = new PluginDescriptionFile(pluginName, "1.0", "nms");
}
+ // Lumina end

public void setEnabled(boolean enabled) {
this.enabled = enabled;
diff --git a/src/main/java/org/leavesmc/lumina/LuminaCommand.java b/src/main/java/org/leavesmc/lumina/LuminaCommand.java
new file mode 100644
index 0000000000000000000000000000000000000000..dca3a12178dc25433251d854d19cfdeb3d5f6cfa
Expand Down Expand Up @@ -279,14 +257,15 @@ index 0000000000000000000000000000000000000000..5f7f258f8ddcde9f050691371662e18c
+}
diff --git a/src/main/java/org/leavesmc/lumina/config/ConfigUtils.java b/src/main/java/org/leavesmc/lumina/config/ConfigUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..fb991c96f88429099a42b43a9de2cf1825f2d89b
index 0000000000000000000000000000000000000000..fe47b35a337211d503ba7993ac9d5e38a1372d37
--- /dev/null
+++ b/src/main/java/org/leavesmc/lumina/config/ConfigUtils.java
@@ -0,0 +1,87 @@
@@ -0,0 +1,88 @@
+package org.leavesmc.lumina.config;
+
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.scheduler.MinecraftInternalPlugin;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.java.JavaPlugin;
+import org.jetbrains.annotations.Contract;
+import org.jetbrains.annotations.NotNull;
+import org.leavesmc.lumina.config.annotations.Suggestion;
Expand All @@ -308,7 +287,7 @@ index 0000000000000000000000000000000000000000..fb991c96f88429099a42b43a9de2cf18
+ int.class,
+ long.class,
+ double.class));
+ static final MinecraftInternalPlugin INTERNAL_PLUGIN = new MinecraftInternalPlugin("LuminaConfigSystem");
+ static final Plugin INTERNAL_PLUGIN = new JavaPlugin("LuminaConfigSystem") {};
+
+ @Contract("_ -> new")
+ public static @NotNull CompletableFuture<Void> runAsync(Runnable runnable) {
Expand Down
104 changes: 56 additions & 48 deletions patches/server/0056-Implementation-Carpet-features.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6670,10 +6670,10 @@ index 0000000000000000000000000000000000000000..949eea4d3c29e0b2f7e90e1ea924f852
+}
diff --git a/src/main/java/org/leavesmc/lumina/carpet/logging/HUDController.java b/src/main/java/org/leavesmc/lumina/carpet/logging/HUDController.java
new file mode 100644
index 0000000000000000000000000000000000000000..319510035b5d8d81f2f863db9bd0b71694835a92
index 0000000000000000000000000000000000000000..ed0868bf1c8d976b738735ca4ebb4af4903e3b0e
--- /dev/null
+++ b/src/main/java/org/leavesmc/lumina/carpet/logging/HUDController.java
@@ -0,0 +1,146 @@
@@ -0,0 +1,154 @@
+package org.leavesmc.lumina.carpet.logging;
+
+import io.papermc.paper.threadedregions.*;
Expand Down Expand Up @@ -6745,62 +6745,70 @@ index 0000000000000000000000000000000000000000..319510035b5d8d81f2f863db9bd0b716
+
+
+ public static void update_hud(MinecraftServer server) {
+ if (RegionizedServer.getGlobalTickData().getCurrentTick() % 20 != 0) {
+ return;
+ }
+ player_huds.clear();
+ server.getPlayerList().getPlayers().forEach(p -> p.getBukkitEntity().taskScheduler.schedule(e -> {
+ ServerPlayer player = (ServerPlayer) e;
+ String playerName = player.getScoreboardName();
+ final ThreadedRegionizer.ThreadedRegion<TickRegions.TickRegionData, TickRegions.TickRegionSectionData> currentRegion = TickRegionScheduler.getCurrentRegion();
+ final TickRegions.TickRegionData currentData = currentRegion.getData();
+ Component tpsMsg = Messenger.c("r error getting tps & mspt");
+ if (currentData != null) {
+ final TickData.TickReportData tickReport = currentData.getRegionSchedulingHandle().getTickReport5s(System.nanoTime());
+
+ final TickData.SegmentedAverage tpsData = tickReport.tpsData();
+ final TickData.SegmentedAverage msptData = tickReport.timePerTickData();
+
+ final double mspt = msptData.segmentAll().average() / 1.0E6;
+ final double tps = tpsData.segmentAll().average();
+ String color = Messenger.heatmap_color(mspt, ((long) ((double) TimeUtil.NANOSECONDS_PER_SECOND / tps) / (float) TimeUtil.NANOSECONDS_PER_MILLISECOND));
+ tpsMsg = Messenger.c(
+ "g TPS: ", String.format(Locale.US, "%s %.1f", color, tps),
+ "g MSPT: ", String.format(Locale.US, "%s %.1f", color, mspt));
+ }
+ if (RegionizedServer.getGlobalTickData().getCurrentTick() % 20 == 0) {
+ Component scarpetFOoter = scarpet_footers.get(player.getScoreboardName());
+ if (scarpetFOoter != null) HUDController.addMessage(player, scarpetFOoter);
+ if (playerSubscriptions.containsKey(playerName) && playerSubscriptions.get(playerName).containsKey("tps")) {
+ HUDController.addMessage(player, tpsMsg);
+ }
+ if (LoggerRegistry.__mobcaps) {
+ LoggerRegistry.getLogger("mobcaps").log((option, pl) -> {
+ ResourceKey<Level> dim = switch (option) {
+ case "overworld" -> Level.OVERWORLD;
+ case "nether" -> Level.NETHER;
+ case "end" -> Level.END;
+ default -> pl.level().dimension();
+ };
+ return new Component[]{SpawnReporter.printMobcapsForDimension(server.getLevel(dim), false).get(0)};
+ });
+ }
+ if (LoggerRegistry.__mobcaps) {
+ LoggerRegistry.getLogger("mobcaps").log((option, pl) -> {
+ ResourceKey<Level> dim = switch (option) {
+ case "overworld" -> Level.OVERWORLD;
+ case "nether" -> Level.NETHER;
+ case "end" -> Level.END;
+ default -> pl.level().dimension();
+ };
+ return new Component[]{SpawnReporter.printMobcapsForDimension(server.getLevel(dim), false).get(0)};
+ });
+ }
+
+ if (LoggerRegistry.__counter) {
+ LoggerRegistry.getLogger("counter").log((option) -> send_counter_info(server, option));
+ }
+ if (LoggerRegistry.__counter) {
+ LoggerRegistry.getLogger("counter").log((option) -> send_counter_info(server, option));
+ }
+
+ if (LoggerRegistry.__packets) {
+ LoggerRegistry.getLogger("packets").log(HUDController::packetCounter);
+ }
+ if (LoggerRegistry.__packets) {
+ LoggerRegistry.getLogger("packets").log(HUDController::packetCounter);
+ }
+ for (ServerPlayer p : server.getPlayerList().getPlayers()) {
+ System.out.println("Updating HUD for ");
+ p.getBukkitEntity().getScheduler().run(CarpetServer.PLUGIN, e -> {
+ final ServerPlayer player = (ServerPlayer) e;
+ System.out.println("Updating HUD for " + player.getScoreboardName());
+ String playerName = player.getScoreboardName();
+ if (LoggerRegistry.__tps) {
+ final ThreadedRegionizer.ThreadedRegion<TickRegions.TickRegionData, TickRegions.TickRegionSectionData> currentRegion = TickRegionScheduler.getCurrentRegion();
+ final TickRegions.TickRegionData currentData = currentRegion.getData();
+ Component tpsMsg = Messenger.c("r error getting tps & mspt");
+ if (currentData != null) {
+ final TickData.TickReportData tickReport = currentData.getRegionSchedulingHandle().getTickReport5s(System.nanoTime());
+
+ // extensions have time to pitch in.
+ HUDListeners.forEach(l -> l.accept(server));
+ final TickData.SegmentedAverage tpsData = tickReport.tpsData();
+ final TickData.SegmentedAverage msptData = tickReport.timePerTickData();
+
+ final double mspt = msptData.segmentAll().average() / 1.0E6;
+ final double tps = tpsData.segmentAll().average();
+ String color = Messenger.heatmap_color(mspt, ((long) ((double) TimeUtil.NANOSECONDS_PER_SECOND / tps) / (float) TimeUtil.NANOSECONDS_PER_MILLISECOND));
+ tpsMsg = Messenger.c(
+ "g TPS: ", String.format(Locale.US, "%s %.1f", color, tps),
+ "g MSPT: ", String.format(Locale.US, "%s %.1f", color, mspt));
+ }
+ if (playerSubscriptions.containsKey(playerName) && playerSubscriptions.get(playerName).containsKey("tps")) {
+ HUDController.addMessage(player, tpsMsg);
+ }
+ }
+ Component scarpetFOoter = scarpet_footers.get(player.getScoreboardName());
+ if (scarpetFOoter != null) HUDController.addMessage(player, scarpetFOoter);
+
+ // Bukkit.getGlobalRegionScheduler().execute(CarpetServer.PLUGIN, () -> {
+ ClientboundTabListPacket packet = new ClientboundTabListPacket(
+ scarpet_headers.getOrDefault(player.getScoreboardName(), Component.literal("")),
+ Messenger.c(player_huds.getOrDefault(player, List.of()).toArray(new Object[0]))
+ );
+ player.connection.send(packet);
+ }
+ }, null, 1));
+ // });
+ // extensions have time to pitch in.
+ // HUDListeners.forEach(l -> l.accept(server)); // TODO
+ }, null);
+ }
+ }
+
+ private static Component[] send_counter_info(MinecraftServer server, String colors) {
Expand Down

0 comments on commit 1bed64d

Please sign in to comment.