First attempt to use UUID, not tested one ounce.

And I imagine the unit tests are going to fail.
This commit is contained in:
graywolf336 2014-04-21 22:58:15 -05:00
parent 1de176e67e
commit a3d9a54ff0
9 changed files with 109 additions and 81 deletions

View File

@ -43,14 +43,14 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.7.2-R0.2-SNAPSHOT</version>
<version>1.7.9-R0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.7.2-R0.2-SNAPSHOT</version>
<version>1.7.9-R0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>

View File

@ -286,6 +286,7 @@ public class JailIO {
st.executeUpdate(cellCreateCmd);
String prisCreateCmd = "CREATE TABLE IF NOT EXISTS `" + prefix + "prisoners` ("
+ "`uuid` VARCHAR(36) NOT NULL COMMENT 'The UUID of the prisoner.',"
+ "`name` VARCHAR(16) NOT NULL COMMENT 'The name of the prisoner.',"
+ "`jail` VARCHAR(250) NOT NULL COMMENT 'The jail the prisoner is in.',"
+ "`cell` VARCHAR(250) NULL COMMENT 'The cell the prisoner is in.',"
@ -299,8 +300,8 @@ public class JailIO {
+ "`armor` BLOB NULL COMMENT 'The armor in base64.',"
+ "`previousLocation` VARCHAR(250) NULL COMMENT 'A string of their previous location.',"
+ "`previousGameMode` VARCHAR(16) NULL COMMENT 'Their previous gamemode before they were jailed.',"
+ "PRIMARY KEY (`name`),"
+ "UNIQUE INDEX `name_UNIQUE` (`name` ASC))"
+ "PRIMARY KEY (`uuid`),"
+ "UNIQUE INDEX `uuid_UNIQUE` (`uuid` ASC))"
+ "COMMENT = 'Contains all the prisoners, in cells and jails.';";
//pl.debug(prisCreateCmd);
@ -308,6 +309,7 @@ public class JailIO {
String proCreateCmd = "CREATE TABLE IF NOT EXISTS `" + prefix + "records` ("
+ "`recordid` INT NOT NULL AUTO_INCREMENT COMMENT 'Auto generated number for the records database.',"
+ "`uuid` VARCHAR(36) NOT NULL COMMENT 'The UUID of the prisoner.',"
+ "`username` VARCHAR(16) NOT NULL COMMENT 'The username of the prisoner.',"
+ "`jailer` VARCHAR(250) NOT NULL COMMENT 'The name of the person who jailed the prisoner.',"
+ "`date` VARCHAR(32) NOT NULL COMMENT 'A string of the date.',"
@ -460,7 +462,7 @@ public class JailIO {
String cellname = set.getString("cell");
Cell c = j.getCell(cellname);
Prisoner p = new Prisoner(set.getString("name"), set.getBoolean("muted"), set.getLong("time"), set.getString("jailer"), set.getString("reason"));
Prisoner p = new Prisoner(set.getString("uuid"), set.getString("name"), set.getBoolean("muted"), set.getLong("time"), set.getString("jailer"), set.getString("reason"));
p.setOfflinePending(set.getBoolean("offlinePending"));
p.setToBeTransferred(set.getBoolean("toBeTransferred"));
Blob inv = set.getBlob("inventory");
@ -593,7 +595,8 @@ public class JailIO {
}
if(flat.contains(cellNode + "prisoner")) {
Prisoner p = new Prisoner(flat.getString(cellNode + "prisoner.name"),
Prisoner p = new Prisoner(flat.getString(cellNode + "prisoner.uuid"),
flat.getString(cellNode + "prisoner.name"),
flat.getBoolean(cellNode + "prisoner.muted"),
flat.getLong(cellNode + "prisoner.time"),
flat.getString(cellNode + "prisoner.jailer"),
@ -615,9 +618,10 @@ public class JailIO {
if(flat.isConfigurationSection(node + "prisoners")) {
Set<String> prisoners = flat.getConfigurationSection(node + "prisoners").getKeys(false);
if(!prisoners.isEmpty()) {
for(String prisoner : prisoners) {
String pNode = node + "prisoners." + prisoner + ".";
Prisoner pris = new Prisoner(prisoner,
for(String uuid : prisoners) {
String pNode = node + "prisoners." + uuid + ".";
Prisoner pris = new Prisoner(uuid,
flat.getString(pNode + "prisoner"),
flat.getBoolean(pNode + "muted"),
flat.getLong(pNode + "time"),
flat.getString(pNode + "jailer"),
@ -693,22 +697,23 @@ public class JailIO {
for(Cell c : j.getCells()) {
if(c.hasPrisoner()) {
Prisoner p = c.getPrisoner();
PreparedStatement pPS = con.prepareStatement("REPLACE INTO `" + prefix + "prisoners` (`name`, `jail`, `cell`, `muted`, `time`,"
PreparedStatement pPS = con.prepareStatement("REPLACE INTO `" + prefix + "prisoners` (`uuid`, `name`, `jail`, `cell`, `muted`, `time`,"
+ "`offlinePending`, `toBeTransferred`, `jailer`, `reason`, `inventory`, `armor`, `previousLocation`, `previousGameMode`)"
+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)");
pPS.setString(1, p.getName());
pPS.setString(2, j.getName());
pPS.setString(3, c.getName());
pPS.setBoolean(4, p.isMuted());
pPS.setFloat(5, p.getRemainingTime());
pPS.setBoolean(6, p.isOfflinePending());
pPS.setBoolean(7, p.isToBeTransferred());
pPS.setString(8, p.getJailer());
pPS.setString(9, p.getReason());
pPS.setBytes(10, p.getInventory().getBytes());
pPS.setBytes(11, p.getArmor().getBytes());
pPS.setString(12, p.getPreviousLocationString());
pPS.setString(13, p.getPreviousGameMode().toString());
+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
pPS.setString(1, p.getUUID().toString());
pPS.setString(2, p.getName());
pPS.setString(3, j.getName());
pPS.setString(4, c.getName());
pPS.setBoolean(5, p.isMuted());
pPS.setFloat(6, p.getRemainingTime());
pPS.setBoolean(7, p.isOfflinePending());
pPS.setBoolean(8, p.isToBeTransferred());
pPS.setString(9, p.getJailer());
pPS.setString(10, p.getReason());
pPS.setBytes(11, p.getInventory().getBytes());
pPS.setBytes(12, p.getArmor().getBytes());
pPS.setString(13, p.getPreviousLocationString());
pPS.setString(14, p.getPreviousGameMode().toString());
pPS.executeUpdate();
pPS.close();
@ -724,21 +729,22 @@ public class JailIO {
if(con == null) this.prepareStorage(false);
for(Prisoner p : j.getPrisonersNotInCells()) {
PreparedStatement pPS = con.prepareStatement("REPLACE INTO `" + prefix + "prisoners` (`name`, `jail`, `cell`, `muted`, `time`,"
+ "`offlinePending`, `toBeTransferred`, `jailer`, `reason`, `inventory`, `armor`, `previousLocation`, `previousGameMode`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)");
pPS.setString(1, p.getName());
pPS.setString(2, j.getName());
pPS.setString(3, "");
pPS.setBoolean(4, p.isMuted());
pPS.setFloat(5, p.getRemainingTime());
pPS.setBoolean(6, p.isOfflinePending());
pPS.setBoolean(7, p.isToBeTransferred());
pPS.setString(8, p.getJailer());
pPS.setString(9, p.getReason());
pPS.setBytes(10, p.getInventory().getBytes());
pPS.setBytes(11, p.getArmor().getBytes());
pPS.setString(12, p.getPreviousLocationString());
pPS.setString(13, p.getPreviousGameMode().toString());
PreparedStatement pPS = con.prepareStatement("REPLACE INTO `" + prefix + "prisoners` (`uuid`, `name`, `jail`, `cell`, `muted`, `time`,"
+ "`offlinePending`, `toBeTransferred`, `jailer`, `reason`, `inventory`, `armor`, `previousLocation`, `previousGameMode`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
pPS.setString(1, p.getUUID().toString());
pPS.setString(2, p.getName());
pPS.setString(3, j.getName());
pPS.setString(4, "");
pPS.setBoolean(5, p.isMuted());
pPS.setFloat(6, p.getRemainingTime());
pPS.setBoolean(7, p.isOfflinePending());
pPS.setBoolean(8, p.isToBeTransferred());
pPS.setString(9, p.getJailer());
pPS.setString(10, p.getReason());
pPS.setBytes(11, p.getInventory().getBytes());
pPS.setBytes(12, p.getArmor().getBytes());
pPS.setString(13, p.getPreviousLocationString());
pPS.setString(14, p.getPreviousGameMode().toString());
pPS.executeUpdate();
pPS.close();
@ -809,6 +815,7 @@ public class JailIO {
if(c.getPrisoner() != null) {
Prisoner p = c.getPrisoner();
flat.set(cNode + "prisoner.uuid", p.getUUID().toString());
flat.set(cNode + "prisoner.name", p.getName());
flat.set(cNode + "prisoner.muted", p.isMuted());
flat.set(cNode + "prisoner.time", p.getRemainingTime());
@ -828,7 +835,8 @@ public class JailIO {
//Null all the prisoners out before we save them again, this way no prisoners are left behind
flat.set(node + "prisoners", null);
for(Prisoner p : j.getPrisonersNotInCells()) {
String pNode = node + "prisoners." + p.getName() + ".";
String pNode = node + "prisoners." + p.getUUID().toString() + ".";
flat.set(pNode + "name", p.getName());
flat.set(pNode + "muted", p.isMuted());
flat.set(pNode + "time", p.getRemainingTime());
flat.set(pNode + "offlinePending", p.isOfflinePending());
@ -890,20 +898,21 @@ public class JailIO {
if(c.hasPrisoner()) {
Prisoner p = c.getPrisoner();
PreparedStatement pPS = con.prepareStatement("REPLACE INTO `" + prefix + "prisoners` (`name`, `jail`, `cell`, `muted`, `time`,"
+ "`offlinePending`, `toBeTransferred`, `jailer`, `reason`, `inventory`, `armor`, `previousLocation`, `previousGameMode`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)");
pPS.setString(1, p.getName());
pPS.setString(2, j.getName());
pPS.setString(3, c.getName());
pPS.setBoolean(4, p.isMuted());
pPS.setFloat(5, p.getRemainingTime());
pPS.setBoolean(6, p.isOfflinePending());
pPS.setBoolean(7, p.isToBeTransferred());
pPS.setString(8, p.getReason());
pPS.setBytes(9, p.getInventory().getBytes());
pPS.setBytes(10, p.getArmor().getBytes());
pPS.setString(11, p.getPreviousLocationString());
pPS.setString(12, p.getPreviousGameMode().toString());
PreparedStatement pPS = con.prepareStatement("REPLACE INTO `" + prefix + "prisoners` (`uuid`, `name`, `jail`, `cell`, `muted`, `time`,"
+ "`offlinePending`, `toBeTransferred`, `jailer`, `reason`, `inventory`, `armor`, `previousLocation`, `previousGameMode`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
pPS.setString(1, p.getUUID().toString());
pPS.setString(2, p.getName());
pPS.setString(3, j.getName());
pPS.setString(4, c.getName());
pPS.setBoolean(5, p.isMuted());
pPS.setFloat(6, p.getRemainingTime());
pPS.setBoolean(7, p.isOfflinePending());
pPS.setBoolean(8, p.isToBeTransferred());
pPS.setString(9, p.getReason());
pPS.setBytes(10, p.getInventory().getBytes());
pPS.setBytes(11, p.getArmor().getBytes());
pPS.setString(12, p.getPreviousLocationString());
pPS.setString(13, p.getPreviousGameMode().toString());
pPS.executeUpdate();
pPS.close();
@ -943,8 +952,8 @@ public class JailIO {
case 1:
case 2:
try {
PreparedStatement pp = con.prepareStatement("delete from `" + prefix + "prisoners` where name = ? limit 1;");
pp.setString(1, p.getName());
PreparedStatement pp = con.prepareStatement("delete from `" + prefix + "prisoners` where uuid = ? limit 1;");
pp.setString(1, p.getUUID().toString());
pl.debug("Removing " + p.getName() + " from MySQL database.");
@ -958,7 +967,7 @@ public class JailIO {
break;
default:
if(c == null)
flat.set("jails." + j.getName() + ".prisoners." + p.getName(), null);
flat.set("jails." + j.getName() + ".prisoners." + p.getUUID().toString(), null);
else
flat.set("jails." + j.getName() + "." + c.getName() + ".prisoner", null);
@ -1063,24 +1072,26 @@ public class JailIO {
/**
* Adds an entry to the database/file for the user, logging when they was jailed.
*
* @param uuid of the player
* @param username of the player
* @param jailer who jailed them
* @param date string of when they are jailed
* @param time of the player's sentence
* @param reason the player is jailed
*/
public void addRecordEntry(String username, String jailer, String date, long time, String reason) {
public void addRecordEntry(String uuid, String username, String jailer, String date, long time, String reason) {
switch(storage) {
case 1:
break;
case 2:
try {
PreparedStatement p = con.prepareStatement("insert into `" + prefix + "records` (`username`, `jailer`, `date`, `time`, `reason`) VALUES (?,?,?,?,?);");
p.setString(1, username);
p.setString(2, jailer);
p.setString(3, date);
p.setLong(4, time);
p.setString(5, reason);
PreparedStatement p = con.prepareStatement("insert into `" + prefix + "records` (`uuid`, `username`, `jailer`, `date`, `time`, `reason`) VALUES (?,?,?,?,?,?);");
p.setString(1, uuid);
p.setString(2, username);
p.setString(3, jailer);
p.setString(4, date);
p.setLong(5, time);
p.setString(6, reason);
p.executeUpdate();
p.close();
@ -1093,8 +1104,8 @@ public class JailIO {
default:
if(records == null) records = YamlConfiguration.loadConfiguration(new File(pl.getDataFolder(), "records.yml"));
List<String> previous = records.getStringList("username");
previous.add(this.getLanguageString(LangString.RECORDENTRY, new String[] { date, username, jailer, String.valueOf(time), reason }));
List<String> previous = records.getStringList(uuid);
previous.add(this.getLanguageString(LangString.RECORDENTRY, new String[] { date, username, jailer, String.valueOf(time), reason, uuid }));
records.set(username, previous);
@ -1115,7 +1126,7 @@ public class JailIO {
* @param username of the prisoner to get.
* @return A List of strings containing the record entries.
*/
public List<String> getRecordEntries(String username) {
public List<String> getRecordEntries(String uuid) {
List<String> entries = new ArrayList<String>();
switch(storage) {
@ -1123,13 +1134,13 @@ public class JailIO {
break;
case 2:
try {
PreparedStatement ps = con.prepareStatement("SELECT * FROM " + prefix + "records where username = ?");
ps.setString(1, username);
PreparedStatement ps = con.prepareStatement("SELECT * FROM " + prefix + "records where uuid = ?");
ps.setString(1, uuid);
ResultSet set = ps.executeQuery();
while(set.next()) {
entries.add(this.getLanguageString(LangString.RECORDENTRY,
new String[] { set.getString("date"), username, set.getString("jailer"), String.valueOf(set.getLong("time")), set.getString("reason") }));
new String[] { set.getString("date"), set.getString("username"), set.getString("jailer"), String.valueOf(set.getLong("time")), set.getString("reason") }));
}
set.close();
@ -1137,13 +1148,13 @@ public class JailIO {
} catch (SQLException e) {
e.printStackTrace();
pl.getLogger().severe("---------- Jail Error!!! ----------");
pl.getLogger().severe("Error while getting all the record entries for '" + username + "', please check the error and fix what is wrong.");
pl.getLogger().severe("Error while getting all the record entries for '" + uuid + "', please check the error and fix what is wrong.");
}
break;
default:
if(records == null) records = YamlConfiguration.loadConfiguration(new File(pl.getDataFolder(), "records.yml"));
entries = records.getStringList(username);
entries = records.getStringList(uuid);
break;
}

View File

@ -1,5 +1,6 @@
package com.graywolf336.jail.beans;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.bukkit.Bukkit;
@ -14,7 +15,7 @@ import org.bukkit.Location;
* @version 3.0.1
*/
public class Prisoner {
private String name, jailer, reason, inventory, armor;
private String uuid, name, jailer, reason, inventory, armor;
private boolean muted, offlinePending, teleporting, toBeTransferred;
private long time, afk;
private Location previousPosition;
@ -23,13 +24,15 @@ public class Prisoner {
/**
* Creates a new prisoner with a name and whether they are muted or not.
*
* @param uuid The uuid of the prisoner
* @param name The name of the prisoner
* @param muted Whether the prisoner is muted or not
* @param time The amount of remaining time the prisoner has
* @param jailer The name of the person who jailed this prisoner
* @param reason The reason why this prisoner is in jail
*/
public Prisoner(String name, boolean muted, long time, String jailer, String reason) {
public Prisoner(String uuid, String name, boolean muted, long time, String jailer, String reason) {
this.uuid = uuid;
this.name = name;
this.muted = muted;
this.time = time;
@ -45,6 +48,11 @@ public class Prisoner {
this.afk = 0;
}
/** Returns the UUID of the prisoner. */
public UUID getUUID() {
return UUID.fromString(this.uuid);
}
/** Gets the name of this player. */
public String getName() {
return this.name;

View File

@ -164,10 +164,17 @@ public class JailCommand implements Command {
return true;
}
String uuid = "";
if(p == null) {
uuid = jm.getPlugin().getServer().getOfflinePlayer(params.getPlayer()).getUniqueId().toString();
}else {
uuid = p.getUniqueId().toString();
}
//Get the jail instance from the name of jail in the params.
Jail j = jm.getJail(jailName);
Cell c = j.getCell(params.getCell());
Prisoner pris = new Prisoner(params.getPlayer(), muted, time, sender.getName(), reason);
Prisoner pris = new Prisoner(uuid, params.getPlayer(), muted, time, sender.getName(), reason);
//call the event
PrePrisonerJailedEvent event = new PrePrisonerJailedEvent(j, c, pris, p, p == null, pris.getJailer());

View File

@ -118,7 +118,7 @@ public class OldInputOutput {
//Check if the jail exists, if not then we refuse to load it
if(j != null) {
Prisoner p = new Prisoner(name, set.getBoolean("muted"), (long) set.getInt("RemainTime"), set.getString("Jailer"), set.getString("reason"));
Prisoner p = new Prisoner(pl.getServer().getOfflinePlayer(name).getUniqueId().toString(), name, set.getBoolean("muted"), (long) set.getInt("RemainTime"), set.getString("Jailer"), set.getString("reason"));
p.setOfflinePending(set.getBoolean("Offline"));
p.setToBeTransferred(transfer);

View File

@ -23,14 +23,16 @@ public class JailingListener implements Listener {
@EventHandler(ignoreCancelled=true)
public void preJailingListener(PrePrisonerJailedEvent event) {
pl.getJailIO().addRecordEntry(event.getPrisoner().getName(),
pl.getJailIO().addRecordEntry(event.getPrisoner().getUUID().toString(),
event.getPrisoner().getName(),
event.getPrisoner().getJailer(), dateFormat.format(new Date()),
event.getPrisoner().getRemainingTimeInMinutes(), event.getPrisoner().getReason());
}
@EventHandler(ignoreCancelled=true)
public void preJailingListener(PrePrisonerJailedByJailStickEvent event) {
pl.getJailIO().addRecordEntry(event.getPrisoner().getName(),
pl.getJailIO().addRecordEntry(event.getPrisoner().getUUID().toString(),
event.getPrisoner().getName(),
event.getPrisoner().getJailer(), dateFormat.format(new Date()),
event.getPrisoner().getRemainingTimeInMinutes(), event.getPrisoner().getReason());
}

View File

@ -204,7 +204,7 @@ public class PlayerListener implements Listener {
}else {
Stick s = pl.getJailStickManager().getStick(attacker.getItemInHand().getType());
Prisoner p = new Prisoner(player.getName(),
Prisoner p = new Prisoner(player.getUniqueId().toString(), player.getName(),
pl.getConfig().getBoolean(Settings.AUTOMATICMUTE.getPath()),
s.getTime(), attacker.getName(), s.getReason());

View File

@ -32,7 +32,7 @@ language:
playernotonline: '&cThat player is not online!'
pluginreloaded: '&9Jail data successfully reloaded.'
prisonerscleared: '&cAll the prisoners from %0% have been cleared.'
recordentry: '&7[%0%]: &9%1% &fjailed by &9%2% &ffor &9%3% &fminutes with a reason of &9%4%&f.'
recordentry: '&7[%0%]: &9%1% &fjailed by &9%2% &ffor &9%3% &fminutes with a reason of &9%4%&f. [%5%]'
recordtimesjailed: '&c%0% has been jailed &a%1% &ctimes.'
timeformat: "MM/dd/yyyy HH:mm:ss"
transferring: '&9transferring'

View File

@ -15,7 +15,7 @@ import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftItemFactory;
import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftItemFactory;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;
import org.bukkit.plugin.Plugin;