From b84ecf8545afc1986ab367b1ae47bddaf104b68f Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 30 Jun 2018 16:28:32 +0200 Subject: [PATCH] Added conversion in DB --- .../limitedcreative/blockstate/BlockState.java | 12 +++++++++--- .../blockstate/CreativeControlImportThread.java | 2 +- .../limitedcreative/blockstate/DBQueries.java | 6 +++--- .../blockstate/worldedit/EditSessionExtent.java | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockState.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockState.java index b3242da..8a5afa3 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockState.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockState.java @@ -82,8 +82,14 @@ public class BlockState { } //TODO Rename - public void setPlayerName(String s) { - uuid = UUID.fromString(s); + @SuppressWarnings("deprecation") + public void setPlayerNameOrUUID(String s) { + if(s==null) + uuid=null; + else if(!s.matches("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$")) + uuid = Bukkit.getOfflinePlayer(s).getUniqueId(); //If it's a name, get UUID + else + uuid = UUID.fromString(s); } public OfflinePlayer getPlayer() { @@ -115,7 +121,7 @@ public class BlockState { public void setSource(Source source) { if (source != Source.PLAYER && source != Source.EDIT && source != Source.COMMAND) - setPlayerName(null); + setPlayerNameOrUUID(null); this.source = source; } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/CreativeControlImportThread.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/CreativeControlImportThread.java index 2a5d519..fea3e5d 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/CreativeControlImportThread.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/CreativeControlImportThread.java @@ -131,7 +131,7 @@ public class CreativeControlImportThread extends DatabaseMigrationThread { bs.setLocation(new Location(c.getWorld(), rs.getInt("x"), rs.getInt("y"), rs.getInt("z"))); bs.setDate(new Date(rs.getLong("time"))); bs.setGameMode(GameMode.CREATIVE); - bs.setPlayerName(rs.getString("player")); + bs.setPlayerNameOrUUID(rs.getString("player")); bs.setSource(Source.PLAYER); return bs; } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/DBQueries.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/DBQueries.java index ba5d85b..9812363 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/DBQueries.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/DBQueries.java @@ -42,7 +42,7 @@ public class DBQueries { bs.setLocation(loc); bs.setDate(rs.getTimestamp("cdate")); bs.setGameMode(getGameMode(rs)); - bs.setPlayerName(rs.getString("player")); + bs.setPlayerNameOrUUID(rs.getString("player")); bs.setSource(getSource(rs)); rs.close(); return bs; @@ -72,7 +72,7 @@ public class DBQueries { bs.setLocation(new Location(c.getWorld(), rs.getInt("x"), rs.getInt("y"), rs.getInt("z"))); bs.setDate(rs.getTimestamp("cdate")); bs.setGameMode(getGameMode(rs)); - bs.setPlayerName(rs.getString("player")); + bs.setPlayerNameOrUUID(rs.getString("player")); bs.setSource(getSource(rs)); blocks.add(bs); } @@ -100,7 +100,7 @@ public class DBQueries { bs.setLocation(new Location(c.getWorld(), rs.getInt("x"), rs.getInt("y"), rs.getInt("z"))); bs.setDate(rs.getTimestamp("cdate")); bs.setGameMode(getGameMode(rs)); - bs.setPlayerName(rs.getString("player")); + bs.setPlayerNameOrUUID(rs.getString("player")); bs.setSource(getSource(rs)); return bs; } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/EditSessionExtent.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/EditSessionExtent.java index 8ba5e1d..57ac3d2 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/EditSessionExtent.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/EditSessionExtent.java @@ -46,7 +46,7 @@ public class EditSessionExtent extends AbstractLoggingExtent { s.setLocation(loc); } s.setGameMode(null); - s.setPlayerName(player.getUniqueId().toString()); + s.setPlayerNameOrUUID(player.getUniqueId().toString()); s.setDate(new Date()); s.setSource(Source.EDIT); if (mod.isDebug())