9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-19 15:09:15 +00:00

改进debug图像指令

This commit is contained in:
XiaoMoMi
2025-11-20 14:56:38 +08:00
parent 1a789b0e55
commit 23402f342b

View File

@@ -4,6 +4,7 @@ import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import net.momirealms.craftengine.bukkit.plugin.command.BukkitCommandFeature; import net.momirealms.craftengine.bukkit.plugin.command.BukkitCommandFeature;
import net.momirealms.craftengine.bukkit.util.KeyUtils; import net.momirealms.craftengine.bukkit.util.KeyUtils;
import net.momirealms.craftengine.core.font.BitmapImage; import net.momirealms.craftengine.core.font.BitmapImage;
@@ -22,6 +23,7 @@ import org.incendo.cloud.parser.standard.IntegerParser;
import org.incendo.cloud.suggestion.Suggestion; import org.incendo.cloud.suggestion.Suggestion;
import org.incendo.cloud.suggestion.SuggestionProvider; import org.incendo.cloud.suggestion.SuggestionProvider;
import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
public class DebugImageCommand extends BukkitCommandFeature<CommandSender> { public class DebugImageCommand extends BukkitCommandFeature<CommandSender> {
@@ -49,12 +51,14 @@ public class DebugImageCommand extends BukkitCommandFeature<CommandSender> {
String string = image.isValidCoordinate(row, column) String string = image.isValidCoordinate(row, column)
? imageId.asString() + ((row != 0 || column != 0) ? ":" + row + ":" + column : "") // 自动最小化 ? imageId.asString() + ((row != 0 || column != 0) ? ":" + row + ":" + column : "") // 自动最小化
: imageId.asString() + ":" + (row = 0) + ":" + (column = 0); // 因为是无效的所以说要强调告诉获取的是00 : imageId.asString() + ":" + (row = 0) + ":" + (column = 0); // 因为是无效的所以说要强调告诉获取的是00
Component component = Component.text() Component component = Component.empty().children(
.append(Component.text(string) List.of(
.hoverEvent(image.componentAt(row, column).color(NamedTextColor.WHITE)) Component.text(string)
.clickEvent(ClickEvent.suggestCommand(string))) .hoverEvent(image.componentAt(row, column).color(NamedTextColor.WHITE))
.append(getHelperInfo(image, row, column)) .clickEvent(ClickEvent.suggestCommand(string)),
.build(); getHelperInfo(image, row, column)
)
);
plugin().senderFactory().wrap(context.sender()).sendMessage(component); plugin().senderFactory().wrap(context.sender()).sendMessage(component);
}); });
}); });
@@ -65,24 +69,25 @@ public class DebugImageCommand extends BukkitCommandFeature<CommandSender> {
return "debug_image"; return "debug_image";
} }
private static TextComponent.Builder getHelperInfo(BitmapImage image, int row, int column) { private static TextComponent getHelperInfo(BitmapImage image, int row, int column) {
String raw = new String(Character.toChars(image.codepointAt(row, column))); String raw = new String(Character.toChars(image.codepointAt(row, column)));
String font = image.font().toString(); String font = image.font().toString();
return Component.text() return Component.empty().children(List.of(
.append(Component.text(" ")) Component.text(" "),
.append(Component.text("[MM]") Component.text("[MiniMessage]")
.color(NamedTextColor.YELLOW) .color(TextColor.color(255,192,203))
.hoverEvent(Component.text("Copy", NamedTextColor.YELLOW)) .hoverEvent(Component.text("Copy", NamedTextColor.YELLOW))
.clickEvent(ClickEvent.suggestCommand(FormatUtils.miniMessageFont(raw, font)))) .clickEvent(ClickEvent.suggestCommand(FormatUtils.miniMessageFont(raw, font))),
.append(Component.text(" ")) Component.text(" "),
.append(Component.text("[MD]") Component.text("[MineDown]")
.color(NamedTextColor.YELLOW) .color(TextColor.color(123,104,238))
.hoverEvent(Component.text("Copy", NamedTextColor.YELLOW)) .hoverEvent(Component.text("Copy", NamedTextColor.YELLOW))
.clickEvent(ClickEvent.suggestCommand(FormatUtils.mineDownFont(raw, font)))) .clickEvent(ClickEvent.suggestCommand(FormatUtils.mineDownFont(raw, font))),
.append(Component.text(" ")) Component.text(" "),
.append(Component.text("[RAW]") Component.text("[RAW]")
.color(NamedTextColor.YELLOW) .color(TextColor.color(119,136,153))
.hoverEvent(Component.text("Copy", NamedTextColor.YELLOW)) .hoverEvent(Component.text("Copy", NamedTextColor.YELLOW))
.clickEvent(ClickEvent.suggestCommand(raw))); .clickEvent(ClickEvent.suggestCommand("{\"text\":\"" + raw + "\",\"font\":\"" + font + "\"}"))
));
} }
} }