1
0
mirror of https://github.com/kami-blue/client synced 2025-02-22 00:06:49 +00:00

reflection bug fixed

This commit is contained in:
Ridan Vandenbergh 2018-08-10 02:02:39 +02:00
parent 4cf8365c7d
commit ff3248f1e3
6 changed files with 37 additions and 47 deletions

View File

@ -76,6 +76,9 @@ dependencies {
compile "com.github.ZeroMemes:Alpine:1.5"
compile group: 'net.jodah', name: 'typetools', version: '0.5.0'
compile group: 'org.yaml', name: 'snakeyaml', version: '1.19'
compile(group: 'org.reflections', name: 'reflections', version: '0.9.11') {
exclude group: 'com.google.guava', module: 'guava'
}
}
processResources {
@ -144,6 +147,8 @@ shadowJar {
include(dependency('com.github.ZeroMemes:Alpine'))
include(dependency('net.jodah:typetools'))
include(dependency('org.yaml:snakeyaml'))
include(dependency('org.reflections:reflections'))
include(dependency('org.javassist:javassist'))
}
exclude 'dummyThing'
exclude 'LICENSE.txt'

View File

@ -4,9 +4,11 @@ import me.zeroeightsix.kami.KamiMod;
import me.zeroeightsix.kami.command.commands.BindCommand;
import me.zeroeightsix.kami.util.ClassFinder;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
public class CommandManager {
@ -15,7 +17,7 @@ public class CommandManager {
public CommandManager() {
commands = new ArrayList<>();
List<Class> classList = ClassFinder.generateClassList(BindCommand.class.getPackage().getName());
Set<Class> classList = ClassFinder.findClasses(BindCommand.class.getPackage().getName(), Command.class);
for (Class s : classList) {
if (Command.class.isAssignableFrom(s)){
try {

View File

@ -2,6 +2,7 @@ package me.zeroeightsix.kami.module;
import me.zeroeightsix.kami.KamiMod;
import me.zeroeightsix.kami.event.events.RenderEvent;
import me.zeroeightsix.kami.module.modules.movement.Sprint;
import me.zeroeightsix.kami.setting.Setting;
import me.zeroeightsix.kami.setting.SettingsClass;
import net.minecraft.client.Minecraft;
@ -15,24 +16,28 @@ import java.lang.annotation.RetentionPolicy;
*/
public class Module extends SettingsClass {
private final String name = ((Info)getClass().getAnnotation(Info.class)).name();
private final String description = ((Info)getClass().getAnnotation(Info.class)).description();
private final Category category = ((Info)getClass().getAnnotation(Info.class)).category();
private final String name = getAnnotation().name();
private final String description = getAnnotation().description();
private final Category category = getAnnotation().category();
@Setting(name = "Bind", hidden = true)
private int bind = ((Info)getClass().getAnnotation(Info.class)).bind();
private int bind = getAnnotation().bind();
@Setting(name = "Enabled", hidden = true)
private boolean enabled;
public boolean alwaysListening = false;
protected static final Minecraft mc = Minecraft.getMinecraft();
public Module() {
alwaysListening = (getClass().getAnnotation(Info.class)).alwaysListening();
alwaysListening = getAnnotation().alwaysListening();
enabled = false;
// FMLCommonHandler.instance().bus().register(this);
initSettings();
}
private Info getAnnotation() {
return getClass().isAnnotationPresent(Info.class) ? getClass().getAnnotation(Info.class) : Sprint.class.getAnnotation(Info.class); // dummy annotation
}
public void onUpdate() {}
public void onRender() {}
public void onWorldRender(RenderEvent event) {}

View File

@ -13,10 +13,8 @@ import net.minecraft.util.math.Vec3d;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import org.lwjgl.opengl.GL11;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.io.IOException;
import java.util.*;
/**
* Created by 086 on 23/08/2017.
@ -31,22 +29,18 @@ public class ModuleManager {
static HashMap<String, Module> lookup = new HashMap<>();
public static void initialize() {
List<Class> classList = ClassFinder.generateClassList(ClickGUI.class.getPackage().getName());
classList.stream().forEach(aClass -> {
if (Module.class.isAssignableFrom(aClass)) {
try {
Module module = (Module) aClass.getConstructor().newInstance();
modules.add(module);
lookup.put(module.getName().toLowerCase(), module);
} catch (Exception e) {
e.printStackTrace();
System.err.println("Couldn't initiate module " + aClass.getSimpleName() + "! Err: " + e.getClass().getSimpleName() + ", message: " + e.getMessage());
}
Set<Class> classList = ClassFinder.findClasses(ClickGUI.class.getPackage().getName(), Module.class);
classList.forEach(aClass -> {
try {
Module module = (Module) aClass.getConstructor().newInstance();
modules.add(module);
lookup.put(module.getName().toLowerCase(), module);
} catch (Exception e) {
e.printStackTrace();
System.err.println("Couldn't initiate module " + aClass.getSimpleName() + "! Err: " + e.getClass().getSimpleName() + ", message: " + e.getMessage());
}
});
KamiMod.log.info("Modules initialized");
getModules().sort(Comparator.comparing(Module::getName));
}

View File

@ -3,6 +3,7 @@ package me.zeroeightsix.kami.module.modules.render;
import me.zeroeightsix.kami.module.Module;
import me.zeroeightsix.kami.setting.Setting;
import me.zeroeightsix.kami.util.ColourHolder;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderItem;
@ -14,7 +15,8 @@ import net.minecraft.item.ItemStack;
@Module.Info(name = "ArmorHUD", category = Module.Category.RENDER)
public class ArmorHUD extends Module {
static RenderItem itemRender = mc.getRenderItem();
static RenderItem itemRender = Minecraft.getMinecraft()
.getRenderItem();
@Setting(name = "Damage") private boolean damage = false;

View File

@ -1,34 +1,16 @@
package me.zeroeightsix.kami.util;
import com.google.common.reflect.ClassPath;
import org.reflections.Reflections;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* Created by 086 on 23/08/2017.
*/
public class ClassFinder {
public static List<Class> generateClassList(String pack) {
ArrayList<Class> classes = new ArrayList<>();
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
try {
for (final ClassPath.ClassInfo info : ClassPath.from(loader).getTopLevelClasses()) {
if (info.getName().startsWith(pack + ".")) {
final Class<?> clazz = info.load();
if (clazz == null) continue;
classes.add(clazz);
}
}
} catch (IOException e) {
e.printStackTrace();
}
return classes;
public static Set<Class> findClasses(String pack, Class subType) {
Reflections reflections = new Reflections(pack);
return reflections.getSubTypesOf(subType);
}
}