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 <joey@ahines.net>
Reviewed-on: https://git.canopymc.net/Canopy/QoL/pulls/8
Reviewed-by: Etzelia <etzelia@hotmail.com>
Co-Authored-By: ZeroHD <joey@ahines.net>
Co-Committed-By: ZeroHD <joey@ahines.net>
pull/10/head
Joey Hines 2021-07-05 14:52:41 +00:00
parent 3c3fdc1725
commit e3cf0d6d9f
4 changed files with 31 additions and 24 deletions

21
pom.xml
View File

@ -3,7 +3,7 @@
<groupId>xyz.etztech</groupId>
<artifactId>QoL</artifactId>
<!-- Version is used in plugin.yml -->
<version>1.10</version>
<version>1.11</version>
<packaging>jar</packaging>
<!-- Plugin Information -->
@ -39,11 +39,6 @@
<artifactId>plugin-api</artifactId>
<version>1.0.7</version>
</dependency>
<dependency>
<groupId>net.ess3</groupId>
<artifactId>EssentialsX</artifactId>
<version>2.18.1</version>
</dependency>
<dependency>
<groupId>us.dynmap</groupId>
<artifactId>dynmap-api</artifactId>
@ -60,6 +55,12 @@
<version>1.19.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.lucko</groupId>
<artifactId>spark-api</artifactId>
<version>0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<repositories>
@ -78,10 +79,6 @@
<repository>
<id>dynmap-repo</id>
<url>https://repo.mikeprimm.com/</url>
</repository>
<repository>
<id>ess-repo</id>
<url>https://ci.ender.zone/plugin/repository/everything/</url>
</repository>
<repository>
<id>mvn-repo</id>
@ -95,6 +92,10 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>sonatype-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
<build>

View File

@ -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<Spark> 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;
}
}

View File

@ -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<StatisticWindow.TicksPerSecond> 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<String, String> data = new HashMap<>();

View File

@ -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