refactor: improve error handling in ProfilerCommand registration and update block argument handling
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
-13
@@ -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<String> {
|
||||
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<Integer> {
|
||||
private BlockXArg() {
|
||||
super("blockX", IntegerArgumentType.integer());
|
||||
children(BlockZArg::new);
|
||||
}
|
||||
}
|
||||
|
||||
private final class BlockZArg extends ArgumentNode<Integer> {
|
||||
private BlockZArg() {
|
||||
super("blockZ", IntegerArgumentType.integer());
|
||||
private final class BlockArg extends ArgumentNode<Coordinates> {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user