Browse Source

Initial 1.17 commit.

master
Stefatorus 3 years ago
parent
commit
e0b97af352
  1. 2
      plugin.yml
  2. 30
      src/cx/sfy/LagAssist/Monitor.java
  3. 2
      src/cx/sfy/LagAssist/client/ClientPacket.java
  4. 7
      src/cx/sfy/LagAssist/packets/PacketInjector.java
  5. 90
      src/cx/sfy/LagAssist/packets/Reflection.java
  6. 10
      src/cx/sfy/LagAssist/utils/VersionMgr.java

2
plugin.yml

@ -1,6 +1,6 @@
name: LagAssist
author: Stefatorus
version: 2.23.4
version: 2.24.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: cx.sfy.LagAssist.Main

30
src/cx/sfy/LagAssist/Monitor.java

@ -1,7 +1,5 @@
package cx.sfy.LagAssist;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.text.DecimalFormat;
import java.util.Arrays;
@ -13,15 +11,12 @@ import org.bukkit.scheduler.BukkitTask;
import cx.sfy.LagAssist.hoppers.ChunkHoppers;
import cx.sfy.LagAssist.mobs.SmartMob;
import cx.sfy.LagAssist.mobs.SpawnerMgr;
import cx.sfy.LagAssist.packets.Reflection;
public class Monitor {
private final static String name = Bukkit.getServer().getClass().getPackage().getName();
private final static String version = name.substring(name.lastIndexOf('.') + 1);
private static DecimalFormat format = new DecimalFormat("##.##");
private static Object serverInstance;
private static Field tpsField;
public static Runtime Rtm = Runtime.getRuntime();
@ -47,15 +42,6 @@ public class Monitor {
GetExactTPS();
createGraph();
}
try {
serverInstance = getNMSClass("MinecraftServer").getMethod("getServer").invoke(null);
tpsField = serverInstance.getClass().getField("recentTps");
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
| SecurityException | NoSuchFieldException e) {
e.printStackTrace();
}
}
private static void LagMeasures(double d) {
@ -195,12 +181,7 @@ public class Monitor {
}
public static String getTPS(int time) {
try {
double[] tps = ((double[]) tpsField.get(serverInstance));
return format.format(tps[time]).replace(',', '.');
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
return format.format(Reflection.getTPS(time)).replace(",", ".");
}
public static void createGraph() {
@ -245,11 +226,4 @@ public class Monitor {
}, 7L, 7L);
}
private static Class<?> getNMSClass(String className) {
try {
return Class.forName("net.minecraft.server." + version + "." + className);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
}

2
src/cx/sfy/LagAssist/client/ClientPacket.java

@ -37,7 +37,7 @@ public class ClientPacket {
int z = ((int) Reflection.getFieldValue(msg, "d")) / 32;
Location loc = new Location(p.getWorld(), x, y, z);
ent = Reflection.getEntity(loc);
} else if (VersionMgr.isV1_13() || VersionMgr.isV1_14()) {
} else if (VersionMgr.isNewMaterials()) {
UUID u = (UUID) Reflection.getFieldValue(msg, "b");
ent = Bukkit.getEntity(u);
} else {

7
src/cx/sfy/LagAssist/packets/PacketInjector.java

@ -9,6 +9,7 @@ import org.bukkit.entity.Player;
import cx.sfy.LagAssist.client.ClientMain;
import cx.sfy.LagAssist.safety.SafetyManager;
import cx.sfy.LagAssist.utils.VersionMgr;
import io.netty.channel.Channel;
public class PacketInjector {
@ -21,10 +22,10 @@ public class PacketInjector {
return;
}
try {
PacketInjector.playerConnection = Reflection.getClass("{nms}.EntityPlayer").getField("playerConnection");
PacketInjector.networkManager = Reflection.getClass("{nms}.PlayerConnection").getField("networkManager");
PacketInjector.playerConnection = Reflection.getClass(VersionMgr.isV_17Plus() ? "{nms}.level.EntityPlayer" : "{nms}.EntityPlayer").getField(VersionMgr.isV_17Plus() ? "b" : "playerConnection");
PacketInjector.networkManager = Reflection.getClass(VersionMgr.isV_17Plus() ? "{nms}.network.PlayerConnection" : "{nms}.PlayerConnection").getField(VersionMgr.isV_17Plus() ? "a" : "networkManager");
PacketInjector.channel = Reflection.getClass("{nms}.NetworkManager").getField("channel");
PacketInjector.channel = Reflection.getClass(VersionMgr.isV1_17() ? "{nm}.network.NetworkManager" : "{nms}.NetworkManager").getField(VersionMgr.isV1_17() ? "k" : "channel");
PacketInjector.refreshSessions();
} catch (Exception e) {

90
src/cx/sfy/LagAssist/packets/Reflection.java

@ -40,7 +40,7 @@ public class Reflection {
public static enum Classes {
CraftWorld(), CraftBlock(), CraftPlayer(), Material(), MapMeta(), WorldServer(), ChunkProviderServer(),
PacketPlayOutTitle(), IChatBaseComponent(), World();
PacketPlayOutTitle(), IChatBaseComponent(), World(), MinecraftServer();
private Class<?> type;
@ -52,7 +52,7 @@ public class Reflection {
public static enum Methods {
setMapId(), getMapId(), getPlayerHandle(), getBlockType(), getChunkProviderServer(), chunkExists(),
getIChatBaseComponent(), setViewDistance();
getIChatBaseComponent(), setViewDistance(), getServer();
private Method mthd;
@ -70,10 +70,11 @@ public class Reflection {
Classes.CraftPlayer.type = getClass("{cb}.entity.CraftPlayer");
Classes.Material.type = getClass("{b}.Material");
Classes.MapMeta.type = getClass("{b}.inventory.meta.MapMeta");
Classes.WorldServer.type = getClass("{nms}.WorldServer");
Classes.ChunkProviderServer.type = getClass("{nms}.ChunkProviderServer");
Classes.IChatBaseComponent.type = getClass("{nms}.IChatBaseComponent");
Classes.PacketPlayOutTitle.type = getClass("{nms}.PacketPlayOutTitle");
Classes.WorldServer.type = getClass(VersionMgr.isV_17Plus() ? "{nms}.level.WorldServer" : "{nms}.WorldServer");
Classes.MinecraftServer.type = getClass("{nms}.MinecraftServer");
Classes.ChunkProviderServer.type = getClass(VersionMgr.isV_17Plus() ? "{nms}.level.ChunkProviderServer" : "{nms}.ChunkProviderServer");
Classes.IChatBaseComponent.type = getClass(VersionMgr.isV_17Plus() ? "{nm}.network.chat.IChatBaseComponent" : "{nms}.IChatBaseComponent");
// Classes.PacketPlayOutTitle.type = getClass(VersionMgr.isV_17Plus()? "{nm}.network.protocol.game.PacketPlayOutTitle" : "{nms}.PacketPlayOutTitle");
// PUTTING METHODS IN ENUM.
Methods.setMapId.mthd = getMethod(Classes.MapMeta.getType(), "setMapId", int.class);
@ -85,6 +86,7 @@ public class Reflection {
Methods.chunkExists.mthd = getMethod(Classes.ChunkProviderServer.getType(), VersionMgr.ChunkExistsName(),
int.class, int.class);
Methods.setViewDistance.mthd = getMethod(Classes.World.getType(), "setViewDistance", int.class);
Methods.getServer.mthd = getMethod(Classes.MinecraftServer.getType(), "getServer");
}
@SuppressWarnings("deprecation")
@ -96,33 +98,33 @@ public class Reflection {
}
}
public void sendTitle(Player p, int fadein, int stay, int fadeout, String title, String subtitle) {
try {
Object enumTitle = Classes.PacketPlayOutTitle.getType().getDeclaredClasses()[0].getField("TITLE").get(null);
Object enumSubtitle = Classes.PacketPlayOutTitle.getType().getDeclaredClasses()[0].getField("SUBTITLE")
.get(null);
Object titlebase = runMethod(null, Methods.getIChatBaseComponent.getMethod(),
"{\"text\": \"" + title + "\"}");
Object subtitlebase = runMethod(null, Methods.getIChatBaseComponent.getMethod(),
"{\"text\": \"" + subtitle + "\"}");
Class<?> packetcls = Classes.PacketPlayOutTitle.getType();
Constructor<?> constr = packetcls.getConstructor(
Classes.PacketPlayOutTitle.getType().getDeclaredClasses()[0], Classes.IChatBaseComponent.getType(),
int.class, int.class, int.class);
Object packetTitle = constr.newInstance(enumTitle, titlebase, fadein, stay, fadeout);
Object packetSubtitle = constr.newInstance(enumSubtitle, subtitlebase, fadein, stay, fadeout);
sendPlayerPacket(p, packetTitle);
sendPlayerPacket(p, packetSubtitle);
}
catch (Exception e) {
e.printStackTrace();
}
}
// public void sendTitle(Player p, int fadein, int stay, int fadeout, String title, String subtitle) {
// try {
// Object enumTitle = Classes.PacketPlayOutTitle.getType().getDeclaredClasses()[0].getField("TITLE").get(null);
// Object enumSubtitle = Classes.PacketPlayOutTitle.getType().getDeclaredClasses()[0].getField("SUBTITLE")
// .get(null);
//
// Object titlebase = runMethod(null, Methods.getIChatBaseComponent.getMethod(),
// "{\"text\": \"" + title + "\"}");
// Object subtitlebase = runMethod(null, Methods.getIChatBaseComponent.getMethod(),
// "{\"text\": \"" + subtitle + "\"}");
//
// Class<?> packetcls = Classes.PacketPlayOutTitle.getType();
// Constructor<?> constr = packetcls.getConstructor(
// Classes.PacketPlayOutTitle.getType().getDeclaredClasses()[0], Classes.IChatBaseComponent.getType(),
// int.class, int.class, int.class);
//
// Object packetTitle = constr.newInstance(enumTitle, titlebase, fadein, stay, fadeout);
// Object packetSubtitle = constr.newInstance(enumSubtitle, subtitlebase, fadein, stay, fadeout);
//
// sendPlayerPacket(p, packetTitle);
// sendPlayerPacket(p, packetSubtitle);
// }
//
// catch (Exception e) {
// e.printStackTrace();
// }
// }
public static MapView getMapView(int i) {
Class<?> buk = Bukkit.class;
@ -136,6 +138,23 @@ public class Reflection {
}
}
private static Object minecraftserver = null;
public static double getTPS(int number) {
try {
if (minecraftserver == null) {
minecraftserver = Methods.getServer.mthd.invoke(null);
}
Field f = Reflection.getField(Classes.MinecraftServer.type, "recentTps");
f.setAccessible(true);
return ((double[])f.get(minecraftserver))[number];
} catch(Exception e) {
e.printStackTrace();
return -1;
}
}
public static int getId(MapView view) {
if (view == null) {
@ -167,8 +186,9 @@ public class Reflection {
public static Class<?> getClass(String classname) {
try {
String path = classname.replace("{nms}", "net.minecraft.server." + version)
.replace("{nm}", "net.minecraft." + version).replace("{cb}", "org.bukkit.craftbukkit." + version)
String path = classname.replace("{nms}", "net.minecraft.server" + (VersionMgr.isV_17Plus() ? "" : "." + version))
.replace("{nm}", "net.minecraft" + (VersionMgr.isV_17Plus() ? "" : "." + version)).replace("{cb}", "org.bukkit.craftbukkit." + version)
.replace("{b}", "org.bukkit");
return Class.forName(path);
} catch (Exception e) {

10
src/cx/sfy/LagAssist/utils/VersionMgr.java

@ -43,7 +43,7 @@ public class VersionMgr {
}
public static boolean isV1_11() {
return !isV1_8() && !isV1_9() && !isV1_10();
return Bukkit.getVersion().contains("1.11");
}
public static boolean isV1_12() {
@ -58,6 +58,14 @@ public class VersionMgr {
return Bukkit.getVersion().contains("1.14");
}
public static boolean isV1_17() {
return Bukkit.getVersion().contains("1.17");
}
public static boolean isV_17Plus() {
return isV1_17();
}
public static boolean isNewMaterials() {
if (isV1_8()) {
return false;

Loading…
Cancel
Save