From efcde8d6692c37a2df2b438ced969e9d9f9bc240 Mon Sep 17 00:00:00 2001 From: Stefatorus Date: Mon, 4 Jul 2022 22:37:02 +0300 Subject: [PATCH] Push 1.19 support --- plugin.yml | 2 +- .../lagassist/chunks/ChkLimiter.java | 5 ++ .../lagassist/minebench/Approximate.java | 29 +++++-- .../lagassist/minebench/BenchResponse.java | 13 +++- .../lagassist/minebench/HTTPClient.java | 76 +++++++++++-------- .../lagassist/minebench/SpecsGetter.java | 4 +- .../lagassist/minebench/SpeedTest.java | 3 +- .../entryrise/lagassist/mobs/SmartMob.java | 17 ++--- .../lagassist/packets/Reflection.java | 1 + .../entryrise/lagassist/utils/VersionMgr.java | 6 +- 10 files changed, 99 insertions(+), 57 deletions(-) diff --git a/plugin.yml b/plugin.yml index 5195d10..efe8d5e 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: LagAssist authors: [Stefatorus, EntryRise] -version: 2.27.0 +version: 2.29.0 api-version: 1.13 description: LagAssist is an advanced anti-lag solution that allows server owners find and remove lag using multiple advanced and efficient methods. main: com.entryrise.lagassist.Main diff --git a/src/com/entryrise/lagassist/chunks/ChkLimiter.java b/src/com/entryrise/lagassist/chunks/ChkLimiter.java index ef5b086..33b9ab8 100644 --- a/src/com/entryrise/lagassist/chunks/ChkLimiter.java +++ b/src/com/entryrise/lagassist/chunks/ChkLimiter.java @@ -50,6 +50,11 @@ public class ChkLimiter implements Listener { for (Chunk chk : w.getLoadedChunks()) { Map counts = new HashMap(); for (Entity ent : chk.getEntities()) { + + if (Main.config.getBoolean("limiter.ignore-named-mobs") && ent.getCustomName() != null) { + continue; + } + EntityType type = ent.getType(); int allowed = getMobMaxHard(type); diff --git a/src/com/entryrise/lagassist/minebench/Approximate.java b/src/com/entryrise/lagassist/minebench/Approximate.java index 5289747..300d9fe 100644 --- a/src/com/entryrise/lagassist/minebench/Approximate.java +++ b/src/com/entryrise/lagassist/minebench/Approximate.java @@ -50,8 +50,19 @@ public class Approximate { max = sthread / 18; } else if (vers.contains("1.13")) { max = sthread / 25; + } else if (vers.contains("1.14")){ + max = sthread / 30; + } else if (vers.contains("1.15")) { + max = sthread / 28; + } else if (vers.contains("1.16")) { + max = sthread / 23; + } else if (vers.contains("1.17")) { + max = sthread / 22; + } else if (vers.contains("1.18")) { + max = sthread / 20; } else { - max = sthread / 37; + // Assume that future mc versions are going to be badly optimized. + max = sthread / 35; } return max; @@ -113,15 +124,21 @@ public class Approximate { cs.sendMessage(""); cs.sendMessage(" §2✸ §fCPU Name: §e" + cpuname); cs.sendMessage(""); - cs.sendMessage(" §2✸ §fCPU Score (SINGLE): §e" + br.getStringifiedSth()); - cs.sendMessage(" §2✸ §fCPU Score (MULTI): §e" + br.getStringifiedMth()); + if (br.getOk()) { + cs.sendMessage(" §2✸ §fCPU Score (SINGLE): §e" + br.getStringifiedSth()); + cs.sendMessage(" §2✸ §fCPU Score (MULTI): §e" + br.getStringifiedMth()); + } else { + cs.sendMessage(" §cThere was an error getting the full benchmark results."); + } cs.sendMessage(""); cs.sendMessage(" §2✸ §fDownload Speed: §e" + MIBDL + " Mib/s (" + MBDL + "MB/s)"); cs.sendMessage(" §2✸ §fUpload Speed: §e" + MIBUP + " Mib/s (" + MBUP + " MB/s)"); cs.sendMessage(""); - cs.sendMessage(" §2✸ §fMax Players (SINGLE): §e" + singleapprox); - cs.sendMessage(" §2✸ §fMax Players (GLOBAL): §e" + multiapprox); - cs.sendMessage(""); + if (br.getOk()) { + cs.sendMessage(" §2✸ §fMax Players (SINGLE): §e" + singleapprox); + cs.sendMessage(" §2✸ §fMax Players (GLOBAL): §e" + multiapprox); + cs.sendMessage(""); + } cs.sendMessage("§2§l⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛"); } receivers.clear(); diff --git a/src/com/entryrise/lagassist/minebench/BenchResponse.java b/src/com/entryrise/lagassist/minebench/BenchResponse.java index 6b64ca8..d9b0bdf 100644 --- a/src/com/entryrise/lagassist/minebench/BenchResponse.java +++ b/src/com/entryrise/lagassist/minebench/BenchResponse.java @@ -4,10 +4,17 @@ public class BenchResponse { private int singlethread; private int multithread; + + private boolean ok; - public BenchResponse(int sth, int mth) { - singlethread = sth; - multithread = mth; + public BenchResponse(int singlethread, int multithread, boolean ok) { + this.singlethread = singlethread; + this.multithread = multithread; + this.ok = ok; + } + + public boolean getOk() { + return ok; } public int getMultithread() { diff --git a/src/com/entryrise/lagassist/minebench/HTTPClient.java b/src/com/entryrise/lagassist/minebench/HTTPClient.java index 93dc4d1..a580aec 100644 --- a/src/com/entryrise/lagassist/minebench/HTTPClient.java +++ b/src/com/entryrise/lagassist/minebench/HTTPClient.java @@ -4,12 +4,12 @@ import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.bukkit.Bukkit; import com.entryrise.lagassist.utils.Others; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; public class HTTPClient { @@ -50,42 +50,52 @@ public class HTTPClient { } } - private static int getMultiThread(String s) { - - String regex = "(.*.)<\\/span>"; - - final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); - final Matcher matcher = pattern.matcher(s); - - if (!matcher.find()) { - return -1; - } - - return Integer.valueOf(matcher.group(1)); - } - - private static int getSingleThread(String s) { - - String regex = "Single Thread Rating: <\\/strong>(.*.)
"; - - final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); - final Matcher matcher = pattern.matcher(s); - - if (!matcher.find()) { - return -1; - } - - float fl = Float.valueOf(matcher.group(1)); - - return (int) fl; - } +// private static int getMultiThread(String s) { +// +// String regex = "(.*.)<\\/span>"; +// +// final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); +// final Matcher matcher = pattern.matcher(s); +// +// if (!matcher.find()) { +// return -1; +// } +// +// return Integer.valueOf(matcher.group(1)); +// } +// +// private static int getSingleThread(String s) { +// +// String regex = "Single Thread Rating: <\\/strong>(.*.)
"; +// +// final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); +// final Matcher matcher = pattern.matcher(s); +// +// if (!matcher.find()) { +// return -1; +// } +// +// float fl = Float.valueOf(matcher.group(1)); +// +// return (int) fl; +// } public BenchResponse getBenchmark() { if (is == null) { - return new BenchResponse(-1, -1); + return new BenchResponse(-1, -1, false); } + String s = Others.readInputStreamAsString(is); - return new BenchResponse(getSingleThread(s), getMultiThread(s)); + + JsonObject response = new JsonParser().parse(s).getAsJsonObject(); + + String status = response.get("status").getAsString(); + + if (!status.equalsIgnoreCase("OK")) { + return new BenchResponse(-1, -1, false); + } + + return new BenchResponse(response.get("single").getAsInt(), response.get("multi").getAsInt(), true); } } diff --git a/src/com/entryrise/lagassist/minebench/SpecsGetter.java b/src/com/entryrise/lagassist/minebench/SpecsGetter.java index 511e9b9..7d882ac 100644 --- a/src/com/entryrise/lagassist/minebench/SpecsGetter.java +++ b/src/com/entryrise/lagassist/minebench/SpecsGetter.java @@ -120,12 +120,12 @@ public class SpecsGetter { String cpu = getCPU(getOS()); if (cpu.equals("unknown")) { - return new BenchResponse(-1, -1); + return new BenchResponse(-1, -1, false); } HTTPClient conn; try { - conn = new HTTPClient("https://www.cpubenchmark.net/cpu.php?cpu=" + URLEncoder.encode(cpu, "UTF-8")); + conn = new HTTPClient("https://lagassist.rz.al/benchmark/" + URLEncoder.encode(cpu, "UTF-8")); return conn.getBenchmark(); } catch (UnsupportedEncodingException e) { diff --git a/src/com/entryrise/lagassist/minebench/SpeedTest.java b/src/com/entryrise/lagassist/minebench/SpeedTest.java index 081bf8f..56962c5 100644 --- a/src/com/entryrise/lagassist/minebench/SpeedTest.java +++ b/src/com/entryrise/lagassist/minebench/SpeedTest.java @@ -112,7 +112,8 @@ public class SpeedTest { String namemin = ""; for (Player p : Bukkit.getOnlinePlayers()) { - int pping = Reflection.getPing(p); +// int pping = Reflection.getPing(p); + int pping = p.spigot().getPing(); med += pping; nr++; if (max == -1) { diff --git a/src/com/entryrise/lagassist/mobs/SmartMob.java b/src/com/entryrise/lagassist/mobs/SmartMob.java index 9bb4d01..80ad6b5 100644 --- a/src/com/entryrise/lagassist/mobs/SmartMob.java +++ b/src/com/entryrise/lagassist/mobs/SmartMob.java @@ -10,6 +10,7 @@ import org.bukkit.World; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; import org.bukkit.entity.Slime; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -61,9 +62,7 @@ public class SmartMob implements Listener { for (Entity e : w.getEntities()) { if (Whitelist) { if (isRemovable(e)) { - if (e.getCustomName() == null && e.getPassenger() == null) { - e.remove(); - } + e.remove(); } } else if (mobs.contains(e.getType().toString())) { if (isRemovable(e)) { @@ -78,15 +77,13 @@ public class SmartMob implements Listener { private static boolean isRemovable(Entity ent) { String name = ent.getCustomName(); - if (name == null || (name != null && StackManager.isStacked(ent))) { - return true; - } + if (VersionMgr.hasPassengers(ent)) return false; - if (!VersionMgr.hasPassengers(ent)) { - return true; - } + if (name != null && !StackManager.isStacked(ent)) return false; + + if (ent instanceof Player) return false; - return false; + return true; } diff --git a/src/com/entryrise/lagassist/packets/Reflection.java b/src/com/entryrise/lagassist/packets/Reflection.java index 473046e..b970037 100644 --- a/src/com/entryrise/lagassist/packets/Reflection.java +++ b/src/com/entryrise/lagassist/packets/Reflection.java @@ -142,6 +142,7 @@ public class Reflection { private static Object minecraftserver = null; public static double getTPS(int number) { + try { if (minecraftserver == null) { minecraftserver = Methods.getServer.mthd.invoke(null); diff --git a/src/com/entryrise/lagassist/utils/VersionMgr.java b/src/com/entryrise/lagassist/utils/VersionMgr.java index 774565d..5d72363 100644 --- a/src/com/entryrise/lagassist/utils/VersionMgr.java +++ b/src/com/entryrise/lagassist/utils/VersionMgr.java @@ -66,8 +66,12 @@ public class VersionMgr { return Bukkit.getVersion().contains("1.18"); } + public static boolean isV1_19() { + return Bukkit.getVersion().contains("1.19"); + } + public static boolean isV_17Plus() { - return isV1_17() || isV1_18(); + return isV1_17() || isV1_18() || isV1_19(); } public static boolean isNewMaterials() {