From 8554d3b9627ab3b1a776fc893b4d9595165a74ad Mon Sep 17 00:00:00 2001 From: Helvetica Volubi Date: Sun, 16 Aug 2026 14:15:00 +0800 Subject: [PATCH] refactor: improve error handling in ProfilerCommand registration and update block argument handling --- .../shiroha/commands/CommandRegister.java | 10 +++++--- .../commands/profiler/ProfilerCommand.java | 23 ++++++++----------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/commands/CommandRegister.java b/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/commands/CommandRegister.java index 99061ce..5624e88 100644 --- a/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/commands/CommandRegister.java +++ b/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/commands/CommandRegister.java @@ -1,5 +1,6 @@ package io.nanachiyo0721.shiroha.commands; +import com.mojang.logging.LogUtils; import io.nanachiyo0721.shiroha.commands.bar.BarCommand; import io.nanachiyo0721.shiroha.commands.profiler.ProfilerCommand; import io.nanachiyo0721.shiroha.config.modules.function.ProfilerConfig; @@ -14,9 +15,12 @@ public class CommandRegister { public static void register() { new BarCommand().register(); if (ProfilerConfig.enabled) { - TickRegions.getScheduleProfilerManager().init(); - - new ProfilerCommand(TickRegions.getScheduleProfilerManager()).register(); + try { + TickRegions.getScheduleProfilerManager().init(); + new ProfilerCommand(TickRegions.getScheduleProfilerManager()).register(); + } catch (UnsupportedOperationException e) { + LogUtils.getLogger().warn("Profiler command registration failed: {}", e.getMessage()); + } } } } diff --git a/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/commands/profiler/ProfilerCommand.java b/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/commands/profiler/ProfilerCommand.java index f2376f6..8fb995f 100644 --- a/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/commands/profiler/ProfilerCommand.java +++ b/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/commands/profiler/ProfilerCommand.java @@ -12,6 +12,9 @@ import io.papermc.paper.command.brigadier.CommandSourceStack; import io.papermc.paper.threadedregions.RegionizedServer; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.TextColor; +import net.minecraft.commands.arguments.coordinates.ColumnPosArgument; +import net.minecraft.commands.arguments.coordinates.Coordinates; +import net.minecraft.core.BlockPos; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.command.CommandSender; @@ -266,7 +269,7 @@ public class ProfilerCommand extends RootNode { private final class WorldArg extends ArgumentNode { private WorldArg() { super("world", StringArgumentType.word()); - children(BlockXArg::new); + children(BlockArg::new); } @Override @@ -279,16 +282,9 @@ public class ProfilerCommand extends RootNode { } } - private final class BlockXArg extends ArgumentNode { - private BlockXArg() { - super("blockX", IntegerArgumentType.integer()); - children(BlockZArg::new); - } - } - - private final class BlockZArg extends ArgumentNode { - private BlockZArg() { - super("blockZ", IntegerArgumentType.integer()); + private final class BlockArg extends ArgumentNode { + private BlockArg() { + super("blockPos", ColumnPosArgument.columnPos()); children(CoordinateSecondsArg::new); } } @@ -302,8 +298,9 @@ public class ProfilerCommand extends RootNode { protected boolean execute(@NotNull CommandContext context) { final CommandSender sender = context.getSender(); final String worldName = context.getArgument(WorldArg.class); - final int blockX = context.getArgument(BlockXArg.class); - final int blockZ = context.getArgument(BlockZArg.class); + final BlockPos blockPos = context.getArgument(BlockArg.class).getBlockPos((net.minecraft.commands.CommandSourceStack) context.getMojangContext().getSource()); + final int blockX = blockPos.getX(); + final int blockZ = blockPos.getZ(); final World world = Bukkit.getWorld(worldName); if (world == null) {