mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2026-01-03 14:22:26 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@89cdcba5 [ci/skip] Replace wiki mention for BlockType#isOccluding (#12446) PaperMC/Paper@5f0b8292 Re-add chunk position check to regionfile recalculation patch PaperMC/Paper@04b91129 Update projects dependents GitHub Action (#12436) PaperMC/Paper@def0532f Fix writing headers and update to be more papery (#12459) PaperMC/Paper@d22644aa Expand cooldown API (#12435) PaperMC/Paper@df429932 Fix floating warning log when the kick event is canceled (#12374) PaperMC/Paper@a820bdae [ci/skip] Some javadoc fixes PaperMC/Paper@55f20209 Fix CCE in LingeringPotionSplashEvent (#12463) PaperMC/Paper@1410a22b Fix passengers sending when riding players PaperMC/Paper@767868dd Fix some components (#12457) PaperMC/Paper@9cddf136 Fix portal create event block list (#12373) PaperMC/Paper@a112d370 Fix horse_variant and tropical_fish_pattern (#12472) PaperMC/Paper@a211ac2e Remove unused warning (#12478) PaperMC/Paper@ae512811 Add isSuffocating to Block and BlockState (#12445) PaperMC/Paper@3409e2d7 Mace was not included in the ENCHANTABLE MaterialSetTag (#12476) PaperMC/Paper@1cfc96bc Add keyStream() API to registries (#12479) PaperMC/Paper@3222985e [ci/skip] Rebuild patches PaperMC/Paper@deaccd2c [ci/skip] Add file reference url to help.yml (#12481) PaperMC/Paper@f86b4352 Add vault change state event (#12069) PaperMC/Paper@3e3b42cd Update player chat session sync (#12382) PaperMC/Paper@f8fa4f6f Add method to retrieve FishHook (#12310) PaperMC/Paper@b9d3147d Use correct placed block position for sound (#12410) PaperMC/Paper@952338b3 [ci/skip] Add missing exception docs to Player#listPlayer (#12488) PaperMC/Paper@1db37853 [ci/skip] improve javadoc for off-hand swaps through getHotbarButton (#12489) PaperMC/Paper@d1810f24 Allow Server#getDefaultGameMode before worlds are initialized (#12490) PaperMC/Paper@02d20ff7 Fix NPE in Server#getMap before worlds are loaded (#12492) PaperMC/Paper@9e873f50 Fix inconsistencies between offline/online spawn position getter (#11960) PaperMC/Paper@fc0c3717 Fix handling of resultant crafting container from craftItemResult (#12307) PaperMC/Paper@a7a76c8f Add methods for Armadillo (#12031) PaperMC/Paper@a74400d9 Update adventure to 4.21.0 (#12499) PaperMC/Paper@1e930763 Fix ipv6 loopback addresses being able to get connection throttled (#12155) PaperMC/Paper@646b80ca Fix unnecessary map data saves (#12296) PaperMC/Paper@e663f999 Add combat tracker API (#11853) PaperMC/Paper@cd4fe5b7 [ci/skip] Drop non-applicable ATs (#12498) PaperMC/Paper@5acfdd6a Fix save/load NaN Entity Motion (#12269) PaperMC/Paper@2754d7c3 Add Throw EntityChangeBlockEvent for BrushableBlockEntity#brush (#12133) PaperMC/Paper@567f63ae Parity for respawn events (#11792) PaperMC/Paper@bc3d946f Normalizes CraftEntity#toString/getHandle (#12170) PaperMC/Paper@0e9b94d5 Fix ItemStack amount issues with Chat Components (#12216) PaperMC/Paper@835b9559 Add a method on InventoryView to get the MenuType (#12193) PaperMC/Paper@c9411bfb Fix min ItemStack amount check for asHoverEvent (#12505) PaperMC/Paper@1acf3b38 Infer block entity data in brigadier blockstate argument (#12197) PaperMC/Paper@b9b3cd65 Use components instead of ChatColor in more places (#12507) PaperMC/Paper@ec421715 Add missing spaces back (#12508) Purpur Changes: PurpurMC/Purpur@c3870bda Updated Upstream (Paper) PurpurMC/Purpur@8b5044e0 [ci/skip] add idea project icon PurpurMC/Purpur@f2f682fb Updated Upstream (Paper) PurpurMC/Purpur@bdeba761 Updated Upstream (Paper) PurpurMC/Purpur@96f5b044 drop void damage height/damage migration PurpurMC/Purpur@6cc78b63 Updated Upstream (Paper) PurpurMC/Purpur@4ce97c1d [ci/skip] Update occurences of version numbers to 1.21.5 (#1658) PurpurMC/Purpur@7f5c4036 Updated Upstream (Paper) PurpurMC/Purpur@4fdf1d11 Updated Upstream (Paper) PurpurMC/Purpur@8c77678e Updated Upstream (Paper)
198 lines
13 KiB
Diff
198 lines
13 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 bcecf48b43eef377354e32695d4258ea8020f73d..aba02a7e3139030050c3c61aabf7708c6c088a68 100644
|
|
--- a/net/minecraft/commands/Commands.java
|
|
+++ b/net/minecraft/commands/Commands.java
|
|
@@ -247,6 +247,7 @@ public class Commands {
|
|
StopCommand.register(this.dispatcher);
|
|
TransferCommand.register(this.dispatcher);
|
|
WhitelistCommand.register(this.dispatcher);
|
|
+ if (org.dreeam.leaf.config.modules.gameplay.AfkCommand.enabled) 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 f3ccabaf4ff9bd0265415193831fd22b1868c00e..6d3b895fcbb3c2fe4438e1e30d87dc2150c7f462 100644
|
|
--- a/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -2382,6 +2382,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) {
|
|
@@ -2419,6 +2423,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 cec88f9bf2ca92dcd97addfbf256cda0bd0b3f6a..76e197dc09f07b5a0156dbc629dfd6818bd03110 100644
|
|
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -2322,6 +2322,7 @@ public class ServerGamePacketListenerImpl
|
|
|
|
@Override
|
|
public void handleChatCommand(ServerboundChatCommandPacket packet) {
|
|
+ final boolean isAfkCommandCooldown = this.performAfkCooldown(packet.command()); // Leaf - Improve Purpur AFK system
|
|
this.tryHandleChat(packet.command(), () -> {
|
|
// CraftBukkit start - SPIGOT-7346: Prevent disconnected players from executing commands
|
|
if (this.player.hasDisconnected()) {
|
|
@@ -2330,7 +2331,7 @@ public class ServerGamePacketListenerImpl
|
|
// CraftBukkit end
|
|
this.performUnsignedChatCommand(packet.command());
|
|
this.detectRateSpam("/" + packet.command()); // Spigot
|
|
- }, true); // CraftBukkit - sync commands
|
|
+ }, true, isAfkCommandCooldown); // CraftBukkit - sync commands // Leaf - Improve Purpur AFK system
|
|
}
|
|
|
|
private void performUnsignedChatCommand(String command) {
|
|
@@ -2363,6 +2364,7 @@ public class ServerGamePacketListenerImpl
|
|
public void handleSignedChatCommand(ServerboundChatCommandSignedPacket packet) {
|
|
Optional<LastSeenMessages> optional = this.unpackAndApplyLastSeen(packet.lastSeenMessages());
|
|
if (!optional.isEmpty()) {
|
|
+ final boolean isAfkCommandCooldown = this.performAfkCooldown(packet.command()); // Leaf - Improve Purpur AFK system
|
|
this.tryHandleChat(packet.command(), () -> {
|
|
// CraftBukkit start - SPIGOT-7346: Prevent disconnected players from executing commands
|
|
if (this.player.hasDisconnected()) {
|
|
@@ -2371,7 +2373,7 @@ public class ServerGamePacketListenerImpl
|
|
// CraftBukkit end
|
|
this.performSignedChatCommand(packet, optional.get());
|
|
this.detectRateSpam("/" + packet.command()); // Spigot
|
|
- }, true); // CraftBukkit - sync commands
|
|
+ }, true, isAfkCommandCooldown); // CraftBukkit - sync commands // Leaf - Improve Purpur AFK system
|
|
}
|
|
}
|
|
|
|
@@ -2478,12 +2480,17 @@ public class ServerGamePacketListenerImpl
|
|
return dispatcher.parse(command, this.player.createCommandSourceStack());
|
|
}
|
|
|
|
- private void tryHandleChat(String message, Runnable handler, boolean sync) { // CraftBukkit
|
|
+ // Leaf start - Improve Purpur AFK system
|
|
+ private void tryHandleChat(String message, Runnable handler, boolean sync) {
|
|
+ tryHandleChat(message, handler, sync, false);
|
|
+ }
|
|
+ private void tryHandleChat(String message, Runnable handler, boolean sync, boolean afkCommandCooldown) { // CraftBukkit
|
|
+ // Leaf end - Improve Purpur AFK system
|
|
if (isChatMessageIllegal(message)) {
|
|
this.disconnectAsync(Component.translatable("multiplayer.disconnect.illegal_characters"), org.bukkit.event.player.PlayerKickEvent.Cause.ILLEGAL_CHARACTERS); // Paper - add proper async disconnect
|
|
} else if (this.player.isRemoved() || this.player.getChatVisibility() == ChatVisiblity.HIDDEN) { // CraftBukkit - dead men tell no tales
|
|
this.send(new ClientboundSystemChatPacket(Component.translatable("chat.disabled.options").withStyle(ChatFormatting.RED), false));
|
|
- } else if (player.didPlayerJoinEvent) { // Gale - EMC - do not process chat/commands before player has joined
|
|
+ } else if (player.didPlayerJoinEvent && !afkCommandCooldown) { // Gale - EMC - do not process chat/commands before player has joined // Leaf - Improve Purpur AFK system - don't process afk command if in cooldown
|
|
this.player.resetLastActionTime();
|
|
// CraftBukkit start
|
|
if (sync) {
|
|
@@ -2495,6 +2502,40 @@ public class ServerGamePacketListenerImpl
|
|
}
|
|
}
|
|
|
|
+ // Leaf start - Improve Purpur AFK system
|
|
+ public static final Map<java.util.UUID, Long> afkCooldown = new it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap<>();
|
|
+ private boolean performAfkCooldown(String command) {
|
|
+ if (!org.dreeam.leaf.config.modules.gameplay.AfkCommand.enabled || !"afk".equals(command)) {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ this.player.commandAfkStatus = this.player.isAfk();
|
|
+ this.player.isCommandAfk = true;
|
|
+
|
|
+ if (org.purpurmc.purpur.PurpurConfig.afkCommandCooldown <= 0) {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ 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 true;
|
|
+ } else {
|
|
+ afkCooldown.put(uuid, currentTime);
|
|
+ return false;
|
|
+ }
|
|
+ }
|
|
+ // Leaf end - Improve Purpur AFK system
|
|
+
|
|
private Optional<LastSeenMessages> unpackAndApplyLastSeen(LastSeenMessages.Update update) {
|
|
synchronized (this.lastSeenMessages) {
|
|
Optional var10000;
|
|
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
|
|
index 536fea9622cdec212aa61adbb627704c59a8999f..37ba75bd50f785da11a0127fb40d86ee8b988c17 100644
|
|
--- a/net/minecraft/server/players/PlayerList.java
|
|
+++ b/net/minecraft/server/players/PlayerList.java
|
|
@@ -524,6 +524,7 @@ public abstract class PlayerList {
|
|
public @Nullable net.kyori.adventure.text.Component remove(ServerPlayer player, net.kyori.adventure.text.Component leaveMessage) {
|
|
// 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 23e959e348a1875d63b5862411dae162625a1aac..78e90d4e173c52c0dadc6c8e00326829a7c57575 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)));
|