aboutsummaryrefslogtreecommitdiff
path: root/spark-bukkit/src/main/java/me
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2020-01-11 19:30:15 +0000
committerLuck <git@lucko.me>2020-01-11 19:30:15 +0000
commit2fe79f4140011f93df1567afcc9b75fababa187e (patch)
tree2a747c3da719d061302577b9cda422fe609ab636 /spark-bukkit/src/main/java/me
parent9e066d1052643b2be270b4039a102260abb41ebb (diff)
downloadspark-2fe79f4140011f93df1567afcc9b75fababa187e.tar.gz
spark-2fe79f4140011f93df1567afcc9b75fababa187e.tar.bz2
spark-2fe79f4140011f93df1567afcc9b75fababa187e.zip
Add AbstractTickCounter
Diffstat (limited to 'spark-bukkit/src/main/java/me')
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitTickCounter.java28
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/PaperTickCounter.java28
2 files changed, 6 insertions, 50 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 44a69cb..2a71257 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,30 +20,22 @@
package me.lucko.spark.bukkit;
+import me.lucko.spark.common.sampler.AbstractTickCounter;
import me.lucko.spark.common.sampler.TickCounter;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitTask;
-import java.util.HashSet;
-import java.util.Set;
-
-public class BukkitTickCounter implements TickCounter, Runnable {
+public class BukkitTickCounter extends AbstractTickCounter implements TickCounter, Runnable {
private final Plugin plugin;
private BukkitTask task;
- private final Set<TickTask> tasks = new HashSet<>();
- private int tick = 0;
-
public BukkitTickCounter(Plugin plugin) {
this.plugin = plugin;
}
@Override
public void run() {
- for (TickTask r : this.tasks) {
- r.onTick(this);
- }
- this.tick++;
+ onTick();
}
@Override
@@ -56,18 +48,4 @@ public class BukkitTickCounter implements TickCounter, Runnable {
this.task.cancel();
}
- @Override
- public int getCurrentTick() {
- return this.tick;
- }
-
- @Override
- public void addTickTask(TickTask runnable) {
- this.tasks.add(runnable);
- }
-
- @Override
- public void removeTickTask(TickTask runnable) {
- this.tasks.remove(runnable);
- }
}
diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/PaperTickCounter.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/PaperTickCounter.java
index e545687..7189429 100644
--- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/PaperTickCounter.java
+++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/PaperTickCounter.java
@@ -21,31 +21,23 @@
package me.lucko.spark.bukkit;
import com.destroystokyo.paper.event.server.ServerTickStartEvent;
+import me.lucko.spark.common.sampler.AbstractTickCounter;
import me.lucko.spark.common.sampler.TickCounter;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
-import java.util.HashSet;
-import java.util.Set;
-
-public class PaperTickCounter implements TickCounter, Listener {
+public class PaperTickCounter extends AbstractTickCounter implements TickCounter, Listener {
private final Plugin plugin;
- private final Set<TickTask> tasks = new HashSet<>();
- private int tick = 0;
-
public PaperTickCounter(Plugin plugin) {
this.plugin = plugin;
}
@EventHandler
public void onServerTickEvent(ServerTickStartEvent e) {
- for (TickTask r : this.tasks) {
- r.onTick(this);
- }
- this.tick++;
+ onTick();
}
@Override
@@ -58,18 +50,4 @@ public class PaperTickCounter implements TickCounter, Listener {
HandlerList.unregisterAll(this);
}
- @Override
- public int getCurrentTick() {
- return this.tick;
- }
-
- @Override
- public void addTickTask(TickTask runnable) {
- this.tasks.add(runnable);
- }
-
- @Override
- public void removeTickTask(TickTask runnable) {
- this.tasks.remove(runnable);
- }
}