From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Tue, 23 Jul 2019 10:07:16 -0500
Subject: [PATCH] Lagging threshold


diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 4cf3af5e933294026c4f2aa00a65b31609f93cf0..bb9059fe10e65975553e41d893deb88cc0c15534 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -305,6 +305,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
     public static final int TICK_TIME = 1000000000 / MinecraftServer.TPS;
     private static final int SAMPLE_INTERVAL = 20; // Paper
     public final double[] recentTps = new double[ 3 ];
+    public boolean lagging = false; // Purpur
     public final SlackActivityAccountant slackActivityAccountant = new SlackActivityAccountant();
     // Spigot end
 
@@ -1243,6 +1244,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
                         this.recentTps[1] = tps5.getAverage();
                         this.recentTps[2] = tps15.getAverage();
                         // Paper end
+                        lagging = recentTps[0] < net.pl3x.purpur.PurpurConfig.laggingThreshold; // Purpur
                         tickSection = curTime;
                     }
                     // Tuinity - replace logic
diff --git a/src/main/java/net/pl3x/purpur/PurpurConfig.java b/src/main/java/net/pl3x/purpur/PurpurConfig.java
index 9577355817a71b2e398ccf411cbcfd3a77bfafaf..dd9fca23e1f96ad261589d9b66d4306a228ec76a 100644
--- a/src/main/java/net/pl3x/purpur/PurpurConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurConfig.java
@@ -188,6 +188,11 @@ public class PurpurConfig {
         if (!co.aikar.timings.TimingsManager.hiddenConfigs.contains("server-ip")) co.aikar.timings.TimingsManager.hiddenConfigs.add("server-ip");
     }
 
+    public static double laggingThreshold = 19.0D;
+    private static void tickLoopSettings() {
+        laggingThreshold = getDouble("settings.lagging-threshold", laggingThreshold);
+    }
+
     public static boolean barrelSixRows = false;
     public static boolean enderChestSixRows = false;
     public static boolean enderChestPermissionRows = false;
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 0b35921fc924fa701e37107aee0f78e25fdf69be..cf13e496d5d69d5a277c07e97f566a157fa55f67 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -2643,5 +2643,10 @@ public final class CraftServer implements Server {
     public String getServerName() {
         return this.getProperties().serverName;
     }
+
+    @Override
+    public boolean isLagging() {
+        return getServer().lagging;
+    }
     // Purpur end
 }
