Some bug fixes
This commit is contained in:
@@ -126,7 +126,7 @@ public class Core {
|
||||
Player p = (Player) P;
|
||||
if (!Core.cachedPlayerLanguage.containsKey(p)) {
|
||||
ResultSet rs = Core.getMySql().querySelect("SELECT lang FROM players WHERE uuid = '" + p.getUniqueId().toString() + "'");
|
||||
if (!rs.next()) {
|
||||
if (rs == null || !rs.next()) {
|
||||
//This is a weird bug
|
||||
Core.cachedPlayerLanguage.put(p, "de");
|
||||
return "de";
|
||||
|
||||
@@ -4,12 +4,14 @@ import java.sql.ResultSet;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Errors {
|
||||
|
||||
/**
|
||||
* Reports an exception to the database
|
||||
*
|
||||
* @param exc A Throwable to get the error data from
|
||||
* @param info Some additional info
|
||||
*/
|
||||
@@ -19,34 +21,37 @@ public class Errors {
|
||||
exc.printStackTrace();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String message = exc.getLocalizedMessage();
|
||||
String name = exc.getClass().toString();
|
||||
String server = Core.getMainClass() == null ? "~not available~" : Core.getMainClass().getConfig().getString("server-name");
|
||||
String errorSql = "INSERT INTO coreErrors (server, exception, msg, info, timestamp) VALUES('" + server + "', '" + name + "', '" + Core.getMySql().escapeString(message) + "', '" + info + "', '" + System.currentTimeMillis() / 1000 + "')";
|
||||
Core.getMySql().queryUpdate(errorSql);
|
||||
ResultSet rs = Core.getMySql().querySelect("SELECT id FROM coreErrors ORDER BY id DESC LIMIT 1");
|
||||
rs.first();
|
||||
int id = rs.getInt("id");
|
||||
String elemSql = "INSERT INTO coreErrorStack(errorId, className, fileName, methodName, lineNumber, nativeMethod) VALUES";
|
||||
boolean first = true;
|
||||
for(StackTraceElement elem : exc.getStackTrace()) {
|
||||
if (!first) {
|
||||
elemSql += ",";
|
||||
} else {
|
||||
first = false;
|
||||
Bukkit.getScheduler().runTaskAsynchronously(Core.getMainClass(), () -> {
|
||||
try {
|
||||
String message = exc.getLocalizedMessage();
|
||||
String name = exc.getClass().toString();
|
||||
String server = Core.getMainClass() == null ? "~not available~" : Core.getMainClass().getConfig().getString("server-name");
|
||||
String errorSql = "INSERT INTO coreErrors (server, exception, msg, info, timestamp) VALUES('" + server + "', '" + name + "', '" + Core.getMySql().escapeString(message) + "', '" + info + "', '" + System.currentTimeMillis() / 1000 + "')";
|
||||
Core.getMySql().queryUpdate(errorSql);
|
||||
ResultSet rs = Core.getMySql().querySelect("SELECT id FROM coreErrors ORDER BY id DESC LIMIT 1");
|
||||
rs.first();
|
||||
int id = rs.getInt("id");
|
||||
String elemSql = "INSERT INTO coreErrorStack(errorId, className, fileName, methodName, lineNumber, nativeMethod) VALUES";
|
||||
boolean first = true;
|
||||
for (StackTraceElement elem : exc.getStackTrace()) {
|
||||
if (!first) {
|
||||
elemSql += ",";
|
||||
} else {
|
||||
first = false;
|
||||
}
|
||||
elemSql += "('" + id + "', '" + elem.getClassName() + "', '" + elem.getFileName() + "', '" + elem.getMethodName() + "', '" + elem.getLineNumber() + "', " + elem.isNativeMethod() + ")";
|
||||
}
|
||||
elemSql += "('" + id + "', '" + elem.getClassName() + "', '" + elem.getFileName() + "', '" + elem.getMethodName() + "', '" + elem.getLineNumber() + "', " + elem.isNativeMethod() + ")";
|
||||
Core.getMySql().queryUpdate(elemSql);
|
||||
} catch (Throwable ex) {
|
||||
System.err.println("FATAL ERROR: Error handler generated an exception!! (" + ex.getLocalizedMessage() + ")");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
Core.getMySql().queryUpdate(elemSql);
|
||||
} catch (Throwable ex) {
|
||||
System.err.println("FATAL ERROR: Error handler generated an exception!! (" + ex.getLocalizedMessage() + ")");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports an exception to the database
|
||||
*
|
||||
* @param exc A Throwable to get the error from
|
||||
*/
|
||||
public static void reportException(Throwable exc) {
|
||||
@@ -55,14 +60,16 @@ public class Errors {
|
||||
|
||||
/**
|
||||
* Method to report a bug
|
||||
*
|
||||
* @param P The reporter
|
||||
* @param msg A message from the reporter
|
||||
* @param data An array of error entries generated by {@link make(String, Object)}
|
||||
* @param data An array of error entries generated by
|
||||
* {@link make(String, Object)}
|
||||
*/
|
||||
public static void bugReport(Player P, String msg, Entry<String, Object>... data) {
|
||||
UUID uuid = P.getUniqueId();
|
||||
String dataText = "";
|
||||
for(Entry<String, Object> date : data) {
|
||||
for (Entry<String, Object> date : data) {
|
||||
dataText += date.getKey() + ":" + date.getValue().toString() + ";";
|
||||
}
|
||||
Core.getMySql().queryUpdate("INSERT INTO serverBugs(player, msg, data, timestamp) VALUES ((SELECT id FROM players WHERE uuid = '" + uuid.toString() + "'), '" + Core.getMySql().escapeString(msg) + "', '" + dataText + "', '" + System.currentTimeMillis() / 1000 + "')");
|
||||
@@ -70,6 +77,7 @@ public class Errors {
|
||||
|
||||
/**
|
||||
* Generates an error entry
|
||||
*
|
||||
* @param key The key for this object
|
||||
* @param value Any object to use as value
|
||||
* @return The error entry to give to
|
||||
|
||||
@@ -132,7 +132,7 @@ public class Setup {
|
||||
Data.sittingPlayer.put(p, a);
|
||||
}
|
||||
}, 600, 600);
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(Core.getMainClass(), AnuraCore.signs::updateServerSigns, 20 * 5, 20 * 5);
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(Core.getMainClass(), AnuraCore.signs::updateServerSigns, 20 * 5, 20 * 5);
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(Core.getMainClass(), new VillagerTask(), 20, 20);
|
||||
} catch (Throwable e) {
|
||||
Errors.reportException(e);
|
||||
|
||||
@@ -24,8 +24,7 @@ public class Signs implements PluginMessageListener {
|
||||
return;
|
||||
}
|
||||
ResultSet rs = Core.getMySql().querySelect("SELECT DISTINCT value FROM coreWarpSigns WHERE type = 'server' AND server = '" + Core.getMainClass().getConfig().getString("server-name") + "'");
|
||||
rs.last();
|
||||
if (rs.getRow() == 0) {
|
||||
if (rs == null || !rs.first()) {
|
||||
return;
|
||||
}
|
||||
rs.beforeFirst();
|
||||
@@ -105,62 +104,63 @@ public class Signs implements PluginMessageListener {
|
||||
|
||||
DataInputStream in = new DataInputStream(new ByteArrayInputStream(message));
|
||||
String subchannel = in.readUTF();
|
||||
if (subchannel.equals("PlayerCount")) {
|
||||
String server = in.readUTF();
|
||||
int playercount = in.readInt();
|
||||
String sqlQ = "SELECT X,Y,Z,world FROM coreWarpSigns WHERE server = '" + Core.getMainClass().getConfig().getString("server-name") + "' AND type = 'server' AND value = '" + server + "'";
|
||||
ResultSet rs = Core.getMySql().querySelect(sqlQ);
|
||||
rs.last();
|
||||
if (rs.getRow() == 0) {
|
||||
return;
|
||||
}
|
||||
rs.beforeFirst();
|
||||
while (rs.next()) {
|
||||
Boolean remove = false;
|
||||
World w = Bukkit.getWorld(rs.getString("world"));
|
||||
BlockState bs = null;
|
||||
if (w == null) {
|
||||
remove = true;
|
||||
} else {
|
||||
Block b = w.getBlockAt(rs.getInt("X"), rs.getInt("Y"), rs.getInt("Z"));
|
||||
if (b == null || !(b.getState() instanceof Sign)) {
|
||||
switch (subchannel) {
|
||||
case "PlayerCount":
|
||||
String server = in.readUTF();
|
||||
int playercount = in.readInt();
|
||||
String sqlQ = "SELECT X,Y,Z,world FROM coreWarpSigns WHERE server = '" + Core.getMainClass().getConfig().getString("server-name") + "' AND type = 'server' AND value = '" + server + "'";
|
||||
ResultSet rs = Core.getMySql().querySelect(sqlQ);
|
||||
rs.last();
|
||||
if (rs.getRow() == 0) {
|
||||
return;
|
||||
} rs.beforeFirst();
|
||||
while (rs.next()) {
|
||||
Boolean remove = false;
|
||||
World w = Bukkit.getWorld(rs.getString("world"));
|
||||
BlockState bs = null;
|
||||
if (w == null) {
|
||||
remove = true;
|
||||
} else {
|
||||
bs = b.getState();
|
||||
Block b = w.getBlockAt(rs.getInt("X"), rs.getInt("Y"), rs.getInt("Z"));
|
||||
if (b == null || !(b.getState() instanceof Sign)) {
|
||||
remove = true;
|
||||
} else {
|
||||
bs = b.getState();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (remove) {
|
||||
String anotherSQL = "DELETE FROM coreWarpSigns WHERE server = '" + Core.getMainClass().getConfig().getString("server-name") + "' AND type = 'server' AND value = '" + server + "'";
|
||||
Core.getMySql().queryUpdate(anotherSQL);
|
||||
continue;
|
||||
}
|
||||
if (bs == null) {
|
||||
continue;
|
||||
}
|
||||
if (bs instanceof Sign) {
|
||||
Sign s = (Sign) bs;
|
||||
if (s.getLine(3).equalsIgnoreCase(ChatColor.RED + "Offline")) {
|
||||
s.setLine(1, ChatColor.RED + "--" + ChatColor.DARK_GRAY + "/" + ChatColor.RED + "--");
|
||||
if (remove) {
|
||||
String anotherSQL = "DELETE FROM coreWarpSigns WHERE server = '" + Core.getMainClass().getConfig().getString("server-name") + "' AND type = 'server' AND value = '" + server + "'";
|
||||
Core.getMySql().queryUpdate(anotherSQL);
|
||||
continue;
|
||||
}
|
||||
String maxplayers = s.getLine(1).substring(s.getLine(1).length() - 2);
|
||||
Boolean hasPlace = true;
|
||||
if (maxplayers.equals("--")) {
|
||||
hasPlace = true;
|
||||
} else if (Integer.parseInt(maxplayers) == playercount) {
|
||||
hasPlace = false;
|
||||
if (bs == null) {
|
||||
continue;
|
||||
}
|
||||
if (hasPlace) {
|
||||
s.setLine(1, ChatColor.GREEN + String.valueOf(playercount) + ChatColor.DARK_GRAY + "/" + ChatColor.GREEN + maxplayers);
|
||||
} else {
|
||||
s.setLine(1, ChatColor.RED + String.valueOf(playercount) + ChatColor.DARK_GRAY + "/" + ChatColor.GREEN + maxplayers);
|
||||
if (bs instanceof Sign) {
|
||||
Sign s = (Sign) bs;
|
||||
if (s.getLine(3).equalsIgnoreCase(ChatColor.RED + "Offline")) {
|
||||
s.setLine(1, ChatColor.RED + "--" + ChatColor.DARK_GRAY + "/" + ChatColor.RED + "--");
|
||||
continue;
|
||||
}
|
||||
String maxplayers = s.getLine(1).substring(s.getLine(1).length() - 2);
|
||||
Boolean hasPlace = true;
|
||||
if (maxplayers.equals("--")) {
|
||||
hasPlace = true;
|
||||
} else if (Integer.parseInt(maxplayers) == playercount) {
|
||||
hasPlace = false;
|
||||
}
|
||||
if (hasPlace) {
|
||||
s.setLine(1, ChatColor.GREEN + String.valueOf(playercount) + ChatColor.DARK_GRAY + "/" + ChatColor.GREEN + maxplayers);
|
||||
} else {
|
||||
s.setLine(1, ChatColor.RED + String.valueOf(playercount) + ChatColor.DARK_GRAY + "/" + ChatColor.GREEN + maxplayers);
|
||||
}
|
||||
s.update();
|
||||
}
|
||||
s.update();
|
||||
}
|
||||
}
|
||||
} else if (subchannel.equals("updatePermissions")) {
|
||||
AnuraCore.perms.reload();
|
||||
AnuraCore.perms.updateAllPlayers();
|
||||
} break;
|
||||
case "updatePermissions":
|
||||
AnuraCore.perms.reload();
|
||||
AnuraCore.perms.updateAllPlayers();
|
||||
break;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Errors.reportException(e);
|
||||
|
||||
@@ -180,7 +180,12 @@ public class TeamCommands implements CommandExecutor {
|
||||
if (args.length != 1) {
|
||||
return false;
|
||||
}
|
||||
if (Float.parseFloat(args[0]) >= 10 || Float.parseFloat(args[0]) < 0) {
|
||||
try {
|
||||
if (Float.parseFloat(args[0]) >= 10 || Float.parseFloat(args[0]) < 0) {
|
||||
Core.statusMsg(P, "flyspeed_wrong_number", false);
|
||||
return true;
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
Core.statusMsg(P, "flyspeed_wrong_number", false);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user