refactor: improve error handling in ProfilerCommand registration and update block argument handling
Shiroha CI / build (push) Canceled after 0s
Shiroha CI / Event File (push) Canceled after 0s

This commit is contained in:
2026-08-16 14:15:00 +08:00
parent 8331d07690
commit 8554d3b962
2 changed files with 17 additions and 16 deletions
@@ -1,5 +1,6 @@
package io.nanachiyo0721.shiroha.commands; package io.nanachiyo0721.shiroha.commands;
import com.mojang.logging.LogUtils;
import io.nanachiyo0721.shiroha.commands.bar.BarCommand; import io.nanachiyo0721.shiroha.commands.bar.BarCommand;
import io.nanachiyo0721.shiroha.commands.profiler.ProfilerCommand; import io.nanachiyo0721.shiroha.commands.profiler.ProfilerCommand;
import io.nanachiyo0721.shiroha.config.modules.function.ProfilerConfig; import io.nanachiyo0721.shiroha.config.modules.function.ProfilerConfig;
@@ -14,9 +15,12 @@ public class CommandRegister {
public static void register() { public static void register() {
new BarCommand().register(); new BarCommand().register();
if (ProfilerConfig.enabled) { if (ProfilerConfig.enabled) {
try {
TickRegions.getScheduleProfilerManager().init(); TickRegions.getScheduleProfilerManager().init();
new ProfilerCommand(TickRegions.getScheduleProfilerManager()).register(); new ProfilerCommand(TickRegions.getScheduleProfilerManager()).register();
} catch (UnsupportedOperationException e) {
LogUtils.getLogger().warn("Profiler command registration failed: {}", e.getMessage());
}
} }
} }
} }
@@ -12,6 +12,9 @@ import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.threadedregions.RegionizedServer; import io.papermc.paper.threadedregions.RegionizedServer;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor; 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.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@@ -266,7 +269,7 @@ public class ProfilerCommand extends RootNode {
private final class WorldArg extends ArgumentNode<String> { private final class WorldArg extends ArgumentNode<String> {
private WorldArg() { private WorldArg() {
super("world", StringArgumentType.word()); super("world", StringArgumentType.word());
children(BlockXArg::new); children(BlockArg::new);
} }
@Override @Override
@@ -279,16 +282,9 @@ public class ProfilerCommand extends RootNode {
} }
} }
private final class BlockXArg extends ArgumentNode<Integer> { private final class BlockArg extends ArgumentNode<Coordinates> {
private BlockXArg() { private BlockArg() {
super("blockX", IntegerArgumentType.integer()); super("blockPos", ColumnPosArgument.columnPos());
children(BlockZArg::new);
}
}
private final class BlockZArg extends ArgumentNode<Integer> {
private BlockZArg() {
super("blockZ", IntegerArgumentType.integer());
children(CoordinateSecondsArg::new); children(CoordinateSecondsArg::new);
} }
} }
@@ -302,8 +298,9 @@ public class ProfilerCommand extends RootNode {
protected boolean execute(@NotNull CommandContext context) { protected boolean execute(@NotNull CommandContext context) {
final CommandSender sender = context.getSender(); final CommandSender sender = context.getSender();
final String worldName = context.getArgument(WorldArg.class); final String worldName = context.getArgument(WorldArg.class);
final int blockX = context.getArgument(BlockXArg.class); final BlockPos blockPos = context.getArgument(BlockArg.class).getBlockPos((net.minecraft.commands.CommandSourceStack) context.getMojangContext().getSource());
final int blockZ = context.getArgument(BlockZArg.class); final int blockX = blockPos.getX();
final int blockZ = blockPos.getZ();
final World world = Bukkit.getWorld(worldName); final World world = Bukkit.getWorld(worldName);
if (world == null) { if (world == null) {