LagAssist is a plugin that provides tools to prevent, analyse or resolve lag.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.3 KiB

package com.entryrise.lagassist.client;
3 years ago
import java.util.ArrayList;
3 years ago
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import com.entryrise.lagassist.gui.ClientGUI;
import com.entryrise.lagassist.gui.ClientGUI.ToggleState;
import com.entryrise.lagassist.packets.Reflection;
import com.entryrise.lagassist.utils.VersionMgr;
import com.entryrise.lagassist.utils.WorldMgr;
3 years ago
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
public class ClientPacket {
public static boolean hidePacket(Player p, ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
if (!ClientMain.enabled) {
return false;
}
if (WorldMgr.isBlacklisted(p.getWorld())) {
return false;
}
try {
String name = msg.getClass().getSimpleName().toLowerCase();
String entitytype = null;
3 years ago
if (name.equals("packetplayoutspawnentity")
&& (ClientGUI.isOn(ToggleState.TNT, p) || ClientGUI.isOn(ToggleState.SAND, p))) {
if (VersionMgr.isV1_8()) {
int x = ((int) Reflection.getFieldValue(msg, "b")) / 32;
int y = ((int) Reflection.getFieldValue(msg, "c")) / 32;
int z = ((int) Reflection.getFieldValue(msg, "d")) / 32;
Location loc = new Location(p.getWorld(), x, y, z);
entitytype = Reflection.getEntity(loc).getType().toString();
} else if (VersionMgr.isV1_17()) {
Object entitytypes = Reflection.getFieldValue(msg, "m");
entitytypes = Reflection.getFieldValue(entitytypes, "bv");
entitytype = entitytypes == null ? "unknown" : entitytypes.toString();
} else if (VersionMgr.isNewMaterials()) {
// TODO: SYNC METHOD FIX MAY CAUSE MAJOR LAG!
3 years ago
UUID u = (UUID) Reflection.getFieldValue(msg, "b");
entitytype = getEntityAsync(p, u).getType().toString().toUpperCase();
3 years ago
} else {
double x = ((double) Reflection.getFieldValue(msg, "c"));
double y = ((double) Reflection.getFieldValue(msg, "d"));
double z = ((double) Reflection.getFieldValue(msg, "e"));
Location loc = new Location(p.getWorld(), x, y, z);
entitytype = Reflection.getEntity(loc).getType().toString();
3 years ago
}
if (entitytype == null) {
3 years ago
return false;
}
3 years ago
if (entitytype.contains("tnt")) {
3 years ago
return ClientGUI.isOn(ToggleState.TNT, p);
} else if (entitytype.contains("falling_block")) {
3 years ago
return ClientGUI.isOn(ToggleState.SAND, p);
}
} else if (name.equals("packetplayoutworldparticles")) {
return ClientGUI.isOn(ToggleState.PARTICLES, p);
} else if (name.equals("packetplayoutblockaction")) {
Object block = Reflection.getFieldValue(msg, "d");
String type = block.getClass().getSimpleName().toLowerCase();
if (type.equals("blockpiston")) {
return ClientGUI.isOn(ToggleState.PISTONS, p);
}
} else if (name.equals("packetplayoutentitystatus")) {
// int ent = (int) Reflection.getFieldValue(msg, "a");
byte status = (byte) Reflection.getFieldValue(msg, "b");
if (status == 3) {
return true;
}
}
return false;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
private static Entity getEntityAsync(Player p, UUID u) {
for (Entity ent : new ArrayList<>(p.getWorld().getEntities())) {
if (ent.getUniqueId() == u) return ent;
}
return null;
}
3 years ago
}