Fix NPE parsing Mojang uuid

This commit is contained in:
games647
2017-10-03 14:19:02 +02:00
parent 105e00b7e8
commit 28a20a46fa
3 changed files with 12 additions and 4 deletions

View File

@ -116,7 +116,7 @@ public class AuthStorage {
public PlayerProfile loadProfile(UUID uuid) {
try (Connection con = dataSource.getConnection();
PreparedStatement loadStmt = con.prepareStatement(LOAD_BY_UUID)) {
loadStmt.setString(1, uuid.toString().replace("-", ""));
loadStmt.setString(1, CommonUtil.toMojangId(uuid));
try (ResultSet resultSet = loadStmt.executeQuery()) {
if (resultSet.next()) {
@ -145,7 +145,7 @@ public class AuthStorage {
if (uuid == null) {
saveStmt.setString(1, null);
} else {
saveStmt.setString(1, uuid.toString().replace("-", ""));
saveStmt.setString(1, CommonUtil.toMojangId(uuid));
}
saveStmt.setString(2, playerProfile.getPlayerName());
@ -165,7 +165,7 @@ public class AuthStorage {
if (uuid == null) {
saveStmt.setString(1, null);
} else {
saveStmt.setString(1, uuid.toString().replace("-", ""));
saveStmt.setString(1, CommonUtil.toMojangId(uuid));
}
saveStmt.setString(2, playerProfile.getPlayerName());

View File

@ -34,6 +34,10 @@ public class CommonUtil {
}
public static UUID parseId(String withoutDashes) {
if (withoutDashes == null) {
return null;
}
return UUID.fromString(withoutDashes.substring(0, 8)
+ '-' + withoutDashes.substring(8, 12)
+ '-' + withoutDashes.substring(12, 16)
@ -41,6 +45,10 @@ public class CommonUtil {
+ '-' + withoutDashes.substring(20, 32));
}
public static String toMojangId(UUID uuid) {
return uuid.toString().replace("-", "");
}
public static String translateColorCodes(String rawMessage) {
char[] chars = rawMessage.toCharArray();
for (int i = 0; i < chars.length - 1; i++) {

View File

@ -11,7 +11,7 @@ import java.util.UUID;
public class UUIDTypeAdapter extends TypeAdapter<UUID> {
public void write(JsonWriter out, UUID value) throws IOException {
out.value(value.toString().replace("-", ""));
out.value(CommonUtil.toMojangId(value));
}
public UUID read(JsonReader in) throws IOException {