mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@88a3a870 Configurable xp orb merge group count (#12503) PaperMC/Paper@53d1d04e Disable Item Obfuscation for entity related stacks (#12297) PaperMC/Paper@c98cd658 Add configuration interface to expose certain config values (#12273) PaperMC/Paper@42a2a6c2 Supports the ability for commands to be registered internally (#12520) PaperMC/Paper@753cff7c Improvements for Dump paper commands (#12512) PaperMC/Paper@e2da5d2f Registry API for supported Mob Variants (#12417) PaperMC/Paper@ab0253fe Expand PlayerDeathEvent API (#12221) PaperMC/Paper@cbcf75a5 Update visual fire handling with TriState support (#12303) PaperMC/Paper@6c3964d2 Properly save level data async (#12530) PaperMC/Paper@d2ad2e66 Add missing EntityLookup#getAllMapped from Moonrise PaperMC/Paper@358e72ec Remove simplify remote item matching stuff for now PaperMC/Paper@04ffca0b Also remove CraftPlayer methods PaperMC/Paper@a2525819 Update mache PaperMC/Paper@d683970d Add FishHookStateChangeEvent (#12165) PaperMC/Paper@369ad170 Cached tag parser for itemstack reading (#12547) PaperMC/Paper@841d6342 Fix ItemStack#addUnsafeEnchantment ignored for missing enchantment component (#12549) PaperMC/Paper@c000b352 fix(bukkit-brig-forwarding-map): Invert isEmpty method (#12555) PaperMC/Paper@28d7df75 Backport HeroesOfTheVillage datafixer fix PaperMC/Paper@f1dbed07 Implement BlocksAttack DamageReduction and ItemDamage (#12538) PaperMC/Paper@cc38032b Deprecate TeleportCause CHORUS_FRUIT for CONSUMABLE_EFFECT (#12546) PaperMC/Paper@35878677 [ci/skip] Fix format and mentions for ItemDamageFunction (#12560) PaperMC/Paper@7171d299 [ci/skip] Mention CAN_PLACE/CAN_BREAK component in ItemMeta (#12559) PaperMC/Paper@6f73e62e Add getPickItemStack (#12552) PaperMC/Paper@ce0fa4c4 Replace old version command with brigadier equivalent (#12502) PaperMC/Paper@fa360aa8 Add some missing annotations and an incorrect one (#12204) PaperMC/Paper@113b18ee Update paperweight and Gradle wrapper (#12573) PaperMC/Paper@f303a076 fix: Don't hardcode checks for translation registries (#12571) PaperMC/Paper@87349c31 Fix CombatTracker stale on death (#12562) PaperMC/Paper@b70bca6b Revert "fix: Don't hardcode checks for translation registries (#12571)" Purpur Changes: PurpurMC/Purpur@93011bc1 Add configuration setting to re-add End void rings (#1656) PurpurMC/Purpur@c2f48591 [ci/skip] only set default world config values once PurpurMC/Purpur@6f5bbae5 [ci/skip] move some code around PurpurMC/Purpur@5c1a9835 fix issue with `shift-right-click-repairs-mending-points` PurpurMC/Purpur@3156e446 check damage value of tool correctly PurpurMC/Purpur@a9fe4f25 Updated Upstream (Paper) PurpurMC/Purpur@9d0aa8eb Updated Upstream (Paper) PurpurMC/Purpur@603c7557 Updated Upstream (Paper) PurpurMC/Purpur@eca78060 Updated Upstream (Paper) PurpurMC/Purpur@e4e9cfdf Updated Upstream (Paper) PurpurMC/Purpur@3de2fc7d Updated Upstream (Paper) PurpurMC/Purpur@09f547de add `mob-griefing-override` config options (#1661) PurpurMC/Purpur@1dd9bd0c Updated Upstream (Paper) PurpurMC/Purpur@7a8aa86a finish updating gradle PurpurMC/Purpur@fd78b90f bandaid fix: increase the daemon heap for now
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 eb600398e4802bb47231bbc0c55fb24ce24a6efb..54cc28bb1693be2077cb30d1dc85f9ae24a6c954 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 a05cd22bfe3a2c25a5e37c973766a162ce8e7244..602a087122a6baa3cb33e1bf5e6c4d98e500fa05 100644
|
|
--- a/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -2385,6 +2385,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) {
|
|
@@ -2422,6 +2426,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 470660998d3df511f00936bcaa210142ab8ba7b2..220dd097aa1d912feb6699dccd1b68523c14cdf6 100644
|
|
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -2324,6 +2324,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()) {
|
|
@@ -2332,7 +2333,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) {
|
|
@@ -2365,6 +2366,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()) {
|
|
@@ -2373,7 +2375,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
|
|
}
|
|
}
|
|
|
|
@@ -2480,12 +2482,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) {
|
|
@@ -2497,6 +2504,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 e0dceff32b47b334ddcb76271e3cf3ea0d27e5f1..ba206b753afe26a5b4c6a2fd1fc438d9a581c3dc 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)));
|