aboutsummaryrefslogtreecommitdiff
path: root/spark-bukkit/src/main/java/me/lucko
diff options
context:
space:
mode:
Diffstat (limited to 'spark-bukkit/src/main/java/me/lucko')
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitTickCounter.java13
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/SparkBukkitPlugin.java129
2 files changed, 69 insertions, 73 deletions
diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitTickCounter.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitTickCounter.java
index 3b95399..44a69cb 100644
--- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitTickCounter.java
+++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitTickCounter.java
@@ -20,8 +20,7 @@
package me.lucko.spark.bukkit;
-import me.lucko.spark.sampler.TickCounter;
-
+import me.lucko.spark.common.sampler.TickCounter;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitTask;
@@ -32,7 +31,7 @@ public class BukkitTickCounter implements TickCounter, Runnable {
private final Plugin plugin;
private BukkitTask task;
- private final Set<Runnable> tasks = new HashSet<>();
+ private final Set<TickTask> tasks = new HashSet<>();
private int tick = 0;
public BukkitTickCounter(Plugin plugin) {
@@ -41,8 +40,8 @@ public class BukkitTickCounter implements TickCounter, Runnable {
@Override
public void run() {
- for (Runnable r : this.tasks) {
- r.run();
+ for (TickTask r : this.tasks) {
+ r.onTick(this);
}
this.tick++;
}
@@ -63,12 +62,12 @@ public class BukkitTickCounter implements TickCounter, Runnable {
}
@Override
- public void addTickTask(Runnable runnable) {
+ public void addTickTask(TickTask runnable) {
this.tasks.add(runnable);
}
@Override
- public void removeTickTask(Runnable runnable) {
+ public void removeTickTask(TickTask runnable) {
this.tasks.remove(runnable);
}
}
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 f1395c4..1d6160a 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
@@ -21,100 +21,97 @@
package me.lucko.spark.bukkit;
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 org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.nio.file.Path;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
-public class SparkBukkitPlugin extends JavaPlugin {
+public class SparkBukkitPlugin extends JavaPlugin implements SparkPlugin<CommandSender> {
- private final SparkPlatform<CommandSender> sparkPlatform = new SparkPlatform<CommandSender>() {
+ private final SparkPlatform<CommandSender> platform = new SparkPlatform<>(this);
- private String colorize(String message) {
- return ChatColor.translateAlternateColorCodes('&', message);
- }
+ @Override
+ public void onEnable() {
+ this.platform.enable();
+ }
- private void broadcast(String msg) {
- getServer().getConsoleSender().sendMessage(msg);
- for (Player player : getServer().getOnlinePlayers()) {
- if (player.hasPermission("spark")) {
- player.sendMessage(msg);
- }
- }
- }
+ @Override
+ public void onDisable() {
+ this.platform.disable();
+ }
- @Override
- public String getVersion() {
- return getDescription().getVersion();
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ if (!sender.hasPermission("spark")) {
+ sender.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
+ return true;
}
- @Override
- public Path getPluginFolder() {
- return getDataFolder().toPath();
- }
+ this.platform.executeCommand(sender, args);
+ return true;
+ }
- @Override
- public String getLabel() {
- return "spark";
+ @Override
+ public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
+ if (!sender.hasPermission("spark")) {
+ return Collections.emptyList();
}
+ return this.platform.tabCompleteCommand(sender, args);
+ }
- @Override
- public void sendMessage(CommandSender sender, String message) {
- sender.sendMessage(colorize(message));
- }
+ @Override
+ public String getVersion() {
+ return getDescription().getVersion();
+ }
- @Override
- public void sendMessage(String message) {
- String msg = colorize(message);
- broadcast(msg);
- }
+ @Override
+ public Path getPluginFolder() {
+ return getDataFolder().toPath();
+ }
- @Override
- public void sendLink(String url) {
- String msg = colorize("&7" + url);
- broadcast(msg);
- }
+ @Override
+ public String getLabel() {
+ return "spark";
+ }
- @Override
- public void runAsync(Runnable r) {
- getServer().getScheduler().runTaskAsynchronously(SparkBukkitPlugin.this, r);
- }
+ @Override
+ public Set<CommandSender> getSenders() {
+ Set<CommandSender> senders = new HashSet<>(getServer().getOnlinePlayers());
+ senders.add(getServer().getConsoleSender());
+ return senders;
+ }
- @Override
- public ThreadDumper getDefaultThreadDumper() {
- return new ThreadDumper.Specific(new long[]{Thread.currentThread().getId()});
- }
+ @Override
+ public void sendMessage(CommandSender sender, String message) {
+ sender.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
+ }
- @Override
- public TickCounter newTickCounter() {
- return new BukkitTickCounter(SparkBukkitPlugin.this);
- }
- };
+ @Override
+ public void sendLink(CommandSender sender, String url) {
+ sendMessage(sender, "&7" + url);
+ }
@Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if (!sender.hasPermission("spark")) {
- sender.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
- return true;
- }
+ public void runAsync(Runnable r) {
+ getServer().getScheduler().runTaskAsynchronously(SparkBukkitPlugin.this, r);
+ }
- this.sparkPlatform.executeCommand(sender, args);
- return true;
+ @Override
+ public ThreadDumper getDefaultThreadDumper() {
+ return new ThreadDumper.Specific(new long[]{Thread.currentThread().getId()});
}
@Override
- public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
- if (!sender.hasPermission("spark")) {
- return Collections.emptyList();
- }
- return this.sparkPlatform.tabCompleteCommand(sender, args);
+ public TickCounter createTickCounter() {
+ return new BukkitTickCounter(this);
}
}