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
137 lines
8.1 KiB
Diff
137 lines
8.1 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
|
Date: Wed, 7 Aug 2024 18:54:01 +0800
|
|
Subject: [PATCH] Configurable unknown command message
|
|
|
|
|
|
diff --git a/net/minecraft/commands/Commands.java b/net/minecraft/commands/Commands.java
|
|
index 54cc28bb1693be2077cb30d1dc85f9ae24a6c954..1e84f726f23877ed4be1aa901d7df0b11aa95552 100644
|
|
--- a/net/minecraft/commands/Commands.java
|
|
+++ b/net/minecraft/commands/Commands.java
|
|
@@ -403,31 +403,8 @@ public class Commands {
|
|
// Paper start - Add UnknownCommandEvent
|
|
final net.kyori.adventure.text.TextComponent.Builder builder = net.kyori.adventure.text.Component.text();
|
|
// source.sendFailure(ComponentUtils.fromMessage(var7.getRawMessage()));
|
|
- builder.color(net.kyori.adventure.text.format.NamedTextColor.RED).append(io.papermc.paper.command.brigadier.MessageComponentSerializer.message().deserialize(var7.getRawMessage()));
|
|
// Paper end - Add UnknownCommandEvent
|
|
- if (var7.getInput() != null && var7.getCursor() >= 0) {
|
|
- int min = Math.min(var7.getInput().length(), var7.getCursor());
|
|
- MutableComponent mutableComponent = Component.empty()
|
|
- .withStyle(ChatFormatting.GRAY)
|
|
- .withStyle(style -> style.withClickEvent(new ClickEvent.SuggestCommand("/" + label))); // CraftBukkit // Paper
|
|
- if (min > 10) {
|
|
- mutableComponent.append(CommonComponents.ELLIPSIS);
|
|
- }
|
|
-
|
|
- mutableComponent.append(var7.getInput().substring(Math.max(0, min - 10), min));
|
|
- if (min < var7.getInput().length()) {
|
|
- Component component = Component.literal(var7.getInput().substring(min)).withStyle(ChatFormatting.RED, ChatFormatting.UNDERLINE);
|
|
- mutableComponent.append(component);
|
|
- }
|
|
-
|
|
- mutableComponent.append(Component.translatable("command.context.here").withStyle(ChatFormatting.RED, ChatFormatting.ITALIC));
|
|
- // Paper start - Add UnknownCommandEvent
|
|
- // source.sendFailure(mutableComponent);
|
|
- builder
|
|
- .append(net.kyori.adventure.text.Component.newline())
|
|
- .append(io.papermc.paper.adventure.PaperAdventure.asAdventure(mutableComponent));
|
|
- }
|
|
- org.bukkit.event.command.UnknownCommandEvent event = new org.bukkit.event.command.UnknownCommandEvent(source.getBukkitSender(), command, org.spigotmc.SpigotConfig.unknownCommandMessage.isEmpty() ? null : builder.build());
|
|
+ org.bukkit.event.command.UnknownCommandEvent event = new org.bukkit.event.command.UnknownCommandEvent(source.getBukkitSender(), command, getUnknownCommandMessage(builder, var7, label)); // Leaf - Configurable unknown command message
|
|
org.bukkit.Bukkit.getServer().getPluginManager().callEvent(event);
|
|
if (event.message() != null) {
|
|
source.sendFailure(io.papermc.paper.adventure.PaperAdventure.asVanilla(event.message()), false);
|
|
@@ -678,6 +655,92 @@ public class Commands {
|
|
};
|
|
}
|
|
|
|
+ // Leaf start - Configurable unknown command message
|
|
+ private static net.kyori.adventure.text.Component getUnknownCommandMessage(
|
|
+ net.kyori.adventure.text.TextComponent.Builder builder, CommandSyntaxException commandSyntaxException, String label
|
|
+ ) {
|
|
+ String rawMessage = org.dreeam.leaf.config.modules.misc.UnknownCommandMessage.unknownCommandMessage;
|
|
+
|
|
+ if ("default".equals(rawMessage)) {
|
|
+ return getVanillaUnknownCommandMessage(builder, commandSyntaxException, label);
|
|
+ }
|
|
+
|
|
+ net.kyori.adventure.text.Component messageComponent = null;
|
|
+ net.kyori.adventure.text.Component detailComponent = null;
|
|
+
|
|
+ if (rawMessage.contains("<message>")) {
|
|
+ messageComponent = io.papermc.paper.command.brigadier.MessageComponentSerializer.message().deserialize(commandSyntaxException.getRawMessage());
|
|
+ }
|
|
+
|
|
+ final String input = commandSyntaxException.getInput();
|
|
+ final int cursor = commandSyntaxException.getCursor();
|
|
+
|
|
+ if (rawMessage.contains("<detail>") && input != null && cursor >= 0) {
|
|
+ final int min = Math.min(input.length(), cursor);
|
|
+ final net.kyori.adventure.text.TextComponent.Builder detail = net.kyori.adventure.text.Component.text();
|
|
+ final net.kyori.adventure.text.Component context = net.kyori.adventure.text.Component.translatable("command.context.here")
|
|
+ .color(net.kyori.adventure.text.format.NamedTextColor.RED)
|
|
+ .decorate(net.kyori.adventure.text.format.TextDecoration.ITALIC);
|
|
+ final net.kyori.adventure.text.event.ClickEvent event = net.kyori.adventure.text.event.ClickEvent.suggestCommand("/" + label);
|
|
+
|
|
+ detail.color(net.kyori.adventure.text.format.NamedTextColor.GRAY);
|
|
+
|
|
+ if (min > 10) {
|
|
+ detail.append(net.kyori.adventure.text.Component.text("..."));
|
|
+ }
|
|
+
|
|
+ detail.append(net.kyori.adventure.text.Component.text(input.substring(Math.max(0, min - 10), min)));
|
|
+ if (min < input.length()) {
|
|
+ net.kyori.adventure.text.Component commandInput = net.kyori.adventure.text.Component.text(input.substring(min))
|
|
+ .color(net.kyori.adventure.text.format.NamedTextColor.RED)
|
|
+ .decorate(net.kyori.adventure.text.format.TextDecoration.UNDERLINED);
|
|
+
|
|
+ detail.append(commandInput);
|
|
+ }
|
|
+
|
|
+ detail.append(context);
|
|
+ detail.clickEvent(event);
|
|
+
|
|
+ detailComponent = detail.build();
|
|
+ }
|
|
+
|
|
+ return builder.append(net.kyori.adventure.text.minimessage.MiniMessage.miniMessage().deserialize(rawMessage)).build()
|
|
+ .replaceText(net.kyori.adventure.text.TextReplacementConfig.builder().matchLiteral("<message>").replacement(messageComponent).build())
|
|
+ .replaceText(net.kyori.adventure.text.TextReplacementConfig.builder().matchLiteral("<detail>").replacement(detailComponent).build());
|
|
+ }
|
|
+
|
|
+ private static net.kyori.adventure.text.Component getVanillaUnknownCommandMessage(
|
|
+ net.kyori.adventure.text.TextComponent.Builder builder, CommandSyntaxException var7, String label
|
|
+ ) {
|
|
+ builder.color(net.kyori.adventure.text.format.NamedTextColor.RED).append(io.papermc.paper.command.brigadier.MessageComponentSerializer.message().deserialize(var7.getRawMessage()));
|
|
+
|
|
+ if (var7.getInput() != null && var7.getCursor() >= 0) {
|
|
+ int min = Math.min(var7.getInput().length(), var7.getCursor());
|
|
+ MutableComponent mutableComponent = Component.empty()
|
|
+ .withStyle(ChatFormatting.GRAY)
|
|
+ .withStyle(style -> style.withClickEvent(new ClickEvent.SuggestCommand("/" + label))); // CraftBukkit // Paper
|
|
+ if (min > 10) {
|
|
+ mutableComponent.append(CommonComponents.ELLIPSIS);
|
|
+ }
|
|
+
|
|
+ mutableComponent.append(var7.getInput().substring(Math.max(0, min - 10), min));
|
|
+ if (min < var7.getInput().length()) {
|
|
+ Component component = Component.literal(var7.getInput().substring(min)).withStyle(ChatFormatting.RED, ChatFormatting.UNDERLINE);
|
|
+ mutableComponent.append(component);
|
|
+ }
|
|
+
|
|
+ mutableComponent.append(Component.translatable("command.context.here").withStyle(ChatFormatting.RED, ChatFormatting.ITALIC));
|
|
+ // Paper start - Add UnknownCommandEvent
|
|
+ // source.sendFailure(mutableComponent);
|
|
+ builder
|
|
+ .append(net.kyori.adventure.text.Component.newline())
|
|
+ .append(io.papermc.paper.adventure.PaperAdventure.asAdventure(mutableComponent));
|
|
+ }
|
|
+
|
|
+ return builder.build();
|
|
+ }
|
|
+ // Leaf end - Configurable unknown command message
|
|
+
|
|
public static void validate() {
|
|
CommandBuildContext commandBuildContext = createValidationContext(VanillaRegistries.createLookup());
|
|
CommandDispatcher<CommandSourceStack> dispatcher = new Commands(Commands.CommandSelection.ALL, commandBuildContext).getDispatcher();
|