mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2026-01-04 15:41:40 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@30fdfb1a [ci/skip] Fix docs for DamageResistant (#11992) PaperMC/Paper@6b7650d8 Only add goat horn once (#12001) PaperMC/Paper@30046e04 Fix a rare crash with a concurrent modification of scaled health attributes (#12002) PaperMC/Paper@88bbead1 Flush regionfiles on save configuration option PaperMC/Paper@336ea9df Check for empty when sending equipment changes (#12008) PaperMC/Paper@939bb782 Add RayTraceConfigurationBuilder (#11907) PaperMC/Paper@81bb82f5 Fix wrong piston world border check (#12007) PaperMC/Paper@ce95b5d6 Use proper default for setting null display background color (#12010) PaperMC/Paper@2477f1f6 [ci/skip] fix and improvements for docs in ConsumeEffect component (#11998) PaperMC/Paper@fb5b173c Add PlayerClientLoadedWorldEvent (#11940) PaperMC/Paper@3af5e771 Add Player#give (#11995) PaperMC/Paper@7e21cb81 fix PlayerChangedMainHandEvent javadoc (#12020) PaperMC/Paper@5a34bf04 Correctly retrun true for empty input shapes in EntityGetter#isUnobstructed PaperMC/Paper@a392d475 Make Watchdog thread extend TickThread Gale Changes: Dreeam-qwq/Gale@f9080a7e Updated Upstream (Paper) Dreeam-qwq/Gale@ff0596c1 [ci/skip] Fix upstream commit sh on mac Dreeam-qwq/Gale@24970274 [ci/skip] Hermanez - Wutaf Dreeam-qwq/Gale@85eabf60 [ci/skip] cleanup Dreeam-qwq/Gale@7d9faf00 [ci/skip] cleanup & drop xor-shift random Dreeam-qwq/Gale@7af04981 [ci/skip] cleanup Dreeam-qwq/Gale@4d5d39df [ci/skip] Remove useless params standardize in upstream commit generator Dreeam-qwq/Gale@964f16ff Updated Upstream (Paper) Dreeam-qwq/Gale@0566a223 [ci/skip] cleanup Dreeam-qwq/Gale@5e3f6740 [ci/skip] cleanup work finished Dreeam-qwq/Gale@98a66cfb Updated Upstream (Paper) Dreeam-qwq/Gale@f7736578 [ci/skip] Update upstreamCommit.sh Dreeam-qwq/Gale@1c46c816 Updated Upstream (Paper) Dreeam-qwq/Gale@2b0a4c09 [ci/skip] Skip tests during auto update validate phase Purpur Changes: PurpurMC/Purpur@4a0a86b9 Updated Upstream (Paper) PurpurMC/Purpur@7399988c Fix hover in /plugins PurpurMC/Purpur@5e5857dc [ci/skip] modify ci skip references in paper upstream commits PurpurMC/Purpur@5583a3f1 Updated Upstream (Paper)
184 lines
12 KiB
Diff
184 lines
12 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
|
Date: Sat, 2 Mar 2024 18:22:15 -0500
|
|
Subject: [PATCH] Improve Purpur AFK system
|
|
|
|
AFK command & command cooldown
|
|
AFK title message
|
|
|
|
diff --git a/net/minecraft/commands/Commands.java b/net/minecraft/commands/Commands.java
|
|
index 967c01f9e40c2c73f266de281425c918472cf66e..d8464f77c54f547161356b78e76429923937b4a7 100644
|
|
--- a/net/minecraft/commands/Commands.java
|
|
+++ b/net/minecraft/commands/Commands.java
|
|
@@ -242,6 +242,7 @@ public class Commands {
|
|
StopCommand.register(this.dispatcher);
|
|
TransferCommand.register(this.dispatcher);
|
|
WhitelistCommand.register(this.dispatcher);
|
|
+ org.purpurmc.purpur.command.AFKCommand.register(this.dispatcher); // Leaf - Improve Purpur AFK system
|
|
org.purpurmc.purpur.command.CreditsCommand.register(this.dispatcher); // Purpur - Add credits command
|
|
org.purpurmc.purpur.command.DemoCommand.register(this.dispatcher); // Purpur - Add demo command
|
|
org.purpurmc.purpur.command.PingCommand.register(this.dispatcher); // Purpur - Add ping command
|
|
diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
|
|
index dfb4524d80f642eff1b146dd2fbfa07f21d844c6..2c67693cc3781eb5aee10b4dfb9617cbe107e922 100644
|
|
--- a/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -2460,6 +2460,10 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
|
|
|
|
// Purpur start - AFK API
|
|
private boolean isAfk = false;
|
|
+ // Leaf sart - Improve Purpur AFK system
|
|
+ public boolean isCommandAfk = false;
|
|
+ public boolean commandAfkStatus = false;
|
|
+ // Leaf end - Improve Purpur AFK system
|
|
|
|
@Override
|
|
public void setAfk(boolean afk) {
|
|
@@ -2497,6 +2501,18 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
|
|
String prefix = (split.length > 0 ? split[0] : "").replace(org.purpurmc.purpur.PurpurConfig.afkTabListPrefix, "");
|
|
String suffix = (split.length > 1 ? split[1] : "").replace(org.purpurmc.purpur.PurpurConfig.afkTabListSuffix, "");
|
|
if (afk) {
|
|
+ // Leaf start - Improve Purpur AFK system
|
|
+ String[] rawTitle = org.purpurmc.purpur.PurpurConfig.afkTitleAway.split(":");
|
|
+ String title = rawTitle[0];
|
|
+ String subTitle = rawTitle[1];
|
|
+ long fadeInTicks = Long.parseLong(rawTitle[2]);
|
|
+ long stayTicks = Long.parseLong(rawTitle[3]);
|
|
+ long fadeOutTicks = Long.parseLong(rawTitle[4]);
|
|
+
|
|
+ net.kyori.adventure.title.Title tile = net.kyori.adventure.title.Title.title(net.kyori.adventure.text.minimessage.MiniMessage.miniMessage().deserialize(title), net.kyori.adventure.text.minimessage.MiniMessage.miniMessage().deserialize(subTitle), net.kyori.adventure.title.Title.Times.times(net.kyori.adventure.util.Ticks.duration(fadeInTicks), net.kyori.adventure.util.Ticks.duration(stayTicks), net.kyori.adventure.util.Ticks.duration(fadeOutTicks)));
|
|
+ getBukkitEntity().showTitle(tile);
|
|
+ // Leaf end - Improve Purpur AFK system
|
|
+
|
|
getBukkitEntity().setPlayerListName(org.purpurmc.purpur.PurpurConfig.afkTabListPrefix + prefix + scoreboardName + suffix + org.purpurmc.purpur.PurpurConfig.afkTabListSuffix, true);
|
|
} else {
|
|
getBukkitEntity().setPlayerListName(prefix + scoreboardName + suffix, true);
|
|
diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
index 5078887fc6056a0f3ef5acd5e052116107737e62..9c5ba056376a731871a2c00654cc179915d4dafd 100644
|
|
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -2261,6 +2261,8 @@ public class ServerGamePacketListenerImpl
|
|
}
|
|
}
|
|
|
|
+ public static final Map<java.util.UUID, Long> afkCooldown = new it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap<>(); // Leaf - Improve Purpur AFK system
|
|
+
|
|
@Override
|
|
public void handleChatCommand(ServerboundChatCommandPacket packet) {
|
|
this.tryHandleChat(packet.command(), () -> {
|
|
@@ -2281,6 +2283,32 @@ public class ServerGamePacketListenerImpl
|
|
LOGGER.info("{} issued server command: {}", this.player.getScoreboardName(), prefixedCommand);
|
|
}
|
|
|
|
+ // Leaf start - Improve Purpur AFK system
|
|
+ if (command.equals("afk")) {
|
|
+ this.player.commandAfkStatus = this.player.isAfk();
|
|
+ this.player.isCommandAfk = true;
|
|
+
|
|
+ if (org.purpurmc.purpur.PurpurConfig.afkCommandCooldown > 0) {
|
|
+ java.util.UUID uuid = this.player.getUUID();
|
|
+ Long cooldown = afkCooldown.get(uuid);
|
|
+ long currentTime = System.nanoTime();
|
|
+
|
|
+ if (cooldown != null && (currentTime - cooldown) / 1_000_000_000 <= org.purpurmc.purpur.PurpurConfig.afkCommandCooldown) {
|
|
+ String msg = org.purpurmc.purpur.PurpurConfig.afkCooldown;
|
|
+
|
|
+ if (msg != null && !msg.isEmpty()) {
|
|
+ net.kyori.adventure.text.Component message = net.kyori.adventure.text.minimessage.MiniMessage.miniMessage().deserialize(msg.replace("%time%", String.valueOf(org.purpurmc.purpur.PurpurConfig.afkCommandCooldown - (currentTime - cooldown) / 1_000_000_000)));
|
|
+ this.player.sendMessage(message);
|
|
+ }
|
|
+
|
|
+ return;
|
|
+ } else {
|
|
+ afkCooldown.put(uuid, currentTime);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ // Leaf end - Improve Purpur AFK system
|
|
+
|
|
PlayerCommandPreprocessEvent event = new PlayerCommandPreprocessEvent(this.getCraftPlayer(), prefixedCommand, new LazyPlayerSet(this.server));
|
|
this.cserver.getPluginManager().callEvent(event);
|
|
|
|
@@ -2318,11 +2346,37 @@ public class ServerGamePacketListenerImpl
|
|
|
|
private void performSignedChatCommand(ServerboundChatCommandSignedPacket packet, LastSeenMessages lastSeenMessages) {
|
|
// CraftBukkit start
|
|
- String command = "/" + packet.command();
|
|
+ String command = "/" + packet.command(); // Leaf start - Improve Purpur AFK system - diff on change
|
|
if (org.spigotmc.SpigotConfig.logCommands) { // Paper - Add missing SpigotConfig logCommands check
|
|
LOGGER.info("{} issued server command: {}", this.player.getScoreboardName(), command);
|
|
} // Paper - Add missing SpigotConfig logCommands check
|
|
|
|
+ // Leaf start - Improve Purpur AFK system
|
|
+ if (command.equals("/afk")) {
|
|
+ this.player.commandAfkStatus = this.player.isAfk();
|
|
+ this.player.isCommandAfk = true;
|
|
+
|
|
+ if (org.purpurmc.purpur.PurpurConfig.afkCommandCooldown > 0) {
|
|
+ java.util.UUID uuid = this.player.getUUID();
|
|
+ Long cooldown = afkCooldown.get(uuid);
|
|
+ long currentTime = System.nanoTime();
|
|
+
|
|
+ if (cooldown != null && (currentTime - cooldown) / 1_000_000_000 <= org.purpurmc.purpur.PurpurConfig.afkCommandCooldown) {
|
|
+ String msg = org.purpurmc.purpur.PurpurConfig.afkCooldown;
|
|
+
|
|
+ if (msg != null && !msg.isEmpty()) {
|
|
+ net.kyori.adventure.text.Component message = net.kyori.adventure.text.minimessage.MiniMessage.miniMessage().deserialize(msg.replace("%time%", String.valueOf(org.purpurmc.purpur.PurpurConfig.afkCommandCooldown - (currentTime - cooldown) / 1_000_000_000)));
|
|
+ this.player.sendMessage(message);
|
|
+ }
|
|
+
|
|
+ return;
|
|
+ } else {
|
|
+ afkCooldown.put(uuid, currentTime);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ // Leaf end - Improve Purpur AFK system
|
|
+
|
|
PlayerCommandPreprocessEvent event = new PlayerCommandPreprocessEvent(this.getCraftPlayer(), command, new LazyPlayerSet(this.server));
|
|
this.cserver.getPluginManager().callEvent(event);
|
|
command = event.getMessage().substring(1);
|
|
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
|
|
index 831d1a60a5ed57d4f09b5ece6ffb50e061398cc0..0bb8c326a468e79a7f5a4f3395a3c2fe84352f47 100644
|
|
--- a/net/minecraft/server/players/PlayerList.java
|
|
+++ b/net/minecraft/server/players/PlayerList.java
|
|
@@ -667,6 +667,7 @@ public abstract class PlayerList {
|
|
org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handlePlayerLeave(player); // Leaves - protocol
|
|
// Paper end - Fix kick event leave message not being sent
|
|
org.purpurmc.purpur.task.BossBarTask.removeFromAll(player.getBukkitEntity()); // Purpur - Implement TPSBar
|
|
+ net.minecraft.server.network.ServerGamePacketListenerImpl.afkCooldown.remove(player.getBukkitEntity().getUniqueId()); // Leaf - Improve Purpur AFK system
|
|
ServerLevel serverLevel = player.serverLevel();
|
|
player.awardStat(Stats.LEAVE_GAME);
|
|
// CraftBukkit start - Quitting must be before we do final save of data, in case plugins need to modify it
|
|
diff --git a/org/purpurmc/purpur/PurpurConfig.java b/org/purpurmc/purpur/PurpurConfig.java
|
|
index c168e9d2c395044a662efd2d9ccde8b20c070b22..ee254498e71d50d461b7d6716704df8c2733037e 100644
|
|
--- a/org/purpurmc/purpur/PurpurConfig.java
|
|
+++ b/org/purpurmc/purpur/PurpurConfig.java
|
|
@@ -175,6 +175,11 @@ public class PurpurConfig {
|
|
public static String cannotRideMob = "<red>You cannot mount that mob";
|
|
public static String afkBroadcastAway = "<yellow><italic>%s is now AFK";
|
|
public static String afkBroadcastBack = "<yellow><italic>%s is no longer AFK";
|
|
+ // Leaf start - Improve Purpur AFK system
|
|
+ public static String afkTitleAway = "<gold><bold>AFK:<red>You are now AFK...:10:70:20";
|
|
+ public static int afkCommandCooldown = 0;
|
|
+ public static String afkCooldown = "<gray>You need to wait %time%s to use /afk.";
|
|
+ // Leaf end - Improve Purpur AFK system
|
|
public static boolean afkBroadcastUseDisplayName = false;
|
|
public static String afkTabListPrefix = "[AFK] ";
|
|
public static String afkTabListSuffix = "";
|
|
@@ -194,6 +199,15 @@ public class PurpurConfig {
|
|
cannotRideMob = getString("settings.messages.cannot-ride-mob", cannotRideMob);
|
|
afkBroadcastAway = getString("settings.messages.afk-broadcast-away", afkBroadcastAway);
|
|
afkBroadcastBack = getString("settings.messages.afk-broadcast-back", afkBroadcastBack);
|
|
+ // Leaf start - Improve Purpur AFK system
|
|
+ afkTitleAway = getString("settings.messages.afk-title-away", afkTitleAway);
|
|
+ if (afkTitleAway.split(":").length != 5) {
|
|
+ Bukkit.getLogger().log(Level.SEVERE, "You put wrong format of afk-title-away in PurpurConfig, it should look like <gold><bold>AFK:<red>You are now AFK...:10:70:20");
|
|
+ Bukkit.getLogger().log(Level.SEVERE, "'Title:Sub Title:Title Fade In Ticks:Title Stay Ticks:Title Fade Out Ticks', split with :");
|
|
+ }
|
|
+ afkCommandCooldown = getInt("settings.messages.afk-command-cooldown", afkCommandCooldown);
|
|
+ afkCooldown = MiniMessage.miniMessage().serialize(MiniMessage.miniMessage().deserialize(getString("settings.messages.afk-command-cooldown-msg", afkCooldown)));
|
|
+ // Leaf end - Improve Purpur AFK system
|
|
afkBroadcastUseDisplayName = getBoolean("settings.messages.afk-broadcast-use-display-name", afkBroadcastUseDisplayName);
|
|
afkTabListPrefix = MiniMessage.miniMessage().serialize(MiniMessage.miniMessage().deserialize(getString("settings.messages.afk-tab-list-prefix", afkTabListPrefix)));
|
|
afkTabListSuffix = MiniMessage.miniMessage().serialize(MiniMessage.miniMessage().deserialize(getString("settings.messages.afk-tab-list-suffix", afkTabListSuffix)));
|