Load and Export config commands
This commit is contained in:
parent
e5ddac4613
commit
c4b9de74e7
|
@ -25,8 +25,12 @@ public abstract class Configurable {
|
|||
return file;
|
||||
}
|
||||
|
||||
public void onLoad() {
|
||||
this.jsonObject = this.convertJsonObjectFromFile();
|
||||
public void onLoad(JsonObject jsonObject) {
|
||||
if (jsonObject != null) {
|
||||
this.jsonObject = jsonObject;
|
||||
} else {
|
||||
this.jsonObject = this.convertJsonObjectFromFile();
|
||||
}
|
||||
}
|
||||
|
||||
public void onSave() {
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
package me.rigamortis.seppuku.impl.command;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import me.rigamortis.seppuku.Seppuku;
|
||||
import me.rigamortis.seppuku.api.command.Command;
|
||||
import me.rigamortis.seppuku.api.config.Configurable;
|
||||
import me.rigamortis.seppuku.api.gui.hud.component.HudComponent;
|
||||
import me.rigamortis.seppuku.api.module.Module;
|
||||
import me.rigamortis.seppuku.api.util.FileUtil;
|
||||
import me.rigamortis.seppuku.impl.config.*;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author noil
|
||||
*/
|
||||
public final class ExportCommand extends Command {
|
||||
public ExportCommand() {
|
||||
super("Export", new String[]{"Exprt"}, "Export all Module & HUD configs into a single json for upload on Seppuku's website.", "Export <config_name>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exec(String input) {
|
||||
if (!this.clamp(input, 2, 2)) {
|
||||
this.printUsage();
|
||||
return;
|
||||
}
|
||||
|
||||
final String[] split = input.split(" ");
|
||||
final String configName = split[1];
|
||||
final File file = FileUtil.createJsonFile(Seppuku.INSTANCE.getConfigManager().getConfigDir(), configName);
|
||||
|
||||
JsonObject endJson = new JsonObject();
|
||||
for (Configurable cfg : Seppuku.INSTANCE.getConfigManager().getConfigurableList()) {
|
||||
if (cfg.getClass().equals(ClientConfig.class)) {
|
||||
final JsonObject clientJson = cfg.getJsonObject();
|
||||
endJson.add("Client", clientJson);
|
||||
}
|
||||
if (cfg.getClass().equals(XrayConfig.class)) {
|
||||
final JsonObject xrayJson = cfg.getJsonObject();
|
||||
endJson.add("Xray", xrayJson);
|
||||
}
|
||||
if (cfg.getClass().equals(SearchConfig.class)) {
|
||||
final JsonObject searchJson = cfg.getJsonObject();
|
||||
endJson.add("Search", searchJson);
|
||||
}
|
||||
if (cfg.getClass().equals(NukerFilterConfig.class)) {
|
||||
final JsonObject nukerFilterJson = cfg.getJsonObject();
|
||||
endJson.add("NukerFilter", nukerFilterJson);
|
||||
}
|
||||
if (cfg.getClass().equals(ModuleConfig.class)) {
|
||||
final JsonObject moduleJson = cfg.getJsonObject();
|
||||
final ModuleConfig moduleConfig = (ModuleConfig) cfg;
|
||||
final Module module = moduleConfig.getModule();
|
||||
endJson.add("Module" + module.getDisplayName(), moduleJson);
|
||||
}
|
||||
if (cfg.getClass().equals(HudConfig.class)) {
|
||||
final JsonObject hudJson = cfg.getJsonObject();
|
||||
final HudConfig hudConfig = (HudConfig) cfg;
|
||||
final HudComponent hudComponent = hudConfig.getHudComponent();
|
||||
endJson.add("HudComponent" + hudComponent.getName(), hudJson);
|
||||
}
|
||||
}
|
||||
|
||||
FileUtil.saveJsonFile(file, endJson);
|
||||
|
||||
Seppuku.INSTANCE.logChat("\247c" + "Exported config " + configName + ".json into the Seppuku directory.");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
package me.rigamortis.seppuku.impl.command;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import me.rigamortis.seppuku.Seppuku;
|
||||
import me.rigamortis.seppuku.api.cape.CapeUser;
|
||||
import me.rigamortis.seppuku.api.command.Command;
|
||||
import me.rigamortis.seppuku.impl.config.*;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* @author noil
|
||||
*/
|
||||
public final class LoadCommand extends Command {
|
||||
|
||||
public LoadCommand() {
|
||||
super("Load", new String[]{"Lode"}, "Load a config from your profile on Seppuku's website.", "Load <pin>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exec(String input) {
|
||||
if (!this.clamp(input, 2, 2)) {
|
||||
this.printUsage();
|
||||
return;
|
||||
}
|
||||
|
||||
final String[] split = input.split(" ");
|
||||
|
||||
JsonObject configJson = null;
|
||||
try { //http://127.0.0.1:5000/config/38aef33297814b07a88a3d2d1a611002/100
|
||||
final String stringUrl = "http://127.0.0.1:5000/config/" + Minecraft.getMinecraft().player.getUniqueID().toString().replace("-", "") + "/" + split[1];
|
||||
URL url = new URL(stringUrl);
|
||||
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
|
||||
httpURLConnection.addRequestProperty("User-Agent", "Mozilla/4.76");
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
|
||||
String line;
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (!line.startsWith("<pre>") && !line.startsWith("</pre>")) {
|
||||
stringBuilder.append(line);
|
||||
}
|
||||
}
|
||||
reader.close();
|
||||
if (stringBuilder.toString().length() > 0) {
|
||||
configJson = new JsonParser().parse(stringBuilder.toString()).getAsJsonObject();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Seppuku.INSTANCE.logChat("\247c" + "Error loading config from server.");
|
||||
}
|
||||
|
||||
if (configJson != null) {
|
||||
configJson.entrySet().forEach(entry -> {
|
||||
if (entry.getKey().equalsIgnoreCase("Client")) {
|
||||
this.loadConfigForClass(ClientConfig.class, entry.getValue().getAsJsonObject());
|
||||
}
|
||||
if (entry.getKey().equalsIgnoreCase("Xray")) {
|
||||
this.loadConfigForClass(XrayConfig.class, entry.getValue().getAsJsonObject());
|
||||
}
|
||||
if (entry.getKey().equalsIgnoreCase("Search")) {
|
||||
this.loadConfigForClass(SearchConfig.class, entry.getValue().getAsJsonObject());
|
||||
|
||||
}
|
||||
if (entry.getKey().equalsIgnoreCase("NukerFilter")) {
|
||||
this.loadConfigForClass(NukerFilterConfig.class, entry.getValue().getAsJsonObject());
|
||||
}
|
||||
Seppuku.INSTANCE.getModuleManager().getModuleList().forEach(module -> {
|
||||
if (entry.getKey().equalsIgnoreCase("Module" + module.getDisplayName())) {
|
||||
this.loadModuleConfigForClass(ModuleConfig.class, entry.getValue().getAsJsonObject(), module.getDisplayName());
|
||||
}
|
||||
});
|
||||
Seppuku.INSTANCE.getHudManager().getComponentList().forEach(hudComponent -> {
|
||||
if (entry.getKey().equalsIgnoreCase("HudComponent" + hudComponent.getName())) {
|
||||
this.loadHudConfigForClass(HudConfig.class, entry.getValue().getAsJsonObject(), hudComponent.getName());
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Seppuku.INSTANCE.logChat("\247c" + "Loaded config from server.");
|
||||
}
|
||||
}
|
||||
|
||||
private void loadConfigForClass(Class configClass, JsonObject jsonObject) {
|
||||
Seppuku.INSTANCE.getConfigManager().getConfigurableList().stream().filter(configurable -> configurable.getClass().equals(configClass)).forEach(configurable -> {
|
||||
configurable.onLoad(jsonObject);
|
||||
});
|
||||
}
|
||||
|
||||
private void loadModuleConfigForClass(Class configClass, JsonObject jsonObject, String displayName) {
|
||||
Seppuku.INSTANCE.getConfigManager().getConfigurableList().stream().filter(configurable -> configurable.getClass().equals(ModuleConfig.class)).forEach(configurable -> {
|
||||
final ModuleConfig moduleConfig = (ModuleConfig) configurable;
|
||||
if (moduleConfig.getModule().getDisplayName().equals(displayName)) {
|
||||
configurable.onLoad(jsonObject);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void loadHudConfigForClass(Class configClass, JsonObject jsonObject, String name) {
|
||||
Seppuku.INSTANCE.getConfigManager().getConfigurableList().stream().filter(configurable -> configurable.getClass().equals(HudConfig.class)).forEach(configurable -> {
|
||||
final HudConfig hudConfig = (HudConfig) configurable;
|
||||
if (hudConfig.getHudComponent().getName().equals(name)) {
|
||||
configurable.onLoad(jsonObject);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -19,8 +19,8 @@ public final class AltConfig extends Configurable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
super.onLoad();
|
||||
public void onLoad(JsonObject jsonObject) {
|
||||
super.onLoad(jsonObject);
|
||||
this.getJsonObject().entrySet().forEach(entry -> {
|
||||
final String username = entry.getKey();
|
||||
|
||||
|
|
|
@ -23,8 +23,8 @@ public final class AutoIgnoreConfig extends Configurable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
super.onLoad();
|
||||
public void onLoad(JsonObject jsonObject) {
|
||||
super.onLoad(jsonObject);
|
||||
|
||||
final JsonArray autoIgnoredJsonArray = this.getJsonObject().get("AutoIgnored").getAsJsonArray();
|
||||
|
||||
|
|
|
@ -17,8 +17,8 @@ public final class ClientConfig extends Configurable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
super.onLoad();
|
||||
public void onLoad(JsonObject jsonObject) {
|
||||
super.onLoad(jsonObject);
|
||||
|
||||
this.getJsonObject().entrySet().forEach(entry -> {
|
||||
if (entry.getKey().equalsIgnoreCase("CustomMainMenuHidden")) {
|
||||
|
|
|
@ -19,8 +19,9 @@ public final class FriendConfig extends Configurable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
super.onLoad();
|
||||
public void onLoad(JsonObject jsonObject) {
|
||||
super.onLoad(jsonObject);
|
||||
|
||||
this.getJsonObject().entrySet().forEach(entry -> {
|
||||
final String name = entry.getKey();
|
||||
|
||||
|
|
|
@ -26,8 +26,8 @@ public final class HudConfig extends Configurable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
super.onLoad();
|
||||
public void onLoad(JsonObject jsonObject) {
|
||||
super.onLoad(jsonObject);
|
||||
|
||||
if (this.hudComponent instanceof DraggableHudComponent) {
|
||||
final DraggableHudComponent draggableHudComponent = (DraggableHudComponent) this.hudComponent;
|
||||
|
@ -172,4 +172,8 @@ public final class HudConfig extends Configurable {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HudComponent getHudComponent() {
|
||||
return hudComponent;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,8 +19,8 @@ public final class IgnoreConfig extends Configurable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
super.onLoad();
|
||||
public void onLoad(JsonObject jsonObject) {
|
||||
super.onLoad(jsonObject);
|
||||
|
||||
final JsonArray ignoredJsonArray = this.getJsonObject().get("Ignored").getAsJsonArray();
|
||||
|
||||
|
|
|
@ -19,8 +19,9 @@ public final class MacroConfig extends Configurable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
super.onLoad();
|
||||
public void onLoad(JsonObject jsonObject) {
|
||||
super.onLoad(jsonObject);
|
||||
|
||||
this.getJsonObject().entrySet().forEach(entry -> {
|
||||
final String name = entry.getKey();
|
||||
final String key = entry.getValue().getAsJsonArray().get(0).getAsString();
|
||||
|
|
|
@ -28,8 +28,8 @@ public class ModuleConfig extends Configurable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
super.onLoad();
|
||||
public void onLoad(JsonObject jsonObject) {
|
||||
super.onLoad(jsonObject);
|
||||
|
||||
this.getJsonObject().entrySet().forEach(entry -> {
|
||||
if (entry.getKey().equalsIgnoreCase("Color")) {
|
||||
|
@ -138,4 +138,8 @@ public class ModuleConfig extends Configurable {
|
|||
}
|
||||
this.saveJsonObjectToFile(moduleJsonObject);
|
||||
}
|
||||
|
||||
public Module getModule() {
|
||||
return module;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@ public class NukerFilterConfig extends Configurable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
super.onLoad();
|
||||
public void onLoad(JsonObject jsonObject) {
|
||||
super.onLoad(jsonObject);
|
||||
|
||||
if (this.nukerModule == null)
|
||||
return;
|
||||
|
|
|
@ -24,8 +24,8 @@ public final class SearchConfig extends Configurable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
super.onLoad();
|
||||
public void onLoad(JsonObject jsonObject) {
|
||||
super.onLoad(jsonObject);
|
||||
|
||||
if (this.searchModule == null)
|
||||
return;
|
||||
|
|
|
@ -20,8 +20,8 @@ public final class WaypointsConfig extends Configurable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
super.onLoad();
|
||||
public void onLoad(JsonObject jsonObject) {
|
||||
super.onLoad(jsonObject);
|
||||
|
||||
final JsonArray waypointsJsonArray = this.getJsonObject().get("Waypoints").getAsJsonArray();
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@ public final class WorldConfig extends Configurable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
super.onLoad();
|
||||
public void onLoad(JsonObject jsonObject) {
|
||||
super.onLoad(jsonObject);
|
||||
|
||||
this.getJsonObject().entrySet().forEach(entry -> {
|
||||
final String host = entry.getKey();
|
||||
|
|
|
@ -24,8 +24,8 @@ public final class XrayConfig extends Configurable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
super.onLoad();
|
||||
public void onLoad(JsonObject jsonObject) {
|
||||
super.onLoad(jsonObject);
|
||||
|
||||
if (this.xrayModule == null)
|
||||
return;
|
||||
|
|
|
@ -77,6 +77,8 @@ public final class CommandManager {
|
|||
this.commandList.add(new MainMenuCommand());
|
||||
this.commandList.add(new ConfigCommand());
|
||||
this.commandList.add(new NukerFilterCommand());
|
||||
this.commandList.add(new ExportCommand());
|
||||
this.commandList.add(new LoadCommand());
|
||||
|
||||
//create commands for every value within every module
|
||||
loadValueCommands();
|
||||
|
|
|
@ -129,7 +129,7 @@ public final class ConfigManager {
|
|||
public void load(Class configurableClassType) {
|
||||
for (Configurable cfg : configurableList) {
|
||||
if (cfg.getClass().isAssignableFrom(configurableClassType)) {
|
||||
cfg.onLoad();
|
||||
cfg.onLoad(null);
|
||||
}
|
||||
}
|
||||
Seppuku.INSTANCE.getEventManager().dispatchEvent(new EventLoadConfig());
|
||||
|
@ -137,7 +137,7 @@ public final class ConfigManager {
|
|||
|
||||
public void loadAll() {
|
||||
for (Configurable cfg : configurableList) {
|
||||
cfg.onLoad();
|
||||
cfg.onLoad(null);
|
||||
}
|
||||
Seppuku.INSTANCE.getEventManager().dispatchEvent(new EventLoadConfig());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue