From e3cf0d6d9fac5f30099fc72b6e7ea6b59c1e5b64 Mon Sep 17 00:00:00 2001 From: ZeroHD Date: Mon, 5 Jul 2021 14:52:41 +0000 Subject: [PATCH] Switched to Spark for TPS alerts (#8) Switched to Spark for TPS alerts + Currently just looks at tps, but we could hook in mspt + Fixes #6 Co-authored-by: Joey Hines Reviewed-on: https://git.canopymc.net/Canopy/QoL/pulls/8 Reviewed-by: Etzelia Co-Authored-By: ZeroHD Co-Committed-By: ZeroHD --- pom.xml | 21 ++++++++++--------- src/main/java/xyz/etztech/qol/QoL.java | 20 +++++++++++------- .../xyz/etztech/qol/other/TPSRunnable.java | 12 ++++++----- src/main/resources/plugin.yml | 2 +- 4 files changed, 31 insertions(+), 24 deletions(-) diff --git a/pom.xml b/pom.xml index 2776d87..b177e0d 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ xyz.etztech QoL - 1.10 + 1.11 jar @@ -39,11 +39,6 @@ plugin-api 1.0.7 - - net.ess3 - EssentialsX - 2.18.1 - us.dynmap dynmap-api @@ -60,6 +55,12 @@ 1.19.1 provided + + me.lucko + spark-api + 0.1-SNAPSHOT + provided + @@ -78,10 +79,6 @@ dynmap-repo https://repo.mikeprimm.com/ - - - ess-repo - https://ci.ender.zone/plugin/repository/everything/ mvn-repo @@ -95,6 +92,10 @@ jitpack.io https://jitpack.io + + sonatype-snapshots + https://oss.sonatype.org/content/repositories/snapshots + diff --git a/src/main/java/xyz/etztech/qol/QoL.java b/src/main/java/xyz/etztech/qol/QoL.java index 469932a..66044e4 100644 --- a/src/main/java/xyz/etztech/qol/QoL.java +++ b/src/main/java/xyz/etztech/qol/QoL.java @@ -1,10 +1,10 @@ package xyz.etztech.qol; -import net.ess3.api.IEssentials; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; +import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; import org.dynmap.DynmapAPI; import org.dynmap.markers.Marker; @@ -16,6 +16,7 @@ import xyz.etztech.qol.listeners.*; import xyz.etztech.qol.other.LinkCommand; import xyz.etztech.qol.other.Reminder; import xyz.etztech.qol.other.TPSRunnable; +import me.lucko.spark.api.Spark; import java.util.ArrayList; import java.util.List; @@ -28,7 +29,7 @@ public class QoL extends JavaPlugin { private String qolMarkerIcon = null; private static QoL instance; - private IEssentials essentials = null; + private Spark spark = null; private DynmapAPI dynmap = null; private MarkerAPI markerAPI = null; private MarkerSet playerMarkerSet = null; @@ -53,10 +54,11 @@ public class QoL extends JavaPlugin { reloadConfig(); saveResource("qol.png", true); - //Essentials hook - if (Bukkit.getPluginManager().isPluginEnabled("Essentials")) { - log("Hooked into Essentials for TPS alert."); - essentials = (IEssentials) Bukkit.getPluginManager().getPlugin("Essentials"); + //Spark hook + RegisteredServiceProvider sparkProvider = Bukkit.getServicesManager().getRegistration(Spark.class); + if (sparkProvider != null) { + log("Hooked into Spark for TPS alert."); + spark = sparkProvider.getProvider(); } //Dynmap hook @@ -276,8 +278,6 @@ public class QoL extends JavaPlugin { return links; } - public IEssentials getEssentials() { return essentials; } - public DynmapAPI getDynmap() { return dynmap; } public void runTask(final String command) { @@ -330,5 +330,9 @@ public class QoL extends JavaPlugin { return marker; } } + + public Spark getSpark() { + return spark; + } } diff --git a/src/main/java/xyz/etztech/qol/other/TPSRunnable.java b/src/main/java/xyz/etztech/qol/other/TPSRunnable.java index 57cf0a4..632d804 100644 --- a/src/main/java/xyz/etztech/qol/other/TPSRunnable.java +++ b/src/main/java/xyz/etztech/qol/other/TPSRunnable.java @@ -1,9 +1,11 @@ package xyz.etztech.qol.other; -import net.ess3.api.IEssentials; +import me.lucko.spark.api.statistic.StatisticWindow; +import me.lucko.spark.api.statistic.types.DoubleStatistic; import org.apache.commons.lang.StringUtils; import xyz.etztech.core.web.Http; import xyz.etztech.qol.QoL; +import me.lucko.spark.api.Spark; import java.util.HashMap; import java.util.Map; @@ -18,13 +20,13 @@ public class TPSRunnable implements Runnable { @Override public void run() { - IEssentials essentials = plugin.getEssentials(); - if (essentials != null) { - double tps = essentials.getTimer().getAverageTPS(); + Spark spark = plugin.getSpark(); + if (spark != null) { + DoubleStatistic tps = spark.tps(); int threshold = plugin.getConfig().getInt("tps.threshold", 0); String webhook = plugin.getConfig().getString("tps.webhook", ""); String message = "@here TPS has fallen below " + threshold + "!"; - if (tps < threshold) { + if (tps.poll(StatisticWindow.TicksPerSecond.SECONDS_10) < threshold) { plugin.log(message); if (StringUtils.isNotEmpty(webhook)) { Map data = new HashMap<>(); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 098c952..5762949 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,7 +4,7 @@ description: ${description} author: ${author} website: ${url} main: ${mainClass} -softdepend: [Essentials, dynmap, DiscordSRV] +softdepend: [spark, dynmap, DiscordSRV] commands: qol: description: Base command