From 8c1240cc24fd9e1c65e1351b550f524714714fb9 Mon Sep 17 00:00:00 2001 From: pickernickel Date: Sun, 22 May 2016 02:48:08 -0500 Subject: [PATCH] Use UUID instead of player name. --- .../blockstate/BlockState.java | 23 ++++++++++++------- .../limitedcreative/blockstate/DBQueries.java | 4 ++-- .../worldedit/EditSessionExtent.java | 2 +- .../inventories/store/InvYamlStorage.java | 4 ++-- 4 files changed, 20 insertions(+), 13 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 a44fc58..b3242da 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockState.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockState.java @@ -1,6 +1,7 @@ package de.jaschastarke.minecraft.limitedcreative.blockstate; import java.util.Date; +import java.util.UUID; import javax.persistence.Column; //import javax.persistence.EmbeddedId; @@ -37,7 +38,7 @@ public class BlockState { private GameMode gameMode; @Column(name = "player") - private String playerName; + private UUID uuid; @NotNull @Column(name = "cdate") @@ -51,7 +52,7 @@ public class BlockState { public BlockState(BlockState copy) { this.location = copy.location; this.gameMode = copy.gameMode; - this.playerName = copy.playerName; + this.uuid = copy.uuid; this.date = copy.date; this.source = copy.source; } @@ -72,24 +73,29 @@ public class BlockState { this.gameMode = gm; } - public String getPlayerName() { - return playerName; + public UUID getPlayerUUID() { + return uuid; } + public String getPlayerName() { + return Bukkit.getOfflinePlayer(uuid).getName(); + } + + //TODO Rename public void setPlayerName(String s) { - playerName = s; + uuid = UUID.fromString(s); } public OfflinePlayer getPlayer() { - OfflinePlayer p = Bukkit.getPlayerExact(playerName); + OfflinePlayer p = Bukkit.getPlayer(uuid); if (p == null) - p = Bukkit.getOfflinePlayer(playerName); + p = Bukkit.getOfflinePlayer(uuid); return p; } public void setPlayer(OfflinePlayer player) { setSource(Source.PLAYER); - this.playerName = player.getName(); + this.uuid = player.getUniqueId(); if (player instanceof Player) { setGameMode(((Player) player).getGameMode()); } @@ -119,6 +125,7 @@ public class BlockState { @Override public String toString() { + String playerName = Bukkit.getOfflinePlayer(uuid).getName(); //return blockLocation.toString() + " by " + return location.toString() + " by " + (source == Source.PLAYER ? playerName : (source.toString() + (playerName != null ? "(" + playerName + ")" : ""))) + 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 2c6f416..ba5d85b 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/DBQueries.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/DBQueries.java @@ -138,7 +138,7 @@ public class DBQueries { update.setString(1, s.getGameMode().name()); else update.setInt(1, s.getGameMode().getValue()); - update.setString(2, s.getPlayerName()); + update.setString(2, s.getPlayerUUID().toString()); update.setTimestamp(3, new java.sql.Timestamp(s.getDate().getTime())); if (db.getType() == Type.MySQL) update.setString(4, s.getSource().name()); @@ -207,7 +207,7 @@ public class DBQueries { insert.setString(5, s.getGameMode().name()); else insert.setInt(5, s.getGameMode().getValue()); - insert.setString(6, s.getPlayerName()); + insert.setString(6, s.getPlayerUUID().toString()); insert.setTimestamp(7, new java.sql.Timestamp(s.getDate().getTime())); if (db.getType() == Type.MySQL) insert.setString(8, s.getSource().name()); 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 3120b65..8ba5e1d 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.getName()); + s.setPlayerName(player.getUniqueId().toString()); s.setDate(new Date()); s.setSource(Source.EDIT); if (mod.isDebug()) diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/store/InvYamlStorage.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/store/InvYamlStorage.java index 326960b..7aa8d33 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/store/InvYamlStorage.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/store/InvYamlStorage.java @@ -71,9 +71,9 @@ public class InvYamlStorage extends InvConfStorage { protected File getFile(Inventory pinv, Target target) { if (target != default_target) { - return new File(dir, pinv.getPlayer().getName() + "_" + target.toString().toLowerCase() + SUFFIX); + return new File(dir, pinv.getPlayer().getUniqueId() + "_" + target.toString().toLowerCase() + SUFFIX); } else { - return new File(dir, pinv.getPlayer().getName() + SUFFIX); + return new File(dir, pinv.getPlayer().getUniqueId() + SUFFIX); } } }