diff options
Diffstat (limited to 'spark-bungeecord/src/main')
-rw-r--r-- | spark-bungeecord/src/main/java/me/lucko/spark/bungeecord/SparkBungeeCordPlugin.java | 82 | ||||
-rw-r--r-- | spark-bungeecord/src/main/resources/bungee.yml | 5 |
2 files changed, 87 insertions, 0 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 new file mode 100644 index 0000000..59bab67 --- /dev/null +++ b/spark-bungeecord/src/main/java/me/lucko/spark/bungeecord/SparkBungeeCordPlugin.java @@ -0,0 +1,82 @@ +package me.lucko.spark.bungeecord; + +import me.lucko.spark.common.CommandHandler; +import me.lucko.spark.profiler.ThreadDumper; +import me.lucko.spark.profiler.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; + +public class SparkBungeeCordPlugin extends Plugin { + + private final CommandHandler<CommandSender> commandHandler = new CommandHandler<CommandSender>() { + private BaseComponent[] colorize(String message) { + return TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', message)); + } + + private void broadcast(BaseComponent... msg) { + getProxy().getConsole().sendMessage(msg); + for (ProxiedPlayer player : getProxy().getPlayers()) { + if (player.hasPermission("spark.profiler")) { + player.sendMessage(msg); + } + } + } + + @Override + protected void sendMessage(CommandSender sender, String message) { + sender.sendMessage(colorize(message)); + } + + @Override + protected void sendMessage(String message) { + broadcast(colorize(message)); + } + + @Override + protected 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 + protected void runAsync(Runnable r) { + getProxy().getScheduler().runAsync(SparkBungeeCordPlugin.this, r); + } + + @Override + protected ThreadDumper getDefaultThreadDumper() { + return new ThreadDumper.All(); + } + + @Override + protected TickCounter newTickCounter() { + throw new UnsupportedOperationException(); + } + }; + + @Override + public void onEnable() { + getProxy().getPluginManager().registerCommand(this, new Command("sparkbungee", null, "gprofiler") { + @Override + public void execute(CommandSender sender, String[] args) { + if (!sender.hasPermission("spark.profiler")) { + TextComponent msg = new TextComponent("You do not have permission to use this command."); + msg.setColor(ChatColor.RED); + sender.sendMessage(msg); + return; + } + + SparkBungeeCordPlugin.this.commandHandler.handleCommand(sender, args); + } + }); + } +} diff --git a/spark-bungeecord/src/main/resources/bungee.yml b/spark-bungeecord/src/main/resources/bungee.yml new file mode 100644 index 0000000..fa65fbc --- /dev/null +++ b/spark-bungeecord/src/main/resources/bungee.yml @@ -0,0 +1,5 @@ +name: spark +version: ${pluginVersion} +description: Spark is a CPU profiling plugin based on sk89q's WarmRoast profiler +author: Luck, sk89q +main: me.lucko.spark.bungeecord.SparkBungeeCordPlugin |