Use lombok, add new config options for disabling pvp, pve, action bar when disguised, permission to hide name above head

This commit is contained in:
libraryaddict
2020-02-02 11:59:18 +13:00
parent 5f98e57316
commit ed098752f6
14 changed files with 590 additions and 720 deletions

View File

@@ -1,5 +1,11 @@
package me.libraryaddict.disguise.utilities.reflection;
import org.bukkit.entity.Entity;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.net.URL;
import java.net.URLDecoder;
import java.security.CodeSource;
@@ -8,26 +14,30 @@ 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 class ClassGetter {
private class TestPrem {
String user = "%%__USER__%%";
}
public static ArrayList<Class<?>> getClassesForPackage(String pkgname)
{
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
private @interface PremInfo {
String user();
}
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)
{
if (src != null) {
URL resource = src.getLocation();
resource.getPath();
processJarfile(resource, pkgname, classes);
@@ -36,26 +46,21 @@ public class ClassGetter
return classes;
}
private static Class<?> loadClass(String className)
{
try
{
private static Class<?> loadClass(String className) {
try {
return Class.forName(className);
}
catch (ClassNotFoundException e)
{
catch (ClassNotFoundException e) {
throw new RuntimeException("Unexpected ClassNotFoundException loading class '" + className + "'");
}
catch (NoClassDefFoundError e)
{
catch (NoClassDefFoundError e) {
return null;
}
}
private static void processJarfile(URL resource, String pkgname, ArrayList<Class<?>> classes)
{
try
{
@PremInfo(user = "%%__USER__%%")
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:", "");
@@ -64,22 +69,18 @@ public class ClassGetter
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements())
{
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()))
{
if (entryName.endsWith(".class") && entryName.startsWith(relPath) &&
entryName.length() > (relPath.length() + "/".length())) {
className = entryName.replace('/', '.').replace('\\', '.').replace(".class", "");
}
if (className != null)
{
if (className != null) {
Class<?> c = loadClass(className);
if (c != null)
{
if (c != null) {
classes.add(c);
}
}
@@ -87,8 +88,7 @@ public class ClassGetter
jarFile.close();
}
catch (Exception ex)
{
catch (Exception ex) {
ex.printStackTrace();
}
}