use of me.shadorc.shadbot.data.stats.annotation.StatsJSON in project Shadbot by Shadorc.
the class StatsManager method save.
@DataSave(filePath = FILE_NAME, initialDelay = 10, period = 10, unit = TimeUnit.MINUTES)
public static void save() throws JSONException, IOException {
JSONObject mainObj = new JSONObject();
Reflections reflections = new Reflections(StatsManager.class.getPackage().getName(), new MethodAnnotationsScanner());
for (Method jsonMethod : reflections.getMethodsAnnotatedWith(StatsJSON.class)) {
StatsJSON annotation = jsonMethod.getAnnotation(StatsJSON.class);
try {
mainObj.put(annotation.name(), jsonMethod.invoke(null));
} catch (Exception err) {
LogUtils.error(err, String.format("An error occurred while saving statistics %s.", jsonMethod.getDeclaringClass().getSimpleName()));
}
}
try (FileWriter writer = new FileWriter(FILE)) {
writer.write(mainObj.toString(Config.JSON_INDENT_FACTOR));
}
}
use of me.shadorc.shadbot.data.stats.annotation.StatsJSON in project Shadbot by Shadorc.
the class CommandStatsManager method toJSON.
@StatsJSON(name = NAME)
public static JSONObject toJSON() {
JSONObject mainObj = new JSONObject();
for (CommandEnum cmdEnum : COMMANDS_STATS_MAP.keySet()) {
JSONObject statsObj = new JSONObject();
for (String key : COMMANDS_STATS_MAP.get(cmdEnum).keySet()) {
statsObj.put(key, COMMANDS_STATS_MAP.get(cmdEnum).get(key).get());
}
mainObj.put(cmdEnum.toString(), statsObj);
}
return mainObj;
}
use of me.shadorc.shadbot.data.stats.annotation.StatsJSON in project Shadbot by Shadorc.
the class MoneyStatsManager method toJSON.
@StatsJSON(name = NAME)
public static JSONObject toJSON() {
JSONObject mainObj = new JSONObject();
for (MoneyEnum moneyEnum : MONEY_STATS_MAP.keySet()) {
JSONObject statsObj = new JSONObject();
for (String key : MONEY_STATS_MAP.get(moneyEnum).keySet()) {
statsObj.put(key, MONEY_STATS_MAP.get(moneyEnum).get(key).get());
}
mainObj.put(moneyEnum.toString(), statsObj);
}
return mainObj;
}
Aggregations