use of me.shadorc.shadbot.data.annotation.DataInit in project Shadbot by Shadorc.
the class StatsManager method init.
@DataInit
public static void init() throws IOException {
if (!FILE.exists()) {
try (FileWriter writer = new FileWriter(FILE)) {
writer.write(new JSONObject().toString(Config.JSON_INDENT_FACTOR));
}
}
JSONObject statsObj;
try (InputStream stream = FILE.toURI().toURL().openStream()) {
statsObj = new JSONObject(new JSONTokener(stream));
}
Reflections reflections = new Reflections(StatsManager.class.getPackage().getName(), new MethodAnnotationsScanner());
for (Method initMethod : reflections.getMethodsAnnotatedWith(StatsInit.class)) {
StatsInit annotation = initMethod.getAnnotation(StatsInit.class);
try {
initMethod.invoke(null, statsObj.has(annotation.name()) ? statsObj.getJSONObject(annotation.name()) : new JSONObject());
} catch (Exception err) {
LogUtils.error(err, String.format("An error occurred while initializing statistics %s.", initMethod.getDeclaringClass().getSimpleName()));
}
}
}
use of me.shadorc.shadbot.data.annotation.DataInit in project Shadbot by Shadorc.
the class PremiumManager method init.
@DataInit
public static void init() throws JSONException, IOException {
if (!FILE.exists()) {
try (FileWriter writer = new FileWriter(FILE)) {
JSONObject defaultObj = new JSONObject().put(DONATORS, new JSONObject()).put(UNUSED_RELICS, new JSONArray());
writer.write(defaultObj.toString(Config.JSON_INDENT_FACTOR));
}
}
try (InputStream stream = FILE.toURI().toURL().openStream()) {
premiumObj = new JSONObject(new JSONTokener(stream));
}
premiumObj.getJSONArray(UNUSED_RELICS).forEach(relicObj -> UNUSED_RELICS_LIST.add(new Relic((JSONObject) relicObj)));
}
use of me.shadorc.shadbot.data.annotation.DataInit in project Shadbot by Shadorc.
the class LottoManager method init.
@DataInit
public static void init() throws JSONException, IOException {
if (!FILE.exists()) {
try (FileWriter writer = new FileWriter(FILE)) {
JSONObject defaultObj = new JSONObject().put(USERS, new JSONArray()).put(POOL, 0);
writer.write(defaultObj.toString(Config.JSON_INDENT_FACTOR));
}
}
try (InputStream stream = FILE.toURI().toURL().openStream()) {
dataObj = new JSONObject(new JSONTokener(stream));
}
}
Aggregations