new json config system

This commit is contained in:
noil755 2019-12-01 20:58:25 -05:00
parent 503c1bc678
commit f3ce7736b2
32 changed files with 693 additions and 962 deletions

View File

@ -78,8 +78,8 @@ public final class Seppuku {
this.initLogger();
this.eventManager = new AnnotatedEventManager();
this.apiManager = new APIManager();
this.moduleManager = new ModuleManager();
this.commandManager = new CommandManager();
this.configManager = new ConfigManager();
this.ignoredManager = new IgnoredManager();
this.friendManager = new FriendManager();
this.rotationManager = new RotationManager();
this.macroManager = new MacroManager();
@ -87,16 +87,17 @@ public final class Seppuku {
this.tickRateManager = new TickRateManager();
this.chatManager = new ChatManager();
this.worldManager = new WorldManager();
this.ignoredManager = new IgnoredManager();
this.capeManager = new CapeManager();
this.positionManager = new PositionManager();
this.joinLeaveManager = new JoinLeaveManager();
this.hudManager = new HudManager();
this.animationManager = new AnimationManager();
this.notificationManager = new NotificationManager();
this.moduleManager = new ModuleManager();
this.commandManager = new CommandManager();
this.hudManager = new HudManager();
//this.seppukuMainMenu = new GuiSeppukuMainMenu();
this.configManager = new ConfigManager(); // Keep last, so we load configs after everything inits
this.configManager.init(); // Keep last, so we load configs after everything else inits
this.prevTitle = Display.getTitle();
Display.setTitle("Seppuku 1.12.2");

View File

@ -1,27 +1,61 @@
package me.rigamortis.seppuku.api.config;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import me.rigamortis.seppuku.api.util.FileUtil;
import java.io.File;
import java.io.FileReader;
/**
* Author Seth
* 4/18/2019 @ 7:02 AM.
* @author noil
*/
public abstract class Configurable {
private String path;
private File file;
public Configurable(String path) {
this.path = path;
private JsonObject jsonObject;
public Configurable(File file) {
this.file = file;
}
public abstract void load();
public abstract void save();
public String getPath() {
return path;
public File getFile() {
return file;
}
public void setPath(String path) {
this.path = path;
public void onLoad() {
this.jsonObject = this.convertJsonObjectFromFile();
}
}
public void onSave() {
}
protected void saveJsonObjectToFile(JsonObject object) {
File newFile = FileUtil.recreateFile(this.getFile());
FileUtil.saveJsonFile(newFile, object);
}
protected JsonObject convertJsonObjectFromFile() {
if (!this.getFile().exists())
return new JsonObject();
FileReader reader = FileUtil.createReader(this.getFile());
if (reader == null)
return new JsonObject();
JsonElement element = new JsonParser().parse(reader);
if (!element.isJsonObject())
return new JsonObject();
FileUtil.closeReader(reader);
return element.getAsJsonObject();
}
public JsonObject getJsonObject() {
return jsonObject;
}
}

View File

@ -32,26 +32,6 @@ public class Module {
}
public Module(String displayName, String[] alias, String desc, String key, int color, boolean hidden, boolean enabled, ModuleType type) {
this.displayName = displayName;
this.alias = alias;
this.desc = desc;
this.key = key;
this.color = color;
this.hidden = hidden;
this.enabled = enabled;
this.type = type;
}
public Module(String displayName, String[] alias, String desc, String key, int color, ModuleType type) {
this.displayName = displayName;
this.alias = alias;
this.desc = desc;
this.key = key;
this.color = color;
this.type = type;
}
public Module(String displayName, String[] alias, String key, int color, ModuleType type) {
this.displayName = displayName;
this.alias = alias;
@ -60,6 +40,17 @@ public class Module {
this.type = type;
}
public Module(String displayName, String[] alias, String desc, String key, int color, ModuleType type) {
this(displayName, alias, key, color, type);
this.desc = desc;
}
public Module(String displayName, String[] alias, String desc, String key, int color, boolean hidden, boolean enabled, ModuleType type) {
this(displayName, alias, desc, key, color, type);
this.hidden = hidden;
this.enabled = enabled;
}
public void onEnable() {
Seppuku.INSTANCE.getEventManager().addEventListener(this);
}

View File

@ -0,0 +1,184 @@
package me.rigamortis.seppuku.api.util;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import me.rigamortis.seppuku.Seppuku;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
/**
* @author noil
* @since 12/1/19 @ 4:16 PM
*/
public class FileUtil {
/**
* Tries to create a file reader
*/
public static FileReader createReader(File file) {
if (file.exists()) {
try {
return new FileReader(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
return null;
}
/**
* Tries to close a file reader
*/
public static void closeReader(FileReader reader) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Creates a directory in the client's folder
*/
public static File createDirectory(String dir) {
File folder = new File(Seppuku.INSTANCE.getConfigManager().getConfigDir(), dir);
if (!folder.exists())
folder.mkdir();
return folder;
}
/**
* Creates a json file in a directory
*/
public static File createJsonFile(File dir, String name) {
File file = new File(dir, name + ".json");
return file;
}
/**
* Removes and existing file or creates a new file
*/
public static File recreateFile(File file) {
if (file.exists()) {
file.delete();
} else {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
return file;
}
/**
* Saves a json object to a file
*/
public static void saveJsonFile(File file, JsonObject jsonObject) {
try {
file.createNewFile();
FileWriter writer = new FileWriter(file);
Throwable throwable = null;
try {
writer.write(new GsonBuilder().setPrettyPrinting().create().toJson(jsonObject));
} catch (Throwable var6_9) {
throwable = var6_9;
throw var6_9;
} finally {
if (throwable != null) {
try {
writer.close();
} catch (Throwable var6_8) {
throwable.addSuppressed(var6_8);
}
} else {
writer.close();
}
}
} catch (IOException e) {
e.printStackTrace();
file.delete();
}
}
public static List<String> read(final File inputFile) {
final List<String> fileContentList = new ArrayList<>();
FileReader fileReader = null;
BufferedReader bufferedFileReader = null;
try {
fileReader = new FileReader(inputFile);
bufferedFileReader = new BufferedReader(fileReader);
String currentReadLine;
while ((currentReadLine = bufferedFileReader.readLine()) != null) {
fileContentList.add(currentReadLine);
}
} catch (FileNotFoundException e) {
System.err.println("FileNotFoundException thrown, make sure the file exists.");
} catch (IOException e) {
System.err.println("IOException thrown, can't read the file's content.");
} finally {
try {
if (bufferedFileReader != null) {
bufferedFileReader.close();
}
if (fileReader != null) {
fileReader.close();
}
} catch (IOException e) {
}
}
return fileContentList;
}
public static String write(final File outputFile, final List<String> writeContent, boolean override) {
BufferedWriter bufferedFileWriter = null;
FileWriter fileWriter = null;
String message = "";
try {
fileWriter = new FileWriter(outputFile, !override);
bufferedFileWriter = new BufferedWriter(fileWriter);
for (final String outputLine : writeContent) {
bufferedFileWriter.write(outputLine);
bufferedFileWriter.flush();
bufferedFileWriter.newLine();
}
message = "Completed writing to the file.";
} catch (IOException e) {
message = "IOException thrown while attempting to write.";
} finally {
try {
if (bufferedFileWriter != null) {
bufferedFileWriter.close();
}
if (fileWriter != null) {
fileWriter.close();
}
} catch (IOException e) {
message = "IOException thrown while attemping to close the writer.";
}
}
return message;
}
public static boolean ensureExistance(File targetFile) {
if (!targetFile.exists()) {
try {
targetFile.createNewFile();
} catch (IOException e) {
System.err.println("IOException thrown, can't create file.");
}
}
return targetFile.exists();
}
}

View File

@ -1,72 +1,45 @@
package me.rigamortis.seppuku.impl.config;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import me.rigamortis.seppuku.Seppuku;
import me.rigamortis.seppuku.api.config.Configurable;
import me.rigamortis.seppuku.impl.management.ConfigManager;
import me.rigamortis.seppuku.api.util.FileUtil;
import me.rigamortis.seppuku.impl.module.misc.AutoIgnoreModule;
import java.io.*;
import java.io.File;
/**
* Author Seth
* 7/2/2019 @ 5:16 AM.
* @author noil
*/
public final class AutoIgnoreConfig extends Configurable {
public AutoIgnoreConfig() {
super(ConfigManager.CONFIG_PATH + "AutoIgnore.cfg");
private AutoIgnoreModule autoIgnoreModule;
public AutoIgnoreConfig(File dir) {
super(FileUtil.createJsonFile(dir, "AutoIgnored"));
this.autoIgnoreModule = (AutoIgnoreModule) Seppuku.INSTANCE.getModuleManager().find(AutoIgnoreModule.class);
}
@Override
public void load() {
try{
final File file = new File(this.getPath());
public void onLoad() {
super.onLoad();
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
final JsonArray autoIgnoredJsonArray = this.getJsonObject().get("AutoIgnored").getAsJsonArray();
final BufferedReader reader = new BufferedReader(new FileReader(this.getPath()));
String line;
while ((line = reader.readLine()) != null) {
final AutoIgnoreModule autoIgnoreModule = (AutoIgnoreModule) Seppuku.INSTANCE.getModuleManager().find(AutoIgnoreModule.class);
if(autoIgnoreModule != null) {
autoIgnoreModule.getBlacklist().add(line);
}
}
reader.close();
}catch (Exception e) {
e.printStackTrace();
for (JsonElement jsonElement : autoIgnoredJsonArray) {
final String blacklistedName = jsonElement.getAsString();
this.autoIgnoreModule.getBlacklist().add(blacklistedName);
}
}
@Override
public void save() {
try{
final File file = new File(this.getPath());
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
final BufferedWriter writer = new BufferedWriter(new FileWriter(this.getPath()));
final AutoIgnoreModule autoIgnoreModule = (AutoIgnoreModule) Seppuku.INSTANCE.getModuleManager().find(AutoIgnoreModule.class);
if(autoIgnoreModule != null) {
for (String s : autoIgnoreModule.getBlacklist()) {
writer.write(s);
writer.newLine();
}
}
writer.close();
}catch (Exception e) {
e.printStackTrace();
}
public void onSave() {
JsonObject save = new JsonObject();
JsonArray autoIgnoreListJsonArray = new JsonArray();
this.autoIgnoreModule.getBlacklist().forEach(autoIgnoreListJsonArray::add);
save.add("AutoIgnored", autoIgnoreListJsonArray);
this.saveJsonObjectToFile(save);
}
}

View File

@ -1,73 +0,0 @@
package me.rigamortis.seppuku.impl.config;
import me.rigamortis.seppuku.Seppuku;
import me.rigamortis.seppuku.api.config.Configurable;
import me.rigamortis.seppuku.api.module.Module;
import me.rigamortis.seppuku.impl.management.ConfigManager;
import java.io.*;
/**
* Author Seth
* 4/18/2019 @ 9:52 PM.
*/
public final class BindConfig extends Configurable {
public BindConfig() {
super(ConfigManager.CONFIG_PATH + "Binds.cfg");
}
@Override
public void load() {
try{
final File file = new File(this.getPath());
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
final BufferedReader reader = new BufferedReader(new FileReader(this.getPath()));
String line;
while ((line = reader.readLine()) != null) {
final String[] split = line.split(":");
final Module mod = Seppuku.INSTANCE.getModuleManager().find(split[0]);
if(mod != null && mod.getType() != Module.ModuleType.HIDDEN) {
if(split[1] != "") {
mod.setKey(split[1].toUpperCase());
}
}
}
reader.close();
}catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void save() {
try{
final File file = new File(this.getPath());
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
final BufferedWriter writer = new BufferedWriter(new FileWriter(this.getPath()));
for(Module mod : Seppuku.INSTANCE.getModuleManager().getModuleList()) {
if(mod != null && mod.getType() != Module.ModuleType.HIDDEN) {
writer.write(mod.getDisplayName() + ":" + mod.getKey().toUpperCase());
writer.newLine();
}
}
writer.close();
}catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -1,73 +0,0 @@
package me.rigamortis.seppuku.impl.config;
import me.rigamortis.seppuku.Seppuku;
import me.rigamortis.seppuku.api.config.Configurable;
import me.rigamortis.seppuku.api.module.Module;
import me.rigamortis.seppuku.impl.management.ConfigManager;
import java.io.*;
/**
* Author Seth
* 4/18/2019 @ 10:59 PM.
*/
public final class ColorConfig extends Configurable {
public ColorConfig() {
super(ConfigManager.CONFIG_PATH + "Colors.cfg");
}
@Override
public void load() {
try{
final File file = new File(this.getPath());
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
final BufferedReader reader = new BufferedReader(new FileReader(this.getPath()));
String line;
while ((line = reader.readLine()) != null) {
final String[] split = line.split(":");
final Module mod = Seppuku.INSTANCE.getModuleManager().find(split[0]);
if(mod != null && mod.getType() != Module.ModuleType.HIDDEN) {
if(split[1] != "") {
mod.setColor((int) Long.parseLong(split[1], 16));
}
}
}
reader.close();
}catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void save() {
try{
final File file = new File(this.getPath());
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
final BufferedWriter writer = new BufferedWriter(new FileWriter(this.getPath()));
for(Module mod : Seppuku.INSTANCE.getModuleManager().getModuleList()) {
if(mod != null && mod.getType() != Module.ModuleType.HIDDEN) {
writer.write(mod.getDisplayName() + ":" + Integer.toHexString(mod.getColor()).toUpperCase());
writer.newLine();
}
}
writer.close();
}catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -1,73 +1,43 @@
package me.rigamortis.seppuku.impl.config;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import me.rigamortis.seppuku.Seppuku;
import me.rigamortis.seppuku.api.config.Configurable;
import me.rigamortis.seppuku.api.friend.Friend;
import me.rigamortis.seppuku.impl.management.ConfigManager;
import me.rigamortis.seppuku.api.util.FileUtil;
import java.io.*;
import java.io.File;
/**
* Author Seth
* 4/18/2019 @ 10:43 PM.
* @author noil
*/
public final class FriendConfig extends Configurable {
public FriendConfig() {
super(ConfigManager.CONFIG_PATH + "Friends.cfg");
public FriendConfig(File dir) {
super(FileUtil.createJsonFile(dir, "Friends"));
}
@Override
public void load() {
try{
final File file = new File(this.getPath());
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
final BufferedReader reader = new BufferedReader(new FileReader(this.getPath()));
String line;
while ((line = reader.readLine()) != null) {
final String[] split = line.split(":");
if(split[0] != null && split[1] != null) {
final Friend friend = new Friend(split[0], split[1]);
if(split.length > 2 && split[2] != null) {
friend.setUuid(split[2]);
}
if(!Seppuku.INSTANCE.getFriendManager().getFriendList().contains(friend)) {
Seppuku.INSTANCE.getFriendManager().getFriendList().add(friend);
}
}
}
reader.close();
}catch (Exception e) {
e.printStackTrace();
}
public void onLoad() {
super.onLoad();
this.getJsonObject().entrySet().forEach(entry -> {
final String name = entry.getKey();
final String alias = entry.getValue().getAsJsonArray().get(0).getAsString();
final String uuid = entry.getValue().getAsJsonArray().get(1).getAsString();
Seppuku.INSTANCE.getFriendManager().getFriendList().add(new Friend(name, uuid, alias));
});
}
@Override
public void save() {
try{
final File file = new File(this.getPath());
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
final BufferedWriter writer = new BufferedWriter(new FileWriter(this.getPath()));
for(Friend friend : Seppuku.INSTANCE.getFriendManager().getFriendList()) {
writer.write(friend.getName() + ":" + friend.getAlias() + ":" + friend.getUuid());
writer.newLine();
}
writer.close();
}catch (Exception e) {
e.printStackTrace();
}
public void onSave() {
JsonObject friendsListJsonObject = new JsonObject();
Seppuku.INSTANCE.getFriendManager().getFriendList().forEach(friend -> {
JsonArray array = new JsonArray();
array.add(friend.getAlias());
array.add(friend.getUuid());
friendsListJsonObject.add(friend.getName(), array);
});
this.saveJsonObjectToFile(friendsListJsonObject);
}
}

View File

@ -1,73 +0,0 @@
package me.rigamortis.seppuku.impl.config;
import me.rigamortis.seppuku.Seppuku;
import me.rigamortis.seppuku.api.config.Configurable;
import me.rigamortis.seppuku.api.module.Module;
import me.rigamortis.seppuku.impl.management.ConfigManager;
import java.io.*;
/**
* Author Seth
* 4/18/2019 @ 11:02 PM.
*/
public final class HiddenConfig extends Configurable {
public HiddenConfig() {
super(ConfigManager.CONFIG_PATH + "Hidden.cfg");
}
@Override
public void load() {
try{
final File file = new File(this.getPath());
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
final BufferedReader reader = new BufferedReader(new FileReader(this.getPath()));
String line;
while ((line = reader.readLine()) != null) {
final String[] split = line.split(":");
final Module mod = Seppuku.INSTANCE.getModuleManager().find(split[0]);
if(mod != null && mod.getType() != Module.ModuleType.HIDDEN) {
if(split[1] != "") {
mod.setHidden(Boolean.parseBoolean(split[1]));
}
}
}
reader.close();
}catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void save() {
try{
final File file = new File(this.getPath());
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
final BufferedWriter writer = new BufferedWriter(new FileWriter(this.getPath()));
for(Module mod : Seppuku.INSTANCE.getModuleManager().getModuleList()) {
if(mod.getType() != Module.ModuleType.HIDDEN) {
writer.write(mod.getDisplayName() + ":" + mod.isHidden());
writer.newLine();
}
}
writer.close();
}catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -1,112 +1,74 @@
package me.rigamortis.seppuku.impl.config;
import com.google.gson.JsonObject;
import me.rigamortis.seppuku.Seppuku;
import me.rigamortis.seppuku.api.config.Configurable;
import me.rigamortis.seppuku.api.gui.hud.component.DraggableHudComponent;
import me.rigamortis.seppuku.api.gui.hud.component.HudComponent;
import me.rigamortis.seppuku.api.util.FileUtil;
import me.rigamortis.seppuku.impl.gui.hud.anchor.AnchorPoint;
import me.rigamortis.seppuku.impl.management.ConfigManager;
import java.io.*;
import java.io.File;
/**
* created by noil on 8/25/2019 at 12:23 PM
* @author noil
*/
public final class HudConfig extends Configurable {
public HudConfig() {
super(ConfigManager.CONFIG_PATH + "Hud.cfg");
private DraggableHudComponent hudComponent;
public HudConfig(File dir, DraggableHudComponent hudComponent) {
super(FileUtil.createJsonFile(dir, hudComponent.getName()));
this.hudComponent = hudComponent;
}
@Override
public void load() {
try {
final File file = new File(this.getPath());
public void onLoad() {
super.onLoad();
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
final BufferedReader reader = new BufferedReader(new FileReader(this.getPath()));
String line;
while ((line = reader.readLine()) != null) {
final String[] split = line.split(":");
final HudComponent component = Seppuku.INSTANCE.getHudManager().findComponent(split[0]);
if (component != null) {
if (!split[1].equals("")) {
component.setX(Float.valueOf(split[1]));
}
if (!split[2].equals("")) {
component.setY(Float.valueOf(split[2]));
}
if (!split[3].equals("")) {
component.setVisible(Boolean.valueOf(split[3]));
}
if (!split[4].equals("")) {
final DraggableHudComponent draggable = (DraggableHudComponent) component;
if (!split[4].equals("NULL_ANCHOR")) {
for (AnchorPoint anchorPoint : Seppuku.INSTANCE.getHudManager().getAnchorPoints()) {
if (anchorPoint.getPoint().equals(AnchorPoint.Point.valueOf(split[4]))) {
draggable.setAnchorPoint(anchorPoint);
}
this.getJsonObject().entrySet().forEach(entry -> {
switch (entry.getKey()) {
case "X":
hudComponent.setX(entry.getValue().getAsFloat());
break;
case "Y":
hudComponent.setY(entry.getValue().getAsFloat());
break;
case "Visible":
hudComponent.setVisible(entry.getValue().getAsBoolean());
break;
case "Anchor":
if (!entry.getValue().getAsString().equals("NONE")) {
for (AnchorPoint anchorPoint : Seppuku.INSTANCE.getHudManager().getAnchorPoints()) {
if (anchorPoint.getPoint().equals(AnchorPoint.Point.valueOf(entry.getValue().getAsString()))) {
hudComponent.setAnchorPoint(anchorPoint);
}
}
if (!split[5].equals("NULL_GLUED") && !split[6].equals("NULL_GLUE_SIDE")) {
draggable.setGlued((DraggableHudComponent) Seppuku.INSTANCE.getHudManager().findComponent(split[5]));
draggable.setGlueSide(DraggableHudComponent.GlueSide.valueOf(split[6]));
}
}
}
break;
case "Glue":
if (!entry.getValue().getAsString().equals("NONE")) {
hudComponent.setGlued((DraggableHudComponent) Seppuku.INSTANCE.getHudManager().findComponent(entry.getValue().getAsString()));
}
break;
case "GlueSide":
if (!entry.getValue().getAsString().equals("NONE")) {
hudComponent.setGlueSide(DraggableHudComponent.GlueSide.valueOf(entry.getValue().getAsString()));
}
break;
}
reader.close();
} catch (Exception e) {
e.printStackTrace();
}
});
}
@Override
public void save() {
try {
final File file = new File(this.getPath());
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
final BufferedWriter writer = new BufferedWriter(new FileWriter(this.getPath()));
if (Seppuku.INSTANCE.getHudManager().getComponentList() != null) {
for (HudComponent component : Seppuku.INSTANCE.getHudManager().getComponentList()) {
writer.write(component.getName() + ":" + component.getX() + ":" + component.getY() + ":" + component.isVisible());
if (component instanceof DraggableHudComponent) {
final DraggableHudComponent draggable = (DraggableHudComponent) component;
// Anchor Point
if (draggable.getAnchorPoint() != null) {
writer.write(":" + draggable.getAnchorPoint().getPoint().name());
} else {
writer.write(":" + "NULL_ANCHOR");
}
// Glued
if (draggable.getGlued() != null) {
writer.write(":" + draggable.getGlued().getName() + ":" + draggable.getGlueSide());
} else {
writer.write(":" + "NULL_GLUED" + ":" + "NULL_GLUE_SIDE");
}
}
writer.newLine();
}
}
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
public void onSave() {
JsonObject componentsListJsonObject = new JsonObject();
componentsListJsonObject.addProperty("Name", hudComponent.getName());
componentsListJsonObject.addProperty("X", hudComponent.getX());
componentsListJsonObject.addProperty("Y", hudComponent.getY());
componentsListJsonObject.addProperty("Visible", hudComponent.isVisible());
componentsListJsonObject.addProperty("Anchor", hudComponent.getAnchorPoint() == null ? "NONE" : hudComponent.getAnchorPoint().getPoint().name());
componentsListJsonObject.addProperty("Glue", hudComponent.getGlued() == null ? "NONE" : hudComponent.getGlued().getName());
componentsListJsonObject.addProperty("GlueSide", hudComponent.getGlued() == null ? "NONE" : hudComponent.getGlueSide().name());
this.saveJsonObjectToFile(componentsListJsonObject);
}
}

View File

@ -1,65 +1,43 @@
package me.rigamortis.seppuku.impl.config;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import me.rigamortis.seppuku.Seppuku;
import me.rigamortis.seppuku.api.config.Configurable;
import me.rigamortis.seppuku.api.ignore.Ignored;
import me.rigamortis.seppuku.impl.management.ConfigManager;
import me.rigamortis.seppuku.api.util.FileUtil;
import java.io.*;
import java.io.File;
/**
* Author Seth
* 6/29/2019 @ 9:14 AM.
* @author noil
*/
public final class IgnoreConfig extends Configurable {
public IgnoreConfig() {
super(ConfigManager.CONFIG_PATH + "Ignored.cfg");
public IgnoreConfig(File dir) {
super(FileUtil.createJsonFile(dir, "Ignored"));
}
@Override
public void load() {
try{
final File file = new File(this.getPath());
public void onLoad() {
super.onLoad();
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
final JsonArray ignoredJsonArray = this.getJsonObject().get("Ignored").getAsJsonArray();
final BufferedReader reader = new BufferedReader(new FileReader(this.getPath()));
String line;
while ((line = reader.readLine()) != null) {
Seppuku.INSTANCE.getIgnoredManager().add(line);
}
reader.close();
}catch (Exception e) {
e.printStackTrace();
for (JsonElement jsonElement : ignoredJsonArray) {
final String blacklistedName = jsonElement.getAsString();
Seppuku.INSTANCE.getIgnoredManager().add(blacklistedName);
}
}
@Override
public void save() {
try{
final File file = new File(this.getPath());
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
final BufferedWriter writer = new BufferedWriter(new FileWriter(this.getPath()));
for(Ignored ignored : Seppuku.INSTANCE.getIgnoredManager().getIgnoredList()) {
writer.write(ignored.getName());
writer.newLine();
}
writer.close();
}catch (Exception e) {
e.printStackTrace();
}
public void onSave() {
JsonObject save = new JsonObject();
JsonArray ignoredJsonArray = new JsonArray();
Seppuku.INSTANCE.getIgnoredManager().getIgnoredList().forEach(ignored -> {
ignoredJsonArray.add(ignored.getName());
});
save.add("Ignored", ignoredJsonArray);
this.saveJsonObjectToFile(save);
}
}

View File

@ -1,67 +1,43 @@
package me.rigamortis.seppuku.impl.config;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import me.rigamortis.seppuku.Seppuku;
import me.rigamortis.seppuku.api.config.Configurable;
import me.rigamortis.seppuku.api.macro.Macro;
import me.rigamortis.seppuku.impl.management.ConfigManager;
import me.rigamortis.seppuku.api.util.FileUtil;
import java.io.*;
import java.io.File;
/**
* Author Seth
* 5/7/2019 @ 9:57 PM.
* @author noil
*/
public final class MacroConfig extends Configurable {
public MacroConfig() {
super(ConfigManager.CONFIG_PATH + "Macros.cfg");
}
@Override
public void load() {
try{
final File file = new File(this.getPath());
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
final BufferedReader reader = new BufferedReader(new FileReader(this.getPath()));
String line;
while ((line = reader.readLine()) != null) {
final String[] split = line.split(":");
Seppuku.INSTANCE.getMacroManager().getMacroList().add(new Macro(split[0], split[1], split[2]));
}
reader.close();
}catch (Exception e) {
e.printStackTrace();
}
public MacroConfig(File dir) {
super(FileUtil.createJsonFile(dir, "Macros"));
}
@Override
public void save() {
try{
final File file = new File(this.getPath());
public void onLoad() {
super.onLoad();
this.getJsonObject().entrySet().forEach(entry -> {
final String name = entry.getKey();
final String key = entry.getValue().getAsJsonArray().get(0).getAsString();
final String macro = entry.getValue().getAsJsonArray().get(1).getAsString();
Seppuku.INSTANCE.getMacroManager().getMacroList().add(new Macro(name, key, macro));
});
}
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
final BufferedWriter writer = new BufferedWriter(new FileWriter(this.getPath()));
for(Macro macro : Seppuku.INSTANCE.getMacroManager().getMacroList()) {
writer.write(macro.getName() + ":" + macro.getKey() + ":" + macro.getMacro());
writer.newLine();
}
writer.close();
}catch (Exception e) {
e.printStackTrace();
}
@Override
public void onSave() {
JsonObject macroListObject = new JsonObject();
Seppuku.INSTANCE.getMacroManager().getMacroList().forEach(macro -> {
JsonArray array = new JsonArray();
array.add(macro.getKey());
array.add(macro.getMacro());
macroListObject.add(macro.getName(), array);
});
this.saveJsonObjectToFile(macroListObject.getAsJsonObject());
}
}

View File

@ -0,0 +1,93 @@
package me.rigamortis.seppuku.impl.config;
import com.google.gson.JsonObject;
import me.rigamortis.seppuku.api.config.Configurable;
import me.rigamortis.seppuku.api.module.Module;
import me.rigamortis.seppuku.api.util.FileUtil;
import me.rigamortis.seppuku.api.value.Value;
import java.io.File;
/**
* @author noil
*/
public class ModuleConfig extends Configurable {
private final Module module;
public ModuleConfig(File dir, Module module) {
super(FileUtil.createJsonFile(dir, module.getDisplayName()));
this.module = module;
}
@Override
public void onLoad() {
super.onLoad();
this.getJsonObject().entrySet().forEach(entry -> {
if (entry.getKey().equalsIgnoreCase("Color")) {
module.setColor((int) Long.parseLong(entry.getValue().getAsString(), 16));
}
if (entry.getKey().equalsIgnoreCase("Hidden")) {
module.setHidden(entry.getValue().getAsBoolean());
}
if (entry.getKey().equalsIgnoreCase("Keybind")) {
module.setKey(entry.getValue().getAsString());
}
// Check if we are already enabled
if (entry.getKey().equalsIgnoreCase("Enabled") && !module.isEnabled() && module.getType() != Module.ModuleType.HIDDEN) {
if (entry.getValue().getAsBoolean()) {
module.toggle();
}
}
for (Value val : module.getValueList()) {
if (val.getName().equalsIgnoreCase(entry.getKey())) {
if (val.getValue() instanceof Boolean) {
val.setValue(entry.getValue().getAsBoolean());
} else if (val.getValue() instanceof Number && !(val.getValue() instanceof Enum)) {
if (val.getValue().getClass() == Float.class) {
val.setValue(entry.getValue().getAsFloat());
} else if (val.getValue().getClass() == Double.class) {
val.setValue(entry.getValue().getAsDouble());
} else if (val.getValue().getClass() == Integer.class) {
val.setValue(entry.getValue().getAsInt());
}
} else if (val.getValue() instanceof Enum) {
val.setEnumValue(entry.getValue().getAsString());
}
}
}
});
}
@Override
public void onSave() {
JsonObject moduleJsonObject = new JsonObject();
moduleJsonObject.addProperty("Name", module.getDisplayName());
moduleJsonObject.addProperty("Color", Integer.toHexString(module.getColor()).toUpperCase());
moduleJsonObject.addProperty("Hidden", module.isHidden());
moduleJsonObject.addProperty("Keybind", (module.getKey() != null) ? module.getKey() : "NONE");
moduleJsonObject.addProperty("Enabled", module.isEnabled());
if (module.getValueList().size() != 0) {
module.getValueList().forEach(value -> {
if (value.getValue() instanceof Boolean)
moduleJsonObject.addProperty(value.getName(), (Boolean) value.getValue());
else if (value.getValue() instanceof Number && !(value.getValue() instanceof Enum)) {
if (value.getValue().getClass() == Float.class) {
moduleJsonObject.addProperty(value.getName(), (Float) value.getValue());
} else if (value.getValue().getClass() == Double.class) {
moduleJsonObject.addProperty(value.getName(), (Double) value.getValue());
} else if (value.getValue().getClass() == Integer.class) {
moduleJsonObject.addProperty(value.getName(), (Integer) value.getValue());
}
} else if (value.getValue() instanceof Enum) {
moduleJsonObject.addProperty(value.getName(), ((Enum) value.getValue()).name());
}
});
}
this.saveJsonObjectToFile(moduleJsonObject);
}
}

View File

@ -1,71 +0,0 @@
package me.rigamortis.seppuku.impl.config;
import me.rigamortis.seppuku.Seppuku;
import me.rigamortis.seppuku.api.config.Configurable;
import me.rigamortis.seppuku.api.module.Module;
import me.rigamortis.seppuku.impl.management.ConfigManager;
import java.io.*;
/**
* Author Seth
* 4/18/2019 @ 7:03 AM.
*/
public final class ToggledConfig extends Configurable {
public ToggledConfig() {
super(ConfigManager.CONFIG_PATH + "Toggled.cfg");
}
@Override
public void load() {
try{
final File file = new File(this.getPath());
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
final BufferedReader reader = new BufferedReader(new FileReader(this.getPath()));
String line;
while ((line = reader.readLine()) != null) {
final String[] split = line.split(":");
final Module mod = Seppuku.INSTANCE.getModuleManager().find(split[0]);
if(mod != null && !mod.isEnabled() && mod.getType() != Module.ModuleType.HIDDEN) {
mod.toggle();
}
}
reader.close();
}catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void save() {
try{
final File file = new File(this.getPath());
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
final BufferedWriter writer = new BufferedWriter(new FileWriter(this.getPath()));
for(Module mod : Seppuku.INSTANCE.getModuleManager().getModuleList()) {
if(mod.isEnabled() && mod.getType() != Module.ModuleType.HIDDEN) {
writer.write(mod.getDisplayName());
writer.newLine();
}
}
writer.close();
}catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -1,131 +0,0 @@
package me.rigamortis.seppuku.impl.config;
import me.rigamortis.seppuku.Seppuku;
import me.rigamortis.seppuku.api.config.Configurable;
import me.rigamortis.seppuku.api.module.Module;
import me.rigamortis.seppuku.api.util.StringUtil;
import me.rigamortis.seppuku.api.value.Value;
import me.rigamortis.seppuku.impl.management.ConfigManager;
import java.io.*;
/**
* Author Seth
* 4/19/2019 @ 12:08 AM.
*/
public final class ValueConfig extends Configurable {
public ValueConfig() {
super(ConfigManager.CONFIG_PATH + "Values/");
}
@Override
public void load() {
try {
for (Module mod : Seppuku.INSTANCE.getModuleManager().getModuleList()) {
final File file = new File(this.getPath() + mod.getDisplayName() + ".cfg");
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
final BufferedReader reader = new BufferedReader(new FileReader(this.getPath() + mod.getDisplayName() + ".cfg"));
String line;
while ((line = reader.readLine()) != null) {
final String[] split = line.split(":");
final Value v = mod.find(split[0]);
if (v != null) {
if (v.getValue() instanceof Boolean) {
if (StringUtil.isBoolean(split[1])) {
v.setValue(Boolean.parseBoolean(split[1]));
}
}
if (v.getValue() instanceof Number && !(v.getValue() instanceof Enum)) {
if (split[2].equals("Float") && v.getValue().getClass() == Float.class) {
if (StringUtil.isFloat(split[1])) {
v.setValue(Float.parseFloat(split[1]));
}
}
if (split[2].equals("Integer") && v.getValue().getClass() == Integer.class) {
if (StringUtil.isInt(split[1])) {
v.setValue(Integer.parseInt(split[1]));
}
}
if (split[2].equals("Double") && v.getValue().getClass() == Double.class) {
if (StringUtil.isDouble(split[1])) {
v.setValue(Double.parseDouble(split[1]));
}
}
}
if (v.getValue() instanceof Enum) {
if (split.length > 1) {
v.setEnumValue(split[1]);
}
}
if (v.getValue() instanceof String) {
if (split.length > 1) {
v.setValue(split[1]);
}
}
}
}
reader.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void save() {
try {
for (Module mod : Seppuku.INSTANCE.getModuleManager().getModuleList()) {
final File file = new File(this.getPath() + mod.getDisplayName() + ".cfg");
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
final BufferedWriter writer = new BufferedWriter(new FileWriter(this.getPath() + mod.getDisplayName() + ".cfg"));
for (Value val : mod.getValueList()) {
if (val.getValue() instanceof Boolean) {
writer.write(val.getName() + ":" + val.getValue());
writer.newLine();
}
if (val.getValue() instanceof Number && !(val.getValue() instanceof Enum)) {
if (val.getValue().getClass() == Float.class) {
writer.write(val.getName() + ":" + val.getValue() + ":Float");
writer.newLine();
} else if (val.getValue().getClass() == Integer.class) {
writer.write(val.getName() + ":" + val.getValue() + ":Integer");
writer.newLine();
} else if (val.getValue().getClass() == Double.class) {
writer.write(val.getName() + ":" + val.getValue() + ":Double");
writer.newLine();
}
}
if (val.getValue() instanceof Enum || val.getValue() instanceof String) {
writer.write(val.getName() + ":" + val.getValue());
writer.newLine();
}
}
writer.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -1,78 +1,68 @@
package me.rigamortis.seppuku.impl.config;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import me.rigamortis.seppuku.Seppuku;
import me.rigamortis.seppuku.api.config.Configurable;
import me.rigamortis.seppuku.impl.management.ConfigManager;
import me.rigamortis.seppuku.api.util.FileUtil;
import me.rigamortis.seppuku.impl.module.world.WaypointsModule;
import java.io.*;
import java.io.File;
/**
* Author Seth
* 5/8/2019 @ 7:08 AM.
* @author noil
*/
public final class WaypointsConfig extends Configurable {
public WaypointsConfig() {
super(ConfigManager.CONFIG_PATH + "Waypoints.cfg");
public WaypointsConfig(File dir) {
super(FileUtil.createJsonFile(dir, "Waypoints"));
}
@Override
public void load() {
try{
final File file = new File(this.getPath());
public void onLoad() {
super.onLoad();
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
final JsonArray waypointsJsonArray = this.getJsonObject().get("Waypoints").getAsJsonArray();
final BufferedReader reader = new BufferedReader(new FileReader(this.getPath()));
for (JsonElement jsonElement : waypointsJsonArray) {
if (jsonElement instanceof JsonArray) {
final JsonArray waypointDataJson = (JsonArray) jsonElement;
String line;
while ((line = reader.readLine()) != null) {
final String[] split = line.split(":");
final String host = split[0];
final String name = split[1];
final String x = split[2];
final String y = split[3];
final String z = split[4];
final String dim = split[5];
final String host = waypointDataJson.get(0).getAsString();
final String name = waypointDataJson.get(1).getAsString();
final int x = waypointDataJson.get(2).getAsInt();
final int y = waypointDataJson.get(3).getAsInt();
final int z = waypointDataJson.get(4).getAsInt();
final int dimension = waypointDataJson.get(5).getAsInt();
final String color = waypointDataJson.get(6).getAsString();
final WaypointsModule.WaypointData waypointData = new WaypointsModule.WaypointData(host, name, Integer.parseInt(dim), Double.parseDouble(x), Double.parseDouble(y), Double.parseDouble(z));
if (split.length > 6) // set color afterwards, since we create a random one in the waypoint data constructor if it doesn't exist
waypointData.setColor(Integer.parseInt(split[6], 16));
final WaypointsModule.WaypointData waypointData = new WaypointsModule.WaypointData(host, name, dimension, x, y, z);
waypointData.setColor((int) Long.parseLong(color, 16));
Seppuku.INSTANCE.getWaypointManager().getWaypointDataList().add(waypointData);
}
reader.close();
}catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void save() {
try{
final File file = new File(this.getPath());
public void onSave() {
JsonObject save = new JsonObject();
JsonArray waypointsJsonArray = new JsonArray();
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
Seppuku.INSTANCE.getWaypointManager().getWaypointDataList().forEach(waypoint -> {
JsonArray waypointDataJson = new JsonArray();
waypointDataJson.add(waypoint.getHost());
waypointDataJson.add(waypoint.getName());
waypointDataJson.add((int) waypoint.getX());
waypointDataJson.add((int) waypoint.getY());
waypointDataJson.add((int) waypoint.getZ());
waypointDataJson.add(waypoint.getDimension());
waypointDataJson.add(Integer.toHexString(waypoint.getColor()).toUpperCase());
waypointsJsonArray.add(waypointDataJson);
});
final BufferedWriter writer = new BufferedWriter(new FileWriter(this.getPath()));
for(WaypointsModule.WaypointData waypointData : Seppuku.INSTANCE.getWaypointManager().getWaypointDataList()) {
writer.write(waypointData.getHost() + ":" + waypointData.getName() + ":" + waypointData.getX() + ":" + waypointData.getY() + ":" + waypointData.getZ() + ":" + waypointData.getDimension() + ":" + Integer.toHexString(waypointData.getColor()));
writer.newLine();
}
writer.close();
}catch (Exception e) {
e.printStackTrace();
}
save.add("Waypoints", waypointsJsonArray);
this.saveJsonObjectToFile(save);
}
}

View File

@ -1,69 +1,42 @@
package me.rigamortis.seppuku.impl.config;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import me.rigamortis.seppuku.Seppuku;
import me.rigamortis.seppuku.api.config.Configurable;
import me.rigamortis.seppuku.impl.management.ConfigManager;
import me.rigamortis.seppuku.api.util.FileUtil;
import me.rigamortis.seppuku.impl.management.WorldManager;
import java.io.*;
import java.io.File;
/**
* Author Seth
* 6/11/2019 @ 7:29 AM.
* @author noil
*/
public final class WorldConfig extends Configurable {
public WorldConfig() {
super(ConfigManager.CONFIG_PATH + "Worlds.cfg");
public WorldConfig(File dir) {
super(FileUtil.createJsonFile(dir, "Worlds"));
}
@Override
public void load() {
try{
final File file = new File(this.getPath());
public void onLoad() {
super.onLoad();
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
final BufferedReader reader = new BufferedReader(new FileReader(this.getPath()));
String line;
while ((line = reader.readLine()) != null) {
final String[] split = line.split(":");
final String host = split[0];
final String seed = split[1];
Seppuku.INSTANCE.getWorldManager().getWorldDataList().add(new WorldManager.WorldData(host, Long.parseLong(seed)));
}
reader.close();
}catch (Exception e) {
e.printStackTrace();
}
this.getJsonObject().entrySet().forEach(entry -> {
final String host = entry.getKey();
final String seed = entry.getValue().getAsJsonArray().get(0).getAsString();
Seppuku.INSTANCE.getWorldManager().getWorldDataList().add(new WorldManager.WorldData(host, Long.parseLong(seed)));
});
}
@Override
public void save() {
try{
final File file = new File(this.getPath());
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
final BufferedWriter writer = new BufferedWriter(new FileWriter(this.getPath()));
for(WorldManager.WorldData worldData : Seppuku.INSTANCE.getWorldManager().getWorldDataList()) {
writer.write(worldData.getHost() + ":" + worldData.getSeed());
writer.newLine();
}
writer.close();
}catch (Exception e) {
e.printStackTrace();
}
public void onSave() {
JsonObject worldListJsonObject = new JsonObject();
Seppuku.INSTANCE.getWorldManager().getWorldDataList().forEach(worldData -> {
final JsonArray array = new JsonArray();
array.add(worldData.getSeed());
worldListJsonObject.add(worldData.getHost(), array);
});
this.saveJsonObjectToFile(worldListJsonObject);
}
}
}

View File

@ -1,75 +1,54 @@
package me.rigamortis.seppuku.impl.config;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import me.rigamortis.seppuku.Seppuku;
import me.rigamortis.seppuku.api.config.Configurable;
import me.rigamortis.seppuku.impl.management.ConfigManager;
import me.rigamortis.seppuku.api.util.FileUtil;
import me.rigamortis.seppuku.impl.module.render.XrayModule;
import java.io.*;
import java.io.File;
/**
* Author Seth
* 4/18/2019 @ 11:05 PM.
* @author noil
*/
public final class XrayConfig extends Configurable {
public XrayConfig() {
super(ConfigManager.CONFIG_PATH + "Xray.cfg");
private XrayModule xrayModule;
public XrayConfig(File dir) {
super(FileUtil.createJsonFile(dir, "Xray"));
this.xrayModule = (XrayModule) Seppuku.INSTANCE.getModuleManager().find("Xray");
}
@Override
public void load() {
try{
final File file = new File(this.getPath());
public void onLoad() {
super.onLoad();
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
if (this.xrayModule == null)
return;
final BufferedReader reader = new BufferedReader(new FileReader(this.getPath()));
final JsonArray xrayIdsJsonArray = this.getJsonObject().get("BlockIds").getAsJsonArray();
String line;
while ((line = reader.readLine()) != null) {
final String[] split = line.split(":");
final XrayModule xray = (XrayModule) Seppuku.INSTANCE.getModuleManager().find("Xray");
if(xray != null) {
int id = Integer.parseInt(split[0]);
if(id > 0) {
xray.add(id);
}
}
}
reader.close();
}catch (Exception e) {
e.printStackTrace();
for (JsonElement jsonElement : xrayIdsJsonArray) {
this.xrayModule.add(jsonElement.getAsInt());
}
}
@Override
public void save() {
try{
final File file = new File(this.getPath());
public void onSave() {
if (this.xrayModule == null)
return;
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
JsonObject save = new JsonObject();
final BufferedWriter writer = new BufferedWriter(new FileWriter(this.getPath()));
JsonArray xrayIdsJsonArray = new JsonArray();
for (Integer i : this.xrayModule.getIds())
xrayIdsJsonArray.add(i);
final XrayModule xray = (XrayModule) Seppuku.INSTANCE.getModuleManager().find("Xray");
if(xray != null) {
for(Integer id : xray.getIds()) {
writer.write("" + id.intValue());
writer.newLine();
}
}
save.add("BlockIds", xrayIdsJsonArray);
writer.close();
}catch (Exception e) {
e.printStackTrace();
}
this.saveJsonObjectToFile(save);
}
}

View File

@ -94,6 +94,7 @@ public final class CapeManager {
/**
* Returns a ResourceLocation for a player
*
* @param player
* @return
*/

View File

@ -45,7 +45,7 @@ public final class ChatManager {
this.chatBuffer.clear();
}
for(int i = 0; i < this.chatBuffer.size(); i++) {
for (int i = 0; i < this.chatBuffer.size(); i++) {
final String s = this.chatBuffer.get(i);
if (s != null) {
if (this.timer.passed(200.0f)) {

View File

@ -8,6 +8,7 @@ import me.rigamortis.seppuku.api.util.ReflectionUtil;
import me.rigamortis.seppuku.api.util.StringUtil;
import me.rigamortis.seppuku.api.value.Value;
import me.rigamortis.seppuku.impl.command.*;
import net.minecraft.util.text.TextComponentString;
import java.io.File;
import java.util.ArrayList;
@ -78,8 +79,8 @@ public final class CommandManager {
*/
public void loadExternalCommands() {
try {
//create a directory at "Seppuku 1.12.2/Commands"
final File dir = new File("Seppuku 1.12.2/Commands");
//create a directory at "Seppuku/Commands"
final File dir = new File("Seppuku/Commands");
//if it doesnt exist create it
if (!dir.exists()) {
@ -114,6 +115,11 @@ public final class CommandManager {
if (module.getValueList().size() > 0) {
this.commandList.add(new Command(module.getDisplayName(), module.getAlias(), module.getDesc() != null ? module.getDesc() : "There is no description for this command", module.toUsageTextComponent()) {
@Override
public TextComponentString getTextComponentUsage() {
return module.toUsageTextComponent();
}
@Override
public void exec(String input) {
if (!this.clamp(input, 2, 3)) {

View File

@ -1,6 +1,8 @@
package me.rigamortis.seppuku.impl.management;
import me.rigamortis.seppuku.Seppuku;
import me.rigamortis.seppuku.api.config.Configurable;
import me.rigamortis.seppuku.api.gui.hud.component.DraggableHudComponent;
import me.rigamortis.seppuku.impl.config.*;
import java.io.File;
@ -8,52 +10,70 @@ import java.util.ArrayList;
import java.util.List;
/**
* Author Seth
* 4/18/2019 @ 7:04 AM.
* @author noil
*/
public final class ConfigManager {
private List<Configurable> configurableList = new ArrayList<>();
public static final String CONFIG_PATH = "Seppuku 1.12.2/Config/";
private File configDir;
private File moduleConfigDir;
private File hudComponentConfigDir;
private boolean firstLaunch;
public ConfigManager() {
final File dir = new File(CONFIG_PATH);
private List<Configurable> configurableList = new ArrayList<>();
if (!dir.exists()) {
public static final String CONFIG_PATH = "Seppuku/Config/";
public ConfigManager() {
this.generateDirectories();
}
private void generateDirectories() {
this.configDir = new File(CONFIG_PATH);
if (!this.configDir.exists()) {
this.firstLaunch = true;
dir.mkdirs();
this.configDir.mkdirs();
}
this.configurableList.add(new ToggledConfig());
this.configurableList.add(new BindConfig());
this.configurableList.add(new ColorConfig());
this.configurableList.add(new HiddenConfig());
this.configurableList.add(new FriendConfig());
this.configurableList.add(new XrayConfig());
this.configurableList.add(new ValueConfig());
this.configurableList.add(new MacroConfig());
this.configurableList.add(new WaypointsConfig());
this.configurableList.add(new WorldConfig());
this.configurableList.add(new IgnoreConfig());
this.configurableList.add(new AutoIgnoreConfig());
this.configurableList.add(new HudConfig());
this.moduleConfigDir = new File(CONFIG_PATH + "Modules" + "/");
if (!this.moduleConfigDir.exists()) {
this.moduleConfigDir.mkdirs();
}
this.hudComponentConfigDir = new File(CONFIG_PATH + "HudComponents" + "/");
if (!this.hudComponentConfigDir.exists()) {
this.hudComponentConfigDir.mkdirs();
}
}
public void init() {
Seppuku.INSTANCE.getModuleManager().getModuleList().forEach(module -> {
this.configurableList.add(new ModuleConfig(this.moduleConfigDir, module));
});
Seppuku.INSTANCE.getHudManager().getComponentList().stream().filter(hudComponent -> hudComponent instanceof DraggableHudComponent).forEach(hudComponent -> {
this.configurableList.add(new HudConfig(this.hudComponentConfigDir, (DraggableHudComponent) hudComponent));
});
this.configurableList.add(new FriendConfig(configDir));
this.configurableList.add(new XrayConfig(configDir));
this.configurableList.add(new MacroConfig(configDir));
this.configurableList.add(new WaypointsConfig(configDir));
this.configurableList.add(new WorldConfig(configDir));
this.configurableList.add(new IgnoreConfig(configDir));
this.configurableList.add(new AutoIgnoreConfig(configDir));
if (this.firstLaunch) {
this.saveAll();
} else {
this.loadAll();
}
//Runtime.getRuntime().addShutdownHook(new Thread(() -> Seppuku.INSTANCE.getConfigManager().saveAll()));
}
public void saveAll() {
new Thread(() -> {
for (Configurable cfg : configurableList) {
cfg.save();
cfg.onSave();
}
}).start();
}
@ -61,11 +81,23 @@ public final class ConfigManager {
public void loadAll() {
new Thread(() -> {
for (Configurable cfg : configurableList) {
cfg.load();
cfg.onLoad();
}
}).start();
}
public File getConfigDir() {
return configDir;
}
public File getModuleConfigDir() {
return moduleConfigDir;
}
public File getHudComponentConfigDir() {
return hudComponentConfigDir;
}
public boolean isFirstLaunch() {
return firstLaunch;
}
@ -74,6 +106,10 @@ public final class ConfigManager {
this.firstLaunch = firstLaunch;
}
public void addConfigurable(Configurable configurable) {
this.configurableList.add(configurable);
}
public List<Configurable> getConfigurableList() {
return configurableList;
}

View File

@ -25,6 +25,7 @@ public final class FriendManager {
/**
* When we add friends we grab their UUID from mojangs api
*
* @param name
* @param alias
*/
@ -34,13 +35,13 @@ public final class FriendManager {
Seppuku.INSTANCE.getConfigManager().saveAll();
if(grabUUID) {
try{
if (grabUUID) {
try {
new Thread(() -> {
final String url = "https://api.mojang.com/users/profiles/minecraft/" + name;
try {
final String json = IOUtils.toString(new URL(url));
if(json.isEmpty()) {
if (json.isEmpty()) {
return;
}
@ -56,7 +57,7 @@ public final class FriendManager {
e.printStackTrace();
}
}).start();
}catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
}
}
@ -64,12 +65,13 @@ public final class FriendManager {
/**
* Returns a friend based on the alias
*
* @param alias
* @return
*/
public Friend find(String alias) {
for(Friend friend : this.getFriendList()) {
if(alias.equalsIgnoreCase(friend.getAlias()) || alias.equalsIgnoreCase(friend.getName())) {
for (Friend friend : this.getFriendList()) {
if (alias.equalsIgnoreCase(friend.getAlias()) || alias.equalsIgnoreCase(friend.getName())) {
return friend;
}
}
@ -78,12 +80,13 @@ public final class FriendManager {
/**
* Returns a friend based on the uuid
*
* @param uuid
* @return
*/
public Friend findUUID(String uuid) {
for(Friend friend : this.getFriendList()) {
if(uuid.equals(friend.getUuid())) {
for (Friend friend : this.getFriendList()) {
if (uuid.equals(friend.getUuid())) {
return friend;
}
}
@ -95,13 +98,13 @@ public final class FriendManager {
final Friend byName = this.find(e.getName());
if(byName != null) {
if (byName != null) {
ret = byName;
}
final Friend byUUID = this.findUUID(e.getUniqueID().toString().replace("-", ""));
if(byUUID != null) {
if (byUUID != null) {
ret = byUUID;
}
@ -110,6 +113,7 @@ public final class FriendManager {
/**
* Returns the most similar friend based on the input
*
* @param input
* @return
*/
@ -117,10 +121,10 @@ public final class FriendManager {
Friend friend = null;
double similarity = 0.0f;
for(Friend f : this.getFriendList()) {
for (Friend f : this.getFriendList()) {
final double currentSimilarity = StringUtil.levenshteinDistance(input, friend.getName());
if(currentSimilarity >= similarity) {
if (currentSimilarity >= similarity) {
similarity = currentSimilarity;
friend = f;
}

View File

@ -122,7 +122,7 @@ public final class HudManager {
public void loadExternalHudComponents() {
try {
final File dir = new File("Seppuku 1.12.2/Hud");
final File dir = new File("Seppuku/Hud");
if (!dir.exists()) {
dir.mkdirs();

View File

@ -21,8 +21,8 @@ public final class IgnoredManager {
}
public Ignored find(String name) {
for(Ignored ignored : this.ignoredList) {
if(ignored.getName().equalsIgnoreCase(name)) {
for (Ignored ignored : this.ignoredList) {
if (ignored.getName().equalsIgnoreCase(name)) {
return ignored;
}
}

View File

@ -18,8 +18,8 @@ public final class MacroManager {
}
public Macro find(String name) {
for(Macro macro : this.macroList) {
if(macro.getName().equalsIgnoreCase(name)) {
for (Macro macro : this.macroList) {
if (macro.getName().equalsIgnoreCase(name)) {
return macro;
}
}

View File

@ -158,8 +158,8 @@ public final class ModuleManager {
*/
public void loadExternalModules() {
try {
//create a directory at "Seppuku 1.12.2/Modules"
final File dir = new File("Seppuku 1.12.2/Modules");
//create a directory at "Seppuku/Modules"
final File dir = new File("Seppuku/Modules");
//if it doesnt exist create it
if (!dir.exists()) {

View File

@ -70,8 +70,8 @@ public final class PatchManager {
*/
void loadExternalPatches() {
try {
//create a directory at "Seppuku 1.12.2/Patches"
final File dir = new File("Seppuku 1.12.2/Patches");
//create a directory at "Seppuku/Patches"
final File dir = new File("Seppuku/Patches");
//if it doesnt exist create it
if (!dir.exists()) {
@ -83,11 +83,11 @@ public final class PatchManager {
for (Class clazz : ReflectionUtil.getClassesEx(dir.getPath())) {
if (clazz != null) {
//if we have found a class and the class inherits "ClassPatch"
if(ClassPatch.class.isAssignableFrom(clazz)) {
if (ClassPatch.class.isAssignableFrom(clazz)) {
//create a new instance of the class
final ClassPatch patch = (ClassPatch) clazz.newInstance();
if(patch != null) {
if (patch != null) {
//add the class to our list of patches
this.patchList.add(patch);
System.out.println("[Seppuku] Found external patch " + patch.getMcpName().replace(".", "/"));
@ -95,28 +95,29 @@ public final class PatchManager {
}
}
}
}catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Find a matching patch based on the input class name and our set environment
*
* @param name
* @return
*/
public ClassPatch findClassPatch(String name) {
for(ClassPatch patch : this.patchList) {
if(patch != null) {
for (ClassPatch patch : this.patchList) {
if (patch != null) {
String patchName = patch.getMcpName();
if(this.env == Environment.RELEASE) {
if(patch.getNotchName() != null && patch.getNotchName().length() > 0) {
if (this.env == Environment.RELEASE) {
if (patch.getNotchName() != null && patch.getNotchName().length() > 0) {
patchName = patch.getNotchName();
}
}
if(name.equals(patchName)) {
if (name.equals(patchName)) {
return patch;
}
}

View File

@ -31,7 +31,7 @@ public final class TickRateManager {
int tickCount = 0;
float tickRate = 0.0f;
for(int i = 0; i < this.ticks.length; i++) {
for (int i = 0; i < this.ticks.length; i++) {
final float tick = this.ticks[i];
if (tick > 0.0f) {
@ -49,8 +49,8 @@ public final class TickRateManager {
@Listener
public void receivePacket(EventReceivePacket event) {
if(event.getStage() == EventStageable.EventStage.PRE) {
if(event.getPacket() instanceof SPacketTimeUpdate) {
if (event.getStage() == EventStageable.EventStage.PRE) {
if (event.getPacket() instanceof SPacketTimeUpdate) {
if (this.prevTime != -1) {
this.ticks[this.currentTick % this.ticks.length] = MathHelper.clamp((20.0f / ((float) (System.currentTimeMillis() - this.prevTime) / 1000.0f)), 0.0f, 20.0f);
this.currentTick++;

View File

@ -14,8 +14,8 @@ public final class WaypointManager {
private List<WaypointsModule.WaypointData> waypointDataList = new ArrayList<>();
public WaypointsModule.WaypointData find(String host, String name) {
for(WaypointsModule.WaypointData data : this.waypointDataList) {
if(data.getHost().equalsIgnoreCase(host) && data.getName().equalsIgnoreCase(name)) {
for (WaypointsModule.WaypointData data : this.waypointDataList) {
if (data.getHost().equalsIgnoreCase(host) && data.getName().equalsIgnoreCase(name)) {
return data;
}
}

View File

@ -16,8 +16,8 @@ public final class WorldManager {
}
public WorldData find(String host) {
for(WorldData worldData : this.worldDataList) {
if(worldData.getHost().equalsIgnoreCase(host)) {
for (WorldData worldData : this.worldDataList) {
if (worldData.getHost().equalsIgnoreCase(host)) {
return worldData;
}
}

View File

@ -23,7 +23,7 @@ public final class WaypointsModule extends Module {
public final Value<Float> width = new Value<Float>("Width", new String[]{"Wid"}, "Pixel width of each tracer line.", 0.5f, 0.0f, 5.0f, 0.1f);
public WaypointsModule() {
super("Waypoints", new String[] {"Wp", "Waypoint"}, "Highlights waypoints", "NONE", -1, ModuleType.WORLD);
super("Waypoints", new String[]{"Wp", "Waypoint"}, "Highlights waypoints", "NONE", -1, ModuleType.WORLD);
}
@Listener
@ -32,11 +32,11 @@ public final class WaypointsModule extends Module {
final String host = mc.getCurrentServerData() == null ? "localhost" : mc.getCurrentServerData().serverIP;
for(WaypointData waypointData : Seppuku.INSTANCE.getWaypointManager().getWaypointDataList()) {
if(waypointData != null) {
if(host.equalsIgnoreCase(waypointData.getHost()) && mc.player.dimension == waypointData.dimension) {
for (WaypointData waypointData : Seppuku.INSTANCE.getWaypointManager().getWaypointDataList()) {
if (waypointData != null) {
if (host.equalsIgnoreCase(waypointData.getHost()) && mc.player.dimension == waypointData.dimension) {
final double dist = mc.player.getDistance(waypointData.getX(), waypointData.getY(), waypointData.getZ());
if(dist >= 5.0f) {
if (dist >= 5.0f) {
final GLUProjection.Projection projection = GLUProjection.getInstance().project(waypointData.getX() - mc.getRenderManager().viewerPosX, waypointData.getY() - mc.getRenderManager().viewerPosY, waypointData.getZ() - mc.getRenderManager().viewerPosZ, GLUProjection.ClampMode.NONE, false);
if (projection != null && projection.getType() == GLUProjection.Projection.Type.INSIDE) {