From 4d4f609b82e8a2551b792b344f180cee59be08c8 Mon Sep 17 00:00:00 2001 From: graywolf336 Date: Tue, 29 Apr 2014 13:20:33 -0500 Subject: [PATCH] Finish using the UUID, we are still using blocking methods. I want to get fully away from blocking methods and instead make the user/player/prisoner/whatever wait to get an answer while we retrieve the uuid information asynchronously. --- .../java/com/graywolf336/jail/JailIO.java | 14 +++---- .../com/graywolf336/jail/JailManager.java | 39 +++++++++++++++++++ .../com/graywolf336/jail/PrisonerManager.java | 4 +- .../java/com/graywolf336/jail/beans/Jail.java | 5 +-- .../com/graywolf336/jail/beans/Prisoner.java | 10 ++++- .../command/commands/HandCuffCommand.java | 2 +- .../jail/command/commands/UnJailCommand.java | 12 +++--- .../command/commands/UnJailForceCommand.java | 4 +- .../command/subcommands/JailCheckCommand.java | 6 +-- .../jail/command/subcommands/JailCommand.java | 7 ++-- .../subcommands/JailListCellsCommand.java | 4 +- .../command/subcommands/JailListCommand.java | 2 +- .../command/subcommands/JailMuteCommand.java | 6 +-- .../command/subcommands/JailPayCommand.java | 24 ++++++------ .../subcommands/JailStatusCommand.java | 2 +- .../command/subcommands/JailStopCommand.java | 2 +- .../command/subcommands/JailTimeCommand.java | 8 ++-- .../subcommands/JailTransferAllCommand.java | 2 +- .../subcommands/JailTransferCommand.java | 16 ++++---- .../jail/legacy/LegacyManager.java | 4 +- .../jail/legacy/OldInputOutput.java | 4 +- .../jail/listeners/JailingListener.java | 4 +- .../jail/listeners/PlayerListener.java | 6 ++- 23 files changed, 118 insertions(+), 69 deletions(-) diff --git a/src/main/java/com/graywolf336/jail/JailIO.java b/src/main/java/com/graywolf336/jail/JailIO.java index 0e6e0c0..d379bc3 100644 --- a/src/main/java/com/graywolf336/jail/JailIO.java +++ b/src/main/java/com/graywolf336/jail/JailIO.java @@ -700,7 +700,7 @@ public class JailIO { + "`offlinePending`, `toBeTransferred`, `jailer`, `reason`, `inventory`, `armor`, `previousLocation`, `previousGameMode`)" + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); pPS.setString(1, p.getUUID().toString()); - pPS.setString(2, p.getName()); + pPS.setString(2, p.getLastKnownName()); pPS.setString(3, j.getName()); pPS.setString(4, c.getName()); pPS.setBoolean(5, p.isMuted()); @@ -731,7 +731,7 @@ public class JailIO { 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(2, p.getLastKnownName()); pPS.setString(3, j.getName()); pPS.setString(4, ""); pPS.setBoolean(5, p.isMuted()); @@ -815,7 +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.name", p.getLastKnownName()); flat.set(cNode + "prisoner.muted", p.isMuted()); flat.set(cNode + "prisoner.time", p.getRemainingTime()); flat.set(cNode + "prisoner.offlinePending", p.isOfflinePending()); @@ -835,7 +835,7 @@ public class JailIO { flat.set(node + "prisoners", null); for(Prisoner p : j.getPrisonersNotInCells()) { String pNode = node + "prisoners." + p.getUUID().toString() + "."; - flat.set(pNode + "name", p.getName()); + flat.set(pNode + "name", p.getLastKnownName()); flat.set(pNode + "muted", p.isMuted()); flat.set(pNode + "time", p.getRemainingTime()); flat.set(pNode + "offlinePending", p.isOfflinePending()); @@ -900,7 +900,7 @@ public class JailIO { 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(2, p.getLastKnownName()); pPS.setString(3, j.getName()); pPS.setString(4, c.getName()); pPS.setBoolean(5, p.isMuted()); @@ -954,14 +954,14 @@ public class JailIO { 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."); + pl.debug("Removing " + p.getLastKnownName() + " (" + p.getUUID().toString() + ") from MySQL database."); pp.executeUpdate(); pp.close(); } catch (SQLException e) { e.printStackTrace(); pl.getLogger().severe("---------- Jail Error!!! ----------"); - pl.getLogger().severe("Error while removing the prisoner '" + p.getName() + "' from the database, please check the error and fix what is wrong."); + pl.getLogger().severe("Error while removing the prisoner '" + p.getLastKnownName() + "' from the database, please check the error and fix what is wrong."); } break; default: diff --git a/src/main/java/com/graywolf336/jail/JailManager.java b/src/main/java/com/graywolf336/jail/JailManager.java index 0d4a835..4631136 100644 --- a/src/main/java/com/graywolf336/jail/JailManager.java +++ b/src/main/java/com/graywolf336/jail/JailManager.java @@ -222,6 +222,45 @@ public class JailManager { } } + /** + * Gets the {@link Jail} the player is in from their last known username, null if not jailed. + * + * @param username Last known username to search by + * @return {@link Jail jail} player is in + */ + public Jail getJailPlayerIsInByLastKnownName(String username) { + for(Jail j : jails.values()) + for(Prisoner p : j.getAllPrisoners()) + if(p.getLastKnownName().equalsIgnoreCase(username)) + return j; + + return null; + } + + /** + * Gets the {@link Prisoner}'s data from the last known username, returning null if no prisoner has that name. + * + * @param username Last known username to go by + * @return {@link Prisoner prisoner} data + */ + public Prisoner getPrisonerByLastKnownName(String username) { + for(Prisoner p : this.getAllPrisoners()) + if(p.getLastKnownName().equalsIgnoreCase(username)) + return p; + + return null; + } + + /** + * Checks if the provided username is jailed, using last known username. + * + * @param username Last known username to go by + * @return true if they are jailed, false if not + */ + public boolean isPlayerJailedByLastKnownUsername(String username) { + return this.getPrisonerByLastKnownName(username) != null; + } + /** * Clears a {@link Jail} of all its prisoners if the jail is provided, otherwise it releases all the prisoners in all the jails. * diff --git a/src/main/java/com/graywolf336/jail/PrisonerManager.java b/src/main/java/com/graywolf336/jail/PrisonerManager.java index 115b430..597fce8 100644 --- a/src/main/java/com/graywolf336/jail/PrisonerManager.java +++ b/src/main/java/com/graywolf336/jail/PrisonerManager.java @@ -86,9 +86,9 @@ public class PrisonerManager { String msg = ""; if(prisoner.getRemainingTime() < 0L) - msg = pl.getJailIO().getLanguageString(LangString.BROADCASTMESSAGEFOREVER, new String[] { prisoner.getName() }); + msg = pl.getJailIO().getLanguageString(LangString.BROADCASTMESSAGEFOREVER, new String[] { prisoner.getLastKnownName() }); else - msg = pl.getJailIO().getLanguageString(LangString.BROADCASTMESSAGEFORMINUTES, new String[] { prisoner.getName(), String.valueOf(prisoner.getRemainingTimeInMinutes()) }); + msg = pl.getJailIO().getLanguageString(LangString.BROADCASTMESSAGEFORMINUTES, new String[] { prisoner.getLastKnownName(), String.valueOf(prisoner.getRemainingTimeInMinutes()) }); boolean broadcasted = false; //Broadcast the message, if it is enabled diff --git a/src/main/java/com/graywolf336/jail/beans/Jail.java b/src/main/java/com/graywolf336/jail/beans/Jail.java index 5152f8b..ae2a749 100644 --- a/src/main/java/com/graywolf336/jail/beans/Jail.java +++ b/src/main/java/com/graywolf336/jail/beans/Jail.java @@ -334,11 +334,10 @@ public class Jail { * * @param name The name of the prisoner to get. * @return the prisoner instance, can be null - * @deprecated Use {@link #getPrisoner(UUID)} */ - public Prisoner getPrisoner(String name) { + public Prisoner getPrisonerByLastKnownName(String name) { for(Prisoner p : this.getAllPrisoners()) - if(p.getName().equalsIgnoreCase(name)) + if(p.getLastKnownName().equalsIgnoreCase(name)) return p; return null; diff --git a/src/main/java/com/graywolf336/jail/beans/Prisoner.java b/src/main/java/com/graywolf336/jail/beans/Prisoner.java index 6755ef4..c60c9ea 100644 --- a/src/main/java/com/graywolf336/jail/beans/Prisoner.java +++ b/src/main/java/com/graywolf336/jail/beans/Prisoner.java @@ -53,8 +53,14 @@ public class Prisoner { return UUID.fromString(this.uuid); } - /** Gets the name of this player. */ - public String getName() { + /** Gets the name of this prisoner. */ + public String getLastKnownName() { + return this.name; + } + + /** Sets the name of this prisoner. */ + public String setLastKnownName(String username) { + this.name = username; return this.name; } diff --git a/src/main/java/com/graywolf336/jail/command/commands/HandCuffCommand.java b/src/main/java/com/graywolf336/jail/command/commands/HandCuffCommand.java index 1feb7b3..232bc1e 100644 --- a/src/main/java/com/graywolf336/jail/command/commands/HandCuffCommand.java +++ b/src/main/java/com/graywolf336/jail/command/commands/HandCuffCommand.java @@ -24,7 +24,7 @@ public class HandCuffCommand implements Command { sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERNOTONLINE)); }else if(player.hasPermission("jail.cantbehandcuffed")) { sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CANTBEHANDCUFFED, new String[] { player.getName() })); - }else if(jm.isPlayerJailed(player.getName())) { + }else if(jm.isPlayerJailed(player.getUniqueId())) { sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CURRENTLYJAILEDHANDCUFF, new String[] { player.getName() })); }else if(jm.getPlugin().getHandCuffManager().isHandCuffed(player.getName())) { sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFSRELEASED, new String[] { player.getName() })); diff --git a/src/main/java/com/graywolf336/jail/command/commands/UnJailCommand.java b/src/main/java/com/graywolf336/jail/command/commands/UnJailCommand.java index b6b089f..bf2c452 100644 --- a/src/main/java/com/graywolf336/jail/command/commands/UnJailCommand.java +++ b/src/main/java/com/graywolf336/jail/command/commands/UnJailCommand.java @@ -24,17 +24,17 @@ public class UnJailCommand implements Command { public boolean execute(JailManager jm, CommandSender sender, String... args) { //Check if the player is jailed - if(jm.isPlayerJailed(args[0])) { - Jail j = jm.getJailPlayerIsIn(args[0]); - Prisoner pris = j.getPrisoner(args[0]); - Player p = jm.getPlugin().getServer().getPlayerExact(args[0]); + if(jm.isPlayerJailedByLastKnownUsername(args[0])) { + Jail j = jm.getJailPlayerIsInByLastKnownName(args[0]); + Prisoner pris = j.getPrisonerByLastKnownName(args[0]); + Player p = jm.getPlugin().getServer().getPlayer(pris.getUUID()); //Check if the player is on the server or not if(p == null) { //Check if the player has offline pending and their remaining time is above 0, if so then //forceably unjail them if(pris.isOfflinePending() && pris.getRemainingTime() != 0L) { - jm.getPlugin().getPrisonerManager().forceUnJail(j, j.getCellPrisonerIsIn(args[0]), p, pris); + jm.getPlugin().getPrisonerManager().forceUnJail(j, j.getCellPrisonerIsIn(pris.getUUID()), p, pris); sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.FORCEUNJAILED, args[0])); }else { //The player is not, so we'll set the remaining time to zero and do it when they login next @@ -45,7 +45,7 @@ public class UnJailCommand implements Command { }else { //Player is online, so let's try unjailing them try { - jm.getPlugin().getPrisonerManager().unJail(j, j.getCellPrisonerIsIn(args[0]), p, pris); + jm.getPlugin().getPrisonerManager().unJail(j, j.getCellPrisonerIsIn(pris.getUUID()), p, pris); } catch (Exception e) { sender.sendMessage(ChatColor.RED + e.getMessage()); } diff --git a/src/main/java/com/graywolf336/jail/command/commands/UnJailForceCommand.java b/src/main/java/com/graywolf336/jail/command/commands/UnJailForceCommand.java index 31d803c..7201004 100644 --- a/src/main/java/com/graywolf336/jail/command/commands/UnJailForceCommand.java +++ b/src/main/java/com/graywolf336/jail/command/commands/UnJailForceCommand.java @@ -21,8 +21,8 @@ public class UnJailForceCommand implements Command { public boolean execute(JailManager jm, CommandSender sender, String... args) { //Check if the player is jailed - if(jm.isPlayerJailed(args[0])) { - jm.getPlugin().getPrisonerManager().forceRelease(jm.getPrisoner(args[0])); + if(jm.isPlayerJailedByLastKnownUsername(args[0])) { + jm.getPlugin().getPrisonerManager().forceRelease(jm.getPrisonerByLastKnownName(args[0])); sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.FORCEUNJAILED, args[0])); if(jm.getPlugin().getConfig().getBoolean(Settings.LOGJAILINGTOCONSOLE.getPath())) { diff --git a/src/main/java/com/graywolf336/jail/command/subcommands/JailCheckCommand.java b/src/main/java/com/graywolf336/jail/command/subcommands/JailCheckCommand.java index 2dd6088..d33d73f 100644 --- a/src/main/java/com/graywolf336/jail/command/subcommands/JailCheckCommand.java +++ b/src/main/java/com/graywolf336/jail/command/subcommands/JailCheckCommand.java @@ -22,12 +22,12 @@ public class JailCheckCommand implements Command{ // Checks the status of the specified prisoner public boolean execute(JailManager jm, CommandSender sender, String... args) { //Otherwise let's check the first argument - if(jm.isPlayerJailed(args[1])) { - Prisoner p = jm.getPrisoner(args[1]); + if(jm.isPlayerJailedByLastKnownUsername(args[1])) { + Prisoner p = jm.getPrisonerByLastKnownName(args[1]); //graywolf663: Being gray's evil twin; CONSOLE (10) //prisoner: reason; jailer (time in minutes) - sender.sendMessage(ChatColor.BLUE + " " + p.getName() + ": " + p.getReason() + "; " + p.getJailer() + " (" + p.getRemainingTimeInMinutes() + " mins)"); + sender.sendMessage(ChatColor.BLUE + " " + p.getLastKnownName() + ": " + p.getReason() + "; " + p.getJailer() + " (" + p.getRemainingTimeInMinutes() + " mins)"); }else { sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, args[1])); } diff --git a/src/main/java/com/graywolf336/jail/command/subcommands/JailCommand.java b/src/main/java/com/graywolf336/jail/command/subcommands/JailCommand.java index 21e754c..b7fbff2 100644 --- a/src/main/java/com/graywolf336/jail/command/subcommands/JailCommand.java +++ b/src/main/java/com/graywolf336/jail/command/subcommands/JailCommand.java @@ -74,7 +74,7 @@ public class JailCommand implements Command { } //Check if the given player is already jailed or not - if(jm.isPlayerJailed(params.getPlayer())) { + if(jm.isPlayerJailedByLastKnownUsername(params.getPlayer())) { sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.ALREADYJAILED, params.getPlayer())); return true; } @@ -166,6 +166,7 @@ public class JailCommand implements Command { String uuid = ""; if(p == null) { + //TODO: Make this whole jail command non-blocking uuid = jm.getPlugin().getServer().getOfflinePlayer(params.getPlayer()).getUniqueId().toString(); }else { uuid = p.getUniqueId().toString(); @@ -198,10 +199,10 @@ public class JailCommand implements Command { //Player is not online if(p == null) { - sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.OFFLINEJAIL, new String[] { pris.getName(), String.valueOf(pris.getRemainingTimeInMinutes()) })); + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.OFFLINEJAIL, new String[] { pris.getLastKnownName(), String.valueOf(pris.getRemainingTimeInMinutes()) })); }else { //Player *is* online - sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.ONLINEJAIL, new String[] { pris.getName(), String.valueOf(pris.getRemainingTimeInMinutes()) })); + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.ONLINEJAIL, new String[] { pris.getLastKnownName(), String.valueOf(pris.getRemainingTimeInMinutes()) })); } try { diff --git a/src/main/java/com/graywolf336/jail/command/subcommands/JailListCellsCommand.java b/src/main/java/com/graywolf336/jail/command/subcommands/JailListCellsCommand.java index b2f6c01..5773876 100644 --- a/src/main/java/com/graywolf336/jail/command/subcommands/JailListCellsCommand.java +++ b/src/main/java/com/graywolf336/jail/command/subcommands/JailListCellsCommand.java @@ -30,9 +30,9 @@ public class JailListCellsCommand implements Command { String message = ""; for(Cell c : j.getCells()) { if(message.isEmpty()) { - message = c.getName() + (c.getPrisoner() == null ? "" : " (" + c.getPrisoner().getName() + ")"); + message = c.getName() + (c.getPrisoner() == null ? "" : " (" + c.getPrisoner().getLastKnownName() + ")"); }else { - message += ", " + c.getName() + (c.getPrisoner() == null ? "" : " (" + c.getPrisoner().getName() + ")"); + message += ", " + c.getName() + (c.getPrisoner() == null ? "" : " (" + c.getPrisoner().getLastKnownName() + ")"); } } diff --git a/src/main/java/com/graywolf336/jail/command/subcommands/JailListCommand.java b/src/main/java/com/graywolf336/jail/command/subcommands/JailListCommand.java index 6f5624a..04e14e0 100644 --- a/src/main/java/com/graywolf336/jail/command/subcommands/JailListCommand.java +++ b/src/main/java/com/graywolf336/jail/command/subcommands/JailListCommand.java @@ -50,7 +50,7 @@ public class JailListCommand implements Command { for(Prisoner p : j.getAllPrisoners()) { //graywolf663: Being gray's evil twin; CONSOLE (10) //prisoner: reason; jailer (time in minutes) - sender.sendMessage(ChatColor.BLUE + " " + p.getName() + ": " + p.getReason() + "; " + p.getJailer() + " (" + p.getRemainingTimeInMinutes() + " mins)"); + sender.sendMessage(ChatColor.BLUE + " " + p.getLastKnownName() + ": " + p.getReason() + "; " + p.getJailer() + " (" + p.getRemainingTimeInMinutes() + " mins)"); } } } diff --git a/src/main/java/com/graywolf336/jail/command/subcommands/JailMuteCommand.java b/src/main/java/com/graywolf336/jail/command/subcommands/JailMuteCommand.java index 4d7a17e..067ea25 100644 --- a/src/main/java/com/graywolf336/jail/command/subcommands/JailMuteCommand.java +++ b/src/main/java/com/graywolf336/jail/command/subcommands/JailMuteCommand.java @@ -18,10 +18,10 @@ import com.graywolf336.jail.enums.LangString; public class JailMuteCommand implements Command { public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception { //Let's check if the player they're sending us is jailed - if(jm.isPlayerJailed(args[1])) { + if(jm.isPlayerJailedByLastKnownUsername(args[1])) { //They are, so let's toggle whether they are muted or not - boolean muted = !jm.getPrisoner(args[1]).isMuted(); - jm.getPrisoner(args[1]).setMuted(muted); + boolean muted = !jm.getPrisonerByLastKnownName(args[1]).isMuted(); + jm.getPrisonerByLastKnownName(args[1]).setMuted(muted); //Send the message to the sender based upon whether they are muted or unmuted if(muted) diff --git a/src/main/java/com/graywolf336/jail/command/subcommands/JailPayCommand.java b/src/main/java/com/graywolf336/jail/command/subcommands/JailPayCommand.java index 4670a11..9740939 100644 --- a/src/main/java/com/graywolf336/jail/command/subcommands/JailPayCommand.java +++ b/src/main/java/com/graywolf336/jail/command/subcommands/JailPayCommand.java @@ -31,8 +31,8 @@ public class JailPayCommand implements Command { case 1: // `/jail pay` //send how much it costs to get out - if(jm.isPlayerJailed(sender.getName())) { - Prisoner p = jm.getPrisoner(sender.getName()); + if(jm.isPlayerJailedByLastKnownUsername(sender.getName())) { + Prisoner p = jm.getPrisonerByLastKnownName(sender.getName()); String amt = ""; if(pm.usingItemsForPayment()) { @@ -64,8 +64,8 @@ public class JailPayCommand implements Command { case 2: // `/jail pay ` //They are trying to pay for their self - if(jm.isPlayerJailed(sender.getName())) { - Prisoner p = jm.getPrisoner(sender.getName()); + if(jm.isPlayerJailedByLastKnownUsername(sender.getName())) { + Prisoner p = jm.getPrisonerByLastKnownName(sender.getName()); if(p.getRemainingTime() > 0) { if(!pm.isTimedEnabled()) { @@ -129,12 +129,12 @@ public class JailPayCommand implements Command { case 3: // `/jail pay //they are trying to pay for someone else - if(jm.isPlayerJailed(sender.getName())) { + if(jm.isPlayerJailedByLastKnownUsername(sender.getName())) { //When they are jailed they can not pay for someone else sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYCANTPAYWHILEJAILED)); }else { - if(jm.isPlayerJailed(args[2])) { - Prisoner p = jm.getPrisoner(args[2]); + if(jm.isPlayerJailedByLastKnownUsername(args[2])) { + Prisoner p = jm.getPrisonerByLastKnownName(args[2]); if(p.getRemainingTime() > 0) { if(!pm.isTimedEnabled()) { @@ -168,21 +168,21 @@ public class JailPayCommand implements Command { //timed sentence if(amt >= bill) { pm.pay((Player) sender, bill); - sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDRELEASEDELSE, new String[] { String.valueOf(bill), p.getName() })); - jm.getPlugin().getPrisonerManager().releasePrisoner(jm.getPlugin().getServer().getPlayerExact(p.getName()), p); + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDRELEASEDELSE, new String[] { String.valueOf(bill), p.getLastKnownName() })); + jm.getPlugin().getPrisonerManager().releasePrisoner(jm.getPlugin().getServer().getPlayer(p.getUUID()), p); }else { long minutes = pm.getMinutesPayingFor(amt); pm.pay((Player) sender, amt); long remain = p.subtractTime(TimeUnit.MILLISECONDS.convert(minutes, TimeUnit.MINUTES)); sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDLOWEREDTIMEELSE, - new String[] { String.valueOf(amt), p.getName(), String.valueOf(TimeUnit.MINUTES.convert(remain, TimeUnit.MILLISECONDS)) })); + new String[] { String.valueOf(amt), p.getLastKnownName(), String.valueOf(TimeUnit.MINUTES.convert(remain, TimeUnit.MILLISECONDS)) })); } }else { //infinite jailing if(amt >= bill) { pm.pay((Player) sender, bill); - sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDRELEASEDELSE, new String[] { String.valueOf(bill), p.getName() })); - jm.getPlugin().getPrisonerManager().releasePrisoner(jm.getPlugin().getServer().getPlayerExact(p.getName()), p); + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDRELEASEDELSE, new String[] { String.valueOf(bill), p.getLastKnownName() })); + jm.getPlugin().getPrisonerManager().releasePrisoner(jm.getPlugin().getServer().getPlayer(p.getUUID()), p); }else { //You haven't provided enough money to get them out sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENOUGHMONEYPROVIDED)); diff --git a/src/main/java/com/graywolf336/jail/command/subcommands/JailStatusCommand.java b/src/main/java/com/graywolf336/jail/command/subcommands/JailStatusCommand.java index 8493b37..9e9d598 100644 --- a/src/main/java/com/graywolf336/jail/command/subcommands/JailStatusCommand.java +++ b/src/main/java/com/graywolf336/jail/command/subcommands/JailStatusCommand.java @@ -13,7 +13,7 @@ import com.graywolf336.jail.enums.LangString; maxArgs = 0, minimumArgs = 0, needsPlayer = true, - pattern = "status|time", + pattern = "status|s", permission = "jail.usercmd.jailstatus", usage = "/jail status" ) diff --git a/src/main/java/com/graywolf336/jail/command/subcommands/JailStopCommand.java b/src/main/java/com/graywolf336/jail/command/subcommands/JailStopCommand.java index f935918..1dbbe56 100644 --- a/src/main/java/com/graywolf336/jail/command/subcommands/JailStopCommand.java +++ b/src/main/java/com/graywolf336/jail/command/subcommands/JailStopCommand.java @@ -11,7 +11,7 @@ import com.graywolf336.jail.command.CommandInfo; maxArgs = 0, minimumArgs = 0, needsPlayer = true, - pattern = "stop|s", + pattern = "stop", permission = "jail.command.jailstop", usage = "/jail stop" ) diff --git a/src/main/java/com/graywolf336/jail/command/subcommands/JailTimeCommand.java b/src/main/java/com/graywolf336/jail/command/subcommands/JailTimeCommand.java index 1efae8a..bbeb82e 100644 --- a/src/main/java/com/graywolf336/jail/command/subcommands/JailTimeCommand.java +++ b/src/main/java/com/graywolf336/jail/command/subcommands/JailTimeCommand.java @@ -19,14 +19,14 @@ import com.graywolf336.jail.enums.LangString; ) public class JailTimeCommand implements Command { public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception { - if(jm.isPlayerJailed(args[2])) { - Prisoner p = jm.getPrisoner(args[2]); + if(jm.isPlayerJailedByLastKnownUsername(args[2])) { + Prisoner p = jm.getPrisonerByLastKnownName(args[2]); switch(args.length) { case 3: if(args[1].equalsIgnoreCase("show")) { sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PRISONERSTIME, - new String[] { p.getName(), String.valueOf(p.getRemainingTimeInMinutes()) })); + new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) })); }else { return false; } @@ -41,7 +41,7 @@ public class JailTimeCommand implements Command { } sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PRISONERSTIME, - new String[] { p.getName(), String.valueOf(p.getRemainingTimeInMinutes()) })); + new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) })); break; default: return false; diff --git a/src/main/java/com/graywolf336/jail/command/subcommands/JailTransferAllCommand.java b/src/main/java/com/graywolf336/jail/command/subcommands/JailTransferAllCommand.java index 7603e5d..e34f43f 100644 --- a/src/main/java/com/graywolf336/jail/command/subcommands/JailTransferAllCommand.java +++ b/src/main/java/com/graywolf336/jail/command/subcommands/JailTransferAllCommand.java @@ -45,7 +45,7 @@ public class JailTransferAllCommand implements Command { //Transfer all the prisoners for(Prisoner p : oldPrisoners) { - jm.getPlugin().getPrisonerManager().transferPrisoner(old, old.getCellPrisonerIsIn(p.getName()), jm.getJail(args[2]), null, p); + jm.getPlugin().getPrisonerManager().transferPrisoner(old, old.getCellPrisonerIsIn(p.getUUID()), jm.getJail(args[2]), null, p); } //Send the messages to the sender when completed diff --git a/src/main/java/com/graywolf336/jail/command/subcommands/JailTransferCommand.java b/src/main/java/com/graywolf336/jail/command/subcommands/JailTransferCommand.java index 8e418ef..dce3dd2 100644 --- a/src/main/java/com/graywolf336/jail/command/subcommands/JailTransferCommand.java +++ b/src/main/java/com/graywolf336/jail/command/subcommands/JailTransferCommand.java @@ -10,6 +10,7 @@ import org.bukkit.command.CommandSender; import com.graywolf336.jail.JailManager; import com.graywolf336.jail.beans.Cell; import com.graywolf336.jail.beans.Jail; +import com.graywolf336.jail.beans.Prisoner; import com.graywolf336.jail.command.Command; import com.graywolf336.jail.command.CommandInfo; import com.graywolf336.jail.command.commands.jewels.Transfer; @@ -52,7 +53,7 @@ public class JailTransferCommand implements Command { if(params.getPlayer() == null) { sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PROVIDEAPLAYER, LangString.TRANSFERRING)); return true; - }else if(!jm.isPlayerJailed(params.getPlayer())) { + }else if(!jm.isPlayerJailedByLastKnownUsername(params.getPlayer())) { sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, params.getPlayer())); return true; } @@ -102,11 +103,12 @@ public class JailTransferCommand implements Command { } jm.getPlugin().debug("Calling the PrePrisonerTransferredEvent, jail and cell check all came out clean."); + Prisoner p = jm.getPrisonerByLastKnownName(params.getPlayer()); //Throw the custom event before transferring them, allowing another plugin to cancel it. - PrePrisonerTransferredEvent event = new PrePrisonerTransferredEvent(jm.getJailPlayerIsIn(params.getPlayer()), - jm.getJailPlayerIsIn(params.getPlayer()).getCellPrisonerIsIn(params.getPlayer()), - target, targetCell, jm.getPrisoner(params.getPlayer()), jm.getPlugin().getServer().getPlayer(params.getPlayer()), sender.getName()); + PrePrisonerTransferredEvent event = new PrePrisonerTransferredEvent(jm.getJailPlayerIsIn(p.getUUID()), + jm.getJailPlayerIsIn(p.getUUID()).getCellPrisonerIsIn(p.getUUID()), + target, targetCell, p, jm.getPlugin().getServer().getPlayer(p.getUUID()), sender.getName()); jm.getPlugin().getServer().getPluginManager().callEvent(event); if(event.isCancelled()) { @@ -121,9 +123,9 @@ public class JailTransferCommand implements Command { } //Start the transferring of the prisoner - jm.getPlugin().getPrisonerManager().transferPrisoner(jm.getJailPlayerIsIn(params.getPlayer()), - jm.getJailPlayerIsIn(params.getPlayer()).getCellPrisonerIsIn(params.getPlayer()), - target, targetCell, jm.getPrisoner(params.getPlayer())); + jm.getPlugin().getPrisonerManager().transferPrisoner(jm.getJailPlayerIsIn(p.getUUID()), + jm.getJailPlayerIsIn(p.getUUID()).getCellPrisonerIsIn(p.getUUID()), + target, targetCell, p); //Send the messages to the sender, if no cell then say that but if cell send that as well if(targetCell == null) { diff --git a/src/main/java/com/graywolf336/jail/legacy/LegacyManager.java b/src/main/java/com/graywolf336/jail/legacy/LegacyManager.java index 3c6b796..27dc2ff 100644 --- a/src/main/java/com/graywolf336/jail/legacy/LegacyManager.java +++ b/src/main/java/com/graywolf336/jail/legacy/LegacyManager.java @@ -53,8 +53,6 @@ public class LegacyManager { } catch (InvalidConfigurationException e) { //e.printStackTrace(); pl.getLogger().severe("Unable to load the old global config: " + e.getMessage()); - }finally { - } }else { pl.debug("The old config file, global.yml, was not found so not loading anything."); @@ -62,9 +60,11 @@ public class LegacyManager { } try { + pl.getLogger().info("Starting to convert Jail 2.x data to Jail 3.0, this does use a blocking call (getOfflinePlayer) so expect the server to be held up until we are finished..."); loadOldConfig(); loadOldData(); moveOldConfigs(); + pl.getLogger().info("...finished converting configs and data."); return true; }catch (Exception e) { if(pl.inDebug()) { diff --git a/src/main/java/com/graywolf336/jail/legacy/OldInputOutput.java b/src/main/java/com/graywolf336/jail/legacy/OldInputOutput.java index e653a38..7aafc8e 100644 --- a/src/main/java/com/graywolf336/jail/legacy/OldInputOutput.java +++ b/src/main/java/com/graywolf336/jail/legacy/OldInputOutput.java @@ -162,7 +162,7 @@ public class OldInputOutput { if(j == null) { pl.getLogger().warning("Refusing to load a cell (" + name + ") as it references a Jail which doesn't exist."); - }else if(j.getCell(name) != null) { + }else if(j.isValidCell(name)) { pl.getLogger().warning("Refusing to load a duplicate named cell, " + name + ", as another one exists with that same name."); } else { Cell c = new Cell(name); @@ -187,7 +187,7 @@ public class OldInputOutput { //Load the prisoner if he is a valid prisoner if(!player.isEmpty()) { - Prisoner p = j.getPrisoner(name); + Prisoner p = j.getPrisonerByLastKnownName(name); if(p != null) { c.setPrisoner(p); diff --git a/src/main/java/com/graywolf336/jail/listeners/JailingListener.java b/src/main/java/com/graywolf336/jail/listeners/JailingListener.java index d1d4b02..9a0bddc 100644 --- a/src/main/java/com/graywolf336/jail/listeners/JailingListener.java +++ b/src/main/java/com/graywolf336/jail/listeners/JailingListener.java @@ -24,7 +24,7 @@ public class JailingListener implements Listener { @EventHandler(ignoreCancelled=true) public void preJailingListener(PrePrisonerJailedEvent event) { pl.getJailIO().addRecordEntry(event.getPrisoner().getUUID().toString(), - event.getPrisoner().getName(), + event.getPrisoner().getLastKnownName(), event.getPrisoner().getJailer(), dateFormat.format(new Date()), event.getPrisoner().getRemainingTimeInMinutes(), event.getPrisoner().getReason()); } @@ -32,7 +32,7 @@ public class JailingListener implements Listener { @EventHandler(ignoreCancelled=true) public void preJailingListener(PrePrisonerJailedByJailStickEvent event) { pl.getJailIO().addRecordEntry(event.getPrisoner().getUUID().toString(), - event.getPrisoner().getName(), + event.getPrisoner().getLastKnownName(), event.getPrisoner().getJailer(), dateFormat.format(new Date()), event.getPrisoner().getRemainingTimeInMinutes(), event.getPrisoner().getReason()); } diff --git a/src/main/java/com/graywolf336/jail/listeners/PlayerListener.java b/src/main/java/com/graywolf336/jail/listeners/PlayerListener.java index 3a9ac23..7c33f8f 100644 --- a/src/main/java/com/graywolf336/jail/listeners/PlayerListener.java +++ b/src/main/java/com/graywolf336/jail/listeners/PlayerListener.java @@ -92,6 +92,8 @@ public class PlayerListener implements Listener { //Get the prisoner object Jail j = pl.getJailManager().getJailPlayerIsIn(event.getPlayer().getUniqueId()); Prisoner p = j.getPrisoner(event.getPlayer().getUniqueId()); + //update their last known username when they login + p.setLastKnownName(event.getPlayer().getName()); //Check if they're offline pending, as if this is true then they were jailed offline if(p.isOfflinePending()) { @@ -226,11 +228,11 @@ public class PlayerListener implements Listener { //Player is not online if(player == null) { attacker.sendMessage(pl.getJailIO().getLanguageString(LangString.OFFLINEJAIL, - new String[] { p.getName(), String.valueOf(p.getRemainingTimeInMinutes()) })); + new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) })); }else { //Player *is* online attacker.sendMessage(pl.getJailIO().getLanguageString(LangString.ONLINEJAIL, - new String[] { p.getName(), String.valueOf(p.getRemainingTimeInMinutes()) })); + new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) })); } try {