From 8331d076909a966fc13617a4ae5663b14994eb41 Mon Sep 17 00:00:00 2001 From: Helvetica Volubi Date: Sun, 16 Aug 2026 13:26:04 +0800 Subject: [PATCH] refactor code --- .../commands/profiler/ProfilerCommand.java | 28 +++++++++---------- .../profiling/RegionScheduleProfiler.java | 5 ++-- .../RegionScheduleProfilerManager.java | 6 +--- 3 files changed, 18 insertions(+), 21 deletions(-) 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 57bd4ab..f2376f6 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 @@ -38,9 +38,9 @@ public class ProfilerCommand extends RootNode { super("sprofiler", PERM_BASE); this.profilerManager = profilerManager; children( - new StartCommand(), - new StartAtCommand(), - new StopCommand() + StartCommand::new, + StartAtCommand::new, + StopCommand::new ); } @@ -145,7 +145,7 @@ public class ProfilerCommand extends RootNode { private final class StartCommand extends LiteralNode { private StartCommand() { super("start"); - children(new TypeArg()); + children(TypeArg::new); } @Override @@ -157,7 +157,7 @@ public class ProfilerCommand extends RootNode { private final class TypeArg extends ArgumentNode { private TypeArg() { super("type", StringArgumentType.word()); - children(new CategoryArg()); + children(CategoryArg::new); } @Override @@ -175,7 +175,7 @@ public class ProfilerCommand extends RootNode { private final class CategoryArg extends ArgumentNode { private CategoryArg() { super("category", StringArgumentType.word()); - children(new RegionArg()); + children(RegionArg::new); } @Override @@ -193,7 +193,7 @@ public class ProfilerCommand extends RootNode { private final class RegionArg extends ArgumentNode { private RegionArg() { super("regionId", LongArgumentType.longArg(0L)); - children(new SecondsArg()); + children(SecondsArg::new); } } @@ -218,7 +218,7 @@ public class ProfilerCommand extends RootNode { private final class StartAtCommand extends LiteralNode { private StartAtCommand() { super("start-at"); - children(new CoordinateTypeArg()); + children(CoordinateTypeArg::new); } @Override @@ -230,7 +230,7 @@ public class ProfilerCommand extends RootNode { private final class CoordinateTypeArg extends ArgumentNode { private CoordinateTypeArg() { super("coordinateType", StringArgumentType.word()); - children(new CoordinateCategoryArg()); + children(CoordinateCategoryArg::new); } @Override @@ -248,7 +248,7 @@ public class ProfilerCommand extends RootNode { private final class CoordinateCategoryArg extends ArgumentNode { private CoordinateCategoryArg() { super("coordinateCategory", StringArgumentType.word()); - children(new WorldArg()); + children(WorldArg::new); } @Override @@ -266,7 +266,7 @@ public class ProfilerCommand extends RootNode { private final class WorldArg extends ArgumentNode { private WorldArg() { super("world", StringArgumentType.word()); - children(new BlockXArg()); + children(BlockXArg::new); } @Override @@ -282,14 +282,14 @@ public class ProfilerCommand extends RootNode { private final class BlockXArg extends ArgumentNode { private BlockXArg() { super("blockX", IntegerArgumentType.integer()); - children(new BlockZArg()); + children(BlockZArg::new); } } private final class BlockZArg extends ArgumentNode { private BlockZArg() { super("blockZ", IntegerArgumentType.integer()); - children(new CoordinateSecondsArg()); + children(CoordinateSecondsArg::new); } } @@ -337,7 +337,7 @@ public class ProfilerCommand extends RootNode { private final class StopCommand extends LiteralNode { private StopCommand() { super("stop"); - children(new SessionArg()); + children(SessionArg::new); } @Override diff --git a/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/utils/profiling/RegionScheduleProfiler.java b/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/utils/profiling/RegionScheduleProfiler.java index d6fca6a..3c85075 100644 --- a/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/utils/profiling/RegionScheduleProfiler.java +++ b/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/utils/profiling/RegionScheduleProfiler.java @@ -7,7 +7,7 @@ import org.jspecify.annotations.NonNull; /** * note: 1.a single instance should be called single threadedly(except method "toggle") - * 2.tickEnd, tickBegin, taskEnd, taskBegin are called serially not concurrently, if not, exception or unexpected behavior would be + * 2.tickEnd, tickBegin, taskEnd, taskBegin are called serially not concurrently, if not, exception or unexpected behavior would be * surely happened */ public class RegionScheduleProfiler { @@ -91,7 +91,8 @@ public class RegionScheduleProfiler { } /** - * Gets the execution time of last operation + * Gets the execution time of last operation + * * @return -1 -> no execution history yet, otherwise the execution time of last operation */ public long lastExecutionTime() { diff --git a/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/utils/profiling/RegionScheduleProfilerManager.java b/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/utils/profiling/RegionScheduleProfilerManager.java index 23e4199..281f6bc 100644 --- a/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/utils/profiling/RegionScheduleProfilerManager.java +++ b/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/utils/profiling/RegionScheduleProfilerManager.java @@ -17,11 +17,7 @@ import java.nio.file.FileAlreadyExistsException; import java.nio.file.Files; import java.nio.file.LinkOption; import java.nio.file.Path; -import java.util.Collections; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; import java.util.concurrent.ConcurrentHashMap;