aboutsummaryrefslogtreecommitdiff
path: root/spark-bungeecord/src
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2018-06-06 15:39:16 +0100
committerLuck <git@lucko.me>2018-06-06 15:39:16 +0100
commit7d6808cbcfbb0f61f93e536d36968eeda5bd302c (patch)
tree3271db1ffa6e4d6c1fa5ea4ccc1335b1ac746f46 /spark-bungeecord/src
parent38f0c12483e6eda79ca36dc829ef678a736d2cef (diff)
downloadspark-7d6808cbcfbb0f61f93e536d36968eeda5bd302c.tar.gz
spark-7d6808cbcfbb0f61f93e536d36968eeda5bd302c.tar.bz2
spark-7d6808cbcfbb0f61f93e536d36968eeda5bd302c.zip
Convert to Gradle
Diffstat (limited to 'spark-bungeecord/src')
-rw-r--r--spark-bungeecord/src/main/java/me/lucko/spark/bungeecord/SparkBungeeCordPlugin.java82
-rw-r--r--spark-bungeecord/src/main/resources/bungee.yml5
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