aboutsummaryrefslogtreecommitdiff
path: root/spark-bukkit/src/main/java/me
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2019-05-13 10:22:16 +0100
committerLuck <git@lucko.me>2019-05-13 10:22:16 +0100
commitcf3ce4d9d7c443e0051eb7cff7dc71cf2a0eb851 (patch)
tree1c14254cb1a04f0ef63045f3c996a866b5d2493a /spark-bukkit/src/main/java/me
parent825c9121af03334a29da8add045b6ab5f96d19ff (diff)
downloadspark-cf3ce4d9d7c443e0051eb7cff7dc71cf2a0eb851.tar.gz
spark-cf3ce4d9d7c443e0051eb7cff7dc71cf2a0eb851.tar.bz2
spark-cf3ce4d9d7c443e0051eb7cff7dc71cf2a0eb851.zip
Ensure things are cleaned up nicely when the plugin disables
Diffstat (limited to 'spark-bukkit/src/main/java/me')
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/SparkBukkitPlugin.java10
1 files changed, 8 insertions, 2 deletions
diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/SparkBukkitPlugin.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/SparkBukkitPlugin.java
index ee85c70..6d0d96e 100644
--- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/SparkBukkitPlugin.java
+++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/SparkBukkitPlugin.java
@@ -30,6 +30,7 @@ import me.lucko.spark.common.sampler.TickCounter;
import net.kyori.text.TextComponent;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
import org.bukkit.plugin.java.JavaPlugin;
import java.nio.file.Path;
@@ -41,6 +42,7 @@ import java.util.stream.Collectors;
public class SparkBukkitPlugin extends JavaPlugin implements SparkPlugin {
private final SparkPlatform platform = new SparkPlatform(this);
+ private CommandExecutor tpsCommand = null;
@Override
public void onEnable() {
@@ -48,7 +50,7 @@ public class SparkBukkitPlugin extends JavaPlugin implements SparkPlugin {
// override Spigot's TPS command with our own.
if (getConfig().getBoolean("override-tps-command", true)) {
- CommandMapUtil.registerCommand(this, (sender, command, label, args) -> {
+ this.tpsCommand = (sender, command, label, args) -> {
if (!sender.hasPermission("spark") && !sender.hasPermission("spark.tps") && !sender.hasPermission("bukkit.command.tps")) {
sender.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
return true;
@@ -59,13 +61,17 @@ public class SparkBukkitPlugin extends JavaPlugin implements SparkPlugin {
resp.replyPrefixed(TextComponent.of("TPS from last 5s, 10s, 1m, 5m, 15m:"));
resp.replyPrefixed(TextComponent.builder(" ").append(tpsCalculator.toFormattedComponent()).build());
return true;
- }, "tps");
+ };
+ CommandMapUtil.registerCommand(this, this.tpsCommand, "tps");
}
}
@Override
public void onDisable() {
this.platform.disable();
+ if (this.tpsCommand != null) {
+ CommandMapUtil.unregisterCommand(this.tpsCommand);
+ }
}
@Override