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;
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 + ")" : ""))) +

View file

@ -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());

View file

@ -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())

View file

@ -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);
}
}
}