Skip to content

Commit a63881b

Browse files
committed
Only register tickmonitor command if supported
1 parent afc58ef commit a63881b

2 files changed

Lines changed: 18 additions & 17 deletions

File tree

spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ public class SparkPlatform {
7474
private final BytebinClient bytebinClient;
7575
private final BytesocksClient bytesocksClient;
7676
private final TrustedKeyStore trustedKeyStore;
77-
private final CommandManager commandManager;
7877
private final ActivityLog activityLog;
7978
private final SamplerContainer samplerContainer;
8079
private final BackgroundSamplerManager backgroundSamplerManager;
@@ -83,9 +82,10 @@ public class SparkPlatform {
8382
private final TickStatistics tickStatistics;
8483
private final PingStatistics pingStatistics;
8584
private final PlatformStatisticsProvider statisticsProvider;
85+
private final CommandManager commandManager;
86+
private final AtomicBoolean enabled = new AtomicBoolean(false);
8687
private Map<String, GarbageCollectorStatistics> startupGcStatistics = ImmutableMap.of();
8788
private long serverNormalOperationStartTime;
88-
private final AtomicBoolean enabled = new AtomicBoolean(false);
8989

9090
public SparkPlatform(SparkPlugin plugin) {
9191
this.plugin = plugin;
@@ -112,8 +112,6 @@ public SparkPlatform(SparkPlugin plugin) {
112112
this.activityLog = new ActivityLog(plugin.getPluginDirectory().resolve("activity.json"));
113113
this.activityLog.load();
114114

115-
this.commandManager = new CommandManager(this, this.configuration);
116-
117115
this.samplerContainer = new SamplerContainer();
118116
this.backgroundSamplerManager = new BackgroundSamplerManager(this, this.configuration);
119117

@@ -129,6 +127,8 @@ public SparkPlatform(SparkPlugin plugin) {
129127
this.pingStatistics = pingProvider != null ? new PingStatistics(pingProvider) : null;
130128

131129
this.statisticsProvider = new PlatformStatisticsProvider(this);
130+
131+
this.commandManager = new CommandManager(this, this.configuration);
132132
}
133133

134134
public void enable() {
@@ -164,6 +164,8 @@ public void enable() {
164164
}
165165

166166
public void disable() {
167+
this.commandManager.close();
168+
167169
if (this.tickHook != null) {
168170
this.tickHook.close();
169171
}
@@ -174,8 +176,6 @@ public void disable() {
174176
this.pingStatistics.close();
175177
}
176178

177-
this.commandManager.close();
178-
179179
this.samplerContainer.close();
180180

181181
SparkApi.unregister();
@@ -279,15 +279,15 @@ public Path resolveSaveFile(String prefix, String extension) {
279279
}
280280

281281
public boolean hasPermissionForAnyCommand(CommandSender sender) {
282-
return commandManager.hasPermissionForAnyCommand(sender);
282+
return this.commandManager.hasPermissionForAnyCommand(sender);
283283
}
284284

285285
public CompletableFuture<Void> executeCommand(CommandSender sender, String[] args) {
286-
return commandManager.executeCommand(sender, args);
286+
return this.commandManager.executeCommand(sender, args);
287287
}
288288

289289
public List<String> tabCompleteCommand(CommandSender sender, String[] args) {
290-
return commandManager.tabCompleteCommand(sender, args);
290+
return this.commandManager.tabCompleteCommand(sender, args);
291291
}
292292

293293
}

spark-common/src/main/java/me/lucko/spark/common/command/CommandManager.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,15 @@ public CommandManager(SparkPlatform platform, Configuration configuration) {
7272

7373
this.disableResponseBroadcast = configuration.getBoolean("disableResponseBroadcast", false);
7474

75-
this.modules = ImmutableList.of(
76-
new SamplerModule(),
77-
new HealthModule(),
78-
new TickMonitoringModule(),
79-
new GcMonitoringModule(),
80-
new HeapAnalysisModule(),
81-
new ActivityLogModule()
82-
);
75+
this.modules = new ArrayList<>();
76+
this.modules.add(new SamplerModule());
77+
this.modules.add(new HealthModule());
78+
if (platform.getTickHook() != null) {
79+
this.modules.add(new TickMonitoringModule());
80+
}
81+
this.modules.add(new GcMonitoringModule());
82+
this.modules.add(new HeapAnalysisModule());
83+
this.modules.add(new ActivityLogModule());
8384

8485
ImmutableList.Builder<Command> commandsBuilder = ImmutableList.builder();
8586
for (CommandModule module : this.modules) {

0 commit comments

Comments
 (0)