Archived
0

Made check generate a default config + fixed thread exception

This commit is contained in:
David Panić
2018-12-16 03:18:34 +01:00
parent 5635733922
commit 08f41a9b08

View File

@@ -8,11 +8,15 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.Scanner;
import java.util.concurrent.ExecutionException;
import com.redstoner.exceptions.NonSaveableConfigException;
import com.redstoner.misc.mysql.Config;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.event.Listener;
import org.bukkit.scheduler.BukkitScheduler;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
@@ -43,20 +47,36 @@ public class Check implements Module, Listener {
@Override
public boolean onEnable() {
Map<Serializable, Serializable> config = JSONManager.getConfiguration("check.json");
Config config;
try {
config = Config.getConfig("check.json");
} catch (IOException | org.json.simple.parser.ParseException e1) {
e1.printStackTrace();
return false;
}
if (config == null || !config.containsKey("database") || !config.containsKey("table")) {
getLogger().warn("Could not load the Check config file, ip info for offline users and website data is unavaliable!");
noTableReason = "Could not load the config file";
}
else {
getLogger().error("Could not load the Check config file, disabling, trying to write defaults!");
config.put("database", "redstoner");
config.put("table", "users");
try {
MysqlDatabase database = MysqlHandler.INSTANCE.getDatabase((String) config.get("database") + "?autoReconnect=true");
table = database.getTable((String) config.get("table"));
} catch (NullPointerException e) {
getLogger().warn("Could not use the Check config file, ip info for offline users and website data is unavaliable!");
noTableReason = "Could not use the config file";
}
config.save();
} catch (IOException | NonSaveableConfigException e) {}
noTableReason = "Could not load the config file";
return false;
}
try {
MysqlDatabase database = MysqlHandler.INSTANCE.getDatabase(config.get("database") + "?autoReconnect=true");
table = database.getTable(config.get("table"));
} catch (NullPointerException e) {
getLogger().warn("Could not use the Check config file, ip info for offline users and website data is unavaliable!");
noTableReason = "Could not use the config file";
}
return true;
@@ -75,7 +95,16 @@ public class Check implements Module, Listener {
sendData(sender, oPlayer);
if (ModuleLoader.exists("Tag")) Bukkit.dispatchCommand(sender, "tag check " + player);
if (ModuleLoader.exists("Tag")) {
try {
Bukkit.getScheduler().callSyncMethod(ModuleLoader.getPlugin(), () -> Bukkit.dispatchCommand(sender, "tag check " + player)).get();
} catch (ExecutionException | InterruptedException e) {
Message msg = new Message(sender, null);
msg.appendText("&4Running /tag check failed! Please inform a dev about this incident!");
e.printStackTrace();
}
}
}
public String read(URL url) {