mirror of
https://github.com/funkemunky/KauriV3.git
synced 2026-05-31 05:51:55 +00:00
Improvements
This commit is contained in:
@@ -23,6 +23,8 @@ local.properties
|
||||
# PyDev specific (Python IDE for Eclipse)
|
||||
*.pydevproject
|
||||
|
||||
*.iml
|
||||
|
||||
# CDT-specific (C/C++ Development Tooling)
|
||||
.cproject
|
||||
|
||||
@@ -272,3 +274,5 @@ $RECYCLE.BIN/
|
||||
*.lnk
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/java,maven,intellij+all,eclipse,linux,macos,windows
|
||||
*.iml
|
||||
API/API.iml
|
||||
|
||||
+9
-13
@@ -1,16 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/annotations" isTestSource="false" generated="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.18.24" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.github.spigot:1.8.8:1.8.8" level="project" />
|
||||
<module version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>SPIGOT</platformType>
|
||||
</autoDetectTypes>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
</module>
|
||||
@@ -4,6 +4,7 @@ import dev.brighten.ac.Anticheat;
|
||||
import dev.brighten.ac.utils.annotation.Init;
|
||||
import dev.brighten.ac.utils.reflections.Reflections;
|
||||
import dev.brighten.ac.utils.reflections.types.WrappedClass;
|
||||
import jdk.tools.jlink.resources.plugins;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.tree.AnnotationNode;
|
||||
@@ -30,19 +31,31 @@ public class ClassScanner {
|
||||
//TODO Get check classes too
|
||||
public static Set<WrappedClass> getClasses(Class<? extends Annotation> annotationClass,
|
||||
String packageName) {
|
||||
return getNames().stream().filter(pkg -> pkg.startsWith(packageName) && findClass(map.get(n), Init.class) != null)
|
||||
Map<String, byte[]> map = (Map<String, byte[]>) Anticheat.INSTANCE.getStuffs();
|
||||
return getNames().stream().filter(pkg -> pkg.startsWith(packageName) && findClass(map.get(pkg), annotationClass) != null)
|
||||
.map(Reflections::getClass).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public static Set<String> getNames() {
|
||||
Map<String, byte[]> map = (Map<String, byte[]>) Anticheat.INSTANCE.getStuffs();
|
||||
|
||||
return map.keySet().stream().filter(n -> {
|
||||
return !n.endsWith(".yml") && !n.endsWith(".xml") && !n.endsWith(".") && !n.endsWith(".properties")
|
||||
&& !n.contains("dev.brighten.ac.packet")
|
||||
&& Character.isLetterOrDigit(n.charAt(n.length() - 1))
|
||||
&& findClass(map.get(n), Init.class) != null;
|
||||
}).collect(Collectors.toSet());
|
||||
Set<String> nameSet = new HashSet<>();
|
||||
|
||||
for (String loadedClass : Anticheat.INSTANCE.getLoadedClasses()) {
|
||||
InputStream stream = Anticheat.INSTANCE.getClassLoader2().getResourceAsStream(loadedClass);
|
||||
|
||||
if(findClass(stream, Init.class) != null) {
|
||||
nameSet.add(loadedClass);
|
||||
}
|
||||
}
|
||||
|
||||
map.keySet().stream().filter(n -> !n.endsWith(".yml")
|
||||
&& !n.endsWith(".xml") && !n.endsWith(".") && !n.endsWith(".properties")
|
||||
&& !n.contains("dev.brighten.ac.packet")
|
||||
&& Character.isLetterOrDigit(n.charAt(n.length() - 1))
|
||||
&& findClass(map.get(n), Init.class) != null).forEach(nameSet::add);
|
||||
|
||||
return nameSet;
|
||||
}
|
||||
|
||||
public static String findClass(byte[] array, Class<? extends Annotation> annotationClass) {
|
||||
@@ -69,6 +82,30 @@ public class ClassScanner {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String findClass(InputStream stream, Class<? extends Annotation> annotationClass) {
|
||||
try {
|
||||
ClassReader reader = new ClassReader(stream);
|
||||
ClassNode classNode = new ClassNode();
|
||||
reader.accept(classNode, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
|
||||
String className = classNode.name.replace('/', '.');
|
||||
|
||||
final String anName = annotationClass.getName().replace(".", "/");
|
||||
if (classNode.visibleAnnotations != null) {
|
||||
for (Object node : classNode.visibleAnnotations) {
|
||||
AnnotationNode annotation = (AnnotationNode) node;
|
||||
if (annotation.desc
|
||||
.equals("L" + anName + ";")) {
|
||||
return className;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//Bukkit.getLogger().info("Failed to scan");
|
||||
//e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static <E> HashSet<E> newHashSet(E... elements) {
|
||||
HashSet<E> set = new HashSet<>();
|
||||
Collections.addAll(set, elements);
|
||||
|
||||
Reference in New Issue
Block a user