Use UUID instead of player name.

This commit is contained in:
pickernickel 2016-05-22 02:48:08 -05:00
parent 05d37326e0
commit 8c1240cc24
4 changed files with 20 additions and 13 deletions

View file

@ -1,6 +1,7 @@
package de.jaschastarke.minecraft.limitedcreative.blockstate; package de.jaschastarke.minecraft.limitedcreative.blockstate;
import java.util.Date; import java.util.Date;
import java.util.UUID;
import javax.persistence.Column; import javax.persistence.Column;
//import javax.persistence.EmbeddedId; //import javax.persistence.EmbeddedId;
@ -37,7 +38,7 @@ public class BlockState {
private GameMode gameMode; private GameMode gameMode;
@Column(name = "player") @Column(name = "player")
private String playerName; private UUID uuid;
@NotNull @NotNull
@Column(name = "cdate") @Column(name = "cdate")
@ -51,7 +52,7 @@ public class BlockState {
public BlockState(BlockState copy) { public BlockState(BlockState copy) {
this.location = copy.location; this.location = copy.location;
this.gameMode = copy.gameMode; this.gameMode = copy.gameMode;
this.playerName = copy.playerName; this.uuid = copy.uuid;
this.date = copy.date; this.date = copy.date;
this.source = copy.source; this.source = copy.source;
} }
@ -72,24 +73,29 @@ public class BlockState {
this.gameMode = gm; this.gameMode = gm;
} }
public String getPlayerName() { public UUID getPlayerUUID() {
return playerName; return uuid;
} }
public String getPlayerName() {
return Bukkit.getOfflinePlayer(uuid).getName();
}
//TODO Rename
public void setPlayerName(String s) { public void setPlayerName(String s) {
playerName = s; uuid = UUID.fromString(s);
} }
public OfflinePlayer getPlayer() { public OfflinePlayer getPlayer() {
OfflinePlayer p = Bukkit.getPlayerExact(playerName); OfflinePlayer p = Bukkit.getPlayer(uuid);
if (p == null) if (p == null)
p = Bukkit.getOfflinePlayer(playerName); p = Bukkit.getOfflinePlayer(uuid);
return p; return p;
} }
public void setPlayer(OfflinePlayer player) { public void setPlayer(OfflinePlayer player) {
setSource(Source.PLAYER); setSource(Source.PLAYER);
this.playerName = player.getName(); this.uuid = player.getUniqueId();
if (player instanceof Player) { if (player instanceof Player) {
setGameMode(((Player) player).getGameMode()); setGameMode(((Player) player).getGameMode());
} }
@ -119,6 +125,7 @@ public class BlockState {
@Override @Override
public String toString() { public String toString() {
String playerName = Bukkit.getOfflinePlayer(uuid).getName();
//return blockLocation.toString() + " by " + //return blockLocation.toString() + " by " +
return location.toString() + " by " + return location.toString() + " by " +
(source == Source.PLAYER ? playerName : (source.toString() + (playerName != null ? "(" + playerName + ")" : ""))) + (source == Source.PLAYER ? playerName : (source.toString() + (playerName != null ? "(" + playerName + ")" : ""))) +

View file

@ -138,7 +138,7 @@ public class DBQueries {
update.setString(1, s.getGameMode().name()); update.setString(1, s.getGameMode().name());
else else
update.setInt(1, s.getGameMode().getValue()); 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())); update.setTimestamp(3, new java.sql.Timestamp(s.getDate().getTime()));
if (db.getType() == Type.MySQL) if (db.getType() == Type.MySQL)
update.setString(4, s.getSource().name()); update.setString(4, s.getSource().name());
@ -207,7 +207,7 @@ public class DBQueries {
insert.setString(5, s.getGameMode().name()); insert.setString(5, s.getGameMode().name());
else else
insert.setInt(5, s.getGameMode().getValue()); 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())); insert.setTimestamp(7, new java.sql.Timestamp(s.getDate().getTime()));
if (db.getType() == Type.MySQL) if (db.getType() == Type.MySQL)
insert.setString(8, s.getSource().name()); insert.setString(8, s.getSource().name());

View file

@ -46,7 +46,7 @@ public class EditSessionExtent extends AbstractLoggingExtent {
s.setLocation(loc); s.setLocation(loc);
} }
s.setGameMode(null); s.setGameMode(null);
s.setPlayerName(player.getName()); s.setPlayerName(player.getUniqueId().toString());
s.setDate(new Date()); s.setDate(new Date());
s.setSource(Source.EDIT); s.setSource(Source.EDIT);
if (mod.isDebug()) if (mod.isDebug())

View file

@ -71,9 +71,9 @@ public class InvYamlStorage extends InvConfStorage {
protected File getFile(Inventory pinv, Target target) { protected File getFile(Inventory pinv, Target target) {
if (target != default_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 { } else {
return new File(dir, pinv.getPlayer().getName() + SUFFIX); return new File(dir, pinv.getPlayer().getUniqueId() + SUFFIX);
} }
} }
} }