3
0
Mirror von https://github.com/TheSilentPro/HeadDB.git synchronisiert 2024-12-27 11:20:05 +01:00
Dieser Commit ist enthalten in:
Silent 2021-11-22 22:24:30 +01:00
Ursprung 7b08613c7a
Commit 832672b74f
3 geänderte Dateien mit 24 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -6,7 +6,7 @@
<groupId>tsp.headdb</groupId>
<artifactId>HeadDB</artifactId>
<version>2.4.3</version>
<version>2.4.4</version>
<packaging>jar</packaging>
<name>HeadDB</name>

Datei anzeigen

@ -8,6 +8,7 @@ import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import tsp.headdb.api.Head;
import tsp.headdb.util.Log;
import tsp.headdb.util.Utils;
import java.io.BufferedReader;
import java.io.IOException;
@ -166,8 +167,13 @@ public class HeadDatabase {
JSONArray array = (JSONArray) parser.parse(response.toString());
for (Object o : array) {
JSONObject obj = (JSONObject) o;
UUID uuid = UUID.fromString(obj.get("uuid").toString());
if (uuid.toString().length() != 36) {
String rawUUID = obj.get("uuid").toString();
UUID uuid;
if (Utils.validateUniqueId(rawUUID)) {
uuid = UUID.fromString(rawUUID);
} else {
Log.debug("UUID " + rawUUID + " is invalid. Using random one for head id: " + id);
uuid = UUID.randomUUID();
}

Datei anzeigen

@ -3,8 +3,23 @@ package tsp.headdb.util;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import java.util.regex.Pattern;
public class Utils {
public static final Pattern UUID_PATTERN = Pattern.compile("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}");
/**
* Validate a UUID (version 4)
*
* @param uuid UUID to be validated
* @return Returns true if the string is a valid UUID
*/
public static boolean validateUniqueId(String uuid) {
return UUID_PATTERN.matcher(uuid).matches();
}
public static void sendMessage(CommandSender sender, String message) {
sender.sendMessage(colorize(message));
}