Browse Source

Push 1.19 support

master
Stefatorus 2 years ago
parent
commit
efcde8d669
  1. 2
      plugin.yml
  2. 5
      src/com/entryrise/lagassist/chunks/ChkLimiter.java
  3. 29
      src/com/entryrise/lagassist/minebench/Approximate.java
  4. 13
      src/com/entryrise/lagassist/minebench/BenchResponse.java
  5. 76
      src/com/entryrise/lagassist/minebench/HTTPClient.java
  6. 4
      src/com/entryrise/lagassist/minebench/SpecsGetter.java
  7. 3
      src/com/entryrise/lagassist/minebench/SpeedTest.java
  8. 17
      src/com/entryrise/lagassist/mobs/SmartMob.java
  9. 1
      src/com/entryrise/lagassist/packets/Reflection.java
  10. 6
      src/com/entryrise/lagassist/utils/VersionMgr.java

2
plugin.yml

@ -1,6 +1,6 @@
name: LagAssist name: LagAssist
authors: [Stefatorus, EntryRise] authors: [Stefatorus, EntryRise]
version: 2.27.0
version: 2.29.0
api-version: 1.13 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. 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 main: com.entryrise.lagassist.Main

5
src/com/entryrise/lagassist/chunks/ChkLimiter.java

@ -50,6 +50,11 @@ public class ChkLimiter implements Listener {
for (Chunk chk : w.getLoadedChunks()) { for (Chunk chk : w.getLoadedChunks()) {
Map<EntityType, Integer> counts = new HashMap<EntityType, Integer>(); Map<EntityType, Integer> counts = new HashMap<EntityType, Integer>();
for (Entity ent : chk.getEntities()) { for (Entity ent : chk.getEntities()) {
if (Main.config.getBoolean("limiter.ignore-named-mobs") && ent.getCustomName() != null) {
continue;
}
EntityType type = ent.getType(); EntityType type = ent.getType();
int allowed = getMobMaxHard(type); int allowed = getMobMaxHard(type);

29
src/com/entryrise/lagassist/minebench/Approximate.java

@ -50,8 +50,19 @@ public class Approximate {
max = sthread / 18; max = sthread / 18;
} else if (vers.contains("1.13")) { } else if (vers.contains("1.13")) {
max = sthread / 25; 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 { } else {
max = sthread / 37;
// Assume that future mc versions are going to be badly optimized.
max = sthread / 35;
} }
return max; return max;
@ -113,15 +124,21 @@ public class Approximate {
cs.sendMessage(""); cs.sendMessage("");
cs.sendMessage(" §2✸ §fCPU Name: §e" + cpuname); cs.sendMessage(" §2✸ §fCPU Name: §e" + cpuname);
cs.sendMessage(""); 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("");
cs.sendMessage(" §2✸ §fDownload Speed: §e" + MIBDL + " Mib/s (" + MBDL + "MB/s)"); 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(" §2✸ §fUpload Speed: §e" + MIBUP + " Mib/s (" + MBUP + " MB/s)");
cs.sendMessage(""); 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⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛"); cs.sendMessage("§2§l⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛");
} }
receivers.clear(); receivers.clear();

13
src/com/entryrise/lagassist/minebench/BenchResponse.java

@ -4,10 +4,17 @@ public class BenchResponse {
private int singlethread; private int singlethread;
private int multithread; 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() { public int getMultithread() {

76
src/com/entryrise/lagassist/minebench/HTTPClient.java

@ -4,12 +4,12 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import com.entryrise.lagassist.utils.Others; import com.entryrise.lagassist.utils.Others;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
public class HTTPClient { public class HTTPClient {
@ -50,42 +50,52 @@ public class HTTPClient {
} }
} }
private static int getMultiThread(String s) {
String regex = "<span style=\"font-family: Arial, Helvetica, sans-serif;font-size: 44px; font-weight: bold; color: #F48A18;\">(.*.)<\\/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>(.*.)<br>";
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 style=\"font-family: Arial, Helvetica, sans-serif;font-size: 44px; font-weight: bold; color: #F48A18;\">(.*.)<\\/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>(.*.)<br>";
//
// 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() { public BenchResponse getBenchmark() {
if (is == null) { if (is == null) {
return new BenchResponse(-1, -1);
return new BenchResponse(-1, -1, false);
} }
String s = Others.readInputStreamAsString(is); 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);
} }
} }

4
src/com/entryrise/lagassist/minebench/SpecsGetter.java

@ -120,12 +120,12 @@ public class SpecsGetter {
String cpu = getCPU(getOS()); String cpu = getCPU(getOS());
if (cpu.equals("unknown")) { if (cpu.equals("unknown")) {
return new BenchResponse(-1, -1);
return new BenchResponse(-1, -1, false);
} }
HTTPClient conn; HTTPClient conn;
try { 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(); return conn.getBenchmark();
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {

3
src/com/entryrise/lagassist/minebench/SpeedTest.java

@ -112,7 +112,8 @@ public class SpeedTest {
String namemin = ""; String namemin = "";
for (Player p : Bukkit.getOnlinePlayers()) { for (Player p : Bukkit.getOnlinePlayers()) {
int pping = Reflection.getPing(p);
// int pping = Reflection.getPing(p);
int pping = p.spigot().getPing();
med += pping; med += pping;
nr++; nr++;
if (max == -1) { if (max == -1) {

17
src/com/entryrise/lagassist/mobs/SmartMob.java

@ -10,6 +10,7 @@ import org.bukkit.World;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Slime; import org.bukkit.entity.Slime;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@ -61,9 +62,7 @@ public class SmartMob implements Listener {
for (Entity e : w.getEntities()) { for (Entity e : w.getEntities()) {
if (Whitelist) { if (Whitelist) {
if (isRemovable(e)) { if (isRemovable(e)) {
if (e.getCustomName() == null && e.getPassenger() == null) {
e.remove();
}
e.remove();
} }
} else if (mobs.contains(e.getType().toString())) { } else if (mobs.contains(e.getType().toString())) {
if (isRemovable(e)) { if (isRemovable(e)) {
@ -78,15 +77,13 @@ public class SmartMob implements Listener {
private static boolean isRemovable(Entity ent) { private static boolean isRemovable(Entity ent) {
String name = ent.getCustomName(); 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;
} }

1
src/com/entryrise/lagassist/packets/Reflection.java

@ -142,6 +142,7 @@ public class Reflection {
private static Object minecraftserver = null; private static Object minecraftserver = null;
public static double getTPS(int number) { public static double getTPS(int number) {
try { try {
if (minecraftserver == null) { if (minecraftserver == null) {
minecraftserver = Methods.getServer.mthd.invoke(null); minecraftserver = Methods.getServer.mthd.invoke(null);

6
src/com/entryrise/lagassist/utils/VersionMgr.java

@ -66,8 +66,12 @@ public class VersionMgr {
return Bukkit.getVersion().contains("1.18"); return Bukkit.getVersion().contains("1.18");
} }
public static boolean isV1_19() {
return Bukkit.getVersion().contains("1.19");
}
public static boolean isV_17Plus() { public static boolean isV_17Plus() {
return isV1_17() || isV1_18();
return isV1_17() || isV1_18() || isV1_19();
} }
public static boolean isNewMaterials() { public static boolean isNewMaterials() {

Loading…
Cancel
Save