use of org.bleachhack.setting.module.ModuleSetting in project BleachHack by BleachDrinker420.
the class BleachFileHelper method saveModules.
public static void saveModules() {
JsonObject json = new JsonObject();
for (Module mod : ModuleManager.getModules()) {
JsonObject modjson = new JsonObject();
if (mod.isEnabled() != mod.isDefaultEnabled() && !mod.getName().equals("ClickGui") && !mod.getName().equals("Freecam")) {
modjson.add("toggled", new JsonPrimitive(mod.isEnabled()));
}
JsonObject setjson = new JsonObject();
Map<String, ModuleSetting<?>> settingMap = getSettingMap(mod.getSettings());
for (Entry<String, ModuleSetting<?>> s : settingMap.entrySet()) {
if (!s.getValue().isDefault())
setjson.add(s.getKey(), s.getValue().write());
}
if (setjson.size() != 0)
modjson.add("settings", setjson);
if (modjson.size() != 0)
json.add(mod.getName(), modjson);
}
BleachJsonHelper.setJsonFile("modules.json", json);
}
use of org.bleachhack.setting.module.ModuleSetting in project BleachHack by BleachDrinker420.
the class CmdSetting method onCommand.
@Override
@SuppressWarnings("unchecked")
public void onCommand(String alias, String[] args) throws Exception {
if (args.length < 2) {
throw new CmdSyntaxException();
}
Module module = ModuleManager.getModule(args[0]);
ModuleSetting<?> setting = module.getSettings().stream().filter(s -> s.getName().equals(args[1])).findFirst().get();
if (setting == null)
throw new CmdSyntaxException("Invalid setting \"" + args[1] + "\"");
Object value = setting.getValue();
if (value instanceof Double) {
((ModuleSetting<Double>) setting).setValue(Double.parseDouble(args[2]));
} else if (value instanceof Integer) {
((ModuleSetting<Integer>) setting).setValue(Integer.parseInt(args[2]));
} else if (value instanceof String) {
((ModuleSetting<String>) setting).setValue(args[2]);
} else {
BleachLogger.error("Setting \"" + setting.getClass().getSimpleName() + "\" is not supported!");
return;
}
BleachLogger.info("Set " + args[1] + " in " + module.getName() + " to " + args[2]);
}
Aggregations