new config
This commit is contained in:
parent
3b010a28af
commit
9d7e4a7a51
4 changed files with 277 additions and 288 deletions
61
.github/README.md
vendored
61
.github/README.md
vendored
|
@ -58,35 +58,36 @@ ANY, WEAPON, ARMOR, ACCESSORIES, CONSUMABLES, BLOCKS, MISC
|
||||||
|
|
||||||
# Example Config:
|
# Example Config:
|
||||||
```cfg
|
```cfg
|
||||||
item1 {
|
{
|
||||||
S:Name=Livid Dagger
|
"APIKey": "",
|
||||||
I:Price=5000000
|
"SendMessageToWebhook": true,
|
||||||
S:Tier=LEGENDARY
|
"Webhook": "",
|
||||||
S:Type=WEAPON
|
"ReconnectDelay": 20,
|
||||||
|
"AuctionHouseDelay": 8,
|
||||||
|
"BedSpamDelay": 100,
|
||||||
|
"OnlySniper": false,
|
||||||
|
"checkMaximumProfitPercentageBeforeBuy": false,
|
||||||
|
"MaximumProfitPercentage": 1000,
|
||||||
|
"MinimumProfitPercentage": 400,
|
||||||
|
"items": [
|
||||||
|
{"Name": " ", "Type": "ANY", "Price": 1000, "Tier": "ANY"},
|
||||||
|
{
|
||||||
|
"Name": "Livid Dagger",
|
||||||
|
"Type": "WEAPON",
|
||||||
|
"Price": 5000000,
|
||||||
|
"Tier": "LEGENDARY"
|
||||||
|
},
|
||||||
|
{"Name": "", "Type": "", "Price": 0, "Tier": ""}
|
||||||
|
],
|
||||||
|
"blacklist": [
|
||||||
|
{"Name": "Rune", "Type": "ANY", "Price": 1, "Tier": "ANY"},
|
||||||
|
{"Name": "", "Type": "", "Price": 0, "Tier": ""},
|
||||||
|
{"Name": "", "Type": "", "Price": 0, "Tier": ""}
|
||||||
|
],
|
||||||
|
"BedSpam": true,
|
||||||
|
"GUI": true,
|
||||||
|
"checkProfitPercentageBeforeBuy": false,
|
||||||
|
"GUI_COLOR": -1,
|
||||||
|
"SniperMode": true
|
||||||
}
|
}
|
||||||
|
|
||||||
blacklist1 {
|
|
||||||
S:Name=Rune
|
|
||||||
I:Price=1
|
|
||||||
S:Tier=ANY
|
|
||||||
S:Type=ANY
|
|
||||||
}
|
|
||||||
|
|
||||||
main {
|
|
||||||
S:APIKey=Paste your api key here
|
|
||||||
B:SendMessageToWebhook=true
|
|
||||||
S:Webhook=Paste your webhook here
|
|
||||||
I:ReconnectDelay=20
|
|
||||||
I:AuctionHouseDelay=9
|
|
||||||
B:BedSpawn=true
|
|
||||||
I:BedSpawnDelay=100
|
|
||||||
B:OnlySniper=false
|
|
||||||
B:checkProfitPercentageBeforeBuy=false
|
|
||||||
B:checkMaxiumProfitPercentageBeforeBuy=false
|
|
||||||
I:MaximumProfitPercentage=1000
|
|
||||||
I:MinimumProfitPercentage=400
|
|
||||||
B:GUI=false
|
|
||||||
I:GUI_COLOR=-65536
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
```
|
|
@ -6,41 +6,38 @@ import cc.polyfrost.oneconfig.config.annotations.*;
|
||||||
import cc.polyfrost.oneconfig.config.core.OneColor;
|
import cc.polyfrost.oneconfig.config.core.OneColor;
|
||||||
import cc.polyfrost.oneconfig.config.data.Mod;
|
import cc.polyfrost.oneconfig.config.data.Mod;
|
||||||
import cc.polyfrost.oneconfig.config.data.ModType;
|
import cc.polyfrost.oneconfig.config.data.ModType;
|
||||||
import me.night0721.lilase.utils.Utils;
|
import me.night0721.lilase.Lilase;
|
||||||
|
|
||||||
public class AHConfig extends Config {
|
public class AHConfig extends Config {
|
||||||
public AHConfig() {
|
public AHConfig() {
|
||||||
super(new Mod("Lilase", ModType.UTIL_QOL), "lilase.json");
|
super(new Mod("Lilase", ModType.UTIL_QOL), "lilase.json");
|
||||||
initialize();
|
initialize();
|
||||||
addListener("SEND_MESSAGE", () -> ConfigUtils.writeBooleanConfig("main", "SendMessageToWebhook", AHConfig.SEND_MESSAGE));
|
addListener("SEND_MESSAGE", () -> Lilase.configHandler.setBoolean("SendMessageToWebhook", SEND_MESSAGE));
|
||||||
addListener("WEBHOOK", () -> ConfigUtils.writeStringConfig("main", "Webhook", AHConfig.WEBHOOK));
|
addListener("WEBHOOK", () -> Lilase.configHandler.setString("Webhook", WEBHOOK));
|
||||||
addListener("RECONNECT_DELAY", () -> ConfigUtils.writeIntConfig("main", "ReconnectDelay", Math.round(AHConfig.RECONNECT_DELAY)));
|
addListener("RECONNECT_DELAY", () -> Lilase.configHandler.setInt("ReconnectDelay", Math.round(RECONNECT_DELAY)));
|
||||||
addListener("AUCTION_HOUSE_DELAY", () -> ConfigUtils.writeIntConfig("main", "AuctionHouseDelay", Math.round(AHConfig.AUCTION_HOUSE_DELAY)));
|
addListener("AUCTION_HOUSE_DELAY", () -> Lilase.configHandler.setInt("AuctionHouseDelay", Math.round(AUCTION_HOUSE_DELAY)));
|
||||||
addListener("BED_SPAM", () -> ConfigUtils.writeBooleanConfig("main", "BedSpam", AHConfig.BED_SPAM));
|
addListener("SNIPER_MODE", () -> Lilase.configHandler.setInt("SniperMode", SNIPER_MODE));
|
||||||
addListener("BED_SPAM_DELAY", () -> ConfigUtils.writeIntConfig("main", "BedSpamDelay", Math.round(AHConfig.BED_SPAM_DELAY)));
|
addListener("BED_SPAM", () -> Lilase.configHandler.setBoolean("BedSpam", BED_SPAM));
|
||||||
addListener("ONLY_SNIPER", () -> ConfigUtils.writeBooleanConfig("main", "OnlySniper", AHConfig.ONLY_SNIPER));
|
addListener("BED_SPAM_DELAY", () -> Lilase.configHandler.setInt("BedSpamDelay", Math.round(BED_SPAM_DELAY)));
|
||||||
addListener("CHECK_PERCENTAGE", () -> ConfigUtils.writeBooleanConfig("main", "checkProfitPercentageBeforeBuy", AHConfig.CHECK_PERCENTAGE));
|
addListener("ONLY_SNIPER", () -> Lilase.configHandler.setBoolean("OnlySniper", ONLY_SNIPER));
|
||||||
addListener("MINIMUM_PROFIT_PERCENTAGE", () -> ConfigUtils.writeIntConfig("main", "MinimumProfitPercentage", Math.round(AHConfig.MINIMUM_PROFIT_PERCENTAGE)));
|
addListener("CHECK_PERCENTAGE", () -> Lilase.configHandler.setBoolean("checkProfitPercentageBeforeBuy", CHECK_PERCENTAGE));
|
||||||
addListener("CHECK_MAXIMAL_PROFIT", () -> ConfigUtils.writeBooleanConfig("main", "checkMaxiumProfitPercentageBeforeBuy", AHConfig.CHECK_MAXIMUM_PROFIT));
|
addListener("MINIMUM_PROFIT_PERCENTAGE", () -> Lilase.configHandler.setInt("MinimumProfitPercentage", Math.round(MINIMUM_PROFIT_PERCENTAGE)));
|
||||||
addListener("MAXIMUM_PROFIT_PERCENTAGE", () -> ConfigUtils.writeIntConfig("main", "MaximumProfitPercentage", AHConfig.MAXIMUM_PROFIT_PERCENTAGE));
|
addListener("CHECK_MAXIMUM_PROFIT", () -> Lilase.configHandler.setBoolean("checkMaxiumProfitPercentageBeforeBuy", CHECK_MAXIMUM_PROFIT));
|
||||||
addListener("GUI", () -> ConfigUtils.writeBooleanConfig("main", "GUI", AHConfig.GUI));
|
addListener("MAXIMUM_PROFIT_PERCENTAGE", () -> Lilase.configHandler.setInt("MaximumProfitPercentage", MAXIMUM_PROFIT_PERCENTAGE));
|
||||||
addListener("GUI_COLOR", () -> ConfigUtils.writeIntConfig("main", "GUI_COLOR", AHConfig.GUI_COLOR.getRGB()));
|
addListener("GUI", () -> Lilase.configHandler.setBoolean("GUI", GUI));
|
||||||
addListener("ITEM_1_NAME", () -> ConfigUtils.writeStringConfig("item1", "Name", AHConfig.ITEM_1_NAME));
|
addListener("GUI_COLOR", () -> Lilase.configHandler.setInt("GUI_COLOR", GUI_COLOR.getRGB()));
|
||||||
addListener("ITEM_1_TYPE", () -> ConfigUtils.writeStringConfig("item1", "Type", AHConfig.ITEM_1_TYPE));
|
|
||||||
addListener("ITEM_1_PRICE", () -> ConfigUtils.writeIntConfig("item1", "Price", Math.round(AHConfig.ITEM_1_PRICE)));
|
|
||||||
addListener("ITEM_1_TIER", () -> ConfigUtils.writeStringConfig("item1", "Tier", AHConfig.ITEM_1_TIER));
|
|
||||||
addDependency("WEBHOOK", "SEND_MESSAGE");
|
addDependency("WEBHOOK", "SEND_MESSAGE");
|
||||||
addDependency("PROFIT_PERCENTAGE", "CHECK_PERCENTAGE");
|
addDependency("MINIMUM_PROFIT_PERCENTAGE", "CHECK_PERCENTAGE");
|
||||||
|
addDependency("MAXIMUM_PROFIT_PERCENTAGE", "CHECK_MAXIMUM_PROFIT");
|
||||||
addDependency("GUI_COLOR", "GUI");
|
addDependency("GUI_COLOR", "GUI");
|
||||||
addDependency("ITEM_1_NAME", "addItem", () -> ConfigUtils.getString("item1", "Name").equals(""));
|
}
|
||||||
addDependency("ITEM_1_TYPE", "addItem", () -> ConfigUtils.getString("item1", "Type").equals(""));
|
|
||||||
addDependency("ITEM_1_PRICE", "addItem", () -> ConfigUtils.getString("item1", "Price").equals(""));
|
|
||||||
addDependency("ITEM_1_TIER", "addItem", () -> ConfigUtils.getString("item1", "Tier").equals(""));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Slider(name = "Time per fetch (seconds)", min = 5, max = 15, step = 1, category = "Auction House", subcategory = "Sniper", description = "Time between each fetch of the auction house, the faster the fetch, the more likely you will snipe the item")
|
@Slider(name = "Time per fetch (seconds)", min = 5, max = 15, step = 1, category = "Auction House", subcategory = "Sniper", description = "Time between each fetch of the auction house, the faster the fetch, the more likely you will snipe the item")
|
||||||
public static int AUCTION_HOUSE_DELAY = 8;
|
public static int AUCTION_HOUSE_DELAY = 8;
|
||||||
|
|
||||||
|
@Dropdown(name = "Sniper Mode", category = "Auction House", subcategory = "Sniper", options = {"API", "Page Flipper[WIP]", "COFL"})
|
||||||
|
public static int SNIPER_MODE = 2;
|
||||||
|
|
||||||
@Switch(name = "Bed Spam & Skip Confirm", category = "Auction House", subcategory = "Sniper", description = "Spam the bed to buy the item just after the grace period ends and skips the confirmation of buying the item")
|
@Switch(name = "Bed Spam & Skip Confirm", category = "Auction House", subcategory = "Sniper", description = "Spam the bed to buy the item just after the grace period ends and skips the confirmation of buying the item")
|
||||||
public static boolean BED_SPAM = true;
|
public static boolean BED_SPAM = true;
|
||||||
|
|
||||||
|
@ -50,11 +47,6 @@ public class AHConfig extends Config {
|
||||||
@Switch(name = "Only Sniper", category = "Auction House", subcategory = "Sniper", description = "Only snipe items, stop auto resell")
|
@Switch(name = "Only Sniper", category = "Auction House", subcategory = "Sniper", description = "Only snipe items, stop auto resell")
|
||||||
public static boolean ONLY_SNIPER = false;
|
public static boolean ONLY_SNIPER = false;
|
||||||
|
|
||||||
@Button(name = "Add Item", text = "Click to add an item to snipe", subcategory = "Items", category = "Auction House")
|
|
||||||
public static void addItem() {
|
|
||||||
Utils.debugLog("[AHConfig] Add Item Button Clicked");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Text(name = "Discord Webhook", placeholder = "URL", category = "Auction House", subcategory = "Webhook", description = "Discord webhook to send messages to")
|
@Text(name = "Discord Webhook", placeholder = "URL", category = "Auction House", subcategory = "Webhook", description = "Discord webhook to send messages to")
|
||||||
public static String WEBHOOK = "";
|
public static String WEBHOOK = "";
|
||||||
|
|
||||||
|
@ -81,16 +73,4 @@ public class AHConfig extends Config {
|
||||||
|
|
||||||
@Color(name = "GUI Color", category = "GUI")
|
@Color(name = "GUI Color", category = "GUI")
|
||||||
public static OneColor GUI_COLOR = new OneColor(0, 49, 83);
|
public static OneColor GUI_COLOR = new OneColor(0, 49, 83);
|
||||||
|
|
||||||
@Text(name = "Item 1 Name", placeholder = "Item Name")
|
|
||||||
public static String ITEM_1_NAME = " ";
|
|
||||||
|
|
||||||
@Text(name = "Item 1 Type", placeholder = "Item Type")
|
|
||||||
public static String ITEM_1_TYPE = "ANY";
|
|
||||||
|
|
||||||
@Number(name = "Item 1 Price", min = 1, max = 1000000000)
|
|
||||||
public static int ITEM_1_PRICE = 1;
|
|
||||||
|
|
||||||
@Text(name = "Item 1 Tier", placeholder = "Item Tier")
|
|
||||||
public static String ITEM_1_TIER = "ANY";
|
|
||||||
}
|
}
|
||||||
|
|
225
src/main/java/me/night0721/lilase/config/ConfigHandler.java
Normal file
225
src/main/java/me/night0721/lilase/config/ConfigHandler.java
Normal file
|
@ -0,0 +1,225 @@
|
||||||
|
package me.night0721.lilase.config;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import me.night0721.lilase.utils.Utils;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
public class ConfigHandler {
|
||||||
|
private final Gson gson = new Gson();
|
||||||
|
String path = "/config/Lilase.json";
|
||||||
|
private JsonObject config;
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
config = readConfigFile();
|
||||||
|
reloadConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reloadConfig() {
|
||||||
|
if (hasNoKey("APIKey")) setString("APIKey", "");
|
||||||
|
if (hasNoKey("SendMessageToWebhook")) setBoolean("SendMessageToWebhook", true);
|
||||||
|
if (hasNoKey("Webhook")) setString("Webhook", "");
|
||||||
|
if (hasNoKey("ReconnectDelay")) setInt("ReconnectDelay", 20);
|
||||||
|
if (hasNoKey("AuctionHouseDelay")) setInt("AuctionHouseDelay", 8);
|
||||||
|
if (hasNoKey("SniperMode")) setBoolean("SniperMode", true);
|
||||||
|
if (hasNoKey("BedSpam")) setBoolean("BedSpam", true);
|
||||||
|
if (hasNoKey("BedSpamDelay")) setInt("BedSpamDelay", 100);
|
||||||
|
if (hasNoKey("OnlySniper")) setBoolean("OnlySniper", false);
|
||||||
|
if (hasNoKey("checkProfitPercentageBeforeBuy")) setBoolean("checkProfitPercentageBeforeBuy", false);
|
||||||
|
if (hasNoKey("checkMaximumProfitPercentageBeforeBuy"))
|
||||||
|
setBoolean("checkMaximumProfitPercentageBeforeBuy", false);
|
||||||
|
if (hasNoKey("MaximumProfitPercentage")) setInt("MaximumProfitPercentage", 1000); //1000%
|
||||||
|
if (hasNoKey("MinimumProfitPercentage")) setInt("MinimumProfitPercentage", 400); //400%
|
||||||
|
if (hasNoKey("GUI")) setBoolean("GUI", true);
|
||||||
|
if (hasNoKey("GUI_COLOR")) setInt("GUI_COLOR", 0x003153);
|
||||||
|
if (hasNoKey("items")) setArray("items", new JsonObject[]{});
|
||||||
|
if (hasNoKey("blacklist")) setArray("blacklist", new JsonObject[]{});
|
||||||
|
for (int i = 1; i <= 3; i++) {
|
||||||
|
if (hasNoItemKey(i, "Name")) setItems(i, "Name", "");
|
||||||
|
if (hasNoItemKey(i, "Type")) setItems(i, "Type", "");
|
||||||
|
if (hasNoItemKey(i, "Price")) setItems(i, "Price", 0);
|
||||||
|
if (hasNoItemKey(i, "Tier")) setItems(i, "Tier", "");
|
||||||
|
}
|
||||||
|
for (int i = 1; i <= 3; i++) {
|
||||||
|
if (hasNoBlacklistKey(i, "Name")) setBlacklists(i, "Name", "");
|
||||||
|
if (hasNoBlacklistKey(i, "Type")) setBlacklists(i, "Type", "");
|
||||||
|
if (hasNoBlacklistKey(i, "Price")) setBlacklists(i, "Price", 0);
|
||||||
|
if (hasNoBlacklistKey(i, "Tier")) setBlacklists(i, "Tier", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkWebhookAndAPI() {
|
||||||
|
if (getString("APIKey").equals("") || getString("Webhook").equals("")) {
|
||||||
|
Utils.sendMessage("API Key or Webhook is not set, please set it in the menu (Press *)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonObject readConfigFile() {
|
||||||
|
try {
|
||||||
|
File configFile = new File(System.getProperty("user.dir") + path);
|
||||||
|
if (configFile.exists()) return new JsonParser().parse(new FileReader(configFile)).getAsJsonObject();
|
||||||
|
else {
|
||||||
|
configFile.createNewFile();
|
||||||
|
BufferedWriter writer = new BufferedWriter(new FileWriter(configFile));
|
||||||
|
writer.write("{}");
|
||||||
|
writer.close();
|
||||||
|
return new JsonObject();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasNoKey(String key) {
|
||||||
|
config = readConfigFile();
|
||||||
|
return config.get(key) == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasNoItemKey(int i, String key) {
|
||||||
|
config = readConfigFile();
|
||||||
|
try {
|
||||||
|
if (config.getAsJsonArray("items").get(i - 1) == null) return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return config.getAsJsonArray("items").get(i - 1).getAsJsonObject().get(key) == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasNoBlacklistKey(int i, String key) {
|
||||||
|
config = readConfigFile();
|
||||||
|
try {
|
||||||
|
if (config.getAsJsonArray("blacklist").get(i - 1) == null) return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return config.getAsJsonArray("blacklist").get(i - 1).getAsJsonObject().get(key) == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getBoolean(String key) {
|
||||||
|
config = readConfigFile();
|
||||||
|
if (config.get(key) != null) return config.get(key).getAsBoolean();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getInt(String key) {
|
||||||
|
config = readConfigFile();
|
||||||
|
if (config.get(key) != null) return config.get(key).getAsInt();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getString(String key) {
|
||||||
|
config = readConfigFile();
|
||||||
|
if (config.get(key) != null) return config.get(key).getAsString();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getString(int item, String key) {
|
||||||
|
config = readConfigFile();
|
||||||
|
try {
|
||||||
|
if (config.getAsJsonArray("items").get(item - 1).getAsJsonObject().get(key) != null)
|
||||||
|
return config.getAsJsonArray("items").get(item - 1).getAsJsonObject().get(key).getAsString();
|
||||||
|
} catch (Exception ignore) {
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getInt(int item, String key) {
|
||||||
|
config = readConfigFile();
|
||||||
|
try {
|
||||||
|
if (config.getAsJsonArray("items").get(item - 1).getAsJsonObject().get(key) != null)
|
||||||
|
return config.getAsJsonArray("items").get(item - 1).getAsJsonObject().get(key).getAsInt();
|
||||||
|
} catch (Exception ignore) {
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBoolean(String key, boolean value) {
|
||||||
|
config = readConfigFile();
|
||||||
|
if (config.get(key) != null) config.remove(key);
|
||||||
|
config.addProperty(key, value);
|
||||||
|
writeJsonToFile(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInt(String key, int value) {
|
||||||
|
config = readConfigFile();
|
||||||
|
if (config.get(key) != null) config.remove(key);
|
||||||
|
config.addProperty(key, value);
|
||||||
|
writeJsonToFile(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setString(String key, String value) {
|
||||||
|
config = readConfigFile();
|
||||||
|
if (config.get(key) != null) config.remove(key);
|
||||||
|
config.addProperty(key, value);
|
||||||
|
writeJsonToFile(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setArray(String key, JsonObject[] value) {
|
||||||
|
config = readConfigFile();
|
||||||
|
if (config.get(key) != null) config.remove(key);
|
||||||
|
JsonArray array = new JsonArray();
|
||||||
|
for (JsonObject object : value) {
|
||||||
|
array.add(object);
|
||||||
|
}
|
||||||
|
config.add(key, array);
|
||||||
|
writeJsonToFile(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItems(int item, String key, Object value) {
|
||||||
|
config = readConfigFile();
|
||||||
|
try {
|
||||||
|
if (config.getAsJsonArray("items").get(item - 1).getAsJsonObject().get(key) != null)
|
||||||
|
config.getAsJsonArray("items").get(item - 1).getAsJsonObject().remove(key);
|
||||||
|
} catch (Exception e) {
|
||||||
|
JsonObject object = new JsonObject();
|
||||||
|
object.addProperty("Name", "");
|
||||||
|
object.addProperty("Type", "");
|
||||||
|
object.addProperty("Price", 0);
|
||||||
|
object.addProperty("Tier", "");
|
||||||
|
config.getAsJsonArray("items").add(object);
|
||||||
|
}
|
||||||
|
if (value instanceof Integer)
|
||||||
|
config.getAsJsonArray("items").get(item - 1).getAsJsonObject().addProperty(key, (Integer) value);
|
||||||
|
else if (value instanceof String)
|
||||||
|
config.getAsJsonArray("items").get(item - 1).getAsJsonObject().addProperty(key, (String) value);
|
||||||
|
else if (value instanceof Boolean)
|
||||||
|
config.getAsJsonArray("items").get(item - 1).getAsJsonObject().addProperty(key, (Boolean) value);
|
||||||
|
writeJsonToFile(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBlacklists(int item, String key, Object value) {
|
||||||
|
config = readConfigFile();
|
||||||
|
try {
|
||||||
|
if (config.getAsJsonArray("blacklist").get(item - 1).getAsJsonObject().get(key) != null)
|
||||||
|
config.getAsJsonArray("blacklist").get(item - 1).getAsJsonObject().remove(key);
|
||||||
|
} catch (Exception e) {
|
||||||
|
JsonObject object = new JsonObject();
|
||||||
|
object.addProperty("Name", "");
|
||||||
|
object.addProperty("Type", "");
|
||||||
|
object.addProperty("Price", 0);
|
||||||
|
object.addProperty("Tier", "");
|
||||||
|
config.getAsJsonArray("blacklist").add(object);
|
||||||
|
}
|
||||||
|
if (value instanceof Integer)
|
||||||
|
config.getAsJsonArray("blacklist").get(item - 1).getAsJsonObject().addProperty(key, (Integer) value);
|
||||||
|
else if (value instanceof String)
|
||||||
|
config.getAsJsonArray("blacklist").get(item - 1).getAsJsonObject().addProperty(key, (String) value);
|
||||||
|
else if (value instanceof Boolean)
|
||||||
|
config.getAsJsonArray("blacklist").get(item - 1).getAsJsonObject().addProperty(key, (Boolean) value);
|
||||||
|
writeJsonToFile(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeJsonToFile(JsonObject jsonObject) {
|
||||||
|
try {
|
||||||
|
BufferedWriter writer = new BufferedWriter(new FileWriter(System.getProperty("user.dir") + path));
|
||||||
|
gson.toJson(jsonObject, writer);
|
||||||
|
writer.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,217 +0,0 @@
|
||||||
package me.night0721.lilase.config;
|
|
||||||
|
|
||||||
import me.night0721.lilase.utils.Utils;
|
|
||||||
import net.minecraftforge.common.config.ConfigCategory;
|
|
||||||
import net.minecraftforge.common.config.Configuration;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class ConfigUtils {
|
|
||||||
public static Configuration config;
|
|
||||||
public final static String file = "config/Lilase.cfg";
|
|
||||||
|
|
||||||
public static void register() {
|
|
||||||
init();
|
|
||||||
reloadConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void checkWebhookAndAPI() {
|
|
||||||
if (getString("main", "APIKey").equals("") || getString("main", "Webhook").equals("")) {
|
|
||||||
Utils.sendMessage("API Key or Webhook is not set, please set it in the menu (Press *)");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void reloadConfig() {
|
|
||||||
if (hasNoKey("main", "APIKey")) writeStringConfig("main", "APIKey", "");
|
|
||||||
if (hasNoKey("main", "SendMessageToWebhook")) writeBooleanConfig("main", "SendMessageToWebhook", true);
|
|
||||||
if (hasNoKey("main", "Webhook")) writeStringConfig("main", "Webhook", "");
|
|
||||||
if (hasNoKey("main", "ReconnectDelay")) writeIntConfig("main", "ReconnectDelay", 20);
|
|
||||||
if (hasNoKey("main", "AuctionHouseDelay")) writeIntConfig("main", "AuctionHouseDelay", 8);
|
|
||||||
if (hasNoKey("main", "BedSpam")) writeBooleanConfig("main", "BedSpam", true);
|
|
||||||
if (hasNoKey("main", "BedSpamDelay")) writeIntConfig("main", "BedSpamDelay", 100);
|
|
||||||
if (hasNoKey("main", "OnlySniper")) writeBooleanConfig("main", "OnlySniper", false);
|
|
||||||
if (hasNoKey("main", "checkProfitPercentageBeforeBuy"))
|
|
||||||
writeBooleanConfig("main", "checkProfitPercentageBeforeBuy", false);
|
|
||||||
if (hasNoKey("main", "checkMaxiumProfitPercentageBeforeBuy"))
|
|
||||||
writeBooleanConfig("main", "checkMaxiumProfitPercentageBeforeBuy", false);
|
|
||||||
if (hasNoKey("main", "MaximumProfitPercentage"))
|
|
||||||
writeIntConfig("main", "MaximumProfitPercentage", 1000); //1000%
|
|
||||||
if (hasNoKey("main", "MinimumProfitPercentage")) writeIntConfig("main", "MinimumProfitPercentage", 400); //400%
|
|
||||||
if (hasNoKey("main", "GUI")) writeBooleanConfig("main", "GUI", true);
|
|
||||||
if (hasNoKey("main", "GUI_COLOR")) writeIntConfig("main", "GUI_COLOR", 0x003153);
|
|
||||||
for (int i = 1; i <= 3; i++) {
|
|
||||||
if (hasNoKey("item" + i, "Name")) writeStringConfig("item" + i, "Name", "");
|
|
||||||
if (hasNoKey("item" + i, "Type")) writeStringConfig("item" + i, "Type", "");
|
|
||||||
if (hasNoKey("item" + i, "Price")) writeIntConfig("item" + i, "Price", 0);
|
|
||||||
if (hasNoKey("item" + i, "Tier")) writeStringConfig("item" + i, "Tier", "");
|
|
||||||
}
|
|
||||||
for (int i = 1; i <= 3; i++) {
|
|
||||||
if (hasNoKey("blacklist" + i, "Name")) writeStringConfig("blacklist" + i, "Name", "");
|
|
||||||
if (hasNoKey("blacklist" + i, "Type")) writeStringConfig("blacklist" + i, "Type", "");
|
|
||||||
if (hasNoKey("blacklist" + i, "Price")) writeIntConfig("blacklist" + i, "Price", 0);
|
|
||||||
if (hasNoKey("blacklist" + i, "Tier")) writeStringConfig("blacklist" + i, "Tier", "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void init() {
|
|
||||||
config = new Configuration(new File(file));
|
|
||||||
try {
|
|
||||||
config.load();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
config.save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static int getInt(String category, String key) {
|
|
||||||
category = category.toLowerCase();
|
|
||||||
config = new Configuration(new File(file));
|
|
||||||
try {
|
|
||||||
config.load();
|
|
||||||
if (config.getCategory(category).containsKey(key)) {
|
|
||||||
return config.get(category, key, 0).getInt();
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
config.save();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getDouble(String category, String key) {
|
|
||||||
category = category.toLowerCase();
|
|
||||||
config = new Configuration(new File(file));
|
|
||||||
try {
|
|
||||||
config.load();
|
|
||||||
if (config.getCategory(category).containsKey(key)) {
|
|
||||||
return config.get(category, key, 0D).getDouble();
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
config.save();
|
|
||||||
}
|
|
||||||
return 0D;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getString(String category, String key) {
|
|
||||||
category = category.toLowerCase();
|
|
||||||
config = new Configuration(new File(file));
|
|
||||||
try {
|
|
||||||
config.load();
|
|
||||||
if (config.getCategory(category).containsKey(key)) {
|
|
||||||
return config.get(category, key, "").getString();
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
config.save();
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean getBoolean(String category, String key) {
|
|
||||||
category = category.toLowerCase();
|
|
||||||
config = new Configuration(new File(file));
|
|
||||||
try {
|
|
||||||
config.load();
|
|
||||||
if (config.getCategory(category).containsKey(key)) {
|
|
||||||
return config.get(category, key, false).getBoolean();
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
config.save();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void writeIntConfig(String category, String key, int value) {
|
|
||||||
category = category.toLowerCase();
|
|
||||||
config = new Configuration(new File(file));
|
|
||||||
try {
|
|
||||||
config.load();
|
|
||||||
// int set = config.get(category, key, value).getInt();
|
|
||||||
config.getCategory(category).get(key).set(value);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
config.save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void writeDoubleConfig(String category, String key, double value) {
|
|
||||||
category = category.toLowerCase();
|
|
||||||
config = new Configuration(new File(file));
|
|
||||||
try {
|
|
||||||
config.load();
|
|
||||||
// double set = config.get(category, key, value).getDouble();
|
|
||||||
config.getCategory(category).get(key).set(value);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
config.save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void writeStringConfig(String category, String key, String value) {
|
|
||||||
category = category.toLowerCase();
|
|
||||||
config = new Configuration(new File(file));
|
|
||||||
try {
|
|
||||||
config.load();
|
|
||||||
// String set = config.get(category, key, value).getString();
|
|
||||||
config.getCategory(category).get(key).set(value);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
config.save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void writeBooleanConfig(String category, String key, boolean value) {
|
|
||||||
category = category.toLowerCase();
|
|
||||||
config = new Configuration(new File(file));
|
|
||||||
try {
|
|
||||||
config.load();
|
|
||||||
// boolean set = config.get(category, key, value).getBoolean();
|
|
||||||
config.getCategory(category).get(key).set(value);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
config.save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean hasNoKey(String category, String key) {
|
|
||||||
category = category.toLowerCase();
|
|
||||||
config = new Configuration(new File(file));
|
|
||||||
try {
|
|
||||||
config.load();
|
|
||||||
if (!config.hasCategory(category)) return true;
|
|
||||||
return !config.getCategory(category).containsKey(key);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
config.save();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void deleteCategory(String category) {
|
|
||||||
category = category.toLowerCase();
|
|
||||||
config = new Configuration(new File(file));
|
|
||||||
try {
|
|
||||||
config.load();
|
|
||||||
if (config.hasCategory(category)) {
|
|
||||||
config.removeCategory(new ConfigCategory(category));
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
config.save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue