Move classes into packages, clean up packet handling into classes, yaw/pitch should be consistent

This commit is contained in:
libraryaddict
2019-01-03 15:13:03 +13:00
parent 43701c1fe8
commit cada0f4f91
68 changed files with 4009 additions and 3625 deletions

View File

@@ -0,0 +1,95 @@
package me.libraryaddict.disguise.utilities.reflection;
import java.net.URL;
import java.net.URLDecoder;
import java.security.CodeSource;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import org.bukkit.entity.Entity;
/**
* User: Austin Date: 4/22/13 Time: 11:47 PM (c) lazertester
*/
// Code for this taken and slightly modified from
// https://github.com/ddopson/java-class-enumerator
public class ClassGetter
{
public static ArrayList<Class<?>> getClassesForPackage(String pkgname)
{
ArrayList<Class<?>> classes = new ArrayList<>();
// String relPath = pkgname.replace('.', '/');
// Get a File object for the package
CodeSource src = Entity.class.getProtectionDomain().getCodeSource();
if (src != null)
{
URL resource = src.getLocation();
resource.getPath();
processJarfile(resource, pkgname, classes);
}
return classes;
}
private static Class<?> loadClass(String className)
{
try
{
return Class.forName(className);
}
catch (ClassNotFoundException e)
{
throw new RuntimeException("Unexpected ClassNotFoundException loading class '" + className + "'");
}
catch (NoClassDefFoundError e)
{
return null;
}
}
private static void processJarfile(URL resource, String pkgname, ArrayList<Class<?>> classes)
{
try
{
String relPath = pkgname.replace('.', '/');
String resPath = URLDecoder.decode(resource.getPath(), "UTF-8");
String jarPath = resPath.replaceFirst("[.]jar[!].*", ".jar").replaceFirst("file:", "");
JarFile jarFile = new JarFile(jarPath);
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements())
{
JarEntry entry = entries.nextElement();
String entryName = entry.getName();
String className = null;
if (entryName.endsWith(".class") && entryName.startsWith(relPath)
&& entryName.length() > (relPath.length() + "/".length()))
{
className = entryName.replace('/', '.').replace('\\', '.').replace(".class", "");
}
if (className != null)
{
Class<?> c = loadClass(className);
if (c != null)
{
classes.add(c);
}
}
}
jarFile.close();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}

View File

@@ -0,0 +1,62 @@
package me.libraryaddict.disguise.utilities.reflection;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import java.util.HashMap;
public class DisguiseValues {
private static HashMap<DisguiseType, DisguiseValues> values = new HashMap<>();
public static DisguiseValues getDisguiseValues(DisguiseType type) {
return values.get(type);
}
public static Class getNmsEntityClass(DisguiseType type) {
return getDisguiseValues(type).getNmsEntityClass();
}
private FakeBoundingBox adultBox;
private FakeBoundingBox babyBox;
private float[] entitySize;
private double maxHealth;
private Class nmsEntityClass;
public DisguiseValues(DisguiseType type, Class classType, int entitySize, double maxHealth) {
values.put(type, this);
nmsEntityClass = classType;
this.maxHealth = maxHealth;
}
public FakeBoundingBox getAdultBox() {
return adultBox;
}
public FakeBoundingBox getBabyBox() {
return babyBox;
}
public float[] getEntitySize() {
return entitySize;
}
public double getMaxHealth() {
return maxHealth;
}
public Class getNmsEntityClass() {
return nmsEntityClass;
}
public void setAdultBox(FakeBoundingBox newBox) {
adultBox = newBox;
}
public void setBabyBox(FakeBoundingBox newBox) {
babyBox = newBox;
}
public void setEntitySize(float[] size) {
this.entitySize = size;
}
}

View File

@@ -0,0 +1,27 @@
package me.libraryaddict.disguise.utilities.reflection;
public class FakeBoundingBox {
private double xMod;
private double yMod;
private double zMod;
public FakeBoundingBox(double xMod, double yMod, double zMod) {
this.xMod = xMod;
this.yMod = yMod;
this.zMod = zMod;
}
public double getX() {
return xMod / 2;
}
public double getY() {
return yMod;
}
public double getZ() {
return zMod / 2;
}
}

View File

@@ -0,0 +1,9 @@
package me.libraryaddict.disguise.utilities.reflection;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
public interface LibsProfileLookup {
void onLookup(WrappedGameProfile gameProfile);
}

View File

@@ -0,0 +1,24 @@
package me.libraryaddict.disguise.utilities.reflection;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.ProfileLookupCallback;
public class LibsProfileLookupCaller implements ProfileLookupCallback {
private WrappedGameProfile gameProfile;
public WrappedGameProfile getGameProfile() {
return gameProfile;
}
@Override
public void onProfileLookupFailed(GameProfile gameProfile, Exception arg1) {
}
@Override
public void onProfileLookupSucceeded(GameProfile profile) {
gameProfile = WrappedGameProfile.fromHandle(profile);
}
}