mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-26 18:39:23 +00:00
ClassInstanceMultiMap belongs to Minecraft vanilla entity storage. And is unused, since replaced by spottedleaf's entity storage (rewrite chunk system). However these patches might be useful for vanilla entity storage if is used.
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 de450f9ef03944b101b483126af6a778ae8a4d1d..d201c3965d5a55de740175c140bc7ee411f1be78 100644
|
|
--- a/net/minecraft/commands/Commands.java
|
|
+++ b/net/minecraft/commands/Commands.java
|
|
@@ -405,31 +405,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("/" + command)));
|
|
- 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, command)); // 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);
|
|
@@ -663,6 +640,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 command
|
|
+ ) {
|
|
+ String rawMessage = org.dreeam.leaf.config.modules.misc.UnknownCommandMessage.unknownCommandMessage;
|
|
+
|
|
+ if ("default".equals(rawMessage)) {
|
|
+ return getVanillaUnknownCommandMessage(builder, commandSyntaxException, command);
|
|
+ }
|
|
+
|
|
+ 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("/" + command);
|
|
+
|
|
+ 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 command
|
|
+ ) {
|
|
+ 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("/" + command)));
|
|
+ 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();
|