diff options
author | Luck <git@lucko.me> | 2019-04-16 21:37:59 +0100 |
---|---|---|
committer | Luck <git@lucko.me> | 2019-04-16 21:37:59 +0100 |
commit | ecd4cec8545460a4fc4ca65b911c2503a00cd8e7 (patch) | |
tree | 62067383a1044abc3a09724e89c6e7c619e87ec0 /spark-bungeecord/src/main | |
parent | 8a61b404848ed8e3c27f06eb73239d37d4273240 (diff) | |
download | spark-ecd4cec8545460a4fc4ca65b911c2503a00cd8e7.tar.gz spark-ecd4cec8545460a4fc4ca65b911c2503a00cd8e7.tar.bz2 spark-ecd4cec8545460a4fc4ca65b911c2503a00cd8e7.zip |
Lots of refactoring, add tps command
Diffstat (limited to 'spark-bungeecord/src/main')
-rw-r--r-- | spark-bungeecord/src/main/java/me/lucko/spark/bungeecord/SparkBungeeCordPlugin.java | 126 |
1 files changed, 62 insertions, 64 deletions
diff --git a/spark-bungeecord/src/main/java/me/lucko/spark/bungeecord/SparkBungeeCordPlugin.java b/spark-bungeecord/src/main/java/me/lucko/spark/bungeecord/SparkBungeeCordPlugin.java index 6d23683..5c39d34 100644 --- a/spark-bungeecord/src/main/java/me/lucko/spark/bungeecord/SparkBungeeCordPlugin.java +++ b/spark-bungeecord/src/main/java/me/lucko/spark/bungeecord/SparkBungeeCordPlugin.java @@ -21,95 +21,93 @@ package me.lucko.spark.bungeecord; import me.lucko.spark.common.SparkPlatform; -import me.lucko.spark.sampler.ThreadDumper; -import me.lucko.spark.sampler.TickCounter; - +import me.lucko.spark.common.SparkPlugin; +import me.lucko.spark.common.sampler.ThreadDumper; +import me.lucko.spark.common.sampler.TickCounter; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.TextComponent; -import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.plugin.Command; import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.api.plugin.TabExecutor; import java.nio.file.Path; import java.util.Collections; +import java.util.HashSet; +import java.util.Set; -public class SparkBungeeCordPlugin extends Plugin { +public class SparkBungeeCordPlugin extends Plugin implements SparkPlugin<CommandSender> { - private final SparkPlatform<CommandSender> sparkPlatform = new SparkPlatform<CommandSender>() { - private BaseComponent[] colorize(String message) { - return TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', message)); - } + private final SparkPlatform<CommandSender> platform = new SparkPlatform<>(this); - private void broadcast(BaseComponent... msg) { - getProxy().getConsole().sendMessage(msg); - for (ProxiedPlayer player : getProxy().getPlayers()) { - if (player.hasPermission("spark")) { - player.sendMessage(msg); - } - } - } + @Override + public void onEnable() { + this.platform.enable(); + getProxy().getPluginManager().registerCommand(this, new SparkCommand(this)); + } - @Override - public String getVersion() { - return getDescription().getVersion(); - } + @Override + public void onDisable() { + this.platform.disable(); + } - @Override - public Path getPluginFolder() { - return getDataFolder().toPath(); - } + @Override + public String getVersion() { + return getDescription().getVersion(); + } - @Override - public String getLabel() { - return "sparkb"; - } + @Override + public Path getPluginFolder() { + return getDataFolder().toPath(); + } - @Override - public void sendMessage(CommandSender sender, String message) { - sender.sendMessage(colorize(message)); - } + @Override + public String getLabel() { + return "sparkb"; + } - @Override - public void sendMessage(String message) { - broadcast(colorize(message)); - } + @Override + public Set<CommandSender> getSenders() { + Set<CommandSender> senders = new HashSet<>(getProxy().getPlayers()); + senders.add(getProxy().getConsole()); + return senders; + } - @Override - public void sendLink(String url) { - TextComponent component = new TextComponent(url); - component.setColor(ChatColor.GRAY); - component.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url)); - broadcast(component); - } + @Override + public void sendMessage(CommandSender sender, String message) { + sender.sendMessage(TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', message))); + } - @Override - public void runAsync(Runnable r) { - getProxy().getScheduler().runAsync(SparkBungeeCordPlugin.this, r); - } + @Override + public void sendLink(CommandSender sender, String url) { + TextComponent component = new TextComponent(url); + component.setColor(ChatColor.GRAY); + component.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url)); + sender.sendMessage(component); + } - @Override - public ThreadDumper getDefaultThreadDumper() { - return ThreadDumper.ALL; - } + @Override + public void runAsync(Runnable r) { + getProxy().getScheduler().runAsync(SparkBungeeCordPlugin.this, r); + } - @Override - public TickCounter newTickCounter() { - throw new UnsupportedOperationException(); - } - }; + @Override + public ThreadDumper getDefaultThreadDumper() { + return ThreadDumper.ALL; + } @Override - public void onEnable() { - getProxy().getPluginManager().registerCommand(this, new SparkCommand()); + public TickCounter createTickCounter() { + return null; } - private final class SparkCommand extends Command implements TabExecutor { - public SparkCommand() { + private static final class SparkCommand extends Command implements TabExecutor { + private final SparkBungeeCordPlugin plugin; + + SparkCommand(SparkBungeeCordPlugin plugin) { super("sparkb", null, "sparkbungee"); + this.plugin = plugin; } @Override @@ -121,7 +119,7 @@ public class SparkBungeeCordPlugin extends Plugin { return; } - SparkBungeeCordPlugin.this.sparkPlatform.executeCommand(sender, args); + this.plugin.platform.executeCommand(sender, args); } @Override @@ -129,7 +127,7 @@ public class SparkBungeeCordPlugin extends Plugin { if (!sender.hasPermission("spark")) { return Collections.emptyList(); } - return SparkBungeeCordPlugin.this.sparkPlatform.tabCompleteCommand(sender, args); + return this.plugin.platform.tabCompleteCommand(sender, args); } } } |