mirror of
https://github.com/kami-blue/client
synced 2025-01-25 08:12:46 +00:00
saving, loading, almost everything converted
This commit is contained in:
parent
a663ee842e
commit
f08f62fa80
@ -18,8 +18,7 @@ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* Created by 086 on 7/11/2017.
|
||||
@ -35,6 +34,8 @@ public class KamiMod {
|
||||
public static final String KAMI_KATAKANA = "\u30AB\u30DF";
|
||||
public static final String KAMI_KANJI = "\u795E";
|
||||
|
||||
private static final String KAMI_CONFIG_NAME_DEFAULT = "KAMIConfig.json";
|
||||
|
||||
public static final Logger log = LogManager.getLogger("KAMI");
|
||||
|
||||
public static final EventBus EVENT_BUS = new EventManager();
|
||||
@ -70,32 +71,75 @@ public class KamiMod {
|
||||
File file = new File("KAMISettings.json");
|
||||
Friends.initFriends();
|
||||
if (file.exists()) {
|
||||
try {
|
||||
Configuration.loadConfiguration(file);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
KamiMod.log.info("Settings loaded");
|
||||
|
||||
// After settings loaded, we want to let the enabled modules know they've been enabled (since the setting is done through reflection)
|
||||
ModuleManager.getModules().stream().filter(Module::isEnabled).forEach(Module::enable);
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||
try {
|
||||
File outputFile = new File("kami.settings");
|
||||
if (!outputFile.exists())
|
||||
outputFile.createNewFile();
|
||||
Configuration.saveConfiguration(outputFile);
|
||||
ModuleManager.getModules().forEach(Module::destroy);
|
||||
}catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}));
|
||||
|
||||
KamiMod.log.info("KAMI Mod initialized!\n");
|
||||
}
|
||||
|
||||
private static String getConfigName() {
|
||||
File configNameFile = new File("KAMILastConfig.txt");
|
||||
String kamiConfigName = KAMI_CONFIG_NAME_DEFAULT;
|
||||
try(BufferedReader reader = new BufferedReader(new FileReader(configNameFile))) {
|
||||
kamiConfigName = reader.readLine();
|
||||
if (!isFilenameValid(kamiConfigName)) kamiConfigName = KAMI_CONFIG_NAME_DEFAULT;
|
||||
} catch (FileNotFoundException e) {
|
||||
try(BufferedWriter writer = new BufferedWriter(new FileWriter(configNameFile))) {
|
||||
writer.write(KAMI_CONFIG_NAME_DEFAULT);
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return kamiConfigName;
|
||||
}
|
||||
|
||||
public static void loadConfiguration() {
|
||||
try {
|
||||
loadConfigurationUnsafe();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadConfigurationUnsafe() throws IOException {
|
||||
String kamiConfigName = getConfigName();
|
||||
File kamiConfig = new File(kamiConfigName);
|
||||
if (!kamiConfig.exists()) return;
|
||||
Configuration.loadConfiguration(kamiConfig);
|
||||
}
|
||||
|
||||
public static void saveConfiguration() {
|
||||
try {
|
||||
saveConfigurationUnsafe();
|
||||
}catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveConfigurationUnsafe() throws IOException {
|
||||
File outputFile = new File(getConfigName());
|
||||
if (!outputFile.exists())
|
||||
outputFile.createNewFile();
|
||||
Configuration.saveConfiguration(outputFile);
|
||||
ModuleManager.getModules().forEach(Module::destroy);
|
||||
}
|
||||
|
||||
public static boolean isFilenameValid(String file) {
|
||||
File f = new File(file);
|
||||
try {
|
||||
f.getCanonicalPath();
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static KamiMod getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
@ -32,12 +32,12 @@ public class FriendCommand extends Command {
|
||||
@Override
|
||||
public void call(String[] args) {
|
||||
if (args[0] == null) {
|
||||
if (Friends.INSTANCE.friends.isEmpty()) {
|
||||
if (Friends.INSTANCE.friends.getValue().isEmpty()) {
|
||||
Command.sendChatMessage("You currently don't have any friends added. &bfriend add <name>&r to add one.");
|
||||
return;
|
||||
}
|
||||
String f = "";
|
||||
for (Friends.Friend friend : Friends.INSTANCE.friends)
|
||||
for (Friends.Friend friend : Friends.INSTANCE.friends.getValue())
|
||||
f += friend.getUsername() + ", ";
|
||||
f = f.substring(0,f.length()-2);
|
||||
Command.sendChatMessage("Your friends: " + f);
|
||||
@ -62,7 +62,7 @@ public class FriendCommand extends Command {
|
||||
Command.sendChatMessage("Failed to find UUID of " + args[1]);
|
||||
return;
|
||||
}
|
||||
Friends.INSTANCE.friends.add(f);
|
||||
Friends.INSTANCE.friends.getValue().add(f);
|
||||
Command.sendChatMessage("&b" + f.getUsername() + "&r has been friended.");
|
||||
}).start();
|
||||
|
||||
@ -73,8 +73,8 @@ public class FriendCommand extends Command {
|
||||
return;
|
||||
}
|
||||
|
||||
Friends.Friend friend = Friends.INSTANCE.friends.stream().filter(friend1 -> friend1.getUsername().equalsIgnoreCase(args[1])).findFirst().get();
|
||||
Friends.INSTANCE.friends.remove(friend);
|
||||
Friends.Friend friend = Friends.INSTANCE.friends.getValue().stream().filter(friend1 -> friend1.getUsername().equalsIgnoreCase(args[1])).findFirst().get();
|
||||
Friends.INSTANCE.friends.getValue().remove(friend);
|
||||
Command.sendChatMessage("&b" + friend.getUsername() + "&r has been unfriended.");
|
||||
return;
|
||||
}else{
|
||||
|
@ -5,8 +5,6 @@ import me.zeroeightsix.kami.command.Command;
|
||||
import me.zeroeightsix.kami.command.syntax.ChunkBuilder;
|
||||
import me.zeroeightsix.kami.gui.kami.KamiGUI;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Created by 086 on 26/12/2017.
|
||||
*/
|
||||
@ -20,15 +18,6 @@ public class ReloadCommand extends Command {
|
||||
public void call(String[] args) {
|
||||
KamiMod.getInstance().guiManager = new KamiGUI();
|
||||
KamiMod.getInstance().guiManager.initializeGUI();
|
||||
File file = new File("kami.settings");
|
||||
if (file.exists()) {
|
||||
try {
|
||||
SettingsPool.save(file);
|
||||
SettingsPool.load(file);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
KamiMod.loadConfiguration();
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package me.zeroeightsix.kami.command.commands;
|
||||
|
||||
import me.zeroeightsix.kami.KamiMod;
|
||||
import me.zeroeightsix.kami.command.Command;
|
||||
import me.zeroeightsix.kami.command.syntax.SyntaxChunk;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
@ -18,8 +18,7 @@ public class SaveCommand extends Command {
|
||||
@Override
|
||||
public void call(String[] args) {
|
||||
try {
|
||||
SettingsPool.save(new File("kami.settings"));
|
||||
Command.sendChatMessage("Configuration saved.");
|
||||
KamiMod.saveConfigurationUnsafe();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Command.sendChatMessage("Failed to save! " + e.getMessage());
|
||||
|
@ -5,6 +5,11 @@ import me.zeroeightsix.kami.command.syntax.ChunkBuilder;
|
||||
import me.zeroeightsix.kami.command.syntax.parsers.ModuleParser;
|
||||
import me.zeroeightsix.kami.module.Module;
|
||||
import me.zeroeightsix.kami.module.ModuleManager;
|
||||
import me.zeroeightsix.kami.setting.Named;
|
||||
import me.zeroeightsix.kami.setting.Setting;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Created by 086 on 18/11/2017.
|
||||
@ -33,34 +38,34 @@ public class SetCommand extends Command {
|
||||
}
|
||||
|
||||
if (args[1] == null) {
|
||||
final String[] settings = {""};
|
||||
m.getSettings().stream().forEach(staticSetting -> settings[0]+=staticSetting.getDisplayName()+", ");
|
||||
if (settings[0].isEmpty())
|
||||
String settings = String.join(", ", m.settingList.stream().filter(setting -> setting instanceof Named).map(setting -> ((Named) setting).getName()).collect(Collectors.toList()));
|
||||
if (settings.isEmpty())
|
||||
Command.sendChatMessage("Module &b" + m.getName() + "&r has no settings.");
|
||||
else{
|
||||
else {
|
||||
Command.sendStringChatMessage(new String[]{
|
||||
"Please specify a setting! Choose one of the following:",
|
||||
settings[0].substring(0,settings[0].length()-2)
|
||||
"Please specify a setting! Choose one of the following:", settings
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
SettingsClass.StaticSetting setting = m.getSettingByDisplayName(args[1]);
|
||||
if (setting == null) {
|
||||
Optional<Setting> optionalSetting = m.settingList.stream().filter(setting1 -> setting1 instanceof Named).filter(setting1 -> ((Named) setting1).getName().equalsIgnoreCase(args[1])).findFirst();
|
||||
if (!optionalSetting .isPresent()) {
|
||||
Command.sendChatMessage("Unknown setting &b" + args[1] + "&r in &b" + m.getName() + "&r!");
|
||||
return;
|
||||
}
|
||||
|
||||
Setting setting = optionalSetting.get();
|
||||
|
||||
if (args[2] == null) {
|
||||
Command.sendChatMessage("&b" + setting.getDisplayName() + "&r is a &3" + setting.getField().getType().getSimpleName() + "&r. Its current value is &3" + setting.getValue());
|
||||
Command.sendChatMessage("&b" + ((Named) setting).getName() + "&r is a &3" + setting.getValue().getClass().getSimpleName() + "&r. Its current value is &3" + setting.getValue());
|
||||
return;
|
||||
}
|
||||
|
||||
try{
|
||||
try {
|
||||
setting.setValue(args[2]);
|
||||
Command.sendChatMessage("Set &b" + setting.getDisplayName() + "&r to &3" + args[2] + "&r.");
|
||||
}catch (Exception e) {
|
||||
Command.sendChatMessage("Set &b" + ((Named) setting).getName() + "&r to &3" + args[2] + "&r.");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Command.sendChatMessage("Unable to set value! &6" + e.getMessage());
|
||||
}
|
||||
|
@ -5,8 +5,11 @@ import me.zeroeightsix.kami.command.syntax.ChunkBuilder;
|
||||
import me.zeroeightsix.kami.command.syntax.parsers.ModuleParser;
|
||||
import me.zeroeightsix.kami.module.Module;
|
||||
import me.zeroeightsix.kami.module.ModuleManager;
|
||||
import me.zeroeightsix.kami.setting.Named;
|
||||
import me.zeroeightsix.kami.setting.Setting;
|
||||
import me.zeroeightsix.kami.setting.impl.EnumSetting;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by 086 on 11/12/2017.
|
||||
@ -31,15 +34,15 @@ public class SettingsCommand extends Command {
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<SettingsClass.StaticSetting> settings = m.getSettings();
|
||||
List<Setting> settings = m.settingList;
|
||||
String[] result = new String[settings.size()];
|
||||
for (int i = 0; i < settings.size(); i++) {
|
||||
SettingsClass.StaticSetting staticSetting = settings.get(i);
|
||||
result[i] = "&b" + staticSetting.getDisplayName() + "&3(=" + staticSetting.getValue() + ") &ftype: &3" + staticSetting.getField().getType().getSimpleName();
|
||||
Setting setting = settings.get(i);
|
||||
result[i] = "&b" + (setting instanceof Named ? (((Named) setting).getName()) : "Unnamed Setting") + "&3(=" + setting.getValue() + ") &ftype: &3" + setting.getValue().getClass().getSimpleName();
|
||||
|
||||
if (staticSetting.getField().getType().isEnum()){
|
||||
if (setting instanceof EnumSetting){
|
||||
result[i] += " (";
|
||||
Enum[] enums = (Enum[]) staticSetting.getField().getType().getEnumConstants();
|
||||
Enum[] enums = (Enum[]) ((EnumSetting) setting).clazz.getEnumConstants();
|
||||
for (Enum e : enums)
|
||||
result[i] += e.name() + ", ";
|
||||
result[i] = result[i].substring(0, result[i].length()-2) + ")";
|
||||
|
@ -3,6 +3,8 @@ package me.zeroeightsix.kami.command.syntax.parsers;
|
||||
import me.zeroeightsix.kami.command.syntax.SyntaxChunk;
|
||||
import me.zeroeightsix.kami.module.Module;
|
||||
import me.zeroeightsix.kami.module.ModuleManager;
|
||||
import me.zeroeightsix.kami.setting.Named;
|
||||
import me.zeroeightsix.kami.setting.Setting;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.TreeMap;
|
||||
@ -21,17 +23,17 @@ public class ValueParser extends AbstractParser {
|
||||
Module m = ModuleManager.getModuleByName(module);
|
||||
if (m == null) return "";
|
||||
|
||||
HashMap<String, SettingsClass.StaticSetting> possibilities = new HashMap<>();
|
||||
HashMap<String, Setting> possibilities = new HashMap<>();
|
||||
|
||||
for (SettingsClass.StaticSetting v : m.getSettings()){
|
||||
if (v.getDisplayName().toLowerCase().startsWith(chunkValue.toLowerCase()))
|
||||
possibilities.put(v.getDisplayName(), v);
|
||||
for (Setting v : m.settingList){
|
||||
if (v instanceof Named && ((Named) v).getName().toLowerCase().startsWith(chunkValue.toLowerCase()))
|
||||
possibilities.put(((Named) v).getName(), v);
|
||||
}
|
||||
|
||||
if (possibilities.isEmpty()) return "";
|
||||
|
||||
TreeMap<String, SettingsClass.StaticSetting> p = new TreeMap<String, SettingsClass.StaticSetting>(possibilities);
|
||||
SettingsClass.StaticSetting aV = p.firstEntry().getValue();
|
||||
return aV.getDisplayName().substring(chunkValue.length());
|
||||
TreeMap<String, Setting> p = new TreeMap<>(possibilities);
|
||||
Setting aV = p.firstEntry().getValue();
|
||||
return ((Named) aV).getName().substring(chunkValue.length());
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ public class ForgeEventProcessor {
|
||||
@SubscribeEvent
|
||||
public void onRenderPre(RenderGameOverlayEvent.Pre event) {
|
||||
if (event.getType() == RenderGameOverlayEvent.ElementType.BOSSINFO && ModuleManager.isModuleEnabled("BossStack")) {
|
||||
if (BossStack.pre(event)) event.setCanceled(true);
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,13 @@ import me.zeroeightsix.kami.gui.rgui.component.use.CheckButton;
|
||||
import me.zeroeightsix.kami.gui.rgui.component.use.Slider;
|
||||
import me.zeroeightsix.kami.gui.rgui.render.theme.Theme;
|
||||
import me.zeroeightsix.kami.module.Module;
|
||||
import me.zeroeightsix.kami.setting.ISetting;
|
||||
import me.zeroeightsix.kami.setting.Named;
|
||||
import me.zeroeightsix.kami.setting.Setting;
|
||||
import me.zeroeightsix.kami.setting.impl.BooleanSetting;
|
||||
import me.zeroeightsix.kami.setting.impl.EnumSetting;
|
||||
import me.zeroeightsix.kami.setting.impl.numerical.IntegerSetting;
|
||||
import me.zeroeightsix.kami.setting.impl.numerical.NumberSetting;
|
||||
import me.zeroeightsix.kami.util.Bind;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@ -40,66 +46,66 @@ public class SettingsPanel extends OrganisedContainer {
|
||||
setVisible(false);
|
||||
return;
|
||||
}
|
||||
if (!module.getSettings().isEmpty()) {
|
||||
for (SettingsClass.StaticSetting staticSetting : module.getSettings()) {
|
||||
Class type = staticSetting.getField().getType();
|
||||
boolean isNumber = type == int.class || type == double.class || type == float.class || type == short.class || type == long.class || type == byte.class;
|
||||
boolean isBoolean = type == boolean.class;
|
||||
boolean isEnum = type.isEnum();
|
||||
ISetting settingAnnotation = staticSetting.getField().getAnnotation(ISetting.class);
|
||||
if (settingAnnotation.hidden()) {
|
||||
if (settingAnnotation.name().equalsIgnoreCase("Bind")) {
|
||||
addChild(new BindButton("Bind", module));
|
||||
}
|
||||
continue;
|
||||
if (!module.settingList.isEmpty()) {
|
||||
for (Setting setting : module.settingList) {
|
||||
if (!(setting instanceof Named)) continue;
|
||||
String name = ((Named) setting).getName();
|
||||
boolean isNumber = setting instanceof NumberSetting;
|
||||
boolean isBoolean = setting instanceof BooleanSetting;
|
||||
boolean isEnum = setting instanceof EnumSetting;
|
||||
|
||||
if (setting.getValue() instanceof Bind) {
|
||||
addChild(new BindButton("Bind", module));
|
||||
}
|
||||
|
||||
if (isNumber) {
|
||||
boolean isBound = settingAnnotation.max() != -1 && settingAnnotation.min() != -1;
|
||||
NumberSetting numberSetting = (NumberSetting) setting;
|
||||
boolean isBound = numberSetting.isBound();
|
||||
|
||||
if (!isBound) {
|
||||
UnboundSlider slider = new UnboundSlider(Double.parseDouble(staticSetting.getValue().toString()), staticSetting.getDisplayName(), settingAnnotation.integer());
|
||||
UnboundSlider slider = new UnboundSlider(numberSetting.getValue().doubleValue(), name, setting instanceof IntegerSetting);
|
||||
slider.addPoof(new Slider.SliderPoof<UnboundSlider, Slider.SliderPoof.SliderPoofInfo>() {
|
||||
@Override
|
||||
public void execute(UnboundSlider component, SliderPoofInfo info) {
|
||||
staticSetting.setValue(info.getNewValue());
|
||||
setting.setValue(info.getNewValue());
|
||||
}
|
||||
});
|
||||
if (settingAnnotation.max() != -1) slider.setMax(settingAnnotation.max());
|
||||
if (settingAnnotation.min() != -1) slider.setMin(settingAnnotation.min());
|
||||
if (numberSetting.getMax() != null) slider.setMax(numberSetting.getMax().doubleValue());
|
||||
if (numberSetting.getMin() != null) slider.setMin(numberSetting.getMin().doubleValue());
|
||||
addChild(slider);
|
||||
} else {
|
||||
Slider slider = new Slider(Double.parseDouble(staticSetting.getValue().toString()), settingAnnotation.min(), settingAnnotation.max(), Slider.getDefaultStep(settingAnnotation.min(), settingAnnotation.max()), staticSetting.getDisplayName(), settingAnnotation.integer());
|
||||
Slider slider = new Slider(numberSetting.getValue().doubleValue(), numberSetting.getMin().doubleValue(), numberSetting.getMax().doubleValue(), Slider.getDefaultStep(numberSetting.getMin().doubleValue(), numberSetting.getMax().doubleValue()), name, setting instanceof IntegerSetting);
|
||||
slider.addPoof(new Slider.SliderPoof<Slider, Slider.SliderPoof.SliderPoofInfo>() {
|
||||
@Override
|
||||
public void execute(Slider component, SliderPoofInfo info) {
|
||||
staticSetting.setValue(info.getNewValue());
|
||||
setting.setValue(info.getNewValue());
|
||||
}
|
||||
});
|
||||
addChild(slider);
|
||||
}
|
||||
}else if(isBoolean) {
|
||||
CheckButton checkButton = new CheckButton(staticSetting.getDisplayName());
|
||||
checkButton.setToggled((Boolean) staticSetting.getValue());
|
||||
CheckButton checkButton = new CheckButton(name);
|
||||
checkButton.setToggled(((BooleanSetting) setting).getValue());
|
||||
checkButton.addPoof(new CheckButton.CheckButtonPoof<CheckButton, CheckButton.CheckButtonPoof.CheckButtonPoofInfo>() {
|
||||
@Override
|
||||
public void execute(CheckButton checkButton1, CheckButtonPoofInfo info) {
|
||||
if (info.getAction() == CheckButtonPoofInfo.CheckButtonPoofInfoAction.TOGGLE)
|
||||
staticSetting.setValue(checkButton.isToggled());
|
||||
setting.setValue(checkButton.isToggled());
|
||||
}
|
||||
});
|
||||
addChild(checkButton);
|
||||
}else if(isEnum) {
|
||||
Class<? extends Enum> type = ((EnumSetting) setting).clazz;
|
||||
Object[] con = type.getEnumConstants();
|
||||
String[] modes = Arrays.stream(con).map(o -> o.toString().toUpperCase()).toArray(String[]::new);
|
||||
EnumButton enumbutton = new EnumButton(staticSetting.getDisplayName(), modes);
|
||||
EnumButton enumbutton = new EnumButton(name, modes);
|
||||
enumbutton.addPoof(new EnumButton.EnumbuttonIndexPoof<EnumButton, EnumButton.EnumbuttonIndexPoof.EnumbuttonInfo>() {
|
||||
@Override
|
||||
public void execute(EnumButton component, EnumbuttonInfo info) {
|
||||
staticSetting.setValue(con[info.getNewIndex()]);
|
||||
setting.setValue(con[info.getNewIndex()]);
|
||||
}
|
||||
});
|
||||
enumbutton.setIndex(Arrays.asList(con).indexOf(staticSetting.getValue()));
|
||||
enumbutton.setIndex(Arrays.asList(con).indexOf(setting.getValue()));
|
||||
addChild(enumbutton);
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ public class MixinGuiPlayerTabOverlay {
|
||||
|
||||
@Redirect(method = "renderPlayerlist", at = @At(value = "INVOKE", target = "Ljava/util/List;subList(II)Ljava/util/List;"))
|
||||
public List subList(List list, int fromIndex, int toIndex) {
|
||||
return list.subList(fromIndex, ExtraTab.INSTANCE.isEnabled() ? Math.min(ExtraTab.INSTANCE.tabSize, list.size()) : toIndex);
|
||||
return list.subList(fromIndex, ExtraTab.INSTANCE.isEnabled() ? Math.min(ExtraTab.INSTANCE.tabSize.getValue(), list.size()) : toIndex);
|
||||
}
|
||||
|
||||
@Inject(method = "getPlayerName", at = @At("HEAD"), cancellable = true)
|
||||
|
@ -10,12 +10,14 @@ import net.minecraft.client.gui.*;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
/**
|
||||
@ -39,7 +41,6 @@ public class MixinMinecraft {
|
||||
@Shadow
|
||||
SoundHandler mcSoundHandler;
|
||||
|
||||
|
||||
@Inject(method = "displayGuiScreen", at = @At("HEAD"), cancellable = true)
|
||||
public void displayGuiScreen(GuiScreen guiScreenIn, CallbackInfo info) {
|
||||
GuiScreenEvent.Closed screenEvent = new GuiScreenEvent.Closed(Wrapper.getMinecraft().currentScreen);
|
||||
@ -102,4 +103,20 @@ public class MixinMinecraft {
|
||||
info.cancel();
|
||||
}
|
||||
|
||||
@Redirect(method = "run", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;displayCrashReport(Lnet/minecraft/crash/CrashReport;)V"))
|
||||
public void displayCrashReport(Minecraft minecraft, CrashReport crashReport) {
|
||||
save();
|
||||
}
|
||||
|
||||
@Inject(method = "shutdown", at = @At("HEAD"))
|
||||
public void shutdown(CallbackInfo info) {
|
||||
save();
|
||||
}
|
||||
|
||||
private void save() {
|
||||
System.out.println("Shutting down: saving KAMI configuration");
|
||||
KamiMod.saveConfiguration();
|
||||
System.out.println("Configuration saved.");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,6 +15,8 @@ import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by 086 on 23/08/2017.
|
||||
@ -24,15 +26,16 @@ public class Module {
|
||||
private final String name = getAnnotation().name();
|
||||
private final String description = getAnnotation().description();
|
||||
private final Category category = getAnnotation().category();
|
||||
private Setting<Bind> bind = register(Settings.custom("Bind", Bind.none(), new BindConverter(), true));
|
||||
private boolean enabled;
|
||||
private Setting<Bind> bind = Settings.custom("Bind", Bind.none(), new BindConverter(), true).build();
|
||||
private Setting<Boolean> enabled = Settings.b("Enabled", false);
|
||||
public boolean alwaysListening;
|
||||
protected static final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
public List<Setting> settingList = new ArrayList<>();
|
||||
|
||||
public Module() {
|
||||
alwaysListening = getAnnotation().alwaysListening();
|
||||
|
||||
enabled = false;
|
||||
registerAll(bind, enabled);
|
||||
}
|
||||
|
||||
private Info getAnnotation() {
|
||||
@ -100,7 +103,7 @@ public class Module {
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
return enabled.getValue();
|
||||
}
|
||||
|
||||
protected void onEnable() {}
|
||||
@ -111,14 +114,14 @@ public class Module {
|
||||
}
|
||||
|
||||
public void enable() {
|
||||
enabled = true;
|
||||
enabled.setValue(true);
|
||||
onEnable();
|
||||
if (!alwaysListening)
|
||||
KamiMod.EVENT_BUS.subscribe(this);
|
||||
}
|
||||
|
||||
public void disable() {
|
||||
enabled = false;
|
||||
enabled.setValue(false);
|
||||
onDisable();
|
||||
if (!alwaysListening)
|
||||
KamiMod.EVENT_BUS.unsubscribe(this);
|
||||
@ -129,7 +132,7 @@ public class Module {
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
boolean prev = this.enabled;
|
||||
boolean prev = this.enabled.getValue();
|
||||
if (prev != enabled)
|
||||
if (enabled)
|
||||
enable();
|
||||
@ -195,11 +198,16 @@ public class Module {
|
||||
}
|
||||
|
||||
protected <T> Setting<T> register(Setting<T> setting) {
|
||||
if (settingList == null) settingList = new ArrayList<>();
|
||||
settingList.add(setting);
|
||||
return SettingBuilder.register(setting, "modules." + name);
|
||||
}
|
||||
|
||||
protected <T> Setting<T> register(SettingBuilder<T> builder) {
|
||||
return builder.buildAndRegister("modules." + name);
|
||||
if (settingList == null) settingList = new ArrayList<>();
|
||||
Setting<T> setting = builder.buildAndRegister("modules." + name);
|
||||
settingList.add(setting);
|
||||
return setting;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
@ -37,6 +38,9 @@ public class ModuleManager {
|
||||
Module module = (Module) aClass.getConstructor().newInstance();
|
||||
modules.add(module);
|
||||
lookup.put(module.getName().toLowerCase(), module);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.getCause().printStackTrace();
|
||||
System.err.println("Couldn't initiate module " + aClass.getSimpleName() + "! Err: " + e.getClass().getSimpleName() + ", message: " + e.getMessage());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.err.println("Couldn't initiate module " + aClass.getSimpleName() + "! Err: " + e.getClass().getSimpleName() + ", message: " + e.getMessage());
|
||||
|
@ -22,16 +22,16 @@ import java.util.UUID;
|
||||
@Module.Info(name = "BossStack", description = "Modify the boss health GUI to take up less space", category = Module.Category.MISC)
|
||||
public class BossStack extends Module {
|
||||
|
||||
private Setting<BossStackMode> mode = register(Settings.e("Mode", BossStackMode.STACK));
|
||||
private Setting<Double> scale = register(Settings.d("Scale", .5d));
|
||||
private static Setting<BossStackMode> mode = Settings.e("Mode", BossStackMode.STACK);
|
||||
private static Setting<Double> scale = Settings.d("Scale", .5d);
|
||||
|
||||
private final ResourceLocation GUI_BARS_TEXTURES = new ResourceLocation("textures/gui/bars.png");
|
||||
private static final ResourceLocation GUI_BARS_TEXTURES = new ResourceLocation("textures/gui/bars.png");
|
||||
|
||||
public boolean pre(RenderGameOverlayEvent.Pre event) {
|
||||
return true;
|
||||
public BossStack() {
|
||||
registerAll(mode, scale);
|
||||
}
|
||||
|
||||
public void render(RenderGameOverlayEvent.Post event) {
|
||||
public static void render(RenderGameOverlayEvent.Post event) {
|
||||
if (mode.getValue() == BossStackMode.MINIMIZE) {
|
||||
Map<UUID, BossInfoClient> map = Minecraft.getMinecraft().ingameGUI.getBossOverlay().mapBossInfos;
|
||||
if (map == null) return;
|
||||
@ -42,7 +42,6 @@ public class BossStack extends Module {
|
||||
for (Map.Entry<UUID, BossInfoClient> entry : map.entrySet()) {
|
||||
BossInfoClient info = entry.getValue();
|
||||
String text = info.getName().getFormattedText();
|
||||
if (text == null || info == null) continue;
|
||||
|
||||
int k = (int) ((i / scale.getValue()) / 2 - 91);
|
||||
GL11.glScaled(scale.getValue(), scale.getValue(), 1);
|
||||
|
@ -14,7 +14,7 @@ import net.minecraft.scoreboard.ScorePlayerTeam;
|
||||
@Module.Info(name = "ExtraTab", description = "Expands the player tab menu", category = Module.Category.RENDER)
|
||||
public class ExtraTab extends Module {
|
||||
|
||||
private Setting<Integer> tabSize = register(Settings.integerBuilder("Players").withMinimum(1).withValue(80).build());
|
||||
public Setting<Integer> tabSize = register(Settings.integerBuilder("Players").withMinimum(1).withValue(80).build());
|
||||
|
||||
public static ExtraTab INSTANCE;
|
||||
|
||||
|
@ -20,4 +20,11 @@ public class ListeningSettingRestrictable<T> extends SettingRestrictable<T> {
|
||||
return consumer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setValue(T value) {
|
||||
T old = getValue();
|
||||
boolean b = super.setValue(value);
|
||||
if (b) consumer.accept(old, value);
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,9 @@ public class SettingsRegister {
|
||||
|
||||
public SettingsRegister subregister(String name) {
|
||||
if (registerHashMap.containsKey(name)) return registerHashMap.get(name);
|
||||
return registerHashMap.put(name, new SettingsRegister());
|
||||
SettingsRegister register = new SettingsRegister();
|
||||
registerHashMap.put(name, register);
|
||||
return register;
|
||||
}
|
||||
|
||||
private void put(String name, Setting setting) {
|
||||
@ -51,7 +53,7 @@ public class SettingsRegister {
|
||||
previousToken = token;
|
||||
}
|
||||
}
|
||||
return new Pair<>(previousToken, current);
|
||||
return new Pair<>(previousToken == null ? "" : previousToken, current);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,6 +9,6 @@ import me.zeroeightsix.kami.setting.impl.numerical.NumberSetting;
|
||||
public class DoubleSettingBuilder extends NumericalSettingBuilder<Double> {
|
||||
@Override
|
||||
public NumberSetting build() {
|
||||
return new DoubleSetting(initialValue, predicate(), consumer(), name, visibilityPredicate());
|
||||
return new DoubleSetting(initialValue, predicate(), consumer(), name, visibilityPredicate(), min, max);
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,6 @@ import me.zeroeightsix.kami.setting.impl.numerical.NumberSetting;
|
||||
public class FloatSettingBuilder extends NumericalSettingBuilder<Float> {
|
||||
@Override
|
||||
public NumberSetting build() {
|
||||
return new FloatSetting(initialValue, predicate(), consumer(), name, visibilityPredicate());
|
||||
return new FloatSetting(initialValue, predicate(), consumer(), name, visibilityPredicate(), min, max);
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,6 @@ import me.zeroeightsix.kami.setting.impl.numerical.NumberSetting;
|
||||
public class IntegerSettingBuilder extends NumericalSettingBuilder<Integer> {
|
||||
@Override
|
||||
public NumberSetting build() {
|
||||
return new IntegerSetting(initialValue, predicate(), consumer(), name, visibilityPredicate());
|
||||
return new IntegerSetting(initialValue, predicate(), consumer(), name, visibilityPredicate(), min, max);
|
||||
}
|
||||
}
|
||||
|
@ -10,21 +10,32 @@ import java.util.function.BiConsumer;
|
||||
*/
|
||||
public abstract class NumericalSettingBuilder<T extends Number> extends SettingBuilder<T> {
|
||||
|
||||
protected T min;
|
||||
protected T max;
|
||||
|
||||
public NumericalSettingBuilder<T> withMinimum(T minimum) {
|
||||
predicateList.add((t -> t.doubleValue() >= minimum.doubleValue()));
|
||||
if (min == null || minimum.doubleValue() > min.doubleValue())
|
||||
min = minimum;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NumericalSettingBuilder<T> withMaximum(T maximum) {
|
||||
predicateList.add((t -> t.doubleValue() <= maximum.doubleValue()));
|
||||
if (max == null || maximum.doubleValue() < max.doubleValue())
|
||||
max = maximum;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NumericalSettingBuilder<T> withRange(T from, T to) {
|
||||
public NumericalSettingBuilder<T> withRange(T minimum, T maximum) {
|
||||
predicateList.add((t -> {
|
||||
double doubleValue = t.doubleValue();
|
||||
return doubleValue >= from.doubleValue() && doubleValue <= to.doubleValue();
|
||||
return doubleValue >= minimum.doubleValue() && doubleValue <= maximum.doubleValue();
|
||||
}));
|
||||
if (min == null || minimum.doubleValue() > min.doubleValue())
|
||||
min = minimum;
|
||||
if (max == null || maximum.doubleValue() < max.doubleValue())
|
||||
max = maximum;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -13,10 +13,12 @@ import java.util.function.Predicate;
|
||||
public class EnumSetting<T extends Enum> extends AbstractSetting<T> {
|
||||
|
||||
private EnumConverter converter;
|
||||
public final Class<? extends Enum> clazz;
|
||||
|
||||
public EnumSetting(T value, Predicate<T> restriction, BiConsumer<T, T> consumer, String name, Predicate<T> visibilityPredicate, Class<? extends Enum> clazz) {
|
||||
super(value, restriction, consumer, name, visibilityPredicate);
|
||||
this.converter = new EnumConverter(clazz);
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -13,8 +13,8 @@ public class DoubleSetting extends NumberSetting<Double> {
|
||||
|
||||
private static final BoxedDoubleConverter converter = new BoxedDoubleConverter();
|
||||
|
||||
public DoubleSetting(Double value, Predicate<Double> restriction, BiConsumer<Double, Double> consumer, String name, Predicate<Double> visibilityPredicate) {
|
||||
super(value, restriction, consumer, name, visibilityPredicate);
|
||||
public DoubleSetting(Double value, Predicate<Double> restriction, BiConsumer<Double, Double> consumer, String name, Predicate<Double> visibilityPredicate, Double min, Double max) {
|
||||
super(value, restriction, consumer, name, visibilityPredicate, min, max);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -13,8 +13,8 @@ public class FloatSetting extends NumberSetting<Float> {
|
||||
|
||||
private static final BoxedFloatConverter converter = new BoxedFloatConverter();
|
||||
|
||||
public FloatSetting(Float value, Predicate<Float> restriction, BiConsumer<Float, Float> consumer, String name, Predicate<Float> visibilityPredicate) {
|
||||
super(value, restriction, consumer, name, visibilityPredicate);
|
||||
public FloatSetting(Float value, Predicate<Float> restriction, BiConsumer<Float, Float> consumer, String name, Predicate<Float> visibilityPredicate, Float min, Float max) {
|
||||
super(value, restriction, consumer, name, visibilityPredicate, min, max);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -13,8 +13,8 @@ public class IntegerSetting extends NumberSetting<Integer> {
|
||||
|
||||
private static final BoxedIntegerConverter converter = new BoxedIntegerConverter();
|
||||
|
||||
public IntegerSetting(Integer value, Predicate<Integer> restriction, BiConsumer<Integer, Integer> consumer, String name, Predicate<Integer> visibilityPredicate) {
|
||||
super(value, restriction, consumer, name, visibilityPredicate);
|
||||
public IntegerSetting(Integer value, Predicate<Integer> restriction, BiConsumer<Integer, Integer> consumer, String name, Predicate<Integer> visibilityPredicate, Integer min, Integer max) {
|
||||
super(value, restriction, consumer, name, visibilityPredicate, min, max);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -11,11 +11,35 @@ import java.util.function.Predicate;
|
||||
*/
|
||||
public abstract class NumberSetting<T extends Number> extends AbstractSetting<T> {
|
||||
|
||||
public NumberSetting(T value, Predicate<T> restriction, BiConsumer<T, T> consumer, String name, Predicate<T> visibilityPredicate) {
|
||||
private final T min;
|
||||
private final T max;
|
||||
|
||||
public NumberSetting(T value, Predicate<T> restriction, BiConsumer<T, T> consumer, String name, Predicate<T> visibilityPredicate, T min, T max) {
|
||||
super(value, restriction, consumer, name, visibilityPredicate);
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if this setting has both a defined maximum and minimum
|
||||
*/
|
||||
public boolean isBound() {
|
||||
return min != null && max != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract AbstractBoxedNumberConverter converter();
|
||||
|
||||
@Override
|
||||
public T getValue() {
|
||||
return super.getValue();
|
||||
}
|
||||
|
||||
public T getMax() {
|
||||
return max;
|
||||
}
|
||||
|
||||
public T getMin() {
|
||||
return min;
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import java.util.regex.Pattern;
|
||||
public class Friends {
|
||||
public static final Friends INSTANCE = new Friends();
|
||||
|
||||
private static Setting<ArrayList<Friend>> friends;
|
||||
public static Setting<ArrayList<Friend>> friends;
|
||||
|
||||
private Friends() {
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user