Advertisement
Guest User

Untitled

a guest
May 3rd, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 745.81 KB | None | 0 0
  1. diff --git a/src/net/innectis/innplugin/BanSystem/BanHandler.java b/src/net/innectis/innplugin/BanSystem/BanHandler.java
  2. index 17bcb5e2b..6b767e729 100644
  3. --- a/src/net/innectis/innplugin/BanSystem/BanHandler.java
  4. +++ b/src/net/innectis/innplugin/BanSystem/BanHandler.java
  5. @@ -5,10 +5,13 @@ import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.sql.Timestamp;
  8. import java.util.*;
  9. +import net.innectis.innplugin.Configuration;
  10. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  11. +import net.innectis.innplugin.IdpCommandSender;
  12. import net.innectis.innplugin.InnPlugin;
  13. import net.innectis.innplugin.Player.Chat.ChatColor;
  14. -import net.innectis.innplugin.Player.IdpPlayer;
  15. +import net.innectis.innplugin.Player.PlayerCredentials;
  16. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  17. import net.innectis.innplugin.Player.PlayerGroup;
  18.  
  19. /**
  20. @@ -20,67 +23,59 @@ public class BanHandler {
  21.  
  22. private static List<BanObject> bannedPlayers = new ArrayList<BanObject>();
  23. // Includes all the whitelisted players (Wrongfully IPBanned players)
  24. - private static List<String> whitelistPlayers = new ArrayList<String>();
  25. + private static List<PlayerCredentials> whitelistedPlayers = new ArrayList<PlayerCredentials>();
  26.  
  27. private BanHandler() {
  28. }
  29.  
  30. /**
  31. * Adds a user to the ban whitelist
  32. - * @param player
  33. + * @param credentials
  34. */
  35. - public static void addWhitelist(String player) {
  36. - if (!whitelistPlayers.contains(player)) {
  37. - whitelistPlayers.add(player);
  38. -
  39. - PreparedStatement statement = null;
  40. -
  41. - try {
  42. - statement = DBManager.prepareStatement("INSERT INTO ban_whitelist VALUES (?)");
  43. - statement.setString(1, player);
  44. - statement.execute();
  45. - } catch (SQLException ex) {
  46. - InnPlugin.logError("Unable to add whitelisted player to the database!", ex);
  47. - } finally {
  48. - DBManager.closePreparedStatement(statement);
  49. - }
  50. + public static void addWhitelist(PlayerCredentials credentials) {
  51. + whitelistedPlayers.add(credentials);
  52. +
  53. + PreparedStatement statement = null;
  54. +
  55. + try {
  56. + statement = DBManager.prepareStatement("INSERT INTO ban_whitelist (player_id) VALUES (?);");
  57. + statement.setString(1, credentials.getUniqueId().toString());
  58. + statement.execute();
  59. + } catch (SQLException ex) {
  60. + InnPlugin.logError("Unable to add whitelisted player to the database!", ex);
  61. + } finally {
  62. + DBManager.closePreparedStatement(statement);
  63. }
  64. }
  65.  
  66. /**
  67. * Removes a player from the ban whitelist
  68. - * @param player
  69. + * @param credentials
  70. */
  71. - public static void removeWhitelist(String player) {
  72. - for (String name : whitelistPlayers) {
  73. - if (name.equalsIgnoreCase(player)) {
  74. - whitelistPlayers.remove(name);
  75. -
  76. - PreparedStatement statement = null;
  77. -
  78. - try {
  79. - statement = DBManager.prepareStatement("DELETE FROM ban_whitelist WHERE name = ?");
  80. - statement.setString(1, player);
  81. - statement.execute();
  82. - } catch (SQLException ex) {
  83. - InnPlugin.logError("Unable to remove whitelisted player from the database!", ex);
  84. - } finally {
  85. - DBManager.closePreparedStatement(statement);
  86. - }
  87. + public static void removeWhitelist(PlayerCredentials credentials) {
  88. + whitelistedPlayers.remove(credentials);
  89.  
  90. - return;
  91. - }
  92. + PreparedStatement statement = null;
  93. +
  94. + try {
  95. + statement = DBManager.prepareStatement("DELETE FROM ban_whitelist WHERE player_id = ?");
  96. + statement.setString(1, credentials.getUniqueId().toString());
  97. + statement.execute();
  98. + } catch (SQLException ex) {
  99. + InnPlugin.logError("Unable to remove whitelisted player " + credentials.getName() + " from the database!", ex);
  100. + } finally {
  101. + DBManager.closePreparedStatement(statement);
  102. }
  103. }
  104.  
  105. /**
  106. - * Checks to see if a player is whitelisted on the ban list
  107. - * @param name
  108. + * Checks to see if a player is on the ban whitelist by their unique id
  109. + * @param playerId
  110. * @return
  111. */
  112. - public static boolean isWhitelisted(String name) {
  113. - for (String user : whitelistPlayers) {
  114. - if (user.equalsIgnoreCase(name)) {
  115. + public static boolean isWhitelisted(UUID playerId) {
  116. + for (PlayerCredentials pc : whitelistedPlayers) {
  117. + if (pc.getUniqueId().equals(playerId)) {
  118. return true;
  119. }
  120. }
  121. @@ -89,11 +84,11 @@ public class BanHandler {
  122. }
  123.  
  124. /**
  125. - * Gets the whitelist as an unmodifiable list
  126. + * Gets the whitelist as an unmodifiable list of player credentials
  127. * @return
  128. */
  129. - public static List<String> getWhitelist() {
  130. - return Collections.unmodifiableList(whitelistPlayers);
  131. + public static List<PlayerCredentials> getWhitelist() {
  132. + return Collections.unmodifiableList(whitelistedPlayers);
  133. }
  134.  
  135. /**
  136. @@ -108,7 +103,10 @@ public class BanHandler {
  137. set = statement.executeQuery();
  138.  
  139. while (set.next()) {
  140. - whitelistPlayers.add(set.getString("name"));
  141. + String playerId = set.getString("player_id");
  142. + UUID uuid = UUID.fromString(playerId);
  143. + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(uuid, true);
  144. + whitelistedPlayers.add(credentials);
  145. }
  146. } catch (SQLException ex) {
  147. InnPlugin.logError("Unable to load ban whitelist!", ex);
  148. @@ -119,17 +117,17 @@ public class BanHandler {
  149. }
  150.  
  151. /**
  152. - * Gets the ban type of the specified username, or IP
  153. - * @param username
  154. + * Gets the ban type from the player's unique ID or IP
  155. + * @param playerId
  156. * @param ip
  157. * @return
  158. */
  159. - public static BanTypes getBanType(String username, String ip) {
  160. - if (isWhitelisted(username)) {
  161. + public static BanTypes getBanType(UUID playerId, String ip) {
  162. + if (isWhitelisted(playerId)) {
  163. return BanTypes.WHITELISTED;
  164. }
  165.  
  166. - BanObject ban = getBan(username);
  167. + BanObject ban = getBan(playerId);
  168.  
  169. if (ban != null) {
  170. if (ban.isJoinBan()) {
  171. @@ -138,10 +136,8 @@ public class BanHandler {
  172. } else if (ban instanceof IPBanObject) {
  173. return BanTypes.BANNED_JOINBAN_IP;
  174. }
  175. - } else if (!ban.isIndefiniteBan() && new Timestamp(System.currentTimeMillis()).after(ban.getUnbanTime())) {
  176. + } else if (!ban.isIndefiniteBan() && new Timestamp(System.currentTimeMillis()).after(ban.getExpireTime())) {
  177. bannedPlayers.remove(ban);
  178. -
  179. - // Same method that inherited from the parent you can just call that.
  180. ban.delete();
  181.  
  182. return BanTypes.UNBANNED;
  183. @@ -159,27 +155,28 @@ public class BanHandler {
  184.  
  185. /**
  186. * Links a username and ip to an existing username's ip ban
  187. - * @param username
  188. + * @param creator
  189. + * @param bannedPlayerCredentials
  190. * @param ip
  191. - * @param linkedUsername
  192. + * @param linkedPlayerCredentials
  193. * @return Whether the name was linked to an existing ip ban or not
  194. */
  195. - public static LinkStatus linkIPBan(IdpPlayer creator, String username, String ip, String linkedUsername) {
  196. + public static LinkStatus linkIPBan(IdpCommandSender creator, PlayerCredentials bannedPlayerCredentials, String ip, PlayerCredentials linkedPlayerCredentials) {
  197. for (BanObject ban : bannedPlayers) {
  198. if (ban instanceof IPBanObject) {
  199. IPBanObject ipban = (IPBanObject) ban;
  200. IPBanGroup group = ipban.getGroup();
  201.  
  202. - if (group.containsPlayer(linkedUsername)) {
  203. - if (creator != null && !ban.canModifyBan(creator)) {
  204. + if (group.containsPlayerId(linkedPlayerCredentials.getUniqueId())) {
  205. + if (!ban.canModifyBan(creator)) {
  206. return LinkStatus.LINK_NOT_CREATOR;
  207. }
  208.  
  209. - if (group.containsPlayer(username)) {
  210. + if (group.containsPlayerId(bannedPlayerCredentials.getUniqueId())) {
  211. return LinkStatus.LINK_SAME_USER;
  212. }
  213.  
  214. - group.addPlayer(username);
  215. + group.addPlayer(bannedPlayerCredentials);
  216. group.addIP(ip);
  217. ipban.save();
  218. return LinkStatus.LINK_SUCCESSFUL;
  219. @@ -192,22 +189,23 @@ public class BanHandler {
  220.  
  221. /**
  222. * Unlinks a username and ip from an existing IPBan
  223. - * @param username
  224. + * @param creator
  225. + * @param credentials
  226. * @param ip
  227. * @return Whether the username was unlinked from an existing ip ban
  228. */
  229. - public static UnlinkStatus unlinkIPBan(IdpPlayer creator, String username, String ip) {
  230. + public static UnlinkStatus unlinkIPBan(IdpCommandSender creator, PlayerCredentials credentials, String ip) {
  231. for (BanObject ban : bannedPlayers) {
  232. if (ban instanceof IPBanObject) {
  233. IPBanObject ipban = (IPBanObject) ban;
  234. IPBanGroup group = ipban.getGroup();
  235.  
  236. - if (group.containsPlayer(username)) {
  237. - if (creator != null && !ban.canModifyBan(creator)) {
  238. + if (group.containsPlayerId(credentials.getUniqueId())) {
  239. + if (!ban.canModifyBan(creator)) {
  240. return UnlinkStatus.UNLINK_NOT_CREATOR;
  241. }
  242.  
  243. - group.removePlayer(username);
  244. + group.removePlayer(credentials);
  245. group.removeIP(ip);
  246.  
  247. // No more players or IPs, so just remove the ban entirely
  248. @@ -282,33 +280,29 @@ public class BanHandler {
  249. }
  250.  
  251. /**
  252. - * Gets the ban object of the user
  253. - * @param username
  254. - * @param ip
  255. + * Gets the ban object from the specified player ID, if available
  256. + * @param playerId
  257. * @return
  258. */
  259. - public static BanObject getBan(String username) {
  260. - BanObject ban = null;
  261. -
  262. + public static BanObject getBan(UUID playerId) {
  263. for (BanObject banobj : bannedPlayers) {
  264. if (banobj instanceof UserBanObject) {
  265. UserBanObject userban = (UserBanObject) banobj;
  266. + PlayerCredentials bannedPlayerCredentials = userban.getBannedPlayerCredentials();
  267.  
  268. - if (userban.getUsername().equalsIgnoreCase(username)) {
  269. - ban = userban;
  270. - break;
  271. + if (bannedPlayerCredentials.getUniqueId().equals(playerId)) {
  272. + return banobj;
  273. }
  274. } else if (banobj instanceof IPBanObject) {
  275. IPBanObject ipban = (IPBanObject) banobj;
  276.  
  277. - if (ipban.getGroup().containsPlayer(username)) {
  278. - ban = ipban;
  279. - break;
  280. + if (ipban.getGroup().containsPlayerId(playerId)) {
  281. + return banobj;
  282. }
  283. }
  284. }
  285.  
  286. - return ban;
  287. + return null;
  288. }
  289.  
  290. /**
  291. @@ -331,7 +325,7 @@ public class BanHandler {
  292. if (b instanceof UserBanObject) {
  293. UserBanObject ub = (UserBanObject) b;
  294.  
  295. - if (ub.getUsername().equalsIgnoreCase(userban.getUsername())) {
  296. + if (ub.getBannedPlayerCredentials().equals(userban.getBannedPlayerCredentials())) {
  297. ub.setAttributesFrom(ban);
  298. ub.save();
  299. type = BanResult.BAN_EXISTING;
  300. @@ -339,7 +333,6 @@ public class BanHandler {
  301. break;
  302. }
  303. }
  304. -
  305. }
  306.  
  307. // If there is no existing ban, just save this, and add it to the
  308. @@ -400,18 +393,31 @@ public class BanHandler {
  309. ResultSet set = null;
  310.  
  311. try {
  312. - statement = DBManager.prepareStatement("SELECT * FROM banned_players WHERE expired = 0");
  313. + statement = DBManager.prepareStatement("SELECT * FROM banned_players WHERE expired = 0;");
  314. set = statement.executeQuery();
  315.  
  316. while (set.next()) {
  317. int id = set.getInt("ID");
  318. - String username = set.getString("username");
  319. - String bannedBy = set.getString("banned_by");
  320. +
  321. + String playerId = set.getString("player_id");
  322. + UUID uuid = UUID.fromString(playerId);
  323. + PlayerCredentials player = PlayerCredentialsManager.getByUniqueId(uuid, true);
  324. +
  325. + String bannedByPlayerId = set.getString("banned_by_player_id");
  326. + UUID bannedByUUID = UUID.fromString(bannedByPlayerId);
  327. + PlayerCredentials bannedByPlayerCredentials = null;
  328. +
  329. + if (bannedByUUID.equals(Configuration.SERVER_GENERATED_IDENTIFIER)) {
  330. + bannedByPlayerCredentials = Configuration.SERVER_GENERATED_CREDENTIALS;
  331. + } else {
  332. + bannedByPlayerCredentials = PlayerCredentialsManager.getByUniqueId(bannedByUUID, true);
  333. + }
  334. +
  335. Timestamp bannedTime = set.getTimestamp("banned_time");
  336. long durationTicks = set.getLong("duration_ticks");
  337. boolean joinBan = set.getBoolean("joinban");
  338.  
  339. - UserBanObject userban = new UserBanObject(id, username, bannedBy, bannedTime, durationTicks, joinBan);
  340. + UserBanObject userban = new UserBanObject(id, player, bannedByPlayerCredentials, bannedTime, durationTicks, joinBan);
  341. bannedPlayers.add(userban);
  342. }
  343. } catch (SQLException ex) {
  344. @@ -424,36 +430,50 @@ public class BanHandler {
  345. InnPlugin.logInfo("Loading ipbanned players...");
  346.  
  347. try {
  348. - statement = DBManager.prepareStatement("SELECT * FROM banned_ip_players where expired = 0");
  349. + statement = DBManager.prepareStatement("SELECT * FROM banned_ip_players where expired = 0;");
  350. set = statement.executeQuery();
  351.  
  352. while (set.next()) {
  353. int id = set.getInt("ID");
  354. - String ipliststring = set.getString("iplist");
  355. - String userliststring = set.getString("userlist");
  356. - String bannedBy = set.getString("banned_by");
  357. + String ipListString = set.getString("iplist");
  358. + String playerIdString = set.getString("player_id_list");
  359. +
  360. + String bannedByPlayerId = set.getString("banned_by_player_id");
  361. + UUID bannedByPlayerUUID = UUID.fromString(bannedByPlayerId);
  362. + PlayerCredentials bannedByPlayerCredentials = null;
  363. +
  364. + if (bannedByPlayerUUID.equals(Configuration.SERVER_GENERATED_IDENTIFIER)) {
  365. + bannedByPlayerCredentials = Configuration.SERVER_GENERATED_CREDENTIALS;
  366. + } else {
  367. + bannedByPlayerCredentials = PlayerCredentialsManager.getByUniqueId(bannedByPlayerUUID, true);
  368. + }
  369. +
  370. Timestamp bannedTime = set.getTimestamp("banned_time");
  371. long durationTicks = set.getLong("duration_ticks");
  372. boolean joinBan = set.getBoolean("joinban");
  373.  
  374. List<String> ipList;
  375. - if (ipliststring != null && !ipliststring.isEmpty()) {
  376. - //String[] aryIPList = ipliststring.split(", ");
  377. - ipList = new ArrayList<String>(Arrays.asList(ipliststring.split(", ")));
  378. +
  379. + if (ipListString != null && !ipListString.isEmpty()) {
  380. + ipList = new ArrayList<String>(Arrays.asList(ipListString.split(", ")));
  381. } else {
  382. ipList = new ArrayList<String>(1);
  383. }
  384.  
  385. - List<String> userList;
  386. - if (userliststring != null && !userliststring.isEmpty()) {
  387. - //String[] aryUserList = userliststring.split(", ");
  388. - userList = new ArrayList<String>(Arrays.asList(userliststring.split(", ")));
  389. + List<PlayerCredentials> playerList = new ArrayList<PlayerCredentials>();
  390. +
  391. + if (playerIdString != null && !playerIdString.isEmpty()) {
  392. + for (String playerId : playerIdString.split(", ")) {
  393. + UUID playerUUID = UUID.fromString(playerId);
  394. + PlayerCredentials player = PlayerCredentialsManager.getByUniqueId(playerUUID, true);
  395. + playerList.add(player);
  396. + }
  397. } else {
  398. - userList = new ArrayList<String>(1);
  399. + playerList = new ArrayList<PlayerCredentials>(1);
  400. }
  401.  
  402. - IPBanGroup group = new IPBanGroup(ipList, userList);
  403. - IPBanObject ipban = new IPBanObject(id, group, bannedBy, bannedTime, durationTicks, joinBan);
  404. + IPBanGroup group = new IPBanGroup(ipList, playerList);
  405. + IPBanObject ipban = new IPBanObject(id, group, bannedByPlayerCredentials, bannedTime, durationTicks, joinBan);
  406. bannedPlayers.add(ipban);
  407. }
  408. } catch (SQLException ex) {
  409. @@ -466,33 +486,35 @@ public class BanHandler {
  410.  
  411. /**
  412. * Gets the full username of a partial username
  413. - * @param username
  414. + * @param checkPlayer
  415. * @return
  416. */
  417. - public static String getPartialName(String username) {
  418. + public static String getPartialName(String checkPlayer) {
  419. for (BanObject ban : Collections.synchronizedList(bannedPlayers)) {
  420. if (ban instanceof UserBanObject) {
  421. UserBanObject userban = (UserBanObject) ban;
  422. - int minLen = Math.min(username.length(), userban.getUsername().length());
  423. + String playerName = userban.getBannedPlayerCredentials().getName();
  424. + int minLen = Math.min(checkPlayer.length(), playerName.length());
  425.  
  426. - if (userban.getUsername().substring(0, minLen).equalsIgnoreCase(username)) {
  427. - return userban.getUsername();
  428. + if (playerName.substring(0, minLen).equalsIgnoreCase(checkPlayer)) {
  429. + return playerName;
  430. }
  431. } else if (ban instanceof IPBanObject) {
  432. IPBanObject ipban = (IPBanObject) ban;
  433. - List<String> usernames = ipban.getGroup().getPlayers();
  434. + List<PlayerCredentials> players = ipban.getGroup().getPlayers();
  435.  
  436. - for (String user : usernames) {
  437. - int minLen = Math.min(user.length(), username.length());
  438. + for (PlayerCredentials player : players) {
  439. + String name = player.getName();
  440. + int minLen = Math.min(name.length(), checkPlayer.length());
  441.  
  442. - if (user.substring(0, minLen).equalsIgnoreCase(username)) {
  443. - return user;
  444. + if (name.substring(0, minLen).equalsIgnoreCase(checkPlayer)) {
  445. + return name;
  446. }
  447. }
  448. }
  449. }
  450.  
  451. - return username;
  452. + return checkPlayer;
  453. }
  454.  
  455. /**
  456. @@ -514,8 +536,9 @@ public class BanHandler {
  457. int idx = 1;
  458.  
  459. for (BanObject ban : Collections.synchronizedList(bannedPlayers)) {
  460. - String bannedBy = ban.getBannedBy();
  461. - PlayerGroup bannedByGroup = PlayerGroup.getGroupOfUsername(bannedBy);
  462. + PlayerCredentials bannedByCredentials = ban.getBannedByCredentials();
  463. + String bannedBy = ban.getBannedByCredentials().getName();
  464. + PlayerGroup bannedByGroup = PlayerGroup.getGroupOfPlayerById(bannedByCredentials.getUniqueId());
  465. String bannedByUserWithGroup = bannedByGroup.getPrefix().getTextColor() + bannedBy;
  466.  
  467. String bannedTime = "";
  468. @@ -533,8 +556,9 @@ public class BanHandler {
  469. if (ban instanceof UserBanObject) {
  470. UserBanObject userban = (UserBanObject) ban;
  471.  
  472. - String username = userban.getUsername();
  473. - PlayerGroup userGroup = PlayerGroup.getGroupOfUsername(username);
  474. + PlayerCredentials bannedPlayerCredentials = userban.getBannedPlayerCredentials();
  475. + String username = bannedPlayerCredentials.getName();
  476. + PlayerGroup userGroup = PlayerGroup.getGroupOfPlayerById(bannedPlayerCredentials.getUniqueId());
  477. String bannedUserWithGroup = userGroup.getPrefix().getTextColor() + username;
  478. String banString = bannedUserWithGroup + " (" + banAttributes + ")";
  479.  
  480. @@ -552,8 +576,9 @@ public class BanHandler {
  481.  
  482. String coloredUsernames = "";
  483.  
  484. - for (String name : group.getPlayers()) {
  485. - PlayerGroup pGroup = PlayerGroup.getGroupOfUsername(name);
  486. + for (PlayerCredentials pc : group.getPlayers()) {
  487. + String name = pc.getName();
  488. + PlayerGroup pGroup = PlayerGroup.getGroupOfPlayerById(pc.getUniqueId());
  489. String nameWithGroup = pGroup.getPrefix().getTextColor() + name;
  490.  
  491. if (coloredUsernames.isEmpty()) {
  492. diff --git a/src/net/innectis/innplugin/BanSystem/BanObject.java b/src/net/innectis/innplugin/BanSystem/BanObject.java
  493. index 43267ce50..d757cae88 100644
  494. --- a/src/net/innectis/innplugin/BanSystem/BanObject.java
  495. +++ b/src/net/innectis/innplugin/BanSystem/BanObject.java
  496. @@ -1,8 +1,10 @@
  497. package net.innectis.innplugin.BanSystem;
  498.  
  499. import java.sql.Timestamp;
  500. +import net.innectis.innplugin.IdpCommandSender;
  501. import net.innectis.innplugin.Player.IdpPlayer;
  502. import net.innectis.innplugin.Player.Permission;
  503. +import net.innectis.innplugin.Player.PlayerCredentials;
  504. import net.innectis.innplugin.Utility.DateUtil;
  505.  
  506. /**
  507. @@ -13,22 +15,14 @@ import net.innectis.innplugin.Utility.DateUtil;
  508. */
  509. public abstract class BanObject {
  510. private int id;
  511. - private String bannedBy;
  512. + private PlayerCredentials bannedByCredentials;
  513. private Timestamp bannedTime;
  514. private long durationTicks;
  515. private boolean joinBan;
  516.  
  517. - /**
  518. - * New constructor to construct an abstract ban object (call from subclass)
  519. - * Called from
  520. - * @param bannedBy
  521. - * @param bannedTime
  522. - * @param durationTicks
  523. - * @param joinBan
  524. - */
  525. - public BanObject(int id, String bannedBy, Timestamp bannedTime, long durationTicks, boolean joinBan) {
  526. + public BanObject(int id, PlayerCredentials bannedByCredentials, Timestamp bannedTime, long durationTicks, boolean joinBan) {
  527. this.id = id;
  528. - this.bannedBy = bannedBy;
  529. + this.bannedByCredentials = bannedByCredentials;
  530. this.bannedTime = bannedTime;
  531. this.durationTicks = durationTicks;
  532. this.joinBan = joinBan;
  533. @@ -39,7 +33,7 @@ public abstract class BanObject {
  534. * @param ban
  535. */
  536. public void setAttributesFrom(BanObject ban) {
  537. - setBannedBy(ban.getBannedBy());
  538. + setBannedBy(ban.getBannedByCredentials());
  539. setBannedTime(ban.getBannedTime(), ban.getDurationTicks());
  540. setJoinBan(ban.isJoinBan());
  541. }
  542. @@ -61,37 +55,34 @@ public abstract class BanObject {
  543. }
  544.  
  545. /**
  546. - * Gets the person that made this ban
  547. + * Gets the credentials of the player that made this ban
  548. * @return
  549. */
  550. - public String getBannedBy() {
  551. - return bannedBy;
  552. + public PlayerCredentials getBannedByCredentials() {
  553. + return bannedByCredentials;
  554. }
  555.  
  556. /**
  557. - * Specifies whether the player may modify this ban
  558. - * @param player
  559. + * Specifies whether the specified sender may modify this ban. It can
  560. + * either be a player or the console
  561. + * @param sender
  562. * @return
  563. */
  564. - public boolean canModifyBan(IdpPlayer player) {
  565. - if (bannedBy.equalsIgnoreCase(player.getName())
  566. - || player.hasPermission(Permission.special_modifyban_otherowner)) {
  567. - return true;
  568. - }
  569. -
  570. - return false;
  571. + public boolean canModifyBan(IdpCommandSender sender) {
  572. + return (bannedByCredentials.getName().equalsIgnoreCase(sender.getName())
  573. + || sender.hasPermission(Permission.special_modifyban_otherowner));
  574. }
  575.  
  576. /**
  577. - * Sets who this ban was made by
  578. + * Sets the credentials of the player that made this ban
  579. * @param bannedBy
  580. */
  581. - public void setBannedBy(String bannedBy) {
  582. - this.bannedBy = bannedBy;
  583. + public void setBannedBy(PlayerCredentials bannedBy) {
  584. + this.bannedByCredentials = bannedBy;
  585. }
  586.  
  587. /**
  588. - * Gets the time the ban was first made
  589. + * Gets the time the ban was created
  590. * @return
  591. */
  592. public Timestamp getBannedTime() {
  593. @@ -110,7 +101,6 @@ public abstract class BanObject {
  594.  
  595. /**
  596. * Sets the new ban time of this ban
  597. - * @param bannedTime
  598. * @param durationTicks
  599. */
  600. public void setNewBannedTime(long durationTicks) {
  601. @@ -119,10 +109,10 @@ public abstract class BanObject {
  602. }
  603.  
  604. /**
  605. - * Gets the timestamp of a user's unban time
  606. + * Gets the timestamp of when this ban will expire
  607. * @return
  608. */
  609. - public Timestamp getUnbanTime() {
  610. + public Timestamp getExpireTime() {
  611. if (joinBan) {
  612. return (new Timestamp(System.currentTimeMillis() + durationTicks));
  613. }
  614. @@ -131,8 +121,8 @@ public abstract class BanObject {
  615. }
  616.  
  617. /**
  618. - * Gets the ban time as a time string
  619. - * @param time
  620. + * Gets the remaining expire time as a time string
  621. + * @param longversion
  622. * @return
  623. */
  624. public String getUnbanTimeString(boolean longversion) {
  625. @@ -140,7 +130,7 @@ public abstract class BanObject {
  626. }
  627.  
  628. /**
  629. - * Gets whether or not this ban is indefinite
  630. + * Gets if this ban is an indefinite ban
  631. * @return
  632. */
  633. public boolean isIndefiniteBan() {
  634. @@ -148,7 +138,7 @@ public abstract class BanObject {
  635. }
  636.  
  637. /**
  638. - * Gets whether or not this ban takes effect on next join
  639. + * Gets if this ban will take effect on the player's next join
  640. * @return
  641. */
  642. public boolean isJoinBan() {
  643. @@ -181,12 +171,10 @@ public abstract class BanObject {
  644. */
  645. public boolean isExpired() {
  646. return (!isIndefiniteBan() && System.currentTimeMillis() > (bannedTime.getTime() + durationTicks));
  647. - //return (!isPermBan() && new Timestamp(System.currentTimeMillis()).after(new Timestamp(bannedTime.getTime() + durationTicks)));
  648. }
  649.  
  650. /**
  651. * Saves this ban object (implementation is object specific)
  652. - * @param update
  653. */
  654. public abstract void save();
  655.  
  656. diff --git a/src/net/innectis/innplugin/BanSystem/IPBanGroup.java b/src/net/innectis/innplugin/BanSystem/IPBanGroup.java
  657. index 00158f5c9..1e6141e2c 100644
  658. --- a/src/net/innectis/innplugin/BanSystem/IPBanGroup.java
  659. +++ b/src/net/innectis/innplugin/BanSystem/IPBanGroup.java
  660. @@ -2,75 +2,62 @@ package net.innectis.innplugin.BanSystem;
  661.  
  662. import java.util.ArrayList;
  663. import java.util.List;
  664. +import java.util.UUID;
  665. +import net.innectis.innplugin.Player.PlayerCredentials;
  666.  
  667. /**
  668. * @author AlphaBlend
  669. - *
  670. + *
  671. * Describes the IPs and usernames associated with an IPBan
  672. *
  673. */
  674. public class IPBanGroup {
  675. private List<String> iplist;
  676. - private List<String> players;
  677. -
  678. - /**
  679. - * Constructs a new IPBanGroup using a singular IP and playerr
  680. - * @param IP
  681. - * @param player
  682. - */
  683. - public IPBanGroup(String IP, String player) {
  684. + private List<PlayerCredentials> players;
  685. +
  686. + public IPBanGroup(String IP, PlayerCredentials credentials) {
  687. this.iplist = new ArrayList<String>(1);
  688. this.iplist.add(IP);
  689. -
  690. - this.players = new ArrayList<String>(1);
  691. - this.players.add(player);
  692. +
  693. + this.players = new ArrayList<PlayerCredentials>(1);
  694. + this.players.add(credentials);
  695. }
  696.  
  697. - /**
  698. - * Constructs a new object using a list of IPs, and a single player
  699. - * @param iplist
  700. - * @param player
  701. - */
  702. - public IPBanGroup(List<String> iplist, String player) {
  703. + public IPBanGroup(List<String> iplist, PlayerCredentials credentials) {
  704. this.iplist = iplist;
  705. -
  706. - this.players = new ArrayList<String>(1);
  707. - this.players.add(player);
  708. +
  709. + this.players = new ArrayList<PlayerCredentials>(1);
  710. + this.players.add(credentials);
  711. }
  712. -
  713. - public IPBanGroup(String ip, List<String> players) {
  714. +
  715. + public IPBanGroup(String ip, List<PlayerCredentials> players) {
  716. this.iplist = new ArrayList<String>(1);
  717. this.iplist.add(ip);
  718. -
  719. +
  720. this.players = players;
  721. }
  722. -
  723. - /**
  724. - * Constructs a new object with a list of IPs and player names
  725. - * @param IPs
  726. - * @param usernames
  727. - */
  728. - public IPBanGroup(List<String> iplist, List<String> players) {
  729. +
  730. + public IPBanGroup(List<String> iplist, List<PlayerCredentials> players) {
  731. this.iplist = iplist;
  732. this.players = players;
  733. }
  734. -
  735. +
  736. /**
  737. * Gets the IPs associated with this IPBan
  738. - * @return
  739. + * @return
  740. */
  741. public List<String> getIPs() {
  742. return iplist;
  743. }
  744. -
  745. +
  746. /**
  747. * Gets the usernames associated with this IPBan
  748. - * @return
  749. + * @return
  750. */
  751. - public List<String> getPlayers() {
  752. + public List<PlayerCredentials> getPlayers() {
  753. return players;
  754. }
  755. -
  756. +
  757. /**
  758. * Adds an IP to the IP list
  759. * @param ip
  760. @@ -80,81 +67,82 @@ public class IPBanGroup {
  761. if (containsIP(ip)) {
  762. return false;
  763. }
  764. -
  765. +
  766. return iplist.add(ip);
  767. }
  768. -
  769. +
  770. /**
  771. * Adds a username to this IPBan
  772. - * @param username
  773. + * @param credentials
  774. * @return whether the username was added or not
  775. */
  776. - public boolean addPlayer(String username) {
  777. - if (containsPlayer(username)) {
  778. + public boolean addPlayer(PlayerCredentials credentials) {
  779. + if (containsPlayerId(credentials.getUniqueId())) {
  780. return false;
  781. }
  782. -
  783. - return players.add(username);
  784. +
  785. + return players.add(credentials);
  786. }
  787. -
  788. +
  789. /**
  790. * Removes the specified IP from the list of IPs
  791. * @param ip
  792. - * @return
  793. + * @return
  794. */
  795. public boolean removeIP(String ip) {
  796. if (!containsIP(ip)) {
  797. return false;
  798. }
  799. -
  800. +
  801. return iplist.remove(ip);
  802. }
  803. -
  804. +
  805. /**
  806. * Removes the specified username from the list of usernames
  807. - * @param username
  808. - * @return
  809. + * @param credentials
  810. + * @return
  811. */
  812. - public boolean removePlayer(String player) {
  813. - if (!containsPlayer(player)) {
  814. + public boolean removePlayer(PlayerCredentials credentials) {
  815. + if (!containsPlayerId(credentials.getUniqueId())) {
  816. return false;
  817. }
  818. -
  819. - return players.remove(player);
  820. +
  821. + return players.remove(credentials);
  822. }
  823. -
  824. +
  825. /**
  826. * Returns if the IP is in this group
  827. * @param IP
  828. - * @return
  829. + * @return
  830. */
  831. - public boolean containsIP(String checkIP) {
  832. - return iplist.contains(checkIP);
  833. + public boolean containsIP(String IP) {
  834. + return iplist.contains(IP);
  835. }
  836. -
  837. +
  838. /**
  839. - * Returns if the player is in this group
  840. - * @param checkPlayer
  841. - * @return
  842. + * Returns if the player represented by the unique ID
  843. + * is in this group
  844. + * @param playerId
  845. + * @return
  846. */
  847. - public boolean containsPlayer(String checkPlayer) {
  848. - for (String player : players) {
  849. - if (checkPlayer.equalsIgnoreCase(player)) {
  850. + public boolean containsPlayerId(UUID playerId) {
  851. + for (PlayerCredentials credentials : players) {
  852. + if (credentials.getUniqueId().equals(playerId)) {
  853. return true;
  854. }
  855. -
  856. +
  857. }
  858. -
  859. +
  860. return false;
  861. }
  862. -
  863. +
  864. /**
  865. - * Returns whether or not this group contains an IP or a player
  866. - * @param player
  867. + * Returns whether or not this group contains a player ID or IP
  868. + * @param playerId
  869. * @param ip
  870. - * @return
  871. + * @return
  872. */
  873. - public boolean containsIPOrPlayer(String player, String ip) {
  874. - return containsIP(ip) || containsPlayer(player);
  875. + public boolean containsIPOrPlayer(UUID playerId, String ip) {
  876. + return containsIP(ip) || containsPlayerId(playerId);
  877. }
  878. }
  879. diff --git a/src/net/innectis/innplugin/BanSystem/IPBanObject.java b/src/net/innectis/innplugin/BanSystem/IPBanObject.java
  880. index 238da8e4b..1d321ebea 100644
  881. --- a/src/net/innectis/innplugin/BanSystem/IPBanObject.java
  882. +++ b/src/net/innectis/innplugin/BanSystem/IPBanObject.java
  883. @@ -7,6 +7,7 @@ import java.sql.Timestamp;
  884. import java.util.List;
  885. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  886. import net.innectis.innplugin.InnPlugin;
  887. +import net.innectis.innplugin.Player.PlayerCredentials;
  888.  
  889. /**
  890. * @author AlphaBlend
  891. @@ -16,30 +17,12 @@ import net.innectis.innplugin.InnPlugin;
  892. public class IPBanObject extends BanObject {
  893. private IPBanGroup group;
  894.  
  895. - /**
  896. - *
  897. - * @param group
  898. - * @param bannedBy
  899. - * @param bannedTime
  900. - * @param durationTicks
  901. - * @param joinBan
  902. - */
  903. - public IPBanObject(IPBanGroup group, String bannedBy, Timestamp bannedTime, long durationTicks, boolean joinBan) {
  904. - this(0, group, bannedBy, bannedTime, durationTicks, joinBan);
  905. + public IPBanObject(IPBanGroup group, PlayerCredentials bannedByCredentials, Timestamp bannedTime, long durationTicks, boolean joinBan) {
  906. + this(0, group, bannedByCredentials, bannedTime, durationTicks, joinBan);
  907. }
  908.  
  909. - /**
  910. - * Constructor for an existing IPBan
  911. - * @param ID
  912. - * @param groupid
  913. - * @param group
  914. - * @param bannedBy
  915. - * @param bannedTime
  916. - * @param durationTicks
  917. - * @param joinBan
  918. - */
  919. - public IPBanObject(int ID, IPBanGroup group, String bannedBy, Timestamp bannedTime, long durationTicks, boolean joinBan) {
  920. - super(ID, bannedBy, bannedTime, durationTicks, joinBan);
  921. + public IPBanObject(int ID, IPBanGroup group, PlayerCredentials bannedByCredentials, Timestamp bannedTime, long durationTicks, boolean joinBan) {
  922. + super(ID, bannedByCredentials, bannedTime, durationTicks, joinBan);
  923. this.group = group;
  924. }
  925.  
  926. @@ -53,11 +36,11 @@ public class IPBanObject extends BanObject {
  927.  
  928. /**
  929. * Copies the IPs and players from an IPBan Group to this IPBan
  930. - * @param object
  931. + * @param group
  932. */
  933. public void copyFromGroup(IPBanGroup group) {
  934. List<String> ips = group.getIPs();
  935. - List<String> players = group.getPlayers();
  936. + List<PlayerCredentials> players = group.getPlayers();
  937.  
  938. for (String IP : ips) {
  939. if (!this.group.containsIP(IP)) {
  940. @@ -65,9 +48,9 @@ public class IPBanObject extends BanObject {
  941. }
  942. }
  943.  
  944. - for (String player : players) {
  945. - if (!this.group.containsPlayer(player)) {
  946. - this.group.addPlayer(player);
  947. + for (PlayerCredentials credentials : players) {
  948. + if (!this.group.containsPlayerId(credentials.getUniqueId())) {
  949. + this.group.addPlayer(credentials);
  950. }
  951. }
  952. }
  953. @@ -79,7 +62,7 @@ public class IPBanObject extends BanObject {
  954. */
  955. public boolean isPartOfThis(IPBanGroup group) {
  956. List<String> ips = group.getIPs();
  957. - List<String> players = group.getPlayers();
  958. + List<PlayerCredentials> players = group.getPlayers();
  959.  
  960. for (String ip : ips) {
  961. if (this.group.containsIP(ip)) {
  962. @@ -87,8 +70,8 @@ public class IPBanObject extends BanObject {
  963. }
  964. }
  965.  
  966. - for (String player : players) {
  967. - if (this.group.containsPlayer(player)) {
  968. + for (PlayerCredentials credentials : players) {
  969. + if (this.group.containsPlayerId(credentials.getUniqueId())) {
  970. return true;
  971. }
  972. }
  973. @@ -115,31 +98,33 @@ public class IPBanObject extends BanObject {
  974. }
  975. }
  976.  
  977. - String playerList = null;
  978. + String playerIdList = null;
  979. +
  980. + for (PlayerCredentials pc : group.getPlayers()) {
  981. + String playerId = pc.getUniqueId().toString();
  982.  
  983. - for (String player : group.getPlayers()) {
  984. - if (playerList == null) {
  985. - playerList = player;
  986. + if (playerIdList == null) {
  987. + playerIdList = playerId;
  988. } else {
  989. - playerList += ", " + player;
  990. + playerIdList += ", " + playerId;
  991. }
  992. }
  993.  
  994. if (getId() > 0) {
  995. - statement = DBManager.prepareStatement("UPDATE banned_ip_players SET iplist = ?, userlist = ?, banned_by = ?, banned_time = ?, duration_ticks = ?, joinban = ? WHERE ID = ?");
  996. + statement = DBManager.prepareStatement("UPDATE banned_ip_players SET iplist = ?, player_id_list = ?, banned_by_player_id = ?, banned_time = ?, duration_ticks = ?, joinban = ? WHERE ID = ?");
  997. statement.setString(1, ipList);
  998. - statement.setString(2, playerList);
  999. - statement.setString(3, getBannedBy());
  1000. + statement.setString(2, playerIdList);
  1001. + statement.setString(3, super.getBannedByCredentials().getUniqueId().toString());
  1002. statement.setTimestamp(4, getBannedTime());
  1003. statement.setLong(5, getDurationTicks());
  1004. statement.setBoolean(6, isJoinBan());
  1005. statement.setInt(7, getId());
  1006. statement.executeUpdate();
  1007. } else {
  1008. - statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO banned_ip_players (iplist, userlist, banned_by, banned_time, duration_ticks, joinban) VALUES (?, ?, ?, ?, ?, ?)");
  1009. + statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO banned_ip_players (iplist, player_id_list, banned_by_player_id, banned_time, duration_ticks, joinban) VALUES (?, ?, ?, ?, ?, ?)");
  1010. statement.setString(1, ipList);
  1011. - statement.setString(2, playerList);
  1012. - statement.setString(3, getBannedBy());
  1013. + statement.setString(2, playerIdList);
  1014. + statement.setString(3, super.getBannedByCredentials().getUniqueId().toString());
  1015. statement.setTimestamp(4, getBannedTime());
  1016. statement.setLong(5, getDurationTicks());
  1017. statement.setBoolean(6, isJoinBan());
  1018. diff --git a/src/net/innectis/innplugin/BanSystem/UserBanObject.java b/src/net/innectis/innplugin/BanSystem/UserBanObject.java
  1019. index 8a4f68b39..5892c02f5 100644
  1020. --- a/src/net/innectis/innplugin/BanSystem/UserBanObject.java
  1021. +++ b/src/net/innectis/innplugin/BanSystem/UserBanObject.java
  1022. @@ -6,6 +6,7 @@ import java.sql.SQLException;
  1023. import java.sql.Timestamp;
  1024. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  1025. import net.innectis.innplugin.InnPlugin;
  1026. +import net.innectis.innplugin.Player.PlayerCredentials;
  1027.  
  1028. /**
  1029. * An object of a single username ban
  1030. @@ -13,63 +14,63 @@ import net.innectis.innplugin.InnPlugin;
  1031. * @author AlphaBlend
  1032. */
  1033. public class UserBanObject extends BanObject {
  1034. -
  1035. - private String username = null;
  1036. + private PlayerCredentials bannedPlayerCredentials = null;
  1037.  
  1038. /**
  1039. * Constructor for setting up a fresh ban
  1040. - * @param username
  1041. - * @param bannedBy
  1042. + * @param bannedPlayerCredentials
  1043. + * @param bannedByPlayerCredentials
  1044. * @param bannedTime
  1045. * @param durationTicks
  1046. * @param joinBan
  1047. */
  1048. - public UserBanObject(String username, String bannedBy, Timestamp bannedTime, long durationTicks, boolean joinBan) {
  1049. - this(0, username, bannedBy, bannedTime, durationTicks, joinBan);
  1050. + public UserBanObject(PlayerCredentials bannedPlayerCredentials, PlayerCredentials bannedByPlayerCredentials, Timestamp bannedTime, long durationTicks, boolean joinBan) {
  1051. + this(0, bannedPlayerCredentials, bannedByPlayerCredentials, bannedTime, durationTicks, joinBan);
  1052. }
  1053.  
  1054. /**
  1055. * Constructor for an already existing ban
  1056. - * @param username
  1057. - * @param bannedBy
  1058. + * @paran id
  1059. + * @param bannedPlayer
  1060. + * @param bannedByPlayer
  1061. * @param bannedTime
  1062. * @param durationTicks
  1063. * @param joinBan
  1064. */
  1065. - public UserBanObject(int id, String username, String bannedBy, Timestamp bannedTime, long durationTicks, boolean joinBan) {
  1066. - super(id, bannedBy, bannedTime, durationTicks, joinBan);
  1067. - this.username = username;
  1068. + public UserBanObject(int id, PlayerCredentials bannedPlayer, PlayerCredentials bannedByPlayer, Timestamp bannedTime, long durationTicks, boolean joinBan) {
  1069. + super(id, bannedByPlayer, bannedTime, durationTicks, joinBan);
  1070. + this.bannedPlayerCredentials = bannedPlayer;
  1071. }
  1072.  
  1073. /**
  1074. * Gets the username associated with this ban
  1075. * @return
  1076. */
  1077. - public String getUsername() {
  1078. - return username;
  1079. + public PlayerCredentials getBannedPlayerCredentials() {
  1080. + return bannedPlayerCredentials;
  1081. }
  1082.  
  1083. /**
  1084. * Saves this username ban to the database
  1085. - * @param update
  1086. */
  1087. + @Override
  1088. public void save() {
  1089. PreparedStatement statement = null;
  1090. ResultSet set = null;
  1091.  
  1092. try {
  1093. if (getId() > 0) {
  1094. - statement = DBManager.prepareStatement("UPDATE banned_players SET banned_by = ?, banned_time = ?, duration_ticks = ?, joinban = ? WHERE ID = ?");
  1095. - statement.setString(1, getBannedBy());
  1096. + statement = DBManager.prepareStatement("UPDATE banned_players SET banned_by_player_id = ?, banned_time = ?, duration_ticks = ?, joinban = ? WHERE ID = ?");
  1097. + statement.setString(1, super.getBannedByCredentials().getUniqueId().toString());
  1098. statement.setTimestamp(2, getBannedTime());
  1099. statement.setLong(3, getDurationTicks());
  1100. statement.setBoolean(4, isJoinBan());
  1101. statement.setInt(5, getId());
  1102. statement.executeUpdate();
  1103. } else {
  1104. - statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO banned_players (username, banned_by, banned_time, duration_ticks, joinban) VALUES (?, ?, ?, ?, ?)");
  1105. - statement.setString(1, getUsername());
  1106. - statement.setString(2, getBannedBy());
  1107. + statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO banned_players (player_id, banned_by_player_id, banned_time, duration_ticks, joinban) VALUES (?, ?, ?, ?, ?)");
  1108. + statement.setString(1, bannedPlayerCredentials.getUniqueId().toString());
  1109. + statement.setString(2, super.getBannedByCredentials().getUniqueId().toString());
  1110. statement.setTimestamp(3, getBannedTime());
  1111. statement.setLong(4, getDurationTicks());
  1112. statement.setBoolean(5, isJoinBan());
  1113. @@ -82,7 +83,7 @@ public class UserBanObject extends BanObject {
  1114. }
  1115. }
  1116. } catch (SQLException ex) {
  1117. - InnPlugin.logError("Unable to save " + username + "'s ban!", ex);
  1118. + InnPlugin.logError("Unable to save " + bannedPlayerCredentials.getName() + "'s ban!", ex);
  1119. } finally {
  1120. DBManager.closeResultSet(set);
  1121. DBManager.closePreparedStatement(statement);
  1122. @@ -102,7 +103,7 @@ public class UserBanObject extends BanObject {
  1123. statement.setInt(2, getId());
  1124. statement.execute();
  1125. } catch (SQLException ex) {
  1126. - InnPlugin.logError("Unable to save " + username + "'s ban!", ex);
  1127. + InnPlugin.logError("Unable to save " + bannedPlayerCredentials.getName() + "'s ban!", ex);
  1128. } finally {
  1129. DBManager.closePreparedStatement(statement);
  1130. }
  1131. diff --git a/src/net/innectis/innplugin/Command/Commands/AdminCommands.java b/src/net/innectis/innplugin/Command/Commands/AdminCommands.java
  1132. index 146ace789..d41b51c40 100644
  1133. --- a/src/net/innectis/innplugin/Command/Commands/AdminCommands.java
  1134. +++ b/src/net/innectis/innplugin/Command/Commands/AdminCommands.java
  1135. @@ -390,15 +390,21 @@ public final class AdminCommands {
  1136. hiddenCommand = true)
  1137. public static boolean commandPerm(InnPlugin parent, IdpCommandSender<? extends CommandSender> sender, LynxyArguments args) {
  1138. if (args.getActionSize() > 1) {
  1139. - IdpPlayer target = parent.getPlayer(args.getString(0));
  1140. - String username = (target != null ? target.getName() : args.getString(0));
  1141. + String playerName = args.getString(0);
  1142. + IdpPlayer target = parent.getPlayer(playerName);
  1143. + PlayerSession session = null;
  1144.  
  1145. - PlayerSession session = (target != null ? target.getSession() : PlayerSession.getSession(username, parent));
  1146. + if (target != null) {
  1147. + session = target.getSession();
  1148. + } else {
  1149. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  1150.  
  1151. - if (!session.isValidPlayer()) {
  1152. - session.destroy();
  1153. - sender.printError("That user doesn't exist.");
  1154. - return true;
  1155. + if (credentials == null) {
  1156. + sender.printError("That player does not exist.");
  1157. + return true;
  1158. + }
  1159. +
  1160. + session = PlayerSession.getSession(credentials.getUniqueId(), credentials.getName(), parent, true);
  1161. }
  1162.  
  1163. int permID = 0;
  1164. @@ -477,9 +483,10 @@ public final class AdminCommands {
  1165. }
  1166.  
  1167. for (ModifiablePermissions perms : permList) {
  1168. + PlayerCredentials credentials = perms.getCredentials();
  1169. String username = perms.getUsername();
  1170. + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(credentials.getUniqueId());
  1171.  
  1172. - PlayerGroup group = PlayerGroup.getGroupOfUsername(username);
  1173. String coloredUsername = group.getPrefix().getTextColor() + username;
  1174.  
  1175. lines.add(ChatColor.DARK_GREEN + "Showing modified permissions for " + coloredUsername);
  1176. @@ -507,14 +514,21 @@ public final class AdminCommands {
  1177. }
  1178. }
  1179. } else {
  1180. - IdpPlayer target = InnPlugin.getPlugin().getPlayer(args.getString("list", "l"));
  1181. - String player = (target != null ? target.getName() : args.getString("list", "l"));
  1182. - PlayerSession session = (target != null ? target.getSession() : PlayerSession.getSession(player, parent));
  1183. + String playerName = args.getString("list", "l");
  1184. + IdpPlayer target = InnPlugin.getPlugin().getPlayer(playerName);
  1185. + PlayerSession session = null;
  1186.  
  1187. - if (!session.isValidPlayer()) {
  1188. - session.destroy();
  1189. - sender.printError("That player doesn't exist.");
  1190. - return true;
  1191. + if (target != null) {
  1192. + session = target.getSession();
  1193. + } else {
  1194. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  1195. +
  1196. + if (credentials == null) {
  1197. + sender.printError("That player does not exist.");
  1198. + return true;
  1199. + }
  1200. +
  1201. + session = PlayerSession.getSession(credentials.getUniqueId(), credentials.getName(), parent, true);
  1202. }
  1203.  
  1204. ModifiablePermissions perms = session.getModifiablePermissions();
  1205. @@ -561,16 +575,21 @@ public final class AdminCommands {
  1206.  
  1207. return true;
  1208. } else if (args.hasArgument("reset", "reload")) {
  1209. - IdpPlayer target = InnPlugin.getPlugin().getPlayer(args.getString("reset", "reload"));
  1210. - String playerName = (target != null ? target.getName() : args.getString("reset", "reload"));
  1211. - PlayerSession session = (target != null ? target.getSession() : PlayerSession.getSession(playerName, parent));
  1212. - PlayerGroup group = session.getGroup();
  1213. + String playerName = args.getString("reset", "reload");
  1214. + IdpPlayer target = parent.getPlayer(playerName);
  1215. + PlayerSession session = null;
  1216.  
  1217. + if (target != null) {
  1218. + session = target.getSession();
  1219. + } else {
  1220. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  1221.  
  1222. - if (!session.isValidPlayer()) {
  1223. - session.destroy();
  1224. - sender.printError("That player doesn't exist.");
  1225. - return true;
  1226. + if (credentials == null) {
  1227. + sender.printError("That player does not exist.");
  1228. + return true;
  1229. + }
  1230. +
  1231. + session = PlayerSession.getSession(credentials.getUniqueId(), credentials.getName(), parent, true);
  1232. }
  1233.  
  1234. ModifiablePermissions perms = session.getModifiablePermissions();
  1235. @@ -580,6 +599,7 @@ public final class AdminCommands {
  1236. return true;
  1237. }
  1238.  
  1239. + PlayerGroup group = session.getGroup();
  1240. List<Integer> addedPerms = perms.getPermissionIDByType(PermissionType.ADDITIONAL);
  1241.  
  1242. for (int permID : addedPerms) {
  1243. @@ -619,18 +639,20 @@ public final class AdminCommands {
  1244. }
  1245.  
  1246. String playerName = args.getString(0);
  1247. - IdpPlayer target = parent.getPlayer(playerName, false);
  1248. + IdpPlayer target = parent.getPlayer(playerName);
  1249. + PlayerCredentials credentials = null;
  1250.  
  1251. - // Check for validity of player if they are not online
  1252. - if (target == null) {
  1253. - if (!PlayerSession.isValidPlayer(playerName)) {
  1254. - sender.printError("That is not a valid player!");
  1255. - return true;
  1256. - }
  1257. - } else {
  1258. + if (target != null) {
  1259. playerName = target.getName();
  1260. }
  1261.  
  1262. + credentials = PlayerCredentialsManager.getByName(playerName);
  1263. +
  1264. + if (credentials == null) {
  1265. + sender.printError("That is not a valid player!");
  1266. + return true;
  1267. + }
  1268. +
  1269. boolean useLiveInventory = false;
  1270.  
  1271. if (target != null && target.isOnline()) {
  1272. @@ -656,7 +678,7 @@ public final class AdminCommands {
  1273.  
  1274. if (sender.isPlayer()) {
  1275. IdpPlayer player = (IdpPlayer) sender;
  1276. - player.getSession().setInventoryView(playerName, type);
  1277. + player.getSession().setInventoryView(credentials.getUniqueId(), credentials.getName(), type);
  1278.  
  1279. if (useLiveInventory) {
  1280. player.openInventory(new IdpInventory(target));
  1281. @@ -666,7 +688,7 @@ public final class AdminCommands {
  1282. type = player.getInventory().getType();
  1283. }
  1284.  
  1285. - IdpPlayerInventory inv = IdpPlayerInventory.load(playerName, type, parent);
  1286. + IdpPlayerInventory inv = IdpPlayerInventory.load(credentials.getUniqueId(), playerName, type, parent);
  1287.  
  1288. IdpInventory inventory = new IdpInventory(playerName + " (" + type.getName() + ")", 45);
  1289. inventory.setContents(inv.getItems(), 0);
  1290. @@ -674,7 +696,7 @@ public final class AdminCommands {
  1291. player.openInventory(inventory);
  1292. }
  1293. } else {
  1294. - List<String> strings = listInventoryAsString(parent, type, playerName);
  1295. + List<String> strings = listInventoryAsString(parent, type, credentials.getUniqueId(), playerName);
  1296.  
  1297. for (int i = 0; i < strings.size(); i++) {
  1298. sender.printInfo(ChatColor.WHITE + strings.get(i));
  1299. @@ -815,7 +837,7 @@ public final class AdminCommands {
  1300. DBManager.closeResultSet(result);
  1301. DBManager.closePreparedStatement(statement);
  1302.  
  1303. - statement = DBManager.prepareStatement("SELECT ID, username, homeid, world, locx, locy, locz FROM homes;");
  1304. + statement = DBManager.prepareStatement("SELECT ID, player_id, homeid, world, locx, locy, locz FROM homes;");
  1305. result = statement.executeQuery();
  1306.  
  1307. while (result.next()) {
  1308. @@ -828,11 +850,15 @@ public final class AdminCommands {
  1309. Location loc = new Location(world, x, y, z);
  1310.  
  1311. InnectisLot lot = LotHandler.getLot(loc);
  1312. - String username = result.getString("username");
  1313.  
  1314. - if (lot != null && !lot.getOwner().equalsIgnoreCase(username) && !lot.containsMember(username) && !lot.containsOperator(username)) {
  1315. + String playerIdString = result.getString("player_id");
  1316. + UUID playerId = UUID.fromString(playerIdString);
  1317. + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(playerId);
  1318. + String name = credentials.getName();
  1319. +
  1320. + if (lot != null && !lot.getOwner().equalsIgnoreCase(name) && !lot.containsMember(name) && !lot.containsOperator(name)) {
  1321. // If player is online make sure to delete the reference to their home
  1322. - IdpPlayer testPlayer = parent.getPlayer(username);
  1323. + IdpPlayer testPlayer = parent.getPlayer(credentials.getUniqueId());
  1324.  
  1325. if (testPlayer != null) {
  1326. int homeId = result.getInt("homeid");
  1327. @@ -922,8 +948,8 @@ public final class AdminCommands {
  1328. } else if (lot.getOwner().length() == 1) {
  1329. break;
  1330. } else {
  1331. - statement = DBManager.prepareStatement("SELECT onlinetime FROM players WHERE name = ?;");
  1332. - statement.setString(1, lot.getOwner());
  1333. + statement = DBManager.prepareStatement("SELECT onlinetime FROM players WHERE player_id = ?;");
  1334. + statement.setString(1, lot.getOwnerCredentials().getUniqueId().toString());
  1335. result = statement.executeQuery();
  1336.  
  1337. if (!(result.next() && result.getFloat("onlinetime") > 10800000)) { //3 hours
  1338. @@ -990,16 +1016,21 @@ public final class AdminCommands {
  1339. }
  1340. }
  1341.  
  1342. - String username = null;
  1343. + String playerName = null;
  1344. + PlayerCredentials credentials = null;
  1345. IdpPlayer targ = null;
  1346.  
  1347. if (args.getString("player", "p") != null) {
  1348. - targ = parent.getPlayer(args.getString("player", "p"));
  1349. - username = (targ != null ? targ.getName() : args.getString("player", "p"));
  1350. + playerName = args.getString("player", "p");
  1351. + targ = parent.getPlayer(playerName);
  1352. +
  1353. + if (targ != null) {
  1354. + playerName = targ.getName();
  1355. + }
  1356.  
  1357. - PlayerGroup group = PlayerGroup.getGroupOfUsername(username);
  1358. + credentials = PlayerCredentialsManager.getByName(playerName);
  1359.  
  1360. - if (group == PlayerGroup.NONE) {
  1361. + if (credentials == null) {
  1362. sender.printError("Player not found.");
  1363. return true;
  1364. }
  1365. @@ -1043,7 +1074,7 @@ public final class AdminCommands {
  1366.  
  1367. if (count > 0 && ((count <= amount && useAsMax) || count >= amount && !useAsMax)) {
  1368. hasCount = true;
  1369. - sender.print(ChatColor.LIGHT_PURPLE, "Count of items in " + username + "'s backpack matching filter: " + amount);
  1370. + sender.print(ChatColor.LIGHT_PURPLE, "Count of items in " + playerName + "'s backpack matching filter: " + amount);
  1371. }
  1372. }
  1373.  
  1374. @@ -1056,9 +1087,9 @@ public final class AdminCommands {
  1375.  
  1376. List<InnectisChest> chests = null;
  1377.  
  1378. - if (username != null) {
  1379. - chests = ChestHandler.getChests(username);
  1380. - sender.print(ChatColor.LIGHT_PURPLE, "Searching all " + chests.size() + " of " + username + "'s chests for " + matString + ":");
  1381. + if (credentials != null) {
  1382. + chests = ChestHandler.getChests(playerName);
  1383. + sender.print(ChatColor.LIGHT_PURPLE, "Searching all " + chests.size() + " of " + playerName + "'s chests for " + matString + ":");
  1384. } else {
  1385. chests = ChestHandler.getAllChests();
  1386. sender.print(ChatColor.LIGHT_PURPLE, "Searching all " + chests.size() + " chests for " + matString + ":");
  1387. @@ -1077,18 +1108,18 @@ public final class AdminCommands {
  1388.  
  1389. List<EnderChestContents> enderChestContents = new ArrayList<EnderChestContents>();
  1390.  
  1391. - if (username != null) {
  1392. + if (playerName != null) {
  1393. List<EnderContentsType> types = EnderChestContents.getAllEnderContentTypes();
  1394.  
  1395. for (EnderContentsType ect : types) {
  1396. - EnderChestContents contents = EnderChestContents.getContents(username, ect);
  1397. + EnderChestContents contents = EnderChestContents.getContents(credentials, ect);
  1398.  
  1399. if (contents != null) {
  1400. enderChestContents.add(contents);
  1401. }
  1402. }
  1403.  
  1404. - sender.print(ChatColor.LIGHT_PURPLE, "Searching " + enderChestContents.size() + " of " + username + "'s ender chests for " + matString + ":");
  1405. + sender.print(ChatColor.LIGHT_PURPLE, "Searching " + enderChestContents.size() + " of " + playerName + "'s ender chests for " + matString + ":");
  1406. } else {
  1407. enderChestContents = EnderChestContents.getAllChestContents();
  1408. sender.print(ChatColor.LIGHT_PURPLE, "Searching " + enderChestContents.size() + " ender chests for " + matString + ":");
  1409. @@ -1097,7 +1128,7 @@ public final class AdminCommands {
  1410. final IdpCommandSender<? extends CommandSender> finalSender = sender;
  1411. final List<ChestDetails> finalChestDetailsList = chestDetailsList;
  1412. final List<EnderChestContents> finalEnderChestContents = enderChestContents;
  1413. - final String finalUsername = username;
  1414. + final String finalUsername = playerName;
  1415. final int finalAmount = amount;
  1416.  
  1417. final Thread thread = new Thread(new Runnable() {
  1418. @@ -1204,7 +1235,7 @@ public final class AdminCommands {
  1419. return true;
  1420. }
  1421.  
  1422. - if (BlockLockHandler.lockBlock(player, loc)) {
  1423. + if (BlockLockHandler.lockBlock(player.getUniqueId(), loc)) {
  1424. player.printInfo("Block (" + loc.getBlockX() + ", " + loc.getBlockY() + ", " + loc.getBlockZ() + ") is now locked!");
  1425. } else {
  1426. player.printError("Failed to lock, notify an Admin!");
  1427. @@ -1248,9 +1279,22 @@ public final class AdminCommands {
  1428. permission = Permission.command_admin_openenderchest,
  1429. usage = "/openenderchest <player> [world]",
  1430. serverCommand = false)
  1431. - public static boolean commandOpenEnderChest(IdpPlayer player, ParameterArguments args) {
  1432. + public static boolean commandOpenEnderChest(InnPlugin parent, IdpPlayer player, ParameterArguments args) {
  1433. if (args.size() > 0) {
  1434. - String user = args.getString(0);
  1435. + String playerName = args.getString(0);
  1436. + IdpPlayer target = parent.getPlayer(playerName);
  1437. +
  1438. + if (target != null) {
  1439. + playerName = target.getName();
  1440. + }
  1441. +
  1442. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  1443. +
  1444. + if (credentials == null) {
  1445. + player.printError("That player does not exist.");
  1446. + return true;
  1447. + }
  1448. +
  1449. IdpWorld world = player.getWorld();
  1450. EnderContentsType type = world.getSettings().getEnderchestType();
  1451.  
  1452. @@ -1269,13 +1313,13 @@ public final class AdminCommands {
  1453. return true;
  1454. }
  1455.  
  1456. - EnderChestContents contents = EnderChestContents.getContents(user, world.getSettings().getEnderchestType());
  1457. - EnderChestView view = InnPlugin.getPlugin().getEnderChestView(user, type);
  1458. + EnderChestContents contents = EnderChestContents.getContents(credentials, world.getSettings().getEnderchestType());
  1459. + EnderChestView view = InnPlugin.getPlugin().getEnderChestView(credentials.getUniqueId(), type);
  1460. Inventory inventory = null;
  1461.  
  1462. if (view == null) {
  1463. - inventory = new IdpInventory(user + " (" + type.name().toLowerCase() + ")", IdpInventory.DEFAULT_CHEST_SIZE);
  1464. - InnPlugin.getPlugin().addEnderChestView(new EnderChestView(user, type, inventory));
  1465. + inventory = new IdpInventory(playerName + " (" + type.name().toLowerCase() + ")", IdpInventory.DEFAULT_CHEST_SIZE);
  1466. + InnPlugin.getPlugin().addEnderChestView(new EnderChestView(credentials.getUniqueId(), type, inventory));
  1467.  
  1468. int idx = 0;
  1469. for (IdpItemStack stack : contents.getItems()) {
  1470. @@ -1288,11 +1332,12 @@ public final class AdminCommands {
  1471. }
  1472.  
  1473. PlayerSession session = player.getSession();
  1474. - session.setEnderchestOwner(user);
  1475. + session.setEnderchestOwner(credentials.getName());
  1476. + session.setEnderchestOwnerId(credentials.getUniqueId());
  1477. session.setEnderchestType(type);
  1478. session.setViewingEnderChest(true);
  1479.  
  1480. - player.printInfo("You opened the ender chest contents of " + user + " in " + world.getName() + " (Type: " + type.name() + ")");
  1481. + player.printInfo("You opened the ender chest contents of " + playerName + " in " + world.getName() + " (Type: " + type.name() + ")");
  1482. player.getHandle().openInventory(inventory);
  1483. return true;
  1484. }
  1485. @@ -1442,19 +1487,21 @@ public final class AdminCommands {
  1486. hiddenCommand = true)
  1487. public static boolean commandSetGroup(InnPlugin parent, IdpCommandSender<? extends CommandSender> sender, String[] args) {
  1488. if (args.length == 2) {
  1489. + String playerName = args[0];
  1490. + IdpPlayer targetPlayer = parent.getPlayer(playerName);
  1491. PlayerSession targetSession = null;
  1492. - IdpPlayer targetPlayer = parent.getPlayer(args[0], false);
  1493. - if (targetPlayer == null) {
  1494. - targetSession = PlayerSession.getSession(args[0], parent);
  1495.  
  1496. - // Stop when player has no onlinetime
  1497. - if (!targetSession.isValidPlayer()) {
  1498. - targetSession.destroy();
  1499. - sender.printError("That player doesn't exist!");
  1500. + if (targetPlayer != null) {
  1501. + targetSession = targetPlayer.getSession();
  1502. + } else {
  1503. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  1504. +
  1505. + if (credentials == null) {
  1506. + sender.printError("That player does not exist.");
  1507. return true;
  1508. }
  1509. - } else {
  1510. - targetSession = targetPlayer.getSession();
  1511. +
  1512. + targetSession = PlayerSession.getSession(credentials.getUniqueId(), credentials.getName(), parent, true);
  1513. }
  1514.  
  1515. PlayerGroup group;
  1516. @@ -1715,8 +1762,8 @@ public final class AdminCommands {
  1517. * @param playerName
  1518. * @return
  1519. */
  1520. - private static List<String> listInventoryAsString(InnPlugin parent, InventoryType type, String playerName) {
  1521. - IdpPlayer player = parent.getPlayer(playerName);
  1522. + private static List<String> listInventoryAsString(InnPlugin parent, InventoryType type, UUID playerId, String playerName) {
  1523. + IdpPlayer player = parent.getPlayer(playerId);
  1524. IdpPlayerInventory inv = null;
  1525.  
  1526. if (player != null) {
  1527. @@ -1725,10 +1772,10 @@ public final class AdminCommands {
  1528.  
  1529. // Not viewing the same type, so load the specified type
  1530. if (type != playerInventoryType) {
  1531. - inv = IdpPlayerInventory.load(playerName, type, parent);
  1532. + inv = IdpPlayerInventory.load(playerId, playerName, type, parent);
  1533. }
  1534. } else {
  1535. - inv = IdpPlayerInventory.load(playerName, type, parent);
  1536. + inv = IdpPlayerInventory.load(playerId, playerName, type, parent);
  1537. }
  1538.  
  1539. IdpItemStack[] items1 = inv.getItems();
  1540. diff --git a/src/net/innectis/innplugin/Command/Commands/ChatCommands.java b/src/net/innectis/innplugin/Command/Commands/ChatCommands.java
  1541. index 77d9d6724..1382df778 100644
  1542. --- a/src/net/innectis/innplugin/Command/Commands/ChatCommands.java
  1543. +++ b/src/net/innectis/innplugin/Command/Commands/ChatCommands.java
  1544. @@ -7,6 +7,7 @@ import java.util.HashSet;
  1545. import java.util.List;
  1546. import java.util.Map;
  1547. import java.util.Set;
  1548. +import java.util.UUID;
  1549. import java.util.regex.Pattern;
  1550. import net.innectis.innplugin.Command.CommandMethod;
  1551. import net.innectis.innplugin.Command.CommandName;
  1552. @@ -20,14 +21,16 @@ import net.innectis.innplugin.Loggers.ChatLogger;
  1553. import net.innectis.innplugin.Loggers.LogManager;
  1554. import net.innectis.innplugin.Player.Channel.ChannelSettings;
  1555. import net.innectis.innplugin.Player.Channel.ChatChannel;
  1556. -import net.innectis.innplugin.Player.Channel.ChatChannelHandler;
  1557. import net.innectis.innplugin.Player.Channel.ChatChannelGroup;
  1558. +import net.innectis.innplugin.Player.Channel.ChatChannelHandler;
  1559. import net.innectis.innplugin.Player.Channel.MemberDetails;
  1560. import net.innectis.innplugin.Player.Chat.ChatColor;
  1561. import net.innectis.innplugin.Player.Chat.ChatMessage;
  1562. import net.innectis.innplugin.Player.Chat.Prefix;
  1563. import net.innectis.innplugin.Player.IdpPlayer;
  1564. import net.innectis.innplugin.Player.Permission;
  1565. +import net.innectis.innplugin.Player.PlayerCredentials;
  1566. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  1567. import net.innectis.innplugin.Player.PlayerGroup;
  1568. import net.innectis.innplugin.Player.PlayerSession;
  1569. import net.innectis.innplugin.Utility.LynxyArguments;
  1570. @@ -572,8 +575,7 @@ public final class ChatCommands {
  1571. permission = Permission.command_misc_chatchannel_join,
  1572. usage = "/join <channel> [-setpass, -sp <password>] [-pass, -password, -p <password>] [-hide, -h]",
  1573. serverCommand = false)
  1574. - public static boolean commandJoin(InnPlugin parent, IdpCommandSender<? extends CommandSender> sender, LynxyArguments args) {
  1575. - IdpPlayer player = (IdpPlayer) sender;
  1576. + public static boolean commandJoin(InnPlugin parent, IdpPlayer player, LynxyArguments args) {
  1577. if (args.getActionSize() == 0) {
  1578. return false;
  1579. }
  1580. @@ -619,7 +621,8 @@ public final class ChatCommands {
  1581. }
  1582. }
  1583.  
  1584. - MemberDetails details = channel.addMember(player.getName(), ChatChannelGroup.MEMBER, player.getSession().makeNextChannelAndNumber(channelName), true);
  1585. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName(), true);
  1586. + MemberDetails details = channel.addMember(credentials, ChatChannelGroup.MEMBER, player.getSession().makeNextChannelAndNumber(channelName), true);
  1587. details.setOnline(true);
  1588. channel.sendGeneralMessage(player.getColoredName() + ChatColor.AQUA + " has joined the channel.");
  1589. } else {
  1590. @@ -638,7 +641,8 @@ public final class ChatCommands {
  1591. }
  1592.  
  1593. ChatChannel channel = ChatChannelHandler.createChannel(channelName, settings, password);
  1594. - MemberDetails details = channel.addMember(player.getName(), ChatChannelGroup.OWNER, player.getSession().makeNextChannelAndNumber(channelName), true);
  1595. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName(), true);
  1596. + MemberDetails details = channel.addMember(credentials, ChatChannelGroup.OWNER, player.getSession().makeNextChannelAndNumber(channelName), true);
  1597. details.setOnline(true);
  1598. channel.sendGeneralMessage(player.getColoredName() + ChatColor.AQUA + " has joined the channel.");
  1599. }
  1600. @@ -798,27 +802,37 @@ public final class ChatCommands {
  1601. }
  1602.  
  1603. if (args.hasArgument("giveup", "gu")) {
  1604. - String targUser = args.getString("giveup", "gu");
  1605. + String playerName = args.getString("giveup", "gu");
  1606. + IdpPlayer target = parent.getPlayer(playerName);
  1607. +
  1608. + if (target != null) {
  1609. + playerName = target.getName();
  1610. + }
  1611. +
  1612. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  1613.  
  1614. - if (!PlayerSession.isValidPlayer(targUser)) {
  1615. - sender.printError("That player doesn't exist.");
  1616. + if (credentials == null) {
  1617. + sender.printError("That player does not exist.");
  1618. return true;
  1619. + } else {
  1620. + // Get the proper casing of the name
  1621. + playerName = credentials.getName();
  1622. }
  1623.  
  1624. - if (!channel.containsMember(targUser)) {
  1625. + if (!channel.containsMember(playerName)) {
  1626. sender.printError("That player isn't part of this channel!");
  1627. return true;
  1628. }
  1629.  
  1630. - MemberDetails details = channel.getMemberDetails(targUser);
  1631. + MemberDetails details = channel.getMemberDetails(playerName);
  1632.  
  1633. if (details.getGroup() == ChatChannelGroup.OWNER) {
  1634. sender.printError("This player is already the owner!");
  1635. return true;
  1636. }
  1637.  
  1638. - String coloredName = getColoredName(targUser, parent);
  1639. - channel.switchOwner(targUser);
  1640. + String coloredName = getColoredName(playerName, parent);
  1641. + channel.switchOwner(credentials);
  1642. channel.sendGeneralMessage("The owner has been changed to " + coloredName + ChatColor.AQUA + "!");
  1643.  
  1644. if (!channel.containsMember(sender.getName())) {
  1645. @@ -827,23 +841,28 @@ public final class ChatCommands {
  1646.  
  1647. return true;
  1648. } else if (args.hasArgument("op", "deop")) {
  1649. - String targUser = args.getString("op", "deop");
  1650. + String playerName = args.getString("op", "deop");
  1651. + IdpPlayer target = parent.getPlayer(playerName);
  1652.  
  1653. - if (!PlayerSession.isValidPlayer(targUser)) {
  1654. - sender.printError("That player doesn't exist!");
  1655. - return true;
  1656. + if (target != null) {
  1657. + playerName = target.getName();
  1658. }
  1659.  
  1660. - if (targUser.equalsIgnoreCase(sender.getName())) {
  1661. - sender.printError("You cannot use this command on yourself!");
  1662. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  1663. +
  1664. + if (credentials == null) {
  1665. + sender.printError("That player doesn't exist!");
  1666. return true;
  1667. + } else {
  1668. + // Get the proper casing of the name
  1669. + playerName = credentials.getName();
  1670. }
  1671.  
  1672. - String coloredName = getColoredName(targUser, parent);
  1673. + String coloredName = getColoredName(playerName, parent);
  1674. boolean doOp = args.hasArgument("op");
  1675.  
  1676. - if (channel.containsMember(targUser)) {
  1677. - MemberDetails memberDetails = channel.getMemberDetails(targUser);
  1678. + if (channel.containsMember(playerName)) {
  1679. + MemberDetails memberDetails = channel.getMemberDetails(playerName);
  1680.  
  1681. if (memberDetails.getGroup().equals(ChatChannelGroup.OWNER)) {
  1682. sender.printError("Cannot op or deop the channel owner.");
  1683. @@ -857,7 +876,7 @@ public final class ChatCommands {
  1684. return true;
  1685. }
  1686.  
  1687. - channel.modifyMemberGroup(targUser, checkGroup);
  1688. + channel.modifyMemberGroup(playerName, checkGroup);
  1689.  
  1690. if (channel.isCached()) {
  1691. channel.sendGeneralMessage(coloredName + ChatColor.AQUA + " is " + (doOp ? "now" : "no longer") + " an operator!");
  1692. @@ -872,28 +891,38 @@ public final class ChatCommands {
  1693.  
  1694. return true;
  1695. } else if (args.hasArgument("kick", "k")) {
  1696. - String targUser = args.getString("kick", "k");
  1697. + String playerName = args.getString("kick", "k");
  1698. + IdpPlayer target = parent.getPlayer(playerName);
  1699.  
  1700. - if (!PlayerSession.isValidPlayer(targUser)) {
  1701. + if (target != null) {
  1702. + playerName = target.getName();
  1703. + }
  1704. +
  1705. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  1706. +
  1707. + if (credentials == null) {
  1708. sender.printError("That player doesn't exist!");
  1709. return true;
  1710. + } else {
  1711. + // Get the proper casing of the name
  1712. + playerName = credentials.getName();
  1713. }
  1714.  
  1715. - if (targUser.equalsIgnoreCase(sender.getName())) {
  1716. + if (playerName.equalsIgnoreCase(sender.getName())) {
  1717. sender.printError("You cannot kick yourself!");
  1718. return true;
  1719. }
  1720.  
  1721. - if (!canModerate(targUser, parent) && !(sender.hasPermission(Permission.special_chatroom_override))) {
  1722. + if (!canModerate(playerName, parent) && !(sender.hasPermission(Permission.special_chatroom_override))) {
  1723. sender.printError("That player cannot be kicked.");
  1724. return true;
  1725. }
  1726.  
  1727. - String coloredName = getColoredName(targUser, parent);
  1728. + String coloredName = getColoredName(playerName, parent);
  1729.  
  1730. - if (channel.containsMember(targUser)) {
  1731. + if (channel.containsMember(playerName)) {
  1732. MemberDetails senderDetails = channel.getMemberDetails(sender.getName());
  1733. - MemberDetails memberDetails = channel.getMemberDetails(targUser);
  1734. + MemberDetails memberDetails = channel.getMemberDetails(playerName);
  1735.  
  1736. if (!memberDetails.getGroup().equalsOrInherits(ChatChannelGroup.OPERATOR)
  1737. || (senderDetails != null && senderDetails.getGroup().equals(ChatChannelGroup.OWNER))
  1738. @@ -903,7 +932,7 @@ public final class ChatCommands {
  1739. channel.sendGeneralMessage(coloredName + ChatColor.AQUA + " has left the channel!");
  1740. }
  1741.  
  1742. - channel.removeMember(targUser);
  1743. + channel.removeMember(playerName);
  1744.  
  1745. if (!channel.containsMember(sender.getName())) {
  1746. sender.printInfo(coloredName + ChatColor.AQUA + " has been kicked from channel " + channel.getName() + "!");
  1747. @@ -923,30 +952,40 @@ public final class ChatCommands {
  1748.  
  1749. return true;
  1750. } else if (args.hasArgument("ban", "b")) {
  1751. - String targUser = args.getString("ban", "b");
  1752. + String playerName = args.getString("ban", "b");
  1753. + IdpPlayer target = parent.getPlayer(playerName);
  1754.  
  1755. - if (targUser.equalsIgnoreCase(sender.getName())) {
  1756. - sender.printError("You cannot ban yourself!");
  1757. + if (target != null) {
  1758. + playerName = target.getName();
  1759. + }
  1760. +
  1761. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  1762. +
  1763. + if (credentials == null) {
  1764. + sender.printError("That player does not exist.");
  1765. return true;
  1766. + } else {
  1767. + // Get the proper casing of the name
  1768. + playerName = credentials.getName();
  1769. }
  1770.  
  1771. - if (!PlayerSession.isValidPlayer(targUser)) {
  1772. - sender.printError("That player doesn't exist.");
  1773. + if (playerName.equalsIgnoreCase(sender.getName())) {
  1774. + sender.printError("You cannot ban yourself!");
  1775. return true;
  1776. }
  1777.  
  1778. - if (!canModerate(targUser, parent) && !(sender.hasPermission(Permission.special_chatroom_override))) {
  1779. + if (!canModerate(playerName, parent) && !(sender.hasPermission(Permission.special_chatroom_override))) {
  1780. sender.printError("That user cannot be banned.");
  1781. return true;
  1782. }
  1783.  
  1784. - if (channel.isBanned(targUser)) {
  1785. - sender.printError(targUser + " is already banned from that channel!");
  1786. + if (channel.isBanned(playerName)) {
  1787. + sender.printError(playerName + " is already banned from that channel!");
  1788. return true;
  1789. }
  1790.  
  1791. - String coloredName = getColoredName(targUser, parent);
  1792. - MemberDetails memberDetails = channel.getMemberDetails(targUser);
  1793. + String coloredName = getColoredName(playerName, parent);
  1794. + MemberDetails memberDetails = channel.getMemberDetails(playerName);
  1795. MemberDetails senderDetails = channel.getMemberDetails(sender.getName());
  1796.  
  1797. if ((memberDetails == null || !memberDetails.getGroup().equalsOrInherits(ChatChannelGroup.OPERATOR)
  1798. @@ -956,8 +995,8 @@ public final class ChatCommands {
  1799. channel.sendGeneralMessage(coloredName + ChatColor.RED + " has been banned from the channel!");
  1800. }
  1801.  
  1802. - if (channel.containsMember(targUser)) {
  1803. - channel.removeMember(targUser);
  1804. + if (channel.containsMember(playerName)) {
  1805. + channel.removeMember(playerName);
  1806. channel.sendGeneralMessage(coloredName + ChatColor.AQUA + " has left the channel!");
  1807. }
  1808.  
  1809. @@ -965,7 +1004,7 @@ public final class ChatCommands {
  1810. if (channel.isEmpty()) {
  1811. ChatChannelHandler.deleteChannel(channel);
  1812. } else {
  1813. - channel.addBanned(targUser);
  1814. + channel.addBanned(credentials);
  1815.  
  1816. if (!channel.containsMember(sender.getName())) {
  1817. sender.printInfo(coloredName + ChatColor.RED + " has been banned from the channel " + channel.getName() + "!");
  1818. @@ -977,21 +1016,31 @@ public final class ChatCommands {
  1819.  
  1820. return true;
  1821. } else if (args.hasArgument("unban", "ub")) {
  1822. - String targUser = args.getString("unban", "ub");
  1823. + String playerName = args.getString("unban", "ub");
  1824. + IdpPlayer target = parent.getPlayer(playerName);
  1825. +
  1826. + if (target != null) {
  1827. + playerName = target.getName();
  1828. + }
  1829.  
  1830. - if (!PlayerSession.isValidPlayer(targUser)) {
  1831. - sender.printError("That player doesn't exist.");
  1832. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  1833. +
  1834. + if (credentials == null) {
  1835. + sender.printError("That player does not exist.");
  1836. return true;
  1837. + } else {
  1838. + // Get the proper casing of the name
  1839. + playerName = credentials.getName();
  1840. }
  1841.  
  1842. - String coloredName = getColoredName(targUser, parent);
  1843. + String coloredName = getColoredName(playerName, parent);
  1844.  
  1845. - if (!channel.isBanned(targUser)) {
  1846. + if (!channel.isBanned(playerName)) {
  1847. sender.printError(coloredName + ChatColor.RED + " is not banned from this channel.");
  1848. return true;
  1849. }
  1850.  
  1851. - channel.removeBanned(targUser);
  1852. + channel.removeBanned(playerName);
  1853.  
  1854. if (channel.isCached()) {
  1855. channel.sendGeneralMessage(coloredName + ChatColor.RED + " has been unbanned from the channel!");
  1856. @@ -1076,11 +1125,11 @@ public final class ChatCommands {
  1857. sender.printInfo("Channel is hidden: " + ChatColor.YELLOW + isHidden);
  1858. sender.printInfo("Channel password: " + (requiresPassword ? ChatColor.YELLOW + channelPassword : ChatColor.RED + "none set"));
  1859.  
  1860. - List<String> ops = channel.getMembers(ChatChannelGroup.OPERATOR, false);
  1861. + List<PlayerCredentials> ops = channel.getMembers(ChatChannelGroup.OPERATOR, false);
  1862. String coloredOpsString = "";
  1863.  
  1864. - for (String op : ops) {
  1865. - String coloredOp = getColoredName(op, parent);
  1866. + for (PlayerCredentials pc : ops) {
  1867. + String coloredOp = getColoredName(pc.getName(), parent);
  1868.  
  1869. if (coloredOpsString.isEmpty()) {
  1870. coloredOpsString = coloredOp;
  1871. @@ -1161,7 +1210,8 @@ public final class ChatCommands {
  1872. StringBuilder sb = new StringBuilder();
  1873. int playerCount = 0, onlineCount = 0;
  1874.  
  1875. - for (String member : chan.getMembers()) {
  1876. + for (PlayerCredentials pc : chan.getMembers()) {
  1877. + String member = pc.getName();
  1878. IdpPlayer player = parent.getPlayer(member);
  1879. String addedTag = "";
  1880.  
  1881. @@ -1267,15 +1317,16 @@ public final class ChatCommands {
  1882. /**
  1883. * Determines if the specified user can be moderated against with
  1884. * channel kick/ban commands
  1885. - * @param username
  1886. + * @param playerName
  1887. * @return
  1888. */
  1889. - private static boolean canModerate(String username, InnPlugin parent) {
  1890. - PlayerSession session = PlayerSession.getActiveSession(username);
  1891. + private static boolean canModerate(String playerName, InnPlugin parent) {
  1892. + UUID playerId = getPlayerId(playerName);
  1893. + PlayerSession session = PlayerSession.getActiveSession(playerId);
  1894. boolean tempSession = false;
  1895.  
  1896. if (session == null) {
  1897. - session = PlayerSession.getSession(username, parent);
  1898. + session = PlayerSession.getSession(playerId, playerName, parent, true);
  1899. tempSession = true;
  1900. }
  1901.  
  1902. @@ -1290,16 +1341,17 @@ public final class ChatCommands {
  1903.  
  1904. /**
  1905. * Gets the colored name of the username
  1906. - * @param username
  1907. + * @param playerName
  1908. * @param parent
  1909. * @return
  1910. */
  1911. - private static String getColoredName(String username, InnPlugin parent) {
  1912. - PlayerSession session = PlayerSession.getActiveSession(username);
  1913. + private static String getColoredName(String playerName, InnPlugin parent) {
  1914. + UUID playerId = getPlayerId(playerName);
  1915. + PlayerSession session = PlayerSession.getActiveSession(playerId);
  1916. boolean tempSession = false;
  1917.  
  1918. if (session == null) {
  1919. - session = PlayerSession.getSession(username, parent);
  1920. + session = PlayerSession.getSession(playerId, playerName, parent, true);
  1921. tempSession = true;
  1922. }
  1923.  
  1924. @@ -1311,4 +1363,14 @@ public final class ChatCommands {
  1925.  
  1926. return coloredName;
  1927. }
  1928. +
  1929. + /**
  1930. + * Gets the unique ID of the specified player
  1931. + * @param playerName
  1932. + * @return
  1933. + */
  1934. + private static UUID getPlayerId(String playerName) {
  1935. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  1936. + return credentials.getUniqueId();
  1937. + }
  1938. }
  1939. diff --git a/src/net/innectis/innplugin/Command/Commands/GameCommands.java b/src/net/innectis/innplugin/Command/Commands/GameCommands.java
  1940. index 11e0ca18b..20703ade3 100644
  1941. --- a/src/net/innectis/innplugin/Command/Commands/GameCommands.java
  1942. +++ b/src/net/innectis/innplugin/Command/Commands/GameCommands.java
  1943. @@ -259,7 +259,7 @@ public final class GameCommands {
  1944.  
  1945. // Check if there is a lot and if the given player is the owner, a member or operator
  1946. InnectisLot lot = LotHandler.getLot(player.getLocation());
  1947. - if (lot != null && !lot.canPlayerManage(player) && !lot.containsMember(player.getDisplayName())
  1948. + if (lot != null && !lot.canPlayerManage(player.getName()) && !lot.containsMember(player.getDisplayName())
  1949. && !player.hasPermission(Permission.game_start_anywhere)) {
  1950. sender.printError("You cannot start a game here!");
  1951. return true;
  1952. diff --git a/src/net/innectis/innplugin/Command/Commands/InformationCommands.java b/src/net/innectis/innplugin/Command/Commands/InformationCommands.java
  1953. index f51ca69cd..5a8e2b903 100644
  1954. --- a/src/net/innectis/innplugin/Command/Commands/InformationCommands.java
  1955. +++ b/src/net/innectis/innplugin/Command/Commands/InformationCommands.java
  1956. @@ -5,6 +5,7 @@ import java.util.ArrayList;
  1957. import java.util.Calendar;
  1958. import java.util.Date;
  1959. import java.util.List;
  1960. +import java.util.UUID;
  1961. import net.innectis.innplugin.Command.CommandMethod;
  1962. import net.innectis.innplugin.Command.ICommand;
  1963. import net.innectis.innplugin.Configuration;
  1964. @@ -19,6 +20,7 @@ import net.innectis.innplugin.Handlers.PagedCommandHandler;
  1965. import net.innectis.innplugin.Handlers.TransactionHandler;
  1966. import net.innectis.innplugin.Handlers.TransactionHandler.TransactionType;
  1967. import net.innectis.innplugin.IdpCommandSender;
  1968. +import net.innectis.innplugin.IdpConsole;
  1969. import net.innectis.innplugin.InnPlugin;
  1970. import net.innectis.innplugin.InnectisObjects.*;
  1971. import net.innectis.innplugin.Inventory.IdpContainer;
  1972. @@ -35,6 +37,8 @@ import net.innectis.innplugin.Player.Chat.ChatColor;
  1973. import net.innectis.innplugin.Player.IdpPlayer;
  1974. import net.innectis.innplugin.Player.Infractions.InfractionManager;
  1975. import net.innectis.innplugin.Player.Permission;
  1976. +import net.innectis.innplugin.Player.PlayerCredentials;
  1977. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  1978. import net.innectis.innplugin.Player.PlayerGroup;
  1979. import net.innectis.innplugin.Player.PlayerSession;
  1980. import net.innectis.innplugin.Player.Request.Request;
  1981. @@ -125,7 +129,7 @@ public final class InformationCommands {
  1982. return true;
  1983. }
  1984.  
  1985. - if (!innchest.canPlayerAccess(player)
  1986. + if (!innchest.canPlayerAccess(player.getName())
  1987. && !player.hasPermission(Permission.owned_object_override)) {
  1988. player.printError("You cannot access this chest. Unable to count contents!");
  1989. return true;
  1990. @@ -155,20 +159,42 @@ public final class InformationCommands {
  1991. usage = "/statistics [player]",
  1992. serverCommand = true)
  1993. public static boolean commandStatistics(Server server, InnPlugin parent, IdpCommandSender<? extends CommandSender> sender, String[] args) {
  1994. - PlayerSession session = PlayerSession.getSession(sender.getName(), parent);
  1995. + PlayerSession session = null;
  1996.  
  1997. - if (args.length == 1) {
  1998. - session = PlayerSession.getSession(args[0], parent);
  1999. - }
  2000. + if (args.length > 0) {
  2001. + String playerName = args[0];
  2002. + IdpPlayer target = parent.getPlayer(playerName);
  2003.  
  2004. - if (!session.isValidPlayer()) {
  2005. - session.destroy();
  2006. - sender.printError("Player not found!");
  2007. - return true;
  2008. + if (target != null) {
  2009. + session = target.getSession();
  2010. + } else {
  2011. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  2012. +
  2013. + if (credentials == null) {
  2014. + sender.printError("That player does not exist.");
  2015. + return true;
  2016. + }
  2017. +
  2018. + session = PlayerSession.getSession(credentials.getUniqueId(), credentials.getName(), parent, true);
  2019. + }
  2020. + } else {
  2021. + if (sender instanceof IdpConsole) {
  2022. + sender.printError("Cannot lookup statistics for console!");
  2023. + return true;
  2024. + }
  2025. +
  2026. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(sender.getName());
  2027. +
  2028. + if (credentials == null) {
  2029. + sender.printError("Could not look up statistics for you!");
  2030. + return true;
  2031. + }
  2032. +
  2033. + session = PlayerSession.getSession(credentials.getUniqueId(), credentials.getName(), parent, true);
  2034. }
  2035.  
  2036. String name = session.getDisplayName();
  2037. - TransactionObject transaction = TransactionHandler.getTransactionObject(name);
  2038. + TransactionObject transaction = TransactionHandler.getTransactionObject(session.getUniqueId(), session.getRealName());
  2039.  
  2040. List<InnectisLot> lots = LotHandler.getLots(name);
  2041. String lotInfo;
  2042. @@ -241,9 +267,10 @@ public final class InformationCommands {
  2043. }
  2044.  
  2045. if (sender.hasPermission(Permission.command_information_statistics_extended)) {
  2046. - sender.print(ChatColor.GOLD, "Infraction level: " + InfractionManager.getManager().getInfractionLevel(session.getRealName()));
  2047. + sender.print(ChatColor.GOLD, "Infraction level: " + InfractionManager.getManager().getInfractionLevel(session.getUniqueId(), session.getRealName()));
  2048. sender.print(ChatColor.GOLD, "Status: " + session.getPlayerStatus());
  2049. }
  2050. +
  2051. return true;
  2052. }
  2053.  
  2054. @@ -376,7 +403,7 @@ public final class InformationCommands {
  2055. InnectisWaypoint wp = (InnectisWaypoint) ownedObj;
  2056. Location waypointLocation = wp.getDestination();
  2057. InnectisLot lot = LotHandler.getLot(waypointLocation);
  2058. - boolean canSee = (!wp.isFlagSet(WaypointFlagType.HIDDEN) || wp.canPlayerAccess(player)
  2059. + boolean canSee = (!wp.isFlagSet(WaypointFlagType.HIDDEN) || wp.canPlayerAccess(player.getName())
  2060. || player.hasPermission(Permission.owned_object_override));
  2061.  
  2062. if (canSee) {
  2063. @@ -473,32 +500,27 @@ public final class InformationCommands {
  2064. }
  2065. //</editor-fold>
  2066.  
  2067. - // Normal command
  2068. + String playerName = args.getString(0);
  2069. + IdpPlayer target = parent.getPlayer(playerName);
  2070. + PlayerSession session = null;
  2071. boolean playerOnline = false;
  2072.  
  2073. - String playername = args.getString(0);
  2074. -
  2075. - if (playername == null) {
  2076. - sender.printError("No player name specified!");
  2077. - return;
  2078. - }
  2079. -
  2080. - IdpPlayer player = parent.getPlayer(playername, false, true);
  2081. - PlayerSession session = null;
  2082. + if (target != null) {
  2083. + playerName = target.getName();
  2084. + session = target.getSession();
  2085. + playerOnline = true;
  2086. + } else {
  2087. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  2088.  
  2089. - if (player == null) {
  2090. - if (!PlayerSession.isValidPlayer(playername)) {
  2091. - sender.printError("Player " + playername + " not found!");
  2092. + if (credentials == null) {
  2093. + sender.printError("That player does not exist.");
  2094. return;
  2095. }
  2096.  
  2097. - session = PlayerSession.getSession(playername, parent);
  2098. - } else {
  2099. - session = player.getSession();
  2100. - playerOnline = true;
  2101. + session = PlayerSession.getSession(credentials.getUniqueId(), credentials.getName(), parent, true);
  2102. }
  2103.  
  2104. - TransactionObject transaction = TransactionHandler.getTransactionObject(playername);
  2105. + TransactionObject transaction = TransactionHandler.getTransactionObject(session.getUniqueId(), session.getRealName());
  2106.  
  2107. sender.printInfo("Player: " + session.getColoredDisplayName());
  2108.  
  2109. @@ -519,14 +541,14 @@ public final class InformationCommands {
  2110. }
  2111.  
  2112. if (playerOnline && args.hasOption("world", "w")) {
  2113. - sender.printInfo("World: " + ChatColor.AQUA + player.getWorld().getName());
  2114. + sender.printInfo("World: " + ChatColor.AQUA + target.getWorld().getName());
  2115. }
  2116.  
  2117. if (playerOnline && args.hasOption("location", "loc")) {
  2118. - sender.printInfo("Location: " + ChatColor.AQUA + LocationUtil.locationString(player.getLocation()));
  2119. + sender.printInfo("Location: " + ChatColor.AQUA + LocationUtil.locationString(target.getLocation()));
  2120. }
  2121.  
  2122. - Player bukkitPlayer = (playerOnline ? player.getHandle() : null);
  2123. + Player bukkitPlayer = (playerOnline ? target.getHandle() : null);
  2124.  
  2125. if (playerOnline && args.hasOption("ip")) {
  2126. sender.printInfo("IP: " + ChatColor.AQUA + bukkitPlayer.getAddress().getAddress().toString());
  2127. @@ -578,7 +600,7 @@ public final class InformationCommands {
  2128. // Destroys the session!
  2129. if (args.hasOption("destroy")) {
  2130. if (playerOnline) {
  2131. - player.getHandle().kickPlayer("Sorry for that, please rejoin.");
  2132. + target.getHandle().kickPlayer("Sorry for that, please rejoin.");
  2133. }
  2134. session.destroy();
  2135. sender.printInfo("Session destroyed!");
  2136. @@ -625,10 +647,10 @@ public final class InformationCommands {
  2137. }
  2138.  
  2139. if (playerOnline) {
  2140. - if (player.getGroup() == PlayerGroup.SADMIN && !sender.hasPermission(Permission.command_admin_perm)) {
  2141. + if (target.getGroup() == PlayerGroup.SADMIN && !sender.hasPermission(Permission.command_admin_perm)) {
  2142. sender.printInfo("No geo info");
  2143. } else {
  2144. - IPAddress[] addresses = info.lookupPartialIp(player.getHandle().getAddress().getAddress().toString().substring(1));
  2145. + IPAddress[] addresses = info.lookupPartialIp(target.getHandle().getAddress().getAddress().toString().substring(1));
  2146. if (addresses.length > 0) {
  2147. GeoLocation geoloc = addresses[0].getGeoLocation();
  2148. if (geoloc != null) {
  2149. @@ -673,7 +695,7 @@ public final class InformationCommands {
  2150. sender.printInfo("Linked accounts: " + ChatColor.AQUA + "None");
  2151. }
  2152. } else {
  2153. - sender.printError("Unable to get linked usernames for " + playername + "!");
  2154. + sender.printError("Unable to get linked usernames for " + playerName + "!");
  2155. }
  2156. }
  2157. }
  2158. diff --git a/src/net/innectis/innplugin/Command/Commands/LocationCommands.java b/src/net/innectis/innplugin/Command/Commands/LocationCommands.java
  2159. index 895f38578..4e2a941ba 100644
  2160. --- a/src/net/innectis/innplugin/Command/Commands/LocationCommands.java
  2161. +++ b/src/net/innectis/innplugin/Command/Commands/LocationCommands.java
  2162. @@ -46,6 +46,8 @@ import net.innectis.innplugin.OwnedObjects.LotFlagType;
  2163. import net.innectis.innplugin.Player.Chat.ChatColor;
  2164. import net.innectis.innplugin.Player.IdpPlayer;
  2165. import net.innectis.innplugin.Player.Permission;
  2166. +import net.innectis.innplugin.Player.PlayerCredentials;
  2167. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  2168. import net.innectis.innplugin.Player.PlayerGroup;
  2169. import net.innectis.innplugin.Player.PlayerSession;
  2170. import net.innectis.innplugin.Player.Request.Request;
  2171. @@ -305,7 +307,7 @@ public final class LocationCommands {
  2172. }
  2173.  
  2174. InnectisLot lot = LotHandler.getLot(loc);
  2175. - if (lot != null && !lot.canPlayerAccess(player) && !lot.getHidden()
  2176. + if (lot != null && !lot.canPlayerAccess(player.getName()) && !lot.getHidden()
  2177. && !player.hasPermission(Permission.lot_sethome_override)) {
  2178. player.printError("You cannot set your home here!");
  2179. return true;
  2180. @@ -792,12 +794,13 @@ public final class LocationCommands {
  2181. return true;
  2182. }
  2183.  
  2184. - if (lot == null || (lot != null && (lot.canPlayerAccess(player))
  2185. + if (lot == null || (lot != null && (lot.canPlayerAccess(player.getName()))
  2186. || player.hasPermission(Permission.owned_object_override))) {
  2187. boolean force = player.hasPermission(Permission.special_waypoint_nodeduct);
  2188.  
  2189. if (force || player.removeItemFromInventory(IdpMaterial.LAPIS_LAZULI_BLOCK, 3)) {
  2190. - InnectisWaypoint waypoint = WaypointHandler.createWaypoint(player, block, force);
  2191. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName(), true);
  2192. + InnectisWaypoint waypoint = WaypointHandler.createWaypoint(credentials, block, force);
  2193. if (waypoint != null) {
  2194. player.printInfo("Waypoint created! Use \"/wpset " + waypoint.getId() + "\" to set target location.");
  2195. } else {
  2196. @@ -847,11 +850,11 @@ public final class LocationCommands {
  2197.  
  2198. if (waypoint == null) {
  2199. player.printError("Waypoint not found!");
  2200. - } else if (waypoint.canPlayerManage(player)
  2201. + } else if (waypoint.canPlayerManage(player.getName())
  2202. || player.hasPermission(Permission.owned_waypoint_setall)) {
  2203. InnectisLot lot = LotHandler.getLot(player.getLocation());
  2204.  
  2205. - if (lot == null || lot.canPlayerManage(player)
  2206. + if (lot == null || lot.canPlayerManage(player.getName())
  2207. || player.hasPermission(Permission.owned_waypoint_setanywhere)) {
  2208. waypoint.setDestination(player.getLocation());
  2209.  
  2210. @@ -1088,7 +1091,22 @@ public final class LocationCommands {
  2211. }
  2212.  
  2213. String previousOwner = obj.getOwner();
  2214. - obj.setOwner(owner);
  2215. +
  2216. + PlayerCredentials credentials = null;
  2217. +
  2218. + // Only allow assignable owner on lots
  2219. + if (owner.equals("#") && obj instanceof InnectisLot) {
  2220. + credentials = Configuration.LOT_ASSIGNABLE_CREDENTIALS;
  2221. + } else {
  2222. + credentials = PlayerCredentialsManager.getByName(owner, true);
  2223. +
  2224. + if (credentials == null) {
  2225. + player.printError("That player doesn't exist!");
  2226. + return true;
  2227. + }
  2228. + }
  2229. +
  2230. + obj.setOwner(credentials);
  2231.  
  2232. // Special cleanup for lots
  2233. if (obj instanceof InnectisLot) {
  2234. @@ -1231,7 +1249,7 @@ public final class LocationCommands {
  2235. tpCost = 35;
  2236. }
  2237.  
  2238. - TransactionObject transaction = TransactionHandler.getTransactionObject(player.getName());
  2239. + TransactionObject transaction = TransactionHandler.getTransactionObject(player.getUniqueId(), player.getName());
  2240. int balance = transaction.getValue(TransactionType.VALUTAS);
  2241.  
  2242. if (balance >= tpCost) {
  2243. @@ -1319,7 +1337,8 @@ public final class LocationCommands {
  2244. case WAYPOINT: {
  2245. if (WaypointHandler.getWaypoint(loc) == null) {
  2246. try {
  2247. - InnectisWaypoint waypoint = WaypointHandler.createWaypoint(lot.getOwner(), block, false);
  2248. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(lot.getOwner(), true);
  2249. + InnectisWaypoint waypoint = WaypointHandler.createWaypoint(credentials, block, false);
  2250. if (waypoint != null) {
  2251. sender.printInfo(StringUtil.format("Unlinked waypoint at {0} -> #{1}", LocationUtil.locationString(loc), waypoint.getId()));
  2252. break;
  2253. @@ -1334,7 +1353,8 @@ public final class LocationCommands {
  2254. case IRON_DOOR_BLOCK: {
  2255. if (DoorHandler.getDoor(loc) == null) {
  2256. try {
  2257. - InnectisDoor door = DoorHandler.createDoor(lot.getOwner(), block);
  2258. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(lot.getOwner(), true);
  2259. + InnectisDoor door = DoorHandler.createDoor(credentials, block);
  2260. if (door != null) {
  2261. sender.printInfo(StringUtil.format("Unlinked door at {0} -> #{1}", LocationUtil.locationString(loc), door.getId()));
  2262. break;
  2263. @@ -1350,7 +1370,8 @@ public final class LocationCommands {
  2264. case TRAPPED_CHEST: {
  2265. if (ChestHandler.getChest(loc) == null) {
  2266. try {
  2267. - InnectisChest chest = ChestHandler.createChest(lot.getOwner(), block);
  2268. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(lot.getOwner());
  2269. + InnectisChest chest = ChestHandler.createChest(credentials, block);
  2270. if (chest != null) {
  2271. sender.printInfo(StringUtil.format("Unlinked chest at {0} -> #{1}", LocationUtil.locationString(loc), chest.getId()));
  2272. break;
  2273. @@ -1365,7 +1386,8 @@ public final class LocationCommands {
  2274. case TRAP_DOOR: {
  2275. if (TrapdoorHandler.getTrapdoor(loc) == null) {
  2276. try {
  2277. - InnectisTrapdoor trapdoor = TrapdoorHandler.createTrapdoor(block.getWorld(), loc, lot.getOwner());
  2278. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(lot.getOwner());
  2279. + InnectisTrapdoor trapdoor = TrapdoorHandler.createTrapdoor(block.getWorld(), loc, credentials);
  2280.  
  2281. if (trapdoor != null) {
  2282. sender.printInfo(StringUtil.format("Unlinked trapdoor at {0} -> #{1}", LocationUtil.locationString(loc), trapdoor.getId()));
  2283. @@ -1579,7 +1601,7 @@ public final class LocationCommands {
  2284. InnectisLot lot = (InnectisLot) innOwnedObj;
  2285.  
  2286. if (!canSet) {
  2287. - canSet = (lot.canPlayerAccess(player) && player.hasPermission(Permission.lot_memberlot_flagset));
  2288. + canSet = (lot.canPlayerAccess(player.getName()) && player.hasPermission(Permission.lot_memberlot_flagset));
  2289. }
  2290.  
  2291. if (!canSet) {
  2292. @@ -1683,25 +1705,28 @@ public final class LocationCommands {
  2293. return true;
  2294. }
  2295.  
  2296. - String targPlayer = args[1];
  2297. + String playerName = args[1];
  2298.  
  2299. - boolean modifyOperator = targPlayer.startsWith("!");
  2300. + boolean modifyOperator = playerName.startsWith("!");
  2301.  
  2302. if (modifyOperator) {
  2303. - targPlayer = targPlayer.substring(1);
  2304. + playerName = playerName.substring(1);
  2305. }
  2306.  
  2307. - IdpPlayer target = parent.getPlayer(targPlayer);
  2308. + IdpPlayer target = parent.getPlayer(playerName);
  2309.  
  2310. if (target != null) {
  2311. - targPlayer = target.getName();
  2312. + playerName = target.getName();
  2313. }
  2314.  
  2315. - PlayerGroup group = PlayerGroup.getGroupOfUsername(targPlayer);
  2316. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  2317.  
  2318. - if (group == PlayerGroup.NONE) {
  2319. - player.printError("That player doesn't exist.");
  2320. + if (credentials == null) {
  2321. + player.printError("That player does not exist.");
  2322. return true;
  2323. + } else {
  2324. + // Get the proper casing of the name
  2325. + playerName = credentials.getName();
  2326. }
  2327.  
  2328. // Lists all checked objects in the selection. This is because multiple
  2329. @@ -1740,62 +1765,64 @@ public final class LocationCommands {
  2330. if (obj != null) {
  2331. // Make sure the object isn't modified more than once
  2332. if (!queried.contains(obj)) {
  2333. - if (obj.canPlayerManage(player) || player.hasPermission(Permission.owned_object_override)) {
  2334. - if (obj.getOwner().equalsIgnoreCase(targPlayer)) {
  2335. - player.printError(targPlayer + " is owner of " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ". Cannot add!");
  2336. + if (obj.canPlayerManage(player.getName()) || player.hasPermission(Permission.owned_object_override)) {
  2337. + if (obj.getOwner().equalsIgnoreCase(playerName)) {
  2338. + player.printError(playerName + " is owner of " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ". Cannot add!");
  2339. continue;
  2340. }
  2341.  
  2342. if (action == 1) {
  2343. - if (obj.containsMember(targPlayer) || obj.containsOperator(targPlayer)) {
  2344. - if (modifyOperator && obj.containsMember(targPlayer)) {
  2345. - obj.addOperator(targPlayer);
  2346. + if (obj.containsMember(playerName) || obj.containsOperator(playerName)) {
  2347. + if (modifyOperator && obj.containsMember(playerName)) {
  2348. + obj.addOperator(credentials);
  2349. save = true;
  2350. - saveMsg = "Added " + targPlayer + " as operator to " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".";
  2351. + saveMsg = "Added " + playerName + " as operator to " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".";
  2352. } else {
  2353. - player.printError(targPlayer + " is already added to " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".");
  2354. + player.printError(playerName + " is already added to " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".");
  2355. continue;
  2356. }
  2357. } else {
  2358. if (modifyOperator) {
  2359. - obj.addOperator(targPlayer);
  2360. + obj.addOperator(credentials);
  2361. } else {
  2362. - obj.addMember(targPlayer);
  2363. + obj.addMember(credentials);
  2364. }
  2365.  
  2366. save = true;
  2367. - saveMsg = "Added " + targPlayer + (modifyOperator ? " as operator" : "") + " to " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".";
  2368. + saveMsg = "Added " + playerName + (modifyOperator ? " as operator" : "") + " to " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".";
  2369. }
  2370. } else if (action == 2) {
  2371. - if (obj.containsMember(targPlayer) || obj.containsOperator(targPlayer)) {
  2372. + if (obj.containsMember(playerName) || obj.containsOperator(playerName)) {
  2373. if (modifyOperator) {
  2374. - if (obj.containsOperator(targPlayer)) {
  2375. - obj.removeOperator(targPlayer);
  2376. + if (obj.containsOperator(playerName)) {
  2377. + obj.removeOperator(playerName);
  2378. save = true;
  2379. - saveMsg = "Removed " + targPlayer + " as operator of " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".";
  2380. + saveMsg = "Removed " + playerName + " as operator of " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".";
  2381. } else {
  2382. - player.printError(targPlayer + " is not an operator of " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".");
  2383. + player.printError(playerName + " is not an operator of " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".");
  2384. continue;
  2385. }
  2386. } else {
  2387. - boolean isOperator = obj.containsOperator(targPlayer);
  2388. + boolean isOperator = obj.containsOperator(playerName);
  2389.  
  2390. if (isOperator) {
  2391. - obj.removeOperator(targPlayer);
  2392. + obj.removeOperator(playerName);
  2393. } else {
  2394. - obj.removeMember(targPlayer);
  2395. + obj.removeMember(playerName);
  2396. }
  2397.  
  2398. save = true;
  2399. - saveMsg = "Removed " + targPlayer + (isOperator ? " as operator" : "") + " from " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".";
  2400. + saveMsg = "Removed " + playerName + (isOperator ? " as operator" : "") + " from " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".";
  2401. }
  2402. } else {
  2403. - player.printError(targPlayer + " is not added to " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".");
  2404. + player.printError(playerName + " is not added to " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".");
  2405. continue;
  2406. }
  2407. }
  2408.  
  2409. if (save) {
  2410. + PlayerCredentialsManager.addCredentialsToCache(credentials);
  2411. +
  2412. if (obj.save()) {
  2413. player.printInfo(saveMsg);
  2414. } else {
  2415. @@ -1803,7 +1830,7 @@ public final class LocationCommands {
  2416. }
  2417. }
  2418. } else {
  2419. - player.printError("You do not have permission to" + (action == 1 ? " add " : "remove ") + targPlayer + (action == 1 ? " to " : " from ") + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".");
  2420. + player.printError("You do not have permission to" + (action == 1 ? " add " : "remove ") + playerName + (action == 1 ? " to " : " from ") + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".");
  2421. }
  2422.  
  2423. queried.add(obj);
  2424. @@ -1838,10 +1865,10 @@ public final class LocationCommands {
  2425. targPlayer = target.getName();
  2426. }
  2427.  
  2428. - PlayerGroup group = PlayerGroup.getGroupOfUsername(targPlayer);
  2429. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(targPlayer);
  2430.  
  2431. - if (group == PlayerGroup.NONE) {
  2432. - player.printError("That player doesn't exist.");
  2433. + if (credentials == null) {
  2434. + player.printError("That player does not exist.");
  2435. return true;
  2436. }
  2437.  
  2438. @@ -1881,7 +1908,8 @@ public final class LocationCommands {
  2439. if (!queried.contains(obj)) {
  2440. if (!obj.getOwner().equalsIgnoreCase(targPlayer)) {
  2441. String previousOwner = obj.getOwner();
  2442. - obj.setOwner(targPlayer);
  2443. + obj.setOwner(credentials);
  2444. + PlayerCredentialsManager.addCredentialsToCache(credentials);
  2445.  
  2446. if (obj.save()) {
  2447. player.print(ChatColor.AQUA, "Set the owner of " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + " from " + previousOwner + " to " + targPlayer + ".");
  2448. diff --git a/src/net/innectis/innplugin/Command/Commands/LotCommands.java b/src/net/innectis/innplugin/Command/Commands/LotCommands.java
  2449. index 13b4978b4..21854e202 100644
  2450. --- a/src/net/innectis/innplugin/Command/Commands/LotCommands.java
  2451. +++ b/src/net/innectis/innplugin/Command/Commands/LotCommands.java
  2452. @@ -8,6 +8,7 @@ import java.util.HashMap;
  2453. import java.util.List;
  2454. import java.util.Random;
  2455. import net.innectis.innplugin.Command.CommandMethod;
  2456. +import net.innectis.innplugin.Configuration;
  2457. import net.innectis.innplugin.Handlers.BlockHandler;
  2458. import net.innectis.innplugin.Handlers.PagedCommandHandler;
  2459. import net.innectis.innplugin.IdpCommandSender;
  2460. @@ -20,6 +21,8 @@ import net.innectis.innplugin.OwnedObjects.InnectisLot;
  2461. import net.innectis.innplugin.Player.Chat.ChatColor;
  2462. import net.innectis.innplugin.Player.IdpPlayer;
  2463. import net.innectis.innplugin.Player.Permission;
  2464. +import net.innectis.innplugin.Player.PlayerCredentials;
  2465. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  2466. import net.innectis.innplugin.Player.PlayerGroup;
  2467. import net.innectis.innplugin.Player.PlayerSession;
  2468. import net.innectis.innplugin.Player.Request.LotRemovalRequest;
  2469. @@ -50,52 +53,64 @@ public final class LotCommands {
  2470. return false;
  2471. }
  2472.  
  2473. - String target = args[0];
  2474. - PlayerGroup group = PlayerGroup.getGroupOfUsername(target);
  2475. + String playerName = args[0];
  2476. + IdpPlayer target = parent.getPlayer(playerName);
  2477.  
  2478. - if (group == PlayerGroup.NONE) {
  2479. - sender.printError("Target does not have a Player Group: " + target);
  2480. + if (target != null) {
  2481. + playerName = target.getName();
  2482. + }
  2483. +
  2484. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  2485. +
  2486. + if (credentials == null) {
  2487. + sender.printError("That player does not exist.");
  2488. + return true;
  2489. } else {
  2490. - List<InnectisLot> lots = LotHandler.getLots(target);
  2491. - if (lots == null) {
  2492. - sender.printError("Target does not have any lots: " + target);
  2493. - } else {
  2494. - sender.print(ChatColor.AQUA, "Checking lots for " + target + " (" + group.name + ")..");
  2495. - List<String> violationsFound = new ArrayList<String>();
  2496. - for (InnectisLot lot : lots) {
  2497. + // Get the proper casing of the player
  2498. + playerName = credentials.getName();
  2499. + }
  2500.  
  2501. - if (lot.containsMember("%")) {
  2502. - violationsFound.add(ChatColor.DARK_PURPLE + "[IDP] Lot #" + lot.getId() + ": Wildcard (%) is lot allowed!");
  2503. - }
  2504. + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(credentials.getUniqueId());
  2505.  
  2506. - for (PlayerGroup targetGroup : PlayerGroup.values()) {
  2507. - if (group.inherits(targetGroup) && lot.containsGroup(group)) {
  2508. - violationsFound.add(ChatColor.LIGHT_PURPLE + "[IDP] Lot #" + lot.getId() + ": Player Group " + targetGroup.color + targetGroup.name + ChatColor.LIGHT_PURPLE + " is lot allowed!");
  2509. - }
  2510. - }
  2511. + List<InnectisLot> lots = LotHandler.getLots(playerName);
  2512.  
  2513. - for (String operator : lot.getOperators()) {
  2514. - PlayerGroup targetGroup = PlayerGroup.getGroupOfUsername(operator);
  2515. - if (group != PlayerGroup.NONE && group.inherits(targetGroup)) {
  2516. - violationsFound.add(ChatColor.DARK_RED + "[IDP] Lot #" + lot.getId() + ": " + operator + " is a lot operator!");
  2517. - }
  2518. + if (lots == null) {
  2519. + sender.printError("Target does not have any lots: " + playerName);
  2520. + } else {
  2521. + sender.print(ChatColor.AQUA, "Checking lots for " + playerName + " (" + group.name + ")..");
  2522. + List<String> violationsFound = new ArrayList<String>();
  2523. + for (InnectisLot lot : lots) {
  2524. + if (lot.containsMember("%")) {
  2525. + violationsFound.add(ChatColor.DARK_PURPLE + "[IDP] Lot #" + lot.getId() + ": Wildcard (%) is lot allowed!");
  2526. + }
  2527. +
  2528. + for (PlayerGroup targetGroup : PlayerGroup.values()) {
  2529. + if (group.inherits(targetGroup) && lot.containsPlayerGroup(group)) {
  2530. + violationsFound.add(ChatColor.LIGHT_PURPLE + "[IDP] Lot #" + lot.getId() + ": Player Group " + targetGroup.color + targetGroup.name + ChatColor.LIGHT_PURPLE + " is lot allowed!");
  2531. }
  2532. + }
  2533.  
  2534. - for (String member : lot.getMembers()) {
  2535. - PlayerGroup targetGroup = PlayerGroup.getGroupOfUsername(member);
  2536. - if (group != PlayerGroup.NONE && group.inherits(targetGroup)) {
  2537. - violationsFound.add(ChatColor.RED + "[IDP] Lot #" + lot.getId() + ": " + member + " is a lot member.");
  2538. - }
  2539. + for (PlayerCredentials pc : lot.getOperators()) {
  2540. + PlayerGroup targetGroup = PlayerGroup.getGroupOfPlayerById(pc.getUniqueId());
  2541. + if (group != PlayerGroup.NONE && group.inherits(targetGroup)) {
  2542. + violationsFound.add(ChatColor.DARK_RED + "[IDP] Lot #" + lot.getId() + ": " + pc.getName() + " is a lot operator!");
  2543. }
  2544. }
  2545. - if (violationsFound.isEmpty()) {
  2546. - sender.printInfo("No violations found on targets lots!");
  2547. - } else {
  2548. - for (String error : violationsFound) {
  2549. - sender.printRaw(error);
  2550. +
  2551. + for (PlayerCredentials pc : lot.getMembers()) {
  2552. + PlayerGroup targetGroup = PlayerGroup.getGroupOfPlayerById(pc.getUniqueId());
  2553. + if (group != PlayerGroup.NONE && group.inherits(targetGroup)) {
  2554. + violationsFound.add(ChatColor.RED + "[IDP] Lot #" + lot.getId() + ": " + pc.getName() + " is a lot member.");
  2555. }
  2556. }
  2557. + }
  2558.  
  2559. + if (violationsFound.isEmpty()) {
  2560. + sender.printInfo("No violations found on targets lots!");
  2561. + } else {
  2562. + for (String error : violationsFound) {
  2563. + sender.printRaw(error);
  2564. + }
  2565. }
  2566. }
  2567.  
  2568. @@ -314,7 +329,6 @@ public final class LotCommands {
  2569. IdpRegion region;
  2570.  
  2571. World world = player.getLocation().getWorld();
  2572. - String playername = player.getName();
  2573.  
  2574. BlockCounter counter = BlockCounterFactory.getCounter(BlockCounterFactory.CountType.CUBOID);
  2575. region = new IdpRegion(start, end);
  2576. @@ -373,6 +387,8 @@ public final class LotCommands {
  2577.  
  2578. int increment = lotWidth + lotMargin * 2 + pathWidth;
  2579.  
  2580. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName(), true);
  2581. +
  2582. Vector loc1, loc2;
  2583. for (; x < max_x; x += increment) {
  2584. for (int z = start_z; z < max_z; z += increment) {
  2585. @@ -411,7 +427,7 @@ public final class LotCommands {
  2586.  
  2587. // Create the lot
  2588. try {
  2589. - InnectisLot lot = LotHandler.addLot(world, vec1, vec2, "#", playername);
  2590. + InnectisLot lot = LotHandler.addLot(world, vec1, vec2, Configuration.LOT_ASSIGNABLE_CREDENTIALS, credentials);
  2591. lot.setSpawn(new Location(world, loc1.getBlockX(), loc1.getBlockY(), loc1.getBlockZ()));
  2592. lot.save();
  2593. player.printInfo("Lot: " + ChatColor.AQUA + lot.getId() + ChatColor.DARK_PURPLE, " " + lot.getMinimumPoint() + " " + lot.getMaximumPoint());
  2594. @@ -423,7 +439,7 @@ public final class LotCommands {
  2595. }
  2596.  
  2597. try {
  2598. - InnectisLot lot = LotHandler.addLot(world, new Vector(start.getBlockX(), 0, start.getBlockZ()), new Vector(end.getBlockX(), 255, end.getBlockZ()), "~", playername);
  2599. + InnectisLot lot = LotHandler.addLot(world, new Vector(start.getBlockX(), 0, start.getBlockZ()), new Vector(end.getBlockX(), 255, end.getBlockZ()), Configuration.OTHER_CREDENTIALS, credentials);
  2600. lot.setSpawn(new Location(player.getLocation().getWorld(), start.getBlockX(), start.getBlockY(), start.getBlockZ()));
  2601. lot.setHidden(true);
  2602. lot.save();
  2603. @@ -531,14 +547,7 @@ public final class LotCommands {
  2604.  
  2605. if (lastEdit > 0 && (System.currentTimeMillis() - lastEdit) >= timeLastEdited) {
  2606. int id = lot.getId();
  2607. - String owner = lot.getOwner();
  2608. -
  2609. - // Filter shop owners
  2610. - if (owner.startsWith("#")) {
  2611. - owner = owner.substring(2);
  2612. - }
  2613. -
  2614. - PlayerGroup group = PlayerGroup.getGroupOfUsername(owner);
  2615. + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(lot.getOwnerCredentials().getUniqueId());
  2616.  
  2617. if (foundLots.containsKey(group)) {
  2618. foundLots.get(group).add(group.getPrefix().getTextColor().toString() + id);
  2619. @@ -836,7 +845,9 @@ public final class LotCommands {
  2620. pos2 = pos2.setY(player.getWorld().getMaxHeight() - 1);
  2621. }
  2622.  
  2623. - InnectisLot lot = LotHandler.addLot(player.getLocation().getWorld(), pos1, pos2, username, player.getName());
  2624. + PlayerCredentials ownerCredentials = PlayerCredentialsManager.getByName(player.getName(), true);
  2625. + PlayerCredentials creatorCredentials = PlayerCredentialsManager.getByName(username, true);
  2626. + InnectisLot lot = LotHandler.addLot(player.getLocation().getWorld(), pos1, pos2, creatorCredentials, ownerCredentials);
  2627. lot.setSpawn(spawn);
  2628. lot.save();
  2629. LotHandler.getLots().put(lot.getId(), lot);
  2630. @@ -881,7 +892,7 @@ public final class LotCommands {
  2631. boolean makeAssignable = args.hasOption("makeassignable", "ma");
  2632.  
  2633. if (makeAssignable) {
  2634. - lot.setOwner("#");
  2635. + lot.setOwner(Configuration.LOT_ASSIGNABLE_CREDENTIALS);
  2636. lot.setLastOwnerEdit(0);
  2637. lot.setLastMemberEdit(0);
  2638. }
  2639. @@ -1007,9 +1018,13 @@ public final class LotCommands {
  2640. player.printError("To get another, please talk to a Moderator.");
  2641. } else {
  2642. try {
  2643. - if (LotHandler.assignLot(player.getName()) == null) {
  2644. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName());
  2645. +
  2646. + if (LotHandler.assignLot(credentials) == null) {
  2647. player.printError("There are no lots available.");
  2648. player.printError("Please notify an Admin so they can get you one.");
  2649. + } else {
  2650. + PlayerCredentialsManager.addCredentialsToCache(credentials);
  2651. }
  2652. } catch (SQLException ex) {
  2653. InnPlugin.logError("Error when assigning a lot! ", ex);
  2654. @@ -1039,7 +1054,8 @@ public final class LotCommands {
  2655. if (targetLot == null) {
  2656. sender.printError("Lot #" + lotId + " not found!");
  2657. } else if (targetLot.isAssignable()) {
  2658. - lot = LotHandler.assignLot(targetName, targetLot);
  2659. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(targetName, true);
  2660. + lot = LotHandler.assignLot(credentials, targetLot);
  2661. } else {
  2662. sender.printError("Lot #" + lotId + " is not an assignable lot!");
  2663. }
  2664. @@ -1048,7 +1064,8 @@ public final class LotCommands {
  2665. return true;
  2666. }
  2667. } else {
  2668. - lot = LotHandler.assignLot(targetName);
  2669. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(targetName);
  2670. + lot = LotHandler.assignLot(credentials);
  2671. }
  2672.  
  2673. if (lot == null) {
  2674. @@ -1100,7 +1117,7 @@ public final class LotCommands {
  2675. player.printError("An internal server occured saving lot #" + lot.getId() + ". Contact an admin!");
  2676. }
  2677. } else {
  2678. - if (!lot.canPlayerManage(player)) {
  2679. + if (!lot.canPlayerManage(player.getName())) {
  2680. player.printError("Cannot change spawn on this lot!");
  2681. return true;
  2682. }
  2683. @@ -1312,7 +1329,7 @@ public final class LotCommands {
  2684. }
  2685.  
  2686. InnectisLot lot = null;
  2687. - String safeUser = "";
  2688. + String playerName = "";
  2689.  
  2690. if (args.length == 2) {
  2691. try {
  2692. @@ -1323,10 +1340,10 @@ public final class LotCommands {
  2693. return true;
  2694. }
  2695.  
  2696. - safeUser = args[1];
  2697. + playerName = args[1];
  2698. } else {
  2699. lot = LotHandler.getLot(player.getLocation());
  2700. - safeUser = args[0];
  2701. + playerName = args[0];
  2702. }
  2703.  
  2704. if (lot == null) {
  2705. @@ -1334,26 +1351,28 @@ public final class LotCommands {
  2706. return true;
  2707. }
  2708.  
  2709. - if (!(lot.canPlayerManage(player) || player.hasPermission(Permission.lot_command_override))) {
  2710. + if (!(lot.canPlayerManage(player.getName()) || player.hasPermission(Permission.lot_command_override))) {
  2711. player.printError("You do not manage this lot. (ID: " + lot.getId() + ")");
  2712. return true;
  2713. }
  2714.  
  2715. - IdpPlayer targ = parent.getPlayer(safeUser);
  2716. + IdpPlayer target = parent.getPlayer(playerName);
  2717.  
  2718. - if (targ != null) {
  2719. - safeUser = targ.getName();
  2720. + if (target != null) {
  2721. + playerName = target.getName();
  2722. }
  2723.  
  2724. - if (!PlayerSession.isValidPlayer(safeUser)) {
  2725. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName, true);
  2726. +
  2727. + if (credentials == null) {
  2728. player.printError("That user doesn't exist!");
  2729. return true;
  2730. }
  2731.  
  2732. - if (lot.addSafelist(safeUser)) {
  2733. - player.printInfo("Added " + safeUser + " to the safelist on lot #" + lot.getId() + ".");
  2734. + if (lot.addSafelist(credentials)) {
  2735. + player.printInfo("Added " + playerName + " to the safelist on lot #" + lot.getId() + ".");
  2736. } else {
  2737. - player.printError(safeUser + " is already safelisted on lot #" + lot.getId() + ".");
  2738. + player.printError(playerName + " is already safelisted on lot #" + lot.getId() + ".");
  2739. }
  2740.  
  2741. return true;
  2742. @@ -1392,7 +1411,7 @@ public final class LotCommands {
  2743. return true;
  2744. }
  2745.  
  2746. - if (!(lot.canPlayerManage(player) || player.hasPermission(Permission.lot_command_override))) {
  2747. + if (!(lot.canPlayerManage(player.getName()) || player.hasPermission(Permission.lot_command_override))) {
  2748. player.printError("You do not manage this lot. (ID: " + lot.getId() + ")");
  2749. return true;
  2750. }
  2751. @@ -1400,7 +1419,7 @@ public final class LotCommands {
  2752. boolean clearAll = safeUser.equalsIgnoreCase("-clear");
  2753.  
  2754. if (clearAll) {
  2755. - List<String> safelist = lot.getSafelist();
  2756. + List<PlayerCredentials> safelist = lot.getSafelist();
  2757.  
  2758. if (safelist.size() > 0) {
  2759. lot.clearSafelist();
  2760. @@ -1409,15 +1428,17 @@ public final class LotCommands {
  2761. player.printError("Lot #" + lot.getId() + " does not have a safelist.");
  2762. }
  2763. } else {
  2764. - IdpPlayer targ = parent.getPlayer(safeUser);
  2765. + IdpPlayer target = parent.getPlayer(safeUser);
  2766.  
  2767. - if (targ != null) {
  2768. - safeUser = targ.getName();
  2769. - }
  2770. + if (target != null) {
  2771. + safeUser = target.getName();
  2772. + } else {
  2773. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(safeUser);
  2774.  
  2775. - if (!PlayerSession.isValidPlayer(safeUser)) {
  2776. - player.printError("That user doesn't exist!");
  2777. - return true;
  2778. + if (credentials == null) {
  2779. + player.printError("That player doesn't exist!");
  2780. + return true;
  2781. + }
  2782. }
  2783.  
  2784. if (lot.removeSafelist(safeUser)) {
  2785. @@ -1519,7 +1540,7 @@ public final class LotCommands {
  2786. }
  2787.  
  2788. if (!lot.isValidPlayer(playerString, true)) {
  2789. - player.printError("That players does not exist!");
  2790. + player.printError("That player does not exist!");
  2791. return true;
  2792. }
  2793.  
  2794. @@ -1528,6 +1549,11 @@ public final class LotCommands {
  2795. return true;
  2796. }
  2797.  
  2798. + if (playerString.contains("@")) {
  2799. + player.printError("You cannot lotban @!");
  2800. + return true;
  2801. + }
  2802. +
  2803. if (playerString.equalsIgnoreCase("%")) {
  2804. for (IdpPlayer p : lot.getPlayersInsideRegion(0)) {
  2805. // If not self or staff
  2806. @@ -1541,13 +1567,13 @@ public final class LotCommands {
  2807. }
  2808. }
  2809.  
  2810. - lot.banUser("%", timeout);
  2811. -
  2812. - String personalBanMsg = "Banned % on lot #" + lot.getId() + ".";
  2813. + lot.banUser(Configuration.EVERYONE_CREDENTIALS, timeout);
  2814. + String personalBanMsg = "Banned everyone on lot #" + lot.getId() + ".";
  2815.  
  2816. if (timeout > 0) {
  2817. personalBanMsg += " for " + timeString;
  2818. }
  2819. +
  2820. personalBanMsg += ".";
  2821.  
  2822. player.printError(personalBanMsg);
  2823. @@ -1563,20 +1589,26 @@ public final class LotCommands {
  2824.  
  2825. for (String name : targetNames) {
  2826. IdpPlayer testPlayer = parent.getPlayer(name);
  2827. - String actualName = null;
  2828. + String actualName = name;
  2829. boolean tempSession = false;
  2830. + boolean valid = false;
  2831. PlayerSession session = null;
  2832.  
  2833. if (testPlayer != null) {
  2834. actualName = testPlayer.getName();
  2835. session = testPlayer.getSession();
  2836. - } else {
  2837. - actualName = name;
  2838. - session = PlayerSession.getSession(name, parent);
  2839. + valid = true;
  2840. + }
  2841. +
  2842. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(actualName);
  2843. +
  2844. + if (credentials != null) {
  2845. + session = PlayerSession.getSession(credentials.getUniqueId(), credentials.getName(), parent, true);
  2846. + valid = true;
  2847. tempSession = true;
  2848. }
  2849.  
  2850. - if (session.isValidPlayer()) {
  2851. + if (valid) {
  2852. if (!nameCache.contains(actualName.toLowerCase())) {
  2853. nameCache.add(actualName.toLowerCase());
  2854.  
  2855. @@ -1588,7 +1620,9 @@ public final class LotCommands {
  2856. }
  2857.  
  2858. if (canBan) {
  2859. - if (lot.banUser(actualName, timeout)) {
  2860. + if (lot.banUser(credentials, timeout)) {
  2861. + PlayerCredentialsManager.addCredentialsToCache(credentials);
  2862. +
  2863. if (timeout > 0) {
  2864. player.printInfo("Banned " + actualName + " from lot #" + lot.getId() + " for " + timeString + ".");
  2865. } else {
  2866. @@ -1920,7 +1954,7 @@ public final class LotCommands {
  2867. }
  2868. }
  2869.  
  2870. - if (lot.canPlayerManage(player)
  2871. + if (lot.canPlayerManage(player.getName())
  2872. || player.hasPermission(Permission.lot_command_override)) {
  2873. String unbanName = args[args.length - 1];
  2874.  
  2875. @@ -2390,7 +2424,7 @@ public final class LotCommands {
  2876. }
  2877.  
  2878. // Can only set border material if you have access to the lot
  2879. - if (!lot.canPlayerAccess(player)
  2880. + if (!lot.canPlayerAccess(player.getName())
  2881. && !player.hasPermission(Permission.lot_command_override)) {
  2882. player.printError("You cannot set a lot border here!");
  2883. return true;
  2884. diff --git a/src/net/innectis/innplugin/Command/Commands/MiscCommands.java b/src/net/innectis/innplugin/Command/Commands/MiscCommands.java
  2885. index 0f9614ac9..5dadf4e49 100644
  2886. --- a/src/net/innectis/innplugin/Command/Commands/MiscCommands.java
  2887. +++ b/src/net/innectis/innplugin/Command/Commands/MiscCommands.java
  2888. @@ -20,7 +20,6 @@ import net.innectis.innplugin.IdpCommandSender;
  2889. import net.innectis.innplugin.InnPlugin;
  2890. import net.innectis.innplugin.InnectisObjects.*;
  2891. import net.innectis.innplugin.Inventory.IdpInventory;
  2892. -import net.innectis.innplugin.Items.IdpItem;
  2893. import net.innectis.innplugin.Items.IdpItemStack;
  2894. import net.innectis.innplugin.Items.IdpMaterial;
  2895. import net.innectis.innplugin.Location.*;
  2896. @@ -38,6 +37,8 @@ import net.innectis.innplugin.Player.Chat.ChatColor;
  2897. import net.innectis.innplugin.Player.IdpPlayer;
  2898. import net.innectis.innplugin.Player.IdpPlayerInventory;
  2899. import net.innectis.innplugin.Player.Permission;
  2900. +import net.innectis.innplugin.Player.PlayerCredentials;
  2901. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  2902. import net.innectis.innplugin.Player.PlayerEffect;
  2903. import net.innectis.innplugin.Player.TinyWE.BlockCounters.BlockCounter;
  2904. import net.innectis.innplugin.Player.TinyWE.BlockCounters.BlockCounterFactory;
  2905. @@ -45,7 +46,6 @@ import net.innectis.innplugin.Tasking.LimitedTask;
  2906. import net.innectis.innplugin.Tasking.RunBehaviour;
  2907. import net.innectis.innplugin.Utility.LynxyArguments;
  2908. import net.innectis.innplugin.Utility.NotANumberException;
  2909. -import net.innectis.innplugin.Utility.NumberUtil;
  2910. import net.innectis.innplugin.Utility.ParameterArguments;
  2911. import net.innectis.innplugin.Utility.SmartArguments;
  2912. import net.innectis.innplugin.Utility.StringUtil;
  2913. @@ -78,33 +78,32 @@ public final class MiscCommands {
  2914. usage_Admin = "/findObject <-username (-u) [username]> <-chests> <-waypoints> <-doors> <-trapdoors> <-bookcases> <-switches>",
  2915. serverCommand = false)
  2916. public static void commandFindObject(InnPlugin plugin, IdpPlayer player, LynxyArguments args) {
  2917. -
  2918. List<InnectisOwnedObject> objectList = new ArrayList<InnectisOwnedObject>();
  2919. + String playerName = player.getName();
  2920.  
  2921. - String lookupPlayer = player.getName();
  2922. boolean extendedInfo = player.hasPermission(Permission.command_misc_findobject_extended);
  2923.  
  2924. if (extendedInfo && args.hasArgument("username", "u")) {
  2925. - lookupPlayer = (args.getString("username", "u"));
  2926. + playerName = (args.getString("username", "u"));
  2927. }
  2928.  
  2929. if (args.hasOption("chests", "chest")) {
  2930. - objectList.addAll(ChestHandler.getChests(lookupPlayer));
  2931. + objectList.addAll(ChestHandler.getChests(playerName));
  2932. }
  2933. if (args.hasOption("waypoints", "waypoint")) {
  2934. - objectList.addAll(WaypointHandler.getWaypoints(lookupPlayer));
  2935. + objectList.addAll(WaypointHandler.getWaypoints(playerName));
  2936. }
  2937. if (args.hasOption("doors", "door")) {
  2938. - objectList.addAll(DoorHandler.getDoors(lookupPlayer));
  2939. + objectList.addAll(DoorHandler.getDoors(playerName));
  2940. }
  2941. if (args.hasOption("trapdoors", "trapdoor")) {
  2942. - objectList.addAll(TrapdoorHandler.getTrapdoors(lookupPlayer));
  2943. + objectList.addAll(TrapdoorHandler.getTrapdoors(playerName));
  2944. }
  2945. if (args.hasOption("bookcases", "bookcase", "book")) {
  2946. - objectList.addAll(InnectisBookcase.getBookcases(lookupPlayer));
  2947. + objectList.addAll(InnectisBookcase.getBookcases(playerName));
  2948. }
  2949. if (args.hasOption("switches", "switch", "levers", "lever")) {
  2950. - objectList.addAll(InnectisSwitch.getSwitches(lookupPlayer));
  2951. + objectList.addAll(InnectisSwitch.getSwitches(playerName));
  2952. }
  2953.  
  2954. if (objectList.isEmpty()) {
  2955. @@ -112,7 +111,7 @@ public final class MiscCommands {
  2956. } else {
  2957. for (InnectisOwnedObject object : objectList) {
  2958. player.printInfo(object.getObjectName() + " #" + object.getId() +
  2959. - (extendedInfo ? " (" + lookupPlayer + ") " : " ")
  2960. + (extendedInfo ? " (" + playerName + ") " : " ")
  2961. + object.getPos1Location().toString());
  2962. }
  2963. }
  2964. @@ -140,7 +139,7 @@ public final class MiscCommands {
  2965. return true;
  2966. }
  2967.  
  2968. - TransactionObject transaction = TransactionHandler.getTransactionObject(player.getName());
  2969. + TransactionObject transaction = TransactionHandler.getTransactionObject(player.getUniqueId(), player.getName());
  2970. int playerValutas = transaction.getValue(TransactionType.VALUTAS);
  2971.  
  2972. if (amount > playerValutas) {
  2973. @@ -163,7 +162,7 @@ public final class MiscCommands {
  2974. }
  2975.  
  2976. transaction.subtractValue(amount, TransactionType.VALUTAS);
  2977. - TheEndPot.addValue(player.getName(), amount);
  2978. + TheEndPot.addValue(player.getUniqueId(), player.getName(), amount);
  2979.  
  2980. player.printInfo("You have added " + amount + " valuta" + (amount != 1 ? "s" : "") + " to The End pot!");
  2981.  
  2982. @@ -218,7 +217,7 @@ public final class MiscCommands {
  2983. if (player.getSession().isTractorRunning()) {
  2984. player.printError("Your tractor is already running!");
  2985. } else {
  2986. - TransactionObject transaction = TransactionHandler.getTransactionObject(player.getName());
  2987. + TransactionObject transaction = TransactionHandler.getTransactionObject(player.getUniqueId(), player.getName());
  2988. int valutas = transaction.getValue(TransactionType.VALUTAS);
  2989.  
  2990. if (valutas >= 100) {
  2991. @@ -251,8 +250,7 @@ public final class MiscCommands {
  2992.  
  2993. if (block != null && IdpMaterial.fromBlock(block).isChest()) {
  2994. InnectisChest chest = ChestHandler.getChest(block.getLocation());
  2995. - if (chest.canPlayerAccess(player)) {
  2996. -
  2997. + if (chest.canPlayerAccess(player.getName())) {
  2998. chest.sortContents();
  2999.  
  3000. player.printInfo("You have sorted chest #" + chest.getId());
  3001. @@ -363,8 +361,10 @@ public final class MiscCommands {
  3002. return true;
  3003. }
  3004.  
  3005. + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(player.getUniqueId());
  3006. +
  3007. // Make a present
  3008. - PresentContent present = new PresentContent(player.getName(), title);
  3009. + PresentContent present = new PresentContent(credentials, title);
  3010.  
  3011. // Make the inventory, replace spaces with underscores
  3012. IdpInventory inventory = new IdpInventory(title.replace(" ", "_"), 9);
  3013. @@ -527,7 +527,7 @@ public final class MiscCommands {
  3014.  
  3015. InnectisLot lot = LotHandler.getLot(signBlock.getLocation());
  3016.  
  3017. - if (lot == null || (lot != null && lot.canPlayerAccess(player))
  3018. + if (lot == null || (lot != null && lot.canPlayerAccess(player.getName()))
  3019. || player.hasPermission(Permission.special_signedit)) {
  3020. int lineNo = 0;
  3021.  
  3022. @@ -563,7 +563,7 @@ public final class MiscCommands {
  3023. if (ChestType.isValidChestBlock(IdpMaterial.fromBlock(chestBlock))) {
  3024. InnectisChest ichest = ChestHandler.getChest(loc);
  3025.  
  3026. - if (ichest != null && !(ichest.canPlayerManage(player)
  3027. + if (ichest != null && !(ichest.canPlayerManage(player.getName())
  3028. || player.hasPermission(Permission.special_chestshop_override))) {
  3029. player.printError("Cannot edit this sign. You do not own or operate the chest below.");
  3030. return true;
  3031. @@ -658,9 +658,11 @@ public final class MiscCommands {
  3032.  
  3033. String[] targetNames = args[args.length - 1].split(",");
  3034. String saveMsg = null;
  3035. + PlayerCredentials credentials = null;
  3036. + boolean saveCacheCredentials = true;
  3037. boolean save = false;
  3038.  
  3039. - if (innObj.canPlayerManage(player) || player.hasPermission(Permission.owned_object_override)) {
  3040. + if (innObj.canPlayerManage(player.getName()) || player.hasPermission(Permission.owned_object_override)) {
  3041. for (String name : targetNames) {
  3042. if (!innObj.isValidPlayer(name, false)) {
  3043. player.printError("Unknown Player or Player Group: \"" + name + "\"");
  3044. @@ -670,7 +672,9 @@ public final class MiscCommands {
  3045.  
  3046. if (innObj.getOwner().equalsIgnoreCase(player.getName())
  3047. || player.hasPermission(Permission.lot_command_override)) {
  3048. - if (innObj.addOperator(name)) {
  3049. + credentials = PlayerCredentialsManager.getByName(name);
  3050. +
  3051. + if (innObj.addOperator(credentials)) {
  3052. save = true;
  3053. saveMsg = "You gave " + name + " operating access to " + innObj.getObjectName() + " #" + innObj.getId() + ".";
  3054. } else {
  3055. @@ -680,7 +684,22 @@ public final class MiscCommands {
  3056. player.printError("You cannot add operators to this " + innObj.getObjectName().toLowerCase() + "!");
  3057. }
  3058. } else {
  3059. - if (innObj.addMember(name)) {
  3060. + if (name.equals("%")) {
  3061. + credentials = Configuration.EVERYONE_CREDENTIALS;
  3062. + saveCacheCredentials = false;
  3063. + } else if (name.equals("@")) {
  3064. + if (innObj instanceof InnectisLot) {
  3065. + player.printError("You cannot allow @ on lots!");
  3066. + return true;
  3067. + }
  3068. +
  3069. + credentials = Configuration.LOT_ACCESS_CREDENTIALS;
  3070. + saveCacheCredentials = false;
  3071. + } else {
  3072. + credentials = PlayerCredentialsManager.getByName(name);
  3073. + }
  3074. +
  3075. + if (innObj.addMember(credentials)) {
  3076. save = true;
  3077. saveMsg = "You gave " + name + " access to " + innObj.getObjectName() + " #" + innObj.getId() + ".";
  3078. } else {
  3079. @@ -690,6 +709,10 @@ public final class MiscCommands {
  3080. }
  3081.  
  3082. if (save) {
  3083. + if (saveCacheCredentials) {
  3084. + PlayerCredentialsManager.addCredentialsToCache(credentials);
  3085. + }
  3086. +
  3087. if (innObj.save()) {
  3088. player.printInfo(saveMsg);
  3089. } else {
  3090. @@ -865,7 +888,7 @@ public final class MiscCommands {
  3091. String saveMsg = null;
  3092. boolean save = false;
  3093.  
  3094. - if (innObj.canPlayerManage(player) || player.hasPermission(Permission.owned_object_override)) {
  3095. + if (innObj.canPlayerManage(player.getName()) || player.hasPermission(Permission.owned_object_override)) {
  3096. if (args[args.length - 1].equalsIgnoreCase("-all")) {
  3097. if (!(innObj.getMembers().isEmpty() && innObj.getOperators().isEmpty())) {
  3098. innObj.clearMembersAndOperators();
  3099. @@ -886,8 +909,9 @@ public final class MiscCommands {
  3100. if (innObj.getOwner().equalsIgnoreCase(player.getName())
  3101. || player.hasPermission(Permission.lot_command_override)) {
  3102. if (innObj.removeOperator(name)) {
  3103. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(name, true);
  3104. // Add the name back as player
  3105. - innObj.addMember(name);
  3106. + innObj.addMember(credentials);
  3107. save = true;
  3108. saveMsg = "You removed " + name + " operating access to " + innObj.getObjectName() + " #" + innObj.getId() + ".";
  3109. } else {
  3110. @@ -1830,10 +1854,10 @@ public final class MiscCommands {
  3111. Location locBelow = player.getLocation().subtract(0, 1, 0);
  3112.  
  3113. if (player.hasLightSourceConditions(locBelow)) {
  3114. - LightsourceHandler.lightBlock(player.getName(), locBelow);
  3115. + LightsourceHandler.lightBlock(player.getUniqueId(), locBelow);
  3116. }
  3117. } else {
  3118. - LightsourceHandler.unlightBlock(player.getName());
  3119. + LightsourceHandler.unlightBlock(player.getUniqueId());
  3120. }
  3121.  
  3122. player.printInfo("Lights are now " + (enabled ? "enabled" : "disabled") + " for you.");
  3123. @@ -1875,7 +1899,7 @@ public final class MiscCommands {
  3124. permission = Permission.command_misc_group_create,
  3125. usage = "/group <add,delete,create,remove,list>",
  3126. serverCommand = false)
  3127. - public static boolean commandGroup(IdpPlayer player, LynxyArguments args) {
  3128. + public static boolean commandGroup(InnPlugin parent, IdpPlayer player, LynxyArguments args) {
  3129. // <editor-fold defaultstate="collapsed" desc="No method / Help method">
  3130. if (StringUtil.matches(args.getString(0), null, "help", "h")) {
  3131. player.printInfo("This command allows you to manage groups");
  3132. @@ -1887,10 +1911,26 @@ public final class MiscCommands {
  3133.  
  3134. // <editor-fold defaultstate="collapsed" desc="Add method">
  3135. } else if (StringUtil.matches(args.getString(0), "add", "a")) {
  3136. - String username = args.getString(1);
  3137. + String playerName = args.getString(1);
  3138. + IdpPlayer target = parent.getPlayer(playerName);
  3139. +
  3140. + if (target != null) {
  3141. + playerName = target.getName();
  3142. + }
  3143. +
  3144. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  3145. +
  3146. + if (credentials == null) {
  3147. + player.printError("That player does not exist.");
  3148. + return true;
  3149. + } else {
  3150. + // Get the proper casing of the name
  3151. + playerName = credentials.getName();
  3152. + }
  3153. +
  3154. String groupname = args.getString(2);
  3155.  
  3156. - if (StringUtil.stringIsNullOrEmpty(username)) {
  3157. + if (StringUtil.stringIsNullOrEmpty(playerName)) {
  3158. player.printError("No username specified!");
  3159. return true;
  3160. }
  3161. @@ -1900,29 +1940,47 @@ public final class MiscCommands {
  3162. return true;
  3163. }
  3164.  
  3165. - MemberGroup group = MemberGroupHandler.getGroup(player.getName(), groupname);
  3166. + MemberGroup group = MemberGroupHandler.getGroup(player.getUniqueId(), groupname);
  3167.  
  3168. if (group == null) {
  3169. player.printError("Member group \"" + groupname + "\" not found!");
  3170. } else {
  3171. - if (group.addMember(username)) {
  3172. + if (group.addMember(credentials)) {
  3173. + PlayerCredentialsManager.addCredentialsToCache(credentials);
  3174. +
  3175. if (group.save()) {
  3176. - player.printInfo("Added " + username + " to member group \"" + group.getName() + "\"!");
  3177. + player.printInfo("Added " + playerName + " to member group \"" + group.getName() + "\"!");
  3178. } else {
  3179. player.printError("Unable to save member group. Notify an admin!");
  3180. }
  3181. } else {
  3182. - player.printError(username + " is already in member group \"" + group.getName() + "\"!");
  3183. + player.printError(playerName + " is already in member group \"" + group.getName() + "\"!");
  3184. }
  3185. }
  3186. //</editor-fold>
  3187.  
  3188. // <editor-fold defaultstate="collapsed" desc="Remove method">
  3189. } else if (StringUtil.matches(args.getString(0), "remove", "rem", "r")) {
  3190. - String username = args.getString(1);
  3191. + String playerName = args.getString(1);
  3192. + IdpPlayer target = parent.getPlayer(playerName);
  3193. +
  3194. + if (target != null) {
  3195. + playerName = target.getName();
  3196. + }
  3197. +
  3198. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  3199. +
  3200. + if (credentials == null) {
  3201. + player.printError("That player does not exist.");
  3202. + return true;
  3203. + } else {
  3204. + // Get the proper casing of the name
  3205. + playerName = credentials.getName();
  3206. + }
  3207. +
  3208. String groupname = args.getString(2);
  3209.  
  3210. - if (StringUtil.stringIsNullOrEmpty(username)) {
  3211. + if (StringUtil.stringIsNullOrEmpty(playerName)) {
  3212. player.printError("No username specified!");
  3213. return true;
  3214. }
  3215. @@ -1932,19 +1990,19 @@ public final class MiscCommands {
  3216. return true;
  3217. }
  3218.  
  3219. - MemberGroup group = MemberGroupHandler.getGroup(player.getName(), groupname);
  3220. + MemberGroup group = MemberGroupHandler.getGroup(player.getUniqueId(), groupname);
  3221.  
  3222. if (group == null) {
  3223. player.printError("Member group \"" + groupname + "\" not found!");
  3224. } else {
  3225. - if (group.removeMember(username)) {
  3226. + if (group.removeMember(playerName)) {
  3227. if (group.save()) {
  3228. - player.printInfo("Removed " + username + " from member group \"" + group.getName() + "\"!");
  3229. + player.printInfo("Removed " + playerName + " from member group \"" + group.getName() + "\"!");
  3230. } else {
  3231. player.printError("Unable to save member group. Nofity an admin!");
  3232. }
  3233. } else {
  3234. - player.printError(username + " is not in member group \"" + group.getName() + "\"!");
  3235. + player.printError(playerName + " is not in member group \"" + group.getName() + "\"!");
  3236. }
  3237. }
  3238. //</editor-fold>
  3239. @@ -1957,12 +2015,15 @@ public final class MiscCommands {
  3240. return true;
  3241. }
  3242.  
  3243. - if (MemberGroupHandler.isGroup(player.getName(), groupname)) {
  3244. + if (MemberGroupHandler.isGroup(player.getUniqueId(), groupname)) {
  3245. player.printError("That group already exists!");
  3246. return true;
  3247. }
  3248.  
  3249. - if (MemberGroupHandler.addGroup(player.getName(), groupname)) {
  3250. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName());
  3251. +
  3252. + if (MemberGroupHandler.addGroup(credentials, groupname)) {
  3253. + PlayerCredentialsManager.addCredentialsToCache(credentials);
  3254. player.printInfo("Member group \"" + groupname + "\" created!");
  3255. } else {
  3256. player.printError("Could not save member group. Nofity an admin!");
  3257. @@ -1977,12 +2038,12 @@ public final class MiscCommands {
  3258. return true;
  3259. }
  3260.  
  3261. - MemberGroup group = MemberGroupHandler.getGroup(player.getName(), groupname);
  3262. + MemberGroup group = MemberGroupHandler.getGroup(player.getUniqueId(), groupname);
  3263.  
  3264. if (group == null) {
  3265. player.printError("Member group \"" + groupname + "\" not found!");
  3266. } else {
  3267. - if (MemberGroupHandler.removeGroup(player.getName(), groupname)) {
  3268. + if (MemberGroupHandler.removeGroup(player.getUniqueId(), groupname)) {
  3269. player.printInfo("Member group \"" + group.getName() + "\" deleted!");
  3270. } else {
  3271. player.printError("Could not delete member group. Nodify an admin!");
  3272. @@ -1994,7 +2055,8 @@ public final class MiscCommands {
  3273. } else if (StringUtil.matches(args.getString(0), "list", "l")) {
  3274. String groupname = args.getString(1);
  3275. if (StringUtil.stringIsNullOrEmpty(groupname)) {
  3276. - List<MemberGroup> groups = MemberGroupHandler.getGroups(player.getName());
  3277. + List<MemberGroup> groups = MemberGroupHandler.getGroups(player.getUniqueId());
  3278. +
  3279. if (groups == null || groups.isEmpty()) {
  3280. player.printInfo("You have no member groups!");
  3281. } else {
  3282. @@ -2011,7 +2073,7 @@ public final class MiscCommands {
  3283. return true;
  3284. }
  3285.  
  3286. - MemberGroup group = MemberGroupHandler.getGroup(player.getName(), groupname);
  3287. + MemberGroup group = MemberGroupHandler.getGroup(player.getUniqueId(), groupname);
  3288.  
  3289. if (group == null) {
  3290. player.printError("Member group \"" + groupname + "\" not found!");
  3291. @@ -2048,7 +2110,7 @@ public final class MiscCommands {
  3292. return true;
  3293. }
  3294.  
  3295. - if (!bookcase.canPlayerManage(player)) {
  3296. + if (!bookcase.canPlayerManage(player.getName())) {
  3297. player.printError("You do not own or operate this bookcase!");
  3298. return true;
  3299. }
  3300. diff --git a/src/net/innectis/innplugin/Command/Commands/ModerationCommands.java b/src/net/innectis/innplugin/Command/Commands/ModerationCommands.java
  3301. index 41d215acb..137732e8a 100644
  3302. --- a/src/net/innectis/innplugin/Command/Commands/ModerationCommands.java
  3303. +++ b/src/net/innectis/innplugin/Command/Commands/ModerationCommands.java
  3304. @@ -16,6 +16,7 @@ import net.innectis.innplugin.Configuration;
  3305. import net.innectis.innplugin.Handlers.PagedCommandHandler;
  3306. import net.innectis.innplugin.Handlers.WarpHandler;
  3307. import net.innectis.innplugin.IdpCommandSender;
  3308. +import net.innectis.innplugin.IdpConsole;
  3309. import net.innectis.innplugin.InnPlugin;
  3310. import net.innectis.innplugin.InnectisObjects.IPLogger;
  3311. import net.innectis.innplugin.Items.Bookinfo;
  3312. @@ -32,6 +33,8 @@ import net.innectis.innplugin.Player.Infractions.Infraction;
  3313. import net.innectis.innplugin.Player.Infractions.InfractionIntensity;
  3314. import net.innectis.innplugin.Player.Infractions.InfractionManager;
  3315. import net.innectis.innplugin.Player.Permission;
  3316. +import net.innectis.innplugin.Player.PlayerCredentials;
  3317. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  3318. import net.innectis.innplugin.Player.PlayerGroup;
  3319. import net.innectis.innplugin.Player.PlayerSession;
  3320. import net.innectis.innplugin.Utility.DateUtil;
  3321. @@ -52,17 +55,24 @@ public final class ModerationCommands {
  3322. return false;
  3323. }
  3324.  
  3325. - String playername = args.getString(0);
  3326. - PlayerSession session = PlayerSession.getSession(playername, parent);
  3327. - if (session.getTotalOnlineTime() <= 0) {
  3328. - sender.printError("Player '" + playername + "' has no onlinetime! Cannot infract!");
  3329. + String playerName = args.getString(0);
  3330. + IdpPlayer target = parent.getPlayer(playerName);
  3331. +
  3332. + if (target != null) {
  3333. + playerName = target.getName();
  3334. + }
  3335. +
  3336. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  3337. +
  3338. + if (credentials == null) {
  3339. + sender.printError("That player does not exist.");
  3340. return true;
  3341. }
  3342.  
  3343. String intensityString = args.getString(1);
  3344.  
  3345. // Subcommand to revoke infractions
  3346. - if (StringUtil.matches(playername, "r", "revoke")) {
  3347. + if (StringUtil.matches(playerName, "r", "revoke")) {
  3348. int id;
  3349. try {
  3350. id = args.getInt(2);
  3351. @@ -76,7 +86,7 @@ public final class ModerationCommands {
  3352. sender.printError("Infraction #" + id + " not found!");
  3353. return true;
  3354. } else if (inf.isRevoked()) {
  3355. - sender.printError("Infraction #" + id + " already revoked by " + inf.getRevoker());
  3356. + sender.printError("Infraction #" + id + " already revoked by " + inf.getRevokerCredentials().getName());
  3357. return true;
  3358. } else {
  3359. Date date = Calendar.getInstance(TimeZone.getTimeZone("GMT")).getTime();
  3360. @@ -106,7 +116,7 @@ public final class ModerationCommands {
  3361. String summary = args.getJoinedStrings(2);
  3362.  
  3363. // Make an injector for the details message
  3364. - ChatInjector injector = new InfractInjector(session.getRealName(), infIntensity, summary);
  3365. + ChatInjector injector = new InfractInjector(credentials, infIntensity, summary);
  3366.  
  3367. if (sender.isPlayer()) {
  3368. PlayerSession currPlayer = ((IdpPlayer) sender).getSession();
  3369. @@ -129,11 +139,27 @@ public final class ModerationCommands {
  3370. permission = Permission.command_moderation_infract,
  3371. usage = "/showinfraction [username [-all] [-page <page>]] [-id <id> [-book]]",
  3372. serverCommand = true)
  3373. - public static boolean commandShowInfraction(IdpCommandSender sender, ParameterArguments args) {
  3374. + public static boolean commandShowInfraction(InnPlugin parent, IdpCommandSender sender, ParameterArguments args) {
  3375. if (args.size() == 1) {
  3376. - String name = args.getString(0);
  3377. + String playerName = args.getString(0);
  3378. +
  3379. + IdpPlayer target = parent.getPlayer(playerName);
  3380. +
  3381. + if (target != null) {
  3382. + playerName = target.getName();
  3383. + }
  3384. +
  3385. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  3386. +
  3387. + if (credentials == null) {
  3388. + sender.printError("That player does not exist.");
  3389. + return true;
  3390. + } else {
  3391. + // Get the proper casing of the name
  3392. + playerName = credentials.getName();
  3393. + }
  3394.  
  3395. - List<Infraction> infractions = InfractionManager.getManager().getInfractions(name, args.hasOption("all"));
  3396. + List<Infraction> infractions = InfractionManager.getManager().getInfractions(credentials, args.hasOption("all"));
  3397.  
  3398. if (infractions.isEmpty()) {
  3399. sender.printInfo("That player has no infractions!");
  3400. @@ -163,7 +189,7 @@ public final class ModerationCommands {
  3401. ph.setNewLinesPerPage(Configuration.INFRACTIONS_PER_PAGE);
  3402.  
  3403. if (ph.isValidPage()) {
  3404. - sender.printInfo("Printing infractions for " + name + " page: " + page + "/" + ph.getMaxPage());
  3405. + sender.printInfo("Printing infractions for " + playerName + " page: " + page + "/" + ph.getMaxPage());
  3406.  
  3407. for (String line : lines) {
  3408. sender.printInfo(line);
  3409. @@ -202,16 +228,16 @@ public final class ModerationCommands {
  3410. // Make a new section in chat (makes it easier to seperate multiple infractios)
  3411. sender.printInfo("----------------------------------");
  3412. sender.printInfo("Infraction #" + inf.getId());
  3413. - sender.printInfo("Player " + inf.getPlayer());
  3414. + sender.printInfo("Player " + inf.getPlayerCredentials().getName());
  3415. sender.printInfo("Intensity " + inf.getIntensity().name());
  3416. sender.printInfo("Created on " + DateUtil.formatString(inf.getDateGMT(), DateUtil.FORMAT_DDMMYYYY_HHMM, tz) + " (" + tz.getDisplayName() + ").");
  3417. - sender.printInfo("Infracted by " + inf.getStaffmember());
  3418. + sender.printInfo("Infracted by " + inf.getCreatorCredentials().getName());
  3419. sender.printInfo("Summary: " + inf.getSummary());
  3420.  
  3421. // Print revoke details.
  3422. if (inf.isRevoked()) {
  3423. String dateString = DateUtil.formatString(inf.getDateGMT(), DateUtil.FORMAT_DDMMYYYY_HHMM, tz) + " (" + tz.getDisplayName() + ")";
  3424. - sender.printError("Revoked on " + dateString + " by " + inf.getRevoker() + ".");
  3425. + sender.printError("Revoked on " + dateString + " by " + inf.getRevokerCredentials().getName() + ".");
  3426. }
  3427.  
  3428. if (inf.getDetails() != null) {
  3429. @@ -252,15 +278,15 @@ public final class ModerationCommands {
  3430. basicInfo.append("Created on: ").append(DateUtil.formatString(date, DateUtil.FORMAT_DDMMYYYY_HHMM)).append(InfractInjector.ENTER_CHAR);
  3431. basicInfo.append(InfractInjector.ENTER_CHAR);
  3432.  
  3433. - basicInfo.append(ChatColor.BLACK).append("Username ").append(ChatColor.DARK_AQUA).append(inf.getPlayer()).append(InfractInjector.ENTER_CHAR);
  3434. + basicInfo.append(ChatColor.BLACK).append("Username ").append(ChatColor.DARK_AQUA).append(inf.getPlayerCredentials().getUniqueId().toString()).append(InfractInjector.ENTER_CHAR);
  3435. basicInfo.append(ChatColor.BLACK).append("Intensity ").append(ChatColor.DARK_AQUA).append(inf.getIntensity().name()).append(InfractInjector.ENTER_CHAR);
  3436.  
  3437. basicInfo.append(ChatColor.BLACK).append("Date ").append(ChatColor.DARK_AQUA).append(DateUtil.formatString(inf.getDateGMT(), DateUtil.FORMAT_DDMMYYYY_HHMM)).append(" GMT").append(InfractInjector.ENTER_CHAR);
  3438. - basicInfo.append(ChatColor.BLACK).append("Staff ").append(ChatColor.DARK_AQUA).append(inf.getStaffmember()).append(InfractInjector.ENTER_CHAR);
  3439. + basicInfo.append(ChatColor.BLACK).append("Staff ").append(ChatColor.DARK_AQUA).append(inf.getCreatorCredentials()).append(InfractInjector.ENTER_CHAR);
  3440.  
  3441. // Revoke details
  3442. if (inf.isRevoked()) {
  3443. - basicInfo.append(ChatColor.BLACK).append("Revoked by: ").append(ChatColor.RED).append(inf.getRevoker()).append(InfractInjector.ENTER_CHAR);
  3444. + basicInfo.append(ChatColor.BLACK).append("Revoked by: ").append(ChatColor.RED).append(inf.getRevokerCredentials().getUniqueId().toString()).append(InfractInjector.ENTER_CHAR);
  3445. basicInfo.append(ChatColor.BLACK).append("Revoked on: ").append(ChatColor.RED).append(DateUtil.formatString(inf.getRevokeDate(), DateUtil.FORMAT_DDMMYYYY_HHMM)).append(InfractInjector.ENTER_CHAR);
  3446. }
  3447.  
  3448. @@ -298,15 +324,13 @@ public final class ModerationCommands {
  3449. }
  3450.  
  3451. IdpPlayer targetPlayer = parent.getPlayer(args.getString(0), false, true);
  3452. - String username = (targetPlayer != null ? targetPlayer.getName() : args.getString(0));
  3453. + String playerName = (targetPlayer != null ? targetPlayer.getName() : args.getString(0));
  3454.  
  3455. - if (targetPlayer == null) {
  3456. - PlayerGroup group = PlayerGroup.getGroupOfUsername(username);
  3457. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  3458.  
  3459. - if (group == PlayerGroup.NONE) {
  3460. - sender.printError("That player doesn't exist! Cannot ban.");
  3461. - return true;
  3462. - }
  3463. + if (credentials == null) {
  3464. + sender.printError("That player doesn't exist! Cannot ban.");
  3465. + return true;
  3466. }
  3467.  
  3468. if (args.hasArgument("time", "t")) {
  3469. @@ -332,8 +356,7 @@ public final class ModerationCommands {
  3470. return true;
  3471. }
  3472.  
  3473. - username = BanHandler.getPartialName(username);
  3474. - BanObject ban = BanHandler.getBan(username);
  3475. + BanObject ban = BanHandler.getBan(credentials.getUniqueId());
  3476.  
  3477. if (ban != null && (sender instanceof IdpPlayer) && !ban.canModifyBan((IdpPlayer) sender)) {
  3478. sender.printError("You did not ban this player! Unable to modify.");
  3479. @@ -341,41 +364,41 @@ public final class ModerationCommands {
  3480. }
  3481.  
  3482. if (isLinkedBan) {
  3483. - BanObject testBan = BanHandler.getBan(username);
  3484. -
  3485. if (ban != null) {
  3486. - boolean ipbanned = (testBan instanceof IPBanObject);
  3487. + boolean ipbanned = (ban instanceof IPBanObject);
  3488.  
  3489. sender.printError("This user is already " + (ipbanned ? "ip" : "") + "banned. Unable to link!");
  3490. return true;
  3491. }
  3492.  
  3493. String linkedUsername = args.getString("link");
  3494. - PlayerGroup linkedGroup = PlayerGroup.getGroupOfUsername(linkedUsername);
  3495. - String coloredLinkedUsername = linkedGroup.getPrefix().getTextColor() + linkedUsername;
  3496. + PlayerCredentials linkedCredentials = PlayerCredentialsManager.getByName(linkedUsername);
  3497.  
  3498. - if (linkedGroup == PlayerGroup.NONE) {
  3499. - sender.printError("The username to link to does not exist!");
  3500. + if (linkedCredentials == null) {
  3501. + sender.printError("The username to link this ban to does not exist!");
  3502. return true;
  3503. }
  3504.  
  3505. + PlayerGroup linkedGroup = PlayerGroup.getGroupOfPlayerById(linkedCredentials.getUniqueId());
  3506. + String coloredLinkedUsername = linkedGroup.getPrefix().getTextColor() + linkedUsername;
  3507. +
  3508. String ip;
  3509.  
  3510. if (targetPlayer != null) {
  3511. ip = targetPlayer.getHandle().getAddress().getAddress().getHostAddress();
  3512. } else {
  3513. - ip = IPLogger.getLastUsedIP(username);
  3514. + ip = IPLogger.getLastUsedIP(credentials.getUniqueId(), credentials.getName());
  3515. }
  3516.  
  3517. - PlayerGroup userGroup = PlayerGroup.getGroupOfUsername(username);
  3518. - String coloredUsername = userGroup.getPrefix().getTextColor() + username;
  3519. + PlayerGroup userGroup = PlayerGroup.getGroupOfPlayerById(credentials.getUniqueId());
  3520. + String coloredUsername = userGroup.getPrefix().getTextColor() + playerName;
  3521.  
  3522. - LinkStatus status = BanHandler.linkIPBan(((sender instanceof IdpPlayer) ? (IdpPlayer) sender : null), username, ip, linkedUsername);
  3523. + LinkStatus status = BanHandler.linkIPBan(sender, credentials, ip, linkedCredentials);
  3524.  
  3525. switch (status) {
  3526. case LINK_SUCCESSFUL:
  3527. sender.printInfo(coloredUsername + ChatColor.YELLOW + " was linked to " + coloredLinkedUsername + ChatColor.YELLOW + "'s ip ban.");
  3528. - String resultMsg = username + " was linked to " + linkedUsername + "'s ip ban.";
  3529. + String resultMsg = playerName + " was linked to " + linkedUsername + "'s ip ban.";
  3530. parent.broadCastMessage(ChatColor.RED + Configuration.MESSAGE_PREFIX + resultMsg);
  3531. break;
  3532. case LINK_NOT_FOUND:
  3533. @@ -391,47 +414,58 @@ public final class ModerationCommands {
  3534. } else {
  3535. if ((ban instanceof IPBanObject) && !isIPBan) {
  3536. IPBanObject ipban = (IPBanObject) ban;
  3537. - String ipbannedusers = "";
  3538. - List<String> ipbanList = ipban.getGroup().getPlayers();
  3539. + String ipBannedPlayerString = "";
  3540. + List<PlayerCredentials> ipBannedPlayers = ipban.getGroup().getPlayers();
  3541.  
  3542. - for (String user : ipbanList) {
  3543. - PlayerGroup group = PlayerGroup.getGroupOfUsername(user);
  3544. + for (PlayerCredentials pc : ipBannedPlayers) {
  3545. + String name = pc.getName();
  3546. + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(pc.getUniqueId());
  3547.  
  3548. - if (ipbannedusers.isEmpty()) {
  3549. - ipbannedusers = group.getPrefix().getTextColor() + user;
  3550. + if (ipBannedPlayerString.isEmpty()) {
  3551. + ipBannedPlayerString = group.getPrefix().getTextColor() + name;
  3552. } else {
  3553. - ipbannedusers += ChatColor.WHITE + ", " + group.getPrefix().getTextColor() + user;
  3554. + ipBannedPlayerString += ChatColor.WHITE + ", " + group.getPrefix().getTextColor() + name;
  3555. }
  3556. }
  3557.  
  3558. - if (ipbanList.size() > 1) {
  3559. + if (ipBannedPlayers.size() > 1) {
  3560. sender.print(ChatColor.YELLOW, "You switched an ipban with multiple accounts to a ban.");
  3561. - sender.print(ChatColor.YELLOW, "IP banned users: " + ipbannedusers);
  3562. + sender.print(ChatColor.YELLOW, "IP banned users: " + ipBannedPlayerString);
  3563. } else {
  3564. - sender.print(ChatColor.RED, username + " was previously ipbanned. Changing to ban. ");
  3565. + sender.print(ChatColor.RED, playerName + " was previously ipbanned. Changing to ban. ");
  3566. }
  3567.  
  3568. BanHandler.removeBan(ban);
  3569. } else if ((ban instanceof UserBanObject) && isIPBan) {
  3570. - sender.print(ChatColor.RED, username + " was previously banned. Changing to ipban.");
  3571. + sender.print(ChatColor.RED, playerName + " was previously banned. Changing to ipban.");
  3572. BanHandler.removeBan(ban);
  3573. }
  3574.  
  3575. + PlayerCredentials bannedByPlayerCredentials = null;
  3576. +
  3577. + // Since console can ban players, our system won't work that way
  3578. + // so replace the console with the name of a stored player we have
  3579. + if (sender instanceof IdpConsole) {
  3580. + bannedByPlayerCredentials = Configuration.SERVER_GENERATED_CREDENTIALS;
  3581. + } else {
  3582. + bannedByPlayerCredentials = PlayerCredentialsManager.getByName(sender.getName());
  3583. + }
  3584. +
  3585. if (isIPBan) {
  3586. List<String> IPs = new ArrayList<String>();
  3587. - String ip = IPLogger.getLastUsedIP(username);
  3588. + String ip = IPLogger.getLastUsedIP(credentials.getUniqueId(), credentials.getName());
  3589.  
  3590. if (ip != null) {
  3591. IPs.add(ip);
  3592. }
  3593.  
  3594. - List<String> usernames = new ArrayList<String>();
  3595. - usernames.add(username);
  3596. - IPBanGroup group = new IPBanGroup(IPs, usernames);
  3597. + List<PlayerCredentials> players = new ArrayList<PlayerCredentials>();
  3598. + players.add(credentials);
  3599. + IPBanGroup group = new IPBanGroup(IPs, players);
  3600.  
  3601. - ban = new IPBanObject(group, sender.getName(), new Timestamp(System.currentTimeMillis()), banFormula, isJoinBan);
  3602. + ban = new IPBanObject(group, bannedByPlayerCredentials, new Timestamp(System.currentTimeMillis()), banFormula, isJoinBan);
  3603. } else {
  3604. - ban = new UserBanObject(username, sender.getName(), new Timestamp(System.currentTimeMillis()), banFormula, isJoinBan);
  3605. + ban = new UserBanObject(credentials, bannedByPlayerCredentials, new Timestamp(System.currentTimeMillis()), banFormula, isJoinBan);
  3606. }
  3607.  
  3608. BanResult result = BanHandler.addBan(ban);
  3609. @@ -440,11 +474,11 @@ public final class ModerationCommands {
  3610. switch (result) {
  3611. case BAN_FRESH:
  3612. case BAN_FRESH_IP:
  3613. - resultMsg = username + " was " + (result == BanResult.BAN_FRESH ? "banned " : "ipbanned ") + (banFormula == 0 ? "indefinitely" : "for " + DateUtil.getTimeString(banFormula, true)) + (isJoinBan ? " (effective on next join)" : "") + " by " + sender.getName() + ".";
  3614. + resultMsg = playerName + " was " + (result == BanResult.BAN_FRESH ? "banned " : "ipbanned ") + (banFormula == 0 ? "indefinitely" : "for " + DateUtil.getTimeString(banFormula, true)) + (isJoinBan ? " (effective on next join)" : "") + " by " + sender.getName() + ".";
  3615. break;
  3616. case BAN_EXISTING:
  3617. case BAN_EXISTING_IP:
  3618. - resultMsg = username + "'s " + (result == BanResult.BAN_EXISTING ? "ban" : "ipban") + " was modified to " + (banFormula == 0 ? "indefinite" : DateUtil.getTimeString(banFormula, true)) + (isJoinBan ? " (effective on next join)" : "") + " by " + sender.getName() + ".";
  3619. + resultMsg = playerName + "'s " + (result == BanResult.BAN_EXISTING ? "ban" : "ipban") + " was modified to " + (banFormula == 0 ? "indefinite" : DateUtil.getTimeString(banFormula, true)) + (isJoinBan ? " (effective on next join)" : "") + " by " + sender.getName() + ".";
  3620. break;
  3621. }
  3622.  
  3623. @@ -457,6 +491,7 @@ public final class ModerationCommands {
  3624.  
  3625. return true;
  3626. }
  3627. +
  3628. return false;
  3629. }
  3630.  
  3631. @@ -467,8 +502,18 @@ public final class ModerationCommands {
  3632. serverCommand = true)
  3633. public static boolean commandUnBan(InnPlugin parent, IdpCommandSender sender, LynxyArguments args) {
  3634. if (args.getActionSize() > 0) {
  3635. - String username = BanHandler.getPartialName(args.getString(0));
  3636. - BanObject ban = BanHandler.getBan(username);
  3637. + String playerName = BanHandler.getPartialName(args.getString(0));
  3638. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  3639. +
  3640. + if (credentials == null) {
  3641. + sender.printError("That player does not exist.");
  3642. + return true;
  3643. + } else {
  3644. + // Get the proper casing of the name
  3645. + playerName = credentials.getName();
  3646. + }
  3647. +
  3648. + BanObject ban = BanHandler.getBan(credentials.getUniqueId());
  3649.  
  3650. if (ban == null) {
  3651. sender.printError("That user is not banned.");
  3652. @@ -484,18 +529,18 @@ public final class ModerationCommands {
  3653. boolean isUnlinkedBan = (args.hasOption("unlink"));
  3654.  
  3655. if (isUnlinkedBan) {
  3656. - String ip = IPLogger.getLastUsedIP(username);
  3657. + String ip = IPLogger.getLastUsedIP(credentials.getUniqueId(), credentials.getName());
  3658.  
  3659. - UnlinkStatus status = BanHandler.unlinkIPBan(((sender instanceof IdpPlayer) ? (IdpPlayer) sender : null), username, ip);
  3660. - PlayerGroup group = PlayerGroup.getGroupOfUsername(username);
  3661. - String coloredUsername = group.getPrefix().getTextColor() + username;
  3662. + UnlinkStatus status = BanHandler.unlinkIPBan(sender, credentials, ip);
  3663. + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(credentials.getUniqueId());
  3664. + String coloredUsername = group.getPrefix().getTextColor() + playerName;
  3665.  
  3666. switch (status) {
  3667. case UNLINK_FOUND:
  3668. sender.printInfo(coloredUsername + ChatColor.YELLOW + " was unlinked from a previous ip ban.");
  3669. break;
  3670. case UNLINK_NOT_FOUND:
  3671. - sender.printError(username + " is not linked to any ip ban.");
  3672. + sender.printError(playerName + " is not linked to any ip ban.");
  3673. return true;
  3674. case UNLINK_REMOVED_BAN:
  3675. sender.printInfo(coloredUsername + ChatColor.DARK_GREEN + " was unlinked from a previous ip ban");
  3676. @@ -506,21 +551,23 @@ public final class ModerationCommands {
  3677. return true;
  3678. }
  3679.  
  3680. - parent.broadCastMessage(ChatColor.RED + Configuration.MESSAGE_PREFIX + username + " was unipbanned");
  3681. + parent.broadCastMessage(ChatColor.RED + Configuration.MESSAGE_PREFIX + playerName + " was unipbanned");
  3682. } else {
  3683. if (isIPBan) {
  3684. IPBanObject ipban = (IPBanObject) ban;
  3685.  
  3686. - List<String> players = ipban.getGroup().getPlayers();
  3687. + List<PlayerCredentials> players = ipban.getGroup().getPlayers();
  3688. String playerList = "";
  3689.  
  3690. - for (String player : players) {
  3691. - PlayerGroup pGroup = PlayerGroup.getGroupOfUsername(player);
  3692. + for (PlayerCredentials pc : players) {
  3693. + String name = pc.getName();
  3694. + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(pc.getUniqueId());
  3695. + ChatColor textColor = group.getPrefix().getTextColor();
  3696.  
  3697. if (playerList.isEmpty()) {
  3698. - playerList += pGroup.getPrefix().getTextColor() + player;
  3699. + playerList += textColor + name;
  3700. } else {
  3701. - playerList += ChatColor.WHITE + ", " + pGroup.getPrefix().getTextColor() + player;
  3702. + playerList += ChatColor.WHITE + ", " + textColor + name;
  3703. }
  3704. }
  3705.  
  3706. @@ -531,7 +578,7 @@ public final class ModerationCommands {
  3707. }
  3708.  
  3709. BanHandler.removeBan(ban);
  3710. - parent.broadCastMessage(ChatColor.RED + Configuration.MESSAGE_PREFIX + username + " was un" + (isIPBan ? "ip" : "") + "banned by " + sender.getName() + "!");
  3711. + parent.broadCastMessage(ChatColor.RED + Configuration.MESSAGE_PREFIX + playerName + " was un" + (isIPBan ? "ip" : "") + "banned by " + sender.getName() + "!");
  3712. }
  3713.  
  3714. return true;
  3715. @@ -679,14 +726,21 @@ public final class ModerationCommands {
  3716. if (username == null || args.hasOption("help", "h")) {
  3717. int pageNo = args.getIntDefaultTo(1, "page", "p");
  3718.  
  3719. - List<String> whitelistPlayers = BanHandler.getWhitelist();
  3720. - PagedCommandHandler ph = new PagedCommandHandler(pageNo, whitelistPlayers);
  3721. + List<PlayerCredentials> whitelistPlayers = BanHandler.getWhitelist();
  3722.  
  3723. if (whitelistPlayers == null) {
  3724. sender.printError("There are no whitelisted users.");
  3725. return true;
  3726. }
  3727.  
  3728. + List<String> whitelistNames = new ArrayList<String>();
  3729. +
  3730. + for (PlayerCredentials credentials : whitelistPlayers) {
  3731. + whitelistNames.add(credentials.getName());
  3732. + }
  3733. +
  3734. + PagedCommandHandler ph = new PagedCommandHandler(pageNo, whitelistNames);
  3735. +
  3736. if (ph.isValidPage()) {
  3737. ph.adjustEntriesPerLine(3);
  3738. sender.printInfo("Listing " + ph.getStartLine() + "-" + ph.getEndLine() + " whitelisted players. Showing page: " + pageNo + " of " + ph.getMaxPage());
  3739. @@ -702,14 +756,19 @@ public final class ModerationCommands {
  3740. }
  3741.  
  3742. if (args.hasOption("add", "a")) {
  3743. - PlayerGroup group = PlayerGroup.getGroupOfUsername(username);
  3744. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(username);
  3745.  
  3746. - if (group == PlayerGroup.NONE) {
  3747. + if (credentials == null) {
  3748. sender.printError("That username doesn't exist.");
  3749. return true;
  3750. }
  3751.  
  3752. - BanHandler.addWhitelist(username);
  3753. + if (BanHandler.isWhitelisted(credentials.getUniqueId())) {
  3754. + sender.printError("That username is already whitelisted.");
  3755. + return true;
  3756. + }
  3757. +
  3758. + BanHandler.addWhitelist(credentials);
  3759.  
  3760. sender.printInfo("Added " + username + " to the ban whitelist.");
  3761.  
  3762. @@ -717,15 +776,14 @@ public final class ModerationCommands {
  3763. }
  3764.  
  3765. if (args.hasOption("remove", "rem")) {
  3766. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(username);
  3767.  
  3768. - PlayerGroup group = PlayerGroup.getGroupOfUsername(username);
  3769. -
  3770. - if (group == PlayerGroup.NONE) {
  3771. + if (credentials == null) {
  3772. sender.printError("That username doesn't exist.");
  3773. return true;
  3774. }
  3775.  
  3776. - BanHandler.removeWhitelist(username);
  3777. + BanHandler.removeWhitelist(credentials);
  3778.  
  3779. sender.printInfo("Removed " + username + " from the ban whitelist.");
  3780.  
  3781. @@ -775,16 +833,16 @@ public final class ModerationCommands {
  3782. }
  3783.  
  3784. if (args.getString(0) != null) {
  3785. - String name = args.getString(0).toLowerCase();
  3786. - IdpPlayer tarplayer = parent.getPlayer(name, false);
  3787. - if (tarplayer != null && tarplayer.isOnline()) {
  3788. + String playerName = args.getString(0);
  3789. + IdpPlayer target = parent.getPlayer(playerName);
  3790.  
  3791. - if (tarplayer.getWorld().getWorldType() == IdpWorldType.NETHER) {
  3792. + if (target != null && target.isOnline()) {
  3793. + if (target.getWorld().getWorldType() == IdpWorldType.NETHER) {
  3794. boolean force = args.hasOption("force", "f")
  3795. && sender.hasPermission(Permission.teleport_others_force);
  3796.  
  3797. if (!force) {
  3798. - String msg = tarplayer.getColoredDisplayName() + ChatColor.RED + " is in the nether.";
  3799. + String msg = target.getColoredDisplayName() + ChatColor.RED + " is in the nether.";
  3800.  
  3801. if (sender.hasPermission(Permission.teleport_others_force)) {
  3802. msg += " Use -force to jail them.";
  3803. @@ -797,31 +855,45 @@ public final class ModerationCommands {
  3804. }
  3805. }
  3806.  
  3807. - if (tarplayer.getSession().isJailed()) {
  3808. - sender.printError(tarplayer.getName() + " is already jailed!");
  3809. + if (target.getSession().isJailed()) {
  3810. + sender.printError(target.getName() + " is already jailed!");
  3811. return true;
  3812. }
  3813.  
  3814. - if (tarplayer.isOnline()) {
  3815. + if (target.isOnline()) {
  3816. IdpWarp jail = WarpHandler.getJail();
  3817. if (jail.getLocation() == WarpHandler.getSpawn()) {
  3818. sender.printError("Jail warp was not found! User not jailed.");
  3819. return true;
  3820. }
  3821. - if (tarplayer.teleport(jail)) {
  3822. - tarplayer.getSession().setJailed(true);
  3823. - sender.printInfo(tarplayer.getName() + " has been jailed!");
  3824. - tarplayer.printError("You have been jailed.");
  3825. + if (target.teleport(jail)) {
  3826. + target.getSession().setJailed(true);
  3827. + sender.printInfo(target.getName() + " has been jailed!");
  3828. + target.printError("You have been jailed.");
  3829. } else {
  3830. sender.printError("Failed to teleport user to jail!");
  3831. }
  3832. }
  3833. } else {
  3834. - PlayerSession.getSession(name, parent).setJailed(true);
  3835. - sender.printInfo(name + " has been jailed!");
  3836. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  3837. +
  3838. + if (credentials == null) {
  3839. + sender.printError("That player doesn't exist!");
  3840. + return false;
  3841. + }
  3842. +
  3843. + if (PlayerSession.hasSession(playerName)) {
  3844. + PlayerSession session = PlayerSession.getSession_(playerName);
  3845. + session.setJailed(true);
  3846. + sender.printInfo(playerName + " has been jailed!");
  3847. + } else {
  3848. + sender.printError("That player doesn't have an active session. Unable to jail!");
  3849. + }
  3850. }
  3851. +
  3852. return true;
  3853. }
  3854. +
  3855. return false;
  3856. }
  3857.  
  3858. @@ -901,30 +973,31 @@ public final class ModerationCommands {
  3859. }
  3860.  
  3861. if (args.getString(0) != null) {
  3862. - String name = args.getString(0).toLowerCase();
  3863. - IdpPlayer tarplayer = parent.getPlayer(name, false);
  3864. - if (tarplayer != null && tarplayer.isOnline()) {
  3865. - name = tarplayer.getName().toLowerCase();
  3866. - }
  3867. -
  3868. - if (PlayerSession.hasSession(name)) {
  3869. - PlayerSession session = PlayerSession.getSession(name, parent);
  3870. + String playerName = args.getString(0);
  3871. + PlayerSession session = null;
  3872.  
  3873. - if (args.hasArgument("time", "t")) {
  3874. - long formula = DateUtil.getTimeFormula(args.getString("time", "t"));
  3875. + if (PlayerSession.hasSession(playerName)) {
  3876. + session = PlayerSession.getSession_(playerName);
  3877. + } else {
  3878. + sender.printError(playerName + " doesn't have an active session!");
  3879. + return true;
  3880. + }
  3881.  
  3882. - if (formula == -1) {
  3883. - sender.printError("Incorrect mute formula. (Ex. 5m3s)");
  3884. - return true;
  3885. - }
  3886. + if (args.hasArgument("time", "t")) {
  3887. + long formula = DateUtil.getTimeFormula(args.getString("time", "t"));
  3888.  
  3889. - session.setMuteTicks(System.currentTimeMillis() + formula);
  3890. - sender.printInfo(name + " is silenced for " + DateUtil.getTimeString(formula, true) + ".");
  3891. - } else {
  3892. - session.setMuteTicks(-1);
  3893. - sender.printInfo(name + " is silenced.");
  3894. + if (formula == -1) {
  3895. + sender.printError("Incorrect mute formula. (Ex. 5m3s)");
  3896. + return true;
  3897. }
  3898. +
  3899. + session.setMuteTicks(System.currentTimeMillis() + formula);
  3900. + sender.printInfo(playerName + " is silenced for " + DateUtil.getTimeString(formula, true) + ".");
  3901. + } else {
  3902. + session.setMuteTicks(-1);
  3903. + sender.printInfo(playerName + " is silenced.");
  3904. }
  3905. +
  3906. return true;
  3907. }
  3908. return false;
  3909. @@ -963,36 +1036,35 @@ public final class ModerationCommands {
  3910. serverCommand = true)
  3911. public static boolean commandUnJail(InnPlugin parent, IdpCommandSender sender, String[] args) {
  3912. if (args.length == 1) {
  3913. - String name = args[0].toLowerCase();
  3914. - IdpPlayer tarplayer = parent.getPlayer(name, false);
  3915. - PlayerSession session;
  3916. - if (tarplayer != null && tarplayer.isOnline()) {
  3917. - name = tarplayer.getName();
  3918. - session = tarplayer.getSession();
  3919. + String playerName = args[0];
  3920. + PlayerSession session = null;
  3921. +
  3922. + if (PlayerSession.hasSession(playerName)) {
  3923. + session = PlayerSession.getSession_(playerName);
  3924. } else {
  3925. - if (PlayerSession.hasSession(name)) {
  3926. - sender.printError(args[0] + " doesn't have an active session!");
  3927. - return true;
  3928. - } else {
  3929. - session = PlayerSession.getSession(name, parent);
  3930. - }
  3931. + sender.printError(playerName + " doesn't have an active session. Cannot unjail!");
  3932. + return true;
  3933. }
  3934.  
  3935. if (!session.isJailed()) {
  3936. - sender.printError(args[0] + " is not jailed!");
  3937. + sender.printError(playerName + " is not jailed!");
  3938. return true;
  3939. }
  3940.  
  3941. session.setJailed(false);
  3942. - sender.printInfo(name + " has been unjailed!");
  3943. + sender.printInfo(playerName + " has been unjailed!");
  3944. +
  3945. + IdpPlayer tarplayer = parent.getPlayer(playerName);
  3946.  
  3947. if (tarplayer != null && tarplayer.isOnline()) {
  3948. tarplayer.teleport(WarpHandler.getSpawn(tarplayer.getGroup()));
  3949.  
  3950. tarplayer.printInfo("You have been unjailed.");
  3951. }
  3952. +
  3953. return true;
  3954. }
  3955. +
  3956. return false;
  3957. }
  3958.  
  3959. @@ -1003,24 +1075,23 @@ public final class ModerationCommands {
  3960. serverCommand = true)
  3961. public static boolean commandUnMute(InnPlugin parent, IdpCommandSender sender, String[] args) {
  3962. if (args.length == 1) {
  3963. - String name = args[0].toLowerCase();
  3964. - IdpPlayer tarplayer = parent.getPlayer(args[0], false);
  3965. + String playerName = args[0];
  3966. + PlayerSession session = null;
  3967.  
  3968. - if (tarplayer != null && tarplayer.isOnline()) {
  3969. - name = tarplayer.getName().toLowerCase();
  3970. + if (PlayerSession.hasSession(playerName)) {
  3971. + session = PlayerSession.getSession_(playerName);
  3972. + } else {
  3973. + sender.printError("That player doesn't have an active session. Cannot unmute!");
  3974. + return true;
  3975. }
  3976.  
  3977. - if (PlayerSession.hasSession(name)) {
  3978. - PlayerSession session = PlayerSession.getSession(name, parent);
  3979. -
  3980. - long muteTicks = session.getRemainingMuteTicks();
  3981. + long muteTicks = session.getRemainingMuteTicks();
  3982.  
  3983. - if (muteTicks == 0) {
  3984. - sender.printError(name + " is not muted!");
  3985. - } else {
  3986. - session.setMuteTicks(0);
  3987. - sender.printInfo(name + " is not longer muted.");
  3988. - }
  3989. + if (muteTicks == 0) {
  3990. + sender.printError(playerName + " is not muted!");
  3991. + } else {
  3992. + session.setMuteTicks(0);
  3993. + sender.printInfo(playerName + " is not longer muted.");
  3994. }
  3995.  
  3996. return true;
  3997. @@ -1036,21 +1107,21 @@ public final class ModerationCommands {
  3998. serverCommand = true)
  3999. public static boolean commandFreeze(InnPlugin parent, IdpCommandSender sender, String[] args) {
  4000. if (args.length == 1) {
  4001. - String name = args[0].toLowerCase();
  4002. - IdpPlayer tarplayer = parent.getPlayer(args[0], false);
  4003. - if (tarplayer != null && tarplayer.isOnline()) {
  4004. - name = tarplayer.getName().toLowerCase();
  4005. - }
  4006. + String playerName = args[0];
  4007. + PlayerSession session = null;
  4008.  
  4009. - if (PlayerSession.hasSession(name)) {
  4010. - PlayerSession session = PlayerSession.getSession(name, parent);
  4011. + if (PlayerSession.hasSession(playerName)) {
  4012. + session = PlayerSession.getSession_(playerName);
  4013. + } else {
  4014. + sender.printError("That player doesn't have an active session. Unable to freeze!");
  4015. + return true;
  4016. + }
  4017.  
  4018. - if (session.isFrozen()) {
  4019. - sender.printError(name + " is already frozen!");
  4020. - } else {
  4021. - session.setFrozen(true);
  4022. - sender.printInfo(name + " was frozen.");
  4023. - }
  4024. + if (session.isFrozen()) {
  4025. + sender.printError(playerName + " is already frozen!");
  4026. + } else {
  4027. + session.setFrozen(true);
  4028. + sender.printInfo(playerName + " was frozen.");
  4029. }
  4030.  
  4031. return true;
  4032. @@ -1066,23 +1137,23 @@ public final class ModerationCommands {
  4033. serverCommand = true)
  4034. public static boolean commandUnFreeze(InnPlugin parent, IdpCommandSender sender, String[] args) {
  4035. if (args.length == 1) {
  4036. - String name = args[0].toLowerCase();
  4037. - IdpPlayer tarplayer = parent.getPlayer(args[0], false);
  4038. + String playerName = args[0];
  4039. + PlayerSession session = null;
  4040.  
  4041. - if (tarplayer != null && tarplayer.isOnline()) {
  4042. - name = tarplayer.getName().toLowerCase();
  4043. + if (PlayerSession.hasSession(playerName)) {
  4044. + session = PlayerSession.getSession_(playerName);
  4045. + } else {
  4046. + sender.printError(playerName + " does not have an active session. Unable to unfreeze!");
  4047. + return true;
  4048. }
  4049.  
  4050. - if (PlayerSession.hasSession(name)) {
  4051. - PlayerSession session = PlayerSession.getSession(name, parent);
  4052. -
  4053. - if (!session.isFrozen()) {
  4054. - sender.printError(name + " is not frozen!");
  4055. - } else {
  4056. - session.setFrozen(false);
  4057. - sender.printInfo(name + " is not longer frozen.");
  4058. - }
  4059. + if (!session.isFrozen()) {
  4060. + sender.printError(playerName + " is not frozen!");
  4061. + } else {
  4062. + session.setFrozen(false);
  4063. + sender.printInfo(playerName + " is not longer frozen.");
  4064. }
  4065. +
  4066. return true;
  4067. }
  4068. return false;
  4069. diff --git a/src/net/innectis/innplugin/Command/Commands/PlayerCommands.java b/src/net/innectis/innplugin/Command/Commands/PlayerCommands.java
  4070. index b47940c1f..1752b8d48 100644
  4071. --- a/src/net/innectis/innplugin/Command/Commands/PlayerCommands.java
  4072. +++ b/src/net/innectis/innplugin/Command/Commands/PlayerCommands.java
  4073. @@ -7,6 +7,7 @@ import java.util.Date;
  4074. import java.util.List;
  4075. import java.util.TimeZone;
  4076. import net.innectis.innplugin.Command.CommandMethod;
  4077. +import net.innectis.innplugin.Configuration;
  4078. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  4079. import net.innectis.innplugin.Handlers.PagedCommandHandler;
  4080. import net.innectis.innplugin.Handlers.StaffMessageHandler;
  4081. @@ -160,7 +161,9 @@ public final class PlayerCommands {
  4082. return false;
  4083. }
  4084.  
  4085. - if (!player.getName().equalsIgnoreCase(args.getString(0))) {
  4086. + String newName = args.getString(0);
  4087. +
  4088. + if (!player.getName().equalsIgnoreCase(newName)) {
  4089. player.printError("You can only change the case of your username!");
  4090. return true;
  4091. }
  4092. @@ -168,12 +171,12 @@ public final class PlayerCommands {
  4093. PreparedStatement statement = null;
  4094.  
  4095. try {
  4096. - statement = DBManager.prepareStatement(" UPDATE players SET name = ? WHERE lower(name) = ?");
  4097. - statement.setString(1, args.getString(0));
  4098. - statement.setString(2, player.getName());
  4099. + statement = DBManager.prepareStatement("UPDATE players SET name = ? WHERE player_id = ?;");
  4100. + statement.setString(1, newName);
  4101. + statement.setString(2, player.getUniqueId().toString());
  4102. statement.executeUpdate();
  4103.  
  4104. - InnPlugin.logInfo("Player ", player.getColoredDisplayName() + " changed name into " + args.getString(0));
  4105. + InnPlugin.logInfo("Player ", player.getColoredDisplayName() + " changed name into " + newName);
  4106. player.getSession().refixUsername();
  4107. player.printInfo("Name updated!");
  4108.  
  4109. @@ -359,28 +362,35 @@ public final class PlayerCommands {
  4110. return true;
  4111. }
  4112.  
  4113. - session.addIgnoredUser("%");
  4114. + session.addIgnoredUser(Configuration.EVERYONE_CREDENTIALS);
  4115. player.print(ChatColor.AQUA, "Added everyone to the ignore list.");
  4116. } else {
  4117. - String ignorePlayer = args.getString(0);
  4118. + String playerName = args.getString(0);
  4119. + IdpPlayer target = parent.getPlayer(playerName);
  4120. +
  4121. + if (target != null) {
  4122. + playerName = target.getName();
  4123. + }
  4124. +
  4125. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  4126.  
  4127. - if (!PlayerSession.isValidPlayer(ignorePlayer)) {
  4128. + if (credentials == null) {
  4129. player.printError("That player doesn't exist!");
  4130. return true;
  4131. }
  4132.  
  4133. - if (ignorePlayer.equalsIgnoreCase(player.getName())) {
  4134. + if (playerName.equalsIgnoreCase(player.getName())) {
  4135. player.printError("You cannot ignore yourself!");
  4136. return true;
  4137. }
  4138.  
  4139. - if (session.isIgnored(ignorePlayer)) {
  4140. + if (session.isIgnored(playerName)) {
  4141. player.printError("This player is already ignored!");
  4142. return true;
  4143. }
  4144.  
  4145. - if (session.addIgnoredUser(ignorePlayer)) {
  4146. - player.print(ChatColor.AQUA, "Added " + ignorePlayer + " to the ignore list.");
  4147. + if (session.addIgnoredUser(credentials)) {
  4148. + player.print(ChatColor.AQUA, "Added " + playerName + " to the ignore list.");
  4149. } else {
  4150. player.printError("That player cannot be ignored.");
  4151. }
  4152. @@ -395,12 +405,14 @@ public final class PlayerCommands {
  4153. usage = "/ignored",
  4154. serverCommand = false)
  4155. public static void commandIgnored(IdpPlayer player) {
  4156. - List<String> ignoredPlayers = player.getSession().getIgnoredPlayers();
  4157. + List<PlayerCredentials> ignoredPlayers = player.getSession().getIgnoredPlayers();
  4158.  
  4159. if (!ignoredPlayers.isEmpty()) {
  4160. String ignoredPlayersString = "";
  4161.  
  4162. - for (String ignoredPlayer : ignoredPlayers) {
  4163. + for (PlayerCredentials pc : ignoredPlayers) {
  4164. + String ignoredPlayer = pc.getName();
  4165. +
  4166. if (ignoredPlayersString.isEmpty()) {
  4167. ignoredPlayersString = ignoredPlayer;
  4168. } else {
  4169. @@ -609,7 +621,7 @@ public final class PlayerCommands {
  4170. m.save();
  4171. }
  4172.  
  4173. - PlayerGroup group = PlayerGroup.getGroupOfUsername(m.getCreator());
  4174. + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(m.getCreatorCredentials().getUniqueId());
  4175. ChatColor color = group.getPrefix().getTextColor();
  4176.  
  4177. player.printInfo("From: " + color + m.getCreator() + ChatColor.DARK_GREEN + " (" + m.getTitle() + ") " + m.getMessage());
  4178. @@ -644,23 +656,33 @@ public final class PlayerCommands {
  4179. return true;
  4180. }
  4181.  
  4182. - String from = player.getName();
  4183. - String title = sargs.getString(1);
  4184. - String content = sargs.getJoinedStrings(2);
  4185. - int lengthToCheck = 100;
  4186.  
  4187. - IdpPlayer toPlayer = parent.getPlayer(sargs.getString(0), false, true);
  4188. - String to = (toPlayer != null ? toPlayer.getName() : sargs.getString(0));
  4189. + String toPlayer = sargs.getString(0);
  4190. + IdpPlayer target = parent.getPlayer(toPlayer);
  4191.  
  4192. - if (from.equalsIgnoreCase(to)) {
  4193. - player.printError("You can't send mail to yourself.");
  4194. + if (target != null) {
  4195. + toPlayer = target.getName();
  4196. + }
  4197. +
  4198. + PlayerCredentials toPlayerCredentials = PlayerCredentialsManager.getByName(toPlayer);
  4199. +
  4200. + if (toPlayerCredentials == null) {
  4201. + player.printError("That player does not exist.");
  4202. return true;
  4203. + } else {
  4204. + // Get the proper casing of the name
  4205. + toPlayer = toPlayerCredentials.getName();
  4206. }
  4207.  
  4208. - PlayerGroup group = PlayerGroup.getGroupOfUsername(to);
  4209. + String fromPlayer = player.getName();
  4210. + PlayerCredentials fromPlayerCredentials = PlayerCredentialsManager.getByName(fromPlayer);
  4211. +
  4212. + String title = sargs.getString(1);
  4213. + String content = sargs.getJoinedStrings(2);
  4214. + int lengthToCheck = 100;
  4215.  
  4216. - if (group == PlayerGroup.NONE) {
  4217. - player.printError("That player doesn't exist.");
  4218. + if (fromPlayer.equalsIgnoreCase(toPlayer)) {
  4219. + player.printError("You can't send mail to yourself.");
  4220. return true;
  4221. }
  4222.  
  4223. @@ -673,19 +695,23 @@ public final class PlayerCommands {
  4224. return true;
  4225. }
  4226.  
  4227. - LogManager.getMailLogger().log(from, to, title, content);
  4228. + PlayerCredentialsManager.addCredentialsToCache(fromPlayerCredentials);
  4229. + PlayerCredentialsManager.addCredentialsToCache(toPlayerCredentials);
  4230.  
  4231. - MailMessage obj = new MailMessage(new Date(), from, to, title, content);
  4232. + LogManager.getMailLogger().log(fromPlayer, toPlayer, title, content);
  4233. +
  4234. + MailMessage obj = new MailMessage(new Date(), fromPlayerCredentials, toPlayerCredentials, title, content);
  4235. obj.save();
  4236.  
  4237. - if (toPlayer != null) {
  4238. - toPlayer.getSession().addMail(obj);
  4239. + if (target != null) {
  4240. + target.getSession().addMail(obj);
  4241.  
  4242. - if (toPlayer.isOnline()) {
  4243. - toPlayer.printInfo(player.getColoredDisplayName() + ChatColor.DARK_GREEN + " has just sent you mail!");
  4244. + if (target.isOnline()) {
  4245. + target.printInfo(player.getColoredDisplayName() + ChatColor.DARK_GREEN + " has just sent you mail!");
  4246. }
  4247. }
  4248. - player.printInfo("Sent a mail message to " + to + "!");
  4249. +
  4250. + player.printInfo("Sent a mail message to " + toPlayer + "!");
  4251.  
  4252. return true;
  4253. }
  4254. @@ -724,7 +750,7 @@ public final class PlayerCommands {
  4255. boolean restricted = !sender.hasPermission(Permission.command_staffrequest_special);
  4256.  
  4257. for (StaffMessage sm : staffRequests) {
  4258. - PlayerGroup group = PlayerGroup.getGroupOfUsername(sm.getCreator());
  4259. + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(sm.getCreatorCredentials().getUniqueId());
  4260. String coloredName = group.getPrefix().getTextColor() + sm.getCreator();
  4261. java.sql.Date date = new java.sql.Date(sm.getDate().getTime());
  4262.  
  4263. @@ -781,7 +807,7 @@ public final class PlayerCommands {
  4264. return true;
  4265. }
  4266.  
  4267. - PlayerGroup group = PlayerGroup.getGroupOfUsername(sm.getCreator());
  4268. + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(sm.getCreatorCredentials().getUniqueId());
  4269. String coloredName = group.getPrefix().getTextColor() + sm.getCreator();
  4270. java.sql.Date date = new java.sql.Date(sm.getDate().getTime());
  4271.  
  4272. @@ -818,7 +844,7 @@ public final class PlayerCommands {
  4273. StaffMessage sm = StaffMessageHandler.deleteStaffRequeustById(requestId);
  4274.  
  4275. if (sm != null) {
  4276. - PlayerGroup group = PlayerGroup.getGroupOfUsername(sm.getCreator());
  4277. + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(sm.getCreatorCredentials().getUniqueId());
  4278. String coloredName = group.getPrefix().getTextColor() + sm.getCreator();
  4279.  
  4280. String staffMsg = sender.getColoredName() + ChatColor.DARK_GREEN + " deleted staff request ID " + requestId + " by " + coloredName + ChatColor.DARK_GREEN + ": " + ChatColor.YELLOW + sm.getMessage();
  4281. @@ -872,7 +898,8 @@ public final class PlayerCommands {
  4282. return true;
  4283. }
  4284.  
  4285. - StaffMessage sm = new StaffMessage(new Date(), player.getName(), request);
  4286. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName());
  4287. + StaffMessage sm = new StaffMessage(new Date(), credentials, request);
  4288. boolean result = StaffMessageHandler.addStaffRequest(sm);
  4289.  
  4290. if (result) {
  4291. @@ -903,21 +930,21 @@ public final class PlayerCommands {
  4292. usage = "/backpack",
  4293. usage_Admin = "/backpack [player]",
  4294. serverCommand = false)
  4295. - public static boolean commandBackpack(InnPlugin plugin, IdpPlayer player, LynxyArguments args) {
  4296. + public static boolean commandBackpack(InnPlugin parent, IdpPlayer player, LynxyArguments args) {
  4297. boolean override = player.hasPermission(Permission.special_backpack_override);
  4298. boolean self = true;
  4299. - String name = player.getName();
  4300. + String playerName = player.getName();
  4301.  
  4302. if (args.getActionSize() > 0) {
  4303. if (override) {
  4304. - name = args.getString(0);
  4305. + playerName = args.getString(0);
  4306. + IdpPlayer target = parent.getPlayer(playerName);
  4307.  
  4308. - if (!PlayerSession.isValidPlayer(name)) {
  4309. - player.printError("That player doesn't exist!");
  4310. - return true;
  4311. + if (target != null) {
  4312. + playerName = target.getName();
  4313. }
  4314.  
  4315. - self = name.equalsIgnoreCase(player.getName());
  4316. + self = playerName.equalsIgnoreCase(player.getName());
  4317. }
  4318. }
  4319.  
  4320. @@ -935,12 +962,19 @@ public final class PlayerCommands {
  4321. }
  4322. }
  4323.  
  4324. - IdpInventory inv = plugin.getBackpackView(name);
  4325. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  4326. +
  4327. + if (credentials == null) {
  4328. + player.printError("That player doesn't exist!");
  4329. + return true;
  4330. + }
  4331. +
  4332. + IdpInventory inv = parent.getBackpackView(credentials.getUniqueId());
  4333. boolean fresh = false;
  4334.  
  4335. if (inv == null) {
  4336. - inv = new IdpInventory(name + "'s backpack", 27);
  4337. - plugin.addBackpackView(name, inv);
  4338. + inv = new IdpInventory(playerName + "'s backpack", 27);
  4339. + parent.addBackpackView(credentials.getUniqueId(), inv);
  4340. fresh = true;
  4341. }
  4342.  
  4343. @@ -951,20 +985,21 @@ public final class PlayerCommands {
  4344. if (self) {
  4345. backpack = player.getSession().getBackpack();
  4346. } else {
  4347. - IdpPlayer testPlayer = plugin.getPlayer(name);
  4348. + IdpPlayer testPlayer = parent.getPlayer(playerName);
  4349.  
  4350. if (testPlayer != null) {
  4351. backpack = testPlayer.getSession().getBackpack();
  4352. } else {
  4353. - backpack = PlayerBackpack.loadBackpackFromDB(name);
  4354. + backpack = PlayerBackpack.loadBackpackFromDB(credentials.getUniqueId(), credentials.getName());
  4355. }
  4356. }
  4357.  
  4358. inv.setContents(backpack.getItems());
  4359. }
  4360.  
  4361. - player.printInfo("You open " + (self ? "your " : name + "'s ") + "backpack!");
  4362. - player.getSession().setBackpackOwner(name);
  4363. + player.printInfo("You open " + (self ? "your " : playerName + "'s ") + "backpack!");
  4364. + player.getSession().setBackpackOwnerId(credentials.getUniqueId());
  4365. + player.getSession().setBackpackOwner(credentials.getName());
  4366. player.openInventory(inv);
  4367.  
  4368. return true;
  4369. @@ -978,7 +1013,6 @@ public final class PlayerCommands {
  4370. obfusticateLogging = true,
  4371. serverCommand = false)
  4372. public static boolean commandLogin(IdpPlayer player, ParameterArguments args) {
  4373. -
  4374. // Check if password was given.
  4375. if (args.size() != 0 && args.size() != 1) {
  4376. return false;
  4377. @@ -992,17 +1026,16 @@ public final class PlayerCommands {
  4378. }
  4379.  
  4380. // Check password
  4381. - if (PlayerSecurity.checkPlayerPassword(player.getName(), args.getString(0))) {
  4382. -
  4383. + if (PlayerSecurity.checkPlayerPassword(player.getUniqueId(), player.getName(), args.getString(0))) {
  4384. player.printInfo("Loggin in succesfully.");
  4385. player.getSession().setPlayerLoggedin(true);
  4386. return true;
  4387.  
  4388. } else {
  4389. - PlayerSecurity.logBadPassword(player.getName(), player.getHandle().getAddress().getAddress().getHostAddress());
  4390. + PlayerSecurity.logBadPassword(player.getUniqueId(), player.getName(), player.getHandle().getAddress().getAddress().getHostAddress());
  4391.  
  4392. // Check if they can still try, if not kick
  4393. - if (!PlayerSecurity.canLogin(player.getName())) {
  4394. + if (!PlayerSecurity.canLogin(player.getUniqueId(), player.getName())) {
  4395. player.getHandle().kickPlayer("Your password was incorrect.");
  4396. } else {
  4397. player.printError("Password incorrect!");
  4398. @@ -1011,7 +1044,6 @@ public final class PlayerCommands {
  4399. return true;
  4400. }
  4401. } else {
  4402. -
  4403. // Check if player wants to update password
  4404. if (args.hasOption("update", "new", "u")) {
  4405.  
  4406. @@ -1020,10 +1052,10 @@ public final class PlayerCommands {
  4407.  
  4408. if (args.size() == 0) {
  4409. // Check if player has a password;
  4410. - canChange = !PlayerSecurity.hasPassword(player.getName());
  4411. + canChange = !PlayerSecurity.hasPassword(player.getUniqueId(), player.getName());
  4412. } else {
  4413. // Check password
  4414. - canChange = PlayerSecurity.checkPlayerPassword(player.getName(), args.getString(0));
  4415. + canChange = PlayerSecurity.checkPlayerPassword(player.getUniqueId(), player.getName(), args.getString(0));
  4416. }
  4417.  
  4418. // Only do rest if the password can be changed.
  4419. @@ -1036,7 +1068,7 @@ public final class PlayerCommands {
  4420. }
  4421.  
  4422. // Update the password.
  4423. - if (PlayerSecurity.setPassword(player.getName(), newpass)) {
  4424. + if (PlayerSecurity.setPassword(player.getUniqueId(), player.getName(), newpass)) {
  4425. player.printInfo("Password was updated!");
  4426. } else {
  4427. player.printError("Could not update password.");
  4428. @@ -1056,9 +1088,9 @@ public final class PlayerCommands {
  4429. }
  4430.  
  4431. // Only do rest if the password can be changed.
  4432. - if (PlayerSecurity.checkPlayerPassword(player.getName(), args.getString("delete"))) {
  4433. + if (PlayerSecurity.checkPlayerPassword(player.getUniqueId(), player.getName(), args.getString("delete"))) {
  4434. // Remove the password
  4435. - if (PlayerSecurity.removePassword(player.getName())) {
  4436. + if (PlayerSecurity.removePassword(player.getUniqueId(), player.getName())) {
  4437. player.printInfo("Password was removed!!");
  4438. } else {
  4439. player.printError("Could not remove password.");
  4440. @@ -1085,7 +1117,7 @@ public final class PlayerCommands {
  4441. return;
  4442. }
  4443.  
  4444. - int votePoints = TransactionHandler.getTransactionObject(player.getName()).getValue(TransactionType.VOTE_POINTS);
  4445. + int votePoints = TransactionHandler.getTransactionObject(player.getUniqueId(), player.getName()).getValue(TransactionType.VOTE_POINTS);
  4446. IdpInventory chest = new IdpInventory("Redeem an Item ("
  4447. + votePoints + " remaining)", 36);
  4448. chest.setCustom("redeemChest");
  4449. diff --git a/src/net/innectis/innplugin/Command/Commands/Polls/AbstractPoll.java b/src/net/innectis/innplugin/Command/Commands/Polls/AbstractPoll.java
  4450. index 93351561b..1ba74d223 100644
  4451. --- a/src/net/innectis/innplugin/Command/Commands/Polls/AbstractPoll.java
  4452. +++ b/src/net/innectis/innplugin/Command/Commands/Polls/AbstractPoll.java
  4453. @@ -1,15 +1,19 @@
  4454. package net.innectis.innplugin.Command.Commands.Polls;
  4455.  
  4456. import java.sql.PreparedStatement;
  4457. +import java.sql.ResultSet;
  4458. import java.sql.SQLException;
  4459. import java.util.ArrayList;
  4460. import java.util.List;
  4461. +import java.util.UUID;
  4462. import java.util.logging.Level;
  4463. import java.util.logging.Logger;
  4464. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  4465. import net.innectis.innplugin.InnPlugin;
  4466. import net.innectis.innplugin.Items.StackBag;
  4467. import net.innectis.innplugin.Player.IdpPlayer;
  4468. +import net.innectis.innplugin.Player.PlayerCredentials;
  4469. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  4470. import net.innectis.innplugin.Player.PlayerGroup;
  4471. import net.innectis.innplugin.Utility.DatabaseTools;
  4472. import net.innectis.innplugin.Utility.ObjectParseException;
  4473. @@ -143,19 +147,32 @@ abstract class AbstractPoll implements Poll {
  4474. */
  4475. protected final List<PlayerAnswer> loadAnswers() {
  4476. if (pollid > 0) {
  4477. + List<PlayerAnswer> playerAnswers = new ArrayList<PlayerAnswer>();
  4478. +
  4479. PreparedStatement statement = null;
  4480. + ResultSet set = null;
  4481.  
  4482. try {
  4483. - statement = DBManager.prepareStatement(" SELECT username as playername, answer FROM poll_answers WHERE id = ? ");
  4484. + statement = DBManager.prepareStatement(" SELECT player_id, answer FROM poll_answers WHERE id = ? ");
  4485. statement.setInt(1, pollid);
  4486. + set = statement.executeQuery();
  4487. +
  4488. + while (set.next()) {
  4489. + String playerIdString = set.getString("player_id");
  4490. + UUID playerId = UUID.fromString(playerIdString);
  4491. + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(playerId);
  4492. +
  4493. + String answer = set.getString("answer");
  4494.  
  4495. - return DatabaseTools.parseToObjects(PlayerAnswer.class, statement.executeQuery());
  4496. + playerAnswers.add(new PlayerAnswer(credentials, answer));
  4497. + }
  4498. +
  4499. + return playerAnswers;
  4500. } catch (SQLException ex) {
  4501. Logger.getLogger(AbstractPoll.class.getName()).log(Level.SEVERE, null, ex);
  4502. - } catch (ObjectParseException ex) {
  4503. - Logger.getLogger(AbstractPoll.class.getName()).log(Level.SEVERE, null, ex);
  4504. } finally {
  4505. DBManager.closePreparedStatement(statement);
  4506. + DBManager.closeResultSet(set);
  4507. }
  4508. }
  4509.  
  4510. @@ -185,9 +202,9 @@ abstract class AbstractPoll implements Poll {
  4511. PreparedStatement statement = null;
  4512.  
  4513. try {
  4514. - statement = DBManager.prepareStatement(" INSERT INTO poll_answers (id, username, answer) VALUES (?,?,?) ");
  4515. + statement = DBManager.prepareStatement(" INSERT INTO poll_answers (id, player_id, answer) VALUES (?,?,?) ");
  4516. statement.setInt(1, pollid);
  4517. - statement.setString(2, answer.getPlayername());
  4518. + statement.setString(2, answer.getCredentials().getUniqueId().toString());
  4519. statement.setString(3, answer.getAnswer());
  4520.  
  4521. answers.add(answer);
  4522. diff --git a/src/net/innectis/innplugin/Command/Commands/Polls/MultipleChoicePoll.java b/src/net/innectis/innplugin/Command/Commands/Polls/MultipleChoicePoll.java
  4523. index 633e1c587..94ab81785 100644
  4524. --- a/src/net/innectis/innplugin/Command/Commands/Polls/MultipleChoicePoll.java
  4525. +++ b/src/net/innectis/innplugin/Command/Commands/Polls/MultipleChoicePoll.java
  4526. @@ -12,6 +12,8 @@ import net.innectis.innplugin.Handlers.Datasource.DBManager;
  4527. import net.innectis.innplugin.InnPlugin;
  4528. import net.innectis.innplugin.Player.Chat.ChatColor;
  4529. import net.innectis.innplugin.Player.IdpPlayer;
  4530. +import net.innectis.innplugin.Player.PlayerCredentials;
  4531. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  4532. import net.innectis.innplugin.Player.PlayerGroup;
  4533. import net.innectis.innplugin.Utility.DatabaseTools;
  4534. import net.innectis.innplugin.Utility.ObjectParseException;
  4535. @@ -73,7 +75,8 @@ public class MultipleChoicePoll extends AbstractPoll {
  4536. return true;
  4537. }
  4538.  
  4539. - existingAnswer = new PlayerAnswer(player.getName(), chosenoption.getOptionValue());
  4540. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName());
  4541. + existingAnswer = new PlayerAnswer(credentials, chosenoption.getOptionValue());
  4542. addAnswer(existingAnswer);
  4543. player.printInfo("Thank you for voting!");
  4544. } else {
  4545. diff --git a/src/net/innectis/innplugin/Command/Commands/Polls/OpenChoicePoll.java b/src/net/innectis/innplugin/Command/Commands/Polls/OpenChoicePoll.java
  4546. index ad4a3ccd5..8de11db49 100644
  4547. --- a/src/net/innectis/innplugin/Command/Commands/Polls/OpenChoicePoll.java
  4548. +++ b/src/net/innectis/innplugin/Command/Commands/Polls/OpenChoicePoll.java
  4549. @@ -8,6 +8,8 @@ import net.innectis.innplugin.Handlers.Datasource.DBManager;
  4550. import net.innectis.innplugin.InnPlugin;
  4551. import net.innectis.innplugin.Player.Chat.ChatColor;
  4552. import net.innectis.innplugin.Player.IdpPlayer;
  4553. +import net.innectis.innplugin.Player.PlayerCredentials;
  4554. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  4555. import net.innectis.innplugin.Player.PlayerGroup;
  4556. import net.innectis.innplugin.Utility.StringUtil;
  4557.  
  4558. @@ -49,7 +51,8 @@ public class OpenChoicePoll extends AbstractPoll {
  4559. }
  4560.  
  4561. if (existingAnswer == null) {
  4562. - existingAnswer = new PlayerAnswer(player.getName(), answer);
  4563. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName());
  4564. + existingAnswer = new PlayerAnswer(credentials, answer);
  4565. addAnswer(existingAnswer);
  4566. player.printInfo("Thank you for voting!");
  4567. } else {
  4568. diff --git a/src/net/innectis/innplugin/Command/Commands/Polls/PlayerAnswer.java b/src/net/innectis/innplugin/Command/Commands/Polls/PlayerAnswer.java
  4569. index dbf9fa83b..2905b8ecc 100644
  4570. --- a/src/net/innectis/innplugin/Command/Commands/Polls/PlayerAnswer.java
  4571. +++ b/src/net/innectis/innplugin/Command/Commands/Polls/PlayerAnswer.java
  4572. @@ -1,36 +1,46 @@
  4573. package net.innectis.innplugin.Command.Commands.Polls;
  4574.  
  4575. +import net.innectis.innplugin.Player.PlayerCredentials;
  4576. +
  4577. /**
  4578. *
  4579. * @author Hretsam
  4580. - *
  4581. + *
  4582. * An answer by a player.
  4583. */
  4584. public class PlayerAnswer {
  4585. -
  4586. - private String playername;
  4587. + private PlayerCredentials credentials;
  4588. private String answer;
  4589.  
  4590. public PlayerAnswer() {
  4591. }
  4592.  
  4593. - public PlayerAnswer(String playername, String answer) {
  4594. - this.playername = playername;
  4595. + public PlayerAnswer(PlayerCredentials credentials, String answer) {
  4596. + this.credentials = credentials;
  4597. this.answer = answer;
  4598. }
  4599.  
  4600. + /**
  4601. + * Returns the credentials of the player that has the answer
  4602. + * @return
  4603. + */
  4604. + public PlayerCredentials getCredentials() {
  4605. + return credentials;
  4606. + }
  4607. +
  4608. /**
  4609. * @return the playername
  4610. */
  4611. public String getPlayername() {
  4612. - return playername;
  4613. + return credentials.getName();
  4614. }
  4615.  
  4616. /**
  4617. - * @param playername the playername to set
  4618. + * Sets the new credentials
  4619. + * @param credentials
  4620. */
  4621. - public void setPlayername(String playername) {
  4622. - this.playername = playername;
  4623. + public void setCredentials(PlayerCredentials credentials) {
  4624. + this.credentials = credentials;
  4625. }
  4626.  
  4627. /**
  4628. @@ -46,5 +56,5 @@ public class PlayerAnswer {
  4629. public void setAnswer(String answer) {
  4630. this.answer = answer;
  4631. }
  4632. -
  4633. +
  4634. }
  4635. diff --git a/src/net/innectis/innplugin/Command/Commands/Polls/PollOption.java b/src/net/innectis/innplugin/Command/Commands/Polls/PollOption.java
  4636. index c0d9879ab..5f7fc493a 100644
  4637. --- a/src/net/innectis/innplugin/Command/Commands/Polls/PollOption.java
  4638. +++ b/src/net/innectis/innplugin/Command/Commands/Polls/PollOption.java
  4639. @@ -5,7 +5,6 @@ package net.innectis.innplugin.Command.Commands.Polls;
  4640. * @author Hretsam
  4641. */
  4642. public class PollOption {
  4643. -
  4644. private String value;
  4645. private String answer;
  4646.  
  4647. diff --git a/src/net/innectis/innplugin/Command/Commands/ShopCommands.java b/src/net/innectis/innplugin/Command/Commands/ShopCommands.java
  4648. index 485a764a3..439b0f631 100644
  4649. --- a/src/net/innectis/innplugin/Command/Commands/ShopCommands.java
  4650. +++ b/src/net/innectis/innplugin/Command/Commands/ShopCommands.java
  4651. @@ -1,25 +1,25 @@
  4652. package net.innectis.innplugin.Command.Commands;
  4653.  
  4654. import java.util.Random;
  4655. -import net.innectis.innplugin.InnPlugin;
  4656. import net.innectis.innplugin.Command.CommandMethod;
  4657. import net.innectis.innplugin.Configuration;
  4658. -import net.innectis.innplugin.IdpCommandSender;
  4659. -import org.bukkit.Server;
  4660. import net.innectis.innplugin.Handlers.TransactionHandler;
  4661. import net.innectis.innplugin.Handlers.TransactionHandler.TransactionType;
  4662. +import net.innectis.innplugin.IdpCommandSender;
  4663. +import net.innectis.innplugin.InnPlugin;
  4664. import net.innectis.innplugin.InnectisObjects.TransactionObject;
  4665. import net.innectis.innplugin.Loggers.LogManager;
  4666. import net.innectis.innplugin.Loggers.SendMoneyLogger;
  4667. import net.innectis.innplugin.Player.Chat.ChatColor;
  4668. import net.innectis.innplugin.Player.IdpPlayer;
  4669. import net.innectis.innplugin.Player.Permission;
  4670. -import net.innectis.innplugin.Player.PlayerGroup;
  4671. +import net.innectis.innplugin.Player.PlayerCredentials;
  4672. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  4673. import net.innectis.innplugin.Player.PlayerSession;
  4674. import net.innectis.innplugin.Tasking.SyncTasks.ValutaBankTransactionTask;
  4675. import net.innectis.innplugin.Tasking.TaskManager;
  4676. import net.innectis.innplugin.Utility.LynxyArguments;
  4677. -import net.innectis.innplugin.Utility.NumberUtil;
  4678. +import org.bukkit.Server;
  4679. import org.bukkit.command.CommandSender;
  4680.  
  4681. public final class ShopCommands {
  4682. @@ -31,17 +31,20 @@ public final class ShopCommands {
  4683. public static boolean commandModifyBalance(InnPlugin parent, IdpCommandSender<? extends CommandSender> sender, String[] args) {
  4684. if (args.length > 2) {
  4685. String playerName = args[0];
  4686. - IdpPlayer testPlayer = parent.getPlayer(playerName);
  4687. + IdpPlayer target = parent.getPlayer(playerName);
  4688.  
  4689. - if (testPlayer != null) {
  4690. - playerName = testPlayer.getName();
  4691. + if (target != null) {
  4692. + playerName = target.getName();
  4693. }
  4694.  
  4695. - PlayerGroup group = PlayerGroup.getGroupOfUsername(playerName);
  4696. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  4697.  
  4698. - if (group == PlayerGroup.NONE) {
  4699. - sender.printError("That user does not exist.");
  4700. + if (credentials == null) {
  4701. + sender.printError("That player does not exist.");
  4702. return true;
  4703. + } else {
  4704. + // Get the proper casing of the name
  4705. + playerName = credentials.getName();
  4706. }
  4707.  
  4708. int action = 0; // 1 = add, 2 = subtract, 3 = set
  4709. @@ -86,18 +89,18 @@ public final class ShopCommands {
  4710. }
  4711. }
  4712.  
  4713. - TransactionObject to = TransactionHandler.getTransactionObject(playerName);
  4714. + TransactionObject transaction = TransactionHandler.getTransactionObject(credentials.getUniqueId(), credentials.getName());
  4715. String amtTypeName = (amount == 1 ? type.getName().toLowerCase().substring(0, type.getName().length() - 1) : type.getName().toLowerCase());
  4716.  
  4717. if (action == 1) {
  4718. - to.addValue(amount, type);
  4719. + transaction.addValue(amount, type);
  4720. sender.printInfo("Deposited " + amount + " " + amtTypeName + " to " + playerName + "!");
  4721.  
  4722. - if (testPlayer != null && testPlayer.isOnline()) {
  4723. - testPlayer.printInfo(amount + " " + amtTypeName + " was deposited to you!");
  4724. + if (target != null && target.isOnline()) {
  4725. + target.printInfo(amount + " " + amtTypeName + " was deposited to you!");
  4726. }
  4727. } else if (action == 2) {
  4728. - int balance = to.getValue(type);
  4729. + int balance = transaction.getValue(type);
  4730. String balTypeName = (balance == 1 ? type.getName().toLowerCase().substring(0, type.getName().length() - 1) : type.getName().toLowerCase());
  4731.  
  4732. if (balance < amount) {
  4733. @@ -105,18 +108,18 @@ public final class ShopCommands {
  4734. return true;
  4735. }
  4736.  
  4737. - to.subtractValue(amount, type);
  4738. + transaction.subtractValue(amount, type);
  4739. sender.printInfo("Withdrew " + amount + " " + amtTypeName + " from " + playerName + "!");
  4740.  
  4741. - if (testPlayer != null && testPlayer.isOnline()) {
  4742. - testPlayer.printInfo(amount + " " + amtTypeName + " was withdrawn from you!");
  4743. + if (target != null && target.isOnline()) {
  4744. + target.printInfo(amount + " " + amtTypeName + " was withdrawn from you!");
  4745. }
  4746. } else if (action == 3) {
  4747. - to.setValue(amount, type);
  4748. + transaction.setValue(amount, type);
  4749. sender.printInfo("Set " + playerName + "'s " + type.getName().toLowerCase() + " to " + amount + "!");
  4750.  
  4751. - if (testPlayer != null && testPlayer.isOnline()) {
  4752. - testPlayer.printInfo("Your " + type.getName().toLowerCase() + " was set to " + amount + "!");
  4753. + if (target != null && target.isOnline()) {
  4754. + target.printInfo("Your " + type.getName().toLowerCase() + " was set to " + amount + "!");
  4755. }
  4756. }
  4757.  
  4758. @@ -131,53 +134,60 @@ public final class ShopCommands {
  4759. permission = Permission.command_shop_sendmoney,
  4760. usage = "/sendmoney <player> <amount>",
  4761. serverCommand = false)
  4762. - public static boolean commandSendMoney(Server server, InnPlugin parent, IdpCommandSender<? extends CommandSender> sender, String args[]) {
  4763. + public static boolean commandSendMoney(Server server, InnPlugin parent, IdpPlayer player, String args[]) {
  4764. if (args.length > 1) {
  4765. + String playerName = args[0];
  4766. + IdpPlayer target = parent.getPlayer(playerName);
  4767. +
  4768. + if (target != null) {
  4769. + playerName = target.getName();
  4770. + }
  4771. +
  4772. + PlayerCredentials receiverCredentials = PlayerCredentialsManager.getByName(playerName);
  4773. +
  4774. + if (receiverCredentials == null) {
  4775. + player.printError("That player does not exist.");
  4776. + return true;
  4777. + } else {
  4778. + // Get the proper casing of the name
  4779. + playerName = receiverCredentials.getName();
  4780. + }
  4781. +
  4782. int amount = 0;
  4783.  
  4784. try {
  4785. amount = Integer.parseInt(args[1]);
  4786.  
  4787. if (amount < 1) {
  4788. - sender.printError("Amount cannot be less than 1.");
  4789. + player.printError("Amount cannot be less than 1.");
  4790. return true;
  4791. }
  4792. } catch (NumberFormatException ex) {
  4793. - sender.printError("Amount is not a number.");
  4794. - return true;
  4795. - }
  4796. -
  4797. - IdpPlayer player = parent.getPlayer(args[0], false, true);
  4798. - String receivePlayer = (player != null ? player.getName() : args[0]);
  4799. -
  4800. - PlayerGroup group = PlayerGroup.getGroupOfUsername(receivePlayer);
  4801. -
  4802. - if (group == PlayerGroup.NONE) {
  4803. - sender.printError("That user does not exist.");
  4804. + player.printError("Amount is not a number.");
  4805. return true;
  4806. }
  4807.  
  4808. - TransactionObject transactionSender = TransactionHandler.getTransactionObject(sender.getName());
  4809. + TransactionObject transactionSender = TransactionHandler.getTransactionObject(player.getUniqueId(), player.getName());
  4810. int balance = transactionSender.getValue(TransactionType.VALUTAS);
  4811.  
  4812. if (amount > balance) {
  4813. - sender.printError("You cannot send more valutas than you have.");
  4814. + player.printError("You cannot send more valutas than you have.");
  4815. return true;
  4816. }
  4817.  
  4818. transactionSender.subtractValue(amount, TransactionType.VALUTAS);
  4819.  
  4820. - TransactionObject transactionReceiver = TransactionHandler.getTransactionObject(receivePlayer);
  4821. + TransactionObject transactionReceiver = TransactionHandler.getTransactionObject(receiverCredentials.getUniqueId(), receiverCredentials.getName());
  4822. transactionReceiver.addValue(amount, TransactionType.VALUTAS);
  4823.  
  4824. - sender.printInfo("You sent " + amount + " valuta" + (amount != 1 ? "s" : "") + " to " + receivePlayer + "!");
  4825. + player.printInfo("You sent " + amount + " valuta" + (amount != 1 ? "s" : "") + " to " + playerName + "!");
  4826.  
  4827. if (player != null && player.isOnline()) {
  4828. - player.printInfo(sender.getName() + " sent you " + amount + " valuta" + (amount != 1 ? "s" : "") + ".");
  4829. + player.printInfo(player.getName() + " sent you " + amount + " valuta" + (amount != 1 ? "s" : "") + ".");
  4830. }
  4831.  
  4832. SendMoneyLogger sml = LogManager.getSendMoneyLogger();
  4833. - sml.log(sender.getName(), receivePlayer, amount);
  4834. + sml.log(player.getName(), playerName, amount);
  4835.  
  4836. return true;
  4837. }
  4838. @@ -192,7 +202,7 @@ public final class ShopCommands {
  4839. serverCommand = false)
  4840. public static boolean commandBank(InnPlugin parent, IdpPlayer player, LynxyArguments args) {
  4841. if (args.hasArgument("deposit", "d", "withdraw", "w")) {
  4842. - TransactionObject transaction = TransactionHandler.getTransactionObject(player.getName());
  4843. + TransactionObject transaction = TransactionHandler.getTransactionObject(player.getUniqueId(), player.getName());
  4844. boolean isDeposit = args.hasArgument("deposit", "d");
  4845. int amount = 0;
  4846.  
  4847. @@ -265,7 +275,7 @@ public final class ShopCommands {
  4848. bankTaskTime = (baseTime + extendedTime);
  4849. }
  4850.  
  4851. - ValutaBankTransactionTask vbtt = new ValutaBankTransactionTask(player.getName(), bankTaskTime);
  4852. + ValutaBankTransactionTask vbtt = new ValutaBankTransactionTask(player.getUniqueId(), player.getName(), bankTaskTime);
  4853. long taskId = parent.getTaskManager().addTask(vbtt);
  4854.  
  4855. session.setBankTaskId(taskId);
  4856. @@ -283,36 +293,43 @@ public final class ShopCommands {
  4857. usage = "/balance [player]",
  4858. serverCommand = true)
  4859. public static boolean commandBalance(Server server, InnPlugin parent, IdpCommandSender sender, String[] args) {
  4860. - String lookupPlayer = sender.getName();
  4861. + String playerName = sender.getName();
  4862.  
  4863. if (args.length > 0) {
  4864. - IdpPlayer playerCheck = parent.getPlayer(args[0], false, true);
  4865. - lookupPlayer = (playerCheck != null ? playerCheck.getName() : args[0]);
  4866. + playerName = args[0];
  4867. + IdpPlayer target = parent.getPlayer(playerName);
  4868.  
  4869. - PlayerGroup group = PlayerGroup.getGroupOfUsername(lookupPlayer);
  4870. -
  4871. - if (group == PlayerGroup.NONE) {
  4872. - sender.printError("That player doesn't exist.");
  4873. - return true;
  4874. + if (target != null) {
  4875. + playerName = target.getName();
  4876. }
  4877.  
  4878. - if (!lookupPlayer.equalsIgnoreCase(sender.getName().toLowerCase())
  4879. + if (!playerName.equalsIgnoreCase(sender.getName().toLowerCase())
  4880. && sender.isPlayer() && !((IdpPlayer) sender).hasPermission(Permission.command_shop_getallbalances)) {
  4881. sender.printError("You are unable to view the balance of other players.");
  4882. return true;
  4883. }
  4884. }
  4885.  
  4886. - if (!sender.isPlayer() && lookupPlayer.equals(sender.getName())) {
  4887. + if (!sender.isPlayer() && playerName.equals(sender.getName())) {
  4888. sender.printError("Console can't lookup itself!");
  4889. return true;
  4890. }
  4891.  
  4892. - TransactionObject transaction = TransactionHandler.getTransactionObject(lookupPlayer);
  4893. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  4894. +
  4895. + if (credentials == null) {
  4896. + sender.printError("That player does not exist.");
  4897. + return true;
  4898. + } else {
  4899. + // Get the proper casing of the name
  4900. + playerName = credentials.getName();
  4901. + }
  4902. +
  4903. + TransactionObject transaction = TransactionHandler.getTransactionObject(credentials.getUniqueId(), credentials.getName());
  4904. int balance = transaction.getValue(TransactionType.VALUTAS);
  4905. - String responseText = lookupPlayer + "'s balance is: " + balance + " valuta" + (balance != 1 ? "s" : "");
  4906. + String responseText = playerName + "'s balance is: " + balance + " valuta" + (balance != 1 ? "s" : "");
  4907.  
  4908. - if (lookupPlayer.equalsIgnoreCase(sender.getName())
  4909. + if (playerName.equalsIgnoreCase(sender.getName())
  4910. || !sender.isPlayer() || ((IdpPlayer) sender).hasPermission(Permission.command_shop_getallbalances)) {
  4911. int bank = transaction.getValue(TransactionType.VALUTAS_IN_BANK);
  4912. responseText += " (Bank: " + bank + " valuta" + (bank != 1 ? "s" : "") + ")";
  4913. diff --git a/src/net/innectis/innplugin/Command/Commands/SpoofCommands.java b/src/net/innectis/innplugin/Command/Commands/SpoofCommands.java
  4914. index 1eb1d360d..3c3bc4a9b 100644
  4915. --- a/src/net/innectis/innplugin/Command/Commands/SpoofCommands.java
  4916. +++ b/src/net/innectis/innplugin/Command/Commands/SpoofCommands.java
  4917. @@ -7,6 +7,8 @@ import net.innectis.innplugin.InnectisObjects.SpoofObject;
  4918. import net.innectis.innplugin.Player.Chat.ChatColor;
  4919. import net.innectis.innplugin.Player.IdpPlayer;
  4920. import net.innectis.innplugin.Player.Permission;
  4921. +import net.innectis.innplugin.Player.PlayerCredentials;
  4922. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  4923. import net.innectis.innplugin.Player.PlayerGroup;
  4924. import net.innectis.innplugin.Utility.LynxyArguments;
  4925. import net.innectis.innplugin.Utility.SmartArguments;
  4926. @@ -23,16 +25,24 @@ public final class SpoofCommands {
  4927. serverCommand = true,
  4928. hiddenCommand = true)
  4929. public static boolean commandLogin(InnPlugin parent, IdpCommandSender sender, String[] args) {
  4930. - if (args.length > 0) {
  4931. - PlayerGroup group = PlayerGroup.getGroupOfUsername(args[0]);
  4932. - net.innectis.innplugin.Player.Chat.ChatColor color = group.getPrefix().getTextColor();
  4933. + if (args.length == 0) {
  4934. + return false;
  4935. + }
  4936.  
  4937. - parent.broadCastMessage((color == net.innectis.innplugin.Player.Chat.ChatColor.WHITE ? net.innectis.innplugin.Player.Chat.ChatColor.YELLOW : color) + args[0] + ChatColor.YELLOW + " joined the server.");
  4938. - return true;
  4939. + // Default to guest color
  4940. + net.innectis.innplugin.Player.Chat.ChatColor color = net.innectis.innplugin.Player.Chat.ChatColor.YELLOW;
  4941.  
  4942. + String playerName = args[0];
  4943. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  4944. +
  4945. + // Modify group color by this player's group
  4946. + if (credentials != null) {
  4947. + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(credentials.getUniqueId());
  4948. + color = group.getPrefix().getTextColor();
  4949. }
  4950.  
  4951. - return false;
  4952. + parent.broadCastMessage(color + playerName + " joined the server.");
  4953. + return true;
  4954. }
  4955.  
  4956. @CommandMethod(aliases = {"slogout"},
  4957. @@ -42,15 +52,24 @@ public final class SpoofCommands {
  4958. serverCommand = true,
  4959. hiddenCommand = true)
  4960. public static boolean commandLogout(InnPlugin parent, IdpCommandSender sender, String[] args) {
  4961. - if (args.length > 0) {
  4962. - PlayerGroup group = PlayerGroup.getGroupOfUsername(args[0]);
  4963. - net.innectis.innplugin.Player.Chat.ChatColor color = group.getPrefix().getTextColor();
  4964. + if (args.length < 1) {
  4965. + return false;
  4966. + }
  4967.  
  4968. - parent.broadCastMessage((color == net.innectis.innplugin.Player.Chat.ChatColor.WHITE ? net.innectis.innplugin.Player.Chat.ChatColor.YELLOW : color) + args[0] + ChatColor.YELLOW + " left the server.");
  4969. - return true;
  4970. + net.innectis.innplugin.Player.Chat.ChatColor color = net.innectis.innplugin.Player.Chat.ChatColor.YELLOW;
  4971. +
  4972. + String playerName = args[0];
  4973. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  4974. +
  4975. + // Modify group color by this player's group
  4976. + if (credentials != null) {
  4977. + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(credentials.getUniqueId());
  4978. + color = group.getPrefix().getTextColor();
  4979. }
  4980.  
  4981. - return false;
  4982. +
  4983. + parent.broadCastMessage(color + playerName + " left the server.");
  4984. + return true;
  4985. }
  4986.  
  4987. @CommandMethod(aliases = {"sresetnames"},
  4988. @@ -115,9 +134,12 @@ public final class SpoofCommands {
  4989. if (target != null) {
  4990. name = target.getName();
  4991. }
  4992. - group = PlayerGroup.getGroupOfUsername(name);
  4993.  
  4994. - if (group == PlayerGroup.NONE) {
  4995. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(name);
  4996. +
  4997. + if (credentials != null) {
  4998. + group = PlayerGroup.getGroupOfPlayerById(credentials.getUniqueId());
  4999. + } else {
  5000. group = PlayerGroup.GUEST;
  5001. }
  5002.  
  5003. @@ -141,9 +163,11 @@ public final class SpoofCommands {
  5004. return true;
  5005. }
  5006.  
  5007. - group = PlayerGroup.getGroupOfUsername(name);
  5008. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(name);
  5009.  
  5010. - if (group == PlayerGroup.NONE) {
  5011. + if (credentials != null) {
  5012. + group = PlayerGroup.getGroupOfPlayerById(credentials.getUniqueId());
  5013. + } else {
  5014. group = PlayerGroup.GUEST;
  5015. }
  5016.  
  5017. diff --git a/src/net/innectis/innplugin/Configuration.java b/src/net/innectis/innplugin/Configuration.java
  5018. index 4cfbe8e5f..6408e882a 100644
  5019. --- a/src/net/innectis/innplugin/Configuration.java
  5020. +++ b/src/net/innectis/innplugin/Configuration.java
  5021. @@ -3,9 +3,11 @@ package net.innectis.innplugin;
  5022. import java.io.FileNotFoundException;
  5023. import java.util.HashSet;
  5024. import java.util.List;
  5025. +import java.util.UUID;
  5026. import net.innectis.innplugin.Handlers.Datasource.FileHandler;
  5027. import net.innectis.innplugin.Player.Chat.ChatColor;
  5028. import net.innectis.innplugin.Player.Infractions.InfractionIntensity;
  5029. +import net.innectis.innplugin.Player.PlayerCredentials;
  5030.  
  5031. /**
  5032. * @author Hretsam
  5033. @@ -32,7 +34,7 @@ public final class Configuration {
  5034. /** Mysql username */
  5035. public static final String MYSQL_USERNAME = "craft";
  5036. /** Database version this plugin uses (live: 158) */
  5037. - public static final int DATABASE_VERSION = 159;
  5038. + public static final int DATABASE_VERSION = 160;
  5039. /** Tells the plugin if the server is live or test */
  5040. public static boolean PRODUCTION_SERVER = false;
  5041. /** Indicates if the server is in maintenance mode **/
  5042. @@ -199,6 +201,23 @@ public final class Configuration {
  5043.  
  5044. // </editor-fold>
  5045. //
  5046. + //<editor-fold defaultstate="collapsed" desc="Fake Player IDs">
  5047. + // These represent UUIDs of special names that do not represent actual players
  5048. + public static final UUID EVERYONE_IDENTIFIER = UUID.nameUUIDFromBytes("%".getBytes());
  5049. + public static final UUID LOT_ASSIGNABLE_IDENTIFIER = UUID.nameUUIDFromBytes("#".getBytes());
  5050. + public static final UUID LOT_ACCESS_IDENTIFIER = UUID.nameUUIDFromBytes("@".getBytes());
  5051. + public static final UUID SERVER_GENERATED_IDENTIFIER = UUID.nameUUIDFromBytes("[SERVER]".getBytes());
  5052. + public static final UUID OTHER_IDENTIFIER = UUID.nameUUIDFromBytes("~".getBytes());
  5053. +
  5054. + // These represent credentials of special names that do not represent actual players
  5055. + public static final PlayerCredentials EVERYONE_CREDENTIALS = new PlayerCredentials(EVERYONE_IDENTIFIER, "%", false);
  5056. + public static final PlayerCredentials LOT_ASSIGNABLE_CREDENTIALS = new PlayerCredentials(LOT_ASSIGNABLE_IDENTIFIER, "#", false);
  5057. + public static final PlayerCredentials LOT_ACCESS_CREDENTIALS = new PlayerCredentials(LOT_ACCESS_IDENTIFIER, "@", false);
  5058. + public static final PlayerCredentials SERVER_GENERATED_CREDENTIALS = new PlayerCredentials(SERVER_GENERATED_IDENTIFIER, "[SERVER]", false);
  5059. + public static final PlayerCredentials OTHER_CREDENTIALS = new PlayerCredentials(OTHER_IDENTIFIER, "~", false);
  5060. +
  5061. + //</editor-fold>
  5062. +
  5063. private Configuration() {
  5064. }
  5065. }
  5066. diff --git a/src/net/innectis/innplugin/Economy/DroppedValutaOrbStore.java b/src/net/innectis/innplugin/Economy/DroppedValutaOrbStore.java
  5067. index 9fa4e2a79..1d342dc95 100644
  5068. --- a/src/net/innectis/innplugin/Economy/DroppedValutaOrbStore.java
  5069. +++ b/src/net/innectis/innplugin/Economy/DroppedValutaOrbStore.java
  5070. @@ -17,7 +17,6 @@ public class DroppedValutaOrbStore {
  5071.  
  5072. /**
  5073. * Adds a new dropped valuta orb class associated by its ID
  5074. - * @param uniqueId
  5075. * @param vorb
  5076. */
  5077. public static void addDroppedValutaOrb(DroppedValutaOrb vorb) {
  5078. diff --git a/src/net/innectis/innplugin/External/API/VotifierIDP.java b/src/net/innectis/innplugin/External/API/VotifierIDP.java
  5079. index d27b8c1e3..8ff14ff14 100644
  5080. --- a/src/net/innectis/innplugin/External/API/VotifierIDP.java
  5081. +++ b/src/net/innectis/innplugin/External/API/VotifierIDP.java
  5082. @@ -9,6 +9,7 @@ import java.sql.ResultSet;
  5083. import java.sql.SQLException;
  5084. import java.sql.Timestamp;
  5085. import java.util.List;
  5086. +import java.util.UUID;
  5087. import net.innectis.innplugin.Configuration;
  5088. import net.innectis.innplugin.External.API.Interfaces.IVotifierIDP;
  5089. import net.innectis.innplugin.External.LibraryInitalizationError;
  5090. @@ -18,6 +19,8 @@ import net.innectis.innplugin.Handlers.TransactionHandler;
  5091. import net.innectis.innplugin.InnPlugin;
  5092. import net.innectis.innplugin.Player.Chat.ChatColor;
  5093. import net.innectis.innplugin.Player.IdpPlayer;
  5094. +import net.innectis.innplugin.Player.PlayerCredentials;
  5095. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  5096. import net.innectis.innplugin.Player.PlayerGroup;
  5097. import org.bukkit.plugin.Plugin;
  5098.  
  5099. @@ -65,6 +68,13 @@ public class VotifierIDP implements VoteListener, IVotifierIDP {
  5100. return;
  5101. }
  5102.  
  5103. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(name);
  5104. +
  5105. + // Don't allow non-existant players to vote
  5106. + if (credentials == null) {
  5107. + return;
  5108. + }
  5109. +
  5110. // Check if service is valid
  5111. if (!isValidService(vote)) {
  5112. InnPlugin.logError("Unauthorized vote server \"" + vote.getServiceName() + "\" tried to send a vote!");
  5113. @@ -75,8 +85,8 @@ public class VotifierIDP implements VoteListener, IVotifierIDP {
  5114. ResultSet result = null;
  5115.  
  5116. try {
  5117. - statement = DBManager.prepareStatement("SELECT timestamp FROM vote_log WHERE username = ? AND service = ?");
  5118. - statement.setString(1, name);
  5119. + statement = DBManager.prepareStatement("SELECT timestamp FROM vote_log WHERE player_id = ? AND service = ?");
  5120. + statement.setString(1, credentials.getUniqueId().toString());
  5121. statement.setString(2, vote.getServiceName());
  5122. result = statement.executeQuery();
  5123.  
  5124. @@ -98,10 +108,10 @@ public class VotifierIDP implements VoteListener, IVotifierIDP {
  5125.  
  5126. return;
  5127. } else {
  5128. - addPlayerVote(vote, true);
  5129. + addPlayerVote(credentials.getUniqueId(), vote, true);
  5130. }
  5131. } else {
  5132. - addPlayerVote(vote, false);
  5133. + addPlayerVote(credentials.getUniqueId(), vote, false);
  5134. }
  5135. } catch (SQLException ex) {
  5136. InnPlugin.logError("SQLException VotifierListener::voteMade(1) - ", ex.getMessage());
  5137. @@ -117,7 +127,7 @@ public class VotifierIDP implements VoteListener, IVotifierIDP {
  5138. }
  5139.  
  5140. InnPlugin.logInfo("Vote received from \"" + vote.getServiceName() + "\" by voter " + name + "(" + vote.getAddress() + ")");
  5141. - TransactionHandler.getTransactionObject(name).addValue(1, TransactionHandler.TransactionType.VOTE_POINTS);
  5142. + TransactionHandler.getTransactionObject(credentials.getUniqueId(), credentials.getName()).addValue(1, TransactionHandler.TransactionType.VOTE_POINTS);
  5143.  
  5144. if (player != null && player.isOnline()) {
  5145. player.printInfo("You have been credited 1 vote point!");
  5146. @@ -128,7 +138,7 @@ public class VotifierIDP implements VoteListener, IVotifierIDP {
  5147. if (player != null) {
  5148. nameColor = player.getGroup().getPrefix().getTextColor().toString();
  5149. } else {
  5150. - nameColor = PlayerGroup.getGroupOfUsername(name).getPrefix().getTextColor().toString();
  5151. + nameColor = PlayerGroup.getGroupOfPlayerById(credentials.getUniqueId()).getPrefix().getTextColor().toString();
  5152. }
  5153.  
  5154. String service = vote.getServiceName();
  5155. @@ -143,19 +153,19 @@ public class VotifierIDP implements VoteListener, IVotifierIDP {
  5156. plugin.broadCastMessage(ChatColor.GREEN, "Thank you for your support!");
  5157. }
  5158.  
  5159. - private static void addPlayerVote(Vote vote, boolean update) {
  5160. + private static void addPlayerVote(UUID playerId, Vote vote, boolean update) {
  5161. PreparedStatement statement = null;
  5162.  
  5163. try {
  5164. if (update) {
  5165. - statement = DBManager.prepareStatement("UPDATE vote_log SET timestamp = ? WHERE username = ? AND service = ?");
  5166. + statement = DBManager.prepareStatement("UPDATE vote_log SET timestamp = ? WHERE player_id = ? AND service = ?");
  5167. statement.setTimestamp(1, new Timestamp(System.currentTimeMillis()));
  5168. - statement.setString(2, vote.getUsername().trim());
  5169. + statement.setString(2, playerId.toString());
  5170. statement.setString(3, vote.getServiceName());
  5171. statement.executeUpdate();
  5172. } else {
  5173. - statement = DBManager.prepareStatement("INSERT INTO vote_log (username, ip, service, timestamp) VALUES (?, ?, ?, ?)");
  5174. - statement.setString(1, vote.getUsername().trim());
  5175. + statement = DBManager.prepareStatement("INSERT INTO vote_log (player_id, ip, service, timestamp) VALUES (?, ?, ?, ?)");
  5176. + statement.setString(1, playerId.toString());
  5177. statement.setString(2, vote.getAddress());
  5178. statement.setString(3, vote.getServiceName());
  5179. statement.setTimestamp(4, new Timestamp(System.currentTimeMillis()));
  5180. diff --git a/src/net/innectis/innplugin/External/DynmapIDP.java b/src/net/innectis/innplugin/External/DynmapIDP.java
  5181. index 2d327ccf6..9683b6bc3 100644
  5182. --- a/src/net/innectis/innplugin/External/DynmapIDP.java
  5183. +++ b/src/net/innectis/innplugin/External/DynmapIDP.java
  5184. @@ -55,7 +55,7 @@ public class DynmapIDP {
  5185.  
  5186. set.setLayerPriority(15);
  5187. set.setHideByDefault(false);
  5188. -
  5189. +
  5190. // Add the task
  5191. plugin.getTaskManager().addTask(new DynmapUpdateTask(this));
  5192. return true;
  5193. @@ -99,7 +99,7 @@ public class DynmapIDP {
  5194. z[2] = lot.getHighestZ();
  5195. z[3] = lot.getLowestZ() + 1;
  5196.  
  5197. - String ownercolor = PlayerGroup.getGroupOfUsername(lot.getOwner()).getPrefix().getTextColor().getHTMLColor();
  5198. + String ownercolor = PlayerGroup.getGroupOfPlayerById(lot.getOwnerCredentials().getUniqueId()).getPrefix().getTextColor().getHTMLColor();
  5199. String desc = formatInfoWindow(lot, ownercolor);
  5200. String markerid = "lot_" + lot.getId();
  5201. AreaMarker m = resareas.remove(markerid); /* Existing area? */
  5202. diff --git a/src/net/innectis/innplugin/GameSystem/Gamemodes/IdpCTF.java b/src/net/innectis/innplugin/GameSystem/Gamemodes/IdpCTF.java
  5203. index accb5b416..ec409cd09 100644
  5204. --- a/src/net/innectis/innplugin/GameSystem/Gamemodes/IdpCTF.java
  5205. +++ b/src/net/innectis/innplugin/GameSystem/Gamemodes/IdpCTF.java
  5206. @@ -159,7 +159,7 @@ public class IdpCTF extends IdpRegionGame implements GameTimer {
  5207.  
  5208. gamelot = ((InnectisLot) getRegion()).getParentTop();
  5209.  
  5210. - if (!(gamelot.canPlayerAccess(host) || host.hasPermission(Permission.lot_command_override))) {
  5211. + if (!(gamelot.canPlayerAccess(host.getName()) || host.hasPermission(Permission.lot_command_override))) {
  5212. return new IdpStartResult(false, "You do not have permission to start a game here.");
  5213. }
  5214.  
  5215. diff --git a/src/net/innectis/innplugin/Handlers/BlockHandler.java b/src/net/innectis/innplugin/Handlers/BlockHandler.java
  5216. index 548d9babb..7b9a74e00 100644
  5217. --- a/src/net/innectis/innplugin/Handlers/BlockHandler.java
  5218. +++ b/src/net/innectis/innplugin/Handlers/BlockHandler.java
  5219. @@ -3,11 +3,13 @@ package net.innectis.innplugin.Handlers;
  5220. import java.sql.PreparedStatement;
  5221. import java.sql.ResultSet;
  5222. import java.sql.SQLException;
  5223. +import java.sql.Timestamp;
  5224. import java.util.ArrayList;
  5225. import java.util.HashMap;
  5226. import java.util.List;
  5227. import java.util.Map;
  5228. import java.util.Random;
  5229. +import java.util.UUID;
  5230. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  5231. import net.innectis.innplugin.InnPlugin;
  5232. import net.innectis.innplugin.InnectisObjects.POJO.BlockLog;
  5233. @@ -25,12 +27,16 @@ import net.innectis.innplugin.OwnedObjects.InnectisLot;
  5234. import net.innectis.innplugin.OwnedObjects.LotFlagType;
  5235. import net.innectis.innplugin.Player.IdpPlayer;
  5236. import net.innectis.innplugin.Player.Permission;
  5237. +import net.innectis.innplugin.Player.PlayerCredentials;
  5238. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  5239. import net.innectis.innplugin.Utility.DatabaseTools;
  5240. import net.innectis.innplugin.Utility.LocationUtil;
  5241. import net.innectis.innplugin.Utility.ObjectParseException;
  5242. +import org.bukkit.Bukkit;
  5243. import org.bukkit.Color;
  5244. import org.bukkit.FireworkEffect;
  5245. import org.bukkit.Location;
  5246. +import org.bukkit.World;
  5247. import org.bukkit.block.Block;
  5248. import org.bukkit.block.BlockFace;
  5249. import org.bukkit.block.BlockState;
  5250. @@ -181,7 +187,7 @@ public final class BlockHandler {
  5251. }
  5252. } else {
  5253. // Check if owner, freebuild or member of lot
  5254. - if (lot.canPlayerAccess(player)) {
  5255. + if (lot.canPlayerAccess(player.getName())) {
  5256. return true; //freebuild
  5257. }
  5258.  
  5259. @@ -273,8 +279,8 @@ public final class BlockHandler {
  5260. PreparedStatement statement = null;
  5261.  
  5262. try {
  5263. - statement = DBManager.prepareStatement("INSERT DELAYED INTO block_quota_log (time,username,blockid) VALUES (NOW(),?,?);");
  5264. - statement.setString(1, player.getName());
  5265. + statement = DBManager.prepareStatement("INSERT DELAYED INTO block_quota_log (time, player_id, blockid) VALUES (NOW(),?,?);");
  5266. + statement.setString(1, player.getUniqueId().toString());
  5267. statement.setInt(2, getBlockTypeId(block));
  5268. statement.executeUpdate();
  5269. } catch (SQLException ex) {
  5270. @@ -302,9 +308,9 @@ public final class BlockHandler {
  5271. ResultSet result = null;
  5272.  
  5273. try {
  5274. - statement = DBManager.prepareStatement("SELECT COUNT(*) FROM block_quota_log WHERE time >= DATE_SUB(NOW(), INTERVAL ? SECOND) AND username = ? AND blockid = ?;");
  5275. + statement = DBManager.prepareStatement("SELECT COUNT(*) FROM block_quota_log WHERE time >= DATE_SUB(NOW(), INTERVAL ? SECOND) AND player_id = ? AND blockid = ?;");
  5276. statement.setInt(1, timespan);
  5277. - statement.setString(2, player.getName());
  5278. + statement.setString(2, player.getUniqueId().toString());
  5279. statement.setInt(3, getBlockTypeId(block));
  5280. result = statement.executeQuery();
  5281.  
  5282. @@ -804,7 +810,7 @@ public final class BlockHandler {
  5283.  
  5284. try {
  5285. statement = DBManager.prepareStatement(
  5286. - "SELECT logid, name, locx, locy, locz, world, Id as id, Data as data, DateTime as datetime, ActionType as actiontype "
  5287. + "SELECT logid, player_id, locx, locy, locz, world, Id as id, Data as data, DateTime as datetime, ActionType as actiontype "
  5288. + "FROM block_log "
  5289. + "WHERE locx = ? AND locy = ? AND locz = ? and world = ? "
  5290. + "ORDER BY datetime DESC "
  5291. @@ -816,12 +822,35 @@ public final class BlockHandler {
  5292. statement.setInt(5, (amount.length == 0 ? 10 : amount[0]));
  5293. set = statement.executeQuery();
  5294.  
  5295. - // Return the parsed list
  5296. - return DatabaseTools.parseToObjects(BlockLog.class, set);
  5297. + List<BlockLog> blockLogs = new ArrayList<BlockLog>();
  5298. +
  5299. + while (set.next()) {
  5300. + World world = Bukkit.getWorld(set.getString("world"));
  5301. +
  5302. + if (world != null) {
  5303. + int x = set.getInt("locx");
  5304. + int y = set.getInt("locy");
  5305. + int z = set.getInt("locz");
  5306. +
  5307. + int logid = set.getInt("logid");
  5308. +
  5309. + String playerIdString = set.getString("player_id");
  5310. + UUID playerId = UUID.fromString(playerIdString);
  5311. + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(playerId);
  5312. +
  5313. + int id = set.getInt("id");
  5314. + int data = set.getInt("data");
  5315. +
  5316. + Timestamp dateTime = set.getTimestamp("datetime");
  5317. + int action = set.getInt("actiontype");
  5318. +
  5319. + blockLogs.add(new BlockLog(credentials.getName(), x, y, z, world.getName(), id, data, dateTime, action));
  5320. + }
  5321. + }
  5322. +
  5323. + return blockLogs;
  5324. } catch (SQLException ex) {
  5325. InnPlugin.logError("SQLException when getting chestaccess logs!", ex);
  5326. - } catch (ObjectParseException ex) {
  5327. - InnPlugin.logError("ObjectParseException parsing chestlogs into objects", ex.getInnerException());
  5328. } finally {
  5329. DBManager.closeResultSet(set);
  5330. DBManager.closePreparedStatement(statement);
  5331. diff --git a/src/net/innectis/innplugin/Handlers/BlockLockHandler.java b/src/net/innectis/innplugin/Handlers/BlockLockHandler.java
  5332. index 21fbd0b7e..810ac3c54 100644
  5333. --- a/src/net/innectis/innplugin/Handlers/BlockLockHandler.java
  5334. +++ b/src/net/innectis/innplugin/Handlers/BlockLockHandler.java
  5335. @@ -4,10 +4,12 @@ import java.sql.PreparedStatement;
  5336. import java.sql.ResultSet;
  5337. import java.sql.SQLException;
  5338. import java.util.HashMap;
  5339. +import java.util.UUID;
  5340. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  5341. import net.innectis.innplugin.InnPlugin;
  5342. import net.innectis.innplugin.Player.Chat.ChatColor;
  5343. -import net.innectis.innplugin.Player.IdpPlayer;
  5344. +import net.innectis.innplugin.Player.PlayerCredentials;
  5345. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  5346. import org.bukkit.Bukkit;
  5347. import org.bukkit.Location;
  5348. import org.bukkit.World;
  5349. @@ -19,9 +21,9 @@ import org.bukkit.World;
  5350. */
  5351. public final class BlockLockHandler {
  5352.  
  5353. - private static HashMap<String, String> _lockedBlocks = new HashMap<String, String>();
  5354. + private static HashMap<String, UUID> _lockedBlocks = new HashMap<String, UUID>();
  5355.  
  5356. - public static synchronized HashMap<String, String> getLockedBlocks() {
  5357. + public static synchronized HashMap<String, UUID> getLockedBlocks() {
  5358. return _lockedBlocks;
  5359. }
  5360.  
  5361. @@ -36,7 +38,7 @@ public final class BlockLockHandler {
  5362. ResultSet result = null;
  5363.  
  5364. try {
  5365. - statement = DBManager.prepareStatement("SELECT username, world, locx, locy, locz FROM block_locks;");
  5366. + statement = DBManager.prepareStatement("SELECT player_id, world, locx, locy, locz FROM block_locks;");
  5367. result = statement.executeQuery();
  5368. getLockedBlocks().clear();
  5369.  
  5370. @@ -44,10 +46,13 @@ public final class BlockLockHandler {
  5371. World world = Bukkit.getWorld(result.getString("world"));
  5372.  
  5373. if (world != null) {
  5374. + String playerIdString = result.getString("player_id");
  5375. + UUID playerId = UUID.fromString(playerIdString);
  5376. +
  5377. getLockedBlocks().put(world.getName() + " "
  5378. + result.getInt("locx") + " "
  5379. + result.getInt("locy") + " "
  5380. - + result.getInt("locz"), result.getString("username"));
  5381. + + result.getInt("locz"), playerId);
  5382. }
  5383. }
  5384. } catch (SQLException ex) {
  5385. @@ -76,36 +81,36 @@ public final class BlockLockHandler {
  5386. public static String getBlockLockerName(Location location) {
  5387. String key = getKey(location);
  5388. if (getLockedBlocks().containsKey(key)) {
  5389. - return getLockedBlocks().get(key);
  5390. + UUID playerId = getLockedBlocks().get(key);
  5391. + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(playerId);
  5392. + return credentials.getName();
  5393. }
  5394. +
  5395. return null;
  5396. }
  5397.  
  5398. /**
  5399. * Locks the given block.
  5400. - * @param player
  5401. + * @param playerId
  5402. * @param location - the location of the block
  5403. * @return true if succeed
  5404. - * @throws SQLException
  5405. */
  5406. - public static boolean lockBlock(IdpPlayer player, Location location) {
  5407. - String playerName = player.getName();
  5408. + public static boolean lockBlock(UUID playerId, Location location) {
  5409. PreparedStatement statement = null;
  5410. + String key = getKey(location);
  5411.  
  5412. try {
  5413. - String key = getKey(location);
  5414. -
  5415. - statement = DBManager.prepareStatement("INSERT INTO block_locks (username, world, locx, locy, locz) VALUES (?, ?, ?, ?, ?);");
  5416. - statement.setString(1, playerName.toLowerCase());
  5417. + statement = DBManager.prepareStatement("INSERT INTO block_locks (player_id, world, locx, locy, locz) VALUES (?, ?, ?, ?, ?);");
  5418. + statement.setString(1, playerId.toString());
  5419. statement.setString(2, location.getWorld().getName());
  5420. statement.setInt(3, location.getBlockX());
  5421. statement.setInt(4, location.getBlockY());
  5422. statement.setInt(5, location.getBlockZ());
  5423. statement.executeUpdate();
  5424.  
  5425. - getLockedBlocks().put(key, playerName.toLowerCase());
  5426. + getLockedBlocks().put(key, playerId);
  5427. } catch (SQLException ex) {
  5428. - InnPlugin.logError("Could not lock block!", ex);
  5429. + InnPlugin.logError("Could not lock block! (location: " + key + ")", ex);
  5430. return false;
  5431. } finally {
  5432. DBManager.closePreparedStatement(statement);
  5433. diff --git a/src/net/innectis/innplugin/Handlers/CTFHandler.java b/src/net/innectis/innplugin/Handlers/CTFHandler.java
  5434. index ce9846e16..2ad03cd48 100644
  5435. --- a/src/net/innectis/innplugin/Handlers/CTFHandler.java
  5436. +++ b/src/net/innectis/innplugin/Handlers/CTFHandler.java
  5437. @@ -11,6 +11,8 @@ import net.innectis.innplugin.Location.IdpWorldRegion;
  5438. import net.innectis.innplugin.OwnedObjects.Handlers.LotHandler;
  5439. import net.innectis.innplugin.OwnedObjects.InnectisLot;
  5440. import net.innectis.innplugin.Player.IdpPlayer;
  5441. +import net.innectis.innplugin.Player.PlayerCredentials;
  5442. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  5443. import net.innectis.innplugin.Player.TinyWE.BlockCounters.BlockCounter;
  5444. import net.innectis.innplugin.Player.TinyWE.BlockCounters.BlockCounterFactory;
  5445. import org.bukkit.Location;
  5446. @@ -205,7 +207,8 @@ public final class CTFHandler {
  5447. region.setPos2(region.getPos2().setY(255));
  5448.  
  5449. try {
  5450. - InnectisLot lot = LotHandler.addLot(player.getLocation().getWorld(), region.getPos1(), region.getPos2(), player.getName(), player.getName());
  5451. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName(), true);
  5452. + InnectisLot lot = LotHandler.addLot(player.getLocation().getWorld(), region.getPos1(), region.getPos2(), credentials, credentials);
  5453. lot.setLotName(baseName);
  5454. lot.save();
  5455. } catch (SQLException ex) {
  5456. @@ -240,7 +243,8 @@ public final class CTFHandler {
  5457. String flagPositionName = (isRedFlag ? "RedFlag" : "BlueFlag");
  5458.  
  5459. try {
  5460. - InnectisLot lot = LotHandler.addLot(player.getLocation().getWorld(), vector, vector, player.getName(), player.getName());
  5461. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName(), true);
  5462. + InnectisLot lot = LotHandler.addLot(player.getLocation().getWorld(), vector, vector, credentials, credentials);
  5463. lot.setLotName(flagPositionName);
  5464. lot.save();
  5465. } catch (SQLException ex) {
  5466. diff --git a/src/net/innectis/innplugin/Handlers/Iplogging/Playerinfo.java b/src/net/innectis/innplugin/Handlers/Iplogging/Playerinfo.java
  5467. index d876a6c75..ac985560b 100644
  5468. --- a/src/net/innectis/innplugin/Handlers/Iplogging/Playerinfo.java
  5469. +++ b/src/net/innectis/innplugin/Handlers/Iplogging/Playerinfo.java
  5470. @@ -8,6 +8,7 @@ import java.util.Collections;
  5471. import java.util.HashSet;
  5472. import java.util.List;
  5473. import java.util.Set;
  5474. +import java.util.UUID;
  5475. import java.util.logging.Level;
  5476. import java.util.logging.Logger;
  5477. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  5478. @@ -19,30 +20,31 @@ import org.apache.commons.lang.NotImplementedException;
  5479. * @author Hretsam
  5480. *
  5481. * This class contains some information about the player and its IP address.
  5482. - * Also the accounts that are linked to this one (used same IP) can be found here.x
  5483. + * Also the accounts that are linked to this one (used same IP) can be found here.
  5484. */
  5485. public final class Playerinfo {
  5486. -
  5487. - private final String username;
  5488. - private HashSet<IPAddress> ipadresses;
  5489. + private final UUID playerId;
  5490. + private final String playerName;
  5491. + private HashSet<IPAddress> ipadresses = new HashSet<IPAddress>();
  5492.  
  5493. // <editor-fold defaultstate="collapsed" desc="Contructors">
  5494. - private Playerinfo(String username) {
  5495. - this.username = username;
  5496. + private Playerinfo(UUID playerId, String playerName) {
  5497. + this(playerId, playerName, null);
  5498. }
  5499.  
  5500. - private Playerinfo(String username, HashSet<IPAddress> ipadresses) {
  5501. - this.username = username;
  5502. + private Playerinfo(UUID playerId, String playerName, HashSet<IPAddress> ipadresses) {
  5503. + this.playerId = playerId;
  5504. + this.playerName = playerName;
  5505. this.ipadresses = ipadresses;
  5506. }
  5507.  
  5508. // </editor-fold>
  5509. /**
  5510. - * Returns the name of the user of this object.
  5511. + * Returns the ID of this player
  5512. * @return
  5513. */
  5514. - public String getUsername() {
  5515. - return username;
  5516. + public UUID getUniqueId() {
  5517. + return playerId;
  5518. }
  5519.  
  5520. /**
  5521. @@ -97,15 +99,15 @@ public final class Playerinfo {
  5522. ResultSet result = null;
  5523.  
  5524. try {
  5525. - statement = DBManager.prepareStatement("SELECT DISTINCT `name` FROM ip_log WHERE ip IN (SELECT distinct ip FROM ip_log WHERE name = ?);");
  5526. - statement.setString(1, username);
  5527. + statement = DBManager.prepareStatement("SELECT DISTINCT `name` FROM ip_log WHERE ip IN (SELECT distinct ip FROM ip_log WHERE player_id = ?);");
  5528. + statement.setString(1, playerId.toString());
  5529. result = statement.executeQuery();
  5530.  
  5531. while (result.next()) {
  5532. playernames.add(result.getString("name"));
  5533. }
  5534. } catch (SQLException ex) {
  5535. - InnPlugin.logError("Cannot find related usernames for " + username + "!", ex);
  5536. + InnPlugin.logError("Cannot find related usernames for player " + playerName + "!", ex);
  5537. return null;
  5538. } finally {
  5539. DBManager.closeResultSet(result);
  5540. @@ -114,41 +116,23 @@ public final class Playerinfo {
  5541.  
  5542. return playernames;
  5543. }
  5544. -
  5545. - /**
  5546. - * Does the same as Playerinfo::findRelatedUsernames().
  5547. - * The only difference is that this method returns the playerinfo objects.
  5548. - * @return List of playerinfo objects of the players that are linked
  5549. - * @throws SQLException
  5550. - */
  5551. - public List<Playerinfo> findRelatedPlayers() throws SQLException {
  5552. - List<String> players = findRelatedUsernames();
  5553. - ArrayList<Playerinfo> playerInfoList = new ArrayList<Playerinfo>(players.size());
  5554. -
  5555. - for (String name : players) {
  5556. - // If the player is in the findRelatedUsernames list then it must have an entry in the DB.
  5557. - playerInfoList.add(Playerinfo.findPlayer(name));
  5558. - }
  5559. - return playerInfoList;
  5560. - }
  5561. -
  5562. // </editor-fold>
  5563. // <editor-fold defaultstate="collapsed" desc="Static methods">
  5564. /**
  5565. * Looks for the playerinformation in the database.<br/>
  5566. * If no data is found, null will be returned
  5567. *
  5568. - * @param username
  5569. + * @param playerId
  5570. * @return The info of the player or null if player not found or no IP-addresses;
  5571. */
  5572. - public static Playerinfo findPlayer(String username) {
  5573. + public static Playerinfo findPlayer(UUID playerId, String playerName) {
  5574. PreparedStatement statement = null;
  5575. ResultSet result = null;
  5576.  
  5577. try {
  5578. // Get the addresses of the player.
  5579. - statement = DBManager.prepareStatement("SELECT DISTINCT ip FROM `ip_log` where `name` = ?;");
  5580. - statement.setString(1, username);
  5581. + statement = DBManager.prepareStatement("SELECT DISTINCT ip FROM `ip_log` where `player_id` = ?;");
  5582. + statement.setString(1, playerId.toString());
  5583. result = statement.executeQuery();
  5584. HashSet<IPAddress> addresses = new HashSet<IPAddress>();
  5585.  
  5586. @@ -157,7 +141,7 @@ public final class Playerinfo {
  5587. }
  5588.  
  5589. // return the object
  5590. - return new Playerinfo(username, addresses);
  5591. + return new Playerinfo(playerId, playerName, addresses);
  5592. } catch (SQLException ex) {
  5593. Logger.getLogger(Playerinfo.class.getName()).log(Level.SEVERE, null, ex);
  5594. } finally {
  5595. diff --git a/src/net/innectis/innplugin/Handlers/LightsourceHandler.java b/src/net/innectis/innplugin/Handlers/LightsourceHandler.java
  5596. index a6841856d..60baa3961 100644
  5597. --- a/src/net/innectis/innplugin/Handlers/LightsourceHandler.java
  5598. +++ b/src/net/innectis/innplugin/Handlers/LightsourceHandler.java
  5599. @@ -2,6 +2,7 @@ package net.innectis.innplugin.Handlers;
  5600.  
  5601. import java.util.HashMap;
  5602. import java.util.Map;
  5603. +import java.util.UUID;
  5604. import net.innectis.innplugin.InnPlugin;
  5605. import net.innectis.innplugin.Items.IdpMaterial;
  5606. import net.innectis.innplugin.Player.IdpPlayer;
  5607. @@ -16,17 +17,17 @@ import org.bukkit.craftbukkit.v1_7_R2.CraftWorld;
  5608. * @author AlphaBlend
  5609. */
  5610. public class LightsourceHandler {
  5611. - private static Map<String, Location> litLocations = new HashMap<String, Location>();
  5612. + private static Map<UUID, Location> litLocations = new HashMap<UUID, Location>();
  5613.  
  5614. /**
  5615. * Light up the specified location
  5616. - * @param player
  5617. + * @param playerId
  5618. * @param location
  5619. */
  5620. - public static void lightBlock(String player, Location location) {
  5621. + public static void lightBlock(UUID playerId, Location location) {
  5622. // Check if the location is not already being lit up
  5623. if (canLightUp(location) && !isLit(location)) {
  5624. - Location previous = litLocations.get(player.toLowerCase());
  5625. + Location previous = litLocations.get(playerId);
  5626.  
  5627. // If the previous block was lit up, notify everyone of the original block
  5628. if (previous != null) {
  5629. @@ -42,16 +43,16 @@ public class LightsourceHandler {
  5630. p.getHandle().sendBlockChange(location, Material.GLOWSTONE, (byte) 0);
  5631. }
  5632.  
  5633. - litLocations.put(player.toLowerCase(), location);
  5634. + litLocations.put(playerId, location);
  5635. }
  5636. }
  5637.  
  5638. /**
  5639. * Makes the specified location unlit
  5640. - * @param player
  5641. + * @param playerId
  5642. */
  5643. - public static void unlightBlock(String player) {
  5644. - Location litLocation = litLocations.get(player.toLowerCase());
  5645. + public static void unlightBlock(UUID playerId) {
  5646. + Location litLocation = litLocations.get(playerId);
  5647.  
  5648. if (litLocation != null) {
  5649. int x = litLocation.getBlockX();
  5650. @@ -59,7 +60,7 @@ public class LightsourceHandler {
  5651. int z = litLocation.getBlockZ();
  5652. World world = ((CraftWorld) litLocation.getWorld()).getHandle();
  5653. world.notify(x, y, z);
  5654. - litLocations.remove(player.toLowerCase());
  5655. + litLocations.remove(playerId);
  5656. }
  5657. }
  5658.  
  5659. @@ -79,16 +80,16 @@ public class LightsourceHandler {
  5660. }
  5661.  
  5662. /**
  5663. - * Gets a player by the location they are lighting up
  5664. + * Gets a player's ID by the location they are lighting up
  5665. * @param location
  5666. * @return
  5667. */
  5668. - public static String getPlayerNameFromLocation(Location location) {
  5669. - for (String player : litLocations.keySet()) {
  5670. - Location loc = litLocations.get(player.toLowerCase());
  5671. + public static UUID getPlayerIdFromLocation(Location location) {
  5672. + for (UUID playerId : litLocations.keySet()) {
  5673. + Location loc = litLocations.get(playerId);
  5674.  
  5675. if (loc.equals(location)) {
  5676. - return player;
  5677. + return playerId;
  5678. }
  5679. }
  5680.  
  5681. @@ -97,11 +98,11 @@ public class LightsourceHandler {
  5682.  
  5683. /**
  5684. * Determines if the player is lighting up a block
  5685. - * @param player
  5686. + * @param playerId
  5687. * @return
  5688. */
  5689. - public static boolean isLightingBlock(String player) {
  5690. - return litLocations.containsKey(player.toLowerCase());
  5691. + public static boolean isLightingBlock(UUID playerId) {
  5692. + return litLocations.containsKey(playerId);
  5693. }
  5694.  
  5695. /**
  5696. diff --git a/src/net/innectis/innplugin/Handlers/MemberGroupHandler.java b/src/net/innectis/innplugin/Handlers/MemberGroupHandler.java
  5697. index 879939e14..5cbee3e2f 100644
  5698. --- a/src/net/innectis/innplugin/Handlers/MemberGroupHandler.java
  5699. +++ b/src/net/innectis/innplugin/Handlers/MemberGroupHandler.java
  5700. @@ -7,9 +7,12 @@ import java.util.ArrayList;
  5701. import java.util.HashMap;
  5702. import java.util.List;
  5703. import java.util.Map.Entry;
  5704. +import java.util.UUID;
  5705. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  5706. import net.innectis.innplugin.InnPlugin;
  5707. import net.innectis.innplugin.InnectisObjects.MemberGroup;
  5708. +import net.innectis.innplugin.Player.PlayerCredentials;
  5709. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  5710.  
  5711. /**
  5712. *
  5713. @@ -31,25 +34,31 @@ public final class MemberGroupHandler {
  5714. ResultSet result2 = null;
  5715.  
  5716. try {
  5717. - statement = DBManager.prepareStatement("SELECT groupid, username, groupname FROM member_groups;");
  5718. + statement = DBManager.prepareStatement("SELECT groupid, player_id, groupname FROM member_groups;");
  5719. result = statement.executeQuery();
  5720. - MemberGroup group;
  5721. - int groupId;
  5722.  
  5723. while (result.next()) {
  5724. - group = new MemberGroup(result.getInt("groupid"), result.getString("username"), result.getString("groupname"));
  5725. - groupId = result.getInt("groupid");
  5726. + String playerIdString = result.getString("player_id");
  5727. + UUID playerId = UUID.fromString(playerIdString);
  5728. + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(playerId, true);
  5729.  
  5730. - statement2 = DBManager.prepareStatement("SELECT username FROM member_users WHERE groupid=?;");
  5731. + int groupId = result.getInt("groupid");
  5732. + String groupName = result.getString("groupname");
  5733. + MemberGroup group = new MemberGroup(groupId, credentials, groupName);
  5734. +
  5735. + statement2 = DBManager.prepareStatement("SELECT player_id FROM member_users WHERE groupid = ?;");
  5736. statement2.setInt(1, groupId);
  5737. result2 = statement2.executeQuery();
  5738.  
  5739. while (result2.next()) {
  5740. - group.addMember(result2.getString("username"));
  5741. + String memberPlayerIdString = result.getString("player_id");
  5742. + UUID memberPlayerId = UUID.fromString(memberPlayerIdString);
  5743. + PlayerCredentials memberCredentials = PlayerCredentialsManager.getByUniqueId(memberPlayerId, true);
  5744. + group.addMember(memberCredentials);
  5745. }
  5746. group.setUpdated(false); //just loaded it from db, so nothing has changed
  5747.  
  5748. - getGroups().put(getKey(group.getOwner(), group.getName()), group);
  5749. + getGroups().put(getKey(group.getOwnerCredentials().getUniqueId(), group.getName()), group);
  5750. }
  5751. } catch (SQLException ex) {
  5752. InnPlugin.logError("COULD NOT GET MEMBER GROUPS FROM DATABASE!", ex);
  5753. @@ -64,20 +73,20 @@ public final class MemberGroupHandler {
  5754. return true;
  5755. }
  5756.  
  5757. - private static String getKey(String owner, String groupName) {
  5758. - return owner.toLowerCase() + ' ' + groupName.toLowerCase();
  5759. + private static String getKey(UUID ownerId, String groupName) {
  5760. + return ownerId.toString() + ' ' + groupName.toLowerCase();
  5761. }
  5762.  
  5763. - public static boolean isGroup(String owner, String groupName) {
  5764. - return getGroups().containsKey(getKey(owner, groupName));
  5765. + public static boolean isGroup(UUID ownerId, String groupName) {
  5766. + return getGroups().containsKey(getKey(ownerId, groupName));
  5767. }
  5768.  
  5769. - public static List<MemberGroup> getGroups(String owner) {
  5770. - ArrayList<MemberGroup> groups = new ArrayList<MemberGroup>();
  5771. - String name;
  5772. + public static List<MemberGroup> getGroups(UUID ownerId) {
  5773. + List<MemberGroup> groups = new ArrayList<MemberGroup>();
  5774. +
  5775. for (Entry<String, MemberGroup> ent : getGroups().entrySet()) {
  5776. - name = ent.getKey().split(" ")[0];
  5777. - if (name.equalsIgnoreCase(owner)) {
  5778. + String ownerIdString = ent.getKey().split(" ")[0];
  5779. + if (ownerIdString.equals(ownerId.toString())) {
  5780. groups.add(ent.getValue());
  5781. }
  5782. }
  5783. @@ -87,27 +96,27 @@ public final class MemberGroupHandler {
  5784. return groups;
  5785. }
  5786.  
  5787. - public static MemberGroup getGroup(String owner, String groupName) {
  5788. - return getGroups().get(getKey(owner, groupName));
  5789. + public static MemberGroup getGroup(UUID ownerId, String groupName) {
  5790. + return getGroups().get(getKey(ownerId, groupName));
  5791. }
  5792.  
  5793. - public static boolean addGroup(String owner, String groupName) {
  5794. - MemberGroup group = new MemberGroup(-1, owner, groupName);
  5795. + public static boolean addGroup(PlayerCredentials credentials, String groupName) {
  5796. + MemberGroup group = new MemberGroup(-1, credentials, groupName);
  5797.  
  5798. if (group.save()) {
  5799. - getGroups().put(getKey(owner, groupName), group);
  5800. + getGroups().put(getKey(credentials.getUniqueId(), groupName), group);
  5801. return true;
  5802. } else {
  5803. return false;
  5804. }
  5805. }
  5806.  
  5807. - public static boolean removeGroup(String owner, String groupName) {
  5808. + public static boolean removeGroup(UUID ownerId, String groupName) {
  5809. PreparedStatement statement = null;
  5810.  
  5811. try {
  5812. - MemberGroup group = getGroup(owner, groupName);
  5813. -
  5814. + MemberGroup group = getGroup(ownerId, groupName);
  5815. +
  5816. statement = DBManager.prepareStatement("DELETE FROM member_users WHERE groupid=?;");
  5817. statement.setInt(1, group.getId());
  5818. statement.executeUpdate();
  5819. diff --git a/src/net/innectis/innplugin/Handlers/ModifiablePermissionsHandler.java b/src/net/innectis/innplugin/Handlers/ModifiablePermissionsHandler.java
  5820. index fc0d976ab..e16252e37 100644
  5821. --- a/src/net/innectis/innplugin/Handlers/ModifiablePermissionsHandler.java
  5822. +++ b/src/net/innectis/innplugin/Handlers/ModifiablePermissionsHandler.java
  5823. @@ -6,10 +6,13 @@ import java.sql.SQLException;
  5824. import java.util.ArrayList;
  5825. import java.util.HashMap;
  5826. import java.util.List;
  5827. +import java.util.UUID;
  5828. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  5829. import net.innectis.innplugin.InnPlugin;
  5830. import net.innectis.innplugin.InnectisObjects.ModifiablePermissions;
  5831. import net.innectis.innplugin.Player.Permission;
  5832. +import net.innectis.innplugin.Player.PlayerCredentials;
  5833. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  5834.  
  5835. /**
  5836. * This handles the modifiable permissions of players.
  5837. @@ -75,18 +78,19 @@ public final class ModifiablePermissionsHandler {
  5838.  
  5839. /**
  5840. * Loads the modifiable permissions from database for specified username
  5841. - * @param username
  5842. + * @param playerId
  5843. * @return
  5844. */
  5845. - public static ModifiablePermissions loadModifiedPermissions(String username) {
  5846. - ModifiablePermissions perms = new ModifiablePermissions(username);
  5847. + public static ModifiablePermissions loadModifiedPermissions(UUID playerId) {
  5848. + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(playerId, true);
  5849. + ModifiablePermissions perms = new ModifiablePermissions(credentials);
  5850.  
  5851. PreparedStatement statement = null;
  5852. ResultSet set = null;
  5853.  
  5854. try {
  5855. - statement = DBManager.prepareStatement("SELECT * FROM player_permission WHERE lower(name) = ?");
  5856. - statement.setString(1, username.toLowerCase());
  5857. + statement = DBManager.prepareStatement("SELECT * FROM player_permission WHERE player_id = ?");
  5858. + statement.setString(1, playerId.toString());
  5859. set = statement.executeQuery();
  5860.  
  5861. while (set.next()) {
  5862. @@ -95,7 +99,7 @@ public final class ModifiablePermissionsHandler {
  5863. perms.addPermissionNoSave(permID, disabled ? PermissionType.DISABLED : PermissionType.ADDITIONAL);
  5864. }
  5865. } catch (SQLException ex) {
  5866. - InnPlugin.logError("Cannot load modifiable permissions for " + username + "!", ex);
  5867. + InnPlugin.logError("Cannot load modifiable permissions for player with ID: " + playerId.toString() + "!", ex);
  5868. } finally {
  5869. DBManager.closeResultSet(set);
  5870. DBManager.closePreparedStatement(statement);
  5871. @@ -109,7 +113,7 @@ public final class ModifiablePermissionsHandler {
  5872. * @return
  5873. */
  5874. public static List<ModifiablePermissions> getAllModifiedPermsFromDB() {
  5875. - HashMap<String, ModifiablePermissions> tempMap = new HashMap<String, ModifiablePermissions>();
  5876. + HashMap<UUID, ModifiablePermissions> tempMap = new HashMap<UUID, ModifiablePermissions>();
  5877. List<ModifiablePermissions> permList = new ArrayList<ModifiablePermissions>();
  5878.  
  5879. PreparedStatement statement = null;
  5880. @@ -120,16 +124,18 @@ public final class ModifiablePermissionsHandler {
  5881. set = statement.executeQuery();
  5882.  
  5883. while (set.next()) {
  5884. - String username = set.getString("name");
  5885. + String playerIdString = set.getString("player_id");
  5886. + UUID playerId = UUID.fromString(playerIdString);
  5887. + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(playerId);
  5888. int permID = set.getInt("permissionid");
  5889. boolean disabled = set.getBoolean("disabled");
  5890.  
  5891. - if (!tempMap.containsKey(username.toLowerCase())) {
  5892. - ModifiablePermissions perms = new ModifiablePermissions(username);
  5893. + if (!tempMap.containsKey(playerId)) {
  5894. + ModifiablePermissions perms = new ModifiablePermissions(credentials);
  5895. perms.addPermissionNoSave(permID, (disabled ? PermissionType.DISABLED : PermissionType.ADDITIONAL));
  5896. - tempMap.put(username.toLowerCase(), perms);
  5897. + tempMap.put(playerId, perms);
  5898. } else {
  5899. - ModifiablePermissions perms = tempMap.get(username.toLowerCase());
  5900. + ModifiablePermissions perms = tempMap.get(playerId);
  5901. perms.addPermissionNoSave(permID, (disabled ? PermissionType.DISABLED : PermissionType.ADDITIONAL));
  5902. }
  5903. }
  5904. diff --git a/src/net/innectis/innplugin/Handlers/PvpHandler.java b/src/net/innectis/innplugin/Handlers/PvpHandler.java
  5905. index b42da1dbe..1f4f4110a 100644
  5906. --- a/src/net/innectis/innplugin/Handlers/PvpHandler.java
  5907. +++ b/src/net/innectis/innplugin/Handlers/PvpHandler.java
  5908. @@ -111,7 +111,7 @@ public final class PvpHandler {
  5909.  
  5910. // No points for killing yourself
  5911. if (!attacker.getName().equalsIgnoreCase(defender.getName())) {
  5912. - int kills = attacker.getSession().getPvpKillTotalOf(defender);
  5913. + int kills = attacker.getSession().getPvpKillTotalOf(defender.getUniqueId());
  5914. if (kills == 0) {
  5915. points = 10;
  5916. } else if (kills == 1) {
  5917. @@ -139,10 +139,10 @@ public final class PvpHandler {
  5918.  
  5919.  
  5920. //defender.dealDamage(100000); //ensure they die
  5921. - attacker.getSession().addPvpKill(defender);
  5922. + attacker.getSession().addPvpKill(defender.getUniqueId());
  5923.  
  5924. - TransactionObject to = TransactionHandler.getTransactionObject(attacker.getName());
  5925. - to.addValue(points, TransactionHandler.TransactionType.PVP_POINTS);
  5926. + TransactionObject transaction = TransactionHandler.getTransactionObject(attacker.getUniqueId(), attacker.getName());
  5927. + transaction.addValue(points, TransactionHandler.TransactionType.PVP_POINTS);
  5928.  
  5929. attacker.print(ChatColor.LIGHT_PURPLE, "You have been awarded " + points + " points for killing " + defender.getColoredName());
  5930. InnectisLot attackerLot = LotHandler.getLot(attacker.getLocation());
  5931. diff --git a/src/net/innectis/innplugin/Handlers/StaffMessageHandler.java b/src/net/innectis/innplugin/Handlers/StaffMessageHandler.java
  5932. index 28f099abe..20377bd9e 100644
  5933. --- a/src/net/innectis/innplugin/Handlers/StaffMessageHandler.java
  5934. +++ b/src/net/innectis/innplugin/Handlers/StaffMessageHandler.java
  5935. @@ -7,6 +7,8 @@ import java.util.*;
  5936. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  5937. import net.innectis.innplugin.InnPlugin;
  5938. import net.innectis.innplugin.InnectisObjects.StaffMessage;
  5939. +import net.innectis.innplugin.Player.PlayerCredentials;
  5940. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  5941.  
  5942. /**
  5943. * A class that handles all staff requests that players have
  5944. @@ -36,10 +38,14 @@ public final class StaffMessageHandler {
  5945. int id = set.getInt("id");
  5946. java.sql.Date date = set.getDate("datecreated");
  5947. boolean read = set.getBoolean("hasread");
  5948. - String creator = set.getString("creator");
  5949. +
  5950. + String creatorId = set.getString("creator_player_id");
  5951. + UUID creatorUUID = UUID.fromString(creatorId);
  5952. + PlayerCredentials creatorCredentials = PlayerCredentialsManager.getByUniqueId(creatorUUID, true);
  5953. +
  5954. String message = set.getString("message");
  5955.  
  5956. - StaffMessage sm = new StaffMessage(id, date, read, creator, message);
  5957. + StaffMessage sm = new StaffMessage(id, date, read, creatorCredentials, message);
  5958. staffRequests.add(sm);
  5959. }
  5960. } catch (SQLException ex) {
  5961. diff --git a/src/net/innectis/innplugin/Handlers/TransactionHandler.java b/src/net/innectis/innplugin/Handlers/TransactionHandler.java
  5962. index 69da6ba2b..49cb1918a 100644
  5963. --- a/src/net/innectis/innplugin/Handlers/TransactionHandler.java
  5964. +++ b/src/net/innectis/innplugin/Handlers/TransactionHandler.java
  5965. @@ -1,13 +1,12 @@
  5966. package net.innectis.innplugin.Handlers;
  5967.  
  5968. -import java.util.HashMap;
  5969. -
  5970. -import net.innectis.innplugin.Handlers.Datasource.DBManager;
  5971. -
  5972. import java.sql.PreparedStatement;
  5973. import java.sql.ResultSet;
  5974. import java.sql.SQLException;
  5975. +import java.util.HashMap;
  5976. import java.util.Map;
  5977. +import java.util.UUID;
  5978. +import net.innectis.innplugin.Handlers.Datasource.DBManager;
  5979. import net.innectis.innplugin.InnPlugin;
  5980. import net.innectis.innplugin.InnectisObjects.TransactionObject;
  5981. import net.innectis.innplugin.Player.IdpPlayer;
  5982. @@ -18,7 +17,7 @@ import net.innectis.innplugin.Player.IdpPlayer;
  5983. * @author AlphaBlend
  5984. */
  5985. public final class TransactionHandler {
  5986. - private static Map<String, TransactionObject> playerTransactions = new HashMap<String, TransactionObject>();
  5987. + private static Map<UUID, TransactionObject> playerTransactions = new HashMap<UUID, TransactionObject>();
  5988.  
  5989. private TransactionHandler() {
  5990. }
  5991. @@ -74,44 +73,44 @@ public final class TransactionHandler {
  5992.  
  5993. /**
  5994. * Removes the transaction object from the cache
  5995. - * @param player
  5996. + * @param playerId
  5997. */
  5998. - public static void removeTransactionObjectFromCache(String player) {
  5999. - if (playerTransactions.containsKey(player.toLowerCase())) {
  6000. - playerTransactions.remove(player.toLowerCase());
  6001. + public static void removeTransactionObjectFromCache(UUID playerId) {
  6002. + if (playerTransactions.containsKey(playerId)) {
  6003. + playerTransactions.remove(playerId);
  6004. }
  6005. }
  6006.  
  6007. /**
  6008. - * Gets the transaction object of the player
  6009. + * Gets the transaction object of the player by their ID
  6010. *
  6011. - * @param player
  6012. + * @param playerId
  6013. * @return the transaction object of the player
  6014. * or null if the player doesn't exist
  6015. */
  6016. - public static TransactionObject getTransactionObject(String player) {
  6017. - TransactionObject to = playerTransactions.get(player.toLowerCase());
  6018. + public static TransactionObject getTransactionObject(UUID playerId, String playerName) {
  6019. + TransactionObject to = playerTransactions.get(playerId);
  6020.  
  6021. // If the currency is not in cache, load from database
  6022. if (to == null) {
  6023. - to = loadPlayerBalance(player);
  6024. + to = loadPlayerBalance(playerId, playerName);
  6025. }
  6026.  
  6027. return to;
  6028. }
  6029.  
  6030. /**
  6031. - * Loads the balance from the specified player into memory
  6032. - * @param player
  6033. + * Loads the balance from the specified player ID into memory
  6034. + * @param playerId
  6035. * @return
  6036. */
  6037. - public static TransactionObject loadPlayerBalance(String player) {
  6038. + private static TransactionObject loadPlayerBalance(UUID playerId, String playerName) {
  6039. PreparedStatement statement = null;
  6040. ResultSet set = null;
  6041.  
  6042. try {
  6043. - statement = DBManager.prepareStatement("SELECT valutas, valutas_in_bank, valutas_to_bank, valutas_to_player, pvp_points, referral_points, vote_points FROM players WHERE lower(name) = ?");
  6044. - statement.setString(1, player.toLowerCase());
  6045. + statement = DBManager.prepareStatement("SELECT valutas, valutas_in_bank, valutas_to_bank, valutas_to_player, pvp_points, referral_points, vote_points FROM players WHERE player_id = ?");
  6046. + statement.setString(1, playerId.toString());
  6047. set = statement.executeQuery();
  6048.  
  6049. if (set.next()) {
  6050. @@ -123,19 +122,19 @@ public final class TransactionHandler {
  6051. int referPoints = set.getInt("referral_points");
  6052. int votePoints = set.getInt("vote_points");
  6053.  
  6054. - TransactionObject transaction = new TransactionObject(player, valutas, valutasInBank, valutasToBank, valutasToPlayer, pvpPoints, referPoints, votePoints);
  6055. + TransactionObject transaction = new TransactionObject(playerId, playerName, valutas, valutasInBank, valutasToBank, valutasToPlayer, pvpPoints, referPoints, votePoints);
  6056.  
  6057. - IdpPlayer testPlayer = InnPlugin.getPlugin().getPlayer(player);
  6058. + IdpPlayer testPlayer = InnPlugin.getPlugin().getPlayer(playerId);
  6059.  
  6060. // Cache the object if we have a player online
  6061. if (testPlayer != null) {
  6062. - playerTransactions.put(player.toLowerCase(), transaction);
  6063. + playerTransactions.put(playerId, transaction);
  6064. }
  6065.  
  6066. return transaction;
  6067. }
  6068. } catch (SQLException ex) {
  6069. - InnPlugin.logError("Unable to load player's balance!", ex);
  6070. + InnPlugin.logError("Unable to load player balance for " + playerName + "!", ex);
  6071. } finally {
  6072. DBManager.closeResultSet(set);
  6073. DBManager.closePreparedStatement(statement);
  6074. diff --git a/src/net/innectis/innplugin/InnPlugin.java b/src/net/innectis/innplugin/InnPlugin.java
  6075. index 33005a0ed..1c8fe3423 100644
  6076. --- a/src/net/innectis/innplugin/InnPlugin.java
  6077. +++ b/src/net/innectis/innplugin/InnPlugin.java
  6078. @@ -9,6 +9,7 @@ import java.util.HashSet;
  6079. import java.util.LinkedList;
  6080. import java.util.List;
  6081. import java.util.Map;
  6082. +import java.util.UUID;
  6083. import java.util.logging.Level;
  6084. import java.util.logging.Logger;
  6085. import net.innectis.innplugin.BanSystem.BanHandler;
  6086. @@ -36,6 +37,8 @@ import net.innectis.innplugin.Player.Channel.ChatChannelHandler;
  6087. import net.innectis.innplugin.Player.Chat.ChatColor;
  6088. import net.innectis.innplugin.Player.IdpPlayer;
  6089. import net.innectis.innplugin.Player.Permission;
  6090. +import net.innectis.innplugin.Player.PlayerCredentials;
  6091. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  6092. import net.innectis.innplugin.Player.PlayerGroup;
  6093. import net.innectis.innplugin.Player.TinyWE.BlockCounters.BlockCounterFactory;
  6094. import net.innectis.innplugin.Shop.ShopHandler;
  6095. @@ -95,7 +98,7 @@ public class InnPlugin extends JavaPlugin implements TabCompleter {
  6096. private Map<String, Long> _adminMsgSpam = Collections.synchronizedMap(new HashMap<String, Long>(200));
  6097. private Map<Long, LotFlagToggle> _lotFlagToggles = Collections.synchronizedMap(new HashMap<Long, LotFlagToggle>(10));
  6098. private List<EnderChestView> _enderchestViews = new LinkedList<EnderChestView>();
  6099. - private Map<String, IdpInventory> _backpackViews = new HashMap<String, IdpInventory>();
  6100. + private Map<UUID, IdpInventory> _backpackViews = new HashMap<UUID, IdpInventory>();
  6101. public CommandManager commandManager;
  6102. public MenuItem helpMenu;
  6103. private List<Long> timers = new LinkedList<Long>();
  6104. @@ -460,7 +463,8 @@ public class InnPlugin extends JavaPlugin implements TabCompleter {
  6105. if (y == height + 2) {
  6106. if (WaypointHandler.getWaypoint(block.getLocation(), false) == null) {
  6107. try {
  6108. - InnectisWaypoint waypoint = WaypointHandler.createWaypoint("Hretsam", block, true);
  6109. + PlayerCredentials credentials = PlayerCredentialsManager.getByName("Hretsam");
  6110. + InnectisWaypoint waypoint = WaypointHandler.createWaypoint(credentials, block, true);
  6111. waypoint.setDestination(new Location(world, block.getX() * 50, 128, block.getZ() * 50));
  6112. waypoint.save();
  6113. } catch (SQLException ex) {
  6114. @@ -838,6 +842,21 @@ public class InnPlugin extends JavaPlugin implements TabCompleter {
  6115. return null;
  6116. }
  6117.  
  6118. + /**
  6119. + * Gets an online player from their unique ID
  6120. + * @param playerId
  6121. + * @return
  6122. + */
  6123. + public IdpPlayer getPlayer(UUID playerId) {
  6124. + for (IdpPlayer player : getOnlinePlayers()) {
  6125. + if (player.getUniqueId().equals(playerId)) {
  6126. + return player;
  6127. + }
  6128. + }
  6129. +
  6130. + return null;
  6131. + }
  6132. +
  6133. /**
  6134. * Returns the given player, or null if he/she is not found (or online)
  6135. *
  6136. @@ -1175,16 +1194,16 @@ public class InnPlugin extends JavaPlugin implements TabCompleter {
  6137. }
  6138.  
  6139. /**
  6140. - * Gets an ender chest view by the given owner and chest type
  6141. - * @param name
  6142. + * Gets an ender chest view by the ID of the given owner and chest type
  6143. + * @param playerId
  6144. * @param type
  6145. * @return
  6146. */
  6147. - public EnderChestView getEnderChestView(String owner, EnderContentsType type) {
  6148. + public EnderChestView getEnderChestView(UUID playerId, EnderContentsType type) {
  6149. EnderChestView enderView = null;
  6150.  
  6151. for (EnderChestView view : _enderchestViews) {
  6152. - if (view.getOwner().equalsIgnoreCase(owner) && view.getContentsType() == type) {
  6153. + if (view.getOwnerId().equals(playerId) && view.getContentsType() == type) {
  6154. enderView = view;
  6155. break;
  6156. }
  6157. @@ -1205,28 +1224,28 @@ public class InnPlugin extends JavaPlugin implements TabCompleter {
  6158. //<editor-fold defaultstate="collapsed" desc="Backpack Viewing">
  6159. /**
  6160. * Adds a new backpack view
  6161. - * @param owner
  6162. + * @param playerId
  6163. * @param inv
  6164. */
  6165. - public void addBackpackView(String owner, IdpInventory inv) {
  6166. - _backpackViews.put(owner.toLowerCase(), inv);
  6167. + public void addBackpackView(UUID playerId, IdpInventory inv) {
  6168. + _backpackViews.put(playerId, inv);
  6169. }
  6170.  
  6171. /**
  6172. * Gets an existing backpack view
  6173. - * @param owner
  6174. - * @return
  6175. + * @param playerId
  6176. + * playerId
  6177. */
  6178. - public IdpInventory getBackpackView(String owner) {
  6179. - return _backpackViews.get(owner.toLowerCase());
  6180. + public IdpInventory getBackpackView(UUID playerId) {
  6181. + return _backpackViews.get(playerId);
  6182. }
  6183.  
  6184. /**
  6185. * Removes a backpack view by the owner
  6186. - * @param owner
  6187. + * @param playerId
  6188. */
  6189. - public void removeBackpackView(String owner) {
  6190. - _backpackViews.remove(owner.toLowerCase());
  6191. + public void removeBackpackView(UUID playerId) {
  6192. + _backpackViews.remove(playerId);
  6193. }
  6194. //</editor-fold>
  6195. }
  6196. diff --git a/src/net/innectis/innplugin/InnectisObjects/EnderChestContents.java b/src/net/innectis/innplugin/InnectisObjects/EnderChestContents.java
  6197. index ecef250b1..546ec3ed1 100644
  6198. --- a/src/net/innectis/innplugin/InnectisObjects/EnderChestContents.java
  6199. +++ b/src/net/innectis/innplugin/InnectisObjects/EnderChestContents.java
  6200. @@ -6,10 +6,13 @@ import java.sql.SQLException;
  6201. import java.util.ArrayList;
  6202. import java.util.HashMap;
  6203. import java.util.List;
  6204. +import java.util.UUID;
  6205. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  6206. import net.innectis.innplugin.InnPlugin;
  6207. import net.innectis.innplugin.Items.IdpItemStack;
  6208. import net.innectis.innplugin.Items.StackBag;
  6209. +import net.innectis.innplugin.Player.PlayerCredentials;
  6210. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  6211.  
  6212. /**
  6213. *
  6214. @@ -22,26 +25,26 @@ public class EnderChestContents {
  6215. private int chestid;
  6216. private long bagid;
  6217. private int typeid;
  6218. - private String player;
  6219. + private PlayerCredentials playerCredentials;
  6220. /** The items */
  6221. private IdpItemStack[] items;
  6222.  
  6223. private EnderChestContents() {
  6224. }
  6225.  
  6226. - private EnderChestContents(int chestid, long bagid, int typeid, String player, IdpItemStack[] items) {
  6227. + private EnderChestContents(int chestid, long bagid, int typeid, PlayerCredentials playerCredentials, IdpItemStack[] items) {
  6228. this.chestid = chestid;
  6229. this.bagid = bagid;
  6230. this.typeid = typeid;
  6231. - this.player = player;
  6232. + this.playerCredentials = playerCredentials;
  6233. this.items = items;
  6234. }
  6235.  
  6236. - private EnderChestContents(int chestid, int typeid, String player, IdpItemStack[] items) {
  6237. + private EnderChestContents(int chestid, int typeid, PlayerCredentials playerCredentials, IdpItemStack[] items) {
  6238. this.chestid = chestid;
  6239. this.bagid = 0;
  6240. this.typeid = typeid;
  6241. - this.player = player;
  6242. + this.playerCredentials = playerCredentials;
  6243. this.items = items;
  6244. }
  6245.  
  6246. @@ -53,12 +56,20 @@ public class EnderChestContents {
  6247. return chestid;
  6248. }
  6249.  
  6250. + /**
  6251. + * Gets the credentials of the player these contents belong to
  6252. + * @return
  6253. + */
  6254. + public PlayerCredentials getPlayerCredentials() {
  6255. + return playerCredentials;
  6256. + }
  6257. +
  6258. /**
  6259. * Returns the name of the player where this content belongs to
  6260. * @return
  6261. */
  6262. public String getPlayername() {
  6263. - return player;
  6264. + return playerCredentials.getName();
  6265. }
  6266.  
  6267. /**
  6268. @@ -100,8 +111,8 @@ public class EnderChestContents {
  6269. StackBag bag = new StackBag(items);
  6270. bag.save();
  6271.  
  6272. - statement = DBManager.prepareStatementWithAutoGeneratedKeys(" INSERT INTO enderchests (username, typeid, bagid) VALUES (?,?,?) ");
  6273. - statement.setString(1, player);
  6274. + statement = DBManager.prepareStatementWithAutoGeneratedKeys(" INSERT INTO enderchests (player_id, typeid, bagid) VALUES (?,?,?) ");
  6275. + statement.setString(1, playerCredentials.getUniqueId().toString());
  6276. statement.setInt(2, typeid);
  6277. statement.setLong(3, bag.getBagid());
  6278. statement.executeUpdate();
  6279. @@ -138,10 +149,10 @@ public class EnderChestContents {
  6280. /**
  6281. * Gives the EnderChestContents of the enderchest for the player.
  6282. * It will use the player's location to get the correct chest.
  6283. - * @param player
  6284. + * @param playerCredentials
  6285. * @return
  6286. */
  6287. - public static EnderChestContents getContents(String player, EnderContentsType type) {
  6288. + public static EnderChestContents getContents(PlayerCredentials playerCredentials, EnderContentsType type) {
  6289. // Return null if type == NONE
  6290. if (type == EnderContentsType.NONE) {
  6291. return null;
  6292. @@ -151,9 +162,9 @@ public class EnderChestContents {
  6293. ResultSet set = null;
  6294.  
  6295. try {
  6296. - statement = DBManager.prepareStatement(" SELECT chestid, bagid FROM enderchests where lower(username) = ? and typeid = ? ");
  6297. + statement = DBManager.prepareStatement(" SELECT chestid, bagid FROM enderchests where player_id = ? and typeid = ? ");
  6298.  
  6299. - statement.setString(1, player.toLowerCase());
  6300. + statement.setString(1, playerCredentials.getUniqueId().toString());
  6301. statement.setInt(2, type.getTypeid());
  6302. set = statement.executeQuery();
  6303.  
  6304. @@ -165,9 +176,9 @@ public class EnderChestContents {
  6305. }
  6306. if (bagid > 0) {
  6307. StackBag bag = StackBag.getContentbag(bagid);
  6308. - return new EnderChestContents(id, bagid, type.getTypeid(), player, bag.getContents());
  6309. + return new EnderChestContents(id, bagid, type.getTypeid(), playerCredentials, bag.getContents());
  6310. } else {
  6311. - return new EnderChestContents(id, type.getTypeid(), player, new IdpItemStack[27]);
  6312. + return new EnderChestContents(id, type.getTypeid(), playerCredentials, new IdpItemStack[27]);
  6313. }
  6314. } catch (SQLException ex) {
  6315. InnPlugin.logError("Error loading endercontents!", ex);
  6316. @@ -190,18 +201,22 @@ public class EnderChestContents {
  6317. ResultSet set = null;
  6318.  
  6319. try {
  6320. - statement = DBManager.prepareStatement("SELECT chestid, username, typeid, bagid FROM enderchests");
  6321. + statement = DBManager.prepareStatement("SELECT chestid, player_id, typeid, bagid FROM enderchests");
  6322. set = statement.executeQuery();
  6323.  
  6324. while (set.next()) {
  6325. int id = set.getInt("chestid");
  6326. - String username = set.getString("username");
  6327. +
  6328. + String playerIdString = set.getString("player_id");
  6329. + UUID playerId = UUID.fromString(playerIdString);
  6330. + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(playerId);
  6331. +
  6332. int typeid = set.getInt("typeid");
  6333. long bagid = set.getLong("bagid");
  6334.  
  6335. if (bagid > 0) {
  6336. StackBag bag = StackBag.getContentbag(bagid);
  6337. - enderChests.add(new EnderChestContents(id, bagid, typeid, username, bag.getContents()));
  6338. + enderChests.add(new EnderChestContents(id, bagid, typeid, credentials, bag.getContents()));
  6339. }
  6340. }
  6341. } catch (SQLException ex) {
  6342. diff --git a/src/net/innectis/innplugin/InnectisObjects/EnderChestView.java b/src/net/innectis/innplugin/InnectisObjects/EnderChestView.java
  6343. index 7f54d8adf..1c1720b8b 100644
  6344. --- a/src/net/innectis/innplugin/InnectisObjects/EnderChestView.java
  6345. +++ b/src/net/innectis/innplugin/InnectisObjects/EnderChestView.java
  6346. @@ -1,5 +1,6 @@
  6347. package net.innectis.innplugin.InnectisObjects;
  6348.  
  6349. +import java.util.UUID;
  6350. import net.innectis.innplugin.InnectisObjects.EnderChestContents.EnderContentsType;
  6351. import org.bukkit.inventory.Inventory;
  6352.  
  6353. @@ -9,41 +10,41 @@ import org.bukkit.inventory.Inventory;
  6354. * @author AlphaBlend
  6355. */
  6356. public class EnderChestView {
  6357. - private String owner;
  6358. + private UUID ownerId;
  6359. private EnderContentsType type;
  6360. private Inventory inventory;
  6361. -
  6362. +
  6363. /**
  6364. * Constructs a new ender chest view of a given chest
  6365. - * @param owner
  6366. + * @param ownerId
  6367. * @param type
  6368. - * @param inventory
  6369. + * @param inventory
  6370. */
  6371. - public EnderChestView(String owner, EnderContentsType type, Inventory inventory) {
  6372. - this.owner = owner;
  6373. + public EnderChestView(UUID ownerId, EnderContentsType type, Inventory inventory) {
  6374. + this.ownerId = ownerId;
  6375. this.type = type;
  6376. this.inventory = inventory;
  6377. }
  6378. -
  6379. +
  6380. /**
  6381. - * Gets the owner of this chest view
  6382. - * @return
  6383. + * Gets the ID of the owner of this chest view
  6384. + * @return
  6385. */
  6386. - public String getOwner() {
  6387. - return owner;
  6388. + public UUID getOwnerId() {
  6389. + return ownerId;
  6390. }
  6391. -
  6392. +
  6393. /**
  6394. * Gets the content type of this ender chest
  6395. - * @return
  6396. + * @return
  6397. */
  6398. public EnderContentsType getContentsType() {
  6399. return type;
  6400. }
  6401. -
  6402. +
  6403. /**
  6404. * Gets the inventory of this ender chest
  6405. - * @return
  6406. + * @return
  6407. */
  6408. public Inventory getInventory() {
  6409. return inventory;
  6410. diff --git a/src/net/innectis/innplugin/InnectisObjects/IPLogger.java b/src/net/innectis/innplugin/InnectisObjects/IPLogger.java
  6411. index b5edf39f2..6d2d1eb11 100644
  6412. --- a/src/net/innectis/innplugin/InnectisObjects/IPLogger.java
  6413. +++ b/src/net/innectis/innplugin/InnectisObjects/IPLogger.java
  6414. @@ -1,20 +1,21 @@
  6415. package net.innectis.innplugin.InnectisObjects;
  6416.  
  6417. -import java.util.ArrayList;
  6418. -import java.util.List;
  6419. -
  6420. import java.sql.PreparedStatement;
  6421. import java.sql.ResultSet;
  6422. import java.sql.SQLException;
  6423. import java.sql.Timestamp;
  6424. +import java.util.ArrayList;
  6425. +import java.util.List;
  6426. +import java.util.UUID;
  6427. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  6428. import net.innectis.innplugin.InnPlugin;
  6429. +import net.innectis.innplugin.Player.PlayerCredentials;
  6430.  
  6431. /**
  6432. *
  6433. * @author AlphaBlend
  6434. *
  6435. - * Logs all IPs of banned users when they attempt to connect
  6436. + * Logs connections from players when they join the server
  6437. */
  6438. public class IPLogger {
  6439. private IPLogger() {}
  6440. @@ -22,35 +23,35 @@ public class IPLogger {
  6441. /**
  6442. * Logs a connection to the database
  6443. */
  6444. - public static void logConnection(String username, String ip, Timestamp timestamp) {
  6445. + public static void logConnection(UUID playerId, String playerName, String ip, Timestamp timestamp) {
  6446. PreparedStatement statement = null;
  6447.  
  6448. try {
  6449. - statement = DBManager.prepareStatement("INSERT INTO ip_log (name, ip, logtime) VALUES (?, ?, ?) ");
  6450. - statement.setString(1, username);
  6451. + statement = DBManager.prepareStatement("INSERT INTO ip_log (player_id, ip, logtime) VALUES (?, ?, ?) ");
  6452. + statement.setString(1, playerId.toString());
  6453. statement.setString(2, ip);
  6454. statement.setTimestamp(3, timestamp);
  6455. statement.execute();
  6456. } catch (SQLException ex) {
  6457. - InnPlugin.logError("Cannot log connection from player '" + username + "' with ip '" + ip + "'", ex);
  6458. + InnPlugin.logError("Cannot log connection from player " + playerName + " with ip " + ip + "!", ex);
  6459. } finally {
  6460. DBManager.closePreparedStatement(statement);
  6461. }
  6462. }
  6463. /**
  6464. * Get IPs used by a given player
  6465. - * @param player
  6466. + * @param playerId
  6467. * @return
  6468. */
  6469. - public static List<String> getIPsByPlayer(String username) {
  6470. + public static List<String> getIPsByPlayer(UUID playerId, String playerName) {
  6471. List<String> IPs = new ArrayList<String>();
  6472.  
  6473. PreparedStatement statement = null;
  6474. ResultSet set = null;
  6475.  
  6476. try {
  6477. - statement = DBManager.prepareStatement("SELECT DISTINCT ip FROM ip_log WHERE lower(name) = ?");
  6478. - statement.setString(1, username.toLowerCase());
  6479. + statement = DBManager.prepareStatement("SELECT DISTINCT ip FROM ip_log WHERE player_id = ?;");
  6480. + statement.setString(1, playerId.toString());
  6481. set = statement.executeQuery();
  6482.  
  6483. while (set.next()) {
  6484. @@ -58,7 +59,7 @@ public class IPLogger {
  6485. IPs.add(ip);
  6486. }
  6487. } catch (SQLException ex) {
  6488. - InnPlugin.logError("Unable to get IPs by player!", ex);
  6489. + InnPlugin.logError("Unable to get IPs for player " + playerName + "!", ex);
  6490. } finally {
  6491. DBManager.closeResultSet(set);
  6492. DBManager.closePreparedStatement(statement);
  6493. @@ -68,26 +69,27 @@ public class IPLogger {
  6494. }
  6495.  
  6496. /**
  6497. - * Gets the last IP used to connect to Innectis from this username
  6498. - * @param username
  6499. + * Gets the last IP used to connect to Innectis from this player
  6500. + * represented by their ID
  6501. + * @param playerId
  6502. * @return
  6503. */
  6504. - public static String getLastUsedIP(String username) {
  6505. + public static String getLastUsedIP(UUID playerId, String playerName) {
  6506. String ip = null;
  6507.  
  6508. PreparedStatement statement = null;
  6509. ResultSet set = null;
  6510.  
  6511. try {
  6512. - statement = DBManager.prepareStatement("SELECT DISTINCT ip FROM ip_log WHERE lower(name) = ? ORDER BY logtime DESC LIMIT 1");
  6513. - statement.setString(1, username.toLowerCase());
  6514. + statement = DBManager.prepareStatement("SELECT DISTINCT ip FROM ip_log WHERE player_id = ? ORDER BY logtime DESC LIMIT 1;");
  6515. + statement.setString(1, playerId.toString());
  6516. set = statement.executeQuery();
  6517.  
  6518. if (set.next()) {
  6519. ip = set.getString("ip");
  6520. }
  6521. } catch (SQLException ex) {
  6522. - InnPlugin.logError("UNable to get last used IP for " + username + "!", ex);
  6523. + InnPlugin.logError("Umable to get last used IP for player " + playerName + "!", ex);
  6524. } finally {
  6525. DBManager.closeResultSet(set);
  6526. DBManager.closePreparedStatement(statement);
  6527. @@ -97,18 +99,18 @@ public class IPLogger {
  6528. }
  6529.  
  6530. /**
  6531. - * Determines if the specified user has used the specified ip to log in with
  6532. - * @param username
  6533. - * @param ip
  6534. + * Determines if the specified player has used the specified ip to log in with
  6535. + * @param playerId
  6536. + * @param checkIP
  6537. * @return
  6538. */
  6539. - public boolean isUsingIP(String username, String checkIP) {
  6540. + public boolean isUsingIP(UUID playerId, String playerName, String checkIP) {
  6541. PreparedStatement statement = null;
  6542. ResultSet set = null;
  6543.  
  6544. try {
  6545. - statement = DBManager.prepareStatement("SELECT DISTINCT ip FROM ip_log WHERE lower(name) = ?");
  6546. - statement.setString(1, username.toLowerCase());
  6547. + statement = DBManager.prepareStatement("SELECT DISTINCT ip FROM ip_log WHERE player_id = ?");
  6548. + statement.setString(1, playerId.toString());
  6549. set = statement.executeQuery();
  6550.  
  6551. while (set.next()) {
  6552. @@ -119,7 +121,7 @@ public class IPLogger {
  6553. }
  6554. }
  6555. } catch (SQLException ex) {
  6556. - InnPlugin.logError("Unable to check if " + username + " is using " + checkIP + "!", ex);
  6557. + InnPlugin.logError("Unable to check if player " + playerName + " is using " + checkIP + "!", ex);
  6558. } finally {
  6559. DBManager.closeResultSet(set);
  6560. DBManager.closePreparedStatement(statement);
  6561. diff --git a/src/net/innectis/innplugin/InnectisObjects/IdpHome.java b/src/net/innectis/innplugin/InnectisObjects/IdpHome.java
  6562. index 062647aa0..9e68db7b4 100644
  6563. --- a/src/net/innectis/innplugin/InnectisObjects/IdpHome.java
  6564. +++ b/src/net/innectis/innplugin/InnectisObjects/IdpHome.java
  6565. @@ -3,6 +3,7 @@ package net.innectis.innplugin.InnectisObjects;
  6566. import java.sql.PreparedStatement;
  6567. import java.sql.ResultSet;
  6568. import java.sql.SQLException;
  6569. +import java.util.UUID;
  6570. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  6571. import net.innectis.innplugin.InnPlugin;
  6572. import org.bukkit.Location;
  6573. @@ -14,33 +15,34 @@ import org.bukkit.Location;
  6574. */
  6575. public class IdpHome {
  6576. private int UID;
  6577. - private String owner;
  6578. + private UUID playerId;
  6579. private int homeId;
  6580. private String homeName;
  6581. private Location location;
  6582.  
  6583. /**
  6584. * Constructs a home object with a brand new home ID
  6585. - * @param owner
  6586. + * @param playerId
  6587. * @param homeID
  6588. * @param name
  6589. * @param location
  6590. */
  6591. - public IdpHome(String owner, int homeID, String homeName, Location location) {
  6592. - this(0, owner, homeID, homeName, location);
  6593. + public IdpHome(UUID playerId, int homeID, String homeName, Location location) {
  6594. + this(0, playerId, homeID, homeName, location);
  6595. }
  6596.  
  6597. /**
  6598. * Constructs a new object to hold a player's home location
  6599. *
  6600. * @param UID
  6601. + * @param playerId
  6602. * @param homeID
  6603. * @param name
  6604. * @param location
  6605. */
  6606. - public IdpHome(int UID, String owner, int homeID, String homeName, Location location) {
  6607. + public IdpHome(int UID, UUID playerId, int homeID, String homeName, Location location) {
  6608. this.UID = UID;
  6609. - this.owner = owner;
  6610. + this.playerId = playerId;
  6611. this.homeId = homeID;
  6612. this.homeName = homeName;
  6613. this.location = location;
  6614. @@ -104,7 +106,6 @@ public class IdpHome {
  6615. * @return
  6616. */
  6617. public boolean equals(Location loc) {
  6618. -
  6619. if (loc.getBlockX() == location.getBlockX()
  6620. && loc.getBlockY() == location.getBlockY()
  6621. && loc.getBlockZ() == location.getBlockZ()
  6622. @@ -124,7 +125,7 @@ public class IdpHome {
  6623.  
  6624. try {
  6625. if (UID > 0) {
  6626. - statement = DBManager.prepareStatement("UPDATE homes SET homeid=?, homename=?, world=?, locx=?, locy=?, locz=?, yaw=? WHERE ID = ?");
  6627. + statement = DBManager.prepareStatement("UPDATE homes SET homeid = ?, homename = ?, world = ?, locx = ?, locy = ?, locz = ?, yaw = ? WHERE ID = ?");
  6628. statement.setInt(1, homeId);
  6629. statement.setString(2, homeName);
  6630. statement.setString(3, location.getWorld().getName());
  6631. @@ -135,8 +136,8 @@ public class IdpHome {
  6632. statement.setInt(8, UID);
  6633. statement.executeUpdate();
  6634. } else {
  6635. - statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO homes (username, homeid, homename, world, locx, locy, locz, yaw) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
  6636. - statement.setString(1, owner);
  6637. + statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO homes (player_id, homeid, homename, world, locx, locy, locz, yaw) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
  6638. + statement.setString(1, playerId.toString());
  6639. statement.setInt(2, homeId);
  6640. statement.setString(3, homeName);
  6641. statement.setString(4, location.getWorld().getName());
  6642. diff --git a/src/net/innectis/innplugin/InnectisObjects/MemberGroup.java b/src/net/innectis/innplugin/InnectisObjects/MemberGroup.java
  6643. index af03e23f3..497271b87 100644
  6644. --- a/src/net/innectis/innplugin/InnectisObjects/MemberGroup.java
  6645. +++ b/src/net/innectis/innplugin/InnectisObjects/MemberGroup.java
  6646. @@ -4,9 +4,11 @@ import java.sql.PreparedStatement;
  6647. import java.sql.ResultSet;
  6648. import java.sql.SQLException;
  6649. import java.util.HashSet;
  6650. +import java.util.Iterator;
  6651. +import java.util.UUID;
  6652. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  6653. import net.innectis.innplugin.InnPlugin;
  6654. -import net.innectis.innplugin.Player.IdpPlayer;
  6655. +import net.innectis.innplugin.Player.PlayerCredentials;
  6656.  
  6657. /**
  6658. *
  6659. @@ -14,15 +16,15 @@ import net.innectis.innplugin.Player.IdpPlayer;
  6660. */
  6661. public class MemberGroup {
  6662. private int id;
  6663. - private String owner;
  6664. - private HashSet<String> members;
  6665. + private PlayerCredentials ownerCredentials;
  6666. + private HashSet<PlayerCredentials> members;
  6667. private String groupName;
  6668. private boolean updated = false;
  6669.  
  6670. - public MemberGroup(int id, String owner, String groupName) {
  6671. + public MemberGroup(int id, PlayerCredentials ownerCredentials, String groupName) {
  6672. this.id = id;
  6673. - this.owner = owner;
  6674. - this.members = new HashSet<String>();
  6675. + this.ownerCredentials = ownerCredentials;
  6676. + this.members = new HashSet<PlayerCredentials>();
  6677. this.groupName = groupName;
  6678. this.updated = true;
  6679. }
  6680. @@ -31,23 +33,30 @@ public class MemberGroup {
  6681. return id;
  6682. }
  6683.  
  6684. + public PlayerCredentials getOwnerCredentials() {
  6685. + return ownerCredentials;
  6686. + }
  6687. +
  6688. public String getOwner() {
  6689. - return owner;
  6690. + return ownerCredentials.getName();
  6691. }
  6692.  
  6693. - public HashSet<String> getMembers() {
  6694. + public HashSet<PlayerCredentials> getMembers() {
  6695. return members;
  6696. }
  6697.  
  6698. public String getMembersString() {
  6699. StringBuilder sb = new StringBuilder();
  6700. - for (String m : members) {
  6701. - sb.append(m).append(", ");
  6702. +
  6703. + for (PlayerCredentials pc : members) {
  6704. + String name = pc.getName();
  6705. + sb.append(name).append(", ");
  6706. }
  6707.  
  6708. if (sb.length() == 0) {
  6709. return "none";
  6710. }
  6711. +
  6712. return sb.substring(0, sb.length() - 2);
  6713. }
  6714.  
  6715. @@ -63,44 +72,40 @@ public class MemberGroup {
  6716. this.updated = updated;
  6717. }
  6718.  
  6719. - public boolean addMember(String username) {
  6720. - boolean ret = members.add(username.toLowerCase());
  6721. - if (ret) {
  6722. - updated = true;
  6723. - }
  6724. - return ret;
  6725. - }
  6726. + public boolean addMember(PlayerCredentials credentials) {
  6727. + boolean ret = members.add(credentials);
  6728.  
  6729. - public boolean addMember(IdpPlayer player) {
  6730. - boolean ret = members.add(player.getName().toLowerCase());
  6731. if (ret) {
  6732. updated = true;
  6733. }
  6734. - return ret;
  6735. - }
  6736.  
  6737. - public boolean removeMember(String username) {
  6738. - boolean ret = members.remove(username.toLowerCase());
  6739. - if (ret) {
  6740. - updated = true;
  6741. - }
  6742. return ret;
  6743. }
  6744.  
  6745. - public boolean removeMember(IdpPlayer player) {
  6746. - boolean ret = members.remove(player.getName().toLowerCase());
  6747. - if (ret) {
  6748. - updated = true;
  6749. + public boolean removeMember(String playerName) {
  6750. + boolean ret = false;
  6751. +
  6752. + for (Iterator<PlayerCredentials> it = members.iterator(); it.hasNext();) {
  6753. + PlayerCredentials pc = it.next();
  6754. +
  6755. + if (pc.getName().equalsIgnoreCase(playerName)) {
  6756. + it.remove();
  6757. + updated = true;
  6758. + break;
  6759. + }
  6760. }
  6761. +
  6762. return ret;
  6763. }
  6764.  
  6765. - public boolean containsMember(String username) {
  6766. - return members.contains(username.toLowerCase());
  6767. - }
  6768. + public boolean containsMember(String playerName) {
  6769. + for (PlayerCredentials pc : members) {
  6770. + if (pc.getName().equalsIgnoreCase(playerName)) {
  6771. + return true;
  6772. + }
  6773. + }
  6774.  
  6775. - public boolean containsMember(IdpPlayer player) {
  6776. - return members.contains(player.getName().toLowerCase());
  6777. + return false;
  6778. }
  6779.  
  6780. public boolean save() {
  6781. @@ -109,8 +114,8 @@ public class MemberGroup {
  6782.  
  6783. try {
  6784. if (getId() == -1) {
  6785. - statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT IGNORE INTO member_groups (username, groupname) VALUES (?, ?);");
  6786. - statement.setString(1, owner);
  6787. + statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT IGNORE INTO member_groups (player_id, groupname) VALUES (?, ?);");
  6788. + statement.setString(1, ownerCredentials.getUniqueId().toString());
  6789. statement.setString(2, groupName);
  6790. statement.executeUpdate();
  6791. result = statement.getGeneratedKeys();
  6792. @@ -128,10 +133,10 @@ public class MemberGroup {
  6793. statement.executeUpdate();
  6794. DBManager.closePreparedStatement(statement);
  6795.  
  6796. - for (String s : getMembers()) {
  6797. - statement = DBManager.prepareStatement("INSERT INTO member_users (groupid, username) VALUES (?, ?);");
  6798. + for (PlayerCredentials pc : getMembers()) {
  6799. + statement = DBManager.prepareStatement("INSERT INTO member_users (groupid, player_id) VALUES (?, ?);");
  6800. statement.setInt(1, getId());
  6801. - statement.setString(2, s);
  6802. + statement.setString(2, pc.getUniqueId().toString());
  6803. statement.executeUpdate();
  6804. DBManager.closePreparedStatement(statement);
  6805. }
  6806. diff --git a/src/net/innectis/innplugin/InnectisObjects/Message.java b/src/net/innectis/innplugin/InnectisObjects/Message.java
  6807. index 3f0203f4d..e0eac4c1a 100644
  6808. --- a/src/net/innectis/innplugin/InnectisObjects/Message.java
  6809. +++ b/src/net/innectis/innplugin/InnectisObjects/Message.java
  6810. @@ -1,6 +1,7 @@
  6811. package net.innectis.innplugin.InnectisObjects;
  6812.  
  6813. import java.util.Date;
  6814. +import net.innectis.innplugin.Player.PlayerCredentials;
  6815.  
  6816. /**
  6817. * An abstract class that defines a basic message
  6818. @@ -11,55 +12,49 @@ public abstract class Message {
  6819. protected int id;
  6820. protected Date date;
  6821. protected boolean read;
  6822. - protected String creator;
  6823. + protected PlayerCredentials creatorCredentials;
  6824. protected String message;
  6825. -
  6826. - /**
  6827. - * Constructs an abstract class of a simple message
  6828. - * @param id
  6829. - * @param date
  6830. - * @param message
  6831. - */
  6832. - public Message(int id, Date date, boolean read, String creator, String message) {
  6833. +
  6834. + public Message(int id, Date date, boolean read, PlayerCredentials creatorCredentials, String message) {
  6835. this.id = id;
  6836. this.date = date;
  6837. this.read = read;
  6838. - this.creator = creator;
  6839. + this.creatorCredentials = creatorCredentials;
  6840. this.message = message;
  6841. }
  6842. -
  6843. +
  6844. /**
  6845. * Gets the ID of this message
  6846. - * @return
  6847. + * @return
  6848. */
  6849. public int getId() {
  6850. return id;
  6851. }
  6852. -
  6853. +
  6854. /**
  6855. * Gets this message
  6856. - * @return
  6857. + * @return
  6858. */
  6859. public String getMessage() {
  6860. return message;
  6861. }
  6862. -
  6863. +
  6864. /**
  6865. * Gets the date this message was created
  6866. - * @return
  6867. + * @return
  6868. */
  6869. public Date getDate() {
  6870. return date;
  6871. }
  6872. -
  6873. +
  6874. /**
  6875. * Sets whether or not this message has been read
  6876. - * @param read
  6877. + * @param read
  6878. */
  6879. public void setRead(Boolean read) {
  6880. this.read = read;
  6881. }
  6882. -
  6883. +
  6884. /**
  6885. * Gets whether or not this message has been read
  6886. * @return
  6887. @@ -67,20 +62,24 @@ public abstract class Message {
  6888. public boolean hasRead() {
  6889. return read;
  6890. }
  6891. -
  6892. +
  6893. + public PlayerCredentials getCreatorCredentials() {
  6894. + return creatorCredentials;
  6895. + }
  6896. +
  6897. /**
  6898. * Gets the creator of the message
  6899. - * @return
  6900. + * @return
  6901. */
  6902. public String getCreator() {
  6903. - return creator;
  6904. + return creatorCredentials.getName();
  6905. }
  6906. -
  6907. +
  6908. /**
  6909. * Saves this message
  6910. */
  6911. public abstract void save();
  6912. -
  6913. +
  6914. /**
  6915. * Deletes this message
  6916. */
  6917. diff --git a/src/net/innectis/innplugin/InnectisObjects/ModifiablePermissions.java b/src/net/innectis/innplugin/InnectisObjects/ModifiablePermissions.java
  6918. index 97239450b..3d65fb988 100644
  6919. --- a/src/net/innectis/innplugin/InnectisObjects/ModifiablePermissions.java
  6920. +++ b/src/net/innectis/innplugin/InnectisObjects/ModifiablePermissions.java
  6921. @@ -10,6 +10,7 @@ import java.util.Map;
  6922. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  6923. import net.innectis.innplugin.Handlers.ModifiablePermissionsHandler.PermissionType;
  6924. import net.innectis.innplugin.InnPlugin;
  6925. +import net.innectis.innplugin.Player.PlayerCredentials;
  6926.  
  6927. /**
  6928. * Class that manages additional / disabled permissions for a player
  6929. @@ -17,8 +18,8 @@ import net.innectis.innplugin.InnPlugin;
  6930. * @author AlphaBlend
  6931. */
  6932. public class ModifiablePermissions {
  6933. - // The username these permissions apply to
  6934. - private String username;
  6935. + // The player credentials these permissions apply to
  6936. + private PlayerCredentials credentials;
  6937.  
  6938. // A map that associates a permission with its type
  6939. private Map<Integer, PermissionType> permissions = new HashMap<Integer, PermissionType>();
  6940. @@ -27,8 +28,16 @@ public class ModifiablePermissions {
  6941. * Constructs a new modifiable permissions object with just the username
  6942. * they are associated with
  6943. */
  6944. - public ModifiablePermissions(String username) {
  6945. - this.username = username;
  6946. + public ModifiablePermissions(PlayerCredentials credentials) {
  6947. + this.credentials = credentials;
  6948. + }
  6949. +
  6950. + /**
  6951. + * Gets the credentials of the player these modified permissions belong to
  6952. + * @return
  6953. + */
  6954. + public PlayerCredentials getCredentials() {
  6955. + return credentials;
  6956. }
  6957.  
  6958. /**
  6959. @@ -36,16 +45,16 @@ public class ModifiablePermissions {
  6960. * @return
  6961. */
  6962. public String getUsername() {
  6963. - return username;
  6964. + return credentials.getName();
  6965. }
  6966.  
  6967. /**
  6968. * Constructs a modifiable permissions object with existing permissions
  6969. - * @param username
  6970. + * @param credentials
  6971. * @param permissions
  6972. */
  6973. - public ModifiablePermissions(String username, Map<Integer, PermissionType> permissions) {
  6974. - this.username = username;
  6975. + public ModifiablePermissions(PlayerCredentials credentials, Map<Integer, PermissionType> permissions) {
  6976. + this.credentials = credentials;
  6977. this.permissions = permissions;
  6978. }
  6979.  
  6980. @@ -136,8 +145,8 @@ public class ModifiablePermissions {
  6981. PreparedStatement statement = null;
  6982.  
  6983. try {
  6984. - statement = DBManager.prepareStatement("INSERT INTO player_permission VALUES (?, ?, ?)");
  6985. - statement.setString(1, username);
  6986. + statement = DBManager.prepareStatement("INSERT INTO player_permission (player_id, permissionid, disabled) VALUES (?, ?, ?)");
  6987. + statement.setString(1, credentials.getUniqueId().toString());
  6988. statement.setInt(2, id);
  6989. statement.setBoolean(3, type == PermissionType.DISABLED);
  6990. statement.execute();
  6991. @@ -156,8 +165,8 @@ public class ModifiablePermissions {
  6992. PreparedStatement statement = null;
  6993.  
  6994. try {
  6995. - statement = DBManager.prepareStatement("DELETE FROM player_permission WHERE lower(name) = ? AND permissionid = ?");
  6996. - statement.setString(1, username.toLowerCase());
  6997. + statement = DBManager.prepareStatement("DELETE FROM player_permission WHERE player_id = ? AND permissionid = ?");
  6998. + statement.setString(1, credentials.getUniqueId().toString());
  6999. statement.setInt(2, id);
  7000. statement.execute();
  7001. } catch (SQLException ex) {
  7002. diff --git a/src/net/innectis/innplugin/InnectisObjects/PresentContent.java b/src/net/innectis/innplugin/InnectisObjects/PresentContent.java
  7003. index 08c0b89cd..d1e36354f 100644
  7004. --- a/src/net/innectis/innplugin/InnectisObjects/PresentContent.java
  7005. +++ b/src/net/innectis/innplugin/InnectisObjects/PresentContent.java
  7006. @@ -3,12 +3,15 @@ package net.innectis.innplugin.InnectisObjects;
  7007. import java.sql.PreparedStatement;
  7008. import java.sql.ResultSet;
  7009. import java.sql.SQLException;
  7010. +import java.util.UUID;
  7011. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  7012. import net.innectis.innplugin.InnPlugin;
  7013. import net.innectis.innplugin.Items.IdpItemStack;
  7014. import net.innectis.innplugin.Items.IdpMaterial;
  7015. import net.innectis.innplugin.Items.SpecialItemType;
  7016. import net.innectis.innplugin.Items.StackBag;
  7017. +import net.innectis.innplugin.Player.PlayerCredentials;
  7018. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  7019. import net.innectis.innplugin.Utility.StringUtil;
  7020.  
  7021. /**
  7022. @@ -25,8 +28,8 @@ public class PresentContent {
  7023. public static final IdpMaterial PRESENT_MATERIAL = IdpMaterial.REDSTONE_LAMP_ON;
  7024. //
  7025. private int presentid;
  7026. - /** The name of the player who created the present */
  7027. - private String creator;
  7028. + /** The credentials of the player who created the present */
  7029. + private PlayerCredentials creatorCredentials;
  7030. private String title;
  7031. private long bagid;
  7032. private boolean opened;
  7033. @@ -38,16 +41,16 @@ public class PresentContent {
  7034.  
  7035. /**
  7036. * Makes a new present without items
  7037. - * @param creator
  7038. + * @param creatorCredentials
  7039. * @param title
  7040. */
  7041. - public PresentContent(String creator, String title) {
  7042. - this(-1, creator, title, false, -1, null);
  7043. + public PresentContent(PlayerCredentials creatorCredentials, String title) {
  7044. + this(-1, creatorCredentials, title, false, -1, null);
  7045. }
  7046.  
  7047. - private PresentContent(int presentid, String creator, String title, boolean opened, long bagid, IdpItemStack[] items) {
  7048. + private PresentContent(int presentid, PlayerCredentials creatorCredentials, String title, boolean opened, long bagid, IdpItemStack[] items) {
  7049. this.presentid = presentid;
  7050. - this.creator = creator;
  7051. + this.creatorCredentials = creatorCredentials;
  7052. this.title = title;
  7053. this.opened = opened;
  7054. this.bagid = bagid;
  7055. @@ -62,12 +65,20 @@ public class PresentContent {
  7056. return presentid;
  7057. }
  7058.  
  7059. + /**
  7060. + * Gets the credentials of the creator of this present
  7061. + * @return
  7062. + */
  7063. + public PlayerCredentials getCreatorCredentials() {
  7064. + return creatorCredentials;
  7065. + }
  7066. +
  7067. /**
  7068. * The name of the player who made the present.
  7069. * @return
  7070. */
  7071. public String getCreator() {
  7072. - return creator;
  7073. + return creatorCredentials.getName();
  7074. }
  7075.  
  7076. /**
  7077. @@ -148,8 +159,8 @@ public class PresentContent {
  7078. bag.save();
  7079. this.bagid = bag.getBagid();
  7080.  
  7081. - statement = DBManager.prepareStatementWithAutoGeneratedKeys(" INSERT INTO presents (creator, title, bagid) VALUES (?,?,?) ");
  7082. - statement.setString(1, creator);
  7083. + statement = DBManager.prepareStatementWithAutoGeneratedKeys(" INSERT INTO presents (creator_id, title, bagid) VALUES (?,?,?) ");
  7084. + statement.setString(1, creatorCredentials.getUniqueId().toString());
  7085. statement.setString(2, title);
  7086. statement.setLong(3, bag.getBagid());
  7087. statement.executeUpdate();
  7088. @@ -202,24 +213,32 @@ public class PresentContent {
  7089. ResultSet set = null;
  7090.  
  7091. try {
  7092. - statement = DBManager.prepareStatement(" SELECT creator, title, bagid, opened FROM presents WHERE presentid = ? ");
  7093. + statement = DBManager.prepareStatement(" SELECT creator_id, title, bagid, opened FROM presents WHERE presentid = ? ");
  7094. statement.setInt(1, presentid);
  7095. set = statement.executeQuery();
  7096.  
  7097. long bagid = 0;
  7098. - String creator = "";
  7099. + String creatorIdString = "";
  7100. + UUID creatorId = null;
  7101. + PlayerCredentials creatorCredentials = null;
  7102. String title = "";
  7103. boolean opened = false;
  7104. +
  7105. if (set.next()) {
  7106. bagid = set.getLong("bagid");
  7107. - creator = set.getString("creator");
  7108. +
  7109. + creatorIdString = set.getString("creator_id");
  7110. + creatorId = UUID.fromString(creatorIdString);
  7111. + creatorCredentials = PlayerCredentialsManager.getByUniqueId(creatorId);
  7112. +
  7113. title = set.getString("title");
  7114. opened = set.getBoolean("opened");
  7115. }
  7116. +
  7117. if (bagid > 0) {
  7118. StackBag bag = StackBag.getContentbag(bagid);
  7119.  
  7120. - return new PresentContent(presentid, creator, title, opened, bagid, bag.getContents());
  7121. + return new PresentContent(presentid, creatorCredentials, title, opened, bagid, bag.getContents());
  7122. }
  7123. } catch (SQLException ex) {
  7124. InnPlugin.logError("Error loading present!", ex);
  7125. @@ -242,7 +261,6 @@ public class PresentContent {
  7126. }
  7127.  
  7128. if (item.getItemdata().getSpecialItem() == SpecialItemType.PRESENT) {
  7129. -
  7130. String presentid = item.getItemdata().getValue(PresentContent.PRESENT_TAG);
  7131.  
  7132. if (StringUtil.stringIsNullOrEmpty(presentid)) {
  7133. @@ -256,6 +274,7 @@ public class PresentContent {
  7134. return null;
  7135. }
  7136. }
  7137. +
  7138. return null;
  7139. }
  7140.  
  7141. diff --git a/src/net/innectis/innplugin/InnectisObjects/StaffMessage.java b/src/net/innectis/innplugin/InnectisObjects/StaffMessage.java
  7142. index 976e7a6cb..772e0e94c 100644
  7143. --- a/src/net/innectis/innplugin/InnectisObjects/StaffMessage.java
  7144. +++ b/src/net/innectis/innplugin/InnectisObjects/StaffMessage.java
  7145. @@ -6,6 +6,7 @@ import java.sql.SQLException;
  7146. import java.util.Date;
  7147. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  7148. import net.innectis.innplugin.InnPlugin;
  7149. +import net.innectis.innplugin.Player.PlayerCredentials;
  7150.  
  7151. /**
  7152. * A simple message for staff members to read
  7153. @@ -16,20 +17,23 @@ public class StaffMessage extends Message {
  7154. /**
  7155. * Constructs a new staff message (no ID present)
  7156. * @param date
  7157. + * @param creatorCredentials
  7158. * @param message
  7159. */
  7160. - public StaffMessage(Date date, String creator, String message) {
  7161. - this(0, date, false, creator, message);
  7162. + public StaffMessage(Date date, PlayerCredentials creatorCredentials, String message) {
  7163. + this(0, date, false, creatorCredentials, message);
  7164. }
  7165.  
  7166. /**
  7167. * Constructs a staff message from the given parameters
  7168. * @param id
  7169. * @param date
  7170. + * @param read
  7171. + * @param creatorCredentials
  7172. * @param message
  7173. */
  7174. - public StaffMessage(int id, Date date, boolean read, String creator, String message) {
  7175. - super(id, date, read, creator, message);
  7176. + public StaffMessage(int id, Date date, boolean read, PlayerCredentials creatorCredentials, String message) {
  7177. + super(id, date, read, creatorCredentials, message);
  7178. }
  7179.  
  7180. /**
  7181. @@ -47,10 +51,10 @@ public class StaffMessage extends Message {
  7182. statement.setInt(2, id);
  7183. statement.executeUpdate();
  7184. } else {
  7185. - statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO staff_requests (datecreated, hasread, creator, message) VALUES (?, ?, ?, ?)");
  7186. + statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO staff_requests (datecreated, hasread, creator_player_id, message) VALUES (?, ?, ?, ?)");
  7187. statement.setDate(1, new java.sql.Date(date.getTime()));
  7188. statement.setBoolean(2, read);
  7189. - statement.setString(3, creator);
  7190. + statement.setString(3, super.getCreatorCredentials().getUniqueId().toString());
  7191. statement.setString(4, message);
  7192. statement.execute();
  7193.  
  7194. diff --git a/src/net/innectis/innplugin/InnectisObjects/TheEndPot.java b/src/net/innectis/innplugin/InnectisObjects/TheEndPot.java
  7195. index 101af6f92..fa5772055 100644
  7196. --- a/src/net/innectis/innplugin/InnectisObjects/TheEndPot.java
  7197. +++ b/src/net/innectis/innplugin/InnectisObjects/TheEndPot.java
  7198. @@ -4,6 +4,7 @@ import java.sql.PreparedStatement;
  7199. import java.sql.ResultSet;
  7200. import java.sql.SQLException;
  7201. import java.util.HashMap;
  7202. +import java.util.UUID;
  7203. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  7204. import net.innectis.innplugin.InnPlugin;
  7205.  
  7206. @@ -15,28 +16,30 @@ import net.innectis.innplugin.InnPlugin;
  7207. * @author AlphaBlend
  7208. */
  7209. public class TheEndPot {
  7210. - private static HashMap<String, Integer> valutaPot = new HashMap<String, Integer>();
  7211. + private static HashMap<UUID, Integer> valutaPot = new HashMap<UUID, Integer>();
  7212.  
  7213. /**
  7214. - * Adds a value to the pot by the specified player
  7215. - * @param player
  7216. + * Adds a value to the pot by the specified player represented by their ID
  7217. + * @param playerId
  7218. + * @param playerName
  7219. * @param amount
  7220. + * @return
  7221. */
  7222. - public static boolean addValue(String player, int amount) {
  7223. + public static boolean addValue(UUID playerId, String playerName, int amount) {
  7224. int total = amount;
  7225. boolean update = false;
  7226.  
  7227. - if (valutaPot.containsKey(player.toLowerCase())) {
  7228. - total += valutaPot.get(player.toLowerCase());
  7229. + if (valutaPot.containsKey(playerId)) {
  7230. + total += valutaPot.get(playerId);
  7231. update = true;
  7232. }
  7233.  
  7234. - boolean result = addValueToDatabase(player, amount, update);
  7235. + boolean result = addValueToDatabase(playerId, playerName, amount, update);
  7236.  
  7237. // Make sure there are no errors adding to the database, then add
  7238. // to the map if the operation is successful
  7239. if (result) {
  7240. - valutaPot.put(player.toLowerCase(), total);
  7241. + valutaPot.put(playerId, total);
  7242. }
  7243.  
  7244. return result;
  7245. @@ -44,14 +47,14 @@ public class TheEndPot {
  7246.  
  7247. /**
  7248. * Gets the value of the pot contributed from the specified player
  7249. - * @param player
  7250. + * @param playerId
  7251. * @return
  7252. */
  7253. - public int getValue(String player) {
  7254. + public int getValue(UUID playerId) {
  7255. int value = 0;
  7256.  
  7257. - if (valutaPot.containsKey(player.toLowerCase())) {
  7258. - value = valutaPot.get(player.toLowerCase());
  7259. + if (valutaPot.containsKey(playerId)) {
  7260. + value = valutaPot.get(playerId);
  7261. }
  7262.  
  7263. return value;
  7264. @@ -106,9 +109,10 @@ public class TheEndPot {
  7265. set = statement.executeQuery();
  7266.  
  7267. while (set.next()) {
  7268. - String player = set.getString("player");
  7269. + String playerIdString = set.getString("player_id");
  7270. + UUID playerId = UUID.fromString(playerIdString);
  7271. int amount = set.getInt("value");
  7272. - valutaPot.put(player, amount);
  7273. + valutaPot.put(playerId, amount);
  7274. }
  7275. } catch (SQLException ex) {
  7276. InnPlugin.logError("Could not load The End pot!", ex);
  7277. @@ -120,27 +124,27 @@ public class TheEndPot {
  7278.  
  7279. /**
  7280. * Adds the specified player's valuta value to the database
  7281. - * @param player
  7282. + * @param playerId
  7283. * @param value
  7284. * @param update
  7285. */
  7286. - private static boolean addValueToDatabase(String player, int value, boolean update) {
  7287. + private static boolean addValueToDatabase(UUID playerId, String playerName, int value, boolean update) {
  7288. PreparedStatement statement = null;
  7289.  
  7290. try {
  7291. if (update) {
  7292. - statement = DBManager.prepareStatement("UPDATE the_end_pot SET value = value + ? WHERE lower(player) = ?;");
  7293. + statement = DBManager.prepareStatement("UPDATE the_end_pot SET value = value + ? WHERE player_id = ?;");
  7294. statement.setInt(1, value);
  7295. - statement.setString(2, player.toLowerCase());
  7296. + statement.setString(2, playerId.toString());
  7297. statement.executeUpdate();
  7298. } else {
  7299. - statement = DBManager.prepareStatement("INSERT INTO the_end_pot VALUES (?, ?);");
  7300. - statement.setString(1, player.toLowerCase());
  7301. + statement = DBManager.prepareStatement("INSERT INTO the_end_pot (player_id, value) VALUES (?, ?);");
  7302. + statement.setString(1, playerId.toString());
  7303. statement.setInt(2, value);
  7304. statement.execute();
  7305. }
  7306. } catch (SQLException ex) {
  7307. - InnPlugin.logError("Unable to update The End pot value for " + player + "!", ex);
  7308. + InnPlugin.logError("Unable to update The End pot value for player " + playerName + "!", ex);
  7309. return false;
  7310. } finally {
  7311. DBManager.closePreparedStatement(statement);
  7312. diff --git a/src/net/innectis/innplugin/InnectisObjects/TransactionObject.java b/src/net/innectis/innplugin/InnectisObjects/TransactionObject.java
  7313. index 22a190fee..b801cccf0 100644
  7314. --- a/src/net/innectis/innplugin/InnectisObjects/TransactionObject.java
  7315. +++ b/src/net/innectis/innplugin/InnectisObjects/TransactionObject.java
  7316. @@ -2,6 +2,7 @@ package net.innectis.innplugin.InnectisObjects;
  7317.  
  7318. import java.sql.PreparedStatement;
  7319. import java.sql.SQLException;
  7320. +import java.util.UUID;
  7321. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  7322. import net.innectis.innplugin.Handlers.TransactionHandler.TransactionType;
  7323. import net.innectis.innplugin.InnPlugin;
  7324. @@ -12,8 +13,8 @@ import net.innectis.innplugin.InnPlugin;
  7325. * @author AlphaBlend
  7326. */
  7327. public class TransactionObject {
  7328. -
  7329. - private String player;
  7330. + private UUID playerId;
  7331. + private String playerName;
  7332. private int valutas;
  7333. private int valutasInBank;
  7334. private int valutasToBank;
  7335. @@ -22,8 +23,9 @@ public class TransactionObject {
  7336. private int referralPoints;
  7337. private int votePoints;
  7338.  
  7339. - public TransactionObject(String player, int valutas, int valutasInBank, int valutasToBank, int valutasToPlayer, int pvpPoints, int referPoints, int votePoints) {
  7340. - this.player = player;
  7341. + public TransactionObject(UUID playerId, String playerName, int valutas, int valutasInBank, int valutasToBank, int valutasToPlayer, int pvpPoints, int referPoints, int votePoints) {
  7342. + this.playerId = playerId;
  7343. + this.playerName = playerName;
  7344. this.valutas = valutas;
  7345. this.valutasInBank = valutasInBank;
  7346. this.valutasToBank = valutasToBank;
  7347. @@ -120,8 +122,7 @@ public class TransactionObject {
  7348. * This immediately updates to the database, so no need to do it manually
  7349. *
  7350. * @param value a value greater than zero
  7351. - * @param currency
  7352. - * @return
  7353. + * @param tt
  7354. */
  7355. public void subtractValue(int value, TransactionType tt) {
  7356. int targetValue;
  7357. @@ -167,8 +168,7 @@ public class TransactionObject {
  7358. * This immediately updates to the database, so no need to do it manually
  7359. *
  7360. * @param value a value greater than zero
  7361. - * @param transaction
  7362. - * @return
  7363. + * @param tt
  7364. */
  7365. public void setValue(int value, TransactionType tt) {
  7366. switch (tt) {
  7367. @@ -204,7 +204,7 @@ public class TransactionObject {
  7368. * Updates the value of the specified transaction type to the database
  7369. *
  7370. * @param value
  7371. - * @param currency
  7372. + * @param tt
  7373. */
  7374. private void updateDatabase(Number value, TransactionType tt) {
  7375. PreparedStatement statement = null;
  7376. @@ -238,12 +238,12 @@ public class TransactionObject {
  7377. throw new IllegalStateException("TransactionType " + tt + " not supported");
  7378. }
  7379.  
  7380. - statement = DBManager.prepareStatement("UPDATE players SET " + columnName + " = ? WHERE lower(name) = ?");
  7381. + statement = DBManager.prepareStatement("UPDATE players SET " + columnName + " = ? WHERE player_id = ?");
  7382. statement.setInt(1, value.intValue());
  7383. - statement.setString(2, player.toLowerCase());
  7384. + statement.setString(2, playerId.toString());
  7385. statement.execute();
  7386. } catch (SQLException ex) {
  7387. - InnPlugin.logError("Unable to update " + tt.getName() + "!", ex);
  7388. + InnPlugin.logError("Unable to update " + tt.getName() + " in database for player " + playerName + "!", ex);
  7389. } finally {
  7390. DBManager.closePreparedStatement(statement);
  7391. }
  7392. diff --git a/src/net/innectis/innplugin/Listeners/Bukkit/BukkitEntityListner.java b/src/net/innectis/innplugin/Listeners/Bukkit/BukkitEntityListner.java
  7393. index e30d9c523..eb5e11f00 100644
  7394. --- a/src/net/innectis/innplugin/Listeners/Bukkit/BukkitEntityListner.java
  7395. +++ b/src/net/innectis/innplugin/Listeners/Bukkit/BukkitEntityListner.java
  7396. @@ -40,12 +40,15 @@ import net.innectis.innplugin.Player.IdpPlayerInventory;
  7397. import net.innectis.innplugin.Player.InventoryType;
  7398. import net.innectis.innplugin.Player.Permission;
  7399. import net.innectis.innplugin.Player.PlayerBackpack;
  7400. +import net.innectis.innplugin.Player.PlayerCredentials;
  7401. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  7402. import net.innectis.innplugin.Player.PlayerGroup;
  7403. import net.innectis.innplugin.Player.PlayerSession;
  7404. import net.innectis.innplugin.Player.PlayerSession.PlayerStatus;
  7405. import net.innectis.innplugin.Player.PlayerSettings;
  7406. import net.innectis.innplugin.Tasking.SyncTasks.TheEndUnloadTask;
  7407. import net.innectis.innplugin.Utility.StringUtil;
  7408. +import org.bukkit.Bukkit;
  7409. import org.bukkit.DyeColor;
  7410. import org.bukkit.Location;
  7411. import org.bukkit.Material;
  7412. @@ -220,6 +223,7 @@ public class BukkitEntityListner implements InnBukkitListener {
  7413.  
  7414. location.setY(location.getWorld().getHighestBlockYAt(location) + 2);
  7415. player.teleport(location);
  7416. + Bukkit.broadcastMessage("Teleporting to somewhere in main world!");
  7417. }
  7418. } else {
  7419. if (event.getEntityType() == EntityType.DROPPED_ITEM) {
  7420. @@ -440,7 +444,7 @@ public class BukkitEntityListner implements InnBukkitListener {
  7421. if (getId > 0) {
  7422. InnectisWaypoint waypoint = WaypointHandler.getWaypoint(getId);
  7423.  
  7424. - if (waypoint != null && (waypoint.canPlayerAccess(player)
  7425. + if (waypoint != null && (waypoint.canPlayerAccess(player.getName())
  7426. || player.hasPermission(Permission.owned_object_override))) {
  7427. loc = waypoint.getDestination();
  7428. }
  7429. @@ -966,7 +970,7 @@ public class BukkitEntityListner implements InnBukkitListener {
  7430. }
  7431.  
  7432. if (dropValutas) {
  7433. - TransactionObject transaction = TransactionHandler.getTransactionObject(player.getName());
  7434. + TransactionObject transaction = TransactionHandler.getTransactionObject(player.getUniqueId(), player.getName());
  7435. int valutas = transaction.getValue(TransactionType.VALUTAS);
  7436.  
  7437. if (valutas > 0) {
  7438. @@ -1003,7 +1007,7 @@ public class BukkitEntityListner implements InnBukkitListener {
  7439.  
  7440. // Set inventory and save
  7441. try {
  7442. - IdpPlayerInventory inv = new IdpPlayerInventory(player.getName(), player.getInventory().getType(), items,
  7443. + IdpPlayerInventory inv = new IdpPlayerInventory(player.getUniqueId(), player.getName(), player.getInventory().getType(), items,
  7444. IdpItemStack.fromBukkitItemStack(player.getInventory().getBukkitArmorItems()),
  7445. bukkitPlayer.getExp(),
  7446. bukkitPlayer.getLevel(), -1, player.getFoodLevel());
  7447. @@ -1016,7 +1020,8 @@ public class BukkitEntityListner implements InnBukkitListener {
  7448.  
  7449. // If Hardcore is set, lets ban the player
  7450. if (lot != null && lot.isFlagSet(LotFlagType.HARDCORE)) {
  7451. - lot.banUser(player.getName());
  7452. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName(), true);
  7453. + lot.banUser(credentials);
  7454. }
  7455.  
  7456. // Update player status
  7457. @@ -1187,7 +1192,7 @@ public class BukkitEntityListner implements InnBukkitListener {
  7458. // not have the nodamage flag
  7459. if (lot == null || !lot.isFlagSet(LotFlagType.NODAMAGE)) {
  7460. int pts = getPointTakenByGroup(player.getGroup());
  7461. - TransactionObject transaction = TransactionHandler.getTransactionObject(player.getName());
  7462. + TransactionObject transaction = TransactionHandler.getTransactionObject(player.getUniqueId(), player.getName());
  7463. int votepts = transaction.getValue(TransactionType.VOTE_POINTS);
  7464.  
  7465. if (votepts >= pts) {
  7466. diff --git a/src/net/innectis/innplugin/Listeners/Bukkit/BukkitHangingListener.java b/src/net/innectis/innplugin/Listeners/Bukkit/BukkitHangingListener.java
  7467. index a8cb840e7..f444e7415 100644
  7468. --- a/src/net/innectis/innplugin/Listeners/Bukkit/BukkitHangingListener.java
  7469. +++ b/src/net/innectis/innplugin/Listeners/Bukkit/BukkitHangingListener.java
  7470. @@ -72,7 +72,7 @@ public class BukkitHangingListener implements InnBukkitListener {
  7471. // Unrestrict reszone
  7472. IdpWorld world = IdpWorldFactory.getWorld(loc.getWorld().getName());
  7473. if (world.getActingWorldType() == IdpWorldType.RESWORLD
  7474. - && (lot == null || lot.canPlayerAccess(player) || player.hasPermission(Permission.world_build_unrestricted))) {
  7475. + && (lot == null || lot.canPlayerAccess(player.getName()) || player.hasPermission(Permission.world_build_unrestricted))) {
  7476. return;
  7477. }
  7478.  
  7479. @@ -131,7 +131,7 @@ public class BukkitHangingListener implements InnBukkitListener {
  7480. }
  7481. }
  7482.  
  7483. - LogManager.getBlockLogger().logEntityAction(player.getName(), event.getEntity(), BlockLogger.BlockAction.ENTITY_BREAK);
  7484. + LogManager.getBlockLogger().logEntityAction(player.getUniqueId(), event.getEntity(), BlockLogger.BlockAction.ENTITY_BREAK);
  7485. return;
  7486. }
  7487. }
  7488. @@ -157,7 +157,7 @@ public class BukkitHangingListener implements InnBukkitListener {
  7489. IdpWorld world = IdpWorldFactory.getWorld(loc.getWorld().getName());
  7490.  
  7491. if (world.getActingWorldType() == IdpWorldType.RESWORLD
  7492. - && (lot == null || lot.canPlayerAccess(player) || player.hasPermission(Permission.world_build_unrestricted))) {
  7493. + && (lot == null || lot.canPlayerAccess(player.getName()) || player.hasPermission(Permission.world_build_unrestricted))) {
  7494. return;
  7495. }
  7496.  
  7497. @@ -181,6 +181,6 @@ public class BukkitHangingListener implements InnBukkitListener {
  7498. event.setCancelled(true);
  7499. return;
  7500. }
  7501. - LogManager.getBlockLogger().logEntityAction(player.getName(), event.getEntity(), BlockLogger.BlockAction.ENTITY_PLACE);
  7502. + LogManager.getBlockLogger().logEntityAction(player.getUniqueId(), event.getEntity(), BlockLogger.BlockAction.ENTITY_PLACE);
  7503. }
  7504. }
  7505. diff --git a/src/net/innectis/innplugin/Listeners/Bukkit/BukkitInventoryListener.java b/src/net/innectis/innplugin/Listeners/Bukkit/BukkitInventoryListener.java
  7506. index fd523d826..e871cd225 100644
  7507. --- a/src/net/innectis/innplugin/Listeners/Bukkit/BukkitInventoryListener.java
  7508. +++ b/src/net/innectis/innplugin/Listeners/Bukkit/BukkitInventoryListener.java
  7509. @@ -4,6 +4,7 @@ import java.util.ArrayList;
  7510. import java.util.List;
  7511. import java.util.Map;
  7512. import java.util.Map.Entry;
  7513. +import java.util.UUID;
  7514. import net.innectis.innplugin.Handlers.TransactionHandler;
  7515. import net.innectis.innplugin.Handlers.TransactionHandler.TransactionType;
  7516. import net.innectis.innplugin.InnPlugin;
  7517. @@ -37,6 +38,8 @@ import net.innectis.innplugin.Player.IdpPlayerInventory;
  7518. import net.innectis.innplugin.Player.InventoryType;
  7519. import net.innectis.innplugin.Player.Permission;
  7520. import net.innectis.innplugin.Player.PlayerBackpack;
  7521. +import net.innectis.innplugin.Player.PlayerCredentials;
  7522. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  7523. import net.innectis.innplugin.Player.PlayerSession;
  7524. import net.innectis.innplugin.Player.PlayerSession.PlayerStatus;
  7525. import net.innectis.innplugin.Shop.ShopHandler;
  7526. @@ -191,7 +194,9 @@ public final class BukkitInventoryListener implements InnBukkitListener {
  7527. if (player != null) {
  7528. session = player.getSession();
  7529. } else {
  7530. - session = PlayerSession.getSession(ownedEntity.getOwner(), plugin);
  7531. + PlayerCredentials credentials = ownedEntity.getOwnerCredentials();
  7532. +
  7533. + session = PlayerSession.getSession(credentials.getUniqueId(), credentials.getName(), plugin, true);
  7534. tempSession = true;
  7535. }
  7536.  
  7537. @@ -254,7 +259,8 @@ public final class BukkitInventoryListener implements InnBukkitListener {
  7538. if (testPlayer != null) {
  7539. session = testPlayer.getSession();
  7540. } else {
  7541. - session = PlayerSession.getSession(ownedEntity.getOwner(), plugin);
  7542. + PlayerCredentials credentials = ownedEntity.getOwnerCredentials();
  7543. + session = PlayerSession.getSession(credentials.getUniqueId(), credentials.getName(), plugin, true);
  7544. tempSession = true;
  7545. }
  7546.  
  7547. @@ -434,7 +440,7 @@ public final class BukkitInventoryListener implements InnBukkitListener {
  7548. if (!error && rawSlot < 54 && event.isLeftClick()) {
  7549. RewardItem reward = RewardItem.fromSlot(rawSlot);
  7550. if (reward != null) {
  7551. - TransactionObject transaction = TransactionHandler.getTransactionObject(player.getName());
  7552. + TransactionObject transaction = TransactionHandler.getTransactionObject(player.getUniqueId(), player.getName());
  7553. int votePoints = transaction.getValue(TransactionType.VOTE_POINTS);
  7554.  
  7555. if (votePoints >= reward.getCost()) {
  7556. @@ -628,8 +634,9 @@ public final class BukkitInventoryListener implements InnBukkitListener {
  7557. }
  7558.  
  7559. if (session.isViewingBackpack()) {
  7560. + UUID backpackOwnerId = session.getBackpackOwnerId();
  7561. String backpackOwner = session.getBackpackOwner();
  7562. - boolean self = backpackOwner.equalsIgnoreCase(player.getName());
  7563. + boolean self = backpackOwnerId.equals(player.getUniqueId());
  7564.  
  7565. ItemStack[] stack = event.getInventory().getContents();
  7566. IdpItemStack[] newStack = new IdpItemStack[stack.length];
  7567. @@ -643,19 +650,19 @@ public final class BukkitInventoryListener implements InnBukkitListener {
  7568. if (self) {
  7569. backpack = session.getBackpack();
  7570. } else {
  7571. - IdpPlayer testPlayer = plugin.getPlayer(backpackOwner);
  7572. + IdpPlayer testPlayer = plugin.getPlayer(backpackOwnerId);
  7573.  
  7574. if (testPlayer != null) {
  7575. backpack = testPlayer.getSession().getBackpack();
  7576. } else {
  7577. - backpack = PlayerBackpack.loadBackpackFromDB(backpackOwner);
  7578. + backpack = PlayerBackpack.loadBackpackFromDB(backpackOwnerId, backpackOwner);
  7579. }
  7580. }
  7581.  
  7582. backpack.setItems(newStack);
  7583. backpack.save();
  7584.  
  7585. - IdpInventory inv = plugin.getBackpackView(backpackOwner);
  7586. + IdpInventory inv = plugin.getBackpackView(backpackOwnerId);
  7587.  
  7588. if (inv == null) {
  7589. player.printError("Internal server error.");
  7590. @@ -666,7 +673,7 @@ public final class BukkitInventoryListener implements InnBukkitListener {
  7591. inv.getViewers().remove(event.getPlayer());
  7592.  
  7593. if (inv.getViewers().isEmpty()) {
  7594. - plugin.removeBackpackView(backpackOwner);
  7595. + plugin.removeBackpackView(backpackOwnerId);
  7596. }
  7597.  
  7598. session.clearBackpackOwner();
  7599. @@ -677,9 +684,11 @@ public final class BukkitInventoryListener implements InnBukkitListener {
  7600. session.setViewingEnderChest(false);
  7601.  
  7602. String name = session.getEnderchestOwner();
  7603. + UUID ownerId = session.getEnderchestOwnerId();
  7604. EnderContentsType type = session.getEnderchestType();
  7605.  
  7606. session.setEnderchestOwner(null);
  7607. + session.setEnderchestOwnerId(null);
  7608. session.setEnderchestType(null);
  7609.  
  7610. IdpItemStack[] items = new IdpItemStack[27];
  7611. @@ -693,7 +702,8 @@ public final class BukkitInventoryListener implements InnBukkitListener {
  7612. }
  7613.  
  7614. // If no one is viewing this ender chest, remove it from our list
  7615. - EnderChestView view = plugin.getEnderChestView(name, type);
  7616. + EnderChestView view = plugin.getEnderChestView(ownerId, type);
  7617. +
  7618. if (view == null) {
  7619. StrangeErrorLogger serrorLogger = LogManager.getStrangeErrorLogger();
  7620.  
  7621. @@ -713,7 +723,8 @@ public final class BukkitInventoryListener implements InnBukkitListener {
  7622. }
  7623.  
  7624. // Get the chestobject
  7625. - EnderChestContents contents = EnderChestContents.getContents(name, type);
  7626. + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(ownerId);
  7627. + EnderChestContents contents = EnderChestContents.getContents(credentials, type);
  7628.  
  7629. if (contents != null) {
  7630. // Set the new items and update
  7631. @@ -787,11 +798,12 @@ public final class BukkitInventoryListener implements InnBukkitListener {
  7632. if (session.isViewingOtherInventory()) {
  7633. IdpContainer container = new IdpContainer(event.getInventory());
  7634.  
  7635. + UUID inventoryOwnerId = session.getViewedInventoryOwnerId();
  7636. String inventoryOwner = session.getViewedInventoryOwner();
  7637. InventoryType type = session.getViewedInventoryType();
  7638. boolean updated = false;
  7639.  
  7640. - IdpPlayer testPlayer = plugin.getPlayer(inventoryOwner);
  7641. + IdpPlayer testPlayer = plugin.getPlayer(inventoryOwnerId);
  7642. // They came online after we were viewing their inventory
  7643. if (testPlayer != null) {
  7644. if (testPlayer.getSession().getPlayerStatus() == PlayerStatus.DEAD_PLAYER) {
  7645. @@ -814,7 +826,7 @@ public final class BukkitInventoryListener implements InnBukkitListener {
  7646.  
  7647. // If the inventory hasn't yet been updated, let's save it
  7648. if (!updated && type != InventoryType.NO_SAVE) {
  7649. - IdpPlayerInventory inv = IdpPlayerInventory.load(inventoryOwner, type, plugin);
  7650. + IdpPlayerInventory inv = IdpPlayerInventory.load(inventoryOwnerId, inventoryOwner, type, plugin);
  7651. inv.setItems(container.getNonArmorItems());
  7652. inv.setArmorItems(container.getArmorItems());
  7653. inv.store();
  7654. diff --git a/src/net/innectis/innplugin/Listeners/Bukkit/BukkitPlayerActionListener.java b/src/net/innectis/innplugin/Listeners/Bukkit/BukkitPlayerActionListener.java
  7655. index 28ee1bbec..dd10dc117 100644
  7656. --- a/src/net/innectis/innplugin/Listeners/Bukkit/BukkitPlayerActionListener.java
  7657. +++ b/src/net/innectis/innplugin/Listeners/Bukkit/BukkitPlayerActionListener.java
  7658. @@ -39,7 +39,6 @@ import net.innectis.innplugin.Player.PlayerSession.PlayerStatus;
  7659. import net.innectis.innplugin.Tasking.LimitedTask;
  7660. import net.innectis.innplugin.Tasking.RunBehaviour;
  7661. import net.innectis.innplugin.Utility.DateUtil;
  7662. -import net.innectis.innplugin.Utility.NumberUtil;
  7663. import net.innectis.innplugin.Utility.StringUtil;
  7664. import org.bukkit.GameMode;
  7665. import org.bukkit.Location;
  7666. @@ -89,13 +88,13 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
  7667. // are allowed to light up blocks
  7668. Location locBelow = player.getLocation().subtract(0, 1, 0);
  7669. if (player.hasLightSourceConditions(locBelow, stack)) {
  7670. - if (!LightsourceHandler.isLightingBlock(player.getName())) {
  7671. - LightsourceHandler.lightBlock(player.getName(), locBelow);
  7672. + if (!LightsourceHandler.isLightingBlock(player.getUniqueId())) {
  7673. + LightsourceHandler.lightBlock(player.getUniqueId(), locBelow);
  7674. }
  7675. } else {
  7676. // Turn their light off if they're currently lighting a block
  7677. - if (LightsourceHandler.isLightingBlock(player.getName())) {
  7678. - LightsourceHandler.unlightBlock(player.getName());
  7679. + if (LightsourceHandler.isLightingBlock(player.getUniqueId())) {
  7680. + LightsourceHandler.unlightBlock(player.getUniqueId());
  7681. }
  7682. }
  7683. }
  7684. @@ -217,7 +216,7 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
  7685. if (!event.getItem().hasMetadata(EntityConstants.METAKEY_DROPPED_ITEM)) {
  7686. //only lot members can pick up
  7687. if (itemLot != null && !itemLot.isFlagSet(LotFlagType.ITEMPICKUP)
  7688. - && !playerLot.canPlayerAccess(player)
  7689. + && !playerLot.canPlayerAccess(player.getName())
  7690. && !player.hasPermission(Permission.lot_ignoreflag_itempickup)) {
  7691. event.setCancelled(true);
  7692. }
  7693. @@ -234,7 +233,7 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
  7694. if (vorb != null) {
  7695. int value = vorb.getAmount();
  7696.  
  7697. - TransactionObject transaction = TransactionHandler.getTransactionObject(player.getName());
  7698. + TransactionObject transaction = TransactionHandler.getTransactionObject(player.getUniqueId(), player.getName());
  7699. transaction.addValue(value, TransactionType.VALUTAS);
  7700. player.printInfo("You have picked up " + value + " valuta" + (value != 1 ? "s" : "") + "!");
  7701. }
  7702. @@ -579,7 +578,7 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
  7703. int z = locTo.getBlockZ();
  7704.  
  7705. Location newLoc = new Location(bworld, x, y - 1, z);
  7706. - LightsourceHandler.lightBlock(player.getName(), newLoc);
  7707. + LightsourceHandler.lightBlock(player.getUniqueId(), newLoc);
  7708. }
  7709. }
  7710.  
  7711. @@ -816,19 +815,35 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
  7712. @EventHandler(priority = EventPriority.HIGH)
  7713. public void onPlayerPreLogin(AsyncPlayerPreLoginEvent event) {
  7714. String ipAddress = event.getAddress().getHostAddress();
  7715. - String username = event.getName();
  7716. - PlayerGroup group = PlayerGroup.getGroupOfUsername(username);
  7717. - String coloredName = group.getPrefix().getTextColor() + username;
  7718. -
  7719. + UUID playerId = event.getUniqueId();
  7720. + String playerName = event.getName();
  7721. + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(playerId);
  7722. + String coloredName = group.getPrefix().getTextColor() + playerName;
  7723. IdpPlayer testPlayer = null;
  7724. - if ((testPlayer = plugin.getPlayer(username, true)) != null) { //player is online!
  7725.  
  7726. + PlayerCredentials testCredentials = PlayerCredentialsManager.getByUniqueId(playerId);
  7727. +
  7728. + // This player renamed themselves, so let's update their credentials
  7729. + // If they are new, don't do anything, as they have no credentials yet
  7730. + if (testCredentials != null && !playerName.equalsIgnoreCase(testCredentials.getName())) {
  7731. + String oldColoredName = group.getPrefix().getTextColor() + testCredentials.getName();
  7732. +
  7733. + plugin.broadCastMessage(ChatColor.DARK_AQUA, "NOTICE: " + coloredName
  7734. + + ChatColor.DARK_AQUA + " has renamed themselves from " + oldColoredName
  7735. + + ChatColor.DARK_AQUA + ".");
  7736. +
  7737. + testCredentials.setName(playerName);
  7738. + testCredentials.update();
  7739. + // TODO: Log name changes
  7740. + }
  7741. +
  7742. + if ((testPlayer = plugin.getPlayer(playerId)) != null) { //player is online!
  7743. // If IP is the same, kick right away. Else kick if AFK
  7744. if (testPlayer.getSession().isAFK() || testPlayer.getHandle().getAddress().getAddress().getHostAddress().equals(ipAddress)) {
  7745. testPlayer.getHandle().kickPlayer("You logged in from another location!");
  7746. try {
  7747. // Get the playerfile and try to delete it
  7748. - File playerfile = new File(IdpWorldFactory.getWorld(IdpWorldType.INNECTIS).getHandle().getWorldFolder() + File.separator + "players" + File.separator + username + ".dat");
  7749. + File playerfile = new File(IdpWorldFactory.getWorld(IdpWorldType.INNECTIS).getHandle().getWorldFolder() + File.separator + "playerdata" + File.separator + playerId.toString() + ".dat");
  7750. if (playerfile.exists()) {
  7751. InnPlugin.logError("Deleting playerfile of '" + testPlayer.getName() + "' due to double login.");
  7752. playerfile.delete();
  7753. @@ -845,9 +860,12 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
  7754. return;
  7755. }
  7756.  
  7757. + // Skip login check if the player is new (has no credentials)
  7758. + boolean skipLoginCheck = (testCredentials == null);
  7759.  
  7760. - if (!PlayerSecurity.canLogin(username)) {
  7761. - event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_FULL, "Your entered your password wrong too many times...");
  7762. + // Only check if valid credentials (player might be new)
  7763. + if (!skipLoginCheck && !PlayerSecurity.canLogin(playerId, playerName)) {
  7764. + event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_FULL, "You entered your password wrong too many times...");
  7765. return;
  7766. }
  7767.  
  7768. @@ -858,15 +876,15 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
  7769. }
  7770.  
  7771. Timestamp stamp = new Timestamp(System.currentTimeMillis());
  7772. - IPLogger.logConnection(username, ipAddress, stamp);
  7773. + IPLogger.logConnection(playerId, playerName, ipAddress, stamp);
  7774.  
  7775. - BanTypes bannedType = BanHandler.getBanType(username, ipAddress);
  7776. + BanTypes bannedType = BanHandler.getBanType(playerId, ipAddress);
  7777.  
  7778. if (bannedType == BanTypes.NONE) {
  7779. return;
  7780. }
  7781.  
  7782. - BanObject ban = BanHandler.getBan(username);
  7783. + BanObject ban = BanHandler.getBan(playerId);
  7784. boolean isIPBan = ban != null && (ban instanceof IPBanObject);
  7785.  
  7786. switch (bannedType) {
  7787. @@ -896,15 +914,17 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
  7788. IPBanGroup ipGroup = BanHandler.getIPBanGroup(ipAddress);
  7789. StringBuilder sb = new StringBuilder();
  7790.  
  7791. - for (String player : ipGroup.getPlayers()) {
  7792. - PlayerGroup playerGroup = PlayerGroup.getGroupOfUsername(player);
  7793. - sb.append(playerGroup.getPrefix().getTextColor()).append(player).append(ChatColor.YELLOW).append(", ");
  7794. + for (PlayerCredentials pc : ipGroup.getPlayers()) {
  7795. + PlayerGroup playerGroup = PlayerGroup.getGroupOfPlayerById(pc.getUniqueId());
  7796. + sb.append(playerGroup.getPrefix().getTextColor()).append(pc.getName()).append(ChatColor.YELLOW).append(", ");
  7797. }
  7798. - String finalString = username + " shares an IP with the following IPBanned players: " + sb.toString().substring(0, sb.length() - 2);
  7799. +
  7800. + String finalString = playerName + " shares an IP with the following IPBanned players: " + sb.toString().substring(0, sb.length() - 2);
  7801.  
  7802. for (IdpPlayer p : plugin.getOnlineStaff(false)) {
  7803. p.printError("NOTICE: " + finalString);
  7804. }
  7805. +
  7806. InnPlugin.logInfo(ChatColor.RED + "NOTICE: " + finalString);
  7807.  
  7808. break;
  7809. @@ -1134,7 +1154,7 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
  7810. }
  7811.  
  7812. // Check if the player needs to login
  7813. - if (PlayerSecurity.hasPassword(innPlayer.getName())) {
  7814. + if (PlayerSecurity.hasPassword(innPlayer.getUniqueId(), innPlayer.getName())) {
  7815. session.setPlayerLoggedin(false);
  7816. }
  7817.  
  7818. @@ -1168,7 +1188,6 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
  7819. * Simple task that will check the security status of a player after 5ms.
  7820. */
  7821. private class CheckPlayerTask extends LimitedTask {
  7822. -
  7823. private IdpPlayer player;
  7824.  
  7825. public CheckPlayerTask(IdpPlayer player) {
  7826. @@ -1409,14 +1428,14 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
  7827. if (player.getHandle().getVehicle() != null) {
  7828. // If the player is in a vehicle while logging out, make sure to eject
  7829. // them if they are in a lot they do not own or operate, to prevent taking a vehicle
  7830. - if (lot != null && !(lot.canPlayerManage(player)
  7831. + if (lot != null && !(lot.canPlayerManage(player.getName())
  7832. || player.hasPermission(Permission.world_build_unrestricted))) {
  7833. player.getHandle().leaveVehicle();
  7834. }
  7835. }
  7836.  
  7837. if (lot != null && lot.isFlagSet(LotFlagType.NOMEMBERLOGOUTSPAWN)
  7838. - && !lot.canPlayerAccessIgnoreGeneric(player)
  7839. + && !lot.canPlayerAccessIgnoreGeneric(player.getName())
  7840. && !player.hasPermission(Permission.lot_ignoreflag_nomemberlogoutspawn)) {
  7841. player.teleport(WarpHandler.getSpawn());
  7842. }
  7843. @@ -1493,12 +1512,12 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
  7844. }
  7845.  
  7846. public static void handlePlayerLogout(IdpPlayer player) {
  7847. - if (LightsourceHandler.isLightingBlock(player.getName())) {
  7848. - LightsourceHandler.unlightBlock(player.getName());
  7849. + if (LightsourceHandler.isLightingBlock(player.getUniqueId())) {
  7850. + LightsourceHandler.unlightBlock(player.getUniqueId());
  7851. }
  7852.  
  7853. // Remove this from the cache, as it's no longer really needed unless requested
  7854. - TransactionHandler.removeTransactionObjectFromCache(player.getName());
  7855. + TransactionHandler.removeTransactionObjectFromCache(player.getUniqueId());
  7856.  
  7857. if (ChatChannelHandler.isGlobalListener(player.getName())) {
  7858. ChatChannelHandler.removeGlobalListener(player.getName());
  7859. @@ -1556,7 +1575,7 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
  7860. InnectisLot lot = LotHandler.getLot(entity.getLocation());
  7861.  
  7862. if (lot != null && lot.isFlagSet(LotFlagType.FARM)
  7863. - && !lot.canPlayerManage(player)
  7864. + && !lot.canPlayerManage(player.getName())
  7865. && !player.hasPermission(Permission.entity_canleadanywhere)) {
  7866. player.printError("Cannot leash entities here!");
  7867. event.setCancelled(true);
  7868. @@ -1583,7 +1602,7 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
  7869. InnectisLot lot = LotHandler.getLot(entity.getLocation());
  7870.  
  7871. if (lot != null && lot.isFlagSet(LotFlagType.FARM)
  7872. - && !lot.canPlayerManage(player)
  7873. + && !lot.canPlayerManage(player.getName())
  7874. && !player.hasPermission(Permission.entity_canleadanywhere)) {
  7875. player.printError("Cannot unleash entities here!");
  7876. event.setCancelled(true);
  7877. diff --git a/src/net/innectis/innplugin/Listeners/Bukkit/BukkitPlayerInteractionListener.java b/src/net/innectis/innplugin/Listeners/Bukkit/BukkitPlayerInteractionListener.java
  7878. index e5a6cd743..b11f85032 100644
  7879. --- a/src/net/innectis/innplugin/Listeners/Bukkit/BukkitPlayerInteractionListener.java
  7880. +++ b/src/net/innectis/innplugin/Listeners/Bukkit/BukkitPlayerInteractionListener.java
  7881. @@ -406,7 +406,7 @@ public class BukkitPlayerInteractionListener implements InnBukkitListener {
  7882.  
  7883. // Prevent fire from being extinguished by anyone but lot members or owner
  7884. if (IdpMaterial.fromBlock(block.getRelative(idpEvent.getBlockFace())) == IdpMaterial.FIRE) {
  7885. - if (lot != null && !lot.canPlayerAccess(player)
  7886. + if (lot != null && !lot.canPlayerAccess(player.getName())
  7887. && !player.hasPermission(Permission.build_block_fire)) {
  7888. event.setCancelled(true);
  7889. return;
  7890. @@ -683,7 +683,7 @@ public class BukkitPlayerInteractionListener implements InnBukkitListener {
  7891. && player.getItemStackInHand().getMaterial() == IdpMaterial.FISHING_ROD) {
  7892. InnectisLot lot = LotHandler.getLot(entity.getLocation());
  7893.  
  7894. - if (lot == null || lot.canPlayerManage(player)
  7895. + if (lot == null || lot.canPlayerManage(player.getName())
  7896. || player.hasPermission(Permission.entity_catchentitiesoverride)) {
  7897. String typeName = "thing";
  7898.  
  7899. @@ -731,7 +731,7 @@ public class BukkitPlayerInteractionListener implements InnBukkitListener {
  7900. InnectisLot lot = LotHandler.getLot(kickPlayer.getLocation());
  7901.  
  7902. if (lot != null && !kickPlayer.getSession().isStaff()
  7903. - && !lot.canPlayerManage(kickPlayer)) {
  7904. + && !lot.canPlayerManage(kickPlayer.getName())) {
  7905. kickPlayer.teleport(WarpHandler.getSpawn(kickPlayer.getGroup()));
  7906. player.printInfo("Kicked " + kickPlayer.getName() + " to spawn!");
  7907. return;
  7908. @@ -889,7 +889,7 @@ public class BukkitPlayerInteractionListener implements InnBukkitListener {
  7909. case WHEAT: {
  7910. if (!player.hasPermission(Permission.entity_canfeedanywhere)) {
  7911. InnectisLot lot = LotHandler.getLot(clickLocation, true);
  7912. - boolean canFeedAnimals = (lot == null || !lot.isFlagSet(LotFlagType.FARM) ? true : lot.canPlayerAccess(player));
  7913. + boolean canFeedAnimals = (lot == null || !lot.isFlagSet(LotFlagType.FARM) ? true : lot.canPlayerAccess(player.getName()));
  7914. if (!canFeedAnimals) {
  7915. player.printError("You cannot feed animals here!");
  7916. event.setCancelled(true);
  7917. @@ -901,7 +901,7 @@ public class BukkitPlayerInteractionListener implements InnBukkitListener {
  7918. case NAME_TAG: {
  7919. if (!player.hasPermission(Permission.entity_cannameanywhere)) {
  7920. InnectisLot lot = LotHandler.getLot(clickLocation, true);
  7921. - boolean canName = (lot == null || !lot.isFlagSet(LotFlagType.FARM) ? true : lot.canPlayerAccess(player));
  7922. + boolean canName = (lot == null || !lot.isFlagSet(LotFlagType.FARM) ? true : lot.canPlayerAccess(player.getName()));
  7923. if (!canName) {
  7924. player.printError("You cannot name animals here!");
  7925. event.setCancelled(true);
  7926. @@ -930,7 +930,7 @@ public class BukkitPlayerInteractionListener implements InnBukkitListener {
  7927. case LEAD: {
  7928. if (!player.hasPermission(Permission.entity_canleadanywhere)) {
  7929. InnectisLot lot = LotHandler.getLot(clickLocation, true);
  7930. - boolean canLead = (lot == null || !lot.isFlagSet(LotFlagType.FARM) ? true : lot.canPlayerAccess(player));
  7931. + boolean canLead = (lot == null || !lot.isFlagSet(LotFlagType.FARM) ? true : lot.canPlayerAccess(player.getName()));
  7932. if (!canLead) {
  7933. player.printError("You cannot leash animals here!");
  7934. event.setCancelled(true);
  7935. @@ -960,7 +960,7 @@ public class BukkitPlayerInteractionListener implements InnBukkitListener {
  7936. if ((entity instanceof Sheep || entity instanceof MushroomCow)
  7937. && !player.hasPermission(Permission.entity_canshearanywhere)) {
  7938. InnectisLot lot = LotHandler.getLot(clickLocation, true);
  7939. - boolean canShearAnimals = (lot == null || !lot.isFlagSet(LotFlagType.FARM) ? true : lot.canPlayerAccess(player));
  7940. + boolean canShearAnimals = (lot == null || !lot.isFlagSet(LotFlagType.FARM) ? true : lot.canPlayerAccess(player.getName()));
  7941. if (!canShearAnimals) {
  7942. player.printError("You cannot shear animals here!");
  7943. event.setCancelled(true);
  7944. @@ -990,7 +990,7 @@ public class BukkitPlayerInteractionListener implements InnBukkitListener {
  7945.  
  7946. // Check lot for farm flag
  7947. if (lot != null && lot.isFlagSet(LotFlagType.FARM)
  7948. - && !(lot.canPlayerAccess(player) || player.hasPermission(Permission.entity_recolourallsheeps))
  7949. + && !(lot.canPlayerAccess(player.getName()) || player.hasPermission(Permission.entity_recolourallsheeps))
  7950. && entity instanceof Sheep) {
  7951.  
  7952. player.printError("Go and brand your own sheep!");
  7953. diff --git a/src/net/innectis/innplugin/Listeners/Bukkit/IdpBlockListener.java b/src/net/innectis/innplugin/Listeners/Bukkit/IdpBlockListener.java
  7954. index e6a79d1b2..f103c22ee 100644
  7955. --- a/src/net/innectis/innplugin/Listeners/Bukkit/IdpBlockListener.java
  7956. +++ b/src/net/innectis/innplugin/Listeners/Bukkit/IdpBlockListener.java
  7957. @@ -6,6 +6,7 @@ import java.util.ArrayList;
  7958. import java.util.List;
  7959. import java.util.Map;
  7960. import java.util.Random;
  7961. +import java.util.UUID;
  7962. import net.innectis.innplugin.Configuration;
  7963. import net.innectis.innplugin.Economy.BlockEconomy;
  7964. import net.innectis.innplugin.Handlers.BlockHandler;
  7965. @@ -20,7 +21,6 @@ import net.innectis.innplugin.InnPlugin;
  7966. import net.innectis.innplugin.InnectisObjects.EnchantmentType;
  7967. import net.innectis.innplugin.InnectisObjects.PresentContent;
  7968. import net.innectis.innplugin.InnectisObjects.TransactionObject;
  7969. -import net.innectis.innplugin.SignSystem.WallSignType;
  7970. import net.innectis.innplugin.Inventory.IdpContainer;
  7971. import net.innectis.innplugin.Inventory.IdpInventory;
  7972. import net.innectis.innplugin.Items.IdpItem;
  7973. @@ -48,10 +48,13 @@ import net.innectis.innplugin.Player.Chat.ChatColor;
  7974. import net.innectis.innplugin.Player.IdpPlayer;
  7975. import net.innectis.innplugin.Player.InventoryType;
  7976. import net.innectis.innplugin.Player.Permission;
  7977. +import net.innectis.innplugin.Player.PlayerCredentials;
  7978. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  7979. import net.innectis.innplugin.Player.PlayerSession;
  7980. import net.innectis.innplugin.Player.PlayerSettings;
  7981. import net.innectis.innplugin.SignSystem.ChestShopSign;
  7982. import net.innectis.innplugin.SignSystem.SignValidator;
  7983. +import net.innectis.innplugin.SignSystem.WallSignType;
  7984. import net.innectis.innplugin.Utility.NumberUtil;
  7985. import org.bukkit.Bukkit;
  7986. import org.bukkit.GameMode;
  7987. @@ -730,7 +733,7 @@ public class IdpBlockListener implements Listener {
  7988. }
  7989.  
  7990. // Log the action
  7991. - LogManager.getBlockLogger().logBlockAction(player.getName(), mat, loc, BlockAction.BLOCK_PLACE);
  7992. + LogManager.getBlockLogger().logBlockAction(player.getUniqueId(), mat, loc, BlockAction.BLOCK_PLACE);
  7993. // Clear the data
  7994. BlockHandler.getIdpBlockData(loc).clear();
  7995. // Only in pixel world
  7996. @@ -894,7 +897,11 @@ public class IdpBlockListener implements Listener {
  7997. player.getInventory().updateBukkitInventory();
  7998. return;
  7999. }
  8000. - if (ChestHandler.createChest(player, block) != null) {
  8001. +
  8002. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName());
  8003. +
  8004. + if (ChestHandler.createChest(credentials, block) != null) {
  8005. + PlayerCredentialsManager.addCredentialsToCache(credentials);
  8006. player.printInfo("You lock the chest. Only you can access this chest.");
  8007. } else {
  8008. event.setCancelled(true);
  8009. @@ -912,7 +919,10 @@ public class IdpBlockListener implements Listener {
  8010. // Iron Door
  8011. if (mat == IdpMaterial.IRON_DOOR_BLOCK) {
  8012. try {
  8013. - if (DoorHandler.createDoor(player, block) == null) {
  8014. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName());
  8015. +
  8016. + if (DoorHandler.createDoor(credentials, block) == null) {
  8017. + PlayerCredentialsManager.addCredentialsToCache(credentials);
  8018. event.setCancelled(true);
  8019. player.getInventory().updateBukkitInventory();
  8020. return;
  8021. @@ -928,7 +938,9 @@ public class IdpBlockListener implements Listener {
  8022. // Trap Door
  8023. if (mat == IdpMaterial.TRAP_DOOR) {
  8024. try {
  8025. - TrapdoorHandler.createTrapdoor(world.getHandle(), loc, player.getName());
  8026. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName());
  8027. + TrapdoorHandler.createTrapdoor(world.getHandle(), loc, credentials);
  8028. + PlayerCredentialsManager.addCredentialsToCache(credentials);
  8029. } catch (SQLException ex) {
  8030. event.setCancelled(true);
  8031. player.getInventory().updateBukkitInventory();
  8032. @@ -985,13 +997,13 @@ public class IdpBlockListener implements Listener {
  8033. if (lot != null) {
  8034. if (lot.getOwner().equalsIgnoreCase(player.getName())) {
  8035. lot.setLastOwnerEdit(System.currentTimeMillis());
  8036. - } else if (lot.canPlayerAccess(player)) {
  8037. + } else if (lot.canPlayerAccess(player.getName())) {
  8038. lot.setLastMemberEdit(System.currentTimeMillis());
  8039. }
  8040. }
  8041.  
  8042. // Log the action
  8043. - LogManager.getBlockLogger().logBlockAction(player.getName(), mat, loc, BlockAction.BLOCK_PLACE);
  8044. + LogManager.getBlockLogger().logBlockAction(player.getUniqueId(), mat, loc, BlockAction.BLOCK_PLACE);
  8045. }
  8046.  
  8047. @EventHandler(priority = EventPriority.LOW)
  8048. @@ -1159,8 +1171,8 @@ public class IdpBlockListener implements Listener {
  8049. // LIGHTING UP A BLOCK. IF SOMEONE ELSE PUNCHES IT OUT, REPLACE WITH
  8050. // ORIGINAL BLOCK
  8051. if (LightsourceHandler.isLit(block.getLocation())) {
  8052. - String name = LightsourceHandler.getPlayerNameFromLocation(loc);
  8053. - IdpPlayer litPlayer = plugin.getPlayer(name);
  8054. + UUID playerId = LightsourceHandler.getPlayerIdFromLocation(loc);
  8055. + IdpPlayer litPlayer = plugin.getPlayer(playerId);
  8056.  
  8057. if (litPlayer.equals(player)) {
  8058. player.printInfo("You punched out your light!");
  8059. @@ -1169,7 +1181,7 @@ public class IdpBlockListener implements Listener {
  8060. litPlayer.printInfo(player.getName() + " punched out your light!");
  8061. }
  8062.  
  8063. - LightsourceHandler.unlightBlock(name);
  8064. + LightsourceHandler.unlightBlock(playerId);
  8065. event.setCancelled(true);
  8066. return;
  8067. }
  8068. @@ -1220,7 +1232,7 @@ public class IdpBlockListener implements Listener {
  8069. }
  8070.  
  8071. // Log the action in pixel world
  8072. - LogManager.getBlockLogger().logBlockAction(player.getName(), mat, loc, BlockAction.BLOCK_BREAK);
  8073. + LogManager.getBlockLogger().logBlockAction(player.getUniqueId(), mat, loc, BlockAction.BLOCK_BREAK);
  8074.  
  8075. BlockHandler.setBlock(block, IdpMaterial.AIR);
  8076.  
  8077. @@ -1415,8 +1427,8 @@ public class IdpBlockListener implements Listener {
  8078. PreparedStatement statement = null;
  8079.  
  8080. try {
  8081. - statement = DBManager.prepareStatement("INSERT DELAYED INTO block_breaks (time, username, blockid, world, x, y, z) VALUES (NOW(), ?, ?, ?, ?, ?, ?);");
  8082. - statement.setString(1, player.getName());
  8083. + statement = DBManager.prepareStatement("INSERT DELAYED INTO block_breaks (time, player_id, blockid, world, x, y, z) VALUES (NOW(), ?, ?, ?, ?, ?, ?);");
  8084. + statement.setString(1, player.getUniqueId().toString());
  8085. statement.setInt(2, BlockHandler.getBlockTypeId(block));
  8086. statement.setString(3, loc.getWorld().getName());
  8087. statement.setInt(4, loc.getBlockX());
  8088. @@ -1453,7 +1465,7 @@ public class IdpBlockListener implements Listener {
  8089. if (lot != null) {
  8090. if (lot.getOwner().equalsIgnoreCase(player.getName())) {
  8091. lot.setLastOwnerEdit(System.currentTimeMillis());
  8092. - } else if (lot.canPlayerAccess(player)) {
  8093. + } else if (lot.canPlayerAccess(player.getName())) {
  8094. lot.setLastMemberEdit(System.currentTimeMillis());
  8095. }
  8096. }
  8097. @@ -1482,7 +1494,7 @@ public class IdpBlockListener implements Listener {
  8098. }
  8099.  
  8100. if (giveValue) {
  8101. - TransactionObject transaction = TransactionHandler.getTransactionObject(player.getName());
  8102. + TransactionObject transaction = TransactionHandler.getTransactionObject(player.getUniqueId(), player.getName());
  8103. transaction.addValue(valutas, TransactionType.VALUTAS);
  8104.  
  8105. player.printInfo("You have gained " + valutas + " valuta" + (valutas != 1 ? "s" : "") + " from this " + mat.getName() + "!");
  8106. @@ -1503,7 +1515,7 @@ public class IdpBlockListener implements Listener {
  8107. }
  8108.  
  8109. // Log the action
  8110. - LogManager.getBlockLogger().logBlockAction(player.getName(), mat, loc, BlockAction.BLOCK_BREAK);
  8111. + LogManager.getBlockLogger().logBlockAction(player.getUniqueId(), mat, loc, BlockAction.BLOCK_BREAK);
  8112. }
  8113.  
  8114. /**
  8115. @@ -1720,7 +1732,7 @@ public class IdpBlockListener implements Listener {
  8116. InnectisChest chest = ChestHandler.getChest(blockBelow.getLocation());
  8117.  
  8118. if (chest != null) {
  8119. - if (!chest.canPlayerManage(player)
  8120. + if (!chest.canPlayerManage(player.getName())
  8121. && !player.hasPermission(Permission.owned_object_override)) {
  8122. player.printError("You do not own or operate the chest under this sign!");
  8123. event.setCancelled(true);
  8124. diff --git a/src/net/innectis/innplugin/Listeners/Bukkit/IdpEntityDamageListener.java b/src/net/innectis/innplugin/Listeners/Bukkit/IdpEntityDamageListener.java
  8125. index 422ed1ab2..8212fee58 100644
  8126. --- a/src/net/innectis/innplugin/Listeners/Bukkit/IdpEntityDamageListener.java
  8127. +++ b/src/net/innectis/innplugin/Listeners/Bukkit/IdpEntityDamageListener.java
  8128. @@ -95,7 +95,7 @@ public class IdpEntityDamageListener {
  8129. }
  8130. }
  8131.  
  8132. - if (lot == null || lot.canPlayerManage(player)
  8133. + if (lot == null || lot.canPlayerManage(player.getName())
  8134. || player.hasPermission(Permission.entity_catchentitiesoverride)) {
  8135. EntityTraits traits = EntityTraits.getEntityTraits(entity);
  8136.  
  8137. @@ -121,7 +121,7 @@ public class IdpEntityDamageListener {
  8138. return true;
  8139. } else if ((entity instanceof Animals || entity instanceof Golem || entity instanceof Squid
  8140. || entity instanceof Bat || entity instanceof Villager) && lot != null && lot.isFlagSet(LotFlagType.FARM)
  8141. - && !lot.canPlayerManage(player)) {
  8142. + && !lot.canPlayerManage(player.getName())) {
  8143. if (entity instanceof Tameable) {
  8144. Tameable tameable = (Tameable) entity;
  8145.  
  8146. diff --git a/src/net/innectis/innplugin/Listeners/Bukkit/IdpPlayerInteractListener.java b/src/net/innectis/innplugin/Listeners/Bukkit/IdpPlayerInteractListener.java
  8147. index 870aff0df..7775a2cc7 100644
  8148. --- a/src/net/innectis/innplugin/Listeners/Bukkit/IdpPlayerInteractListener.java
  8149. +++ b/src/net/innectis/innplugin/Listeners/Bukkit/IdpPlayerInteractListener.java
  8150. @@ -149,7 +149,7 @@ public class IdpPlayerInteractListener {
  8151. // copying sign text
  8152. if (event.getBlockMaterial() == IdpMaterial.WALL_SIGN || event.getBlockMaterial() == IdpMaterial.SIGN_POST) {
  8153. if (event.getBlockLot() == null
  8154. - || event.getBlockLot().canPlayerAccess(player)
  8155. + || event.getBlockLot().canPlayerAccess(player.getName())
  8156. || player.hasPermission(Permission.special_edit_any_sign)) {
  8157. Sign newSign = (Sign) event.getBlock().getState();
  8158. player.getSession().setSignLines(newSign.getLines());
  8159. @@ -163,7 +163,7 @@ public class IdpPlayerInteractListener {
  8160. Block oppositeBlock = event.getBlock().getRelative(event.getBlockFace());
  8161. InnectisLot lot = LotHandler.getLot(oppositeBlock.getLocation(), true);
  8162.  
  8163. - if (lot == null || lot.canPlayerManage(player)
  8164. + if (lot == null || lot.canPlayerManage(player.getName())
  8165. || player.hasPermission(Permission.special_signcopy)) {
  8166. IdpMaterial oppositeMaterial = IdpMaterial.fromBlock(oppositeBlock);
  8167.  
  8168. @@ -263,7 +263,7 @@ public class IdpPlayerInteractListener {
  8169. //(excluding Chests as they have their own protection system [chestallow])
  8170. //The interaction check above SHOULD catch these - this is a failsafe!
  8171. if (event.getBlockLot() != null
  8172. - && !event.getBlockLot().canPlayerAccess(event.getPlayer())
  8173. + && !event.getBlockLot().canPlayerAccess(event.getPlayer().getName())
  8174. && mat != IdpMaterial.CHEST && mat != IdpMaterial.TRAPPED_CHEST
  8175. && !event.getPlayer().hasPermission(Permission.command_admin_open_any_container)) {
  8176. event.getPlayer().printError("Try as you might, you are unable to open this " + mat.getName() + "!");
  8177. @@ -275,7 +275,7 @@ public class IdpPlayerInteractListener {
  8178.  
  8179. public boolean playerFlintAndSteelUse(InnPlayerInteractEvent event) {
  8180. if (event.getBlockLot() != null
  8181. - && event.getBlockLot().canPlayerManage(event.getPlayer())
  8182. + && event.getBlockLot().canPlayerManage(event.getPlayer().getName())
  8183. && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
  8184.  
  8185. event.getPlayer().getSession().setUsingFintSteel(true);
  8186. @@ -293,7 +293,7 @@ public class IdpPlayerInteractListener {
  8187. IdpPlayer player = event.getPlayer();
  8188.  
  8189. if ((event.getBlockLot() != null
  8190. - && event.getBlockLot().canPlayerManage(player))
  8191. + && event.getBlockLot().canPlayerManage(player.getName()))
  8192. || player.hasPermission(Permission.entity_catchentitiesoverride)) {
  8193. List<EntityTraits> caughtEntityTraits = player.getSession().getCaughtEntityTraits();
  8194. boolean renameOwners = player.getSession().getRenameOwners();
  8195. @@ -346,7 +346,7 @@ public class IdpPlayerInteractListener {
  8196. IdpPlayer player = event.getPlayer();
  8197. InnectisLot lot = LotHandler.getLot(placeBlock.getLocation(), true);
  8198.  
  8199. - if ((lot != null && !lot.canPlayerAccess(player))) {
  8200. + if ((lot != null && !lot.canPlayerAccess(player.getName()))) {
  8201. player.printError("You may not use a firework here!");
  8202. return true;
  8203. }
  8204. @@ -357,7 +357,7 @@ public class IdpPlayerInteractListener {
  8205. public boolean playerFireChargeUse(InnPlayerInteractEvent event) {
  8206. InnectisLot lot = event.getBlockLot();
  8207. IdpPlayer player = event.getPlayer();
  8208. - if (lot != null && !lot.canPlayerAccess(player) && !player.hasPermission(Permission.world_build_unrestricted)) {
  8209. + if (lot != null && !lot.canPlayerAccess(player.getName()) && !player.hasPermission(Permission.world_build_unrestricted)) {
  8210. player.printError("You cannot place a fire charge here!");
  8211. return true;
  8212. }
  8213. @@ -372,7 +372,7 @@ public class IdpPlayerInteractListener {
  8214. || mat == IdpMaterial.REDSTONE_REPEATER_ON);
  8215.  
  8216. //prevent redstone repeater/comparator tampering
  8217. - if (lot != null && !lot.canPlayerAccess(player) && !player.hasPermission(Permission.world_build_unrestricted)) {
  8218. + if (lot != null && !lot.canPlayerAccess(player.getName()) && !player.hasPermission(Permission.world_build_unrestricted)) {
  8219. player.printError("You cannot change the state of someone elses " + (isRepeater ? "repeater" : "comparator") + "!");
  8220. return true;
  8221. }
  8222. @@ -526,7 +526,7 @@ public class IdpPlayerInteractListener {
  8223. InnectisChest innChest = ChestHandler.getChest(chestBlock.getLocation());
  8224.  
  8225. if (innChest != null) {
  8226. - if (innChest.canPlayerAccess(player)
  8227. + if (innChest.canPlayerAccess(player.getName())
  8228. || player.hasPermission(Permission.special_chest_stashall)) {
  8229. mat = IdpMaterial.fromString(sign.getLine(1));
  8230. boolean useArmor = false;
  8231. @@ -819,7 +819,7 @@ public class IdpPlayerInteractListener {
  8232. return true;
  8233. }
  8234.  
  8235. - TransactionObject transactionSender = TransactionHandler.getTransactionObject(player.getName());
  8236. + TransactionObject transactionSender = TransactionHandler.getTransactionObject(player.getUniqueId(), player.getName());
  8237. int balance = transactionSender.getValue(TransactionType.VALUTAS);
  8238.  
  8239. if (balance < amount) {
  8240. @@ -827,7 +827,8 @@ public class IdpPlayerInteractListener {
  8241. return true;
  8242. }
  8243.  
  8244. - TransactionObject transactionReceiver = TransactionHandler.getTransactionObject(lot.getOwner());
  8245. + PlayerCredentials credentials = lot.getOwnerCredentials();
  8246. + TransactionObject transactionReceiver = TransactionHandler.getTransactionObject(credentials.getUniqueId(), credentials.getName());
  8247.  
  8248. // Lot owner did not represent an actual player
  8249. if (transactionReceiver == null) {
  8250. @@ -877,7 +878,7 @@ public class IdpPlayerInteractListener {
  8251. && !player.hasPermission(Permission.owned_object_override)) {
  8252. Jukebox box = (Jukebox) event.getBlock().getState();
  8253.  
  8254. - if (lot != null && !lot.canPlayerAccess(player) && box.isPlaying()) {
  8255. + if (lot != null && !lot.canPlayerAccess(player.getName()) && box.isPlaying()) {
  8256. player.printError("You may not eject this disc!");
  8257. return true;
  8258. }
  8259. @@ -891,7 +892,7 @@ public class IdpPlayerInteractListener {
  8260.  
  8261. //prevent note block tweaking
  8262. if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
  8263. - if (lot != null && !lot.canPlayerAccess(player) && !player.hasPermission(Permission.world_build_unrestricted)) {
  8264. + if (lot != null && !lot.canPlayerAccess(player.getName()) && !player.hasPermission(Permission.world_build_unrestricted)) {
  8265. player.printError("Tisk tisk, don't tamper with someone else's tunes!");
  8266. return true;
  8267. }
  8268. @@ -922,7 +923,7 @@ public class IdpPlayerInteractListener {
  8269. }
  8270.  
  8271. // Check access
  8272. - if ((lot != null && !lot.canPlayerAccess(player))) {
  8273. + if ((lot != null && !lot.canPlayerAccess(player.getName()))) {
  8274. player.printError("You may not use bonemeal here!");
  8275. return true;
  8276. }
  8277. @@ -980,7 +981,7 @@ public class IdpPlayerInteractListener {
  8278. IdpItemStack itemStack = event.getItem();
  8279.  
  8280. if (lot != null && lot.isFlagSet(LotFlagType.RESTRICTMINECART)
  8281. - && !lot.canPlayerAccess(player)
  8282. + && !lot.canPlayerAccess(player.getName())
  8283. && !player.hasPermission(Permission.world_build_unrestricted)) {
  8284. player.printError("You may not place a minecart here.");
  8285. return true;
  8286. @@ -990,7 +991,8 @@ public class IdpPlayerInteractListener {
  8287. // (this is not available in VehicleCreateEvent, so we do it here instead)
  8288. if (itemStack.getMaterial() == IdpMaterial.HOPPER_MINECART) {
  8289. HopperMinecart hopperMinecart = (HopperMinecart) player.getLocation().getWorld().spawnEntity(block.getLocation(), EntityType.MINECART_HOPPER);
  8290. - OwnedEntityHandler.addOwnedEntity(hopperMinecart.getUniqueId(), player.getName(), EntityType.MINECART_HOPPER);
  8291. + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(player.getUniqueId());
  8292. + OwnedEntityHandler.addOwnedEntity(hopperMinecart.getUniqueId(), credentials, EntityType.MINECART_HOPPER);
  8293. player.setItemStackInHand(new IdpItemStack(IdpMaterial.AIR, 1));
  8294.  
  8295. return true;
  8296. @@ -1058,14 +1060,14 @@ public class IdpPlayerInteractListener {
  8297. // Now we are sure there is a chest and a player owns it
  8298. // --------------------------------------------------
  8299.  
  8300. - if (chest.canPlayerAccess(player)
  8301. + if (chest.canPlayerAccess(player.getName())
  8302. || (chest.isFlagSet(ChestFlagType.LOT_MEMBER_CHEST) && chestlot != null
  8303. && (chestlot.containsMember(player.getName()) || chestlot.containsOperator(player.getName())))) {
  8304. player.getSession().setCheckSignUpdate(true);
  8305.  
  8306. // Auto-refill chests
  8307. if (chest.isFlagSet(ChestFlagType.AUTO_REFILL)) {
  8308. - chest.logChestAccess(player);
  8309. + chest.logChestAccess(player.getUniqueId());
  8310.  
  8311. IdpInventory checkInv = chest.getInventory("Auto-refill");
  8312. checkInv.setCustom("autofill:" + checkInv.getSize());
  8313. @@ -1082,7 +1084,7 @@ public class IdpPlayerInteractListener {
  8314.  
  8315. // Auto-refill chests
  8316. if (chest.isFlagSet(ChestFlagType.AUTO_REFILL)) {
  8317. - chest.logChestAccess(player);
  8318. + chest.logChestAccess(player.getUniqueId());
  8319.  
  8320. IdpInventory checkInv = chest.getInventory("Auto-refill");
  8321. checkInv.setCustom("autofill:" + checkInv.getSize());
  8322. @@ -1092,7 +1094,7 @@ public class IdpPlayerInteractListener {
  8323. return true;
  8324. }
  8325.  
  8326. - } else if (chestlot != null && chestlot.canPlayerManage(player)) {
  8327. + } else if (chestlot != null && chestlot.canPlayerManage(player.getName())) {
  8328. // Lets open up a read-only chest.
  8329. IdpInventory showcase = chest.getInventory("Read-Only Chest");
  8330. showcase.setCustom("showcase");
  8331. @@ -1120,7 +1122,7 @@ public class IdpPlayerInteractListener {
  8332. // --------------------------------------------------
  8333.  
  8334. // Log the access
  8335. - chest.logChestAccess(player);
  8336. + chest.logChestAccess(player.getUniqueId());
  8337.  
  8338. if (!player.getSession().isVisible()
  8339. || player.getSession().getSpectating() != null) {
  8340. @@ -1153,8 +1155,9 @@ public class IdpPlayerInteractListener {
  8341. if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
  8342. IdpPlayer player = event.getPlayer();
  8343.  
  8344. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName());
  8345. EnderContentsType type = player.getWorld().getSettings().getEnderchestType();
  8346. - EnderChestContents chestcontents = EnderChestContents.getContents(player.getName(), type);
  8347. + EnderChestContents chestcontents = EnderChestContents.getContents(credentials, type);
  8348.  
  8349. IdpMaterial mat = IdpMaterial.fromBlock(event.getBlock());
  8350.  
  8351. @@ -1173,12 +1176,12 @@ public class IdpPlayerInteractListener {
  8352.  
  8353. // If an ender chest of this player is currently being viewed let's use that instead!
  8354. // (it is viewed if an admin is already viewing their ender chest
  8355. - EnderChestView view = plugin.getEnderChestView(player.getName(), type);
  8356. + EnderChestView view = plugin.getEnderChestView(player.getUniqueId(), type);
  8357. Inventory virtualChest;
  8358.  
  8359. if (view == null) {
  8360. virtualChest = new IdpInventory("container.enderchest", 27);
  8361. - plugin.addEnderChestView(new EnderChestView(player.getName(), type, virtualChest));
  8362. + plugin.addEnderChestView(new EnderChestView(player.getUniqueId(), type, virtualChest));
  8363. // Update the contents of the ender chest
  8364. IdpItemStack[] items = chestcontents.getItems();
  8365.  
  8366. @@ -1216,7 +1219,7 @@ public class IdpPlayerInteractListener {
  8367. if (mat == IdpMaterial.IRON_DOOR_BLOCK) {
  8368. if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
  8369. InnectisDoor door = DoorHandler.getDoor(event.getBlock().getLocation());
  8370. - if ((door == null || !door.canPlayerAccess(player))
  8371. + if ((door == null || !door.canPlayerAccess(player.getName()))
  8372. && !player.hasPermission(Permission.owned_object_override)) {
  8373. player.printError("This door is locked!");
  8374. } else {
  8375. @@ -1253,7 +1256,7 @@ public class IdpPlayerInteractListener {
  8376. return true;
  8377. }
  8378.  
  8379. - if ((waypoint == null || !waypoint.canPlayerAccess(player))
  8380. + if ((waypoint == null || !waypoint.canPlayerAccess(player.getName()))
  8381. && !player.hasPermission(Permission.owned_object_override)) {
  8382. player.printError("You cannot use that waypoint!");
  8383. } else {
  8384. @@ -1266,7 +1269,7 @@ public class IdpPlayerInteractListener {
  8385. } else {
  8386. player.printError("This waypoint does not go anywhere!");
  8387.  
  8388. - if (waypoint.canPlayerManage(player)
  8389. + if (waypoint.canPlayerManage(player.getName())
  8390. || player.hasPermission(Permission.owned_object_override)) {
  8391. player.printInfo("Set a location with /wpset " + waypoint.getId() + ".");
  8392. }
  8393. @@ -1294,7 +1297,8 @@ public class IdpPlayerInteractListener {
  8394.  
  8395. // Switches
  8396. if (event.getItem().getMaterial() == IdpMaterial.REDSTONE_BLOCK) {
  8397. - InnectisSwitch.createOrGetSwitch(loc, event.getPlayer().getName());
  8398. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(event.getPlayer().getName());
  8399. + InnectisSwitch.createOrGetSwitch(loc, credentials);
  8400. } else {
  8401. InnectisSwitch st = InnectisSwitch.getSwitch(loc);
  8402. if (st != null) {
  8403. @@ -1446,7 +1450,7 @@ public class IdpPlayerInteractListener {
  8404. //Prevents a player from putting a fire out on a lot
  8405. //they do not have build rights on
  8406. if (lot != null) {
  8407. - if (!lot.canPlayerAccess(player)) {
  8408. + if (!lot.canPlayerAccess(player.getName())) {
  8409. return true;
  8410. }
  8411. }
  8412. @@ -1602,7 +1606,7 @@ public class IdpPlayerInteractListener {
  8413.  
  8414. // Only check access for trapdoors that are owned
  8415. if (trapdoor != null) {
  8416. - if (!(trapdoor.canPlayerAccess(player) || player.hasPermission(Permission.owned_object_override))) {
  8417. + if (!(trapdoor.canPlayerAccess(player.getName()) || player.hasPermission(Permission.owned_object_override))) {
  8418. player.printError("You may not access this trapdoor.");
  8419. return true;
  8420. }
  8421. @@ -1626,7 +1630,7 @@ public class IdpPlayerInteractListener {
  8422. InnectisBookcase bookcase = InnectisBookcase.getBookcase(loc);
  8423.  
  8424. if (bookcase != null) {
  8425. - if (bookcase.canPlayerAccess(player) || player.hasPermission(Permission.owned_object_override)) {
  8426. + if (bookcase.canPlayerAccess(player.getName()) || player.hasPermission(Permission.owned_object_override)) {
  8427. // if holding an written book, just store it.
  8428. if (player.getMaterialInHand() == IdpMaterial.WRITTEN_BOOK) {
  8429. IdpItemStack item = player.getItemStackInHand();
  8430. @@ -1658,13 +1662,15 @@ public class IdpPlayerInteractListener {
  8431. if (action == Action.LEFT_CLICK_BLOCK && player.getMaterialInHand() == IdpMaterial.CHEST) {
  8432. InnectisLot lot = LotHandler.getLot(loc);
  8433.  
  8434. - if (lot == null || lot.canPlayerAccess(player) || player.hasPermission(Permission.owned_object_override)) {
  8435. + if (lot == null || lot.canPlayerAccess(player.getName()) || player.hasPermission(Permission.owned_object_override)) {
  8436. InnectisBookcase bookcase = InnectisBookcase.getBookcase(loc);
  8437.  
  8438. if (bookcase == null) {
  8439. - bookcase = new InnectisBookcase(block.getWorld(), block, player.getName());
  8440. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName());
  8441. + bookcase = new InnectisBookcase(block.getWorld(), block, credentials);
  8442.  
  8443. if (bookcase.save()) {
  8444. + PlayerCredentialsManager.addCredentialsToCache(credentials);
  8445. player.printInfo("That bookcase has been given an inventory.");
  8446. } else {
  8447. player.printError("Unable to save bookcase. Notify an admin!");
  8448. diff --git a/src/net/innectis/innplugin/Loggers/BlockLogger.java b/src/net/innectis/innplugin/Loggers/BlockLogger.java
  8449. index a09bcb6db..3845c52d8 100644
  8450. --- a/src/net/innectis/innplugin/Loggers/BlockLogger.java
  8451. +++ b/src/net/innectis/innplugin/Loggers/BlockLogger.java
  8452. @@ -1,6 +1,7 @@
  8453. package net.innectis.innplugin.Loggers;
  8454.  
  8455. import java.util.Date;
  8456. +import java.util.UUID;
  8457. import net.innectis.innplugin.Handlers.BlockHandler;
  8458. import net.innectis.innplugin.Items.IdpMaterial;
  8459. import org.bukkit.Location;
  8460. @@ -14,7 +15,7 @@ import org.bukkit.entity.Entity;
  8461. public class BlockLogger extends IdpDBLogger {
  8462.  
  8463. BlockLogger() {
  8464. - super("block_log", "name", "locx", "locy", "locz", "world", "Id", "Data", "DateTime", "ActionType");
  8465. + super("block_log", "player_id", "locx", "locy", "locz", "world", "Id", "Data", "DateTime", "ActionType");
  8466. }
  8467.  
  8468. /**
  8469. @@ -69,12 +70,12 @@ public class BlockLogger extends IdpDBLogger {
  8470. * For the <b>REVERTION</b> action the block is the block after it got reverted.
  8471. * @param action - The action that was done
  8472. */
  8473. - public void logBlockAction(String username, IdpMaterial mat, Location loc, BlockAction action) {
  8474. + public void logBlockAction(UUID playerId, IdpMaterial mat, Location loc, BlockAction action) {
  8475. int id = mat.getId();
  8476. byte dat = (byte) mat.getData();
  8477.  
  8478. addToCache(
  8479. - username,
  8480. + playerId.toString(),
  8481. loc.getBlockX(),
  8482. loc.getBlockY(),
  8483. loc.getBlockZ(),
  8484. @@ -87,11 +88,11 @@ public class BlockLogger extends IdpDBLogger {
  8485.  
  8486. /**
  8487. * Log an blockaction.
  8488. - * @param username - The name of the user that done the action.
  8489. + * @param playerId - The ID of the player that did the action
  8490. * @param entity - the entity interacted with
  8491. * @param action - The action that was done
  8492. */
  8493. - public void logEntityAction(String username, Entity entity, BlockAction action) {
  8494. + public void logEntityAction(UUID playerId, Entity entity, BlockAction action) {
  8495. IdpMaterial mat = null;
  8496.  
  8497. switch (entity.getType()) {
  8498. @@ -106,7 +107,7 @@ public class BlockLogger extends IdpDBLogger {
  8499. Location loc = entity.getLocation();
  8500.  
  8501. addToCache(
  8502. - username,
  8503. + playerId.toString(),
  8504. loc.getBlockX(),
  8505. loc.getBlockY(),
  8506. loc.getBlockZ(),
  8507. diff --git a/src/net/innectis/innplugin/MailSystem/MailHandler.java b/src/net/innectis/innplugin/MailSystem/MailHandler.java
  8508. index 574db4c00..a769ab42e 100644
  8509. --- a/src/net/innectis/innplugin/MailSystem/MailHandler.java
  8510. +++ b/src/net/innectis/innplugin/MailSystem/MailHandler.java
  8511. @@ -4,9 +4,14 @@ import java.sql.Date;
  8512. import java.sql.PreparedStatement;
  8513. import java.sql.ResultSet;
  8514. import java.sql.SQLException;
  8515. +import java.util.List;
  8516. +import java.util.UUID;
  8517. +import net.innectis.innplugin.Configuration;
  8518. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  8519. import net.innectis.innplugin.InnPlugin;
  8520. import net.innectis.innplugin.Player.IdpPlayer;
  8521. +import net.innectis.innplugin.Player.PlayerCredentials;
  8522. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  8523.  
  8524. /**
  8525. * Handles the mail for each user
  8526. @@ -19,27 +24,37 @@ public class MailHandler {
  8527. /**
  8528. * Loads player's mail to the session
  8529. *
  8530. - * @param player
  8531. - * @return true if the player has mail, false otherwise
  8532. + * @param playerId
  8533. */
  8534. public static void loadPlayerMailToSession(IdpPlayer player) {
  8535. + PlayerCredentials toPlayerCredentials = PlayerCredentialsManager.getByUniqueId(player.getUniqueId());
  8536. PreparedStatement statement = null;
  8537. ResultSet set = null;
  8538.  
  8539. try {
  8540. - statement = DBManager.prepareStatement("SELECT * FROM playermail WHERE lower(toplayer) = ?");
  8541. - statement.setString(1, player.getName().toLowerCase());
  8542. + statement = DBManager.prepareStatement("SELECT * FROM playermail WHERE to_player_id = ?");
  8543. + statement.setString(1, player.getUniqueId().toString());
  8544. set = statement.executeQuery();
  8545.  
  8546. while (set.next()) {
  8547. int ID = set.getInt("ID");
  8548. Date date = set.getDate("datecreated");
  8549. boolean read = set.getBoolean("readmail");
  8550. - String from = set.getString("fromplayer");
  8551. +
  8552. + String fromPlayerIdString = set.getString("from_player_id");
  8553. + UUID fromPlayerId = UUID.fromString(fromPlayerIdString);
  8554. + PlayerCredentials fromPlayerCredentials = null;
  8555. +
  8556. + if (fromPlayerId.equals(Configuration.SERVER_GENERATED_IDENTIFIER)) {
  8557. + fromPlayerCredentials = Configuration.SERVER_GENERATED_CREDENTIALS;
  8558. + } else {
  8559. + fromPlayerCredentials = PlayerCredentialsManager.getByUniqueId(fromPlayerId);
  8560. + }
  8561. +
  8562. String title = set.getString("title");
  8563. String content = set.getString("content");
  8564.  
  8565. - MailMessage obj = new MailMessage(ID, date, read, from, player.getName(), title, content);
  8566. + MailMessage obj = new MailMessage(ID, date, read, fromPlayerCredentials, toPlayerCredentials, title, content);
  8567. player.getSession().addMail(obj);
  8568. }
  8569. } catch (SQLException ex) {
  8570. diff --git a/src/net/innectis/innplugin/MailSystem/MailMessage.java b/src/net/innectis/innplugin/MailSystem/MailMessage.java
  8571. index 9be2bc028..c8dbe8e30 100644
  8572. --- a/src/net/innectis/innplugin/MailSystem/MailMessage.java
  8573. +++ b/src/net/innectis/innplugin/MailSystem/MailMessage.java
  8574. @@ -7,6 +7,7 @@ import java.util.Date;
  8575. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  8576. import net.innectis.innplugin.InnPlugin;
  8577. import net.innectis.innplugin.InnectisObjects.Message;
  8578. +import net.innectis.innplugin.Player.PlayerCredentials;
  8579.  
  8580. /**
  8581. * Contains a single mail entry for a player
  8582. @@ -14,33 +15,37 @@ import net.innectis.innplugin.InnectisObjects.Message;
  8583. * @author AlphaBlend
  8584. */
  8585. public class MailMessage extends Message {
  8586. - private String to;
  8587. + private PlayerCredentials fromPlayerCredentials;
  8588. private String title;
  8589.  
  8590. /**
  8591. * Sets up a mail object for a new message
  8592. *
  8593. - * @param from
  8594. - * @param to
  8595. + * @param date
  8596. + * @param fromCredentials
  8597. + * @param toPlayerCredentials
  8598. * @param title
  8599. * @param message
  8600. */
  8601. - public MailMessage(Date date, String from, String to, String title, String message) {
  8602. - this(0, date, false, from, to, title, message);
  8603. + public MailMessage(Date date, PlayerCredentials fromCredentials, PlayerCredentials toPlayerCredentials, String title, String message) {
  8604. + this(0, date, false, fromCredentials, toPlayerCredentials, title, message);
  8605. }
  8606.  
  8607. /**
  8608. * Sets up the mail object
  8609. *
  8610. * @param ID
  8611. - * @param from
  8612. + * @param date
  8613. + * @param read
  8614. + * @param fromPlayerCredentials
  8615. + * @param toPlayerCredentials
  8616. * @param title
  8617. - * @param contents
  8618. + * @param message
  8619. */
  8620. - public MailMessage(int ID, Date date, boolean read, String from, String to, String title, String message) {
  8621. - super(ID, date, read, from, message);
  8622. + public MailMessage(int ID, Date date, boolean read, PlayerCredentials fromPlayerCredentials, PlayerCredentials toPlayerCredentials, String title, String message) {
  8623. + super(ID, date, read, fromPlayerCredentials, message);
  8624.  
  8625. - this.to = to;
  8626. + this.fromPlayerCredentials = toPlayerCredentials;
  8627. this.title = title;
  8628. }
  8629.  
  8630. @@ -67,11 +72,11 @@ public class MailMessage extends Message {
  8631. statement.setInt(2, id);
  8632. statement.executeUpdate();
  8633. } else {
  8634. - statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO playermail (datecreated, readmail, toplayer, fromplayer, title, content) VALUES (?, ?, ?, ?, ?, ?)");
  8635. + statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO playermail (datecreated, readmail, to_player_id, from_player_id, title, content) VALUES (?, ?, ?, ?, ?, ?)");
  8636. statement.setDate(1, new java.sql.Date(date.getTime()));
  8637. statement.setBoolean(2, read);
  8638. - statement.setString(3, to);
  8639. - statement.setString(4, creator);
  8640. + statement.setString(3, fromPlayerCredentials.getUniqueId().toString());
  8641. + statement.setString(4, creatorCredentials.getUniqueId().toString());
  8642. statement.setString(5, title);
  8643. statement.setString(6, message);
  8644. statement.execute();
  8645. diff --git a/src/net/innectis/innplugin/OwnedObjects/Handlers/ChestHandler.java b/src/net/innectis/innplugin/OwnedObjects/Handlers/ChestHandler.java
  8646. index 3eb464db5..e303b4d02 100644
  8647. --- a/src/net/innectis/innplugin/OwnedObjects/Handlers/ChestHandler.java
  8648. +++ b/src/net/innectis/innplugin/OwnedObjects/Handlers/ChestHandler.java
  8649. @@ -7,6 +7,8 @@ import java.util.ArrayList;
  8650. import java.util.HashMap;
  8651. import java.util.Iterator;
  8652. import java.util.List;
  8653. +import java.util.UUID;
  8654. +import net.innectis.innplugin.Configuration;
  8655. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  8656. import net.innectis.innplugin.InnPlugin;
  8657. import net.innectis.innplugin.Items.IdpMaterial;
  8658. @@ -15,6 +17,8 @@ import net.innectis.innplugin.OwnedObjects.InnectisLot;
  8659. import net.innectis.innplugin.Player.Chat.ChatColor;
  8660. import net.innectis.innplugin.Player.IdpPlayer;
  8661. import net.innectis.innplugin.Player.Permission;
  8662. +import net.innectis.innplugin.Player.PlayerCredentials;
  8663. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  8664. import net.innectis.innplugin.Utility.LocationUtil;
  8665. import org.bukkit.Bukkit;
  8666. import org.bukkit.Location;
  8667. @@ -204,12 +208,12 @@ public class ChestHandler {
  8668. return null;
  8669. }
  8670.  
  8671. - public static List<InnectisChest> getChests(String owner) {
  8672. + public static List<InnectisChest> getChests(String playerName) {
  8673. List<InnectisChest> chests = new ArrayList<InnectisChest>();
  8674. InnectisChest chest;
  8675. for (Iterator<InnectisChest> it = getChests().values().iterator(); it.hasNext();) {
  8676. chest = it.next();
  8677. - if (chest.getOwner().equalsIgnoreCase(owner) && chest.isValid()) {
  8678. + if (chest.getOwner().equalsIgnoreCase(playerName) && chest.isValid()) {
  8679. chests.add(chest);
  8680. }
  8681. }
  8682. @@ -249,48 +253,71 @@ public class ChestHandler {
  8683. return null;
  8684. }
  8685.  
  8686. - PreparedStatement statement = DBManager.prepareStatement("SELECT username, isop FROM chests_members WHERE chestid = ?;");
  8687. + String ownerIdString = result.getString("owner_id");
  8688. + UUID ownerId = UUID.fromString(ownerIdString);
  8689. + PlayerCredentials ownerCredentials = PlayerCredentialsManager.getByUniqueId(ownerId, true);
  8690. +
  8691. + PreparedStatement statement = DBManager.prepareStatement("SELECT player_id, isop FROM chests_members WHERE chestid = ?;");
  8692. statement.setInt(1, result.getInt("chestid"));
  8693. + List<PlayerCredentials> members = new ArrayList<PlayerCredentials>();
  8694. + List<PlayerCredentials> operators = new ArrayList<PlayerCredentials>();
  8695. ResultSet result2 = statement.executeQuery();
  8696. - List<String> members = new ArrayList<String>();
  8697. - List<String> operators = new ArrayList<String>();
  8698. +
  8699. while (result2.next()) {
  8700. - if (result2.getBoolean("isop")) {
  8701. - operators.add(result2.getString("username"));
  8702. + String memberIdString = result2.getString("player_id");
  8703. + UUID memberId = UUID.fromString(memberIdString);
  8704. +
  8705. + if (memberId.equals(Configuration.EVERYONE_IDENTIFIER)) {
  8706. + members.add(Configuration.EVERYONE_CREDENTIALS);
  8707. + } else if (memberId.equals(Configuration.LOT_ACCESS_IDENTIFIER)) {
  8708. + members.add(Configuration.LOT_ACCESS_CREDENTIALS);
  8709. } else {
  8710. - members.add(result2.getString("username"));
  8711. + boolean isOp = result2.getBoolean("isop");
  8712. +
  8713. + PlayerCredentials memberCredentials = PlayerCredentialsManager.getByUniqueId(memberId, true);
  8714. +
  8715. + if (isOp) {
  8716. + operators.add(memberCredentials);
  8717. + } else {
  8718. + members.add(memberCredentials);
  8719. + }
  8720. }
  8721. }
  8722.  
  8723. DBManager.closeResultSet(result2);
  8724. DBManager.closePreparedStatement(statement);
  8725.  
  8726. - return new InnectisChest(type, world, primaryChest, optionalChest, result.getInt("chestid"), result.getString("owner"), members, operators, result.getLong("flags"));
  8727. + return new InnectisChest(type, world, primaryChest, optionalChest, result.getInt("chestid"), ownerCredentials, members, operators, result.getLong("flags"));
  8728. }
  8729.  
  8730. - public static boolean hasChest(IdpPlayer player) {
  8731. + public static boolean hasChest(String playerName) {
  8732. InnectisChest chest;
  8733. for (Iterator<InnectisChest> it = getChests().values().iterator(); it.hasNext();) {
  8734. chest = it.next();
  8735. - if (chest.getOwner().equalsIgnoreCase(player.getName())) {
  8736. +
  8737. + if (chest.getOwner().equalsIgnoreCase(playerName)) {
  8738. return true;
  8739. }
  8740. }
  8741. +
  8742. return false;
  8743. }
  8744.  
  8745. - public static boolean isOwnChest(IdpPlayer player, Location location) {
  8746. + public static boolean isOwnChest(String playerName, Location location) {
  8747. InnectisChest chest = getChest(location);
  8748. +
  8749. if (chest == null) {
  8750. return false;
  8751. }
  8752. - if (chest.getOwner().equalsIgnoreCase(player.getName())) {
  8753. +
  8754. + if (chest.getOwner().equalsIgnoreCase(playerName)) {
  8755. return true;
  8756. }
  8757. +
  8758. return false;
  8759. }
  8760.  
  8761. - public static InnectisChest createChest(IdpPlayer player, Block block) throws SQLException {
  8762. + public static InnectisChest createChest(PlayerCredentials ownerCredentials, Block block) throws SQLException {
  8763. InnectisChest existingChest = getChest(block.getLocation());
  8764.  
  8765. // Allow placement, original owner is assumed
  8766. @@ -303,7 +330,7 @@ public class ChestHandler {
  8767.  
  8768. if (attached == null) { //no adjacent chests
  8769. //all is good, make the chest
  8770. - InnectisChest innchest = new InnectisChest(ChestType.fromMaterial(IdpMaterial.fromBlock(block)), block.getWorld(), block, null, -1, player.getName(), null, null, 0);
  8771. + InnectisChest innchest = new InnectisChest(ChestType.fromMaterial(IdpMaterial.fromBlock(block)), block.getWorld(), block, null, -1, ownerCredentials, null, null, 0);
  8772. innchest.save();
  8773. ChestHandler.getChests().put(innchest.getId(), innchest);
  8774. return innchest;
  8775. @@ -320,8 +347,15 @@ public class ChestHandler {
  8776. return null; //already an double chest
  8777. }
  8778.  
  8779. - if (!innAttached.getOwner().equalsIgnoreCase(player.getName())) {
  8780. - player.printError("You cannot place a chest next to a chest you do not own.");
  8781. + String ownerName = ownerCredentials.getName();
  8782. +
  8783. + if (!innAttached.getOwner().equalsIgnoreCase(ownerName)) {
  8784. + IdpPlayer player = InnPlugin.getPlugin().getPlayer(ownerCredentials.getUniqueId());
  8785. +
  8786. + if (player != null) {
  8787. + player.printError("You cannot place a chest next to a chest you do not own.");
  8788. + }
  8789. +
  8790. return null;
  8791. }
  8792.  
  8793. @@ -331,71 +365,23 @@ public class ChestHandler {
  8794. }
  8795. }
  8796.  
  8797. - /**
  8798. - * Creates a new chest with the given name as owner. <br/>
  8799. - * <b> This does not check the max chest size! </b>
  8800. - * @param playername
  8801. - * Name of the owner of the chest
  8802. - * @param block
  8803. - * The chest itself
  8804. - * @return
  8805. - * The innectischest or null if invalid
  8806. - * @throws SQLException
  8807. - */
  8808. - public static InnectisChest createChest(String playername, Block block) throws SQLException {
  8809. - InnectisChest existingChest = getChest(block.getLocation());
  8810. -
  8811. - // Allow placement, original owner is assumed
  8812. - if (existingChest != null) {
  8813. - return existingChest;
  8814. - }
  8815. -
  8816. - //check for adjacent chests
  8817. - Block attached = getAttachedChest(block);
  8818. -
  8819. - if (attached != null) {
  8820. - InnectisChest innAttached = getChest(attached.getLocation());
  8821. -
  8822. - // Check if the attached chest is already an innectis chest
  8823. - if (innAttached != null) {
  8824. -
  8825. - if (innAttached.isDoubleChest()) {
  8826. - return null; //already an double chest
  8827. - }
  8828. -
  8829. - if (!innAttached.getOwner().equalsIgnoreCase(playername)) {
  8830. - return null;
  8831. - }
  8832. -
  8833. - innAttached.setChest2(block);
  8834. - innAttached.save();
  8835. - return innAttached;
  8836. - }
  8837. - }
  8838. -
  8839. - //all is good, make the chest
  8840. - InnectisChest innchest = new InnectisChest(ChestType.fromMaterial(IdpMaterial.fromBlock(block)), block.getWorld(), block, null, -1, playername, null, null, 0);
  8841. - innchest.save();
  8842. - ChestHandler.getChests().put(innchest.getId(), innchest);
  8843. - return innchest;
  8844. - }
  8845. -
  8846. public static boolean removeChest(IdpPlayer player, Block block) throws SQLException {
  8847. if (!ChestType.isValidChestBlock(IdpMaterial.fromBlock(block))) {
  8848. return true;
  8849. }
  8850.  
  8851. Location loc = block.getLocation();
  8852. -
  8853. InnectisChest chest = getChest(loc);
  8854. +
  8855. if (chest == null || chest.getOwner() == null) {
  8856. return true;
  8857. }
  8858.  
  8859. InnectisLot lot = LotHandler.getLot(loc);
  8860. +
  8861. //you can remove a chest if you own it or if its on your lot
  8862. - if (chest.getOwner().equalsIgnoreCase(player.getName())
  8863. - || (lot != null && lot.getOwner().equalsIgnoreCase(player.getName()))
  8864. + if (chest.getOwnerCredentials().getUniqueId().equals(player.getUniqueId())
  8865. + || (lot != null && lot.getOwnerCredentials().getUniqueId().equals(player.getUniqueId()))
  8866. || player.hasPermission(Permission.owned_object_override)) {
  8867. removeChestForcibly(block, chest.getId(), true);
  8868. return true;
  8869. diff --git a/src/net/innectis/innplugin/OwnedObjects/Handlers/DoorHandler.java b/src/net/innectis/innplugin/OwnedObjects/Handlers/DoorHandler.java
  8870. index a798af9b1..20aa95359 100644
  8871. --- a/src/net/innectis/innplugin/OwnedObjects/Handlers/DoorHandler.java
  8872. +++ b/src/net/innectis/innplugin/OwnedObjects/Handlers/DoorHandler.java
  8873. @@ -7,15 +7,19 @@ import java.util.ArrayList;
  8874. import java.util.HashMap;
  8875. import java.util.Iterator;
  8876. import java.util.List;
  8877. +import java.util.UUID;
  8878. +import net.innectis.innplugin.Configuration;
  8879. import net.innectis.innplugin.Handlers.BlockHandler;
  8880. -import net.innectis.innplugin.Items.IdpMaterial;
  8881. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  8882. import net.innectis.innplugin.InnPlugin;
  8883. +import net.innectis.innplugin.Items.IdpMaterial;
  8884. import net.innectis.innplugin.OwnedObjects.InnectisDoor;
  8885. import net.innectis.innplugin.OwnedObjects.InnectisLot;
  8886. import net.innectis.innplugin.Player.Chat.ChatColor;
  8887. import net.innectis.innplugin.Player.IdpPlayer;
  8888. import net.innectis.innplugin.Player.Permission;
  8889. +import net.innectis.innplugin.Player.PlayerCredentials;
  8890. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  8891. import org.bukkit.Bukkit;
  8892. import org.bukkit.Location;
  8893. import org.bukkit.World;
  8894. @@ -163,48 +167,71 @@ public class DoorHandler {
  8895. return null;
  8896. }
  8897.  
  8898. - PreparedStatement statement = DBManager.prepareStatement("SELECT username, isop FROM doors_members WHERE doorid = ?;");
  8899. + String ownerIdString = result.getString("owner_id");
  8900. + UUID ownerId = UUID.fromString(ownerIdString);
  8901. + PlayerCredentials ownerCredentials = PlayerCredentialsManager.getByUniqueId(ownerId, true);
  8902. +
  8903. + PreparedStatement statement = DBManager.prepareStatement("SELECT player_id, isop FROM doors_members WHERE doorid = ?;");
  8904. statement.setInt(1, result.getInt("doorid"));
  8905. ResultSet result2 = statement.executeQuery();
  8906. - List<String> members = new ArrayList<String>();
  8907. - List<String> operators = new ArrayList<String>();
  8908. +
  8909. + List<PlayerCredentials> members = new ArrayList<PlayerCredentials>();
  8910. + List<PlayerCredentials> operators = new ArrayList<PlayerCredentials>();
  8911. +
  8912. while (result2.next()) {
  8913. - if (result2.getBoolean("isop")) {
  8914. - operators.add(result2.getString("username"));
  8915. + String memberIdString = result2.getString("player_id");
  8916. + UUID memberId = UUID.fromString(memberIdString);
  8917. +
  8918. + if (memberId.equals(Configuration.EVERYONE_IDENTIFIER)) {
  8919. + members.add(Configuration.EVERYONE_CREDENTIALS);
  8920. + } else if (memberId.equals(Configuration.LOT_ACCESS_IDENTIFIER)) {
  8921. + members.add(Configuration.LOT_ACCESS_CREDENTIALS);
  8922. } else {
  8923. - members.add(result2.getString("username"));
  8924. + boolean isOp = result2.getBoolean("isop");
  8925. +
  8926. + PlayerCredentials memberCredentials = PlayerCredentialsManager.getByUniqueId(memberId, true);
  8927. +
  8928. + if (isOp) {
  8929. + operators.add(memberCredentials);
  8930. + } else {
  8931. + members.add(memberCredentials);
  8932. + }
  8933. }
  8934. }
  8935.  
  8936. DBManager.closeResultSet(result2);
  8937. DBManager.closePreparedStatement(statement);
  8938.  
  8939. - return new InnectisDoor(world, primaryDoor, optionalDoor, result.getInt("doorid"), result.getString("owner"), members, operators, result.getLong("flags"));
  8940. + return new InnectisDoor(world, primaryDoor, optionalDoor, result.getInt("doorid"), ownerCredentials, members, operators, result.getLong("flags"));
  8941. }
  8942.  
  8943. - public static boolean hasDoor(IdpPlayer player) {
  8944. - InnectisDoor door;
  8945. + public static boolean hasDoor(String playerName) {
  8946. for (Iterator<InnectisDoor> it = getDoors().values().iterator(); it.hasNext();) {
  8947. - door = it.next();
  8948. - if (door.getOwner().equalsIgnoreCase(player.getName())) {
  8949. + InnectisDoor door = it.next();
  8950. +
  8951. + if (door.getOwner().equalsIgnoreCase(playerName)) {
  8952. return true;
  8953. }
  8954. }
  8955. +
  8956. return false;
  8957. }
  8958.  
  8959. - public static boolean isOwnDoor(IdpPlayer player, Location location) {
  8960. + public static boolean isOwnDoor(String playerName, Location location) {
  8961. InnectisDoor door = getDoor(location);
  8962. +
  8963. if (door == null) {
  8964. return false;
  8965. }
  8966. - if (door.getOwner().equalsIgnoreCase(player.getName())) {
  8967. +
  8968. + if (door.getOwner().equalsIgnoreCase(playerName)) {
  8969. return true;
  8970. }
  8971. +
  8972. return false;
  8973. }
  8974.  
  8975. - public static InnectisDoor createDoor(IdpPlayer player, Block block) throws SQLException {
  8976. + public static InnectisDoor createDoor(PlayerCredentials ownerCredentials, Block block) throws SQLException {
  8977. Location loc = block.getLocation();
  8978. InnectisDoor door = getDoor(loc);
  8979.  
  8980. @@ -220,64 +247,25 @@ public class DoorHandler {
  8981.  
  8982. if (attached == null) { //no adjacent doors
  8983. //all is good, make the door
  8984. - InnectisDoor inndoor = new InnectisDoor(block.getWorld(), block, null, -1, player.getName(), null, null, 0);
  8985. + InnectisDoor inndoor = new InnectisDoor(block.getWorld(), block, null, -1, ownerCredentials, null, null, 0);
  8986. inndoor.save();
  8987. DoorHandler.getDoors().put(inndoor.getId(), inndoor);
  8988. return inndoor;
  8989. } else {
  8990. InnectisDoor innAttached = getDoor(attached.getLocation());
  8991. if (innAttached.isDoubleDoor()) {
  8992. - return null; //already an double door
  8993. - }
  8994. - if (!innAttached.getOwner().equalsIgnoreCase(player.getName())) {
  8995. - player.printError("You cannot place a door next to a door you do not own.");
  8996. - return null;
  8997. + return null; //already a double door
  8998. }
  8999.  
  9000. - innAttached.setDoor2(block);
  9001. - innAttached.save();
  9002. - return innAttached;
  9003. - }
  9004. - }
  9005. + String ownerName = ownerCredentials.getName();
  9006.  
  9007. - /**
  9008. - * Creates an innectis door at the given location
  9009. - * @param playername
  9010. - * @param block
  9011. - * @return
  9012. - * The innectisdoor is succeeded, else null
  9013. - * @throws SQLException
  9014. - */
  9015. - public static InnectisDoor createDoor(String playername, Block block) throws SQLException {
  9016. - if (getDoor(block.getLocation()) != null) { //prevent hijacking a door
  9017. - return null;
  9018. - }
  9019. + if (!innAttached.getOwner().equalsIgnoreCase(ownerName)) {
  9020. + IdpPlayer player = InnPlugin.getPlugin().getPlayer(ownerCredentials.getUniqueId());
  9021.  
  9022. - //check for adjacent doors
  9023. - Block attached = getAdjacentDoor(block);
  9024. -
  9025. - if (attached == null) { //no adjacent doors
  9026. - //all is good, make the door
  9027. - InnectisDoor inndoor = new InnectisDoor(block.getWorld(), block, null, -1, playername, null, null, 0);
  9028. - inndoor.save();
  9029. - DoorHandler.getDoors().put(inndoor.getId(), inndoor);
  9030. - return inndoor;
  9031. - } else {
  9032. - InnectisDoor innAttached = getDoor(attached.getLocation());
  9033. -
  9034. - // Other door doesn't exist either
  9035. - if (innAttached == null) {
  9036. - // Create new double door
  9037. - InnectisDoor inndoor = new InnectisDoor(block.getWorld(), block, attached, -1, playername, null, null, 0);
  9038. - inndoor.save();
  9039. - return inndoor;
  9040. - }
  9041. -
  9042. - if (innAttached.isDoubleDoor()) {
  9043. - return null; //already an double door
  9044. - }
  9045. - if (!innAttached.getOwner().equalsIgnoreCase(playername)) {
  9046. - return null;
  9047. + if (player != null && player.isOnline()) {
  9048. + player.printError("You cannot place a door next to a door you do not own.");
  9049. + return null;
  9050. + }
  9051. }
  9052.  
  9053. innAttached.setDoor2(block);
  9054. @@ -302,8 +290,8 @@ public class DoorHandler {
  9055.  
  9056. InnectisLot lot = LotHandler.getLot(loc);
  9057. //you can remove a door if you own it or if its on your lot
  9058. - if (door.getOwner().equalsIgnoreCase(player.getName())
  9059. - || (lot != null && lot.getOwner().equalsIgnoreCase(player.getName()))
  9060. + if (door.getOwnerCredentials().getUniqueId().equals(player.getUniqueId())
  9061. + || (lot != null && lot.getOwnerCredentials().getUniqueId().equals(player.getUniqueId()))
  9062. || player.hasPermission(Permission.owned_object_override)) {
  9063. removeDoorForcibly(block, door.getId(), true);
  9064. return true;
  9065. diff --git a/src/net/innectis/innplugin/OwnedObjects/Handlers/LotHandler.java b/src/net/innectis/innplugin/OwnedObjects/Handlers/LotHandler.java
  9066. index 061e4a030..5c1b2f4dc 100644
  9067. --- a/src/net/innectis/innplugin/OwnedObjects/Handlers/LotHandler.java
  9068. +++ b/src/net/innectis/innplugin/OwnedObjects/Handlers/LotHandler.java
  9069. @@ -12,6 +12,8 @@ import java.util.HashMap;
  9070. import java.util.Iterator;
  9071. import java.util.List;
  9072. import java.util.Map;
  9073. +import java.util.UUID;
  9074. +import net.innectis.innplugin.Configuration;
  9075. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  9076. import net.innectis.innplugin.InnPlugin;
  9077. import net.innectis.innplugin.Location.IdpWorld;
  9078. @@ -20,6 +22,8 @@ import net.innectis.innplugin.Location.IdpWorldRegion;
  9079. import net.innectis.innplugin.OwnedObjects.InnectisLot;
  9080. import net.innectis.innplugin.Player.Chat.ChatColor;
  9081. import net.innectis.innplugin.Player.IdpPlayer;
  9082. +import net.innectis.innplugin.Player.PlayerCredentials;
  9083. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  9084. import net.innectis.innplugin.Player.PlayerGroup;
  9085. import net.innectis.innplugin.Player.PlayerSession;
  9086. import org.bukkit.Bukkit;
  9087. @@ -93,8 +97,6 @@ public final class LotHandler {
  9088. /**
  9089. * Clears the cache and reload all lots from the database. <br/>
  9090. * <b>Additionally it will check for disabled lots and fix lot nr's.</b>
  9091. - *
  9092. - * @throws SQLException
  9093. */
  9094. public static boolean loadLots() {
  9095. getLots().clear();
  9096. @@ -166,16 +168,46 @@ public final class LotHandler {
  9097.  
  9098. Location spawn = new Location(world, result.getInt("sx"), result.getInt("sy"), result.getInt("sz"), result.getInt("yaw"), 0);
  9099.  
  9100. - PreparedStatement statement = DBManager.prepareStatement("SELECT username, isop FROM lot_members WHERE lotid = ?;");
  9101. + String ownerIdString = result.getString("owner_id");
  9102. + UUID ownerId = UUID.fromString(ownerIdString);
  9103. + PlayerCredentials ownerCredentials = null;
  9104. +
  9105. + // Owner credentials are different if this lot is assignable
  9106. + if (ownerId.equals(Configuration.LOT_ASSIGNABLE_IDENTIFIER)) {
  9107. + ownerCredentials = Configuration.LOT_ASSIGNABLE_CREDENTIALS;
  9108. + } else if (ownerId.equals(Configuration.OTHER_IDENTIFIER)) {
  9109. + ownerCredentials = Configuration.OTHER_CREDENTIALS;
  9110. + } else {
  9111. + ownerCredentials = PlayerCredentialsManager.getByUniqueId(ownerId, true);
  9112. + }
  9113. +
  9114. + String creatorIdString = result.getString("creator_id");
  9115. + UUID creatorId = UUID.fromString(creatorIdString);
  9116. + PlayerCredentials creatorCredentials = PlayerCredentialsManager.getByUniqueId(creatorId, true);
  9117. +
  9118. + PreparedStatement statement = DBManager.prepareStatement("SELECT player_id, isop FROM lot_members WHERE lotid = ?;");
  9119. statement.setInt(1, lotId);
  9120. ResultSet result2 = statement.executeQuery();
  9121. - List<String> members = new ArrayList<String>();
  9122. - List<String> operators = new ArrayList<String>();
  9123. +
  9124. + List<PlayerCredentials> members = new ArrayList<PlayerCredentials>();
  9125. + List<PlayerCredentials> operators = new ArrayList<PlayerCredentials>();
  9126. +
  9127. while (result2.next()) {
  9128. - if (result2.getBoolean("isop")) {
  9129. - operators.add(result2.getString("username"));
  9130. + String memberIdString = result2.getString("player_id");
  9131. + UUID memberId = UUID.fromString(memberIdString);
  9132. +
  9133. + if (memberId.equals(Configuration.EVERYONE_IDENTIFIER)) {
  9134. + members.add(Configuration.EVERYONE_CREDENTIALS);
  9135. } else {
  9136. - members.add(result2.getString("username"));
  9137. + boolean isOp = result2.getBoolean("isop");
  9138. +
  9139. + PlayerCredentials memberCredentials = PlayerCredentialsManager.getByUniqueId(memberId, true);
  9140. +
  9141. + if (isOp) {
  9142. + operators.add(memberCredentials);
  9143. + } else {
  9144. + members.add(memberCredentials);
  9145. + }
  9146. }
  9147. }
  9148.  
  9149. @@ -185,44 +217,61 @@ public final class LotHandler {
  9150. statement = DBManager.prepareStatement("SELECT * FROM lot_safelist WHERE lotid = ?;");
  9151. statement.setInt(1, lotId);
  9152. result2 = statement.executeQuery();
  9153. - List<String> safelist = new ArrayList<String>();
  9154. + List<PlayerCredentials> safelist = new ArrayList<PlayerCredentials>();
  9155. +
  9156. while(result2.next()) {
  9157. - safelist.add(result2.getString("username"));
  9158. + String playerIdString = result2.getString("player_id");
  9159. + UUID playerId = UUID.fromString(playerIdString);
  9160. + PlayerCredentials playerCredentials = PlayerCredentialsManager.getByUniqueId(playerId, true);
  9161. + safelist.add(playerCredentials);
  9162. }
  9163.  
  9164. DBManager.closeResultSet(result2);
  9165. DBManager.closePreparedStatement(statement);
  9166.  
  9167. - statement = DBManager.prepareStatement("SELECT username, timeout FROM lot_banned WHERE lotid = ?;");
  9168. + statement = DBManager.prepareStatement("SELECT player_id, timeout FROM lot_banned WHERE lotid = ?;");
  9169. statement.setInt(1, lotId);
  9170. result2 = statement.executeQuery();
  9171. - Map<String, Long> banned = new HashMap<String, Long>();
  9172. + Map<PlayerCredentials, Long> banned = new HashMap<PlayerCredentials, Long>();
  9173. +
  9174. while (result2.next()) {
  9175. - banned.put(result2.getString("username"), result2.getLong("timeout"));
  9176. + String playerIdString = result2.getString("player_id");
  9177. + UUID playerId = UUID.fromString(playerIdString);
  9178. + PlayerCredentials playerCredentials = null;
  9179. +
  9180. + if (playerId.equals(Configuration.EVERYONE_IDENTIFIER)) {
  9181. + playerCredentials = Configuration.EVERYONE_CREDENTIALS;
  9182. + } else {
  9183. + playerCredentials = PlayerCredentialsManager.getByUniqueId(playerId);
  9184. + }
  9185. +
  9186. + long timeout = result2.getLong("timeout");
  9187. +
  9188. + banned.put(playerCredentials, timeout);
  9189. }
  9190.  
  9191. DBManager.closeResultSet(result2);
  9192. DBManager.closePreparedStatement(statement);
  9193.  
  9194. - String owner = result.getString("owner");
  9195. -
  9196. - return new InnectisLot(lotId, world, point1, point2, spawn, owner, result.getString("lotname"), members, operators, banned, safelist, result.getInt("lotnr"), result.getLong("flags"), mainLot, result.getString("creator"), result.getString("enter_msg"), result.getString("exit_msg"), result.getLong("last_owner_edit"), result.getLong("last_member_edit"), result.getInt("warp_count"), result.getBoolean("hidden"), result.getBoolean("deleted"));
  9197. + return new InnectisLot(lotId, world, point1, point2, spawn, ownerCredentials, result.getString("lotname"), members, operators, banned, safelist, result.getInt("lotnr"), result.getLong("flags"), mainLot, creatorCredentials, result.getString("enter_msg"), result.getString("exit_msg"), result.getLong("last_owner_edit"), result.getLong("last_member_edit"), result.getInt("warp_count"), result.getBoolean("hidden"), result.getBoolean("deleted"));
  9198. }
  9199.  
  9200. /**
  9201. * This method will get a list all owners with lots and fix the lotnumbers so they are ordered correctly.
  9202. */
  9203. private static void fixLotNumbers() {
  9204. - List<String> owners = new ArrayList<String>();
  9205. - InnectisLot lot;
  9206. + List<PlayerCredentials> owners = new ArrayList<PlayerCredentials>();
  9207. +
  9208. for (Iterator<InnectisLot> it = getLots().values().iterator(); it.hasNext();) {
  9209. - lot = it.next();
  9210. - if (!owners.contains(lot.getOwner().toLowerCase())) {
  9211. - owners.add(lot.getOwner().toLowerCase());
  9212. + InnectisLot lot = it.next();
  9213. + PlayerCredentials ownerCredentials = lot.getOwnerCredentials();
  9214. +
  9215. + if (!owners.contains(ownerCredentials)) {
  9216. + owners.add(ownerCredentials);
  9217. }
  9218. }
  9219. - for (String owner : owners) {
  9220. - fixLotNumber(owner);
  9221. + for (PlayerCredentials pc : owners) {
  9222. + fixLotNumber(pc.getName());
  9223. }
  9224. saveLots();
  9225. }
  9226. @@ -260,10 +309,7 @@ public final class LotHandler {
  9227. */
  9228. private static void cleanLots(Collection<InnectisLot> lots) {
  9229. InnectisLot lot;
  9230. - HashMap<String, Integer> lotCount = new HashMap<String, Integer>();
  9231. - PlayerGroup group;
  9232. - String ownername;
  9233. - PlayerSession session;
  9234. + HashMap<PlayerCredentials, Integer> lotCount = new HashMap<PlayerCredentials, Integer>();
  9235. int count;
  9236.  
  9237. Date targetdate = new Date(System.currentTimeMillis() - 1209600000);
  9238. @@ -273,17 +319,20 @@ public final class LotHandler {
  9239.  
  9240. // Check if its a top lot (not a sublot)
  9241. if (lot.getParent() == null || lot.getParent() == mainLot) {
  9242. - ownername = lot.getOwner().toLowerCase();
  9243. - group = PlayerGroup.getGroupOfUsername(lot.getOwner());
  9244. + PlayerCredentials ownerCredentials = lot.getOwnerCredentials();
  9245. + UUID playerId = ownerCredentials.getUniqueId();
  9246. + String name = ownerCredentials.getName();
  9247. +
  9248. + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(playerId);
  9249.  
  9250. // Check for inactive lots of guest players who left
  9251. if (lot.getLastOwnerEdit() == 0 && group == PlayerGroup.GUEST) {
  9252. - session = PlayerSession.getSession(ownername, InnPlugin.getPlugin());
  9253. + PlayerSession session = PlayerSession.getSession(playerId, name, InnPlugin.getPlugin(), true);
  9254.  
  9255. if (session != null) {
  9256. // Check date
  9257. if (session.getLastLogin().before(targetdate)) {
  9258. - lot.setOwner("#");
  9259. + lot.setOwner(Configuration.LOT_ASSIGNABLE_CREDENTIALS);
  9260. InnPlugin.logInfo("Lot #" + lot.getId() + " (" + lot.getOwner() + ") set to assignable; player innactive, never editted lot!");
  9261. }
  9262. }
  9263. @@ -291,7 +340,7 @@ public final class LotHandler {
  9264.  
  9265. // Dont disable lots whose player names are invalid (I.E. #, %, or ~)
  9266. if (group != PlayerGroup.NONE) {
  9267. - count = (lotCount.get(ownername) == null ? 0 : lotCount.get(ownername));
  9268. + count = (lotCount.get(ownerCredentials) == null ? 0 : lotCount.get(ownerCredentials));
  9269.  
  9270. if (count + 1 > group.getMaxLots()) {
  9271. lot.setDisabled(true);
  9272. @@ -300,7 +349,7 @@ public final class LotHandler {
  9273. lot.setDisabled(true);
  9274. InnPlugin.logInfo("Lot #" + lot.getId() + " (" + lot.getOwner() + ") disabled; width/length too large! (" + lot.getWidth() + " or " + lot.getLength() + ")>" + group.getMaxLotSize());
  9275. } else {
  9276. - lotCount.put(ownername, ++count);
  9277. + lotCount.put(ownerCredentials, ++count);
  9278. }
  9279. }
  9280.  
  9281. @@ -319,12 +368,12 @@ public final class LotHandler {
  9282. }
  9283.  
  9284. /**
  9285. - * This method will check all lots of the given player and remove lots if he's a guests that
  9286. + * This method will check all lots of the given player by ID and remove lots if he's a guests that
  9287. * hasn't used them in a while. It will also check if the size and amount of lots for this
  9288. * player are still accepted.
  9289. */
  9290. - public static void cleanLots(String username) {
  9291. - cleanLots(getLots(username));
  9292. + public static void cleanLots(String playerName) {
  9293. + cleanLots(getLots(playerName));
  9294. }
  9295. //</editor-fold>
  9296.  
  9297. @@ -361,87 +410,55 @@ public final class LotHandler {
  9298. if (lots == null) {
  9299. return null;
  9300. }
  9301. +
  9302. return lots.get(0);
  9303. }
  9304.  
  9305. /**
  9306. * This method will look for a lot with the given string as the owner aswell as the lotnumber
  9307. - * @param owner
  9308. - * The owner's name, either be the exact name or a partial name.
  9309. + * @param playerName
  9310. + * The ID of the owner
  9311. * @param lotNumber
  9312. * The lotnumber to look for.
  9313. * @return
  9314. */
  9315. - public static InnectisLot getLot(String owner, int lotNumber) {
  9316. - InnectisLot lot, partialMatchStart = null, partialMatchAny = null;
  9317. + public static InnectisLot getLot(String playerName, int lotNumber) {
  9318. for (Iterator<InnectisLot> it = getLots().values().iterator(); it.hasNext();) {
  9319. - lot = it.next();
  9320. + InnectisLot lot = it.next();
  9321. +
  9322. if (lot.getLotNumber() == lotNumber) {
  9323.  
  9324. // Check for exact match
  9325. - if (lot.getOwner().equalsIgnoreCase(owner)) {
  9326. + if (lot.getOwner().equalsIgnoreCase(playerName)) {
  9327. return lot;
  9328. }
  9329. -
  9330. - // Check for partial matches
  9331. - if (partialMatchStart == null && owner.length() > 1
  9332. - && lot.getOwner().length() >= owner.length()
  9333. - && lot.getOwner().toLowerCase().substring(0, owner.length()).equalsIgnoreCase(owner.toLowerCase())) {
  9334. -
  9335. - partialMatchStart = lot;
  9336. - } else if (partialMatchAny == null && owner.length() > 1
  9337. - && lot.getOwner().length() >= owner.length()
  9338. - && lot.getOwner().toLowerCase().contains(owner.toLowerCase())) {
  9339. - partialMatchAny = lot;
  9340. - }
  9341. }
  9342. }
  9343. - // Check if there is a partial match on string start.
  9344. - if (partialMatchStart != null) {
  9345. - return partialMatchStart;
  9346. - }
  9347. - return partialMatchAny;
  9348. +
  9349. + return null;
  9350. }
  9351.  
  9352. /**
  9353. - * This will look for a lot with the given owner and the given lotname
  9354. - * @param owner
  9355. - * The owner's name, either be the exact name or a partial name.
  9356. + * This will look for a lot with the given owner by ID and the given lotname
  9357. + * @param playerName
  9358. + * The owner's ID
  9359. * @param lotName
  9360. * The exact name of the lot
  9361. * @return
  9362. */
  9363. - public static InnectisLot getLot(String owner, String lotName) {
  9364. - InnectisLot lot, partialMatchStart = null, partialMatchAny = null;
  9365. + public static InnectisLot getLot(String playerName, String lotName) {
  9366. for (Iterator<InnectisLot> it = getLots().values().iterator(); it.hasNext();) {
  9367. - lot = it.next();
  9368. + InnectisLot lot = it.next();
  9369.  
  9370. if (lot.getLotName().equalsIgnoreCase(lotName)) {
  9371. -
  9372. // Check exact match
  9373. - if (lot.getOwner().equalsIgnoreCase(owner)) {
  9374. + if (lot.getOwner().equalsIgnoreCase(playerName)) {
  9375. return lot;
  9376. }
  9377. -
  9378. - // Check partial match
  9379. - if (partialMatchStart == null && owner.length() > 1
  9380. - && lot.getOwner().length() >= owner.length()
  9381. - && lot.getOwner().toLowerCase().substring(0, owner.length()).equalsIgnoreCase(owner.toLowerCase())) {
  9382. -
  9383. - partialMatchStart = lot;
  9384. - } else if (partialMatchAny == null && owner.length() > 1
  9385. - && lot.getOwner().length() >= owner.length()
  9386. - && lot.getOwner().toLowerCase().contains(owner.toLowerCase())) {
  9387. -
  9388. - partialMatchAny = lot;
  9389. - }
  9390. }
  9391. }
  9392. - // Check if there is a partial match on string start.
  9393. - if (partialMatchStart != null) {
  9394. - return partialMatchStart;
  9395. - }
  9396. - return partialMatchAny;
  9397. +
  9398. + return null;
  9399. }
  9400.  
  9401. /**
  9402. @@ -511,44 +528,26 @@ public final class LotHandler {
  9403.  
  9404. /**
  9405. * This will return a list with all lots that are owned by the player with the given name.
  9406. - * @param owner
  9407. + * @param playerName
  9408. * @return
  9409. */
  9410. - public static List<InnectisLot> getLots(String owner) {
  9411. + public static List<InnectisLot> getLots(String playerName) {
  9412. List<InnectisLot> lots = new ArrayList<InnectisLot>();
  9413. InnectisLot lot;
  9414. - String ownerMatchStart = null, ownerMatchAny = null;
  9415.  
  9416. // Find all lots that match the given name (partial or exact).
  9417. for (Iterator<InnectisLot> it = getLots().values().iterator(); it.hasNext();) {
  9418. lot = it.next();
  9419. - if (lot.getOwner().equalsIgnoreCase(owner)) {
  9420. + if (lot.getOwner().equalsIgnoreCase(playerName)) {
  9421. lots.add(lot);
  9422. - } else if (ownerMatchStart != null
  9423. - && lot.getOwner().length() >= owner.length()
  9424. - && lot.getOwner().toLowerCase().substring(0, owner.length()).equalsIgnoreCase(owner.toLowerCase())) {
  9425. - ownerMatchStart = lot.getOwner();
  9426. - } else if (ownerMatchAny != null
  9427. - && lot.getOwner().length() >= owner.length()
  9428. - && lot.getOwner().toLowerCase().contains(owner.toLowerCase())) {
  9429. - ownerMatchAny = lot.getOwner();
  9430. - }
  9431. - }
  9432. -
  9433. - // If no lots found, check for partial matches
  9434. - if (lots.isEmpty()) {
  9435. - if (ownerMatchStart != null) {
  9436. - return getLots(ownerMatchStart);
  9437. - } else if (ownerMatchAny != null) {
  9438. - return getLots(ownerMatchAny);
  9439. }
  9440. - return null;
  9441. }
  9442.  
  9443. // Sort if bigger then 1
  9444. if (lots.size() > 1) {
  9445. Collections.sort(lots, getLotNumberComparator());
  9446. }
  9447. +
  9448. return lots;
  9449. }
  9450.  
  9451. @@ -740,7 +739,7 @@ public final class LotHandler {
  9452. * Removes the lot with the given id from the database.
  9453. * <p/>
  9454. * This will not remove sublots that are not owned by the owner of the removed lot.
  9455. - * @param lot
  9456. + * @param lotId
  9457. * @return
  9458. * @throws SQLException
  9459. */
  9460. @@ -805,6 +804,7 @@ public final class LotHandler {
  9461.  
  9462. return remCount;
  9463. }
  9464. +
  9465. return 0;
  9466. }
  9467. //</editor-fold>
  9468. @@ -813,44 +813,47 @@ public final class LotHandler {
  9469. /**
  9470. * Randomly assigns a lot the the given player
  9471. *
  9472. - * @param name - name of the player
  9473. + * @param ownerCredentials credentials of the player the lot will be assigned to
  9474. * @return InnectisLot - the newly created lot
  9475. * @throws SQLException - Is thrown when something happens when saving the
  9476. * lot in the database.
  9477. */
  9478. - public static InnectisLot assignLot(String name) throws SQLException {
  9479. - return assignLot(name, getLot(ASSIGNABLE_LOT_OWNER, 1));
  9480. + public static InnectisLot assignLot(PlayerCredentials ownerCredentials) throws SQLException {
  9481. + return assignLot(ownerCredentials, getLot(ASSIGNABLE_LOT_OWNER, 1));
  9482. }
  9483.  
  9484. /**
  9485. * Assigns the given lot the player with the given name
  9486. *
  9487. - * @param name - name of the player
  9488. + * @param ownerCredentials - name of the player
  9489. * @param lot - The lot that needs to be assigned to the player
  9490. * @return InnectisLot - the newly created lot
  9491. * @throws SQLException - Is thrown when something happens when saving the
  9492. * lot in the database.
  9493. */
  9494. - public static InnectisLot assignLot(String name, InnectisLot lot) throws SQLException {
  9495. + public static InnectisLot assignLot(PlayerCredentials ownerCredentials, InnectisLot lot) throws SQLException {
  9496. if (lot == null) {
  9497. return null;
  9498. }
  9499.  
  9500. - lot.setOwner(name);
  9501. + String name = ownerCredentials.getName();
  9502. + lot.setOwner(ownerCredentials);
  9503. lot.setLotNumber(0);
  9504. lot.save();
  9505. InnPlugin.logInfo("Assigning lot #" + lot.getId() + " to " + name);
  9506. - LotHandler.cleanLots(name);
  9507. + LotHandler.cleanLots(ownerCredentials.getName());
  9508.  
  9509. fixLotNumber(ASSIGNABLE_LOT_OWNER); //reorder lotnr for available lots
  9510.  
  9511. - IdpPlayer target = InnPlugin.getPlugin().getPlayer(name, true);
  9512. + IdpPlayer target = InnPlugin.getPlugin().getPlayer(ownerCredentials.getUniqueId());
  9513. +
  9514. if (target != null) {
  9515. name = target.getName();
  9516. target.printInfo("You have been assigned a lot!");
  9517. target.printInfo("Type " + ChatColor.AQUA + "/mylot" + (lot.getLotNumber() > 1 ? " " + lot.getLotNumber() : "") + ChatColor.GREEN + " to go to it.");
  9518. target.teleport(lot.getSpawn());
  9519. }
  9520. +
  9521. InnPlugin.getPlugin().sendModeratorMessage(null, "Lot #" + lot.getId() + " assigned to " + name);
  9522.  
  9523. return lot;
  9524. @@ -859,31 +862,31 @@ public final class LotHandler {
  9525.  
  9526. //<editor-fold defaultstate="collapsed" desc="Get lotcount">
  9527. /**
  9528. - * Gets the amount of lots the given name has. <b>This will not count
  9529. + * Gets the amount of lots the given player has. <b>This will not count
  9530. * sublots.</b>
  9531. *
  9532. - * @param name
  9533. - * @return The amount of lots the given name has
  9534. + * @param playerName
  9535. + * @return The amount of lots the given player by ID has
  9536. */
  9537. - public static int getLotCount(String name) {
  9538. - return getLotCount(name, 0);
  9539. + public static int getLotCount(String playerName) {
  9540. + return getLotCount(playerName, 0);
  9541. }
  9542.  
  9543. /**
  9544. - * Gets the amount of lots the given name has. <b>This will not count
  9545. + * Gets the amount of lots the given player by ID has. <b>This will not count
  9546. * sublots.</b>
  9547. *
  9548. - * @param name
  9549. + * @param playerName
  9550. * @param sublotCount - acts as an output parameter. This value will be set
  9551. - * to the amount of sublots the 'name' has. Doesn't matter if the 'name' is
  9552. + * to the amount of sublots the player by ID has. Doesn't matter if the 'name' is
  9553. * the owner of the parent or not.
  9554. * @return The amount of lots the given name has
  9555. */
  9556. - public static int getLotCount(String name, int sublotCount) {
  9557. + public static int getLotCount(String playerName, int sublotCount) {
  9558. int count = 0;
  9559. sublotCount = 0;
  9560.  
  9561. - List<InnectisLot> lots = getLots(name);
  9562. + List<InnectisLot> lots = getLots(playerName);
  9563.  
  9564. if (lots != null) {
  9565. for (InnectisLot lot : lots) {
  9566. @@ -947,17 +950,17 @@ public final class LotHandler {
  9567.  
  9568. /**
  9569. * This will recount the lotnumbers and set the correctly.
  9570. - * @param owner
  9571. + * @param playerName
  9572. * The owner of the lots
  9573. */
  9574. - private static void fixLotNumber(String owner) {
  9575. + private static void fixLotNumber(String playerName) {
  9576. // Do Hretsam's lot differently
  9577. - if (owner.equalsIgnoreCase("Hretsam")) {
  9578. - fixHretLotNumber(owner);
  9579. + if (playerName.equalsIgnoreCase("hretsam")) {
  9580. + fixHretLotNumber(playerName);
  9581. return;
  9582. }
  9583.  
  9584. - List<InnectisLot> lots = getLots(owner);
  9585. + List<InnectisLot> lots = getLots(playerName);
  9586. InnectisLot lot;
  9587. int curI = 1;
  9588.  
  9589. @@ -986,10 +989,10 @@ public final class LotHandler {
  9590.  
  9591. /**
  9592. * Alt method for setting lotnumber for 'Hretsam'.
  9593. - * @param owner
  9594. + * @param playerName
  9595. */
  9596. - private static void fixHretLotNumber(String owner) {
  9597. - List<InnectisLot> lots = getLots(owner);
  9598. + private static void fixHretLotNumber(String playerName) {
  9599. + List<InnectisLot> lots = getLots(playerName);
  9600. InnectisLot lot;
  9601.  
  9602. int normalInx = 1;
  9603. @@ -1104,13 +1107,13 @@ public final class LotHandler {
  9604. * @param world
  9605. * @param point1
  9606. * @param point2
  9607. - * @param owner
  9608. - * @param creator
  9609. + * @param ownerCredentials
  9610. + * @param creatorCredentials
  9611. * @return
  9612. * @throws SQLException
  9613. */
  9614. - public static InnectisLot addLot(World world, Vector point1, Vector point2, String owner, String creator) throws SQLException {
  9615. - InnectisLot lot = new InnectisLot(world, point1, point2, owner, creator, mainLot);
  9616. + public static InnectisLot addLot(World world, Vector point1, Vector point2, PlayerCredentials ownerCredentials, PlayerCredentials creatorCredentials) throws SQLException {
  9617. + InnectisLot lot = new InnectisLot(world, point1, point2, ownerCredentials, creatorCredentials, mainLot);
  9618.  
  9619. lot.save();
  9620. LotHandler.getLots().put(lot.getId(), lot);
  9621. @@ -1178,7 +1181,7 @@ public final class LotHandler {
  9622.  
  9623. saveLots();
  9624. }
  9625. -
  9626. +
  9627. return true;
  9628. }
  9629.  
  9630. diff --git a/src/net/innectis/innplugin/OwnedObjects/Handlers/OwnedEntityHandler.java b/src/net/innectis/innplugin/OwnedObjects/Handlers/OwnedEntityHandler.java
  9631. index bfdbaa3be..04f4e3e74 100644
  9632. --- a/src/net/innectis/innplugin/OwnedObjects/Handlers/OwnedEntityHandler.java
  9633. +++ b/src/net/innectis/innplugin/OwnedObjects/Handlers/OwnedEntityHandler.java
  9634. @@ -9,6 +9,8 @@ import java.util.UUID;
  9635. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  9636. import net.innectis.innplugin.InnPlugin;
  9637. import net.innectis.innplugin.OwnedObjects.OwnedEntity;
  9638. +import net.innectis.innplugin.Player.PlayerCredentials;
  9639. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  9640. import org.bukkit.entity.EntityType;
  9641.  
  9642. /**
  9643. @@ -31,19 +33,21 @@ public class OwnedEntityHandler {
  9644. ResultSet set = null;
  9645.  
  9646. try {
  9647. - statement = DBManager.prepareStatement("SELECT * FROM owned_entities");
  9648. + statement = DBManager.prepareStatement("SELECT * FROM owned_entities;");
  9649. set = statement.executeQuery();
  9650.  
  9651. while (set.next()) {
  9652. - String owner = set.getString("owner");
  9653. + String playerIdString = set.getString("owner_id");
  9654. + UUID playerId = UUID.fromString(playerIdString);
  9655. + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(playerId, true);
  9656. EntityType type = EntityType.fromId(set.getInt("entityid"));
  9657.  
  9658. long mostSigBits = set.getLong("mostsigbits");
  9659. long leastSigBits = set.getLong("leastsigbits");
  9660. - UUID uniqueId = new UUID(mostSigBits, leastSigBits);
  9661. + UUID ownedEntityId = new UUID(mostSigBits, leastSigBits);
  9662.  
  9663. - OwnedEntity ownedEntity = new OwnedEntity(owner, type);
  9664. - ownedEntities.put(uniqueId, ownedEntity);
  9665. + OwnedEntity ownedEntity = new OwnedEntity(credentials, type);
  9666. + ownedEntities.put(ownedEntityId, ownedEntity);
  9667. }
  9668. } catch (SQLException ex) {
  9669. InnPlugin.logError("COULD NOT GET OWNED ENTITIES FROM DATABASE!", ex);
  9670. @@ -67,22 +71,22 @@ public class OwnedEntityHandler {
  9671.  
  9672. /**
  9673. * Adds an owned entity to the list
  9674. - * @param uniqueId
  9675. - * @param owner
  9676. + * @param entityId
  9677. + * @param ownerCredentials
  9678. * @param type
  9679. */
  9680. - public static void addOwnedEntity(UUID uniqueId, String owner, EntityType type) {
  9681. - OwnedEntity ownedEntity = new OwnedEntity(owner, type);
  9682. - ownedEntities.put(uniqueId, ownedEntity);
  9683. + public static void addOwnedEntity(UUID entityId, PlayerCredentials ownerCredentials, EntityType type) {
  9684. + OwnedEntity ownedEntity = new OwnedEntity(ownerCredentials ,type);
  9685. + ownedEntities.put(entityId, ownedEntity);
  9686.  
  9687. - long mostSigBits = uniqueId.getMostSignificantBits();
  9688. - long leastSigBits = uniqueId.getLeastSignificantBits();
  9689. + long mostSigBits = entityId.getMostSignificantBits();
  9690. + long leastSigBits = entityId.getLeastSignificantBits();
  9691.  
  9692. PreparedStatement statement = null;
  9693.  
  9694. try {
  9695. - statement = DBManager.prepareStatement("INSERT INTO owned_entities VALUES (?, ?, ?, ?)");
  9696. - statement.setString(1, owner);
  9697. + statement = DBManager.prepareStatement("INSERT INTO owned_entities (owner_id, entityid, mostsigbits, leastsigbits) VALUES (?, ?, ?, ?);");
  9698. + statement.setString(1, ownerCredentials.getUniqueId().toString());
  9699. statement.setInt(2, type.getTypeId());
  9700. statement.setLong(3, mostSigBits);
  9701. statement.setLong(4, leastSigBits);
  9702. @@ -95,25 +99,24 @@ public class OwnedEntityHandler {
  9703. }
  9704.  
  9705. /**
  9706. - * Removes the specified owned entity from the database
  9707. - * @param uniqueId
  9708. - * @param type
  9709. + * Removes the specified owned entityId from the database
  9710. + * @param entityId
  9711. */
  9712. - public static void removeOwnedEntity(UUID uniqueId) {
  9713. - OwnedEntity ownedEntity = ownedEntities.remove(uniqueId);
  9714. + public static void removeOwnedEntity(UUID entityId) {
  9715. + OwnedEntity ownedEntity = ownedEntities.remove(entityId);
  9716.  
  9717. // Doesn't exist, so don't attempt to remove
  9718. if (ownedEntity == null) {
  9719. return;
  9720. }
  9721.  
  9722. - long mostSigBits = uniqueId.getMostSignificantBits();
  9723. - long leastSigBits = uniqueId.getLeastSignificantBits();
  9724. + long mostSigBits = entityId.getMostSignificantBits();
  9725. + long leastSigBits = entityId.getLeastSignificantBits();
  9726.  
  9727. PreparedStatement statement = null;
  9728.  
  9729. try {
  9730. - statement = DBManager.prepareStatement("DELETE FROM owned_entities WHERE mostsigbits = ? AND leastsigbits = ?");
  9731. + statement = DBManager.prepareStatement("DELETE FROM owned_entities WHERE mostsigbits = ? AND leastsigbits = ?;");
  9732. statement.setLong(1, mostSigBits);
  9733. statement.setLong(2, leastSigBits);
  9734. statement.execute();
  9735. diff --git a/src/net/innectis/innplugin/OwnedObjects/Handlers/TrapdoorHandler.java b/src/net/innectis/innplugin/OwnedObjects/Handlers/TrapdoorHandler.java
  9736. index c1574a449..a64638fc7 100644
  9737. --- a/src/net/innectis/innplugin/OwnedObjects/Handlers/TrapdoorHandler.java
  9738. +++ b/src/net/innectis/innplugin/OwnedObjects/Handlers/TrapdoorHandler.java
  9739. @@ -6,9 +6,13 @@ import java.sql.SQLException;
  9740. import java.util.ArrayList;
  9741. import java.util.HashMap;
  9742. import java.util.List;
  9743. +import java.util.UUID;
  9744. +import net.innectis.innplugin.Configuration;
  9745. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  9746. import net.innectis.innplugin.InnPlugin;
  9747. import net.innectis.innplugin.OwnedObjects.InnectisTrapdoor;
  9748. +import net.innectis.innplugin.Player.PlayerCredentials;
  9749. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  9750. import org.bukkit.Bukkit;
  9751. import org.bukkit.Location;
  9752. import org.bukkit.World;
  9753. @@ -19,7 +23,6 @@ import org.bukkit.World;
  9754. * @author AlphaBlend
  9755. */
  9756. public class TrapdoorHandler {
  9757. -
  9758. private static HashMap<Integer, InnectisTrapdoor> trapdoors = new HashMap<Integer, InnectisTrapdoor>();
  9759.  
  9760. public TrapdoorHandler() {
  9761. @@ -29,20 +32,20 @@ public class TrapdoorHandler {
  9762. * Adds a new trapdoor to the list of trapdoors
  9763. * @param world
  9764. * @param loc
  9765. - * @param owner
  9766. + * @param ownerCredentials
  9767. * @return The owned Trapdoor object
  9768. * @throws SQLException
  9769. */
  9770. - public static InnectisTrapdoor createTrapdoor(World world, Location loc, String owner) throws SQLException {
  9771. + public static InnectisTrapdoor createTrapdoor(World world, Location loc, PlayerCredentials ownerCredentials) throws SQLException {
  9772. // Allow placement, original owner is assumed
  9773. if (isTrapdoorAtLocation(loc)) {
  9774. return null;
  9775. }
  9776.  
  9777. - List<String> members = new ArrayList<String>();
  9778. - members.add("%");
  9779. + List<PlayerCredentials> members = new ArrayList<PlayerCredentials>();
  9780. + members.add(Configuration.EVERYONE_CREDENTIALS);
  9781.  
  9782. - InnectisTrapdoor trapdoor = new InnectisTrapdoor(world, loc, 0, owner, members, null, 0);
  9783. + InnectisTrapdoor trapdoor = new InnectisTrapdoor(world, loc, 0, ownerCredentials, members, null, 0);
  9784. trapdoor.save();
  9785. trapdoors.put(trapdoor.getId(), trapdoor);
  9786. return trapdoor;
  9787. @@ -115,14 +118,14 @@ public class TrapdoorHandler {
  9788.  
  9789. /**
  9790. * Gets the trapdoors owned by the specified owner
  9791. - * @param owner
  9792. + * @param playerName
  9793. * @return
  9794. */
  9795. - public static List<InnectisTrapdoor> getTrapdoors(String owner) {
  9796. + public static List<InnectisTrapdoor> getTrapdoors(String playerName) {
  9797. List<InnectisTrapdoor> tdlist = new ArrayList<InnectisTrapdoor>();
  9798.  
  9799. for (InnectisTrapdoor trapdoor : trapdoors.values()) {
  9800. - if (trapdoor.getOwner().equalsIgnoreCase(owner)) {
  9801. + if (trapdoor.getOwner().equalsIgnoreCase(playerName)) {
  9802. tdlist.add(trapdoor);
  9803. }
  9804. }
  9805. @@ -150,7 +153,9 @@ public class TrapdoorHandler {
  9806. */
  9807. public static boolean loadTrapdoors() {
  9808. PreparedStatement statement = null;
  9809. + PreparedStatement statement2 = null;
  9810. ResultSet set = null;
  9811. + ResultSet set2 = null;
  9812.  
  9813. try {
  9814. // First, load all the trapdoors into memory
  9815. @@ -162,7 +167,10 @@ public class TrapdoorHandler {
  9816.  
  9817. if (world != null) {
  9818. int id = set.getInt("trapdoorid");
  9819. - String owner = set.getString("owner");
  9820. +
  9821. + String ownerIdString = set.getString("owner_id");
  9822. + UUID ownerId = UUID.fromString(ownerIdString);
  9823. + PlayerCredentials ownerCredentials = PlayerCredentialsManager.getByUniqueId(ownerId, true);
  9824.  
  9825. int x = set.getInt("locx");
  9826. int y = set.getInt("locy");
  9827. @@ -171,26 +179,39 @@ public class TrapdoorHandler {
  9828.  
  9829. long flags = set.getLong("flags");
  9830.  
  9831. - DBManager.closeResultSet(set);
  9832. - DBManager.closePreparedStatement(statement);
  9833. -
  9834. // Load the members of the trapdoor
  9835. - statement = DBManager.prepareStatement("SELECT username, isop FROM trapdoors_members WHERE trapdoorid = ?;");
  9836. - statement.setInt(1, id);
  9837. - set = statement.executeQuery();
  9838. + statement2 = DBManager.prepareStatement("SELECT player_id, isop FROM trapdoors_members WHERE trapdoorid = ?;");
  9839. + statement2.setInt(1, id);
  9840. + set2 = statement2.executeQuery();
  9841. +
  9842. + List<PlayerCredentials> members = new ArrayList<PlayerCredentials>();
  9843. + List<PlayerCredentials> operators = new ArrayList<PlayerCredentials>();
  9844.  
  9845. - List<String> members = new ArrayList<String>();
  9846. - List<String> operators = new ArrayList<String>();
  9847. + while (set2.next()) {
  9848. + String memberIdString = set2.getString("player_id");
  9849. + UUID memberId = UUID.fromString(memberIdString);
  9850.  
  9851. - while (set.next()) {
  9852. - if (set.getBoolean("isop")) {
  9853. - operators.add(set.getString("username"));
  9854. + if (memberId.equals(Configuration.EVERYONE_IDENTIFIER)) {
  9855. + members.add(Configuration.EVERYONE_CREDENTIALS);
  9856. + } else if (memberId.equals(Configuration.LOT_ACCESS_IDENTIFIER)) {
  9857. + members.add(Configuration.LOT_ACCESS_CREDENTIALS);
  9858. } else {
  9859. - members.add(set.getString("username"));
  9860. + boolean isOp = set2.getBoolean("isop");
  9861. +
  9862. + PlayerCredentials memberCredentials = PlayerCredentialsManager.getByUniqueId(memberId, true);
  9863. +
  9864. + if (isOp) {
  9865. + operators.add(memberCredentials);
  9866. + } else {
  9867. + members.add(memberCredentials);
  9868. + }
  9869. }
  9870. }
  9871.  
  9872. - trapdoors.put(id, new InnectisTrapdoor(world, loc, id, owner, members, operators, flags));
  9873. + DBManager.closeResultSet(set2);
  9874. + DBManager.closePreparedStatement(statement2);
  9875. +
  9876. + trapdoors.put(id, new InnectisTrapdoor(world, loc, id, ownerCredentials, members, operators, flags));
  9877. }
  9878. }
  9879. } catch (SQLException ex) {
  9880. @@ -198,7 +219,9 @@ public class TrapdoorHandler {
  9881. return false;
  9882. } finally {
  9883. DBManager.closeResultSet(set);
  9884. + DBManager.closeResultSet(set2);
  9885. DBManager.closePreparedStatement(statement);
  9886. + DBManager.closePreparedStatement(statement2);
  9887. }
  9888.  
  9889. return true;
  9890. diff --git a/src/net/innectis/innplugin/OwnedObjects/Handlers/WaypointHandler.java b/src/net/innectis/innplugin/OwnedObjects/Handlers/WaypointHandler.java
  9891. index e1d9a9f18..18e42f3e7 100644
  9892. --- a/src/net/innectis/innplugin/OwnedObjects/Handlers/WaypointHandler.java
  9893. +++ b/src/net/innectis/innplugin/OwnedObjects/Handlers/WaypointHandler.java
  9894. @@ -7,6 +7,8 @@ import java.util.ArrayList;
  9895. import java.util.HashMap;
  9896. import java.util.Iterator;
  9897. import java.util.List;
  9898. +import java.util.UUID;
  9899. +import net.innectis.innplugin.Configuration;
  9900. import net.innectis.innplugin.Handlers.BlockHandler;
  9901. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  9902. import net.innectis.innplugin.InnPlugin;
  9903. @@ -16,6 +18,8 @@ import net.innectis.innplugin.OwnedObjects.InnectisWaypoint;
  9904. import net.innectis.innplugin.Player.Chat.ChatColor;
  9905. import net.innectis.innplugin.Player.IdpPlayer;
  9906. import net.innectis.innplugin.Player.Permission;
  9907. +import net.innectis.innplugin.Player.PlayerCredentials;
  9908. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  9909. import org.bukkit.Bukkit;
  9910. import org.bukkit.Location;
  9911. import org.bukkit.World;
  9912. @@ -121,12 +125,14 @@ public class WaypointHandler {
  9913. return null;
  9914. }
  9915.  
  9916. - public static List<InnectisWaypoint> getWaypoints(String owner) {
  9917. + public static List<InnectisWaypoint> getWaypoints(String playerName) {
  9918. List<InnectisWaypoint> waypoints = new ArrayList<InnectisWaypoint>();
  9919. InnectisWaypoint waypoint;
  9920. +
  9921. for (Iterator<InnectisWaypoint> it = getWaypoints().values().iterator(); it.hasNext();) {
  9922. waypoint = it.next();
  9923. - if (waypoint.getOwner().equalsIgnoreCase(owner)) {
  9924. +
  9925. + if (waypoint.getOwner().equalsIgnoreCase(playerName)) {
  9926. waypoints.add(waypoint);
  9927. }
  9928. }
  9929. @@ -156,48 +162,71 @@ public class WaypointHandler {
  9930. return null;
  9931. }
  9932.  
  9933. - PreparedStatement statement = DBManager.prepareStatement("SELECT username, isop FROM waypoints_members WHERE waypointid = ?;");
  9934. + String ownerIdString = result.getString("owner_id");
  9935. + UUID ownerId = UUID.fromString(ownerIdString);
  9936. + PlayerCredentials ownerCredentials = PlayerCredentialsManager.getByUniqueId(ownerId, true);
  9937. +
  9938. + PreparedStatement statement = DBManager.prepareStatement("SELECT player_id, isop FROM waypoints_members WHERE waypointid = ?;");
  9939. statement.setInt(1, result.getInt("waypointid"));
  9940. ResultSet result2 = statement.executeQuery();
  9941. - List<String> members = new ArrayList<String>();
  9942. - List<String> operators = new ArrayList<String>();
  9943. +
  9944. + List<PlayerCredentials> members = new ArrayList<PlayerCredentials>();
  9945. + List<PlayerCredentials> operators = new ArrayList<PlayerCredentials>();
  9946. +
  9947. while (result2.next()) {
  9948. - if (result2.getBoolean("isop")) {
  9949. - operators.add(result2.getString("username"));
  9950. + String memberIdString = result2.getString("player_id");
  9951. + UUID memberId = UUID.fromString(memberIdString);
  9952. +
  9953. + if (memberId.equals(Configuration.EVERYONE_IDENTIFIER)) {
  9954. + members.add(Configuration.EVERYONE_CREDENTIALS);
  9955. + } else if (memberId.equals(Configuration.LOT_ACCESS_IDENTIFIER)) {
  9956. + members.add(Configuration.LOT_ACCESS_CREDENTIALS);
  9957. } else {
  9958. - members.add(result2.getString("username"));
  9959. + boolean isOp = result2.getBoolean("isop");
  9960. +
  9961. + PlayerCredentials memberCredentials = PlayerCredentialsManager.getByUniqueId(memberId, true);
  9962. +
  9963. + if (isOp) {
  9964. + operators.add(memberCredentials);
  9965. + } else {
  9966. + members.add(memberCredentials);
  9967. + }
  9968. }
  9969. }
  9970.  
  9971. DBManager.closeResultSet(result2);
  9972. DBManager.closePreparedStatement(statement);
  9973.  
  9974. - return new InnectisWaypoint(world, waypoint, destination, result.getInt("waypointid"), result.getString("owner"), members, operators, result.getLong("flags"), result.getBoolean("forced"));
  9975. + return new InnectisWaypoint(world, waypoint, destination, result.getInt("waypointid"), ownerCredentials, members, operators, result.getLong("flags"), result.getBoolean("forced"));
  9976. }
  9977.  
  9978. - public static boolean hasWaypoint(IdpPlayer player) {
  9979. + public static boolean hasWaypoint(String playerName) {
  9980. InnectisWaypoint waypoint;
  9981. for (Iterator<InnectisWaypoint> it = getWaypoints().values().iterator(); it.hasNext();) {
  9982. waypoint = it.next();
  9983. - if (waypoint.getOwner().equalsIgnoreCase(player.getName())) {
  9984. +
  9985. + if (waypoint.getOwner().equalsIgnoreCase(playerName)) {
  9986. return true;
  9987. }
  9988. }
  9989. return false;
  9990. }
  9991.  
  9992. - public static boolean isOwnWaypoint(IdpPlayer player, Location location) {
  9993. + public static boolean isOwnWaypoint(String playerName, Location location) {
  9994. InnectisWaypoint waypoint = getWaypoint(location);
  9995. +
  9996. if (waypoint == null) {
  9997. return false;
  9998. }
  9999. - if (waypoint.getOwner().equalsIgnoreCase(player.getName())) {
  10000. +
  10001. + if (waypoint.getOwner().equalsIgnoreCase(playerName)) {
  10002. return true;
  10003. }
  10004. +
  10005. return false;
  10006. }
  10007.  
  10008. - public static InnectisWaypoint createWaypoint(IdpPlayer player, Block block, boolean force) throws SQLException {
  10009. + public static InnectisWaypoint createWaypoint(PlayerCredentials ownerCredentials, Block block, boolean force) throws SQLException {
  10010. Location loc = block.getLocation();
  10011. InnectisWaypoint existingWaypoint = getWaypoint(loc);
  10012.  
  10013. @@ -206,35 +235,10 @@ public class WaypointHandler {
  10014. return existingWaypoint;
  10015. }
  10016.  
  10017. - InnectisWaypoint innwaypoint = new InnectisWaypoint(block.getWorld(), block, loc, -1, player.getName(), null, null, 0, force);
  10018. - innwaypoint.addMember("%");
  10019. - innwaypoint.save();
  10020. - WaypointHandler.getWaypoints().put(innwaypoint.getId(), innwaypoint);
  10021. -
  10022. - BlockHandler.setBlock(block, IdpMaterial.WAYPOINT);
  10023. -
  10024. - return innwaypoint;
  10025. - }
  10026. -
  10027. - /**
  10028. - * Creates a waypoint at the given location
  10029. - * @param playername
  10030. - * @param block
  10031. - * @return
  10032. - * The waypoint if success else null
  10033. - * @throws SQLException
  10034. - */
  10035. - public static InnectisWaypoint createWaypoint(String playername, Block block, boolean force) throws SQLException {
  10036. - Location loc = block.getLocation();
  10037. - InnectisWaypoint existingWaypoint = getWaypoint(loc);
  10038. -
  10039. - // Allow placement, original owner is assumed
  10040. - if (existingWaypoint != null) {
  10041. - return existingWaypoint;
  10042. - }
  10043. + List<PlayerCredentials> members = new ArrayList<PlayerCredentials>();
  10044. + members.add(Configuration.EVERYONE_CREDENTIALS);
  10045.  
  10046. - InnectisWaypoint innwaypoint = new InnectisWaypoint(block.getWorld(), block, loc, -1, playername, null, null, 0, force);
  10047. - innwaypoint.addMember("%");
  10048. + InnectisWaypoint innwaypoint = new InnectisWaypoint(block.getWorld(), block, loc, -1, ownerCredentials, members, null, 0, force);
  10049. innwaypoint.save();
  10050. WaypointHandler.getWaypoints().put(innwaypoint.getId(), innwaypoint);
  10051.  
  10052. diff --git a/src/net/innectis/innplugin/OwnedObjects/InnectisBookcase.java b/src/net/innectis/innplugin/OwnedObjects/InnectisBookcase.java
  10053. index 8f8db1996..ed7b446df 100644
  10054. --- a/src/net/innectis/innplugin/OwnedObjects/InnectisBookcase.java
  10055. +++ b/src/net/innectis/innplugin/OwnedObjects/InnectisBookcase.java
  10056. @@ -5,16 +5,17 @@ import java.sql.PreparedStatement;
  10057. import java.sql.ResultSet;
  10058. import java.sql.SQLException;
  10059. import java.util.ArrayList;
  10060. -import java.util.Arrays;
  10061. import java.util.List;
  10062. +import java.util.UUID;
  10063. +import net.innectis.innplugin.Configuration;
  10064. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  10065. import net.innectis.innplugin.InnPlugin;
  10066. import net.innectis.innplugin.Items.IdpItemStack;
  10067. import net.innectis.innplugin.Items.IdpMaterial;
  10068. import net.innectis.innplugin.Items.StackBag;
  10069. import net.innectis.innplugin.OwnedObjects.Handlers.LotHandler;
  10070. -import net.innectis.innplugin.Player.IdpPlayer;
  10071. -import net.innectis.innplugin.Utility.StringUtil;
  10072. +import net.innectis.innplugin.Player.PlayerCredentials;
  10073. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  10074. import org.bukkit.Bukkit;
  10075. import org.bukkit.Location;
  10076. import org.bukkit.World;
  10077. @@ -25,7 +26,7 @@ import org.bukkit.block.Block;
  10078. * @author Hretsam
  10079. *
  10080. */
  10081. -public class InnectisBookcase extends InnectisOwnedObject<Long> {
  10082. +public class InnectisBookcase extends InnectisOwnedObject {
  10083. private Block bookcase;
  10084. private long bagid;
  10085. private IdpItemStack[] items = null;
  10086. @@ -35,19 +36,19 @@ public class InnectisBookcase extends InnectisOwnedObject<Long> {
  10087. * Makes a new InnectisBookcase object
  10088. * @param world
  10089. * @param bookcase
  10090. - * @param owner
  10091. + * @param ownerCredentials
  10092. */
  10093. - public InnectisBookcase(World world, Block bookcase, String owner) {
  10094. - super(world, bookcase.getLocation().toVector(), bookcase.getLocation().toVector(), -1l, owner, new ArrayList<String>(0), new ArrayList<String>(0), 0);
  10095. + public InnectisBookcase(World world, Block bookcase, PlayerCredentials ownerCredentials) {
  10096. + super(world, bookcase.getLocation().toVector(), bookcase.getLocation().toVector(), -1, ownerCredentials, new ArrayList<PlayerCredentials>(0), new ArrayList<PlayerCredentials>(0), 0);
  10097. this.bookcase = bookcase;
  10098. - this.caseTitle = "Bookcase";
  10099. - this.bagid = -1l;
  10100. + caseTitle = "Bookcase";
  10101. + bagid = -1l;
  10102. }
  10103.  
  10104. - private InnectisBookcase(World world, Block bookcase, long id, long bagid, String owner, String casetitle, List<String> members, List<String> operators, long flags) {
  10105. - super(world, bookcase.getLocation().toVector(), bookcase.getLocation().toVector(), id, owner, members, operators, flags);
  10106. + private InnectisBookcase(World world, Block bookcase, int id, long bagid, PlayerCredentials ownerCredentials, String caseTitle, List<PlayerCredentials> members, List<PlayerCredentials> operators, long flags) {
  10107. + super(world, bookcase.getLocation().toVector(), bookcase.getLocation().toVector(), id, ownerCredentials, members, operators, flags);
  10108. this.bookcase = bookcase;
  10109. - this.caseTitle = casetitle;
  10110. + this.caseTitle = caseTitle;
  10111. this.bagid = bagid;
  10112. }
  10113.  
  10114. @@ -73,11 +74,11 @@ public class InnectisBookcase extends InnectisOwnedObject<Long> {
  10115. */
  10116. public void setCaseTitle(String caseTitle) {
  10117. this.caseTitle = caseTitle;
  10118. - setUpdated(true);
  10119. + super.setUpdated(true);
  10120. }
  10121.  
  10122. public Block getBookcase() {
  10123. - return this.bookcase;
  10124. + return bookcase;
  10125. }
  10126.  
  10127. /**
  10128. @@ -109,7 +110,7 @@ public class InnectisBookcase extends InnectisOwnedObject<Long> {
  10129. */
  10130. public void setItems(IdpItemStack[] items) {
  10131. this.items = items;
  10132. - setUpdated(true);
  10133. + super.setUpdated(true);
  10134. }
  10135.  
  10136. /**
  10137. @@ -126,7 +127,7 @@ public class InnectisBookcase extends InnectisOwnedObject<Long> {
  10138. for (int i = 0; i < getItems().length; i++) {
  10139. if (getItem(i) == null || getItem(i).getMaterial() == IdpMaterial.AIR) {
  10140. items[i] = item;
  10141. - setUpdated(true);
  10142. + super.setUpdated(true);
  10143. return true;
  10144. }
  10145. }
  10146. @@ -167,13 +168,14 @@ public class InnectisBookcase extends InnectisOwnedObject<Long> {
  10147. * @param player
  10148. */
  10149. @Override
  10150. - public boolean canPlayerAccess(IdpPlayer player) {
  10151. - if (super.canPlayerAccess(player)) {
  10152. + public boolean canPlayerAccess(String playerName) {
  10153. + if (super.canPlayerAccess(playerName)) {
  10154. return true;
  10155. }
  10156. +
  10157. if (containsMember("@")) { //allow lot members
  10158. InnectisLot lot = LotHandler.getLot(bookcase.getLocation());
  10159. - if (lot != null && (lot.containsMember(player.getName()) || lot.containsOperator(player.getName()))) {
  10160. + if (lot != null && (lot.containsMember(playerName) || lot.containsOperator(playerName))) {
  10161. return true;
  10162. }
  10163. }
  10164. @@ -191,21 +193,21 @@ public class InnectisBookcase extends InnectisOwnedObject<Long> {
  10165.  
  10166. try {
  10167. statement = DBManager.prepareStatementWithAutoGeneratedKeys("REPLACE INTO bookcase "
  10168. - + "(bagid, owner, world, locx, locy, locz, flags, casetitle) VALUES (?,?,?,?,?,?,?,?) ");
  10169. + + "(bagid, owner_id, world, locx, locy, locz, flags, casetitle) VALUES (?,?,?,?,?,?,?,?);");
  10170. statement.setLong(1, bagid);
  10171. - statement.setString(2, getOwner());
  10172. - statement.setString(3, getWorld().getName());
  10173. + statement.setString(2, super.getOwnerCredentials().getUniqueId().toString());
  10174. + statement.setString(3, super.getWorld().getName());
  10175. statement.setInt(4, getBookcase().getX());
  10176. statement.setInt(5, getBookcase().getY());
  10177. statement.setInt(6, getBookcase().getZ());
  10178. - statement.setLong(7, getFlags());
  10179. + statement.setLong(7, super.getFlags());
  10180. statement.setString(8, getCaseTitle());
  10181. statement.executeUpdate();
  10182. result = statement.getGeneratedKeys();
  10183.  
  10184. if (result.next()) {
  10185. - setId(result.getLong(1));
  10186. - setUpdated(false);
  10187. + setId(result.getInt(1));
  10188. + super.setUpdated(false);
  10189. } else {
  10190. InnPlugin.logError("New bookcase not found in the database!");
  10191. return false;
  10192. @@ -240,43 +242,43 @@ public class InnectisBookcase extends InnectisOwnedObject<Long> {
  10193. conn.setAutoCommit(false);
  10194.  
  10195. statement = conn.prepareStatement(
  10196. - "UPDATE bookcase SET bagid = ?, owner = ?, world = ?, locx = ?, "
  10197. - + "locy = ?, locz = ?, flags = ?, casetitle = ? WHERE bookcaseid = ? ");
  10198. + "UPDATE bookcase SET bagid = ?, owner_id = ?, world = ?, locx = ?, "
  10199. + + "locy = ?, locz = ?, flags = ?, casetitle = ? WHERE bookcaseid = ?;");
  10200. statement.setLong(1, bagid);
  10201. - statement.setString(2, getOwner());
  10202. - statement.setString(3, getWorld().getName());
  10203. + statement.setString(2, super.getOwnerCredentials().getUniqueId().toString());
  10204. + statement.setString(3, super.getWorld().getName());
  10205. statement.setInt(4, getBookcase().getX());
  10206. statement.setInt(5, getBookcase().getY());
  10207. statement.setInt(6, getBookcase().getZ());
  10208. - statement.setLong(7, getFlags());
  10209. + statement.setLong(7, super.getFlags());
  10210. statement.setString(8, getCaseTitle());
  10211. - statement.setLong(9, getId());
  10212. + statement.setInt(9, super.getId());
  10213. statement.executeUpdate();
  10214. DBManager.closePreparedStatement(statement);
  10215.  
  10216. statement = conn.prepareStatement("DELETE FROM bookcase_members WHERE bookcaseid = ?; ");
  10217. - statement.setLong(1, getId());
  10218. + statement.setLong(1, super.getId());
  10219. statement.executeUpdate();
  10220. DBManager.closePreparedStatement(statement);
  10221.  
  10222. - for (String s : getMembers()) {
  10223. - statement = conn.prepareStatement("INSERT INTO bookcase_members (bookcaseid, username, isop) VALUES (?, ?, 0);");
  10224. - statement.setLong(1, getId());
  10225. - statement.setString(2, s);
  10226. + for (PlayerCredentials pc : super.getMembers()) {
  10227. + statement = conn.prepareStatement("INSERT INTO bookcase_members (bookcaseid, player_id, isop) VALUES (?, ?, 0);");
  10228. + statement.setInt(1, super.getId());
  10229. + statement.setString(2, pc.getUniqueId().toString());
  10230. statement.executeUpdate();
  10231. DBManager.closePreparedStatement(statement);
  10232. }
  10233.  
  10234. - for (String s : getOperators()) {
  10235. - statement = conn.prepareStatement("INSERT INTO bookcase_members (bookcaseid, username, isop) VALUES (?, ?, 1);");
  10236. - statement.setLong(1, getId());
  10237. - statement.setString(2, s);
  10238. + for (PlayerCredentials pc : super.getOperators()) {
  10239. + statement = conn.prepareStatement("INSERT INTO bookcase_members (bookcaseid, player_id, isop) VALUES (?, ?, 1);");
  10240. + statement.setInt(1, super.getId());
  10241. + statement.setString(2, pc.getUniqueId().toString());
  10242. statement.executeUpdate();
  10243. DBManager.closePreparedStatement(statement);
  10244. }
  10245.  
  10246. conn.commit();
  10247. - setUpdated(false);
  10248. + super.setUpdated(false);
  10249. } catch (SQLException ex) {
  10250. InnPlugin.logError("Unable to save bookcase!", ex);
  10251. return false;
  10252. @@ -301,19 +303,19 @@ public class InnectisBookcase extends InnectisOwnedObject<Long> {
  10253. * @param bookcaseid
  10254. * @return the bookcase or null if not found
  10255. */
  10256. - public static InnectisBookcase getBookcase(long bookcaseid) {
  10257. + public static InnectisBookcase getBookcase(int bookcaseid) {
  10258. PreparedStatement statement = null;
  10259. ResultSet set = null;
  10260.  
  10261. try {
  10262. statement = DBManager.prepareStatement(""
  10263. - + "SELECT b.bookcaseid, bagid, owner, world, locx, locy, locz, flags, casetitle, "
  10264. - + " (SELECT group_concat(bmem.username SEPARATOR ';') "
  10265. - + " FROM bookcase_members as bmem where b.bookcaseid = bmem.bookcaseid and isop = 0 ) as members, "
  10266. - + " (SELECT group_concat(bop.username SEPARATOR ';') "
  10267. - + " FROM bookcase_members as bop where b.bookcaseid = bop.bookcaseid and isop = 1 ) as operators "
  10268. - + "FROM bookcase as b WHERE b.bookcaseid = ? ");
  10269. - statement.setLong(1, bookcaseid);
  10270. + + "SELECT b.bookcaseid, bagid, owner_id, world, locx, locy, locz, flags, casetitle, "
  10271. + + " (SELECT group_concat(bmem.owner_id SEPARATOR ';') "
  10272. + + " FROM bookcase_members as bmem where b.bookcaseid = bmem.bookcaseid and isop = 0 ) as member_id_list, "
  10273. + + " (SELECT group_concat(bop.player_id SEPARATOR ';') "
  10274. + + " FROM bookcase_members as bop where b.bookcaseid = bop.bookcaseid and isop = 1 ) as operator_id_list "
  10275. + + "FROM bookcase as b WHERE b.bookcaseid = ?;");
  10276. + statement.setInt(1, bookcaseid);
  10277. set = statement.executeQuery();
  10278.  
  10279. if (set.next()) {
  10280. @@ -340,12 +342,12 @@ public class InnectisBookcase extends InnectisOwnedObject<Long> {
  10281.  
  10282. try {
  10283. statement = DBManager.prepareStatement(""
  10284. - + "SELECT b.bookcaseid, bagid, owner, world, locx, locy, locz, flags, casetitle, "
  10285. - + " (SELECT group_concat(bmem.username SEPARATOR ';') "
  10286. - + " FROM bookcase_members as bmem where b.bookcaseid = bmem.bookcaseid and isop = 0 ) as members, "
  10287. - + " (SELECT group_concat(bop.username SEPARATOR ';') "
  10288. - + " FROM bookcase_members as bop where b.bookcaseid = bop.bookcaseid and isop = 1 ) as operators "
  10289. - + "FROM bookcase as b WHERE world = ? AND locx = ? AND locy = ? AND locz = ? ");
  10290. + + "SELECT b.bookcaseid, bagid, owner_id, world, locx, locy, locz, flags, casetitle, "
  10291. + + " (SELECT group_concat(bmem.player_id SEPARATOR ';') "
  10292. + + " FROM bookcase_members as bmem where b.bookcaseid = bmem.bookcaseid and isop = 0 ) as member_id_list, "
  10293. + + " (SELECT group_concat(bop.player_id SEPARATOR ';') "
  10294. + + " FROM bookcase_members as bop where b.bookcaseid = bop.bookcaseid and isop = 1 ) as operator_id_list "
  10295. + + "FROM bookcase as b WHERE world = ? AND locx = ? AND locy = ? AND locz = ?;");
  10296. statement.setString(1, location.getWorld().getName());
  10297. statement.setInt(2, location.getBlockX());
  10298. statement.setInt(3, location.getBlockY());
  10299. @@ -366,23 +368,26 @@ public class InnectisBookcase extends InnectisOwnedObject<Long> {
  10300. }
  10301.  
  10302. /**
  10303. - * Looks up all the bookcases owned by the given player.
  10304. - * @param owner
  10305. + * Looks up all the bookcases owned by the player represented by their ID
  10306. + * @param playerName
  10307. * @return List of the bookcases or null is none.
  10308. */
  10309. - public static List<InnectisBookcase>getBookcases(String owner) {
  10310. + public static List<InnectisBookcase> getBookcases(String playerName) {
  10311. + // TODO: Load these trapdoors in another way, this method isn't the best
  10312. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  10313. +
  10314. PreparedStatement statement = null;
  10315. ResultSet set = null;
  10316.  
  10317. try {
  10318. statement = DBManager.prepareStatement(""
  10319. - + "SELECT b.bookcaseid, bagid, owner, world, locx, locy, locz, flags, casetitle, "
  10320. - + " (SELECT group_concat(bmem.username SEPARATOR ';') "
  10321. + + "SELECT b.bookcaseid, bagid, owner_id, world, locx, locy, locz, flags, casetitle, "
  10322. + + " (SELECT group_concat(bmem.player_id SEPARATOR ';') "
  10323. + " FROM bookcase_members as bmem where b.bookcaseid = bmem.bookcaseid and isop = 0 ) as members, "
  10324. - + " (SELECT group_concat(bop.username SEPARATOR ';') "
  10325. + + " (SELECT group_concat(bop.player_id SEPARATOR ';') "
  10326. + " FROM bookcase_members as bop where b.bookcaseid = bop.bookcaseid and isop = 1 ) as operators "
  10327. - + "FROM bookcase as b WHERE lower(owner) = ? ");
  10328. - statement.setString(1, owner.toLowerCase());
  10329. + + "FROM bookcase as b WHERE owner_id = ?;");
  10330. + statement.setString(1, credentials.getUniqueId().toString());
  10331. set = statement.executeQuery();
  10332.  
  10333. List<InnectisBookcase> bookcases = new ArrayList<InnectisBookcase>(set.getFetchSize());
  10334. @@ -415,31 +420,49 @@ public class InnectisBookcase extends InnectisOwnedObject<Long> {
  10335. return null;
  10336. }
  10337.  
  10338. - long bookcaseid = set.getLong("bookcaseid");
  10339. + int bookcaseid = set.getInt("bookcaseid");
  10340. long bagid = set.getLong("bagid");
  10341. - String owner = set.getString("owner");
  10342. +
  10343. + String ownerIdString = set.getString("owner_id");
  10344. + UUID ownerId = UUID.fromString(ownerIdString);
  10345. + PlayerCredentials ownerCredentials = PlayerCredentialsManager.getByUniqueId(ownerId, true);
  10346. +
  10347. String casetitle = set.getString("casetitle");
  10348. int x = set.getInt("locx");
  10349. int y = set.getInt("locy");
  10350. int z = set.getInt("locz");
  10351. long flags = set.getLong("flags");
  10352. - List<String> members;
  10353. - String memberString = set.getString("members");
  10354. - if (!StringUtil.stringIsNullOrEmpty(memberString)) {
  10355. - members = new ArrayList<String>(Arrays.asList(memberString.split(";")));
  10356. - } else {
  10357. - members = new ArrayList<String>();
  10358. +
  10359. + List<PlayerCredentials> members = new ArrayList<PlayerCredentials>();
  10360. + String memberIdStringList = set.getString("member_id_list");
  10361. +
  10362. + if (memberIdStringList != null) {
  10363. + for (String memberIdString : memberIdStringList.split(";")) {
  10364. + UUID memberId = UUID.fromString(memberIdString);
  10365. +
  10366. + if (memberId.equals(Configuration.EVERYONE_IDENTIFIER)) {
  10367. + members.add(Configuration.EVERYONE_CREDENTIALS);
  10368. + } else if (memberId.equals(Configuration.LOT_ACCESS_IDENTIFIER)) {
  10369. + members.add(Configuration.LOT_ACCESS_CREDENTIALS);
  10370. + } else {
  10371. + PlayerCredentials memberCredentials = PlayerCredentialsManager.getByUniqueId(memberId, true);
  10372. + members.add(memberCredentials);
  10373. + }
  10374. + }
  10375. }
  10376.  
  10377. - List<String> operators;
  10378. - String operatorString = set.getString("operators");
  10379. - if (!StringUtil.stringIsNullOrEmpty(operatorString)) {
  10380. - operators = new ArrayList<String>(Arrays.asList(operatorString.split(";")));
  10381. - } else {
  10382. - operators = new ArrayList<String>();
  10383. + List<PlayerCredentials> operators = new ArrayList<PlayerCredentials>();
  10384. + String operatorIdStringList = set.getString("operator_id_list");
  10385. +
  10386. + if (operatorIdStringList != null) {
  10387. + for (String operatorIdString : operatorIdStringList.split(";")) {
  10388. + UUID operatorId = UUID.fromString(operatorIdString);
  10389. + PlayerCredentials operatorCredentials = PlayerCredentialsManager.getByUniqueId(operatorId);
  10390. + operators.add(operatorCredentials);
  10391. + }
  10392. }
  10393.  
  10394. - return new InnectisBookcase(world, world.getBlockAt(x, y, z), bookcaseid, bagid, owner, casetitle, members, operators, flags);
  10395. + return new InnectisBookcase(world, world.getBlockAt(x, y, z), bookcaseid, bagid, ownerCredentials, casetitle, members, operators, flags);
  10396. }
  10397.  
  10398. /**
  10399. @@ -452,12 +475,12 @@ public class InnectisBookcase extends InnectisOwnedObject<Long> {
  10400. StackBag.delete(bagid);
  10401.  
  10402. statement = DBManager.prepareStatement("DELETE FROM bookcase WHERE bookcaseid = ? ");
  10403. - statement.setLong(1, getId());
  10404. + statement.setInt(1, super.getId());
  10405. statement.executeUpdate();
  10406. DBManager.closePreparedStatement(statement);
  10407.  
  10408. statement = DBManager.prepareStatement("DELETE FROM bookcase_members WHERE bookcaseid = ? ");
  10409. - statement.setLong(1, getId());
  10410. + statement.setInt(1, super.getId());
  10411. statement.executeUpdate();
  10412. } catch (SQLException ex) {
  10413. InnPlugin.logError("Cant remove get bookcase! ", ex);
  10414. @@ -476,7 +499,7 @@ public class InnectisBookcase extends InnectisOwnedObject<Long> {
  10415. return false;
  10416. }
  10417. }
  10418. - return true;
  10419.  
  10420. + return true;
  10421. }
  10422. }
  10423. diff --git a/src/net/innectis/innplugin/OwnedObjects/InnectisChest.java b/src/net/innectis/innplugin/OwnedObjects/InnectisChest.java
  10424. index 84d203e12..6404cbe58 100644
  10425. --- a/src/net/innectis/innplugin/OwnedObjects/InnectisChest.java
  10426. +++ b/src/net/innectis/innplugin/OwnedObjects/InnectisChest.java
  10427. @@ -6,6 +6,7 @@ import java.sql.SQLException;
  10428. import java.util.Arrays;
  10429. import java.util.Comparator;
  10430. import java.util.List;
  10431. +import java.util.UUID;
  10432. import java.util.logging.Level;
  10433. import java.util.logging.Logger;
  10434. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  10435. @@ -16,7 +17,7 @@ import net.innectis.innplugin.Items.IdpItemStack;
  10436. import net.innectis.innplugin.Items.IdpMaterial;
  10437. import net.innectis.innplugin.OwnedObjects.Handlers.ChestHandler;
  10438. import net.innectis.innplugin.OwnedObjects.Handlers.ChestHandler.ChestType;
  10439. -import net.innectis.innplugin.Player.IdpPlayer;
  10440. +import net.innectis.innplugin.Player.PlayerCredentials;
  10441. import net.innectis.innplugin.Utility.DatabaseTools;
  10442. import net.innectis.innplugin.Utility.ObjectParseException;
  10443. import org.bukkit.Location;
  10444. @@ -30,7 +31,7 @@ import org.bukkit.inventory.Inventory;
  10445. *
  10446. * @author Lynxy
  10447. */
  10448. -public class InnectisChest extends InnectisOwnedObject<Integer> {
  10449. +public class InnectisChest extends InnectisOwnedObject {
  10450. // Cached comparator for IdpItemStacks in chests
  10451. private static Comparator<IdpItemStack> chestComparator = null;
  10452.  
  10453. @@ -38,8 +39,8 @@ public class InnectisChest extends InnectisOwnedObject<Integer> {
  10454. private Block chest2;
  10455. private ChestType type;
  10456.  
  10457. - public InnectisChest(ChestType type, World world, Block chest1, Block chest2, int id, String owner, List<String> members, List<String> operators, long flags) {
  10458. - super(world, chest1.getLocation().toVector(), (chest2 == null ? chest1.getLocation().toVector() : chest2.getLocation().toVector()), id, owner, members, operators, flags);
  10459. + public InnectisChest(ChestType type, World world, Block chest1, Block chest2, int id, PlayerCredentials ownerCredentials, List<PlayerCredentials> members, List<PlayerCredentials> operators, long flags) {
  10460. + super(world, chest1.getLocation().toVector(), (chest2 == null ? chest1.getLocation().toVector() : chest2.getLocation().toVector()), id, ownerCredentials, members, operators, flags);
  10461. this.chest1 = chest1;
  10462. this.chest2 = chest2;
  10463. this.type = type;
  10464. @@ -187,25 +188,16 @@ public class InnectisChest extends InnectisOwnedObject<Integer> {
  10465. }
  10466.  
  10467. /**
  10468. - * Returns true if the player is the owner or a member, or if this Chest's owner is % or contains member %, or if this Chest has member
  10469. - * @ and player is a member of the Lot this chest is on
  10470. - * @param player
  10471. + * Logs chest access from the following player represented by ID
  10472. + * @param playerId
  10473. */
  10474. - @Override
  10475. - public boolean canPlayerAccess(IdpPlayer player) {
  10476. - if (super.canPlayerAccess(player)) {
  10477. - return true;
  10478. - }
  10479. - return false;
  10480. - }
  10481. -
  10482. - public void logChestAccess(IdpPlayer player) {
  10483. + public void logChestAccess(UUID playerId) {
  10484. PreparedStatement statement = null;
  10485.  
  10486. try {
  10487. - statement = DBManager.prepareStatement("INSERT DELAYED INTO chestlog (chestid,username) VALUES (?,?);");
  10488. - statement.setInt(1, getId());
  10489. - statement.setString(2, player.getName().toLowerCase());
  10490. + statement = DBManager.prepareStatement("INSERT DELAYED INTO chestlog (chestid, player_id) VALUES (?,?);");
  10491. + statement.setInt(1, super.getId());
  10492. + statement.setString(2, playerId.toString());
  10493. statement.executeUpdate();
  10494. } catch (SQLException ex) {
  10495. Logger.getLogger(ChestHandler.class.getName()).log(Level.SEVERE, null, ex);
  10496. @@ -225,7 +217,7 @@ public class InnectisChest extends InnectisOwnedObject<Integer> {
  10497.  
  10498. try {
  10499. statement = DBManager.prepareStatement("SELECT * FROM chestlog WHERE chestid = ? ORDER BY DATE desc LIMIT ?;");
  10500. - statement.setInt(1, getId());
  10501. + statement.setInt(1, super.getId());
  10502. statement.setInt(2, (amount.length == 0 ? 10 : amount[0]));
  10503.  
  10504. // Return the parsed list
  10505. @@ -241,30 +233,32 @@ public class InnectisChest extends InnectisOwnedObject<Integer> {
  10506. return null;
  10507. }
  10508.  
  10509. + // TODO: Add lot member access checks
  10510. +
  10511. private boolean createChestInDB() {
  10512. PreparedStatement statement = null;
  10513. ResultSet result = null;
  10514.  
  10515. try {
  10516. statement = DBManager.prepareStatementWithAutoGeneratedKeys("REPLACE INTO chests "
  10517. - + "(typeid, owner, world, locx1, locy1, locz1, locx2, locy2, locz2, flags)"
  10518. + + "(typeid, owner_id, world, locx1, locy1, locz1, locx2, locy2, locz2, flags)"
  10519. + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
  10520. statement.setInt(1, getType().getId());
  10521. - statement.setString(2, getOwner());
  10522. - statement.setString(3, getWorld().getName());
  10523. + statement.setString(2, super.getOwnerCredentials().getUniqueId().toString());
  10524. + statement.setString(3, super.getWorld().getName());
  10525. statement.setInt(4, getChest1().getX());
  10526. statement.setInt(5, getChest1().getY());
  10527. statement.setInt(6, getChest1().getZ());
  10528. statement.setInt(7, getChest2() == null ? 0 : getChest2().getX());
  10529. statement.setInt(8, getChest2() == null ? 0 : getChest2().getY());
  10530. statement.setInt(9, getChest2() == null ? 0 : getChest2().getZ());
  10531. - statement.setLong(10, getFlags());
  10532. + statement.setLong(10, super.getFlags());
  10533. statement.executeUpdate();
  10534. result = statement.getGeneratedKeys();
  10535.  
  10536. if (result.next()) {
  10537. - setId(result.getInt(1));
  10538. - setUpdated(false);
  10539. + super.setId(result.getInt(1));
  10540. + super.setUpdated(false);
  10541. } else {
  10542. InnPlugin.logError("New chest was not found in the database!");
  10543. return false;
  10544. @@ -291,52 +285,45 @@ public class InnectisChest extends InnectisOwnedObject<Integer> {
  10545. }
  10546.  
  10547. statement = DBManager.prepareStatement("UPDATE chests SET "
  10548. - + "typeid = ?, "
  10549. - + "owner = ?, "
  10550. - + "world = ?, "
  10551. - + "locx1 = ?, "
  10552. - + "locy1 = ?, "
  10553. - + "locz1 = ?, "
  10554. - + "locx2 = ?, "
  10555. - + "locy2 = ?, "
  10556. - + "locz2 = ?, "
  10557. - + "flags = ? "
  10558. - + "WHERE chestid = ?;");
  10559. + + "typeid = ?, owner_id = ?, world = ?, "
  10560. + + "locx1 = ?, locy1 = ?, locz1 = ?, "
  10561. + + "locx2 = ?, locy2 = ?, locz2 = ?, "
  10562. + + "flags = ? WHERE chestid = ?;");
  10563. statement.setInt(1, getType().getId());
  10564. - statement.setString(2, getOwner());
  10565. - statement.setString(3, getWorld().getName());
  10566. + statement.setString(2, super.getOwnerCredentials().getUniqueId().toString());
  10567. + statement.setString(3, super.getWorld().getName());
  10568. statement.setInt(4, getChest1().getX());
  10569. statement.setInt(5, getChest1().getY());
  10570. statement.setInt(6, getChest1().getZ());
  10571. statement.setInt(7, getChest2() == null ? 0 : getChest2().getX());
  10572. statement.setInt(8, getChest2() == null ? 0 : getChest2().getY());
  10573. statement.setInt(9, getChest2() == null ? 0 : getChest2().getZ());
  10574. - statement.setLong(10, getFlags());
  10575. - statement.setInt(11, getId());
  10576. + statement.setLong(10, super.getFlags());
  10577. + statement.setInt(11, super.getId());
  10578. statement.executeUpdate();
  10579. DBManager.closePreparedStatement(statement);
  10580.  
  10581. statement = DBManager.prepareStatement("DELETE FROM chests_members WHERE chestid = ?;");
  10582. - statement.setInt(1, getId());
  10583. + statement.setInt(1, super.getId());
  10584. statement.executeUpdate();
  10585. DBManager.closePreparedStatement(statement);
  10586.  
  10587. - for (String s : getMembers()) {
  10588. - statement = DBManager.prepareStatement("INSERT INTO chests_members (chestid, username, isop) VALUES (?, ?, 0);");
  10589. - statement.setInt(1, getId());
  10590. - statement.setString(2, s);
  10591. + for (PlayerCredentials pc : getMembers()) {
  10592. + statement = DBManager.prepareStatement("INSERT INTO chests_members (chestid, player_id, isop) VALUES (?, ?, 0);");
  10593. + statement.setInt(1, super.getId());
  10594. + statement.setString(2, pc.getUniqueId().toString());
  10595. statement.executeUpdate();
  10596. DBManager.closePreparedStatement(statement);
  10597. }
  10598. - for (String s : getOperators()) {
  10599. - statement = DBManager.prepareStatement("INSERT INTO chests_members (chestid, username, isop) VALUES (?, ?, 1);");
  10600. - statement.setInt(1, getId());
  10601. - statement.setString(2, s);
  10602. + for (PlayerCredentials pc : getOperators()) {
  10603. + statement = DBManager.prepareStatement("INSERT INTO chests_members (chestid, player_id, isop) VALUES (?, ?, 1);");
  10604. + statement.setInt(1, super.getId());
  10605. + statement.setString(2, pc.getUniqueId().toString());
  10606. statement.executeUpdate();
  10607. DBManager.closePreparedStatement(statement);
  10608. }
  10609.  
  10610. - setUpdated(false);
  10611. + super.setUpdated(false);
  10612. } catch (SQLException ex) {
  10613. InnPlugin.logError("Unable to save chest!", ex);
  10614. return false;
  10615. diff --git a/src/net/innectis/innplugin/OwnedObjects/InnectisDoor.java b/src/net/innectis/innplugin/OwnedObjects/InnectisDoor.java
  10616. index bb80fa765..f61f3fb54 100644
  10617. --- a/src/net/innectis/innplugin/OwnedObjects/InnectisDoor.java
  10618. +++ b/src/net/innectis/innplugin/OwnedObjects/InnectisDoor.java
  10619. @@ -8,7 +8,7 @@ import net.innectis.innplugin.Handlers.Datasource.DBManager;
  10620. import net.innectis.innplugin.InnPlugin;
  10621. import net.innectis.innplugin.Items.IdpMaterial;
  10622. import net.innectis.innplugin.OwnedObjects.Handlers.LotHandler;
  10623. -import net.innectis.innplugin.Player.IdpPlayer;
  10624. +import net.innectis.innplugin.Player.PlayerCredentials;
  10625. import org.bukkit.Location;
  10626. import org.bukkit.World;
  10627. import org.bukkit.block.Block;
  10628. @@ -17,12 +17,12 @@ import org.bukkit.block.Block;
  10629. *
  10630. * @author Lynxy
  10631. */
  10632. -public class InnectisDoor extends InnectisOwnedObject<Integer> {
  10633. +public class InnectisDoor extends InnectisOwnedObject {
  10634. private Block door1;
  10635. private Block door2;
  10636.  
  10637. - public InnectisDoor(World world, Block door1, Block door2, int id, String owner, List<String> members,List<String> operators, long flags) {
  10638. - super(world, door1.getLocation().toVector(), (door2 == null ? door1.getLocation().toVector() : door2.getLocation().toVector()), id, owner, members, operators, flags);
  10639. + public InnectisDoor(World world, Block door1, Block door2, int id, PlayerCredentials ownerCredentials, List<PlayerCredentials> members, List<PlayerCredentials> operators, long flags) {
  10640. + super(world, door1.getLocation().toVector(), (door2 == null ? door1.getLocation().toVector() : door2.getLocation().toVector()), id, ownerCredentials, members, operators, flags);
  10641. this.door1 = door1;
  10642. this.door2 = door2;
  10643. }
  10644. @@ -109,13 +109,14 @@ public class InnectisDoor extends InnectisOwnedObject<Integer> {
  10645. * @param player
  10646. */
  10647. @Override
  10648. - public boolean canPlayerAccess(IdpPlayer player) {
  10649. - if (super.canPlayerAccess(player)) {
  10650. + public boolean canPlayerAccess(String playerName) {
  10651. + if (super.canPlayerAccess(playerName)) {
  10652. return true;
  10653. }
  10654. +
  10655. if (containsMember("@")) { //allow lot members
  10656. InnectisLot lot = LotHandler.getLot(door1.getLocation());
  10657. - if (lot != null && (lot.containsMember(player.getName()) || lot.containsOperator(player.getName()))) {
  10658. + if (lot != null && (lot.containsMember(playerName) || lot.containsOperator(playerName))) {
  10659. return true;
  10660. }
  10661. }
  10662. @@ -128,23 +129,23 @@ public class InnectisDoor extends InnectisOwnedObject<Integer> {
  10663.  
  10664. try {
  10665. statement = DBManager.prepareStatementWithAutoGeneratedKeys("REPLACE INTO doors "
  10666. - + "(owner, world, locx1, locy1, locz1, locx2, locy2, locz2, flags)"
  10667. + + "(owner_id, world, locx1, locy1, locz1, locx2, locy2, locz2, flags)"
  10668. + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
  10669. - statement.setString(1, getOwner());
  10670. - statement.setString(2, getWorld().getName());
  10671. + statement.setString(1, super.getOwnerCredentials().getUniqueId().toString());
  10672. + statement.setString(2, super.getWorld().getName());
  10673. statement.setInt(3, getDoor1().getX());
  10674. statement.setInt(4, getDoor1().getY());
  10675. statement.setInt(5, getDoor1().getZ());
  10676. statement.setInt(6, getDoor2() == null ? 0 : getDoor2().getX());
  10677. statement.setInt(7, getDoor2() == null ? 0 : getDoor2().getY());
  10678. statement.setInt(8, getDoor2() == null ? 0 : getDoor2().getZ());
  10679. - statement.setLong(9, getFlags());
  10680. + statement.setLong(9, super.getFlags());
  10681. statement.executeUpdate();
  10682. result = statement.getGeneratedKeys();
  10683.  
  10684. if (result.next()) {
  10685. - setId(result.getInt(1));
  10686. - setUpdated(false);
  10687. + super.setId(result.getInt(1));
  10688. + super.setUpdated(false);
  10689. } else {
  10690. InnPlugin.logError("New door not found in the database!");
  10691. return false;
  10692. @@ -170,50 +171,44 @@ public class InnectisDoor extends InnectisOwnedObject<Integer> {
  10693. }
  10694.  
  10695. statement = DBManager.prepareStatement("UPDATE doors SET "
  10696. - + "owner = ?, "
  10697. - + "world = ?, "
  10698. - + "locx1 = ?, "
  10699. - + "locy1 = ?, "
  10700. - + "locz1 = ?, "
  10701. - + "locx2 = ?, "
  10702. - + "locy2 = ?, "
  10703. - + "locz2 = ?, "
  10704. - + "flags = ? "
  10705. + + "owner_id = ?, world = ?, locx1 = ?, "
  10706. + + "locy1 = ?, locz1 = ?, locx2 = ?, "
  10707. + + "locy2 = ?, locz2 = ?, flags = ? "
  10708. + "WHERE doorid = ?;");
  10709. - statement.setString(1, getOwner());
  10710. - statement.setString(2, getWorld().getName());
  10711. + statement.setString(1, super.getOwnerCredentials().getUniqueId().toString());
  10712. + statement.setString(2, super.getWorld().getName());
  10713. statement.setInt(3, getDoor1().getX());
  10714. statement.setInt(4, getDoor1().getY());
  10715. statement.setInt(5, getDoor1().getZ());
  10716. statement.setInt(6, getDoor2() == null ? 0 : getDoor2().getX());
  10717. statement.setInt(7, getDoor2() == null ? 0 : getDoor2().getY());
  10718. statement.setInt(8, getDoor2() == null ? 0 : getDoor2().getZ());
  10719. - statement.setLong(9, getFlags());
  10720. - statement.setInt(10, getId());
  10721. + statement.setLong(9, super.getFlags());
  10722. + statement.setInt(10, super.getId());
  10723. statement.executeUpdate();
  10724. DBManager.closePreparedStatement(statement);
  10725.  
  10726. statement = DBManager.prepareStatement("DELETE FROM doors_members WHERE doorid = ?;");
  10727. - statement.setInt(1, getId());
  10728. + statement.setInt(1, super.getId());
  10729. statement.executeUpdate();
  10730. DBManager.closePreparedStatement(statement);
  10731.  
  10732. - for (String s : getMembers()) {
  10733. - statement = DBManager.prepareStatement("INSERT INTO doors_members (doorid, username, isop) VALUES (?, ?, 0);");
  10734. - statement.setInt(1, getId());
  10735. - statement.setString(2, s);
  10736. + for (PlayerCredentials pc : getMembers()) {
  10737. + statement = DBManager.prepareStatement("INSERT INTO doors_members (doorid, player_id, isop) VALUES (?, ?, 0);");
  10738. + statement.setInt(1, super.getId());
  10739. + statement.setString(2, pc.getUniqueId().toString());
  10740. statement.executeUpdate();
  10741. DBManager.closePreparedStatement(statement);
  10742. }
  10743. - for (String s : getOperators()) {
  10744. - statement = DBManager.prepareStatement("INSERT INTO doors_members (doorid, username, isop) VALUES (?, ?, 1);");
  10745. - statement.setInt(1, getId());
  10746. - statement.setString(2, s);
  10747. + for (PlayerCredentials pc : getOperators()) {
  10748. + statement = DBManager.prepareStatement("INSERT INTO doors_members (doorid, player_id, isop) VALUES (?, ?, 1);");
  10749. + statement.setInt(1, super.getId());
  10750. + statement.setString(2, pc.getUniqueId().toString());
  10751. statement.executeUpdate();
  10752. DBManager.closePreparedStatement(statement);
  10753. }
  10754.  
  10755. - setUpdated(false);
  10756. + super.setUpdated(false);
  10757. } catch (SQLException ex) {
  10758. InnPlugin.logError("Unable to save door #" + super.getId() + "!", ex);
  10759. return false;
  10760. diff --git a/src/net/innectis/innplugin/OwnedObjects/InnectisLot.java b/src/net/innectis/innplugin/OwnedObjects/InnectisLot.java
  10761. index a0442ed3b..763786286 100644
  10762. --- a/src/net/innectis/innplugin/OwnedObjects/InnectisLot.java
  10763. +++ b/src/net/innectis/innplugin/OwnedObjects/InnectisLot.java
  10764. @@ -7,6 +7,7 @@ import java.util.ArrayList;
  10765. import java.util.Calendar;
  10766. import java.util.Collections;
  10767. import java.util.HashMap;
  10768. +import java.util.Iterator;
  10769. import java.util.List;
  10770. import java.util.Map;
  10771. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  10772. @@ -17,6 +18,7 @@ import net.innectis.innplugin.Location.IdpWorldRegion;
  10773. import net.innectis.innplugin.OwnedObjects.Handlers.LotHandler;
  10774. import net.innectis.innplugin.Player.Chat.ChatColor;
  10775. import net.innectis.innplugin.Player.IdpPlayer;
  10776. +import net.innectis.innplugin.Player.PlayerCredentials;
  10777. import net.innectis.innplugin.Utility.DateUtil;
  10778. import org.bukkit.Location;
  10779. import org.bukkit.World;
  10780. @@ -26,16 +28,15 @@ import org.bukkit.util.Vector;
  10781. /**
  10782. * @author Lynxy
  10783. */
  10784. -public class InnectisLot extends InnectisOwnedObject<Integer> {
  10785. -
  10786. +public class InnectisLot extends InnectisOwnedObject {
  10787. private int lotnr;
  10788. - private String lotname;
  10789. + private String lotName;
  10790. private int timesWarpUsed;
  10791. - private Map<String, Long> banned;
  10792. - private List<String> safelist;
  10793. + private Map<PlayerCredentials, Long> banned;
  10794. + private List<PlayerCredentials> safelist;
  10795. private Location spawn;
  10796. private InnectisLot parent;
  10797. - private String creator;
  10798. + private PlayerCredentials creatorCredentials;
  10799. private String enterMsg;
  10800. private String exitMsg;
  10801. private long lastOwnerEdit;
  10802. @@ -45,23 +46,23 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
  10803. private boolean disabled;
  10804. private List<InnectisLot> sublots;
  10805.  
  10806. - public InnectisLot(World world, Vector point1, Vector point2, String owner, String creator, InnectisLot parent) {
  10807. - this(-1, world, point1, point2, point1, owner, null, null, new HashMap<String, Long>(), new ArrayList<String>(), 0, 0, parent, creator, 0, 0);
  10808. + public InnectisLot(World world, Vector point1, Vector point2, PlayerCredentials ownerCredentials, PlayerCredentials creatorCredentials, InnectisLot parent) {
  10809. + this(-1, world, point1, point2, point1, ownerCredentials, null, null, new HashMap<PlayerCredentials, Long>(), new ArrayList<PlayerCredentials>(), 0, 0, parent, creatorCredentials, 0, 0);
  10810. }
  10811.  
  10812. - public InnectisLot(int id, World world, Vector point1, Vector point2, Vector spawn, String owner, List<String> members, List<String> operators, Map<String, Long> banned, List<String> safelist, int lotnr, long flags, InnectisLot parent, String creator, long lastOwnerEdit, long lastMemberEdit) {
  10813. - this(id, world, point1, point2, new Location(world, point1.getBlockX(), point1.getBlockY(), point1.getBlockZ()), owner, "", members, operators, banned, safelist, lotnr, flags, parent, creator, "", "", lastOwnerEdit, lastMemberEdit, 0, false, false);
  10814. + public InnectisLot(int id, World world, Vector point1, Vector point2, Vector spawn, PlayerCredentials ownerCredentials, List<PlayerCredentials> members, List<PlayerCredentials> operators, Map<PlayerCredentials, Long> banned, List<PlayerCredentials> safelist, int lotnr, long flags, InnectisLot parent, PlayerCredentials creatorCredentials, long lastOwnerEdit, long lastMemberEdit) {
  10815. + this(id, world, point1, point2, new Location(world, point1.getBlockX(), point1.getBlockY(), point1.getBlockZ()), ownerCredentials, "", members, operators, banned, safelist, lotnr, flags, parent, creatorCredentials, "", "", lastOwnerEdit, lastMemberEdit, 0, false, false);
  10816. }
  10817.  
  10818. - public InnectisLot(int id, World world, Vector point1, Vector point2, Location spawn, String owner, String lotname, List<String> members, List<String> operators, Map<String, Long> banned, List<String> safelist, int lotnr, long flags, InnectisLot parent, String creator, String enterMsg, String exitMsg, long lastOwnerEdit, long lastMemberEdit, int timesWarpUsed, boolean hidden, boolean deleted) {
  10819. - super(world, point1, point2, id, owner, members, operators, flags);
  10820. - this.lotname = lotname;
  10821. + public InnectisLot(int id, World world, Vector point1, Vector point2, Location spawn, PlayerCredentials ownerCredentials, String lotname, List<PlayerCredentials> members, List<PlayerCredentials> operators, Map<PlayerCredentials, Long> banned, List<PlayerCredentials> safelist, int lotnr, long flags, InnectisLot parent, PlayerCredentials creatorCredentials, String enterMsg, String exitMsg, long lastOwnerEdit, long lastMemberEdit, int timesWarpUsed, boolean hidden, boolean deleted) {
  10822. + super(world, point1, point2, id, ownerCredentials, members, operators, flags);
  10823. + this.lotName = lotname;
  10824. this.banned = banned;
  10825. this.safelist = safelist;
  10826. this.spawn = spawn;
  10827. this.lotnr = lotnr;
  10828. this.sublots = new ArrayList<InnectisLot>();
  10829. - this.creator = creator;
  10830. + this.creatorCredentials = creatorCredentials;
  10831. this.enterMsg = enterMsg;
  10832. this.exitMsg = exitMsg;
  10833. this.lastOwnerEdit = lastOwnerEdit;
  10834. @@ -96,31 +97,35 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
  10835. * Returns true if this lot or any of its parents have a flag bit set.
  10836. * If both child and parent lot have the flag set, it is negated.
  10837. * @param flag
  10838. + * @return
  10839. */
  10840. @Override
  10841. public boolean isFlagSet(FlagType flag) {
  10842. InnectisLot curLot = this;
  10843. boolean isSet = false;
  10844. +
  10845. while (curLot != null && curLot != LotHandler.getMainLot()) {
  10846. if (curLot.isFlagSetNoInheritance(flag)) {
  10847. isSet = !isSet;
  10848. }
  10849. +
  10850. curLot = curLot.getParentAllowHidden();
  10851. }
  10852. +
  10853. return isSet;
  10854. }
  10855.  
  10856. public int getLotNumber() {
  10857. - return this.lotnr;
  10858. + return lotnr;
  10859. }
  10860.  
  10861. public void setLotNumber(int lotnr) {
  10862. this.lotnr = lotnr;
  10863. - setUpdated(true);
  10864. + super.setUpdated(true);
  10865. }
  10866.  
  10867. public String getLotName() {
  10868. - return this.lotname;
  10869. + return lotName;
  10870. }
  10871.  
  10872. /**
  10873. @@ -132,20 +137,20 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
  10874.  
  10875. try {
  10876. statement = DBManager.prepareStatement("DELETE FROM lot_names WHERE lotid=?;");
  10877. - statement.setInt(1, getId());
  10878. + statement.setInt(1, super.getId());
  10879. statement.executeUpdate();
  10880. DBManager.closePreparedStatement(statement);
  10881.  
  10882. if (!lotName.equalsIgnoreCase("")) {
  10883. statement = DBManager.prepareStatement("INSERT INTO lot_names (lotname, lotid, time) VALUES (?, ?, ?);");
  10884. statement.setString(1, lotName);
  10885. - statement.setInt(2, getId());
  10886. + statement.setInt(2, super.getId());
  10887. statement.setLong(3, Calendar.getInstance().getTimeInMillis());
  10888. statement.executeUpdate();
  10889. }
  10890.  
  10891. - this.lotname = lotName;
  10892. - setUpdated(true);
  10893. + this.lotName = lotName;
  10894. + super.setUpdated(true);
  10895. } catch (SQLException ex) {
  10896. InnPlugin.logError("Unable to set name of lot #" + getId() + "!", ex);
  10897. return false;
  10898. @@ -161,7 +166,14 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
  10899. */
  10900. public List<String> getBannedList() {
  10901. reloadBanned();
  10902. - return new ArrayList<String>(this.banned.keySet());
  10903. +
  10904. + List<String> bannedPlayers = new ArrayList<String>(banned.size());
  10905. +
  10906. + for (PlayerCredentials pc : banned.keySet()) {
  10907. + bannedPlayers.add(pc.getName());
  10908. + }
  10909. +
  10910. + return bannedPlayers;
  10911. }
  10912.  
  10913. /**
  10914. @@ -169,67 +181,85 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
  10915. */
  10916. public String getBannedString(ChatColor colour) {
  10917. StringBuilder sb = new StringBuilder("" + colour);
  10918. - for (String s : getBannedList()) {
  10919. - long timeout = this.banned.get(s) - System.currentTimeMillis();
  10920. +
  10921. + for (PlayerCredentials pc : banned.keySet()) {
  10922. + long timeout = banned.get(pc) - System.currentTimeMillis();
  10923. + String name = pc.getName();
  10924. +
  10925. if (timeout > 0) {
  10926. - sb.append("[").append(s).append(":").append(DateUtil.getTimeString(timeout, false)).append(colour).append("]");
  10927. + sb.append("[").append(name).append(":").append(DateUtil.getTimeString(timeout, false)).append(colour).append("]");
  10928. } else {
  10929. - sb.append(s);
  10930. + sb.append(name);
  10931. }
  10932. +
  10933. sb.append(", ");
  10934. }
  10935. +
  10936. if (sb.length() == 0) {
  10937. return "none";
  10938. }
  10939. +
  10940. return sb.substring(0, sb.length() - 2);
  10941. }
  10942.  
  10943. /**
  10944. - * Adds the specified user to the safelist
  10945. - * @param name
  10946. + * Adds the credentials of the specified player to this lot's safelist
  10947. + * @param credentials
  10948. * @return true if added, false if already added
  10949. */
  10950. - public boolean addSafelist(String name) {
  10951. - name = name.toLowerCase();
  10952. -
  10953. - if (safelist.contains(name)) {
  10954. + public boolean addSafelist(PlayerCredentials credentials) {
  10955. + if (containsSafelist(credentials.getName())) {
  10956. return false;
  10957. }
  10958.  
  10959. - if (banned.containsKey(name)) {
  10960. - banned.remove(name);
  10961. + if (isBanned(credentials.getName())) {
  10962. + banned.remove(credentials);
  10963. }
  10964.  
  10965. - safelist.add(name);
  10966. - setUpdated(true);
  10967. + safelist.add(credentials);
  10968. + super.setUpdated(true);
  10969. return true;
  10970. }
  10971.  
  10972. /**
  10973. - * Removes the specified user from the safelist
  10974. - * @param name
  10975. - * @return true if removed, false if they do not exist
  10976. + * Removes the specified player from the safelist
  10977. + * @param playerName
  10978. + * @return true if removed, false otherwise
  10979. */
  10980. - public boolean removeSafelist(String name) {
  10981. - name = name.toLowerCase();
  10982. + public boolean removeSafelist(String playerName) {
  10983. + boolean removed = false;
  10984.  
  10985. - if (!safelist.contains(name)) {
  10986. - return false;
  10987. + for (Iterator<PlayerCredentials> it = safelist.iterator(); it.hasNext();) {
  10988. + PlayerCredentials pc = it.next();
  10989. +
  10990. + if (pc.getName().equalsIgnoreCase(playerName)) {
  10991. + it.remove();
  10992. + removed = true;
  10993. + break;
  10994. + }
  10995. }
  10996.  
  10997. - safelist.remove(name);
  10998. - setUpdated(true);
  10999. - return true;
  11000. + if (removed) {
  11001. + super.setUpdated(true);
  11002. + return true;
  11003. + } else {
  11004. + return false;
  11005. + }
  11006. }
  11007.  
  11008. /**
  11009. - * Checks if the specified name is on the safelist
  11010. - * @param name
  11011. + * Checks if the player represented by their ID is on this lot's safelist
  11012. + * @param playerName
  11013. * @return
  11014. */
  11015. - public boolean containsSafelist(String name) {
  11016. - name = name.toLowerCase();
  11017. - return safelist.contains(name);
  11018. + public boolean containsSafelist(String playerName) {
  11019. + for (PlayerCredentials pc : safelist) {
  11020. + if (pc.getName().equalsIgnoreCase(playerName)) {
  11021. + return true;
  11022. + }
  11023. + }
  11024. +
  11025. + return false;
  11026. }
  11027.  
  11028. /**
  11029. @@ -237,14 +267,14 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
  11030. */
  11031. public void clearSafelist() {
  11032. safelist.clear();
  11033. - setUpdated(true);
  11034. + super.setUpdated(true);
  11035. }
  11036.  
  11037. /**
  11038. * Returns an unmodifiable list of the safelist
  11039. * @return
  11040. */
  11041. - public List<String> getSafelist() {
  11042. + public List<PlayerCredentials> getSafelist() {
  11043. return Collections.unmodifiableList(safelist);
  11044. }
  11045.  
  11046. @@ -256,12 +286,14 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
  11047. StringBuilder sb = new StringBuilder();
  11048. int idx = 0;
  11049.  
  11050. - for (String s : getSafelist()) {
  11051. + for (PlayerCredentials pc : safelist) {
  11052. + String name = pc.getName();
  11053. +
  11054. if (idx > 0) {
  11055. sb.append(", ");
  11056. }
  11057.  
  11058. - sb.append(s);
  11059. + sb.append(name);
  11060. idx++;
  11061. }
  11062.  
  11063. @@ -269,105 +301,128 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
  11064. }
  11065.  
  11066. /**
  11067. - * Adds a username to the banned list perm and returns true. If username is already banned, returns false
  11068. - * @param name
  11069. + * Adds the credentials of a player to this lot's ban list
  11070. + * If they are already banned, returns false
  11071. + * @param credentials
  11072. */
  11073. - public boolean banUser(String name) {
  11074. - return banUser(name, (long) 0);
  11075. + public boolean banUser(PlayerCredentials credentials) {
  11076. + return banUser(credentials, 0L);
  11077. }
  11078.  
  11079. /**
  11080. * Adds a username to the banned list until the entered time and returns true. If username is already banned, returns false.
  11081. * If time is put as '0' then perm.
  11082. - * @param name
  11083. + * @param credentials
  11084. * @param timeout
  11085. * @return
  11086. */
  11087. - public boolean banUser(String name, long timeout) {
  11088. - String name2 = name.toLowerCase();
  11089. - if (getBannedList().contains(name2)) {
  11090. + public boolean banUser(PlayerCredentials credentials, long timeout) {
  11091. + String name = credentials.getName();
  11092. +
  11093. + if (isBanned(name)) {
  11094. return false;
  11095. }
  11096.  
  11097. - if (safelist.contains(name2)) {
  11098. - safelist.remove(name2);
  11099. + if (containsSafelist(name)) {
  11100. + removeSafelist(name);
  11101. }
  11102.  
  11103. - this.banned.put(name2, timeout);
  11104. - setUpdated(true);
  11105. + banned.put(credentials, timeout);
  11106. + super.setUpdated(true);
  11107. return true;
  11108. }
  11109.  
  11110. /**
  11111. - * If a username is banned, removes it and returns true
  11112. - * @param name
  11113. + * Removes the player from this lot's ban list
  11114. + * not banned
  11115. + * @param playerName
  11116. */
  11117. - public boolean unbanUser(String name) {
  11118. - String name2 = name.toLowerCase();
  11119. - if (getBannedList().contains(name2)) {
  11120. - this.banned.remove(name2);
  11121. - setUpdated(true);
  11122. + public boolean unbanUser(String playerName) {
  11123. + boolean removed = false;
  11124. +
  11125. + for (Iterator<PlayerCredentials> it = banned.keySet().iterator(); it.hasNext();) {
  11126. + PlayerCredentials pc = it.next();
  11127. +
  11128. + if (pc.getName().equalsIgnoreCase(playerName)) {
  11129. + it.remove();
  11130. + removed = true;
  11131. + break;
  11132. + }
  11133. + }
  11134. +
  11135. + if (removed) {
  11136. + super.setUpdated(true);
  11137. return true;
  11138. + } else {
  11139. + return false;
  11140. }
  11141. - return false;
  11142. }
  11143.  
  11144. /**
  11145. - * Returns true if a user is banned, false otherwise
  11146. - * @param name
  11147. + * Returns true if a player is banned, false otherwise
  11148. + * @param playerName
  11149. * @return
  11150. */
  11151. - public boolean isBanned(String name) {
  11152. - return getBannedList().contains(name.toLowerCase());
  11153. + public boolean isBanned(String playerName) {
  11154. + for (PlayerCredentials pc : banned.keySet()) {
  11155. + if (pc.getName().equalsIgnoreCase(playerName)) {
  11156. + return true;
  11157. + }
  11158. + }
  11159. +
  11160. + return false;
  11161. }
  11162.  
  11163. /**
  11164. * Clears the banned user list of this lot
  11165. */
  11166. public void clearBanned() {
  11167. - this.banned.clear();
  11168. - setUpdated(true);
  11169. + banned.clear();
  11170. + super.setUpdated(true);
  11171. }
  11172.  
  11173. /**
  11174. * Checks through all lot bans, and removes them if they have timed out.
  11175. */
  11176. public void reloadBanned() {
  11177. - for (String s : this.banned.keySet()) {
  11178. - long banTime = this.banned.get(s);
  11179. + for (PlayerCredentials pc : banned.keySet()) {
  11180. + long banTime = banned.get(pc);
  11181.  
  11182. if (banTime > 0 && banTime < System.currentTimeMillis()) {
  11183. + String name = pc.getName();
  11184. +
  11185. // Log auto-unbans.
  11186. IdpPlayer player = InnPlugin.getPlugin().getPlayer(getOwner(), true);
  11187.  
  11188. if (player != null) {
  11189. - player.printInfo(s + "'s ban has automatically expired on lot #" + getId());
  11190. + player.printInfo(name + "'s ban has automatically expired on lot #" + getId());
  11191. }
  11192.  
  11193. - InnPlugin.logInfo(s + "'s ban has automatically expired on lot #" + getId() + " (" + getOwner() + ")");
  11194. - this.banned.remove(s);
  11195. + InnPlugin.logInfo(name + "'s ban has automatically expired on lot #" + getId() + " (" + getOwner() + ")");
  11196. + banned.remove(pc);
  11197. }
  11198. }
  11199. }
  11200.  
  11201. public Location getSpawn() {
  11202. - return this.spawn;
  11203. + return spawn;
  11204. }
  11205.  
  11206. public void setSpawn(Location spawn) {
  11207. this.spawn = spawn;
  11208. - setUpdated(true);
  11209. + super.setUpdated(true);
  11210. }
  11211.  
  11212. /**
  11213. * Returns the parent lot. If no parent, or parent is hidden, returns null
  11214. */
  11215. public InnectisLot getParent() {
  11216. - if (this.parent == LotHandler.getMainLot()
  11217. - || (this.parent != null && this.parent.getHidden())) {
  11218. + if (parent == LotHandler.getMainLot()
  11219. + || (parent != null && parent.getHidden())) {
  11220. return null;
  11221. }
  11222. - return this.parent;
  11223. +
  11224. + return parent;
  11225. }
  11226.  
  11227. /**
  11228. @@ -375,17 +430,18 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
  11229. * @return
  11230. */
  11231. public boolean isYaxis() {
  11232. - return (this.getLowestY() > 0 || this.getHighestY() < 256);
  11233. + return (super.getLowestY() > 0 || super.getHighestY() < 256);
  11234. }
  11235.  
  11236. /**
  11237. * Returns the parent lot. If no parent, returns null
  11238. */
  11239. public InnectisLot getParentAllowHidden() {
  11240. - if (this.parent == LotHandler.getMainLot()) {
  11241. + if (parent == LotHandler.getMainLot()) {
  11242. return null;
  11243. }
  11244. - return this.parent;
  11245. +
  11246. + return parent;
  11247. }
  11248.  
  11249. /**
  11250. @@ -393,12 +449,15 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
  11251. */
  11252. public InnectisLot getParentNotHidden() {
  11253. InnectisLot par = getParent();
  11254. +
  11255. if (par == null) {
  11256. return null;
  11257. }
  11258. +
  11259. if (par.getHidden()) {
  11260. return null;
  11261. }
  11262. +
  11263. return par;
  11264. }
  11265.  
  11266. @@ -409,13 +468,16 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
  11267. public final boolean setParent(InnectisLot parent) {
  11268. if (parent == null) {
  11269. parent = LotHandler.getMainLot();
  11270. +
  11271. if (parent == null) {
  11272. return false;
  11273. }
  11274. }
  11275. +
  11276. if (parent == this) {
  11277. return false;
  11278. }
  11279. +
  11280. if (!LotHandler.isSublotWithinLot(this, parent)) {
  11281. return false;
  11282. }
  11283. @@ -428,7 +490,8 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
  11284. if (parent.addSublot(this)) {
  11285. this.parent = parent;
  11286. }
  11287. - setUpdated(true);
  11288. +
  11289. + super.setUpdated(true);
  11290. return true;
  11291. }
  11292.  
  11293. @@ -445,14 +508,15 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
  11294. || (checkLot.parent != null && checkLot.parent.getHidden())) {
  11295. return checkLot;
  11296. }
  11297. +
  11298. return getParentTop(checkLot.parent);
  11299. }
  11300.  
  11301. public List<InnectisLot> getSublots() {
  11302. - if (this.sublots.contains(this)) { //sanity check
  11303. - this.sublots.remove(this);
  11304. + if (sublots.contains(this)) { //sanity check
  11305. + sublots.remove(this);
  11306. }
  11307. - return this.sublots;
  11308. + return sublots;
  11309. }
  11310.  
  11311. /**
  11312. @@ -460,9 +524,9 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
  11313. * @param sublot
  11314. */
  11315. private boolean addSublot(InnectisLot sublot) {
  11316. - if (this != sublot && !this.sublots.contains(sublot)) {
  11317. + if (this != sublot && !sublots.contains(sublot)) {
  11318. if (LotHandler.isSublotWithinLot(sublot, this)) {
  11319. - this.sublots.add(sublot);
  11320. + sublots.add(sublot);
  11321. return true;
  11322. }
  11323. }
  11324. @@ -474,76 +538,82 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
  11325. * @param sublot
  11326. */
  11327. private boolean removeSublot(InnectisLot sublot) {
  11328. - if (this.sublots.contains(sublot)) {
  11329. - this.sublots.remove(sublot);
  11330. + if (sublots.contains(sublot)) {
  11331. + sublots.remove(sublot);
  11332. return true;
  11333. }
  11334. return false;
  11335. }
  11336.  
  11337. + public PlayerCredentials getCreatorCredentials() {
  11338. + return creatorCredentials;
  11339. + }
  11340. +
  11341. public String getCreator() {
  11342. - return this.creator;
  11343. + return creatorCredentials.getName();
  11344. }
  11345.  
  11346. - public void setCreator(String creator) {
  11347. - this.creator = creator;
  11348. - setUpdated(true);
  11349. + public void setCreator(PlayerCredentials creatorCredentials) {
  11350. + this.creatorCredentials = creatorCredentials;
  11351. + super.setUpdated(true);
  11352. }
  11353.  
  11354. public long getLastOwnerEdit() {
  11355. - return this.lastOwnerEdit;
  11356. + return lastOwnerEdit;
  11357. }
  11358.  
  11359. public String getLastOwnerEditString() {
  11360. - if (this.lastOwnerEdit == 0) {
  11361. + if (lastOwnerEdit == 0) {
  11362. return "Never";
  11363. }
  11364. - long timeDiff = (System.currentTimeMillis() - this.lastOwnerEdit) / 1000;
  11365. +
  11366. + long timeDiff = (System.currentTimeMillis() - lastOwnerEdit) / 1000;
  11367. return DateUtil.getTimeDifferenceString(timeDiff) + " ago";
  11368. }
  11369.  
  11370. public void setLastOwnerEdit(long lastEdit) {
  11371. - this.lastOwnerEdit = lastEdit;
  11372. - setUpdated(true);
  11373. + lastOwnerEdit = lastEdit;
  11374. + super.setUpdated(true);
  11375. }
  11376.  
  11377. public long getLastMemberEdit() {
  11378. - return this.lastMemberEdit;
  11379. + return lastMemberEdit;
  11380. }
  11381.  
  11382. public String getLastMemberEditString() {
  11383. - if (this.lastMemberEdit == 0) {
  11384. + if (lastMemberEdit == 0) {
  11385. return "Never";
  11386. }
  11387. - long timeDiff = (System.currentTimeMillis() - this.lastMemberEdit) / 1000;
  11388. +
  11389. + long timeDiff = (System.currentTimeMillis() - lastMemberEdit) / 1000;
  11390. return DateUtil.getTimeDifferenceString(timeDiff) + " ago";
  11391. }
  11392.  
  11393. public void setLastMemberEdit(long lastEdit) {
  11394. - this.lastMemberEdit = lastEdit;
  11395. - setUpdated(true);
  11396. + lastMemberEdit = lastEdit;
  11397. + super.setUpdated(true);
  11398. }
  11399.  
  11400. public boolean getHidden() {
  11401. - return this.hidden;
  11402. + return hidden;
  11403. }
  11404.  
  11405. public void setHidden(boolean hidden) {
  11406. this.hidden = hidden;
  11407. - setUpdated(true);
  11408. + super.setUpdated(true);
  11409. }
  11410.  
  11411. public boolean getDeleted() {
  11412. - return this.deleted;
  11413. + return deleted;
  11414. }
  11415.  
  11416. public void setDeleted(boolean deleted) {
  11417. this.deleted = deleted;
  11418. - setUpdated(true);
  11419. + super.setUpdated(true);
  11420. }
  11421.  
  11422. public boolean getDisabled() {
  11423. - return this.disabled;
  11424. + return disabled;
  11425. }
  11426.  
  11427. public void setDisabled(boolean disabled) {
  11428. @@ -566,13 +636,13 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
  11429. * @return
  11430. */
  11431. public boolean equals(IdpWorldRegion region, boolean yaxis) {
  11432. - if (this.getLowestX() == region.getLowestX()
  11433. - && this.getLowestZ() == region.getLowestZ()
  11434. - && this.getHighestX() == region.getHighestX()
  11435. - && this.getHighestZ() == region.getHighestZ()
  11436. - && (!yaxis || (region.getLowestY() == this.getLowestY()
  11437. - && region.getHighestY() == this.getHighestY()))
  11438. - && this.getWorld().getName().equalsIgnoreCase(region.getWorld().getName())) {
  11439. + if (super.getLowestX() == region.getLowestX()
  11440. + && super.getLowestZ() == region.getLowestZ()
  11441. + && super.getHighestX() == region.getHighestX()
  11442. + && super.getHighestZ() == region.getHighestZ()
  11443. + && (!yaxis || (super.getLowestY() == region.getLowestY()
  11444. + && super.getHighestY() == region.getHighestY()))
  11445. + && super.getWorld().getName().equalsIgnoreCase(region.getWorld().getName())) {
  11446. return true;
  11447. }
  11448.  
  11449. @@ -613,8 +683,7 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
  11450. * Sets the flag on the lot, then sends leave/enter events for every player on the lot
  11451. *
  11452. * @param flag
  11453. - * @param toggle
  11454. - * @throws SQLException
  11455. + * @param disable
  11456. */
  11457. public void setLotFlag(FlagType flag, boolean disable) {
  11458. //before we update the flag, we need ot simulate every user on the lot leaving it
  11459. @@ -633,14 +702,17 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
  11460. private int getFreeLotNumber() throws SQLException {
  11461. int highestLotNr = 0;
  11462. List<InnectisLot> lots = LotHandler.getLots(getOwner());
  11463. +
  11464. if (lots == null) {
  11465. return 1;
  11466. }
  11467. +
  11468. for (InnectisLot lot : lots) {
  11469. if (lot.getLotNumber() > highestLotNr) {
  11470. highestLotNr = lot.getLotNumber();
  11471. }
  11472. }
  11473. +
  11474. return highestLotNr + 1;
  11475. }
  11476.  
  11477. @@ -649,42 +721,42 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
  11478. ResultSet result = null;
  11479.  
  11480. try {
  11481. - if (this.lotnr == 0) {
  11482. - this.lotnr = getFreeLotNumber();
  11483. + if (lotnr == 0) {
  11484. + lotnr = getFreeLotNumber();
  11485. }
  11486.  
  11487. statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO lots "
  11488. - + "(owner, lotnr, world, lotname, x1, y1, z1, x2, y2, z2, sx, sy, sz, yaw, flags, creator, enter_msg, exit_msg, last_owner_edit, last_member_edit, warp_count, hidden, deleted)"
  11489. + + "(owner_id, lotnr, world, lotname, x1, y1, z1, x2, y2, z2, sx, sy, sz, yaw, flags, creator_id, enter_msg, exit_msg, last_owner_edit, last_member_edit, warp_count, hidden, deleted)"
  11490. + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
  11491. - statement.setString(1, super.getOwner());
  11492. - statement.setInt(2, this.lotnr);
  11493. - statement.setString(3, getWorld().getName());
  11494. - statement.setString(4, this.lotname);
  11495. - statement.setInt(5, getPos1().getBlockX());
  11496. - statement.setInt(6, getPos1().getBlockY());
  11497. - statement.setInt(7, getPos1().getBlockZ());
  11498. - statement.setInt(8, getPos2().getBlockX());
  11499. - statement.setInt(9, getPos2().getBlockY());
  11500. - statement.setInt(10, getPos2().getBlockZ());
  11501. - statement.setInt(11, this.spawn.getBlockX());
  11502. - statement.setInt(12, this.spawn.getBlockY());
  11503. - statement.setInt(13, this.spawn.getBlockZ());
  11504. - statement.setInt(14, Math.round(this.spawn.getYaw()));
  11505. - statement.setLong(15, getFlags());
  11506. - statement.setString(16, this.creator);
  11507. - statement.setString(17, this.enterMsg);
  11508. - statement.setString(18, this.exitMsg);
  11509. - statement.setLong(19, this.lastOwnerEdit);
  11510. - statement.setLong(20, this.lastMemberEdit);
  11511. - statement.setInt(21, this.timesWarpUsed);
  11512. - statement.setBoolean(22, this.hidden);
  11513. - statement.setBoolean(23, this.deleted);
  11514. + statement.setString(1, super.getOwnerCredentials().getUniqueId().toString());
  11515. + statement.setInt(2, lotnr);
  11516. + statement.setString(3, super.getWorld().getName());
  11517. + statement.setString(4, lotName);
  11518. + statement.setInt(5, super.getPos1().getBlockX());
  11519. + statement.setInt(6, super.getPos1().getBlockY());
  11520. + statement.setInt(7, super.getPos1().getBlockZ());
  11521. + statement.setInt(8, super.getPos2().getBlockX());
  11522. + statement.setInt(9, super.getPos2().getBlockY());
  11523. + statement.setInt(10, super.getPos2().getBlockZ());
  11524. + statement.setInt(11, spawn.getBlockX());
  11525. + statement.setInt(12, spawn.getBlockY());
  11526. + statement.setInt(13, spawn.getBlockZ());
  11527. + statement.setInt(14, Math.round(spawn.getYaw()));
  11528. + statement.setLong(15, super.getFlags());
  11529. + statement.setString(16, creatorCredentials.getUniqueId().toString());
  11530. + statement.setString(17, enterMsg);
  11531. + statement.setString(18, exitMsg);
  11532. + statement.setLong(19, lastOwnerEdit);
  11533. + statement.setLong(20, lastMemberEdit);
  11534. + statement.setInt(21, timesWarpUsed);
  11535. + statement.setBoolean(22, hidden);
  11536. + statement.setBoolean(23, deleted);
  11537. statement.executeUpdate();
  11538. result = statement.getGeneratedKeys();
  11539.  
  11540. if (result.next()) {
  11541. - setId(result.getInt(1));
  11542. - setUpdated(false);
  11543. + super.setId(result.getInt(1));
  11544. + super.setUpdated(false);
  11545. } else {
  11546. InnPlugin.logError("New lot not found in the database!");
  11547. return false;
  11548. @@ -702,125 +774,111 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
  11549.  
  11550. @Override
  11551. public boolean save() {
  11552. - if (getId() == 0) { //main lot (virtual)
  11553. - setUpdated(false);
  11554. + if (super.getId() == 0) { //main lot (virtual)
  11555. + super.setUpdated(false);
  11556. return true;
  11557. }
  11558.  
  11559. - if (getId() == -1) {
  11560. + if (super.getId() == -1) {
  11561. return createLotInDB();
  11562. }
  11563.  
  11564. PreparedStatement statement = null;
  11565.  
  11566. try {
  11567. - if (this.lotnr == 0) {
  11568. - this.lotnr = getFreeLotNumber();
  11569. + if (lotnr == 0) {
  11570. + lotnr = getFreeLotNumber();
  11571. }
  11572.  
  11573. statement = DBManager.prepareStatement("UPDATE lots SET "
  11574. - + "owner = ?, "
  11575. - + "lotnr = ?, "
  11576. - + "world = ?, "
  11577. - + "lotname = ?, "
  11578. - + "x1 = ?, "
  11579. - + "y1 = ?, "
  11580. - + "z1 = ?, "
  11581. - + "x2 = ?, "
  11582. - + "y2 = ?, "
  11583. - + "z2 = ?, "
  11584. - + "sx = ?, "
  11585. - + "sy = ?, "
  11586. - + "sz = ?, "
  11587. - + "yaw = ?, "
  11588. - + "flags = ?, "
  11589. - + "creator = ?, "
  11590. - + "enter_msg = ?, "
  11591. - + "exit_msg = ?, "
  11592. - + "last_owner_edit = ?, "
  11593. - + "last_member_edit = ?, "
  11594. - + "warp_count = ?, "
  11595. - + "hidden = ?, "
  11596. - + "deleted = ? "
  11597. - + "WHERE lotid = ?;");
  11598. - statement.setString(1, super.getOwner());
  11599. - statement.setInt(2, this.lotnr);
  11600. - statement.setString(3, getWorld().getName());
  11601. - statement.setString(4, this.lotname);
  11602. - statement.setInt(5, getPos1().getBlockX());
  11603. - statement.setInt(6, getPos1().getBlockY());
  11604. - statement.setInt(7, getPos1().getBlockZ());
  11605. - statement.setInt(8, getPos2().getBlockX());
  11606. - statement.setInt(9, getPos2().getBlockY());
  11607. - statement.setInt(10, getPos2().getBlockZ());
  11608. - statement.setInt(11, this.spawn.getBlockX());
  11609. - statement.setInt(12, this.spawn.getBlockY());
  11610. - statement.setInt(13, this.spawn.getBlockZ());
  11611. - statement.setInt(14, Math.round(this.spawn.getYaw()));
  11612. - statement.setLong(15, getFlags());
  11613. - statement.setString(16, this.creator);
  11614. - statement.setString(17, this.enterMsg);
  11615. - statement.setString(18, this.exitMsg);
  11616. - statement.setLong(19, this.lastOwnerEdit);
  11617. - statement.setLong(20, this.lastMemberEdit);
  11618. - statement.setInt(21, this.timesWarpUsed);
  11619. - statement.setBoolean(22, this.hidden);
  11620. - statement.setBoolean(23, this.deleted);
  11621. - statement.setInt(24, getId());
  11622. + + "owner_id = ?, lotnr = ?, world = ?, "
  11623. + + "lotname = ?, x1 = ?, y1 = ?, "
  11624. + + "z1 = ?, x2 = ?, y2 = ?, "
  11625. + + "z2 = ?, sx = ?, sy = ?, "
  11626. + + "sz = ?, yaw = ?, flags = ?, "
  11627. + + "creator_id = ?, enter_msg = ?, exit_msg = ?, "
  11628. + + "last_owner_edit = ?, last_member_edit = ?, warp_count = ?, "
  11629. + + "hidden = ?, deleted = ? WHERE lotid = ?;");
  11630. + statement.setString(1, super.getOwnerCredentials().getUniqueId().toString());
  11631. + statement.setInt(2, lotnr);
  11632. + statement.setString(3, super.getWorld().getName());
  11633. + statement.setString(4, lotName);
  11634. + statement.setInt(5, super.getPos1().getBlockX());
  11635. + statement.setInt(6, super.getPos1().getBlockY());
  11636. + statement.setInt(7, super.getPos1().getBlockZ());
  11637. + statement.setInt(8, super.getPos2().getBlockX());
  11638. + statement.setInt(9, super.getPos2().getBlockY());
  11639. + statement.setInt(10, super.getPos2().getBlockZ());
  11640. + statement.setInt(11, spawn.getBlockX());
  11641. + statement.setInt(12, spawn.getBlockY());
  11642. + statement.setInt(13, spawn.getBlockZ());
  11643. + statement.setInt(14, Math.round(spawn.getYaw()));
  11644. + statement.setLong(15, super.getFlags());
  11645. + statement.setString(16, creatorCredentials.getUniqueId().toString());
  11646. + statement.setString(17, enterMsg);
  11647. + statement.setString(18, exitMsg);
  11648. + statement.setLong(19, lastOwnerEdit);
  11649. + statement.setLong(20, lastMemberEdit);
  11650. + statement.setInt(21, timesWarpUsed);
  11651. + statement.setBoolean(22, hidden);
  11652. + statement.setBoolean(23, deleted);
  11653. + statement.setInt(24, super.getId());
  11654. statement.executeUpdate();
  11655. DBManager.closePreparedStatement(statement);
  11656.  
  11657. statement = DBManager.prepareStatement("DELETE FROM lot_members WHERE lotid = ?;");
  11658. - statement.setInt(1, getId());
  11659. + statement.setInt(1, super.getId());
  11660. statement.executeUpdate();
  11661. DBManager.closePreparedStatement(statement);
  11662.  
  11663. statement = DBManager.prepareStatement("DELETE FROM lot_banned WHERE lotid = ?;");
  11664. - statement.setInt(1, getId());
  11665. + statement.setInt(1, super.getId());
  11666. statement.executeUpdate();
  11667. DBManager.closePreparedStatement(statement);
  11668.  
  11669. statement = DBManager.prepareStatement("DELETE FROM lot_safelist WHERE lotid = ?;");
  11670. - statement.setInt(1, getId());
  11671. + statement.setInt(1, super.getId());
  11672. statement.executeUpdate();
  11673. DBManager.closePreparedStatement(statement);
  11674.  
  11675. - for (String s : getMembers()) {
  11676. - statement = DBManager.prepareStatement("INSERT INTO lot_members (lotid, username, isop) VALUES (?, ?, 0);");
  11677. - statement.setInt(1, getId());
  11678. - statement.setString(2, s);
  11679. + for (PlayerCredentials pc : super.getMembers()) {
  11680. + statement = DBManager.prepareStatement("INSERT INTO lot_members (lotid, player_id, isop) VALUES (?, ?, 0);");
  11681. + statement.setInt(1, super.getId());
  11682. + statement.setString(2, pc.getUniqueId().toString());
  11683. statement.executeUpdate();
  11684. DBManager.closePreparedStatement(statement);
  11685. }
  11686.  
  11687. - for (String s : getOperators()) {
  11688. - statement = DBManager.prepareStatement("INSERT INTO lot_members (lotid, username, isop) VALUES (?, ?, 1);");
  11689. - statement.setInt(1, getId());
  11690. - statement.setString(2, s);
  11691. + for (PlayerCredentials pc : super.getOperators()) {
  11692. + statement = DBManager.prepareStatement("INSERT INTO lot_members (lotid, player_id, isop) VALUES (?, ?, 1);");
  11693. + statement.setInt(1, super.getId());
  11694. + statement.setString(2, pc.getUniqueId().toString());
  11695. statement.executeUpdate();
  11696. DBManager.closePreparedStatement(statement);
  11697. }
  11698.  
  11699. - for (String s : this.banned.keySet()) {
  11700. - statement = DBManager.prepareStatement("INSERT INTO lot_banned (lotid, username, timeout) VALUES (?, ?, ?);");
  11701. - statement.setInt(1, getId());
  11702. - statement.setString(2, s);
  11703. - statement.setLong(3, this.banned.get(s));
  11704. + for (PlayerCredentials pc : banned.keySet()) {
  11705. + long time = banned.get(pc);
  11706. +
  11707. + statement = DBManager.prepareStatement("INSERT INTO lot_banned (lotid, player_id, timeout) VALUES (?, ?, ?);");
  11708. + statement.setInt(1, super.getId());
  11709. + statement.setString(2, pc.getUniqueId().toString());
  11710. + statement.setLong(3, time);
  11711. statement.executeUpdate();
  11712. DBManager.closePreparedStatement(statement);
  11713. }
  11714.  
  11715. - for (String s : getSafelist()) {
  11716. - statement = DBManager.prepareStatement("INSERT INTO lot_safelist (lotid, username) VALUES (?, ?);");
  11717. - statement.setInt(1, getId());
  11718. - statement.setString(2, s);
  11719. + for (PlayerCredentials pc : getSafelist()) {
  11720. + statement = DBManager.prepareStatement("INSERT INTO lot_safelist (lotid, player_id) VALUES (?, ?);");
  11721. + statement.setInt(1, super.getId());
  11722. + statement.setString(2, pc.getUniqueId().toString());
  11723. statement.executeUpdate();
  11724. DBManager.closePreparedStatement(statement);
  11725. }
  11726.  
  11727. - setUpdated(false);
  11728. + super.setUpdated(false);
  11729. } catch (SQLException ex) {
  11730. - InnPlugin.logError("Unable to save lot #" + getId() + "!", ex);
  11731. + InnPlugin.logError("Unable to save lot #" + super.getId() + "!", ex);
  11732. return false;
  11733. } finally {
  11734. DBManager.closePreparedStatement(statement);
  11735. @@ -831,7 +889,7 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
  11736.  
  11737. public void setEnterMsg(String msg) {
  11738. enterMsg = msg;
  11739. - setUpdated(true);
  11740. + super.setUpdated(true);
  11741. }
  11742.  
  11743. /**
  11744. @@ -933,7 +991,7 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
  11745.  
  11746. public void setExitMsg(String msg) {
  11747. exitMsg = msg;
  11748. - setUpdated(true);
  11749. + super.setUpdated(true);
  11750. }
  11751.  
  11752. public String getExitMsg() {
  11753. @@ -956,12 +1014,12 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
  11754. setDisabled(false);
  11755. setLotName("");
  11756.  
  11757. - setUpdated(true);
  11758. + super.setUpdated(true);
  11759. }
  11760.  
  11761. public void addWarpTimeUsed() {
  11762. timesWarpUsed++;
  11763. - setUpdated(true);
  11764. + super.setUpdated(true);
  11765. }
  11766.  
  11767. public int getTimesWarpUsed() {
  11768. @@ -970,6 +1028,6 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
  11769.  
  11770. public void resetWarpTimesUsed() {
  11771. timesWarpUsed = 0;
  11772. - setUpdated(true);
  11773. + super.setUpdated(true);
  11774. }
  11775. }
  11776. diff --git a/src/net/innectis/innplugin/OwnedObjects/InnectisOwnedObject.java b/src/net/innectis/innplugin/OwnedObjects/InnectisOwnedObject.java
  11777. index d8c579a9b..3dac3c104 100644
  11778. --- a/src/net/innectis/innplugin/OwnedObjects/InnectisOwnedObject.java
  11779. +++ b/src/net/innectis/innplugin/OwnedObjects/InnectisOwnedObject.java
  11780. @@ -1,14 +1,15 @@
  11781. package net.innectis.innplugin.OwnedObjects;
  11782.  
  11783. -import java.sql.SQLException;
  11784. import java.util.ArrayList;
  11785. import java.util.Collections;
  11786. +import java.util.Iterator;
  11787. import java.util.List;
  11788. import net.innectis.innplugin.Handlers.MemberGroupHandler;
  11789. import net.innectis.innplugin.InnectisObjects.MemberGroup;
  11790. import net.innectis.innplugin.Location.IdpWorldRegion;
  11791. import net.innectis.innplugin.Player.Chat.ChatColor;
  11792. -import net.innectis.innplugin.Player.IdpPlayer;
  11793. +import net.innectis.innplugin.Player.PlayerCredentials;
  11794. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  11795. import net.innectis.innplugin.Player.PlayerGroup;
  11796. import org.bukkit.Location;
  11797. import org.bukkit.World;
  11798. @@ -17,29 +18,31 @@ import org.bukkit.util.Vector;
  11799. /**
  11800. *
  11801. * @author Lynxy
  11802. + *
  11803. + * TODO: remove player groups and public group support
  11804. */
  11805. -public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
  11806. +public abstract class InnectisOwnedObject extends IdpWorldRegion {
  11807.  
  11808. /** Status of the object. Is true when a value has been changed */
  11809. private boolean updated = false;
  11810. /** The ID of the given object (0 means no owner, as DB begins at 1) */
  11811. - private IDType id;
  11812. - /** The name of the owner of the object */
  11813. - private String owner;
  11814. + private int id;
  11815. + /** The credentials of the owner of this object */
  11816. + private PlayerCredentials ownerCredentials;
  11817. /** List of members of this object */
  11818. - private List<String> members;
  11819. + private List<PlayerCredentials> members;
  11820. /** List of operators of this object */
  11821. - private List<String> operators;
  11822. + private List<PlayerCredentials> operators;
  11823. /** Long containing all the flags (set bitwise) */
  11824. private long flags;
  11825.  
  11826. /** Creates a new InnectisOwnedObject */
  11827. - protected InnectisOwnedObject(World world, Vector pos1, Vector pos2, IDType id, String owner, List<String> members, List<String> operators, long flags) {
  11828. + protected InnectisOwnedObject(World world, Vector pos1, Vector pos2, int id, PlayerCredentials ownerCredentials, List<PlayerCredentials> members, List<PlayerCredentials> operators, long flags) {
  11829. super(world, pos1, pos2);
  11830. this.id = id;
  11831. - this.owner = owner;
  11832. - this.members = (members == null ? new ArrayList<String>() : members);
  11833. - this.operators = (operators == null ? new ArrayList<String>() : operators);
  11834. + this.ownerCredentials = ownerCredentials;
  11835. + this.members = (members == null ? new ArrayList<PlayerCredentials>() : members);
  11836. + this.operators = (operators == null ? new ArrayList<PlayerCredentials>() : operators);
  11837. this.flags = flags;
  11838. }
  11839.  
  11840. @@ -48,7 +51,7 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
  11841. * @return boolean
  11842. */
  11843. public boolean getUpdated() {
  11844. - return this.updated;
  11845. + return updated;
  11846. }
  11847.  
  11848. /**
  11849. @@ -63,33 +66,41 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
  11850. * Returns the ID of the object
  11851. * @return ID
  11852. */
  11853. - public IDType getId() {
  11854. - return this.id;
  11855. + public int getId() {
  11856. + return id;
  11857. }
  11858.  
  11859. /**
  11860. * Sets the ID of the owned object
  11861. * @param id
  11862. */
  11863. - protected void setId(IDType id) {
  11864. + protected void setId(int id) {
  11865. this.id = id;
  11866. }
  11867.  
  11868. + /**
  11869. + * Gets the credentials of the owner of this object
  11870. + * @return
  11871. + */
  11872. + public PlayerCredentials getOwnerCredentials() {
  11873. + return ownerCredentials;
  11874. + }
  11875. +
  11876. /**
  11877. * Returns the owner of the owned object
  11878. * @return
  11879. */
  11880. public String getOwner() {
  11881. - return this.owner;
  11882. + return ownerCredentials.getName();
  11883. }
  11884.  
  11885. /**
  11886. - * Sets the owner of the owned object
  11887. - * @param owner
  11888. + * Sets the owner credentials of this owned object
  11889. + * @param ownerCredentials
  11890. */
  11891. - public void setOwner(String owner) {
  11892. - this.owner = owner;
  11893. - this.updated = true;
  11894. + public void setOwner(PlayerCredentials ownerCredentials) {
  11895. + this.ownerCredentials = ownerCredentials;
  11896. + updated = true;
  11897. }
  11898.  
  11899. //<editor-fold defaultstate="collapsed" desc="Object members">
  11900. @@ -99,9 +110,8 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
  11901. * @return
  11902. */
  11903. public boolean isValidPlayer(String check, boolean playerOnly) {
  11904. -
  11905. - // Allow Wildcard
  11906. - if (check.equalsIgnoreCase("%")) {
  11907. + // Allow Wildcard and @ characters
  11908. + if (check.equals("%") || check.equals("@")) {
  11909. return true;
  11910. }
  11911.  
  11912. @@ -111,8 +121,10 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
  11913. check = check.substring(1, check.length());
  11914. }
  11915.  
  11916. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(check);
  11917. +
  11918. // Check if the player is valid.
  11919. - if (PlayerGroup.getGroupOfUsername(check) != PlayerGroup.NONE) {
  11920. + if (credentials != null) {
  11921. return true;
  11922. }
  11923.  
  11924. @@ -125,7 +137,7 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
  11925. return true;
  11926. }
  11927.  
  11928. - if (subString.equalsIgnoreCase("[") && MemberGroupHandler.getGroup(owner, check.substring(0, check.length() - 1)) != null) {
  11929. + if (subString.equalsIgnoreCase("[") && MemberGroupHandler.getGroup(ownerCredentials.getUniqueId(), check.substring(0, check.length() - 1)) != null) {
  11930. return true;
  11931. }
  11932.  
  11933. @@ -136,8 +148,8 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
  11934. * Clears the members and operators list for this owned object
  11935. */
  11936. public void clearMembersAndOperators() {
  11937. - this.members.clear();
  11938. - this.operators.clear();
  11939. + members.clear();
  11940. + operators.clear();
  11941. setUpdated(true);
  11942. }
  11943.  
  11944. @@ -145,7 +157,7 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
  11945. * Clears the flags for this owned object
  11946. */
  11947. public void clearFlags() {
  11948. - this.flags = 0;
  11949. + flags = 0;
  11950. setUpdated(true);
  11951. }
  11952.  
  11953. @@ -161,16 +173,16 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
  11954. * Returns a List of each member.
  11955. * <br /><b>This list can't be modified!</b>
  11956. */
  11957. - public List<String> getMembers() {
  11958. - return Collections.unmodifiableList(this.members);
  11959. + public List<PlayerCredentials> getMembers() {
  11960. + return Collections.unmodifiableList(members);
  11961. }
  11962.  
  11963. /**
  11964. * Returns a List of each operator.
  11965. * <br /><b>This list can't be modified!</b>
  11966. */
  11967. - public List<String> getOperators() {
  11968. - return Collections.unmodifiableList(this.operators);
  11969. + public List<PlayerCredentials> getOperators() {
  11970. + return Collections.unmodifiableList(operators);
  11971. }
  11972.  
  11973. /**
  11974. @@ -178,18 +190,20 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
  11975. */
  11976. public List<MemberGroup> getMemberGroups() {
  11977. List<MemberGroup> groups = new ArrayList<MemberGroup>();
  11978. - MemberGroup group;
  11979. - String groupName;
  11980. - for (String member : members) {
  11981. + for (PlayerCredentials pc : members) {
  11982. + String member = pc.getName();
  11983. +
  11984. if (member.substring(0, 1).equalsIgnoreCase("[")
  11985. && member.substring(member.length() - 1, member.length()).equalsIgnoreCase("]")) {
  11986. - groupName = member.substring(1, member.length() - 1);
  11987. - group = MemberGroupHandler.getGroup(owner, groupName);
  11988. + String groupName = member.substring(1, member.length() - 1);
  11989. + MemberGroup group = MemberGroupHandler.getGroup(ownerCredentials.getUniqueId(), groupName);
  11990. +
  11991. if (group != null) {
  11992. groups.add(group);
  11993. }
  11994. }
  11995. }
  11996. +
  11997. return groups;
  11998. }
  11999.  
  12000. @@ -200,47 +214,25 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
  12001. StringBuilder sb = new StringBuilder();
  12002. String groupName;
  12003. MemberGroup group;
  12004. - PlayerGroup playerGroup;
  12005.  
  12006. // First print operators!
  12007. - for (String name : this.operators) {
  12008. + for (PlayerCredentials pc : operators) {
  12009. + String name = pc.getName();
  12010. +
  12011. if (userColor != null) {
  12012. sb.append(opColor);
  12013. }
  12014. sb.append(name).append(", ");
  12015. }
  12016.  
  12017. - // After operators, lets print player groups.
  12018. - for (String name : this.members) {
  12019. - if (name.substring(0, 1).equalsIgnoreCase("#")) {
  12020. - playerGroup = PlayerGroup.getGroup(name.substring(1, name.length()));
  12021. -
  12022. - switch (playerGroup) {
  12023. - case NONE:
  12024. - if (userColor != null) {
  12025. - sb.append(userColor);
  12026. - }
  12027. - sb.append(name).append(", ");
  12028. - continue;
  12029. - }
  12030. - if (groupColor != null) {
  12031. - sb.append(playerGroup.color);
  12032. - }
  12033. - // sb.append(groupColor);
  12034. - sb.append(playerGroup.name);
  12035. - if (userColor != null) {
  12036. - sb.append(userColor);
  12037. - }
  12038. - sb.append(", ");
  12039. - }
  12040. - }
  12041. -
  12042. // Print members
  12043. - for (String name : this.members) {
  12044. + for (PlayerCredentials pc : members) {
  12045. + String name = pc.getName();
  12046. +
  12047. if (name.substring(0, 1).equalsIgnoreCase("[")
  12048. && name.substring(name.length() - 1, name.length()).equalsIgnoreCase("]")) {
  12049. groupName = name.substring(1, name.length() - 1);
  12050. - group = MemberGroupHandler.getGroup(owner, groupName);
  12051. + group = MemberGroupHandler.getGroup(ownerCredentials.getUniqueId(), groupName);
  12052. if (group == null) {
  12053. if (customGroupColor != null) {
  12054. sb.append(customGroupColor);
  12055. @@ -259,6 +251,7 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
  12056. sb.append(name).append(", ");
  12057. }
  12058. }
  12059. +
  12060. if (sb.length() == 0) {
  12061. return "none";
  12062. }
  12063. @@ -266,83 +259,122 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
  12064. }
  12065.  
  12066. /**
  12067. - * Adds the given name as member of this object.
  12068. + * Adds the credentials of the given player as member of this object.
  12069. * If the given name is already a member or operator, this method will return false;
  12070. - * @param name
  12071. + * @param credentials
  12072. */
  12073. - public boolean addMember(String name) {
  12074. - name = name.toLowerCase();
  12075. - if (this.containsMember(name) || this.containsOperator(name)) {
  12076. + public boolean addMember(PlayerCredentials credentials) {
  12077. + if (containsMember(credentials.getName()) || containsOperator(credentials.getName())) {
  12078. return false;
  12079. }
  12080. - this.members.add(name);
  12081. - this.updated = true;
  12082. +
  12083. + members.add(credentials);
  12084. + updated = true;
  12085. return true;
  12086. }
  12087.  
  12088. /**
  12089. - * Removes a member and returns true. If member didn't exist in first place, returns false
  12090. - * @param name
  12091. + * Removes the specified player from this owned object.
  12092. + * If member didn't exist in first place, returns false
  12093. + * @param playerName
  12094. */
  12095. - public boolean removeMember(String name) {
  12096. - String name2 = name.toLowerCase();
  12097. - if (this.members.contains(name2)) {
  12098. - this.members.remove(name2);
  12099. - this.updated = true;
  12100. + public boolean removeMember(String playerName) {
  12101. + boolean removed = false;
  12102. +
  12103. + for (Iterator<PlayerCredentials> it = members.iterator(); it.hasNext();) {
  12104. + PlayerCredentials pc = it.next();
  12105. +
  12106. + if (pc.getName().equalsIgnoreCase(playerName)) {
  12107. + it.remove();
  12108. + removed = true;
  12109. + break;
  12110. + }
  12111. +
  12112. + }
  12113. +
  12114. + if (removed) {
  12115. + updated = true;
  12116. return true;
  12117. + } else {
  12118. + return false;
  12119. }
  12120. - return false;
  12121. }
  12122.  
  12123. /**
  12124. - * This method add an operator.
  12125. - * If the given name is a member, it will be removed from the member list and added to the operator list.
  12126. - * @param name
  12127. + * Adds the credentials of the specified player as an operator
  12128. + * if this is a member already added, it will be removed from
  12129. + * the member list and added to the operator list.
  12130. + * @param credentials
  12131. */
  12132. - public boolean addOperator(String name) {
  12133. - name = name.toLowerCase();
  12134. - if (this.containsOperator(name)) {
  12135. + public boolean addOperator(PlayerCredentials credentials) {
  12136. + if (containsOperator(credentials.getName())) {
  12137. return false;
  12138. }
  12139. +
  12140. // Remove from members, if given name is a member
  12141. - if (this.containsMember(name)) {
  12142. - this.members.remove(name);
  12143. + if (containsMember(credentials.getName())) {
  12144. + members.remove(credentials);
  12145. }
  12146. - this.operators.add(name);
  12147. - this.updated = true;
  12148. +
  12149. + operators.add(credentials);
  12150. + updated = true;
  12151. return true;
  12152. }
  12153.  
  12154. /**
  12155. - * Removes an operator and returns true. If operator didn't exist in first place, returns false
  12156. - * @param name
  12157. + * Removes the given player from this object.
  12158. + * If operator didn't exist in first place, returns false
  12159. + * @param playerName
  12160. */
  12161. - public boolean removeOperator(String name) {
  12162. - String name2 = name.toLowerCase();
  12163. - if (this.operators.contains(name2)) {
  12164. - this.operators.remove(name2);
  12165. - this.updated = true;
  12166. + public boolean removeOperator(String playerName) {
  12167. + boolean removed = false;
  12168. +
  12169. + for (Iterator<PlayerCredentials> it = operators.iterator(); it.hasNext();) {
  12170. + PlayerCredentials pc = it.next();
  12171. +
  12172. + if (pc.getName().equalsIgnoreCase(playerName)) {
  12173. + it.remove();
  12174. + removed = true;
  12175. + break;
  12176. + }
  12177. + }
  12178. +
  12179. + if (removed) {
  12180. + updated = true;
  12181. return true;
  12182. + } else {
  12183. + return false;
  12184. }
  12185. - return false;
  12186. }
  12187.  
  12188. /**
  12189. - * Checks if the given name is a member or of the object.
  12190. - * @param name
  12191. + * Checks if the player is a valid member
  12192. + * @param playerName
  12193. * @return
  12194. */
  12195. - public boolean containsMember(String name) {
  12196. - return name != null && this.members.contains(name.toLowerCase());
  12197. + public boolean containsMember(String playerName) {
  12198. + for (PlayerCredentials pc : members) {
  12199. + if (pc.getName().equalsIgnoreCase(playerName)) {
  12200. + return true;
  12201. + }
  12202. + }
  12203. +
  12204. + return false;
  12205. }
  12206.  
  12207. /**
  12208. - * Checks if the given name is an operator of the object.
  12209. - * @param name
  12210. + * Checks if the player is a valid operator
  12211. + * @param playerName
  12212. * @return
  12213. */
  12214. - public boolean containsOperator(String name) {
  12215. - return name != null && this.operators.contains(name.toLowerCase());
  12216. + public boolean containsOperator(String playerName) {
  12217. + for (PlayerCredentials pc : operators) {
  12218. + if (pc.getName().equalsIgnoreCase(playerName)) {
  12219. + return true;
  12220. + }
  12221. + }
  12222. +
  12223. + return false;
  12224. }
  12225.  
  12226. /**
  12227. @@ -351,39 +383,35 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
  12228. * @param group
  12229. * @return
  12230. */
  12231. - public boolean containsGroup(PlayerGroup group) {
  12232. - return this.members.contains("#" + group.name.replace(" ", "_").toLowerCase());
  12233. + public boolean containsPlayerGroup(PlayerGroup group) {
  12234. + return members.contains("#" + group.name.replace(" ", "_").toLowerCase());
  12235. }
  12236. //</editor-fold>
  12237.  
  12238. /**
  12239. - * Returns true if the player is the owner or a member, or if this object's owner is %, contains operator, or contains member %, or is part of a member group on this object
  12240. - * @param player
  12241. - */
  12242. - public boolean canPlayerAccess(IdpPlayer player) {
  12243. - return canPlayerAccess(player.getName());
  12244. - }
  12245. -
  12246. - /**
  12247. - * Returns true if the player is the owner or a member, or if this object's owner is %, contains operator, or contains member %, or is part of a member group on this object
  12248. - * @param name
  12249. + * Returns true if the player represented by the ID is the owner
  12250. + * or member, the object has % as a special member, the player is
  12251. + * an operator, or whose player group is part of this lot
  12252. + * on this object
  12253. + * @param playerName
  12254. */
  12255. - public boolean canPlayerAccess(String name) {
  12256. - name = name.toLowerCase();
  12257. - if (this.owner.equalsIgnoreCase("%") || this.owner.equalsIgnoreCase(name)) {
  12258. + public boolean canPlayerAccess(String playerName) {
  12259. + if (ownerCredentials.getName().equalsIgnoreCase(playerName)) {
  12260. return true;
  12261. }
  12262.  
  12263. - if (this.containsMember("%") || this.containsMember(name) || this.containsOperator(name)) {
  12264. + if (containsMember("%") || containsMember(playerName) || containsOperator(playerName)) {
  12265. return true;
  12266. }
  12267.  
  12268. - if (this.containsGroup(PlayerGroup.getGroupOfUsername(name))) {
  12269. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  12270. +
  12271. + if (containsPlayerGroup(PlayerGroup.getGroupOfPlayerById(credentials.getUniqueId()))) {
  12272. return true;
  12273. }
  12274.  
  12275. for (MemberGroup group : getMemberGroups()) {
  12276. - if (group != null && group.containsMember(name)) {
  12277. + if (group != null && group.containsMember(playerName)) {
  12278. return true;
  12279. }
  12280. }
  12281. @@ -392,47 +420,29 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
  12282. }
  12283.  
  12284. /**
  12285. - * Checks if the given player can manage the object
  12286. - * @param name
  12287. - * @return
  12288. - */
  12289. - public boolean canPlayerManage(IdpPlayer player) {
  12290. - return canPlayerManage(player.getName());
  12291. - }
  12292. -
  12293. - /**
  12294. - * Checks if the given playername can manage the object
  12295. - * @param name
  12296. + * Checks if the player player can manage this object
  12297. + * @param playerName
  12298. * @return
  12299. */
  12300. - public boolean canPlayerManage(String name) {
  12301. - return this.owner.equalsIgnoreCase(name) || this.containsOperator(name);
  12302. + public boolean canPlayerManage(String playerName) {
  12303. + return ownerCredentials.getUniqueId().equals(playerName) || containsOperator(playerName);
  12304. }
  12305.  
  12306. /**
  12307. - * Returns true if the player is the owner,contains operator, a member or is part of a member group on this object.
  12308. + * Returns true if the player represented by the ID is the owner,
  12309. + * contains operator, a member or is part of a member group on
  12310. + * this object.
  12311. * <p/>
  12312. * This ignores the generic lotmember '%'
  12313. - * @param player
  12314. + * @param playerName
  12315. */
  12316. - public boolean canPlayerAccessIgnoreGeneric(IdpPlayer player) {
  12317. - return canPlayerAccessIgnoreGeneric(player.getName());
  12318. - }
  12319. -
  12320. - /**
  12321. - * Returns true if the player is the owner,contains operator, a member or is part of a member group on this object.
  12322. - * <p/>
  12323. - * This ignores the generic lotmember '%'
  12324. - * @param name
  12325. - */
  12326. - public boolean canPlayerAccessIgnoreGeneric(String name) {
  12327. - name = name.toLowerCase();
  12328. - if (this.owner.equalsIgnoreCase(name) || this.containsMember(name) || this.containsOperator(name)) {
  12329. + public boolean canPlayerAccessIgnoreGeneric(String playerName) {
  12330. + if (ownerCredentials.getName().equalsIgnoreCase(playerName) || containsMember(playerName) || containsOperator(playerName)) {
  12331. return true;
  12332. }
  12333.  
  12334. for (MemberGroup group : getMemberGroups()) {
  12335. - if (group != null && group.containsMember(name)) {
  12336. + if (group != null && group.containsMember(playerName)) {
  12337. return true;
  12338. }
  12339. }
  12340. @@ -560,22 +570,22 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
  12341. * @param flag
  12342. */
  12343. public boolean isFlagSetNoInheritance(FlagType flag) {
  12344. - return ((this.flags & flag.getFlagBit()) == flag.getFlagBit());
  12345. + return ((flags & flag.getFlagBit()) == flag.getFlagBit());
  12346. }
  12347.  
  12348. /**
  12349. * Returns all flags set on this object
  12350. */
  12351. public long getFlags() {
  12352. - return this.flags;
  12353. + return flags;
  12354. }
  12355.  
  12356. /**
  12357. * Sets the flags on this object. Note: this does not turn a flag on or off! Use setFlag() for that
  12358. */
  12359. public void setFlags(long flags) {
  12360. - this.flags = flags;
  12361. - this.updated = true;
  12362. + flags = flags;
  12363. + updated = true;
  12364. }
  12365.  
  12366. /**
  12367. @@ -594,30 +604,30 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
  12368. */
  12369. public void setFlag(long flag, boolean disable) {
  12370. if (disable) {
  12371. - this.flags &= ~flag;
  12372. + flags &= ~flag;
  12373. } else {
  12374. - this.flags |= flag;
  12375. + flags |= flag;
  12376. }
  12377. - this.updated = true;
  12378. + updated = true;
  12379. }
  12380. //</editor-fold>
  12381.  
  12382. @Override
  12383. public void setPos1(Vector point) {
  12384. super.setPos1(point);
  12385. - this.updated = true;
  12386. + updated = true;
  12387. }
  12388.  
  12389. @Override
  12390. public void setPos2(Vector point) {
  12391. super.setPos2(point);
  12392. - this.updated = true;
  12393. + updated = true;
  12394. }
  12395.  
  12396. @Override
  12397. public void setWorld(World world) {
  12398. super.setWorld(world);
  12399. - this.updated = true;
  12400. + updated = true;
  12401. }
  12402.  
  12403. /** Returns the name of the owned object */
  12404. @@ -625,7 +635,6 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
  12405.  
  12406. /**
  12407. * Saves the object object to the database
  12408. - * @throws SQLException
  12409. * @return true if the method had no errors, false if there
  12410. * was an error saving to the database. Behavior modified
  12411. * for design simplicity
  12412. diff --git a/src/net/innectis/innplugin/OwnedObjects/InnectisSwitch.java b/src/net/innectis/innplugin/OwnedObjects/InnectisSwitch.java
  12413. index 83fb20bf0..d7f37eb63 100644
  12414. --- a/src/net/innectis/innplugin/OwnedObjects/InnectisSwitch.java
  12415. +++ b/src/net/innectis/innplugin/OwnedObjects/InnectisSwitch.java
  12416. @@ -10,6 +10,7 @@ import java.util.Iterator;
  12417. import java.util.LinkedList;
  12418. import java.util.List;
  12419. import java.util.Map;
  12420. +import java.util.UUID;
  12421. import java.util.logging.Level;
  12422. import java.util.logging.Logger;
  12423. import net.innectis.innplugin.Handlers.BlockHandler;
  12424. @@ -17,6 +18,8 @@ import net.innectis.innplugin.Handlers.Datasource.DBManager;
  12425. import net.innectis.innplugin.InnPlugin;
  12426. import net.innectis.innplugin.InnectisObjects.MemberGroup;
  12427. import net.innectis.innplugin.Player.Chat.ChatColor;
  12428. +import net.innectis.innplugin.Player.PlayerCredentials;
  12429. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  12430. import org.bukkit.Bukkit;
  12431. import org.bukkit.Location;
  12432. import org.bukkit.World;
  12433. @@ -30,23 +33,23 @@ import org.bukkit.util.Vector;
  12434. *
  12435. * A switch in the IDP which can be owned and linked.
  12436. */
  12437. -public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12438. +public class InnectisSwitch extends InnectisOwnedObject {
  12439. private static final Map<Integer, InnectisSwitch> switchChache = Collections.synchronizedMap(new HashMap<Integer, InnectisSwitch>());
  12440. private List<Integer> links;
  12441.  
  12442. - public InnectisSwitch(Location loc, String owner) {
  12443. - this(loc.getWorld(), loc.toVector(), owner);
  12444. - this.setUpdated(true);
  12445. + public InnectisSwitch(Location loc, PlayerCredentials ownerCredentials) {
  12446. + this(loc.getWorld(), loc.toVector(), ownerCredentials);
  12447. + super.setUpdated(true);
  12448. }
  12449.  
  12450. - public InnectisSwitch(World world, Vector loc, String owner) {
  12451. - super(world, loc, loc, -1, owner, null, null, 0);
  12452. - this.links = new ArrayList<Integer>();
  12453. - this.setUpdated(true);
  12454. + public InnectisSwitch(World world, Vector loc, PlayerCredentials ownerCredentials) {
  12455. + super(world, loc, loc, -1, ownerCredentials, null, null, 0);
  12456. + links = new ArrayList<Integer>();
  12457. + super.setUpdated(true);
  12458. }
  12459.  
  12460. - private InnectisSwitch(Integer id, String owner, World world, Vector loc, long flags, List<Integer> links) {
  12461. - super(world, loc, loc, id, owner, null, null, flags);
  12462. + private InnectisSwitch(Integer id, PlayerCredentials ownerCredentials, World world, Vector loc, long flags, List<Integer> links) {
  12463. + super(world, loc, loc, id, ownerCredentials, null, null, flags);
  12464. this.links = links;
  12465. }
  12466.  
  12467. @@ -54,7 +57,7 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12468. * Not supported
  12469. */
  12470. @Override
  12471. - public List<String> getMembers() {
  12472. + public List<PlayerCredentials> getMembers() {
  12473. return Collections.emptyList();
  12474. }
  12475.  
  12476. @@ -62,7 +65,7 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12477. * Not supported
  12478. */
  12479. @Override
  12480. - public List<String> getOperators() {
  12481. + public List<PlayerCredentials> getOperators() {
  12482. return Collections.emptyList();
  12483. }
  12484.  
  12485. @@ -78,7 +81,7 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12486. * Not supported
  12487. */
  12488. @Override
  12489. - public boolean containsMember(String name) {
  12490. + public boolean containsMember(String playerName) {
  12491. return false; // No members
  12492. }
  12493.  
  12494. @@ -86,7 +89,7 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12495. * Not supported
  12496. */
  12497. @Override
  12498. - public boolean containsOperator(String name) {
  12499. + public boolean containsOperator(String playerName) {
  12500. return false; // No ops
  12501. }
  12502.  
  12503. @@ -94,7 +97,7 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12504. * Not supported
  12505. */
  12506. @Override
  12507. - public boolean addMember(String name) {
  12508. + public boolean addMember(PlayerCredentials credentials) {
  12509. return false; // No members
  12510. }
  12511.  
  12512. @@ -102,7 +105,7 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12513. * Not supported
  12514. */
  12515. @Override
  12516. - public boolean addOperator(String name) {
  12517. + public boolean addOperator(PlayerCredentials credentials) {
  12518. return false;
  12519. }
  12520.  
  12521. @@ -126,16 +129,16 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12522. * Not supported
  12523. */
  12524. @Override
  12525. - public boolean removeMember(String name) {
  12526. - return super.removeMember(name);
  12527. + public boolean removeMember(String playerName) {
  12528. + return super.removeMember(playerName);
  12529. }
  12530.  
  12531. /**
  12532. * Not supported
  12533. */
  12534. @Override
  12535. - public boolean removeOperator(String name) {
  12536. - return super.removeOperator(name);
  12537. + public boolean removeOperator(String playerName) {
  12538. + return super.removeOperator(playerName);
  12539. }
  12540.  
  12541. /**
  12542. @@ -163,7 +166,7 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12543. */
  12544. @Override
  12545. public boolean isAtLocation(Location location) {
  12546. - return this.getPos1().equals(location.toVector());
  12547. + return super.getPos1().equals(location.toVector());
  12548. }
  12549.  
  12550. /**
  12551. @@ -172,9 +175,9 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12552. * @param switchid
  12553. */
  12554. public boolean addLink(int switchid) {
  12555. - if (!links.contains(switchid) && switchid != getId()) {
  12556. + if (!links.contains(switchid) && switchid != super.getId()) {
  12557. // Add link both directions
  12558. - this.links.add(switchid);
  12559. + links.add(switchid);
  12560. createDBLink(getId(), switchid);
  12561.  
  12562. InnectisSwitch temp = getSwitch(switchid);
  12563. @@ -185,22 +188,23 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12564. for (int id : links) {
  12565. temp = getSwitch(id);
  12566. if (temp != null) {
  12567. - temp.updateLinks(this.links);
  12568. + temp.updateLinks(links);
  12569. }
  12570. }
  12571.  
  12572. // Update other switch and their links
  12573. - temp.updateLinks(this.links);
  12574. + temp.updateLinks(links);
  12575. // Share the new link with all switches that are already linked
  12576. for (int id : temp.links) {
  12577. temp = getSwitch(id);
  12578. if (temp != null) {
  12579. - temp.updateLinks(this.links);
  12580. + temp.updateLinks(links);
  12581. }
  12582. }
  12583.  
  12584. return true;
  12585. }
  12586. +
  12587. return false;
  12588. }
  12589.  
  12590. @@ -210,9 +214,9 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12591. */
  12592. public void updateLinks(List<Integer> newLinks) {
  12593. for (int id : newLinks) {
  12594. - if (!this.links.contains(id) && id != getId()) {
  12595. - this.links.add(id);
  12596. - createDBLink(id, this.getId());
  12597. + if (!links.contains(id) && id != super.getId()) {
  12598. + links.add(id);
  12599. + createDBLink(id, super.getId());
  12600. }
  12601. }
  12602. }
  12603. @@ -242,7 +246,7 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12604. * @return TRUE if ON
  12605. */
  12606. public boolean getOnState() {
  12607. - byte dat = BlockHandler.getBlockData(getPos1Location().getBlock());
  12608. + byte dat = BlockHandler.getBlockData(super.getPos1Location().getBlock());
  12609. return dat > 8;
  12610. }
  12611.  
  12612. @@ -250,7 +254,7 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12613. * Toggles this switch and all coppled switches
  12614. */
  12615. public void toggleAll() {
  12616. - toggleSwitch(this.getPos1Location());
  12617. + toggleSwitch(super.getPos1Location());
  12618. toggleLinkedSwitches();
  12619. }
  12620.  
  12621. @@ -285,17 +289,17 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12622. /**
  12623. * This method will try to find a switch at the given location, or create one if not.
  12624. * @param location
  12625. - * @param playername
  12626. + * @param credentials
  12627. * @return the existing or new switch
  12628. */
  12629. - public static InnectisSwitch createOrGetSwitch(Location location, String playername) {
  12630. + public static InnectisSwitch createOrGetSwitch(Location location, PlayerCredentials credentials) {
  12631. InnectisSwitch sw = getSwitch(location);
  12632.  
  12633. if (sw == null) {
  12634. - sw = new InnectisSwitch(location, playername);
  12635. + sw = new InnectisSwitch(location, credentials);
  12636.  
  12637. if (!sw.save()) {
  12638. - InnPlugin.logError("Could not create switch on location: " + location + " for " + playername + "!");
  12639. + InnPlugin.logError("Could not create switch on location: " + location + " for " + credentials + "!");
  12640. }
  12641. }
  12642. return sw;
  12643. @@ -305,11 +309,11 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12644. * Creates a switch at the given location, or gets the switch on the given
  12645. * location and returns the ID of this switch.
  12646. * @param location
  12647. - * @param playername
  12648. + * @param credentials
  12649. * @return
  12650. */
  12651. - public static int createOrGetSwitchId(Location location, String playername) {
  12652. - return createOrGetSwitch(location, playername).getId();
  12653. + public static int createOrGetSwitchId(Location location, PlayerCredentials credentials) {
  12654. + return createOrGetSwitch(location, credentials).getId();
  12655. }
  12656.  
  12657. /**
  12658. @@ -327,7 +331,7 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12659. ResultSet result = null;
  12660.  
  12661. try {
  12662. - statement = DBManager.prepareStatement("SELECT switchid, owner, locx, locy, locz, world, flags FROM switches WHERE switchid = ? ");
  12663. + statement = DBManager.prepareStatement("SELECT switchid, owner_id, locx, locy, locz, world, flags FROM switches WHERE switchid = ? ");
  12664. statement.setInt(1, id);
  12665. result = statement.executeQuery();
  12666.  
  12667. @@ -346,16 +350,18 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12668.  
  12669. /**
  12670. * Looks up all the switches owned by the given player.
  12671. - * @param owner
  12672. + * @param playerName
  12673. * @return List of the switches or null is none.
  12674. */
  12675. - public static List<InnectisSwitch> getSwitches(String owner) {
  12676. + public static List<InnectisSwitch> getSwitches(String playerName) {
  12677. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
  12678. +
  12679. PreparedStatement statement = null;
  12680. ResultSet set = null;
  12681.  
  12682. try {
  12683. - statement = DBManager.prepareStatement("SELECT switchid, owner, locx, locy, locz, world, flags FROM switches WHERE owner = ? ");
  12684. - statement.setString(1, owner.toLowerCase());
  12685. + statement = DBManager.prepareStatement("SELECT switchid, owner_id, locx, locy, locz, world, flags FROM switches WHERE owner_id = ? ");
  12686. + statement.setString(1, credentials.getUniqueId().toString());
  12687. set = statement.executeQuery();
  12688.  
  12689. List<InnectisSwitch> switches = new ArrayList<InnectisSwitch>(set.getFetchSize());
  12690. @@ -393,7 +399,10 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12691.  
  12692. Vector loc = new Vector(result.getInt("locx"), result.getInt("locy"), result.getInt("locz"));
  12693. long flags = result.getLong("flags");
  12694. - String owner = result.getString("owner");
  12695. +
  12696. + String ownerIdString = result.getString("owner_id");
  12697. + UUID ownerId = UUID.fromString(ownerIdString);
  12698. + PlayerCredentials ownerCredentials = PlayerCredentialsManager.getByUniqueId(ownerId, true);
  12699.  
  12700. // Load the links
  12701. PreparedStatement statement = DBManager.prepareStatement("SELECT switcha, switchb FROM switches_links WHERE switcha = ? OR switchb = ? ");
  12702. @@ -421,7 +430,7 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12703. DBManager.closePreparedStatement(statement);
  12704.  
  12705. // Create the switch
  12706. - InnectisSwitch returnvalue = new InnectisSwitch(switchid, owner, world, loc, flags, links);
  12707. + InnectisSwitch returnvalue = new InnectisSwitch(switchid, ownerCredentials, world, loc, flags, links);
  12708.  
  12709. // Add to chache
  12710. synchronized (switchChache) {
  12711. @@ -449,7 +458,7 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12712. ResultSet result = null;
  12713.  
  12714. try {
  12715. - statement = DBManager.prepareStatement("SELECT switchid, owner, locx, locy, locz, world, flags FROM switches "
  12716. + statement = DBManager.prepareStatement("SELECT switchid, owner_id, locx, locy, locz, world, flags FROM switches "
  12717. + " WHERE locx = ? AND locy = ? AND locz = ? AND world = ? ");
  12718. statement.setInt(1, location.getBlockX());
  12719. statement.setInt(2, location.getBlockY());
  12720. @@ -475,8 +484,8 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12721. */
  12722. @Override
  12723. public boolean save() {
  12724. - if (this.getUpdated()) {
  12725. - if (this.getId() < 0) {
  12726. + if (super.getUpdated()) {
  12727. + if (super.getId() < 0) {
  12728. return createInDB();
  12729. } else {
  12730. return updateInDB();
  12731. @@ -497,19 +506,19 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12732.  
  12733. try {
  12734. statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO switches "
  12735. - + " (owner, locx, locy, locz, world, flags) VALUES (?, ?, ?, ?, ?, ?) ");
  12736. - statement.setString(1, super.getOwner());
  12737. - statement.setInt(2, getPos1().getBlockX());
  12738. - statement.setInt(3, getPos1().getBlockY());
  12739. - statement.setInt(4, getPos1().getBlockZ());
  12740. - statement.setString(5, getWorld().getName());
  12741. - statement.setLong(6, getFlags());
  12742. + + " (owner_id, locx, locy, locz, world, flags) VALUES (?, ?, ?, ?, ?, ?) ");
  12743. + statement.setString(1, super.getOwnerCredentials().getUniqueId().toString());
  12744. + statement.setInt(2, super.getPos1().getBlockX());
  12745. + statement.setInt(3, super.getPos1().getBlockY());
  12746. + statement.setInt(4, super.getPos1().getBlockZ());
  12747. + statement.setString(5, super.getWorld().getName());
  12748. + statement.setLong(6, super.getFlags());
  12749. statement.executeUpdate();
  12750. result = statement.getGeneratedKeys();
  12751.  
  12752. if (result.next()) {
  12753. - setId(result.getInt(1));
  12754. - setUpdated(false);
  12755. + super.setId(result.getInt(1));
  12756. + super.setUpdated(false);
  12757. } else {
  12758. InnPlugin.logError("New switch not found in the database!");
  12759. return false;
  12760. @@ -535,8 +544,8 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12761.  
  12762. try {
  12763. statement = DBManager.prepareStatement("UPDATE switches SET flags = ? WHERE switchid = ?;");
  12764. - statement.setLong(1, getFlags());
  12765. - statement.setInt(2, getId());
  12766. + statement.setLong(1, super.getFlags());
  12767. + statement.setInt(2, super.getId());
  12768. statement.executeUpdate();
  12769. setUpdated(false);
  12770. } catch (SQLException ex) {
  12771. @@ -559,8 +568,8 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12772. try {
  12773. // Remove the DB links
  12774. statement = DBManager.prepareStatement(" DELETE FROM switches_links WHERE switcha = ? OR switchb = ? ");
  12775. - statement.setInt(1, getId());
  12776. - statement.setInt(2, getId());
  12777. + statement.setInt(1, super.getId());
  12778. + statement.setInt(2, super.getId());
  12779. statement.executeUpdate();
  12780.  
  12781. // Remove the link of other switches
  12782. @@ -568,12 +577,12 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12783. for (int id : links) {
  12784. tmp = getSwitch(id);
  12785. if (tmp != null) {
  12786. - tmp.removeFromLinksList(getId());
  12787. + tmp.removeFromLinksList(super.getId());
  12788. }
  12789. }
  12790.  
  12791. // Clear own links
  12792. - this.links.clear();
  12793. + links.clear();
  12794. } catch (SQLException ex) {
  12795. Logger.getLogger(InnectisSwitch.class.getName()).log(Level.SEVERE, null, ex);
  12796. } finally {
  12797. @@ -587,24 +596,25 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12798. * @return true if the ID was in the list.
  12799. */
  12800. private boolean removeFromLinksList(int id) {
  12801. - if (this.links.contains(id)) {
  12802. + if (links.contains(id)) {
  12803. for (Iterator<Integer> it = links.iterator(); it.hasNext();) {
  12804. Integer currid = it.next();
  12805. if (currid == id) {
  12806. it.remove();
  12807. }
  12808. }
  12809. +
  12810. return true;
  12811. }
  12812. +
  12813. return false;
  12814. }
  12815.  
  12816. /**
  12817. - * Deletes an switch
  12818. - * @throws SQLException
  12819. + * Deletes a switch
  12820. */
  12821. public void delete() {
  12822. - if (getId() <= 0) {
  12823. + if (super.getId() <= 0) {
  12824. return;
  12825. }
  12826.  
  12827. @@ -613,19 +623,19 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12828. try {
  12829. // Remove the switch
  12830. statement = DBManager.prepareStatement(" DELETE FROM switches WHERE switchid = ? ");
  12831. - statement.setInt(1, getId());
  12832. + statement.setInt(1, super.getId());
  12833. statement.executeUpdate();
  12834. DBManager.closePreparedStatement(statement);
  12835.  
  12836. // Remove all links
  12837. statement = DBManager.prepareStatement(" DELETE FROM switches_links WHERE switcha = ? OR switchb = ? ");
  12838. - statement.setInt(1, getId());
  12839. - statement.setInt(2, getId());
  12840. + statement.setInt(1, super.getId());
  12841. + statement.setInt(2, super.getId());
  12842. statement.executeUpdate();
  12843.  
  12844. // Remove from chache
  12845. synchronized (switchChache) {
  12846. - switchChache.remove(this.getId());
  12847. + switchChache.remove(super.getId());
  12848. }
  12849.  
  12850. // Unlink their links
  12851. @@ -633,11 +643,11 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
  12852. for (int id : links) {
  12853. tmp = getSwitch(id);
  12854. if (tmp != null) {
  12855. - tmp.removeFromLinksList(getId());
  12856. + tmp.removeFromLinksList(super.getId());
  12857. }
  12858. }
  12859.  
  12860. - this.setId(-1);
  12861. + super.setId(-1);
  12862. } catch (SQLException sqle) {
  12863. InnPlugin.logError("Could not remove Switch", sqle);
  12864. } finally {
  12865. diff --git a/src/net/innectis/innplugin/OwnedObjects/InnectisTrapdoor.java b/src/net/innectis/innplugin/OwnedObjects/InnectisTrapdoor.java
  12866. index 417370bc3..117c0e28a 100644
  12867. --- a/src/net/innectis/innplugin/OwnedObjects/InnectisTrapdoor.java
  12868. +++ b/src/net/innectis/innplugin/OwnedObjects/InnectisTrapdoor.java
  12869. @@ -6,6 +6,7 @@ import java.sql.SQLException;
  12870. import java.util.List;
  12871. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  12872. import net.innectis.innplugin.InnPlugin;
  12873. +import net.innectis.innplugin.Player.PlayerCredentials;
  12874. import org.bukkit.Location;
  12875. import org.bukkit.World;
  12876. import org.bukkit.block.Block;
  12877. @@ -15,11 +16,11 @@ import org.bukkit.block.Block;
  12878. *
  12879. * @author AlphaBlend
  12880. */
  12881. -public class InnectisTrapdoor extends InnectisOwnedObject<Integer> {
  12882. - Block trapdoor;
  12883. +public class InnectisTrapdoor extends InnectisOwnedObject {
  12884. + private Block trapdoor;
  12885.  
  12886. - public InnectisTrapdoor(World world, Location loc, int id, String owner, List<String> members, List<String> operators, long flags) {
  12887. - super(world, loc.toVector(), loc.toVector(), id, owner, members, operators, flags);
  12888. + public InnectisTrapdoor(World world, Location loc, int id, PlayerCredentials ownerCredentials, List<PlayerCredentials> members, List<PlayerCredentials> operators, long flags) {
  12889. + super(world, loc.toVector(), loc.toVector(), id, ownerCredentials, members, operators, flags);
  12890. trapdoor = loc.getBlock();
  12891. }
  12892.  
  12893. @@ -44,18 +45,18 @@ public class InnectisTrapdoor extends InnectisOwnedObject<Integer> {
  12894. int y = loc.getBlockY();
  12895. int z = loc.getBlockZ();
  12896.  
  12897. - statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO trapdoors (owner, world, locx, locy, locz, flags) VALUES (?, ?, ?, ?, ?, ?)");
  12898. - statement.setString(1, this.getOwner());
  12899. + statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO trapdoors (owner_id, world, locx, locy, locz, flags) VALUES (?, ?, ?, ?, ?, ?)");
  12900. + statement.setString(1, super.getOwnerCredentials().getUniqueId().toString());
  12901. statement.setString(2, loc.getWorld().getName());
  12902. statement.setInt(3, x);
  12903. statement.setInt(4, y);
  12904. statement.setInt(5, z);
  12905. - statement.setLong(6, getFlags());
  12906. + statement.setLong(6, super.getFlags());
  12907. statement.execute();
  12908. set = statement.getGeneratedKeys();
  12909.  
  12910. if (set.next()) {
  12911. - setId(set.getInt(1));
  12912. + super.setId(set.getInt(1));
  12913. } else {
  12914. InnPlugin.logError("New trapdoor not found in the database!");
  12915. return false;
  12916. @@ -79,9 +80,11 @@ public class InnectisTrapdoor extends InnectisOwnedObject<Integer> {
  12917. return trapdoor.getLocation();
  12918. }
  12919.  
  12920. + // TODO: Add check for lot access
  12921. +
  12922. @Override
  12923. public boolean save() {
  12924. - if (getId() == 0) {
  12925. + if (super.getId() == 0) {
  12926. return createTrapdoorInDB();
  12927. }
  12928.  
  12929. @@ -94,34 +97,34 @@ public class InnectisTrapdoor extends InnectisOwnedObject<Integer> {
  12930. PreparedStatement statement = null;
  12931.  
  12932. try {
  12933. - statement = DBManager.prepareStatement("UPDATE trapdoors SET owner = ?, world = ?, locx = ?, locy = ?, locz = ?, flags = ? WHERE trapdoorid = ?");
  12934. - statement.setString(1, getOwner());
  12935. + statement = DBManager.prepareStatement("UPDATE trapdoors SET owner_id = ?, world = ?, locx = ?, locy = ?, locz = ?, flags = ? WHERE trapdoorid = ?");
  12936. + statement.setString(1, super.getOwnerCredentials().getUniqueId().toString());
  12937. statement.setString(2, loc.getWorld().getName());
  12938. statement.setInt(3, x);
  12939. statement.setInt(4, y);
  12940. statement.setInt(5, z);
  12941. - statement.setLong(6, getFlags());
  12942. - statement.setInt(7, getId());
  12943. + statement.setLong(6, super.getFlags());
  12944. + statement.setInt(7, super.getId());
  12945. statement.executeUpdate();
  12946. DBManager.closePreparedStatement(statement);
  12947.  
  12948. statement = DBManager.prepareStatement("DELETE FROM trapdoors_members WHERE trapdoorid = ?");
  12949. - statement.setInt(1, getId());
  12950. + statement.setInt(1, super.getId());
  12951. statement.execute();
  12952. DBManager.closePreparedStatement(statement);
  12953.  
  12954. - for (String member : getMembers()) {
  12955. - statement = DBManager.prepareStatement("INSERT INTO trapdoors_members (trapdoorid, username, isop) VALUES (?, ?, 0)");
  12956. - statement.setInt(1, getId());
  12957. - statement.setString(2, member);
  12958. + for (PlayerCredentials pc : getMembers()) {
  12959. + statement = DBManager.prepareStatement("INSERT INTO trapdoors_members (trapdoorid, player_id, isop) VALUES (?, ?, 0)");
  12960. + statement.setInt(1, super.getId());
  12961. + statement.setString(2, pc.getUniqueId().toString());
  12962. statement.execute();
  12963. DBManager.closePreparedStatement(statement);
  12964. }
  12965.  
  12966. - for (String member : getOperators()) {
  12967. - statement = DBManager.prepareStatement("INSERT INTO trapdoors_members (trapdoorid, username, isop) VALUES (?, ?, 1)");
  12968. - statement.setInt(1, getId());
  12969. - statement.setString(2, member);
  12970. + for (PlayerCredentials pc : getOperators()) {
  12971. + statement = DBManager.prepareStatement("INSERT INTO trapdoors_members (trapdoorid, player_id, isop) VALUES (?, ?, 1)");
  12972. + statement.setInt(1, super.getId());
  12973. + statement.setString(2, pc.getUniqueId().toString());
  12974. statement.execute();
  12975. DBManager.closePreparedStatement(statement);
  12976. }
  12977. diff --git a/src/net/innectis/innplugin/OwnedObjects/InnectisWaypoint.java b/src/net/innectis/innplugin/OwnedObjects/InnectisWaypoint.java
  12978. index ff62394a7..5fe1271a3 100644
  12979. --- a/src/net/innectis/innplugin/OwnedObjects/InnectisWaypoint.java
  12980. +++ b/src/net/innectis/innplugin/OwnedObjects/InnectisWaypoint.java
  12981. @@ -8,7 +8,7 @@ import net.innectis.innplugin.Handlers.Datasource.DBManager;
  12982. import net.innectis.innplugin.InnPlugin;
  12983. import net.innectis.innplugin.Items.IdpMaterial;
  12984. import net.innectis.innplugin.OwnedObjects.Handlers.LotHandler;
  12985. -import net.innectis.innplugin.Player.IdpPlayer;
  12986. +import net.innectis.innplugin.Player.PlayerCredentials;
  12987. import org.bukkit.Location;
  12988. import org.bukkit.World;
  12989. import org.bukkit.block.Block;
  12990. @@ -17,20 +17,20 @@ import org.bukkit.block.Block;
  12991. *
  12992. * @author Lynxy
  12993. */
  12994. -public class InnectisWaypoint extends InnectisOwnedObject<Integer> {
  12995. +public class InnectisWaypoint extends InnectisOwnedObject {
  12996. private Block waypoint;
  12997. private Location destination;
  12998. private boolean forced;
  12999.  
  13000. - public InnectisWaypoint(World world, Block waypoint, Location destination, int id, String owner, List<String> members, List<String> operators, long flags, boolean forced) {
  13001. - super(world, waypoint.getLocation().toVector(), waypoint.getLocation().toVector(), id, owner, members, operators, flags);
  13002. + public InnectisWaypoint(World world, Block waypoint, Location destination, int id, PlayerCredentials ownerCredentials, List<PlayerCredentials> members, List<PlayerCredentials> operators, long flags, boolean forced) {
  13003. + super(world, waypoint.getLocation().toVector(), waypoint.getLocation().toVector(), id, ownerCredentials, members, operators, flags);
  13004. this.waypoint = waypoint;
  13005. this.destination = destination;
  13006. this.forced = forced;
  13007. }
  13008.  
  13009. - public InnectisWaypoint(Block waypoint, Location destination, int id, String owner, List<String> members, List<String> operators, long flags, boolean forced) {
  13010. - this(waypoint.getWorld(), waypoint, destination, id, owner, members, operators, flags, forced);
  13011. + public InnectisWaypoint(Block waypoint, Location destination, int id, PlayerCredentials ownerCredentials, List<PlayerCredentials> members, List<PlayerCredentials> operators, long flags, boolean forced) {
  13012. + this(waypoint.getWorld(), waypoint, destination, id, ownerCredentials, members, operators, flags, forced);
  13013. }
  13014.  
  13015. @Override
  13016. @@ -72,6 +72,7 @@ public class InnectisWaypoint extends InnectisOwnedObject<Integer> {
  13017. && waypoint.getLocation().getBlockZ() == location.getBlockZ()) {
  13018. return true;
  13019. }
  13020. +
  13021. return false;
  13022. }
  13023.  
  13024. @@ -86,18 +87,20 @@ public class InnectisWaypoint extends InnectisOwnedObject<Integer> {
  13025. }
  13026.  
  13027. /**
  13028. - * Returns true if the player is the owner or a member, or if this Waypoint's owner is % or contains member %, or if this Waypoint has member
  13029. + * Returns true if the player is the owner or a member, or if this
  13030. + * Waypoint's owner is % or contains member %, or if this Waypoint has member
  13031. * @ and player is a member of the Lot this waypoint is on
  13032. - * @param player
  13033. + * @param playerName
  13034. */
  13035. @Override
  13036. - public boolean canPlayerAccess(IdpPlayer player) {
  13037. - if (super.canPlayerAccess(player)) {
  13038. + public boolean canPlayerAccess(String playerName) {
  13039. + if (super.canPlayerAccess(playerName)) {
  13040. return true;
  13041. }
  13042. +
  13043. if (containsMember("@")) { //allow lot members
  13044. InnectisLot lot = LotHandler.getLot(waypoint.getLocation());
  13045. - if (lot != null && (lot.containsMember(player.getName()) || lot.containsOperator(player.getName()))) {
  13046. + if (lot != null && (lot.containsMember(playerName) || lot.containsOperator(playerName))) {
  13047. return true;
  13048. }
  13049. }
  13050. @@ -118,10 +121,10 @@ public class InnectisWaypoint extends InnectisOwnedObject<Integer> {
  13051.  
  13052. try {
  13053. statement = DBManager.prepareStatementWithAutoGeneratedKeys("REPLACE INTO waypoints "
  13054. - + "(owner, world, locx, locy, locz, tworld, tlocx, tlocy, tlocz, tyaw, flags, forced)"
  13055. + + "(owner_id, world, locx, locy, locz, tworld, tlocx, tlocy, tlocz, tyaw, flags, forced)"
  13056. + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
  13057. - statement.setString(1, getOwner());
  13058. - statement.setString(2, getWorld().getName());
  13059. + statement.setString(1, super.getOwnerCredentials().getUniqueId().toString());
  13060. + statement.setString(2, super.getWorld().getName());
  13061. statement.setInt(3, getWaypoint().getX());
  13062. statement.setInt(4, getWaypoint().getY());
  13063. statement.setInt(5, getWaypoint().getZ());
  13064. @@ -130,14 +133,14 @@ public class InnectisWaypoint extends InnectisOwnedObject<Integer> {
  13065. statement.setInt(8, getDestination().getBlockY());
  13066. statement.setInt(9, getDestination().getBlockZ());
  13067. statement.setFloat(10, getDestination().getYaw());
  13068. - statement.setLong(11, getFlags());
  13069. + statement.setLong(11, super.getFlags());
  13070. statement.setBoolean(12, isForced());
  13071. statement.executeUpdate();
  13072. result = statement.getGeneratedKeys();
  13073.  
  13074. if (result.next()) {
  13075. - setId(result.getInt(1));
  13076. - setUpdated(false);
  13077. + super.setId(result.getInt(1));
  13078. + super.setUpdated(false);
  13079. } else {
  13080. InnPlugin.logError("New waypoint not found in the database!");
  13081. return false;
  13082. @@ -155,7 +158,7 @@ public class InnectisWaypoint extends InnectisOwnedObject<Integer> {
  13083.  
  13084. @Override
  13085. public boolean save() {
  13086. - if (getId() == -1) {
  13087. + if (super.getId() == -1) {
  13088. return createWaypointInDB();
  13089. }
  13090.  
  13091. @@ -163,21 +166,13 @@ public class InnectisWaypoint extends InnectisOwnedObject<Integer> {
  13092.  
  13093. try {
  13094. statement = DBManager.prepareStatement("UPDATE waypoints SET "
  13095. - + "owner = ?, "
  13096. - + "world = ?, "
  13097. - + "locx = ?, "
  13098. - + "locy = ?, "
  13099. - + "locz = ?, "
  13100. - + "tworld = ?, "
  13101. - + "tlocx = ?, "
  13102. - + "tlocy = ?, "
  13103. - + "tlocz = ?, "
  13104. - + "tyaw = ?, "
  13105. - + "flags = ?, "
  13106. - + "forced = ? "
  13107. + + "owner_id = ?, world = ?, locx = ?, "
  13108. + + "locy = ?, locz = ?, tworld = ?, "
  13109. + + "tlocx = ?, tlocy = ?, tlocz = ?, "
  13110. + + "tyaw = ?, flags = ?, forced = ? "
  13111. + "WHERE waypointid = ?;");
  13112. - statement.setString(1, getOwner());
  13113. - statement.setString(2, getWorld().getName());
  13114. + statement.setString(1, super.getOwnerCredentials().getUniqueId().toString());
  13115. + statement.setString(2, super.getWorld().getName());
  13116. statement.setInt(3, getWaypoint().getX());
  13117. statement.setInt(4, getWaypoint().getY());
  13118. statement.setInt(5, getWaypoint().getZ());
  13119. @@ -186,34 +181,34 @@ public class InnectisWaypoint extends InnectisOwnedObject<Integer> {
  13120. statement.setInt(8, getDestination().getBlockY());
  13121. statement.setInt(9, getDestination().getBlockZ());
  13122. statement.setFloat(10, getDestination().getYaw());
  13123. - statement.setLong(11, getFlags());
  13124. + statement.setLong(11, super.getFlags());
  13125. statement.setBoolean(12, isForced());
  13126. - statement.setInt(13, getId());
  13127. + statement.setInt(13, super.getId());
  13128. statement.executeUpdate();
  13129. DBManager.closePreparedStatement(statement);
  13130.  
  13131. statement = DBManager.prepareStatement("DELETE FROM waypoints_members WHERE waypointid = ?;");
  13132. - statement.setInt(1, getId());
  13133. + statement.setInt(1, super.getId());
  13134. statement.executeUpdate();
  13135. DBManager.closePreparedStatement(statement);
  13136.  
  13137. - for (String s : getMembers()) {
  13138. - statement = DBManager.prepareStatement("INSERT INTO waypoints_members (waypointid, username, isop) VALUES (?, ?, 0);");
  13139. - statement.setInt(1, getId());
  13140. - statement.setString(2, s);
  13141. + for (PlayerCredentials pc : getMembers()) {
  13142. + statement = DBManager.prepareStatement("INSERT INTO waypoints_members (waypointid, player_id, isop) VALUES (?, ?, 0);");
  13143. + statement.setInt(1, super.getId());
  13144. + statement.setString(2, pc.getUniqueId().toString());
  13145. statement.executeUpdate();
  13146. DBManager.closePreparedStatement(statement);
  13147. }
  13148.  
  13149. - for (String s : getOperators()) {
  13150. - statement = DBManager.prepareStatement("INSERT INTO waypoints_members (waypointid, username, isop) VALUES (?, ?, 1);");
  13151. - statement.setInt(1, getId());
  13152. - statement.setString(2, s);
  13153. + for (PlayerCredentials pc : getOperators()) {
  13154. + statement = DBManager.prepareStatement("INSERT INTO waypoints_members (waypointid, player_id, isop) VALUES (?, ?, 1);");
  13155. + statement.setInt(1, super.getId());
  13156. + statement.setString(2, pc.getUniqueId().toString());
  13157. statement.executeUpdate();
  13158. DBManager.closePreparedStatement(statement);
  13159. }
  13160.  
  13161. - setUpdated(false);
  13162. + super.setUpdated(false);
  13163. } catch (SQLException ex) {
  13164. InnPlugin.logError("Unable to save waypoint #" + getId() + "!", ex);
  13165. return false;
  13166. diff --git a/src/net/innectis/innplugin/OwnedObjects/LotFlagType.java b/src/net/innectis/innplugin/OwnedObjects/LotFlagType.java
  13167. index 0723cda17..8569bc065 100644
  13168. --- a/src/net/innectis/innplugin/OwnedObjects/LotFlagType.java
  13169. +++ b/src/net/innectis/innplugin/OwnedObjects/LotFlagType.java
  13170. @@ -46,7 +46,7 @@ public enum LotFlagType implements FlagType {
  13171. CREATIVEWATER (35 , "CreativeWater" , PlayerGroup.ADMIN),
  13172. RESTRICTMINECART (36 , "RestrictMinecart" , PlayerGroup.GUEST),
  13173. LOCKINPUT (37 , "LockInput" , PlayerGroup.GUEST),
  13174. - NOMELT (38 , "NoMelt" , PlayerGroup.GUEST),
  13175. + NOMELT (38 , "NoMelt" , PlayerGroup.GUEST),
  13176. LOCKOUTPUT (39 , "LockOutput" , PlayerGroup.GUEST),
  13177. NOSTRUCTURE (40 , "NoBridge" , PlayerGroup.GUEST),
  13178. INVISIBLE (41 , "Invisible" , PlayerGroup.MODERATOR),
  13179. diff --git a/src/net/innectis/innplugin/OwnedObjects/OwnedEntity.java b/src/net/innectis/innplugin/OwnedObjects/OwnedEntity.java
  13180. index 8f40d129e..3fc2579b6 100644
  13181. --- a/src/net/innectis/innplugin/OwnedObjects/OwnedEntity.java
  13182. +++ b/src/net/innectis/innplugin/OwnedObjects/OwnedEntity.java
  13183. @@ -1,5 +1,6 @@
  13184. package net.innectis.innplugin.OwnedObjects;
  13185.  
  13186. +import net.innectis.innplugin.Player.PlayerCredentials;
  13187. import org.bukkit.entity.EntityType;
  13188.  
  13189. /**
  13190. @@ -8,20 +9,28 @@ import org.bukkit.entity.EntityType;
  13191. * @author AlphaBlend
  13192. */
  13193. public class OwnedEntity {
  13194. - private String owner;
  13195. + private PlayerCredentials ownerCredentials;
  13196. private EntityType type;
  13197.  
  13198. - public OwnedEntity(String owner, EntityType type) {
  13199. - this.owner = owner;
  13200. + public OwnedEntity(PlayerCredentials ownerCredentials, EntityType type) {
  13201. + this.ownerCredentials = ownerCredentials;
  13202. this.type = type;
  13203. }
  13204.  
  13205. + /**
  13206. + * Gets the credentials of the player that owns this entity
  13207. + * @return
  13208. + */
  13209. + public PlayerCredentials getOwnerCredentials() {
  13210. + return ownerCredentials;
  13211. + }
  13212. +
  13213. /**
  13214. * Returns the owner of this entity
  13215. * @return
  13216. */
  13217. public String getOwner() {
  13218. - return owner;
  13219. + return ownerCredentials.getName();
  13220. }
  13221.  
  13222. /**
  13223. diff --git a/src/net/innectis/innplugin/Player/Channel/ChatChannel.java b/src/net/innectis/innplugin/Player/Channel/ChatChannel.java
  13224. index de12d4f6a..b41b614eb 100644
  13225. --- a/src/net/innectis/innplugin/Player/Channel/ChatChannel.java
  13226. +++ b/src/net/innectis/innplugin/Player/Channel/ChatChannel.java
  13227. @@ -5,13 +5,16 @@ import java.sql.ResultSet;
  13228. import java.sql.SQLException;
  13229. import java.util.ArrayList;
  13230. import java.util.HashMap;
  13231. +import java.util.Iterator;
  13232. import java.util.List;
  13233. import java.util.Set;
  13234. +import java.util.UUID;
  13235. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  13236. import net.innectis.innplugin.InnPlugin;
  13237. import net.innectis.innplugin.Loggers.LogManager;
  13238. import net.innectis.innplugin.Player.Chat.ChatMessage;
  13239. import net.innectis.innplugin.Player.IdpPlayer;
  13240. +import net.innectis.innplugin.Player.PlayerCredentials;
  13241. import net.innectis.innplugin.Player.PlayerSession;
  13242. import org.bukkit.ChatColor;
  13243.  
  13244. @@ -28,9 +31,9 @@ public class ChatChannel {
  13245. private String name;
  13246. private long settings = 0;
  13247. private String password = null;
  13248. - private String owner = null;
  13249. - private HashMap<String, MemberDetails> members = new HashMap<String, MemberDetails>();
  13250. - private List<String> banned = new ArrayList<String>();
  13251. + private PlayerCredentials ownerCredentials = null;
  13252. + private HashMap<PlayerCredentials, MemberDetails> members = new HashMap<PlayerCredentials, MemberDetails>();
  13253. + private List<PlayerCredentials> banned = new ArrayList<PlayerCredentials>();
  13254.  
  13255. public ChatChannel(String name, long settings, String password, long lastActivity) {
  13256. this(0, name, settings, password, lastActivity);
  13257. @@ -100,7 +103,7 @@ public class ChatChannel {
  13258.  
  13259. /**
  13260. * Checks if the channel has the specified setting
  13261. - * @param flagBit
  13262. + * @param settomg
  13263. * @return
  13264. */
  13265. public boolean hasSetting(ChannelSettings setting) {
  13266. @@ -109,7 +112,7 @@ public class ChatChannel {
  13267.  
  13268. /**
  13269. * Clears the channel setting
  13270. - * @param flagBit
  13271. + * @param setting
  13272. */
  13273. public void clearSetting(ChannelSettings setting) {
  13274. settings &= ~setting.getBit();
  13275. @@ -118,7 +121,7 @@ public class ChatChannel {
  13276.  
  13277. /**
  13278. * Sets the channel setting
  13279. - * @param flagBit
  13280. + * @param setting
  13281. */
  13282. public void setSetting(ChannelSettings setting) {
  13283. settings |= setting.getBit();
  13284. @@ -150,30 +153,38 @@ public class ChatChannel {
  13285. return (password != null && !password.isEmpty());
  13286. }
  13287.  
  13288. + /**
  13289. + * Gets the credentials of the owner of this channel
  13290. + * @return
  13291. + */
  13292. + public PlayerCredentials getOwnerCredentials() {
  13293. + return ownerCredentials;
  13294. + }
  13295. +
  13296. /**
  13297. * Gets the owner of this channel
  13298. * @return
  13299. */
  13300. public String getOwner() {
  13301. - return owner;
  13302. + return ownerCredentials.getName();
  13303. }
  13304.  
  13305. /**
  13306. - * Adds the specified member to this channel and returns their member
  13307. + * Adds the credentials of a member to this channel and returns their member
  13308. * details object. If they are the owner then it sets the owner
  13309. * string to them
  13310. - * @param username
  13311. + * @param credentials
  13312. * @param group
  13313. * @param personalnum
  13314. * @param save This will save the member table if true
  13315. * @return
  13316. */
  13317. - public MemberDetails addMember(String username, ChatChannelGroup group, int personalnum, boolean save) {
  13318. + public MemberDetails addMember(PlayerCredentials credentials, ChatChannelGroup group, int personalnum, boolean save) {
  13319. MemberDetails details = new MemberDetails(personalnum, group);
  13320. - members.put(username.toLowerCase(), details);
  13321. + members.put(credentials, details);
  13322.  
  13323. if (group == ChatChannelGroup.OWNER) {
  13324. - owner = username;
  13325. + ownerCredentials = credentials;
  13326. }
  13327.  
  13328. if (save) {
  13329. @@ -187,13 +198,25 @@ public class ChatChannel {
  13330. * Removes the member and returns their member group. This will
  13331. * also promote the next user to owner if the person that left
  13332. * was the current owner
  13333. - * @param username
  13334. + * @param playerName
  13335. * @return
  13336. */
  13337. - public MemberDetails removeMember(String username) {
  13338. - MemberDetails details = members.remove(username.toLowerCase());
  13339. + public MemberDetails removeMember(String playerName) {
  13340. + MemberDetails details = null;
  13341. + UUID playerId = null;
  13342.  
  13343. - PlayerSession session = PlayerSession.getActiveSession(username);
  13344. + for (Iterator<PlayerCredentials> it = members.keySet().iterator(); it.hasNext();) {
  13345. + PlayerCredentials pc = it.next();
  13346. +
  13347. + if (pc.getName().equalsIgnoreCase(playerName)) {
  13348. + details = members.get(pc);
  13349. + playerId = pc.getUniqueId();
  13350. + it.remove();
  13351. + break;
  13352. + }
  13353. + }
  13354. +
  13355. + PlayerSession session = PlayerSession.getActiveSession(playerId);
  13356.  
  13357. // Make sure to remove their personal channel number when they leave
  13358. if (session != null) {
  13359. @@ -203,10 +226,10 @@ public class ChatChannel {
  13360. // If this channel still has members, check if there needs to be a new owner
  13361. if (members.size() > 0) {
  13362. if (details.getGroup() == ChatChannelGroup.OWNER) {
  13363. - String nextOwner = members.keySet().iterator().next();
  13364. + PlayerCredentials nextOwner = members.keySet().iterator().next();
  13365. MemberDetails nextOwnerDetails = members.get(nextOwner);
  13366. nextOwnerDetails.setGroup(ChatChannelGroup.OWNER);
  13367. - owner = nextOwner;
  13368. + ownerCredentials = nextOwner;
  13369. }
  13370.  
  13371. updateMembersTable();
  13372. @@ -216,25 +239,30 @@ public class ChatChannel {
  13373. }
  13374.  
  13375. /**
  13376. - * Modifies the member group of this user
  13377. - * @param username
  13378. + * Modifies the playerName group the member
  13379. + * @param playerName
  13380. * @param group
  13381. */
  13382. - public void modifyMemberGroup(String username, ChatChannelGroup group) {
  13383. - MemberDetails details = members.get(username.toLowerCase());
  13384. - details.setGroup(group);
  13385. - updateMembersTable();
  13386. + public void modifyMemberGroup(String playerName, ChatChannelGroup group) {
  13387. + for (PlayerCredentials pc : members.keySet()) {
  13388. + if (pc.getName().equalsIgnoreCase(playerName)) {
  13389. + MemberDetails details = members.get(pc);
  13390. + details.setGroup(group);
  13391. + updateMembersTable();
  13392. + break;
  13393. + }
  13394. + }
  13395. }
  13396.  
  13397. /**
  13398. * Sets the online/offline status of the member
  13399. - *
  13400. + * @param playerName
  13401. * @param online
  13402. */
  13403. - public void setMemberStatus(String username, boolean online) {
  13404. - for (String member : members.keySet()) {
  13405. - if (member.equalsIgnoreCase(username)) {
  13406. - MemberDetails details = members.get(member);
  13407. + public void setMemberStatus(String playerName, boolean online) {
  13408. + for (PlayerCredentials pc : members.keySet()) {
  13409. + if (pc.getName().equalsIgnoreCase(playerName)) {
  13410. + MemberDetails details = members.get(pc);
  13411. details.setOnline(online);
  13412. break;
  13413. }
  13414. @@ -243,40 +271,52 @@ public class ChatChannel {
  13415.  
  13416. /**
  13417. * Switches the current owner with the specified member
  13418. - * @param username
  13419. + * @param credentials
  13420. */
  13421. - public void switchOwner(String username) {
  13422. - MemberDetails previousOwnerDetails = members.get(owner.toLowerCase());
  13423. - MemberDetails newOwnerDetails = members.get(username.toLowerCase());
  13424. + public void switchOwner(PlayerCredentials credentials) {
  13425. + MemberDetails previousOwnerDetails = members.get(ownerCredentials);
  13426. + MemberDetails newOwnerDetails = members.get(credentials);
  13427. previousOwnerDetails.setGroup(ChatChannelGroup.MEMBER);
  13428. newOwnerDetails.setGroup(ChatChannelGroup.OWNER);
  13429. - owner = username;
  13430. + ownerCredentials = credentials;
  13431. updateMembersTable();
  13432. }
  13433.  
  13434. /**
  13435. * Checks if the specified user is in this channel
  13436. - * @param username
  13437. + * @param playerName
  13438. * @return
  13439. */
  13440. - public boolean containsMember(String username) {
  13441. - return members.containsKey(username.toLowerCase());
  13442. + public boolean containsMember(String playerName) {
  13443. + for (PlayerCredentials pc : members.keySet()) {
  13444. + if (pc.getName().equalsIgnoreCase(playerName)) {
  13445. + return true;
  13446. + }
  13447. + }
  13448. +
  13449. + return false;
  13450. }
  13451.  
  13452. /**
  13453. * Gets the details of the specified member
  13454. - * @param username
  13455. + * @param playerName
  13456. * @return
  13457. */
  13458. - public MemberDetails getMemberDetails(String username) {
  13459. - return members.get(username.toLowerCase());
  13460. + public MemberDetails getMemberDetails(String playerName) {
  13461. + for (PlayerCredentials pc : members.keySet()) {
  13462. + if (pc.getName().equalsIgnoreCase(playerName)) {
  13463. + return members.get(pc);
  13464. + }
  13465. + }
  13466. +
  13467. + return null;
  13468. }
  13469.  
  13470. /**
  13471. * Returns a list of all members with the specified group
  13472. * @return
  13473. */
  13474. - public List<String> getMembers() {
  13475. + public List<PlayerCredentials> getMembers() {
  13476. return getMembers(ChatChannelGroup.MEMBER, true);
  13477. }
  13478.  
  13479. @@ -286,16 +326,16 @@ public class ChatChannel {
  13480. * @param inherited If true, returns if the member inherits the group
  13481. * @return
  13482. */
  13483. - public List<String> getMembers(ChatChannelGroup group, boolean inherited) {
  13484. - List<String> memberList = new ArrayList<String>();
  13485. + public List<PlayerCredentials> getMembers(ChatChannelGroup group, boolean inherited) {
  13486. + List<PlayerCredentials> memberList = new ArrayList<PlayerCredentials>();
  13487.  
  13488. - for (String member : members.keySet()) {
  13489. - MemberDetails details = members.get(member);
  13490. + for (PlayerCredentials pc : members.keySet()) {
  13491. + MemberDetails details = members.get(pc);
  13492. ChatChannelGroup memberGroup = details.getGroup();
  13493. boolean isRequisite = (inherited ? memberGroup.equalsOrInherits(group) : memberGroup.equals(group));
  13494.  
  13495. if (isRequisite) {
  13496. - memberList.add(member);
  13497. + memberList.add(pc);
  13498. }
  13499. }
  13500.  
  13501. @@ -320,29 +360,48 @@ public class ChatChannel {
  13502.  
  13503. /**
  13504. * Adds the user to the banned list
  13505. - * @param username
  13506. + * @param credentials
  13507. */
  13508. - public void addBanned(String username) {
  13509. - banned.add(username.toLowerCase());
  13510. + public void addBanned(PlayerCredentials credentials) {
  13511. + banned.add(credentials);
  13512. updateBannedMembersTable();
  13513. }
  13514.  
  13515. /**
  13516. * Removes the user from the banned list
  13517. - * @param username
  13518. + * @param playerName
  13519. */
  13520. - public void removeBanned(String username) {
  13521. - banned.remove(username.toLowerCase());
  13522. - updateBannedMembersTable();
  13523. + public void removeBanned(String playerName) {
  13524. + boolean removed = false;
  13525. +
  13526. + for (Iterator<PlayerCredentials> it = banned.iterator(); it.hasNext();) {
  13527. + PlayerCredentials pc = it.next();
  13528. +
  13529. + if (pc.getName().equalsIgnoreCase(playerName)) {
  13530. + it.remove();
  13531. + removed = true;
  13532. + break;
  13533. + }
  13534. + }
  13535. +
  13536. + if (removed) {
  13537. + updateBannedMembersTable();
  13538. + }
  13539. }
  13540.  
  13541. /**
  13542. * Checks if the user is banned from this channel
  13543. - * @param username
  13544. + * playerName playerName
  13545. * @return
  13546. */
  13547. - public boolean isBanned(String username) {
  13548. - return banned.contains(username.toLowerCase());
  13549. + public boolean isBanned(String playerName) {
  13550. + for (PlayerCredentials pc : banned) {
  13551. + if (pc.getName().equalsIgnoreCase(playerName)) {
  13552. + return true;
  13553. + }
  13554. + }
  13555. +
  13556. + return false;
  13557. }
  13558.  
  13559. /**
  13560. @@ -350,12 +409,17 @@ public class ChatChannel {
  13561. * @return
  13562. */
  13563. public List<String> getBanned() {
  13564. - return banned;
  13565. + List<String> bannedMembers = new ArrayList<String>();
  13566. +
  13567. + for (PlayerCredentials pc : banned) {
  13568. + bannedMembers.add(pc.getName());
  13569. + }
  13570. +
  13571. + return bannedMembers;
  13572. }
  13573.  
  13574. /**
  13575. * Sends a general channel message to the specified channel
  13576. - * @param channel
  13577. * @param msg
  13578. */
  13579. public void sendGeneralMessage(String msg) {
  13580. @@ -367,8 +431,9 @@ public class ChatChannel {
  13581.  
  13582. /**
  13583. * Sends a chat message to the channel
  13584. + * @param player
  13585. * @param msg
  13586. - * @param additionalRecipients
  13587. + * @param globalListeners
  13588. */
  13589. public void sendChatMessage(IdpPlayer player, String msg, Set<String> globalListeners) {
  13590. msg = player.getColoredName() + ChatColor.AQUA + ": " + msg;
  13591. @@ -423,12 +488,14 @@ public class ChatChannel {
  13592. public List<IdpPlayer> getPlayers() {
  13593. List<IdpPlayer> players = new ArrayList<IdpPlayer>();
  13594. IdpPlayer tmpPlayer;
  13595. - for (String member : members.keySet()) {
  13596. - tmpPlayer = InnPlugin.getPlugin().getPlayer(member, true);
  13597. + for (PlayerCredentials pc : members.keySet()) {
  13598. + tmpPlayer = InnPlugin.getPlugin().getPlayer(pc.getUniqueId());
  13599. +
  13600. if (tmpPlayer != null) {
  13601. players.add(tmpPlayer);
  13602. }
  13603. }
  13604. +
  13605. return players;
  13606. }
  13607.  
  13608. @@ -575,12 +642,12 @@ public class ChatChannel {
  13609. DBManager.closePreparedStatement(statement);
  13610. }
  13611.  
  13612. - statement = DBManager.prepareStatement("INSERT INTO channel_members VALUES (?, ?, ?, ?)");
  13613. + statement = DBManager.prepareStatement("INSERT INTO channel_members (channelid, player_id, personalnum, membergroup) VALUES (?, ?, ?, ?)");
  13614.  
  13615. - for (String member : members.keySet()) {
  13616. - MemberDetails details = members.get(member);
  13617. + for (PlayerCredentials pc : members.keySet()) {
  13618. + MemberDetails details = members.get(pc);
  13619. statement.setInt(1, id);
  13620. - statement.setString(2, member);
  13621. + statement.setString(2, pc.getUniqueId().toString());
  13622. statement.setInt(3, details.getPersonalNumber());
  13623. statement.setInt(4, details.getGroup().getId());
  13624. statement.execute();
  13625. @@ -610,11 +677,11 @@ public class ChatChannel {
  13626. }
  13627.  
  13628. if (banned.size() > 0) {
  13629. - statement = DBManager.prepareStatement("INSERT INTO channel_bans VALUES (?, ?);");
  13630. + statement = DBManager.prepareStatement("INSERT INTO channel_bans (channelid, player_id) VALUES (?, ?);");
  13631.  
  13632. - for (String bannedMember : banned) {
  13633. + for (PlayerCredentials pc : banned) {
  13634. statement.setInt(1, id);
  13635. - statement.setString(2, bannedMember);
  13636. + statement.setString(2, pc.getUniqueId().toString());
  13637. statement.execute();
  13638. }
  13639. }
  13640. diff --git a/src/net/innectis/innplugin/Player/Channel/ChatChannelHandler.java b/src/net/innectis/innplugin/Player/Channel/ChatChannelHandler.java
  13641. index b0c1fae4f..093a1f101 100644
  13642. --- a/src/net/innectis/innplugin/Player/Channel/ChatChannelHandler.java
  13643. +++ b/src/net/innectis/innplugin/Player/Channel/ChatChannelHandler.java
  13644. @@ -9,8 +9,11 @@ import java.util.HashMap;
  13645. import java.util.HashSet;
  13646. import java.util.List;
  13647. import java.util.Set;
  13648. +import java.util.UUID;
  13649. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  13650. import net.innectis.innplugin.InnPlugin;
  13651. +import net.innectis.innplugin.Player.PlayerCredentials;
  13652. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  13653. import net.innectis.innplugin.Player.PlayerSession;
  13654.  
  13655. /**
  13656. @@ -136,16 +139,16 @@ public class ChatChannelHandler {
  13657.  
  13658. /**
  13659. * Deletes the channel by its channel object
  13660. - * @param channelName
  13661. + * @param channel
  13662. */
  13663. public static void deleteChannel(ChatChannel channel) {
  13664. _channels.remove(channel.getName().toLowerCase());
  13665. idNameMap.remove(channel.getId());
  13666.  
  13667. - for (String member : channel.getMembers()) {
  13668. - MemberDetails details = channel.getMemberDetails(member);
  13669. + for (PlayerCredentials pc : channel.getMembers()) {
  13670. + MemberDetails details = channel.getMemberDetails(pc.getName());
  13671. + PlayerSession session = PlayerSession.getActiveSession(pc.getUniqueId());
  13672.  
  13673. - PlayerSession session = PlayerSession.getActiveSession(member);
  13674. if (session != null) {
  13675. session.removeChannelNumber(details.getPersonalNumber());
  13676. }
  13677. @@ -249,10 +252,13 @@ public class ChatChannelHandler {
  13678. set = statement.executeQuery();
  13679.  
  13680. while (set.next()) {
  13681. - String name = set.getString("username");
  13682. + String playerIdString = set.getString("player_id");
  13683. + UUID playerId = UUID.fromString(playerIdString);
  13684. + PlayerCredentials memberCredentials = PlayerCredentialsManager.getByUniqueId(playerId, true);
  13685. +
  13686. int personalNumber = set.getInt("personalnum");
  13687. ChatChannelGroup group = ChatChannelGroup.fromId(set.getInt("membergroup"));
  13688. - channel.addMember(name, group, personalNumber, false);
  13689. + channel.addMember(memberCredentials, group, personalNumber, false);
  13690. }
  13691.  
  13692. DBManager.closeResultSet(set);
  13693. @@ -263,7 +269,11 @@ public class ChatChannelHandler {
  13694. set = statement.executeQuery();
  13695.  
  13696. while (set.next()) {
  13697. - channel.addBanned(set.getString("username"));
  13698. + String playerIdString = set.getString("player_id");
  13699. + UUID playerId = UUID.fromString(playerIdString);
  13700. + PlayerCredentials playerCredentials = PlayerCredentialsManager.getByUniqueId(playerId, true);
  13701. +
  13702. + channel.addBanned(playerCredentials);
  13703. }
  13704. }
  13705.  
  13706. diff --git a/src/net/innectis/innplugin/Player/IdpPlayer.java b/src/net/innectis/innplugin/Player/IdpPlayer.java
  13707. index 5f6d08783..a1d444f51 100644
  13708. --- a/src/net/innectis/innplugin/Player/IdpPlayer.java
  13709. +++ b/src/net/innectis/innplugin/Player/IdpPlayer.java
  13710. @@ -5,6 +5,7 @@ import java.util.HashSet;
  13711. import java.util.List;
  13712. import java.util.Map;
  13713. import java.util.NoSuchElementException;
  13714. +import java.util.UUID;
  13715. import net.innectis.innplugin.Configuration;
  13716. import net.innectis.innplugin.Economy.ValutaSinkManager;
  13717. import net.innectis.innplugin.External.API.Interfaces.IWorldEditIDP;
  13718. @@ -91,6 +92,14 @@ public class IdpPlayer extends IdpCommandSender<CraftPlayer> {
  13719. return CommandSenderType.PLAYER;
  13720. }
  13721.  
  13722. + /**
  13723. + * Gets the unique ID of this player
  13724. + * @return
  13725. + */
  13726. + public UUID getUniqueId() {
  13727. + return player.getUniqueId();
  13728. + }
  13729. +
  13730. /**
  13731. * Returns the players name
  13732. *
  13733. @@ -160,8 +169,9 @@ public class IdpPlayer extends IdpCommandSender<CraftPlayer> {
  13734. */
  13735. public PlayerSession getSession() {
  13736. if (session == null) {
  13737. - session = PlayerSession.getSession(getName(), plugin);
  13738. + session = PlayerSession.getSession(getUniqueId(), getName(), plugin);
  13739. }
  13740. +
  13741. return session;
  13742. }
  13743.  
  13744. @@ -254,7 +264,6 @@ public class IdpPlayer extends IdpCommandSender<CraftPlayer> {
  13745. public void resetFoodLevel() {
  13746. player.setFoodLevel(20);
  13747. }
  13748. -
  13749. //</editor-fold>
  13750. //
  13751. // <editor-fold defaultstate="collapsed" desc="Location">
  13752. @@ -547,7 +556,7 @@ public class IdpPlayer extends IdpCommandSender<CraftPlayer> {
  13753. if (getWorld().getWorldType() == IdpWorldType.NETHER && restrictIfNether
  13754. && !hasPermission(Permission.special_nether_tp_no_cost)) {
  13755. int requiredCost = Configuration.WARP_OUT_NETHER_COST;
  13756. - TransactionObject transaction = TransactionHandler.getTransactionObject(getName());
  13757. + TransactionObject transaction = TransactionHandler.getTransactionObject(getUniqueId(), getName());
  13758. int valutas = transaction.getValue(TransactionType.VALUTAS);
  13759.  
  13760. if (valutas >= requiredCost) {
  13761. @@ -621,8 +630,8 @@ public class IdpPlayer extends IdpCommandSender<CraftPlayer> {
  13762.  
  13763. // Before the teleport, make sure the player isn't lighting up any blocks.
  13764. // If they are, restore the original block
  13765. - if (LightsourceHandler.isLightingBlock(getName())) {
  13766. - LightsourceHandler.unlightBlock(getName());
  13767. + if (LightsourceHandler.isLightingBlock(getUniqueId())) {
  13768. + LightsourceHandler.unlightBlock(getUniqueId());
  13769. }
  13770.  
  13771. // if (worldFrom != worldTo) //fix tp going to wrong coords
  13772. @@ -931,7 +940,7 @@ public class IdpPlayer extends IdpCommandSender<CraftPlayer> {
  13773. * @return
  13774. */
  13775. public IdpPlayerInventory getInventory() {
  13776. - IdpPlayerInventory inventory = new IdpPlayerInventory(player.getName(), getCurrentInventoryType());
  13777. + IdpPlayerInventory inventory = new IdpPlayerInventory(getUniqueId(), getName(), getCurrentInventoryType());
  13778. inventory.setContents(player.getInventory().getContents(), player.getInventory().getArmorContents());
  13779. inventory.setExperience(player.getExp());
  13780. inventory.setLevel(player.getLevel());
  13781. @@ -976,7 +985,7 @@ public class IdpPlayer extends IdpCommandSender<CraftPlayer> {
  13782. public void setInventory(InventoryType newType) {
  13783. clearInventory();
  13784. clearPotionEffects();
  13785. - IdpPlayerInventory inventory = IdpPlayerInventory.load(player.getName(), newType, plugin);
  13786. + IdpPlayerInventory inventory = IdpPlayerInventory.load(getUniqueId(), getName(), newType, plugin);
  13787. setCurrentInventoryType(inventory.getType());
  13788. player.getInventory().setContents(inventory.getBukkitItems());
  13789. player.getInventory().setArmorContents(inventory.getBukkitArmorItems());
  13790. @@ -1558,7 +1567,7 @@ public class IdpPlayer extends IdpCommandSender<CraftPlayer> {
  13791. }
  13792.  
  13793. InnectisLot lot = LotHandler.getLot(loc);
  13794. - mainConditionMet = ((lot == null || lot.canPlayerAccess(this))
  13795. + mainConditionMet = ((lot == null || lot.canPlayerAccess(getName()))
  13796. && hasPermission(Permission.special_lightsource_torch));
  13797. }
  13798.  
  13799. diff --git a/src/net/innectis/innplugin/Player/IdpPlayerInventory.java b/src/net/innectis/innplugin/Player/IdpPlayerInventory.java
  13800. index 9a205676c..edd06510c 100644
  13801. --- a/src/net/innectis/innplugin/Player/IdpPlayerInventory.java
  13802. +++ b/src/net/innectis/innplugin/Player/IdpPlayerInventory.java
  13803. @@ -5,6 +5,7 @@ import java.sql.ResultSet;
  13804. import java.sql.SQLException;
  13805. import java.util.ArrayList;
  13806. import java.util.List;
  13807. +import java.util.UUID;
  13808. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  13809. import net.innectis.innplugin.IdpRuntimeException;
  13810. import net.innectis.innplugin.InnPlugin;
  13811. @@ -25,9 +26,13 @@ public class IdpPlayerInventory {
  13812. private static final int DEFAULT_ITEM_SIZE = 36;
  13813. private static final int DEFAULT_ARMOR_SIZE = 4;
  13814. /**
  13815. - * Owner of the inventory
  13816. + * ID of the owner of this inventory
  13817. */
  13818. - private String username;
  13819. + private UUID playerId;
  13820. + /**
  13821. + * Owner of this inventory
  13822. + */
  13823. + private String playerName;
  13824. /**
  13825. * The type of the inventory
  13826. */
  13827. @@ -64,12 +69,13 @@ public class IdpPlayerInventory {
  13828. /**
  13829. * Creates a new empty inventory
  13830. *
  13831. - * @param username
  13832. + * @param playerId
  13833. + * @param playerName
  13834. * @param type
  13835. - * @param plugin
  13836. */
  13837. - public IdpPlayerInventory(String username, InventoryType type) {
  13838. - this.username = username;
  13839. + public IdpPlayerInventory(UUID playerId, String playerName, InventoryType type) {
  13840. + this.playerId = playerId;
  13841. + this.playerName = playerName;
  13842. this.type = type;
  13843. items = new IdpItemStack[DEFAULT_ITEM_SIZE];
  13844. armor = new IdpItemStack[DEFAULT_ARMOR_SIZE];
  13845. @@ -83,14 +89,19 @@ public class IdpPlayerInventory {
  13846. /**
  13847. * Creates a new empty inventory
  13848. *
  13849. - * @param username
  13850. + * @param playerId
  13851. + * @param playerName
  13852. * @param type
  13853. - * @param plugin
  13854. * @param items
  13855. * @param armor
  13856. - */
  13857. - public IdpPlayerInventory(String username, InventoryType type, IdpItemStack[] items, IdpItemStack[] armor, float experience, int level, double health, int hunger) {
  13858. - this.username = username;
  13859. + * @param experience
  13860. + * @param level
  13861. + * @param health
  13862. + * @param hunger
  13863. + */
  13864. + public IdpPlayerInventory(UUID playerId, String playerName, InventoryType type, IdpItemStack[] items, IdpItemStack[] armor, float experience, int level, double health, int hunger) {
  13865. + this.playerId = playerId;
  13866. + this.playerName = playerName;
  13867. this.type = type;
  13868. this.items = new IdpItemStack[DEFAULT_ITEM_SIZE];
  13869. for (int i = 0; i < this.items.length && i < items.length; i++) {
  13870. @@ -238,7 +249,7 @@ public class IdpPlayerInventory {
  13871. public boolean store() {
  13872. // Dont save the none type inventory
  13873. if (type == InventoryType.NONE) {
  13874. - InnPlugin.logError("Trying to store a 'none' inventory for player " + username + " - is player new?");
  13875. + InnPlugin.logError("Trying to store a 'none' inventory for player " + playerName + " - is player new?");
  13876. return true;
  13877. }
  13878.  
  13879. @@ -251,8 +262,8 @@ public class IdpPlayerInventory {
  13880. ResultSet resultset = null;
  13881.  
  13882. try {
  13883. - statement = DBManager.prepareStatement(" SELECT bagid FROM player_inventory where name = ? and inventorytype = ? ");
  13884. - statement.setString(1, username);
  13885. + statement = DBManager.prepareStatement(" SELECT bagid FROM player_inventory where player_id = ? and inventorytype = ? ");
  13886. + statement.setString(1, playerId.toString());
  13887. statement.setInt(2, type.getId());
  13888.  
  13889. long bagid = 0;
  13890. @@ -282,9 +293,9 @@ public class IdpPlayerInventory {
  13891. DBManager.closeResultSet(resultset);
  13892. DBManager.closePreparedStatement(statement);
  13893.  
  13894. - statement = DBManager.prepareStatement(" insert into player_inventory (name, inventorytype, level, experience, bagid, health, hunger, potioneffects) values "
  13895. - + "(?,?,?,?,?,?,?, ?) on duplicate key update level = ?, experience = ?, bagid = ?, health = ?, hunger = ?, potioneffects = ?;");
  13896. - statement.setString(1, username);
  13897. + statement = DBManager.prepareStatement("INSERT INTO player_inventory (player_id, inventorytype, level, experience, bagid, health, hunger, potioneffects) VALUES "
  13898. + + "(?,?,?,?,?,?,?, ?) ON DUPLICATE KEY UPDATE level = ?, experience = ?, bagid = ?, health = ?, hunger = ?, potioneffects = ?;");
  13899. + statement.setString(1, playerId.toString());
  13900. statement.setInt(2, type.getId());
  13901. statement.setInt(3, level);
  13902. statement.setFloat(DEFAULT_ARMOR_SIZE, experience);
  13903. @@ -301,7 +312,7 @@ public class IdpPlayerInventory {
  13904. statement.executeUpdate();
  13905. return true;
  13906. } catch (SQLException ex) {
  13907. - InnPlugin.logError("Failed to store inventory for player " + username, ex);
  13908. + InnPlugin.logError("Failed to store inventory for player " + playerName + "!", ex);
  13909. } finally {
  13910. DBManager.closeResultSet(resultset);
  13911. DBManager.closePreparedStatement(statement);
  13912. @@ -313,9 +324,12 @@ public class IdpPlayerInventory {
  13913. /**
  13914. * Loads the inventory from the database
  13915. *
  13916. + * @param playerCredentials
  13917. * @param type
  13918. + * @param plugin
  13919. + * @return
  13920. */
  13921. - public static IdpPlayerInventory load(String username, InventoryType type, InnPlugin plugin) {
  13922. + public static IdpPlayerInventory load(UUID playerId, String playerName, InventoryType type, InnPlugin plugin) {
  13923. PreparedStatement statement = null;
  13924. ResultSet resultset = null;
  13925.  
  13926. @@ -327,8 +341,8 @@ public class IdpPlayerInventory {
  13927. long bagid = 0;
  13928. String potionEffects = "";
  13929.  
  13930. - statement = DBManager.prepareStatement(" SELECT level, experience, bagid, health, hunger, potioneffects FROM player_inventory WHERE name = ? and inventorytype = ? LIMIT 1 ");
  13931. - statement.setString(1, username);
  13932. + statement = DBManager.prepareStatement("SELECT level, experience, bagid, health, hunger, potioneffects FROM player_inventory WHERE player_id = ? and inventorytype = ? LIMIT 1;");
  13933. + statement.setString(1, playerId.toString());
  13934. statement.setInt(2, type.getId());
  13935. resultset = statement.executeQuery();
  13936.  
  13937. @@ -344,7 +358,7 @@ public class IdpPlayerInventory {
  13938. if (bagid > 0) {
  13939. StackBag bag = StackBag.getContentbag(bagid);
  13940.  
  13941. - IdpPlayerInventory inv = new IdpPlayerInventory(username, type);
  13942. + IdpPlayerInventory inv = new IdpPlayerInventory(playerId, playerName, type);
  13943. inv.experience = exp;
  13944. inv.level = level;
  13945. inv.health = health;
  13946. @@ -359,7 +373,7 @@ public class IdpPlayerInventory {
  13947. }
  13948. }
  13949. } catch (NumberFormatException ex) {
  13950. - InnPlugin.logError("Error loading inventory potion effects of player " + username, ex);
  13951. + InnPlugin.logError("Error loading inventory potion effects of player " + playerName + "!", ex);
  13952. }
  13953.  
  13954. System.arraycopy(itemarr, 0, inv.items, 0, DEFAULT_ITEM_SIZE);
  13955. @@ -368,13 +382,13 @@ public class IdpPlayerInventory {
  13956. return inv;
  13957. }
  13958. } catch (SQLException ex) {
  13959. - InnPlugin.logError("Error getting group of player " + username, ex);
  13960. + InnPlugin.logError("Error getting group of player " + playerName + "!", ex);
  13961. } finally {
  13962. DBManager.closeResultSet(resultset);
  13963. DBManager.closePreparedStatement(statement);
  13964. }
  13965.  
  13966. - return new IdpPlayerInventory(username, type);
  13967. + return new IdpPlayerInventory(playerId, playerName, type);
  13968. }
  13969.  
  13970. /**
  13971. @@ -443,7 +457,7 @@ public class IdpPlayerInventory {
  13972. * Updates bukkit's inventory with this one
  13973. */
  13974. public void updateBukkitInventory() {
  13975. - IdpPlayer idpplayer = InnPlugin.getPlugin().getPlayer(username, false);
  13976. + IdpPlayer idpplayer = InnPlugin.getPlugin().getPlayer(playerId);
  13977.  
  13978. if (idpplayer == null) {
  13979. InnPlugin.logError("Trying to update inventory of offline player.");
  13980. diff --git a/src/net/innectis/innplugin/Player/Infractions/InfractInjector.java b/src/net/innectis/innplugin/Player/Infractions/InfractInjector.java
  13981. index 103d2dad2..a020dbe99 100644
  13982. --- a/src/net/innectis/innplugin/Player/Infractions/InfractInjector.java
  13983. +++ b/src/net/innectis/innplugin/Player/Infractions/InfractInjector.java
  13984. @@ -3,10 +3,14 @@ package net.innectis.innplugin.Player.Infractions;
  13985. import java.util.Calendar;
  13986. import java.util.Date;
  13987. import java.util.TimeZone;
  13988. +import net.innectis.innplugin.Configuration;
  13989. import net.innectis.innplugin.IdpCommandSender;
  13990. +import net.innectis.innplugin.IdpConsole;
  13991. import net.innectis.innplugin.Player.Chat.ChatColor;
  13992. import net.innectis.innplugin.Player.Chat.ChatInjector;
  13993. import net.innectis.innplugin.Player.IdpPlayer;
  13994. +import net.innectis.innplugin.Player.PlayerCredentials;
  13995. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  13996. import net.innectis.innplugin.Utility.StringUtil;
  13997.  
  13998. /**
  13999. @@ -18,37 +22,45 @@ import net.innectis.innplugin.Utility.StringUtil;
  14000. public final class InfractInjector extends ChatInjector {
  14001.  
  14002. public static final String ENTER_CHAR = "\n";
  14003. - private final String player;
  14004. + private final PlayerCredentials playerCredentials;
  14005. private final InfractionIntensity intensity;
  14006. private final String summary;
  14007. private StringBuilder details;
  14008.  
  14009. /**
  14010. * Creates a new infractioninjector with the given details
  14011. - * @param player
  14012. + * @param playerCredentials
  14013. * @param intensity
  14014. * @param summary
  14015. */
  14016. - public InfractInjector(String player, InfractionIntensity intensity, String summary) {
  14017. - this.player = player;
  14018. + public InfractInjector(PlayerCredentials playerCredentials, InfractionIntensity intensity, String summary) {
  14019. + this.playerCredentials = playerCredentials;
  14020. this.intensity = intensity;
  14021. this.summary = summary;
  14022. }
  14023.  
  14024. @Override
  14025. public void onChat(IdpCommandSender sender, String message) {
  14026. -
  14027. // Close the injector and save the infraction
  14028. if (StringUtil.matches(message, "q", "quit", "exit", "save")) {
  14029. Date date = Calendar.getInstance(TimeZone.getTimeZone("GMT")).getTime();
  14030.  
  14031. - Infraction inf = new Infraction(player, intensity, summary, details == null ? null : details.toString(), date, sender.getName());
  14032. + PlayerCredentials credentials = null;
  14033. +
  14034. + // Determine if we should use server generated credentials or player's
  14035. + if (sender instanceof IdpConsole) {
  14036. + credentials = Configuration.SERVER_GENERATED_CREDENTIALS;
  14037. + } else {
  14038. + credentials = PlayerCredentialsManager.getByName(sender.getName());
  14039. + }
  14040. +
  14041. + Infraction inf = new Infraction(playerCredentials, intensity, summary, details == null ? null : details.toString(), date, credentials);
  14042.  
  14043. // Save the infraction and report
  14044. int level = InfractionManager.getManager().saveInfraction(inf);
  14045. if (inf.getId() != Infraction.DEFAULT_ID) {
  14046. sender.printInfo("Infraction #" + inf.getId() + " saved!");
  14047. - sender.printInfo("Player '" + player + "' infraction level: " + level);
  14048. + sender.printInfo("Player '" + playerCredentials.getName() + "' infraction level: " + level);
  14049. } else {
  14050. sender.printError("Could not save infraction!");
  14051. }
  14052. diff --git a/src/net/innectis/innplugin/Player/Infractions/Infraction.java b/src/net/innectis/innplugin/Player/Infractions/Infraction.java
  14053. index 355f30195..c93fe74ee 100644
  14054. --- a/src/net/innectis/innplugin/Player/Infractions/Infraction.java
  14055. +++ b/src/net/innectis/innplugin/Player/Infractions/Infraction.java
  14056. @@ -1,6 +1,8 @@
  14057. package net.innectis.innplugin.Player.Infractions;
  14058.  
  14059. import java.util.Date;
  14060. +import java.util.UUID;
  14061. +import net.innectis.innplugin.Player.PlayerCredentials;
  14062.  
  14063. /**
  14064. *
  14065. @@ -12,20 +14,20 @@ public final class Infraction {
  14066.  
  14067. protected static final int DEFAULT_ID = -1;
  14068. private int id;
  14069. - private final String player;
  14070. + private final PlayerCredentials playerCredentials;
  14071. private final InfractionIntensity intensity;
  14072. private final String summary;
  14073. private final String details;
  14074. private final Date dateGMT;
  14075. - private final String staffmember;
  14076. + private final PlayerCredentials creatorCredentials;
  14077. private final boolean revoked;
  14078. - private final String revoker;
  14079. + private final PlayerCredentials revokerCredentials;
  14080. private final Date revokeDate;
  14081.  
  14082. /**
  14083. * Creates a new infraction with the given details.
  14084. - * @param player
  14085. - * The player this infraction is given to
  14086. + * @param credentials
  14087. + * The credentials of the player this infraction is given to
  14088. * @param intensity
  14089. * The intensity of the infraction
  14090. * @param summary
  14091. @@ -34,45 +36,45 @@ public final class Infraction {
  14092. * Optional list of details about the infraction and further information about the context.
  14093. * @param dateGMT
  14094. * The date in GMT when the infraction was created
  14095. - * @param staffmember
  14096. - * The staffmember that created the infraction or <b>[SERVER]</b> for server generated infractions.
  14097. + * @param creatorCredentials
  14098. + * The creatpr of the infraction or <b>[SERVER]</b> for server generated infractions.
  14099. */
  14100. - public Infraction(String player, InfractionIntensity intensity, String summary, String details, Date dateGMT, String staffmember) {
  14101. + public Infraction(PlayerCredentials credentials, InfractionIntensity intensity, String summary, String details, Date dateGMT, PlayerCredentials creatorCredentials) {
  14102. this.id = DEFAULT_ID;
  14103. - this.player = player;
  14104. + this.playerCredentials = credentials;
  14105. this.intensity = intensity;
  14106. this.summary = summary;
  14107. this.details = details;
  14108. this.dateGMT = dateGMT;
  14109. - this.staffmember = staffmember;
  14110. + this.creatorCredentials = creatorCredentials;
  14111. this.revoked = false;
  14112. - this.revoker = null;
  14113. + this.revokerCredentials = null;
  14114. this.revokeDate = null;
  14115. }
  14116.  
  14117. /**
  14118. * Created a new infraction with all details possible to be given.
  14119. * @param id
  14120. - * @param player
  14121. + * @param credentials
  14122. * @param intensity
  14123. * @param summary
  14124. * @param details
  14125. * @param dateGMT
  14126. - * @param staffmember
  14127. + * @param creatorCredentials
  14128. * @param revoked
  14129. - * @param revoker
  14130. + * @param revokerCredentials
  14131. * @param revokeDate
  14132. */
  14133. - protected Infraction(int id, String player, InfractionIntensity intensity, String summary, String details, Date dateGMT, String staffmember, boolean revoked, String revoker, Date revokeDate) {
  14134. + protected Infraction(int id, PlayerCredentials credentials, InfractionIntensity intensity, String summary, String details, Date dateGMT, PlayerCredentials creatorCredentials, boolean revoked, PlayerCredentials revokerCredentials, Date revokeDate) {
  14135. this.id = id;
  14136. - this.player = player;
  14137. + this.playerCredentials = credentials;
  14138. this.intensity = intensity;
  14139. this.summary = summary;
  14140. this.details = details;
  14141. this.dateGMT = dateGMT;
  14142. - this.staffmember = staffmember;
  14143. + this.creatorCredentials = creatorCredentials;
  14144. this.revoked = revoked;
  14145. - this.revoker = revoker;
  14146. + this.revokerCredentials = revokerCredentials;
  14147. this.revokeDate = revokeDate;
  14148. }
  14149.  
  14150. @@ -94,11 +96,11 @@ public final class Infraction {
  14151. }
  14152.  
  14153. /**
  14154. - * The player to whom the infraction is listed to.
  14155. + * The credentials of the player to whom the infraction is listed to.
  14156. * @return
  14157. */
  14158. - public String getPlayer() {
  14159. - return player;
  14160. + public PlayerCredentials getPlayerCredentials() {
  14161. + return playerCredentials;
  14162. }
  14163.  
  14164. /**
  14165. @@ -118,11 +120,11 @@ public final class Infraction {
  14166. }
  14167.  
  14168. /**
  14169. - * The staffmember that did the infraction.
  14170. + * The credentials of the creator that did the infraction.
  14171. * @return
  14172. */
  14173. - public String getStaffmember() {
  14174. - return staffmember;
  14175. + public PlayerCredentials getCreatorCredentials() {
  14176. + return creatorCredentials;
  14177. }
  14178.  
  14179. /**
  14180. @@ -150,11 +152,11 @@ public final class Infraction {
  14181. }
  14182.  
  14183. /**
  14184. - * The name of the player that has revoked the infraction
  14185. + * The credentials of the player that has revoked the infraction
  14186. * @return
  14187. */
  14188. - public String getRevoker() {
  14189. - return revoker;
  14190. + public PlayerCredentials getRevokerCredentials() {
  14191. + return revokerCredentials;
  14192. }
  14193.  
  14194. /**
  14195. diff --git a/src/net/innectis/innplugin/Player/Infractions/InfractionBan.java b/src/net/innectis/innplugin/Player/Infractions/InfractionBan.java
  14196. index 19c79c111..02b586e70 100644
  14197. --- a/src/net/innectis/innplugin/Player/Infractions/InfractionBan.java
  14198. +++ b/src/net/innectis/innplugin/Player/Infractions/InfractionBan.java
  14199. @@ -4,6 +4,7 @@ import java.util.Date;
  14200. import net.innectis.innplugin.BanSystem.BanHandler;
  14201. import net.innectis.innplugin.BanSystem.BanObject;
  14202. import net.innectis.innplugin.BanSystem.UserBanObject;
  14203. +import net.innectis.innplugin.Configuration;
  14204. import net.innectis.innplugin.InnPlugin;
  14205. import net.innectis.innplugin.Player.Chat.ChatColor;
  14206. import net.innectis.innplugin.Player.IdpPlayer;
  14207. @@ -50,20 +51,20 @@ class InfractionBan {
  14208. * @param infraction the infraction that caused the ban
  14209. */
  14210. public void banPlayer(Infraction infraction) {
  14211. - BanObject obj = BanHandler.getBan(infraction.getPlayer());
  14212. + BanObject obj = BanHandler.getBan(infraction.getPlayerCredentials().getUniqueId());
  14213. // Only ban if not already banned!
  14214. if (obj == null) {
  14215. InnPlugin plugin = InnPlugin.getPlugin();
  14216.  
  14217. // Create the ban
  14218. - obj = new UserBanObject(infraction.getPlayer(), "[SERVER]", DatabaseTools.dateToTimeStamp(new Date()), bantimeSec * 1000, true);
  14219. + obj = new UserBanObject(infraction.getPlayerCredentials(), Configuration.SERVER_GENERATED_CREDENTIALS, DatabaseTools.dateToTimeStamp(new Date()), bantimeSec * 1000, true);
  14220. BanHandler.addBan(obj);
  14221.  
  14222. // Broadcast the ban
  14223. - plugin.broadCastMessage(ChatColor.RED, StringUtil.format(BAN_BROAD_MESSAGE, infraction.getPlayer(), DateUtil.getTimeDifferenceString(bantimeSec)));
  14224. + plugin.broadCastMessage(ChatColor.RED, StringUtil.format(BAN_BROAD_MESSAGE, infraction.getPlayerCredentials().getName(), DateUtil.getTimeDifferenceString(bantimeSec)));
  14225.  
  14226. // Find the player and kick if online
  14227. - IdpPlayer player = plugin.getPlayer(infraction.getPlayer());
  14228. + IdpPlayer player = plugin.getPlayer(infraction.getPlayerCredentials().getUniqueId());
  14229. if (player != null && player.isOnline()) {
  14230. player.getHandle().kickPlayer(StringUtil.format(BAN_KICK_MESSAGE, DateUtil.getTimeDifferenceString(bantimeSec)));
  14231. }
  14232. diff --git a/src/net/innectis/innplugin/Player/Infractions/InfractionManager.java b/src/net/innectis/innplugin/Player/Infractions/InfractionManager.java
  14233. index 2b6d61bc2..54984e949 100644
  14234. --- a/src/net/innectis/innplugin/Player/Infractions/InfractionManager.java
  14235. +++ b/src/net/innectis/innplugin/Player/Infractions/InfractionManager.java
  14236. @@ -8,8 +8,12 @@ import java.util.Calendar;
  14237. import java.util.Collections;
  14238. import java.util.Date;
  14239. import java.util.List;
  14240. +import java.util.UUID;
  14241. +import net.innectis.innplugin.Configuration;
  14242. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  14243. import net.innectis.innplugin.InnPlugin;
  14244. +import net.innectis.innplugin.Player.PlayerCredentials;
  14245. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  14246. import net.innectis.innplugin.Utility.DateUtil;
  14247.  
  14248. /**
  14249. @@ -68,14 +72,14 @@ public class InfractionManager {
  14250. // Save the infraction
  14251. try {
  14252. statement = DBManager.prepareStatementWithAutoGeneratedKeys(
  14253. - "INSERT INTO player_infracts (name, intensity, dateGMT, summary, details, staff)"
  14254. + "INSERT INTO player_infracts (player_id, intensity, dateGMT, summary, details, staff_id)"
  14255. + " VALUES (?,?,?,?,?,?); ");
  14256. - statement.setString(1, infraction.getPlayer());
  14257. + statement.setString(1, infraction.getPlayerCredentials().getUniqueId().toString());
  14258. statement.setInt(2, infraction.getIntensity().getIntensityLevel());
  14259. statement.setLong(3, infraction.getDateGMT().getTime());
  14260. statement.setString(4, infraction.getSummary());
  14261. statement.setString(5, infraction.getDetails());
  14262. - statement.setString(6, infraction.getStaffmember());
  14263. + statement.setString(6, infraction.getCreatorCredentials().getUniqueId().toString());
  14264. statement.execute();
  14265. set = statement.getGeneratedKeys();
  14266.  
  14267. @@ -84,14 +88,15 @@ public class InfractionManager {
  14268. }
  14269.  
  14270. } catch (SQLException ex) {
  14271. - InnPlugin.logError("Could not save infraction for '" + infraction.getPlayer() + "'", ex);
  14272. + InnPlugin.logError("Could not save infraction for '" + infraction.getPlayerCredentials().getName() + "'", ex);
  14273. } finally {
  14274. DBManager.closeResultSet(set);
  14275. DBManager.closePreparedStatement(statement);
  14276. }
  14277.  
  14278. + PlayerCredentials credentials = infraction.getPlayerCredentials();
  14279. // Check if the player needs to be banned
  14280. - int infractionLevel = getInfractionLevel(infraction.getPlayer());
  14281. + int infractionLevel = getInfractionLevel(credentials.getUniqueId(), credentials.getName());
  14282. checkBans(infraction, infractionLevel);
  14283.  
  14284. return infractionLevel;
  14285. @@ -100,11 +105,12 @@ public class InfractionManager {
  14286. /**
  14287. * This will get the infraction level of the player.
  14288. * The level is the sum of the intesity of all recent infractions.
  14289. - * @param player - The name of the player to lookup.
  14290. + * @param playerId - The ID of the player to lookup.
  14291. + * @param playerName - The name of the player to lookup.
  14292. * @return 0 or higher according to the infraction levle of the player. If an error occured -1
  14293. * will be returend instead.
  14294. */
  14295. - public int getInfractionLevel(String player) {
  14296. + public int getInfractionLevel(UUID playerId, String playerName) {
  14297. PreparedStatement statement = null;
  14298. ResultSet set = null;
  14299.  
  14300. @@ -112,8 +118,8 @@ public class InfractionManager {
  14301. Calendar cal = Calendar.getInstance(DateUtil.TIMEZONE_GMT);
  14302. cal.add(Calendar.DAY_OF_WEEK, -INFRACTION_GRACE_DAYS);
  14303.  
  14304. - statement = DBManager.prepareStatement("SELECT sum(intensity) FROM player_infracts WHERE name = ? and dateGMT > ? AND revoker IS NULL");
  14305. - statement.setString(1, player);
  14306. + statement = DBManager.prepareStatement("SELECT sum(intensity) FROM player_infracts WHERE player_id = ? and dateGMT > ? AND revoker_id IS NULL");
  14307. + statement.setString(1, playerId.toString());
  14308. statement.setLong(2, cal.getTimeInMillis());
  14309. set = statement.executeQuery();
  14310.  
  14311. @@ -123,7 +129,7 @@ public class InfractionManager {
  14312. return 0;
  14313. }
  14314. } catch (SQLException ex) {
  14315. - InnPlugin.logError("Could not get infractionlevel for '" + player + "'", ex);
  14316. + InnPlugin.logError("Could not get infractionlevel for '" + playerName + "'", ex);
  14317. } finally {
  14318. DBManager.closeResultSet(set);
  14319. DBManager.closePreparedStatement(statement);
  14320. @@ -164,7 +170,7 @@ public class InfractionManager {
  14321. // Return the updated infraction
  14322. return getInfraction(infraction.getId());
  14323. } catch (SQLException ex) {
  14324. - InnPlugin.logError("Could not save infraction for '" + infraction.getPlayer() + "'", ex);
  14325. + InnPlugin.logError("Could not save infraction for '" + infraction.getPlayerCredentials().getName() + "'", ex);
  14326. } finally {
  14327. DBManager.closePreparedStatement(statement);
  14328. }
  14329. @@ -174,14 +180,14 @@ public class InfractionManager {
  14330.  
  14331. /**
  14332. * This will get a list with the infractions on the given player.
  14333. - * @param player - The player to lookup.
  14334. + * @param credentials - The credentials of the player to lookup.
  14335. * @param all - When true all infractions will be returned instead of the infractions that comply
  14336. * with the INFRACTION_GRACE_DAYS time setting.
  14337. * @return A new list with the infracitons for the given player.
  14338. * If an error occured Collections.EMPTY_LIST will be returned instead. The error itself will be
  14339. * reported to the error logger.
  14340. */
  14341. - public List<Infraction> getInfractions(String player, boolean all) {
  14342. + public List<Infraction> getInfractions(PlayerCredentials credentials, boolean all) {
  14343. PreparedStatement statement = null;
  14344. ResultSet set = null;
  14345.  
  14346. @@ -190,15 +196,15 @@ public class InfractionManager {
  14347. cal.add(Calendar.DAY_OF_WEEK, -INFRACTION_GRACE_DAYS);
  14348.  
  14349. // Construct the SQL
  14350. - String sql = "SELECT id, name, intensity, dateGMT, summary, details, staff, revoker, revokeDateGMT FROM player_infracts ";
  14351. + String sql = "SELECT id, player_id, intensity, dateGMT, summary, details, staff_id, revoker_id, revokeDateGMT FROM player_infracts ";
  14352. if (all) {
  14353. - sql += " WHERE name = ? ";
  14354. + sql += " WHERE player_id = ? ";
  14355. } else {
  14356. - sql += " WHERE name = ? and dateGMT > ? AND revoker IS NULL ";
  14357. + sql += " WHERE player_id = ? and dateGMT > ? AND revoker_id IS NULL ";
  14358. }
  14359.  
  14360. statement = DBManager.prepareStatement(sql);
  14361. - statement.setString(1, player);
  14362. + statement.setString(1, credentials.getUniqueId().toString());
  14363.  
  14364. if (!all) {
  14365. statement.setLong(2, cal.getTimeInMillis());
  14366. @@ -215,7 +221,7 @@ public class InfractionManager {
  14367.  
  14368. return infractions;
  14369. } catch (SQLException ex) {
  14370. - InnPlugin.logError("Could not get infractions for '" + player + "'", ex);
  14371. + InnPlugin.logError("Could not get infractions for '" + credentials.getName() + "'", ex);
  14372. } finally {
  14373. DBManager.closeResultSet(set);
  14374. DBManager.closePreparedStatement(statement);
  14375. @@ -235,8 +241,8 @@ public class InfractionManager {
  14376. ResultSet set = null;
  14377.  
  14378. try {
  14379. - statement = DBManager.prepareStatement("SELECT id, name, intensity, dateGMT, "
  14380. - + " summary, details, staff, revoker, revokeDateGMT FROM player_infracts WHERE id = ? ");
  14381. + statement = DBManager.prepareStatement("SELECT id, player_id, intensity, dateGMT, "
  14382. + + " summary, details, staff_id, revoker_id, revokeDateGMT FROM player_infracts WHERE id = ?;");
  14383. statement.setInt(1, id);
  14384. set = statement.executeQuery();
  14385.  
  14386. @@ -265,17 +271,35 @@ public class InfractionManager {
  14387. private static Infraction infFromCurrentRow(ResultSet set) throws SQLException {
  14388. // Get normal information
  14389. int id = set.getInt("id");
  14390. - String name = set.getString("name");
  14391. +
  14392. + String playerIdString = set.getString("player_id");
  14393. + UUID playerId = UUID.fromString(playerIdString);
  14394. + PlayerCredentials playerCredentials = PlayerCredentialsManager.getByUniqueId(playerId);
  14395. +
  14396. int intensity = set.getInt("intensity");
  14397. String summary = set.getString("summary");
  14398. String details = set.getString("details");
  14399. Date dateGMT = new Date(set.getLong("dateGMT"));
  14400. - String staffmember = set.getString("staff");
  14401. +
  14402. + String staffIdString = set.getString("staff_id");
  14403. + UUID staffId = UUID.fromString(staffIdString);
  14404. + PlayerCredentials staffCredentials = null;
  14405. +
  14406. + if (staffId.equals(Configuration.SERVER_GENERATED_IDENTIFIER)) {
  14407. + staffCredentials = Configuration.SERVER_GENERATED_CREDENTIALS;
  14408. + } else {
  14409. + staffCredentials = PlayerCredentialsManager.getByUniqueId(staffId);
  14410. + }
  14411.  
  14412. // Get revoking details;
  14413. - String revoker = set.getString("revoker");
  14414. + String revokerIdString = set.getString("revoker_id");
  14415. + PlayerCredentials revokerCredentials = null;
  14416. Date revokeDate = null;
  14417. - if (revoker != null) {
  14418. +
  14419. + if (revokerIdString != null) {
  14420. + UUID revokerId = UUID.fromString(revokerIdString);
  14421. + revokerCredentials = PlayerCredentialsManager.getByUniqueId(revokerId);
  14422. +
  14423. revokeDate = new Date(set.getLong("revokeDateGMT"));
  14424. }
  14425.  
  14426. @@ -287,7 +311,7 @@ public class InfractionManager {
  14427. }
  14428. }
  14429.  
  14430. - return new Infraction(id, name, infInt, summary, details, dateGMT, staffmember, revoker != null, revoker, revokeDate);
  14431. + return new Infraction(id, playerCredentials, infInt, summary, details, dateGMT, staffCredentials, revokerCredentials != null, revokerCredentials, revokeDate);
  14432. }
  14433.  
  14434. /**
  14435. diff --git a/src/net/innectis/innplugin/Player/PlayerBackpack.java b/src/net/innectis/innplugin/Player/PlayerBackpack.java
  14436. index faf0112af..4a8436093 100644
  14437. --- a/src/net/innectis/innplugin/Player/PlayerBackpack.java
  14438. +++ b/src/net/innectis/innplugin/Player/PlayerBackpack.java
  14439. @@ -3,6 +3,7 @@ package net.innectis.innplugin.Player;
  14440. import java.sql.PreparedStatement;
  14441. import java.sql.ResultSet;
  14442. import java.sql.SQLException;
  14443. +import java.util.UUID;
  14444. import net.innectis.innplugin.Configuration;
  14445. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  14446. import net.innectis.innplugin.InnPlugin;
  14447. @@ -24,27 +25,35 @@ import net.innectis.innplugin.Items.StackBag;
  14448. public class PlayerBackpack extends IdpContainer {
  14449.  
  14450. private static final int BACKPACK_SIZE = Configuration.BACKPACK_SIZE;
  14451. - private final String owner;
  14452. + private final PlayerCredentials ownerCredentials;
  14453. private long bagid;
  14454.  
  14455. /** Makes an empty backpack */
  14456. - private PlayerBackpack(String owner) {
  14457. + private PlayerBackpack(PlayerCredentials ownerCredentials) {
  14458. super(new IdpItemStack[BACKPACK_SIZE], BACKPACK_SIZE);
  14459. - this.owner = owner;
  14460. + this.ownerCredentials = ownerCredentials;
  14461. }
  14462.  
  14463. - private PlayerBackpack(String owner, long bagid, IdpItemStack[] contents) {
  14464. + private PlayerBackpack(PlayerCredentials ownerCredentials, long bagid, IdpItemStack[] contents) {
  14465. super(contents, BACKPACK_SIZE);
  14466. - this.owner = owner;
  14467. + this.ownerCredentials = ownerCredentials;
  14468. this.bagid = bagid;
  14469. }
  14470.  
  14471. + /**
  14472. + * Gets the credentials of the owner of this backpack
  14473. + * @return
  14474. + */
  14475. + public PlayerCredentials getOwnerCredentials() {
  14476. + return ownerCredentials;
  14477. + }
  14478. +
  14479. /**
  14480. * The name of the player that owns this backpack.
  14481. * @return
  14482. */
  14483. public String getOwner() {
  14484. - return owner;
  14485. + return ownerCredentials.getName();
  14486. }
  14487.  
  14488. /**
  14489. @@ -53,8 +62,9 @@ public class PlayerBackpack extends IdpContainer {
  14490. */
  14491. public void setItems(IdpItemStack[] items) {
  14492. if (items.length > BACKPACK_SIZE) {
  14493. - throw new RuntimeException("Backpack to large!");
  14494. + throw new RuntimeException("Backpack too large!");
  14495. }
  14496. +
  14497. this.items = items;
  14498. }
  14499.  
  14500. @@ -69,13 +79,13 @@ public class PlayerBackpack extends IdpContainer {
  14501. StackBag bag = new StackBag(bagid, getItems());
  14502. bag.save();
  14503.  
  14504. - statement = DBManager.prepareStatement("UPDATE players SET backpack = ? WHERE name = ?");
  14505. + statement = DBManager.prepareStatement("UPDATE players SET backpack = ? WHERE player_id = ?");
  14506. statement.setLong(1, bag.getBagid());
  14507. - statement.setString(2, owner);
  14508. + statement.setString(2, ownerCredentials.getUniqueId().toString());
  14509. statement.execute();
  14510. return true;
  14511. } catch (SQLException ex) {
  14512. - InnPlugin.logError("Unable to save " + owner + "'s backpack!", ex);
  14513. + InnPlugin.logError("Unable to save " + getOwner() + "'s backpack!", ex);
  14514. } finally {
  14515. DBManager.closePreparedStatement(statement);
  14516. }
  14517. @@ -84,36 +94,37 @@ public class PlayerBackpack extends IdpContainer {
  14518. }
  14519.  
  14520. /**
  14521. - * Loads the player's backpack from the database
  14522. - * @param username
  14523. - * The name of the user it should look up
  14524. + * Loads a backpack from the database by the specified player ID
  14525. + * @param playerId
  14526. + * The ID of the player's backpack to load
  14527. * @return The backpack of the player or a new one.
  14528. * If it returns null something went wrong.
  14529. */
  14530. - public static PlayerBackpack loadBackpackFromDB(String username) {
  14531. + public static PlayerBackpack loadBackpackFromDB(UUID playerId, String playerName) {
  14532. PreparedStatement statement = null;
  14533. ResultSet set = null;
  14534.  
  14535. try {
  14536. - statement = DBManager.prepareStatement(" SELECT backpack FROM players WHERE name = ? AND backpack IS NOT NULL ");
  14537. - statement.setString(1, username);
  14538. + statement = DBManager.prepareStatement("SELECT backpack FROM players WHERE player_id = ? AND backpack IS NOT NULL;");
  14539. + statement.setString(1, playerId.toString());
  14540. set = statement.executeQuery();
  14541.  
  14542. + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(playerId, true);
  14543. PlayerBackpack pack = null;
  14544. if (set.next()) {
  14545. long bagid = set.getLong("backpack");
  14546. if (bagid > 0) {
  14547. - pack = new PlayerBackpack(username, bagid, StackBag.getContentbag(bagid).getContents());
  14548. + pack = new PlayerBackpack(credentials, bagid, StackBag.getContentbag(bagid).getContents());
  14549. }
  14550. }
  14551.  
  14552. if (pack == null) {
  14553. - pack = new PlayerBackpack(username);
  14554. + pack = new PlayerBackpack(credentials);
  14555. }
  14556.  
  14557. return pack;
  14558. } catch (SQLException ex) {
  14559. - InnPlugin.logError("Unable to load " + username + "'s backpack!", ex);
  14560. + InnPlugin.logError("Unable to load backpack for player " + playerName + "!", ex);
  14561. } finally {
  14562. DBManager.closeResultSet(set);
  14563. DBManager.closePreparedStatement(statement);
  14564. diff --git a/src/net/innectis/innplugin/Player/PlayerCredentials.java b/src/net/innectis/innplugin/Player/PlayerCredentials.java
  14565. new file mode 100644
  14566. index 000000000..baca3f284
  14567. --- /dev/null
  14568. +++ b/src/net/innectis/innplugin/Player/PlayerCredentials.java
  14569. @@ -0,0 +1,89 @@
  14570. +package net.innectis.innplugin.Player;
  14571. +
  14572. +import java.sql.PreparedStatement;
  14573. +import java.sql.SQLException;
  14574. +import java.util.UUID;
  14575. +import net.innectis.innplugin.Handlers.Datasource.DBManager;
  14576. +import net.innectis.innplugin.InnPlugin;
  14577. +
  14578. +/**
  14579. + * Describes a player, both by name, and by unique ID
  14580. + *
  14581. + * @author AlphaBlend
  14582. + */
  14583. +public class PlayerCredentials {
  14584. + private UUID uniqueId;
  14585. + private String name;
  14586. + private boolean isValidPlayer = false;
  14587. +
  14588. + public PlayerCredentials(UUID uniqueId, String name) {
  14589. + this(uniqueId, name, true);
  14590. + }
  14591. +
  14592. + public PlayerCredentials(UUID uniqueId, String name, boolean isValidPlayer) {
  14593. + this.uniqueId = uniqueId;
  14594. + this.name = name;
  14595. + this.isValidPlayer = isValidPlayer;
  14596. + }
  14597. +
  14598. + /**
  14599. + * Gets the unique ID of this player
  14600. + * @return
  14601. + */
  14602. + public UUID getUniqueId() {
  14603. + return uniqueId;
  14604. + }
  14605. +
  14606. + /**
  14607. + * Gets the name of this player
  14608. + * @return
  14609. + */
  14610. + public String getName() {
  14611. + return name;
  14612. + }
  14613. +
  14614. + /**
  14615. + * Sets the name of this player
  14616. + * @param name
  14617. + */
  14618. + public void setName(String name) {
  14619. + this.name = name;
  14620. + }
  14621. +
  14622. + /**
  14623. + * Gets if these credentials belong to a valid player
  14624. + * @return
  14625. + */
  14626. + public boolean isValidPlayer() {
  14627. + return isValidPlayer;
  14628. + }
  14629. +
  14630. + /**
  14631. + * Updates the player's name in database according to their unique ID
  14632. + */
  14633. + public void update() {
  14634. + PreparedStatement statement = null;
  14635. +
  14636. + try {
  14637. + statement = DBManager.prepareStatement("UPDATE players SET name = ? WHERE player_id = ?;");
  14638. + statement.setString(1, name);
  14639. + statement.setString(2, uniqueId.toString());
  14640. + statement.executeUpdate();
  14641. + } catch (SQLException ex) {
  14642. + InnPlugin.logError("Unable to update player with UUID " + uniqueId + "!", ex);
  14643. + } finally {
  14644. + DBManager.closePreparedStatement(statement);
  14645. + }
  14646. + }
  14647. +
  14648. + @Override
  14649. + public boolean equals(Object obj) {
  14650. + if (!(obj instanceof PlayerCredentials)) {
  14651. + return false;
  14652. + }
  14653. +
  14654. + PlayerCredentials credentials = (PlayerCredentials) obj;
  14655. +
  14656. + return credentials.getUniqueId().equals(uniqueId);
  14657. + }
  14658. +}
  14659. diff --git a/src/net/innectis/innplugin/Player/PlayerCredentialsManager.java b/src/net/innectis/innplugin/Player/PlayerCredentialsManager.java
  14660. new file mode 100644
  14661. index 000000000..0a9b4113e
  14662. --- /dev/null
  14663. +++ b/src/net/innectis/innplugin/Player/PlayerCredentialsManager.java
  14664. @@ -0,0 +1,155 @@
  14665. +package net.innectis.innplugin.Player;
  14666. +
  14667. +import java.sql.PreparedStatement;
  14668. +import java.sql.ResultSet;
  14669. +import java.sql.SQLException;
  14670. +import java.util.ArrayList;
  14671. +import java.util.List;
  14672. +import java.util.UUID;
  14673. +import net.innectis.innplugin.Handlers.Datasource.DBManager;
  14674. +import net.innectis.innplugin.InnPlugin;
  14675. +
  14676. +/**
  14677. + * A manager that keeps track of all the player credentials
  14678. + *
  14679. + * @author AlphaBlend
  14680. + */
  14681. +public class PlayerCredentialsManager {
  14682. + private static List<PlayerCredentials> playerCredentialsList = new ArrayList<PlayerCredentials>();
  14683. +
  14684. + /**
  14685. + * Gets a player credentials object by player name
  14686. + * @param name
  14687. + * @return
  14688. + */
  14689. + public static PlayerCredentials getByName(String name) {
  14690. + return getByName(name, false);
  14691. + }
  14692. +
  14693. + /**
  14694. + * Gets a player credentials object by player name
  14695. + * @param name
  14696. + * @param cacheIfLoaded if true, then if this requires a database query, the
  14697. + * resulting player credentials object will be cached
  14698. + * @return
  14699. + */
  14700. + public static PlayerCredentials getByName(String name, boolean cacheIfLoaded) {
  14701. + for (PlayerCredentials playerCredentials : playerCredentialsList) {
  14702. + if (playerCredentials.getName().equalsIgnoreCase(name)) {
  14703. + return playerCredentials;
  14704. + }
  14705. + }
  14706. +
  14707. + // If we're at this point, then it was not found, so check from database
  14708. + PlayerCredentials playerCredentials = loadFromDatabaseByName(name);
  14709. +
  14710. + if (cacheIfLoaded && playerCredentials != null) {
  14711. + playerCredentialsList.add(playerCredentials);
  14712. + }
  14713. +
  14714. + return playerCredentials;
  14715. + }
  14716. +
  14717. + /**
  14718. + * Gets a player credentials object by unique ID
  14719. + * @param playerId
  14720. + * @return
  14721. + */
  14722. + public static PlayerCredentials getByUniqueId(UUID playerId) {
  14723. + return getByUniqueId(playerId, false);
  14724. + }
  14725. +
  14726. + /**
  14727. + * Gets a player credentials object by unique ID
  14728. + * @param playerId
  14729. + * @param cacheIfLoaded if true, then if this requires a database query, the
  14730. + * resulting player credentials object will be cached
  14731. + * @return
  14732. + */
  14733. + public static PlayerCredentials getByUniqueId(UUID playerId, boolean cacheIfLoaded) {
  14734. + for (PlayerCredentials credentials : playerCredentialsList) {
  14735. + if (credentials.getUniqueId().equals(playerId)) {
  14736. + return credentials;
  14737. + }
  14738. + }
  14739. +
  14740. + // If we're at this point, then it was not found, so check from database
  14741. + PlayerCredentials credentials = loadFromDatabaseByUniqueId(playerId);
  14742. +
  14743. + if (credentials != null && cacheIfLoaded) {
  14744. + playerCredentialsList.add(credentials);
  14745. + }
  14746. +
  14747. + return credentials;
  14748. + }
  14749. +
  14750. + /**
  14751. + * Adds the specified credentials to the list
  14752. + * @param credentials
  14753. + */
  14754. + public static void addCredentialsToCache(PlayerCredentials credentials) {
  14755. + playerCredentialsList.add(credentials);
  14756. + }
  14757. +
  14758. + /**
  14759. + * Loads player's credentials from database by name
  14760. + * @param name
  14761. + * @return
  14762. + */
  14763. + private static PlayerCredentials loadFromDatabaseByName(String playerName) {
  14764. + PreparedStatement statement = null;
  14765. + ResultSet set = null;
  14766. +
  14767. + try {
  14768. + statement = DBManager.prepareStatement("SELECT player_id FROM players WHERE lower(name) = ?;");
  14769. + statement.setString(1, playerName.toLowerCase());
  14770. + set = statement.executeQuery();
  14771. +
  14772. + if (set.next()) {
  14773. + String uuidString = set.getString("player_id");
  14774. + UUID uuid = UUID.fromString(uuidString);
  14775. + PlayerCredentials credentials = new PlayerCredentials(uuid, playerName);
  14776. +
  14777. + return credentials;
  14778. + }
  14779. + } catch (SQLException ex) {
  14780. + InnPlugin.logError("Unable to load player credentials from player name " + playerName + "!", ex);
  14781. + } finally {
  14782. + DBManager.closePreparedStatement(statement);
  14783. + DBManager.closeResultSet(set);
  14784. + }
  14785. +
  14786. + return null;
  14787. + }
  14788. +
  14789. + /**
  14790. + * Loads player's credentials from database by unique ID
  14791. + * @param playerId
  14792. + * @return
  14793. + */
  14794. + private static PlayerCredentials loadFromDatabaseByUniqueId(UUID playerId) {
  14795. + PreparedStatement statement = null;
  14796. + ResultSet set = null;
  14797. +
  14798. + try {
  14799. + statement = DBManager.prepareStatement("SELECT name FROM players WHERE player_id = ?;");
  14800. + statement.setString(1, playerId.toString());
  14801. + set = statement.executeQuery();
  14802. +
  14803. + if (set.next()) {
  14804. + String name = set.getString("name");
  14805. + UUID uuid = UUID.fromString(playerId.toString());
  14806. + PlayerCredentials credentials = new PlayerCredentials(uuid, name);
  14807. +
  14808. + return credentials;
  14809. + }
  14810. + } catch (SQLException ex) {
  14811. + InnPlugin.logError("Unable to load player credentials from player ID " + playerId.toString() + "!", ex);
  14812. + } finally {
  14813. + DBManager.closePreparedStatement(statement);
  14814. + DBManager.closeResultSet(set);
  14815. + }
  14816. +
  14817. + return null;
  14818. + }
  14819. +}
  14820. diff --git a/src/net/innectis/innplugin/Player/PlayerGroup.java b/src/net/innectis/innplugin/Player/PlayerGroup.java
  14821. index 895127dba..2c05fa0ad 100644
  14822. --- a/src/net/innectis/innplugin/Player/PlayerGroup.java
  14823. +++ b/src/net/innectis/innplugin/Player/PlayerGroup.java
  14824. @@ -6,6 +6,7 @@ import java.sql.SQLException;
  14825. import java.util.HashMap;
  14826. import java.util.HashSet;
  14827. import java.util.Set;
  14828. +import java.util.UUID;
  14829. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  14830. import net.innectis.innplugin.InnPlugin;
  14831. import net.innectis.innplugin.Player.Chat.ChatColor;
  14832. @@ -266,20 +267,20 @@ public enum PlayerGroup {
  14833. }
  14834.  
  14835. /**
  14836. - * This method will look in the database for the group of the player with the given name.<br />
  14837. + * This method will look in the database for the group of the player with the given ID.<br />
  14838. * <b>If the player is online dont use this method, but look in their session object.</b>
  14839. * @param playerName
  14840. * @return PlayerGroup or PlayerGroup.NONE if not found
  14841. */
  14842. - public static PlayerGroup getGroupOfUsername(String playerName) {
  14843. + public static PlayerGroup getGroupOfPlayerById(UUID playerId) {
  14844. PlayerGroup group = PlayerGroup.NONE;
  14845.  
  14846. PreparedStatement statement = null;
  14847. ResultSet result = null;
  14848.  
  14849. try {
  14850. - statement = DBManager.prepareStatement("SELECT playergroup FROM players WHERE name = ? LIMIT 1;");
  14851. - statement.setString(1, playerName);
  14852. + statement = DBManager.prepareStatement("SELECT playergroup FROM players WHERE player_id = ?;");
  14853. + statement.setString(1, playerId.toString());
  14854. result = statement.executeQuery();
  14855.  
  14856. if (result.next()) {
  14857. @@ -287,7 +288,7 @@ public enum PlayerGroup {
  14858. group = PlayerGroup.getGroup(groupId);
  14859. }
  14860. } catch (SQLException ex) {
  14861. - InnPlugin.logError("Error getting group of player " + playerName, ex);
  14862. + InnPlugin.logError("Error getting group of player with ID: " + playerId, ex);
  14863. } finally {
  14864. DBManager.closeResultSet(result);
  14865. DBManager.closePreparedStatement(statement);
  14866. diff --git a/src/net/innectis/innplugin/Player/PlayerSecurity.java b/src/net/innectis/innplugin/Player/PlayerSecurity.java
  14867. index 7b6a21f4e..17cc16d96 100644
  14868. --- a/src/net/innectis/innplugin/Player/PlayerSecurity.java
  14869. +++ b/src/net/innectis/innplugin/Player/PlayerSecurity.java
  14870. @@ -10,6 +10,7 @@ import java.text.DecimalFormatSymbols;
  14871. import java.util.Calendar;
  14872. import java.util.Date;
  14873. import java.util.Locale;
  14874. +import java.util.UUID;
  14875. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  14876. import net.innectis.innplugin.Handlers.Iplogging.GeoLocation;
  14877. import net.innectis.innplugin.Handlers.Iplogging.IPAddress;
  14878. @@ -48,7 +49,7 @@ public class PlayerSecurity {
  14879. */
  14880. public static void checkPlayer(IdpPlayer player) {
  14881. String currentip = player.getHandle().getAddress().getAddress().getHostAddress();
  14882. - String lastIp = getLastIp(player.getName());
  14883. + String lastIp = getLastIp(player.getUniqueId(), player.getName());
  14884.  
  14885. // Check if there is a previous ip
  14886. if (lastIp == null) {
  14887. @@ -84,23 +85,22 @@ public class PlayerSecurity {
  14888. InnPlugin.logInfo("Previous IP: " + lastIp + " - " + lastIpGeo.getCity() + " (" + lastIpGeo.getCountryCode() + ")");
  14889. DecimalFormat format = new DecimalFormat("###,###", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
  14890. InnPlugin.logInfo("Distance: " + format.format(distanceKM).replace(",", ".") + " KM");
  14891. -
  14892. }
  14893. }
  14894.  
  14895. /**
  14896. - * This will lookup the IP the player has used <u>before</u> the current one.
  14897. + * This will lookup the IP the player represented by their ID has used <u>before</u> the current one.
  14898. * Meaning that this method will skip the first IP it finds.
  14899. - * @param playername
  14900. + * @param playerId
  14901. * @return the IP used before the current IP, otherwise null
  14902. */
  14903. - private static String getLastIp(String playername) {
  14904. + private static String getLastIp(UUID playerId, String playerName) {
  14905. PreparedStatement statement = null;
  14906. ResultSet result = null;
  14907.  
  14908. try {
  14909. - statement = DBManager.prepareStatement(" SELECT ip, logtime FROM innectis_db.ip_log WHERE name = ? ORDER BY logid DESC LIMIT 2; ");
  14910. - statement.setString(1, playername);
  14911. + statement = DBManager.prepareStatement("SELECT ip, logtime FROM ip_log WHERE player_id = ? ORDER BY logid DESC LIMIT 2;");
  14912. + statement.setString(1, playerId.toString());
  14913. result = statement.executeQuery();
  14914.  
  14915. Calendar cal = Calendar.getInstance();
  14916. @@ -117,7 +117,7 @@ public class PlayerSecurity {
  14917. }
  14918. }
  14919. } catch (SQLException ex) {
  14920. - InnPlugin.logError("Can't get previous IP of player ", ex);
  14921. + InnPlugin.logError("Can't get previous IP of " + playerName + "!", ex);
  14922. } finally {
  14923. DBManager.closeResultSet(result);
  14924. DBManager.closePreparedStatement(statement);
  14925. @@ -128,13 +128,13 @@ public class PlayerSecurity {
  14926.  
  14927. /**
  14928. * This will check the password of a player
  14929. - * @param playername
  14930. - * @param teststring
  14931. + * @param playerId
  14932. + * @param password
  14933. * @return
  14934. */
  14935. - public static boolean checkPlayerPassword(String playername, String teststring) {
  14936. - byte[] inputpass = calculateSecurityHash(playername, teststring, DEFAULT_MULTI);
  14937. - byte[] pass = getPlayerPassword(playername);
  14938. + public static boolean checkPlayerPassword(UUID playerId, String playerName, String password) {
  14939. + byte[] inputpass = calculateSecurityHash(playerId, password, DEFAULT_MULTI);
  14940. + byte[] pass = getPlayerPassword(playerId, playerName);
  14941.  
  14942. if (pass == null || inputpass == null) {
  14943. return false;
  14944. @@ -152,10 +152,9 @@ public class PlayerSecurity {
  14945.  
  14946. /**
  14947. * This will log a bad password for a player
  14948. - * @param playername
  14949. - * @param ip
  14950. + * @param playerId
  14951. */
  14952. - public static boolean canLogin(String playername) {
  14953. + public static boolean canLogin(UUID playerId, String playerName) {
  14954. PreparedStatement statement = null;
  14955. ResultSet set = null;
  14956.  
  14957. @@ -163,11 +162,16 @@ public class PlayerSecurity {
  14958. Calendar cal = Calendar.getInstance();
  14959. cal.add(Calendar.HOUR, -BADLOGIN_HOURSCHECK);
  14960.  
  14961. - statement = DBManager.prepareStatement(" SELECT logid FROM player_failedlogin WHERE logdate > ? AND username = ?");
  14962. + statement = DBManager.prepareStatement("SELECT logid FROM player_failedlogin WHERE logdate > ? AND player_id = ?;");
  14963. statement.setTimestamp(1, new Timestamp(cal.getTimeInMillis()));
  14964. - statement.setString(2, playername);
  14965. + statement.setString(2, playerId.toString());
  14966. set = statement.executeQuery();
  14967.  
  14968. + // No record, player is new, so allow login
  14969. + if (!set.next()) {
  14970. + return true;
  14971. + }
  14972. +
  14973. int counter = 0;
  14974.  
  14975. while (set.next()) {
  14976. @@ -176,7 +180,7 @@ public class PlayerSecurity {
  14977.  
  14978. return counter < BADLOGIN_MAXTIMES;
  14979. } catch (SQLException ex) {
  14980. - InnPlugin.logError("Cannot check if player can login, disallowing player. ", ex);
  14981. + InnPlugin.logError("Cannot check if player " + playerName + " can login, disallowing login.", ex);
  14982. } finally {
  14983. DBManager.closeResultSet(set);
  14984. DBManager.closePreparedStatement(statement);
  14985. @@ -187,22 +191,22 @@ public class PlayerSecurity {
  14986.  
  14987. /**
  14988. * This will check if the player has a password setup.
  14989. - * @param playername
  14990. + * @param playerId
  14991. */
  14992. - public static boolean hasPassword(String playername) {
  14993. + public static boolean hasPassword(UUID playerId, String playerName) {
  14994. PreparedStatement statement = null;
  14995. ResultSet result = null;
  14996.  
  14997. try {
  14998. - statement = DBManager.prepareStatement(" SELECT username FROM player_password WHERE username = ? ");
  14999. - statement.setString(1, playername);
  15000. + statement = DBManager.prepareStatement("SELECT player_id FROM player_password WHERE player_id = ?;");
  15001. + statement.setString(1, playerId.toString());
  15002. result = statement.executeQuery();
  15003.  
  15004. if (result.next()) {
  15005. return true;
  15006. }
  15007. } catch (SQLException ex) {
  15008. - InnPlugin.logError("Error checking for player password... ", ex);
  15009. + InnPlugin.logError("Error checking password for player " + playerName + "!", ex);
  15010. } finally {
  15011. DBManager.closeResultSet(result);
  15012. DBManager.closePreparedStatement(statement);
  15013. @@ -213,10 +217,10 @@ public class PlayerSecurity {
  15014.  
  15015. /**
  15016. * This will log a bad password for a player
  15017. - * @param playername
  15018. - * @param ip
  15019. + * @param playerId
  15020. + * @param password
  15021. */
  15022. - public static boolean setPassword(String playername, String password) {
  15023. + public static boolean setPassword(UUID playerId, String playerName, String password) {
  15024. PreparedStatement statement = null;
  15025.  
  15026. try {
  15027. @@ -224,18 +228,18 @@ public class PlayerSecurity {
  15028. return false;
  15029. }
  15030.  
  15031. - byte[] pass = calculateSecurityHash(playername, password, DEFAULT_MULTI);
  15032. + byte[] pass = calculateSecurityHash(playerId, password, DEFAULT_MULTI);
  15033.  
  15034. - statement = DBManager.prepareStatement(" INSERT INTO player_password (username, password, dateset) "
  15035. + statement = DBManager.prepareStatement(" INSERT INTO player_password (player_id, password, dateset) "
  15036. + " values (?,?, CURRENT_TIMESTAMP) ON DUPLICATE KEY update password = ?, dateset = CURRENT_TIMESTAMP; ");
  15037. - statement.setString(1, playername);
  15038. + statement.setString(1, playerId.toString());
  15039. statement.setBytes(2, pass);
  15040. statement.setBytes(3, pass);
  15041. statement.executeUpdate();
  15042.  
  15043. return true;
  15044. } catch (SQLException ex) {
  15045. - InnPlugin.logError("Error setting player password... ", ex);
  15046. + InnPlugin.logError("Error setting password of " + playerName + "!", ex);
  15047. } finally {
  15048. DBManager.closePreparedStatement(statement);
  15049. }
  15050. @@ -244,21 +248,21 @@ public class PlayerSecurity {
  15051. }
  15052.  
  15053. /**
  15054. - * This will delete the password for the given player
  15055. - * @param playername
  15056. + * This will delete the password by the specified player ID
  15057. + * @param playerId
  15058. * @return true if password was removed
  15059. */
  15060. - public static boolean removePassword(String playername) {
  15061. + public static boolean removePassword(UUID playerId, String playerName) {
  15062. PreparedStatement statement = null;
  15063.  
  15064. try {
  15065. - statement = DBManager.prepareStatement(" DELETE FROM player_password WHERE username = ? ");
  15066. - statement.setString(1, playername);
  15067. -
  15068. + statement = DBManager.prepareStatement("DELETE FROM player_password WHERE player_id = ?;");
  15069. + statement.setString(1, playerId.toString());
  15070. statement.executeUpdate();
  15071. +
  15072. return true;
  15073. } catch (SQLException ex) {
  15074. - InnPlugin.logError("Error removing player password... ", ex);
  15075. + InnPlugin.logError("Error removing password for player " + playerName + "!", ex);
  15076. } finally {
  15077. DBManager.closePreparedStatement(statement);
  15078. }
  15079. @@ -268,20 +272,20 @@ public class PlayerSecurity {
  15080.  
  15081. /**
  15082. * This will log a bad password for a player
  15083. - * @param playername
  15084. + * @param playerId
  15085. * @param ip
  15086. */
  15087. - public static void logBadPassword(String playername, String ip) {
  15088. + public static void logBadPassword(UUID playerId, String playerName, String ip) {
  15089. PreparedStatement statement = null;
  15090.  
  15091. try {
  15092. - statement = DBManager.prepareStatement(" INSERT INTO player_failedlogin (username, ip, logdate) VALUES (?,?,?) ; ");
  15093. - statement.setString(1, playername);
  15094. + statement = DBManager.prepareStatement("INSERT INTO player_failedlogin (player_id, ip, logdate) VALUES (?,?,?);");
  15095. + statement.setString(1, playerId.toString());
  15096. statement.setString(2, ip);
  15097. statement.setTimestamp(3, new Timestamp(new Date().getTime()));
  15098. statement.executeUpdate();
  15099. } catch (SQLException ex) {
  15100. - InnPlugin.logError("Cannot log bad password.. ('" + playername + "', '" + ip + "','" + new Date().getTime() + "') ", ex);
  15101. + InnPlugin.logError("Cannot log bad password! (Player " + playerName + " trying pass with IP of " + ip + " on " + new Date().getTime() + ")", ex);
  15102. } finally {
  15103. DBManager.closePreparedStatement(statement);
  15104. }
  15105. @@ -295,8 +299,11 @@ public class PlayerSecurity {
  15106. * Amount of times the hash must rewrite itself.
  15107. * @return
  15108. */
  15109. - private static byte[] calculateSecurityHash(String salt, String input, int multiplyer) {
  15110. + private static byte[] calculateSecurityHash(UUID playerId, String input, int multiplyer) {
  15111. try {
  15112. + // Add salt using player's name
  15113. + String salt = playerId.toString();
  15114. +
  15115. java.security.MessageDigest messageDigest = java.security.MessageDigest.getInstance("SHA-256");
  15116. messageDigest.update(salt.getBytes());
  15117. byte[] buffer = messageDigest.digest(input.getBytes());
  15118. @@ -306,30 +313,30 @@ public class PlayerSecurity {
  15119. }
  15120. return buffer;
  15121. } catch (NoSuchAlgorithmException ex) {
  15122. - InnPlugin.logError("Error digesting password... ", ex);
  15123. + InnPlugin.logError("Error digesting password for player ID: " + playerId.toString() + "!", ex);
  15124. return null;
  15125. }
  15126. }
  15127.  
  15128. /**
  15129. - * Looks up the encrypted password of the player in the database
  15130. - * @param playername
  15131. + * Looks up the encrypted password based on the player ID
  15132. + * @param playerId
  15133. * @return
  15134. */
  15135. - private static byte[] getPlayerPassword(String playername) {
  15136. + private static byte[] getPlayerPassword(UUID playerId, String playerName) {
  15137. PreparedStatement statement = null;
  15138. ResultSet result = null;
  15139.  
  15140. try {
  15141. - statement = DBManager.prepareStatement(" SELECT password FROM player_password WHERE username = ? ");
  15142. - statement.setString(1, playername);
  15143. + statement = DBManager.prepareStatement("SELECT password FROM player_password WHERE player_id = ?;");
  15144. + statement.setString(1, playerId.toString());
  15145. result = statement.executeQuery();
  15146.  
  15147. if (result.next()) {
  15148. return result.getBytes("password");
  15149. }
  15150. } catch (SQLException ex) {
  15151. - InnPlugin.logError("Error getting player password... ", ex);
  15152. + InnPlugin.logError("Error getting password of " + playerName + "!", ex);
  15153. } finally {
  15154. DBManager.closeResultSet(result);
  15155. DBManager.closePreparedStatement(statement);
  15156. diff --git a/src/net/innectis/innplugin/Player/PlayerSession.java b/src/net/innectis/innplugin/Player/PlayerSession.java
  15157. index 4b848f23f..6e1fb05ab 100644
  15158. --- a/src/net/innectis/innplugin/Player/PlayerSession.java
  15159. +++ b/src/net/innectis/innplugin/Player/PlayerSession.java
  15160. @@ -4,7 +4,6 @@ import java.sql.PreparedStatement;
  15161. import java.sql.ResultSet;
  15162. import java.sql.SQLException;
  15163. import java.util.ArrayList;
  15164. -import java.util.Arrays;
  15165. import java.util.Collections;
  15166. import java.util.Date;
  15167. import java.util.HashMap;
  15168. @@ -14,6 +13,7 @@ import java.util.List;
  15169. import java.util.Map;
  15170. import java.util.Map.Entry;
  15171. import java.util.TimeZone;
  15172. +import java.util.UUID;
  15173. import net.innectis.innplugin.Configuration;
  15174. import net.innectis.innplugin.Handlers.Datasource.DBManager;
  15175. import net.innectis.innplugin.Handlers.Iplogging.Playerinfo;
  15176. @@ -61,31 +61,53 @@ import org.bukkit.util.Vector;
  15177. public class PlayerSession {
  15178.  
  15179. // <editor-fold defaultstate="collapsed" desc="Static methods and objects">
  15180. - private static Map<String, PlayerSession> sessions = Collections.synchronizedMap(new HashMap<String, PlayerSession>());
  15181. + private static Map<UUID, PlayerSession> sessions = Collections.synchronizedMap(new HashMap<UUID, PlayerSession>());
  15182. private static final Object _synclock = new Object();
  15183.  
  15184. /**
  15185. * Checks if there is a session for the player
  15186. *
  15187. - * @param playername
  15188. + * @param playerName
  15189. * @return
  15190. */
  15191. - public static boolean hasSession(String playername) {
  15192. - return sessions.containsKey(playername.toLowerCase());
  15193. + public static boolean hasSession(String playerName) {
  15194. + for (PlayerSession session : sessions.values()) {
  15195. + if (session.getRealName().equalsIgnoreCase(playerName)) {
  15196. + return true;
  15197. + }
  15198. + }
  15199. +
  15200. + return false;
  15201. + }
  15202. +
  15203. + /**
  15204. + * Checks if there is a session for the player by ID
  15205. + *
  15206. + * @param playerName
  15207. + * @return
  15208. + */
  15209. + public static boolean hasSession(UUID playerId) {
  15210. + for (PlayerSession session : sessions.values()) {
  15211. + if (session.getUniqueId().equals(playerId)) {
  15212. + return true;
  15213. + }
  15214. + }
  15215. +
  15216. + return false;
  15217. }
  15218.  
  15219. /**
  15220. * Cleans up expired sessions
  15221. *
  15222. - * @param currentTimeMillis
  15223. + * @param now
  15224. */
  15225. - public static void cleanup(Long now) {
  15226. + public static void cleanup(long now) {
  15227. for (PlayerSession session : getSessions()) {
  15228. if (session.getExpireTime() > 0 && now > session.getExpireTime()) {
  15229. session.destroy();
  15230. } else if (session.getExpireTime() == 0) {
  15231. // Check if session got stuck.
  15232. - if (InnPlugin.getPlugin().getPlayer(session.username) == null) {
  15233. + if (InnPlugin.getPlugin().getPlayer(session.playerName) == null) {
  15234. session.expireSession(5);
  15235. }
  15236. }
  15237. @@ -95,32 +117,81 @@ public class PlayerSession {
  15238. /**
  15239. * Returns an active session. This will be null if the session had
  15240. * already expired.
  15241. - * @param playername
  15242. + * @param uniqueId
  15243. + * @return
  15244. + */
  15245. + public static PlayerSession getActiveSession(UUID uniqueId) {
  15246. + return sessions.get(uniqueId);
  15247. + }
  15248. +
  15249. + /**
  15250. + * Gets a session from the specified player ID
  15251. + * @param playerName
  15252. + * @return
  15253. + */
  15254. + public static PlayerSession getSession_(UUID playerId) {
  15255. + for (PlayerSession session : sessions.values()) {
  15256. + if (session.getUniqueId().equals(playerId)) {
  15257. + return session;
  15258. + }
  15259. + }
  15260. +
  15261. + return null;
  15262. + }
  15263. +
  15264. + /**
  15265. + * Gets a session from the specified player name
  15266. + * @param playerName
  15267. * @return
  15268. */
  15269. - public static PlayerSession getActiveSession(String playername) {
  15270. - return sessions.get(playername.toLowerCase());
  15271. + public static PlayerSession getSession_(String playerName) {
  15272. + for (PlayerSession session : sessions.values()) {
  15273. + if (session.getDisplayName().equalsIgnoreCase(playerName)) {
  15274. + return session;
  15275. + }
  15276. + }
  15277. +
  15278. + return null;
  15279. }
  15280.  
  15281. /**
  15282. - * Retuns the session of the given player. If there is no session for the
  15283. - * player, a new one is created. If the player of the session is not online,
  15284. - * it will expire automaticly in 10 minutes
  15285. + * Retuns the session of the player represented by name and ID.
  15286. + * If there is no session for the player, a new one is created. If the
  15287. + * player of the session is not online, it will expire automaticly in
  15288. + * 10 minutes
  15289. *
  15290. - * @param playername
  15291. + * @param playerId
  15292. + * @param playerName
  15293. * @param server
  15294. * @return session for the given player
  15295. */
  15296. - public static PlayerSession getSession(String playername, InnPlugin server) {
  15297. + public static PlayerSession getSession(UUID playerId, String playerName, InnPlugin server) {
  15298. + return getSession(playerId, playerName, server, false);
  15299. + }
  15300. +
  15301. + /**
  15302. + * Retuns the session of the player represented by name and ID.
  15303. + * If there is no session for the player, a new one is created. If the
  15304. + * player of the session is not online, it will expire automaticly in
  15305. + * 10 minutes
  15306. + *
  15307. + * @param playerId
  15308. + * @param playerName
  15309. + * @param server
  15310. + * @param isFixedName if true, then this name is fixed and does not need to
  15311. + * be updated from the database
  15312. + * @return session for the given player
  15313. + */
  15314. + public static PlayerSession getSession(UUID playerId, String playerName, InnPlugin server, boolean isFixedName) {
  15315. synchronized (_synclock) {
  15316. // Get the session
  15317. - PlayerSession session = sessions.get(playername.toLowerCase());
  15318. + PlayerSession session = sessions.get(playerId);
  15319.  
  15320. if (session != null) {
  15321. // Check if object was about to expire
  15322. if (session.getExpireTime() > 0) {
  15323. // Check if player is still online
  15324. - if (server.getPlayer(playername.toLowerCase(), true) == null) {
  15325. + if (server.getPlayer(playerId) == null) {
  15326. // Reset expire time
  15327. session.expireSession(10);
  15328. } else {
  15329. @@ -130,31 +201,34 @@ public class PlayerSession {
  15330. }
  15331. } else {
  15332. if (InnPlugin.isDebugEnabled()) {
  15333. - InnPlugin.logDebug("Creating new session for " + playername);
  15334. + InnPlugin.logDebug("Creating new session for " + playerName + ".");
  15335. + }
  15336. +
  15337. + // If this name is not fixed (according to the player's chatname setting)
  15338. + // then get the fixed name from the database
  15339. + if (!isFixedName) {
  15340. + String testName = getFixedPlayerName(playerId);
  15341. +
  15342. + // Player might be new, so there is no name in the database yet
  15343. + if (testName != null) {
  15344. + playerName = testName;
  15345. + }
  15346. }
  15347. +
  15348. // Create new session
  15349. - session = new PlayerSession(playername, server);
  15350. + session = new PlayerSession(playerId, playerName, server);
  15351. // Register the session!
  15352. - sessions.put(playername.toLowerCase(), session);
  15353. + sessions.put(playerId, session);
  15354. // Expire session in 10 minutes if player not online
  15355. - if (server.getPlayer(playername.toLowerCase(), true) == null) {
  15356. + if (server.getPlayer(playerId) == null) {
  15357. session.expireSession(10);
  15358. }
  15359. }
  15360. +
  15361. return session;
  15362. }
  15363. }
  15364.  
  15365. - /**
  15366. - * Checks if the player is valid
  15367. - * @param username
  15368. - * @return
  15369. - */
  15370. - public static boolean isValidPlayer(String username) {
  15371. - PlayerGroup group = PlayerGroup.getGroupOfUsername(username);
  15372. - return (group != PlayerGroup.NONE);
  15373. - }
  15374. -
  15375. /**
  15376. * Returns a list with all sessions Note: some session can contain players
  15377. * that are offline!
  15378. @@ -171,27 +245,28 @@ public class PlayerSession {
  15379. * Will do a call to the database to get the fixed name.
  15380. */
  15381. public void refixUsername() {
  15382. - this.username = getFixedUsername(username);
  15383. + this.playerName = getFixedPlayerName(playerId);
  15384. }
  15385.  
  15386. /**
  15387. * Looks up the username from the database.
  15388. *
  15389. - * @param username
  15390. + * @param playerId
  15391. * @return The username as in the database
  15392. */
  15393. - private static String getFixedUsername(String username) {
  15394. + private static String getFixedPlayerName(UUID playerId) {
  15395. + String fixedName = null;
  15396. PreparedStatement statement = null;
  15397. ResultSet set = null;
  15398.  
  15399. try {
  15400. // Check the username for caps
  15401. - statement = DBManager.prepareStatement("SELECT name FROM players WHERE lower(name) = ?");
  15402. - statement.setString(1, username);
  15403. + statement = DBManager.prepareStatement("SELECT name FROM players WHERE player_id = ?");
  15404. + statement.setString(1, playerId.toString());
  15405. set = statement.executeQuery();
  15406.  
  15407. if (set.next()) {
  15408. - username = set.getString("name");
  15409. + fixedName = set.getString("name");
  15410. }
  15411. } catch (SQLException ex) {
  15412. InnPlugin.logError("Cannot get the fixed username from the database.", ex);
  15413. @@ -200,7 +275,7 @@ public class PlayerSession {
  15414. DBManager.closePreparedStatement(statement);
  15415. }
  15416.  
  15417. - return username;
  15418. + return fixedName;
  15419. }
  15420. //</editor-fold>
  15421. //
  15422. @@ -217,10 +292,16 @@ public class PlayerSession {
  15423. }
  15424. //</editor-fold>
  15425. //
  15426. + /**
  15427. + * The ID of the owner of this session
  15428. + */
  15429. + protected UUID playerId;
  15430. +
  15431. /**
  15432. * The playername of the owner of this session
  15433. */
  15434. - protected String username;
  15435. + protected String playerName;
  15436. +
  15437. private InnPlugin server;
  15438. /**
  15439. * The type of inventory the player has
  15440. @@ -228,15 +309,15 @@ public class PlayerSession {
  15441. protected InventoryType invType;
  15442.  
  15443. /**
  15444. - * @param username
  15445. + * @param playerId
  15446. * @param server
  15447. */
  15448. - private PlayerSession(String username, InnPlugin server) {
  15449. + private PlayerSession(UUID playerId, String playerName, InnPlugin server) {
  15450. // Reset session time.
  15451. sessionStart = System.currentTimeMillis();
  15452.  
  15453. - // Get the (fixed) chat name.
  15454. - this.username = getFixedUsername(username);
  15455. + this.playerId = playerId;
  15456. + this.playerName = playerName;
  15457. this.server = server;
  15458.  
  15459. loadSettings();
  15460. @@ -305,8 +386,8 @@ public class PlayerSession {
  15461. // This is not inside a method as it should never be fired for any other reason...
  15462. try {
  15463. // Set the logout time.
  15464. - statement = DBManager.prepareStatement("UPDATE ip_log SET logouttime = CURRENT_TIMESTAMP where name = ? AND logouttime is null order by logtime desc limit 1;");
  15465. - statement.setString(1, username);
  15466. + statement = DBManager.prepareStatement("UPDATE ip_log SET logouttime = CURRENT_TIMESTAMP WHERE player_id = ? AND logouttime IS NULL ORDER BY logtime DESC LIMIT 1;");
  15467. + statement.setString(1, playerId.toString());
  15468. statement.execute();
  15469. } catch (SQLException ex) {
  15470. InnPlugin.logError("SqlException updating logouttime", ex);
  15471. @@ -365,16 +446,30 @@ public class PlayerSession {
  15472. */
  15473. public String getDisplayName() {
  15474. if (spoofObject == null) {
  15475. - return this.username;
  15476. + return playerName;
  15477. }
  15478. +
  15479. return spoofObject.getSpoofName();
  15480. }
  15481.  
  15482. +
  15483. + public void setUsername(String username) {
  15484. + this.playerName = username;
  15485. + }
  15486. +
  15487. + /**
  15488. + * Gets the ID of this player
  15489. + * @return
  15490. + */
  15491. + public UUID getUniqueId() {
  15492. + return playerId;
  15493. + }
  15494. +
  15495. /**
  15496. * Gets the real name of the current player.
  15497. */
  15498. public String getRealName() {
  15499. - return this.username;
  15500. + return this.playerName;
  15501. }
  15502.  
  15503. /**
  15504. @@ -382,7 +477,7 @@ public class PlayerSession {
  15505. */
  15506. public String getColoredDisplayName() {
  15507. if (spoofObject == null) {
  15508. - return this.nameColor + this.username;
  15509. + return this.nameColor + this.playerName;
  15510. }
  15511. return spoofObject.getSpoofNameColor();
  15512. }
  15513. @@ -514,8 +609,8 @@ public class PlayerSession {
  15514. ResultSet result = null;
  15515.  
  15516. try {
  15517. - statement = DBManager.prepareStatement("SELECT onlinetime FROM players WHERE name = ?;");
  15518. - statement.setString(1, username);
  15519. + statement = DBManager.prepareStatement("SELECT onlinetime FROM players WHERE player_id = ?;");
  15520. + statement.setString(1, playerId.toString());
  15521. result = statement.executeQuery();
  15522.  
  15523. if (result.next()) {
  15524. @@ -553,9 +648,9 @@ public class PlayerSession {
  15525. return; //dont increment played time if they're afk
  15526. }
  15527.  
  15528. - statement = DBManager.prepareStatement("update players set onlinetime = ? where name = ?");
  15529. + statement = DBManager.prepareStatement("UPDATE players SET onlinetime = ? WHERE player_id = ?");
  15530. statement.setFloat(1, newvalue);
  15531. - statement.setString(2, username);
  15532. + statement.setString(2, playerId.toString());
  15533. statement.executeUpdate();
  15534.  
  15535. _totalOnlineTime = newvalue;
  15536. @@ -581,9 +676,10 @@ public class PlayerSession {
  15537. PreparedStatement statement = null;
  15538.  
  15539. try {
  15540. - statement = DBManager.prepareStatement("INSERT INTO players (name, playergroup) VALUES (?,?) ON DUPLICATE KEY UPDATE lastlogin = CURRENT_TIMESTAMP");
  15541. - statement.setString(1, username);
  15542. - statement.setInt(2, PlayerGroup.GUEST.id);
  15543. + statement = DBManager.prepareStatement("INSERT INTO players (player_id, name, playergroup) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE lastlogin = CURRENT_TIMESTAMP");
  15544. + statement.setString(1, playerId.toString());
  15545. + statement.setString(2, playerName);
  15546. + statement.setInt(3, PlayerGroup.GUEST.id);
  15547. statement.executeUpdate();
  15548. } catch (SQLException ex) {
  15549. server.logError("SQLException setLastLogin() " + getColoredName() + ChatColor.RED + " " + ex.getMessage());
  15550. @@ -604,8 +700,8 @@ public class PlayerSession {
  15551. ResultSet result = null;
  15552.  
  15553. try {
  15554. - statement = DBManager.prepareStatement("SELECT lastlogin FROM players WHERE name = ? LIMIT 1;");
  15555. - statement.setString(1, username);
  15556. + statement = DBManager.prepareStatement("SELECT lastlogin FROM players WHERE player_id = ? LIMIT 1;");
  15557. + statement.setString(1, playerId.toString());
  15558. result = statement.executeQuery();
  15559.  
  15560. if (result.next()) {
  15561. @@ -636,8 +732,8 @@ public class PlayerSession {
  15562. ResultSet result = null;
  15563.  
  15564. try {
  15565. - statement = DBManager.prepareStatement(" SELECT logouttime FROM ip_log where name = ? and logouttime is not null order by logtime desc LIMIT 1;");
  15566. - statement.setString(1, username);
  15567. + statement = DBManager.prepareStatement(" SELECT logouttime FROM ip_log WHERE player_id = ? AND logouttime IS NOT NULL ORDER BY logtime DESC LIMIT 1;");
  15568. + statement.setString(1, playerId.toString());
  15569. result = statement.executeQuery();
  15570.  
  15571. if (result.next()) {
  15572. @@ -661,7 +757,7 @@ public class PlayerSession {
  15573. * @return
  15574. */
  15575. public Playerinfo getPlayerinfo() {
  15576. - return Playerinfo.findPlayer(username);
  15577. + return Playerinfo.findPlayer(playerId, playerName);
  15578. }
  15579. // </editor-fold>
  15580. //
  15581. @@ -707,7 +803,7 @@ public class PlayerSession {
  15582. public void destroy() {
  15583. synchronized (_synclock) {
  15584. expire();
  15585. - sessions.remove(username.toLowerCase());
  15586. + sessions.remove(playerId);
  15587. }
  15588. }
  15589. // </editor-fold>
  15590. @@ -724,7 +820,7 @@ public class PlayerSession {
  15591. */
  15592. public final PlayerGroup getGroup() {
  15593. if (group == null) {
  15594. - group = PlayerGroup.getGroupOfUsername(username);
  15595. + group = PlayerGroup.getGroupOfPlayerById(playerId);
  15596.  
  15597. // Group not found
  15598. if (group == PlayerGroup.NONE) {
  15599. @@ -742,7 +838,7 @@ public class PlayerSession {
  15600. * @return
  15601. */
  15602. public boolean isValidPlayer() {
  15603. - PlayerGroup tempGroup = PlayerGroup.getGroupOfUsername(username);
  15604. + PlayerGroup tempGroup = PlayerGroup.getGroupOfPlayerById(playerId);
  15605. return (tempGroup != PlayerGroup.NONE);
  15606. }
  15607.  
  15608. @@ -757,9 +853,9 @@ public class PlayerSession {
  15609. PreparedStatement statement = null;
  15610.  
  15611. try {
  15612. - statement = DBManager.prepareStatement("update players set playergroup = ? where name = ?;");
  15613. + statement = DBManager.prepareStatement("UPDATE players set playergroup = ? WHERE player_id = ?;");
  15614. statement.setInt(1, newGroup.id);
  15615. - statement.setString(2, username);
  15616. + statement.setString(2, playerId.toString());
  15617. statement.executeUpdate();
  15618.  
  15619. setGroupWithoutUpdate(newGroup);
  15620. @@ -853,9 +949,9 @@ public class PlayerSession {
  15621. PreparedStatement statement = null;
  15622.  
  15623. try {
  15624. - statement = DBManager.prepareStatement("insert into prefix (name, subid, text, color1, color2) values "
  15625. - + "(?,?,?,?,?) on duplicate key update text = ?, color1 = ?, color2 = ? ;");
  15626. - statement.setString(1, username);
  15627. + statement = DBManager.prepareStatement("INSERT INTO prefix (player_id, subid, text, color1, color2) values "
  15628. + + "(?,?,?,?,?) on duplicate key update text = ?, color1 = ?, color2 = ?;");
  15629. + statement.setString(1, playerId.toString());
  15630. statement.setInt(2, id);
  15631. statement.setString(3, text);
  15632. statement.setString(4, bracketcolor.getCode());
  15633. @@ -884,8 +980,8 @@ public class PlayerSession {
  15634. ResultSet result = null;
  15635.  
  15636. try {
  15637. - statement = DBManager.prepareStatement("SELECT text, color1, color2, subid FROM prefix WHERE name = ? ;");
  15638. - statement.setString(1, username);
  15639. + statement = DBManager.prepareStatement("SELECT text, color1, color2, subid FROM prefix WHERE player_id = ?;");
  15640. + statement.setString(1, playerId.toString());
  15641. result = statement.executeQuery();
  15642.  
  15643. while (result.next()) {
  15644. @@ -941,12 +1037,12 @@ public class PlayerSession {
  15645. * Gets the coloured name of the player
  15646. */
  15647. public String getColoredName() {
  15648. - return nameColor + username;
  15649. + return nameColor + playerName;
  15650. }
  15651.  
  15652. public void setColoredName(ChatColor color, String username) {
  15653. this.nameColor = color;
  15654. - this.username = username;
  15655. + this.playerName = username;
  15656. }
  15657. // </editor-fold>
  15658. //
  15659. @@ -1462,7 +1558,9 @@ public class PlayerSession {
  15660. if (name == null) {
  15661. return;
  15662. }
  15663. - IdpPlayer player = InnPlugin.getPlugin().getPlayer(username, true);
  15664. +
  15665. + IdpPlayer player = InnPlugin.getPlugin().getPlayer(playerId);
  15666. +
  15667. if (player != null) {
  15668. player.getHandle().getHandle().playerConnection.sendIDPPacketPlayOutPlayerInfo(new PacketPlayOutPlayerInfo(name, online, ping));
  15669. }
  15670. @@ -1514,59 +1612,47 @@ public class PlayerSession {
  15671. private long lastDamageTick = 0L;
  15672. private long lastPvPTick = 0L;
  15673. private long pvpImmuneTime = 0L;
  15674. - private Map<String, List<Long>> pvpList = new HashMap<String, List<Long>>();
  15675. + private Map<UUID, List<Long>> pvpList = new HashMap<UUID, List<Long>>();
  15676.  
  15677. /**
  15678. * Adds a kill to the pvp kill list
  15679. *
  15680. - * @param target
  15681. + * @param playerId
  15682. */
  15683. - public void addPvpKill(IdpPlayer target) {
  15684. - String nameLower = target.getName().toLowerCase();
  15685. -
  15686. - if (!pvpList.containsKey(nameLower)) {
  15687. + public void addPvpKill(UUID playerId) {
  15688. + if (!pvpList.containsKey(playerId)) {
  15689. List<Long> pvpTimes = new ArrayList<Long>();
  15690. pvpTimes.add(System.currentTimeMillis());
  15691. - pvpList.put(nameLower, pvpTimes);
  15692. + pvpList.put(playerId, pvpTimes);
  15693. } else {
  15694. - List<Long> pvpTimes = new ArrayList<Long>(pvpList.get(nameLower));
  15695. + List<Long> pvpTimes = new ArrayList<Long>(pvpList.get(playerId));
  15696. pvpTimes.add(System.currentTimeMillis());
  15697. - pvpList.put(nameLower, pvpTimes);
  15698. + pvpList.put(playerId, pvpTimes);
  15699. }
  15700. }
  15701.  
  15702. - /**
  15703. - * Gets the amount of times this player has killed the target player.
  15704. - *
  15705. - * @param target
  15706. - * @return amount of kills
  15707. - */
  15708. - public int getPvpKillTotalOf(IdpPlayer target) {
  15709. - return getPvpKillTotalOf(target.getName());
  15710. - }
  15711. -
  15712. /**
  15713. * Gets the amount of times this player has killed the target player.
  15714. * Kills past the PvP retention time will not be counted.
  15715. *
  15716. - * @param username of the target
  15717. + * @param playerId ID of the player
  15718. * @return amount of kills
  15719. */
  15720. - public int getPvpKillTotalOf(String username) {
  15721. - String nameLower = username.toLowerCase();
  15722. -
  15723. - if (!pvpList.containsKey(nameLower)) {
  15724. + public int getPvpKillTotalOf(UUID playerId) {
  15725. + if (!pvpList.containsKey(playerId)) {
  15726. return 0;
  15727. }
  15728.  
  15729. int count = 0;
  15730. long now = System.currentTimeMillis();
  15731. - ArrayList<Long> pvpTimes = new ArrayList<Long>(pvpList.get(nameLower));
  15732. + ArrayList<Long> pvpTimes = new ArrayList<Long>(pvpList.get(playerId));
  15733. +
  15734. for (long time : pvpTimes) {
  15735. if (now - time < Configuration.PLAYER_PVP_KILL_RETENTION) {
  15736. count++;
  15737. }
  15738. }
  15739. +
  15740. return count;
  15741. }
  15742.  
  15743. @@ -1575,8 +1661,8 @@ public class PlayerSession {
  15744. */
  15745. public void cleanupPvpKills() {
  15746. long time, now = System.currentTimeMillis();
  15747. - for (Iterator<Entry<String, List<Long>>> it = pvpList.entrySet().iterator(); it.hasNext();) {
  15748. - Entry<String, List<Long>> entry = it.next();
  15749. + for (Iterator<Entry<UUID, List<Long>>> it = pvpList.entrySet().iterator(); it.hasNext();) {
  15750. + Entry<UUID, List<Long>> entry = it.next();
  15751.  
  15752. for (Iterator<Long> it2 = entry.getValue().iterator(); it2.hasNext();) {
  15753. time = it2.next();
  15754. @@ -1899,12 +1985,14 @@ public class PlayerSession {
  15755. if (requests == null) {
  15756. requests = new HashMap<Long, Request>(1);
  15757. }
  15758. - String currentRequestPlayer = request.getRequester().getName();
  15759. - IdpPlayer requester;
  15760. +
  15761. + UUID currentRequesterId = request.getRequesterId();
  15762. +
  15763. for (Request req : requests.values()) {
  15764. if (req != null) {
  15765. - requester = req.getRequester();
  15766. - if (requester != null && currentRequestPlayer.equalsIgnoreCase(requester.getName())) {
  15767. + IdpPlayer requester = req.getRequester();
  15768. +
  15769. + if (requester != null && currentRequesterId.equals(requester.getUniqueId())) {
  15770. return false;
  15771. }
  15772. }
  15773. @@ -1916,25 +2004,25 @@ public class PlayerSession {
  15774. //
  15775. // <editor-fold defaultstate="collapsed" desc="Chat">
  15776. // Holds the list of ignored players
  15777. - private List<String> ignoredPlayers = new ArrayList<String>();
  15778. + private List<PlayerCredentials> ignoredPlayers = new ArrayList<PlayerCredentials>();
  15779. private ChatInjector injector = null;
  15780.  
  15781. /**
  15782. * Adds a new player to the ignored list
  15783. *
  15784. - * @param player
  15785. + * @param credentials
  15786. * @return false if the player cannot be ignored
  15787. */
  15788. - public boolean addIgnoredUser(String player) {
  15789. + public boolean addIgnoredUser(PlayerCredentials credentials) {
  15790. PlayerSession session = null;
  15791. boolean isTempSession = false;
  15792.  
  15793. - IdpPlayer p = server.getPlayer(player);
  15794. + IdpPlayer p = server.getPlayer(credentials.getUniqueId());
  15795.  
  15796. if (p != null) {
  15797. session = p.getSession();
  15798. } else {
  15799. - session = PlayerSession.getSession(player, server);
  15800. + session = PlayerSession.getSession(credentials.getUniqueId(), credentials.getName(), server, true);
  15801. isTempSession = true;
  15802. }
  15803.  
  15804. @@ -1947,8 +2035,8 @@ public class PlayerSession {
  15805. return false;
  15806. }
  15807.  
  15808. - ignoredPlayers.add(player);
  15809. - addIgnoredPlayerToDB(player);
  15810. + ignoredPlayers.add(credentials);
  15811. + addIgnoredPlayerToDB(credentials.getUniqueId(), credentials.getName());
  15812.  
  15813. return true;
  15814. }
  15815. @@ -1956,19 +2044,26 @@ public class PlayerSession {
  15816. /**
  15817. * This removes a player from the ignore list lowercase
  15818. *
  15819. - * @param player
  15820. + * @param playerName
  15821. */
  15822. - public void removeIgnoredUser(String player) {
  15823. - for (Iterator<String> it = ignoredPlayers.iterator(); it.hasNext();) {
  15824. - String p = it.next();
  15825. + public void removeIgnoredUser(String playerName) {
  15826. + PlayerCredentials removeCredentials = null;
  15827.  
  15828. - if (p.equalsIgnoreCase(player)) {
  15829. + for (Iterator<PlayerCredentials> it = ignoredPlayers.iterator(); it.hasNext();) {
  15830. + PlayerCredentials credentials = it.next();
  15831. +
  15832. + if (credentials.getName().equalsIgnoreCase(playerName)) {
  15833. + removeCredentials = credentials;
  15834. it.remove();
  15835. break;
  15836. }
  15837. }
  15838.  
  15839. - removeIgnoredPlayerFromDB(player);
  15840. + if (removeCredentials == null) {
  15841. + return;
  15842. + }
  15843. +
  15844. + removeIgnoredPlayerFromDB(removeCredentials);
  15845. }
  15846.  
  15847. /**
  15848. @@ -1980,14 +2075,13 @@ public class PlayerSession {
  15849. }
  15850.  
  15851. /**
  15852. - * Checks if the player is ignored or not. The name is automaticly set to
  15853. - * lowercase
  15854. + * Checks if the player is ignored or not
  15855. *
  15856. - * @param player
  15857. + * @param playerName
  15858. * @return
  15859. */
  15860. - public boolean isIgnored(String player) {
  15861. - IdpPlayer testPlayer = server.getPlayer(player);
  15862. + public boolean isIgnored(String playerName) {
  15863. + IdpPlayer testPlayer = server.getPlayer(playerName);
  15864.  
  15865. // If a staff member is on the ignore list somehow and they have ignore override
  15866. // then return false because they can't be ignored
  15867. @@ -1995,8 +2089,8 @@ public class PlayerSession {
  15868. return false;
  15869. }
  15870.  
  15871. - for (String checkPlayer : ignoredPlayers) {
  15872. - if (checkPlayer.equalsIgnoreCase(player)) {
  15873. + for (PlayerCredentials pc : ignoredPlayers) {
  15874. + if (pc.getName().equalsIgnoreCase(playerName)) {
  15875. return true;
  15876. }
  15877. }
  15878. @@ -2009,29 +2103,35 @@ public class PlayerSession {
  15879. *
  15880. * @return unmodifiable list of ignored players
  15881. */
  15882. - public List<String> getIgnoredPlayers() {
  15883. + public List<PlayerCredentials> getIgnoredPlayers() {
  15884. return Collections.unmodifiableList(ignoredPlayers);
  15885. }
  15886.  
  15887. /**
  15888. * Loads the ignored players from database
  15889. - * @todo: use a separate table for ignored users, this is ugly
  15890. */
  15891. private void loadIgnoredPlayersFromDB() {
  15892. PreparedStatement statement = null;
  15893. ResultSet set = null;
  15894.  
  15895. try {
  15896. - statement = DBManager.prepareStatement("SELECT * FROM players_ignored where lower(player) = ?;");
  15897. - statement.setString(1, username);
  15898. + statement = DBManager.prepareStatement("SELECT * FROM players_ignored where player_id = ?;");
  15899. + statement.setString(1, playerId.toString());
  15900. set = statement.executeQuery();
  15901.  
  15902. while (set.next()) {
  15903. - String ignoredPlayer = set.getString("ignored_player");
  15904. - ignoredPlayers.add(ignoredPlayer);
  15905. + String ignoredPlayerIdString = set.getString("ignored_player_id");
  15906. + UUID ignoredPlayerId = UUID.fromString(ignoredPlayerIdString);
  15907. +
  15908. + if (ignoredPlayerId.equals(Configuration.EVERYONE_IDENTIFIER)) {
  15909. + ignoredPlayers.add(Configuration.EVERYONE_CREDENTIALS);
  15910. + } else {
  15911. + PlayerCredentials ignoredPlayerCredentials = PlayerCredentialsManager.getByUniqueId(ignoredPlayerId, true);
  15912. + ignoredPlayers.add(ignoredPlayerCredentials);
  15913. + }
  15914. }
  15915. } catch (SQLException ex) {
  15916. - InnPlugin.logError("Unable to load ignore list for " + username + "!", ex);
  15917. + InnPlugin.logError("Unable to load ignore list for " + playerName + "!", ex);
  15918. } finally {
  15919. DBManager.closeResultSet(set);
  15920. DBManager.closePreparedStatement(statement);
  15921. @@ -2041,35 +2141,35 @@ public class PlayerSession {
  15922. /**
  15923. * Adds the ignored player to the database
  15924. */
  15925. - private void addIgnoredPlayerToDB(String player) {
  15926. + private void addIgnoredPlayerToDB(UUID ignoredPlayerId, String ignoredPlayerName) {
  15927. PreparedStatement statement = null;
  15928.  
  15929. try {
  15930. - statement = DBManager.prepareStatement("INSERT INTO players_ignored VALUES (?, ?);");
  15931. - statement.setString(1, username);
  15932. - statement.setString(2, player);
  15933. + statement = DBManager.prepareStatement("INSERT INTO players_ignored (player_id, ignored_player_id) VALUES (?, ?);");
  15934. + statement.setString(1, playerId.toString());
  15935. + statement.setString(2, ignoredPlayerId.toString());
  15936. statement.execute();
  15937. } catch (SQLException ex) {
  15938. - InnPlugin.logError("Failed to add ignored player " + player + " for " + username + "!", ex);
  15939. + InnPlugin.logError("Failed to add ignored player " + ignoredPlayerName + " for " + playerName + "!", ex);
  15940. } finally {
  15941. DBManager.closePreparedStatement(statement);
  15942. }
  15943. }
  15944.  
  15945. /**
  15946. - * Removes the ignored player from the database
  15947. + * playerId the ignored player from the database
  15948. * @param player
  15949. */
  15950. - private void removeIgnoredPlayerFromDB(String player) {
  15951. + private void removeIgnoredPlayerFromDB(PlayerCredentials credentials) {
  15952. PreparedStatement statement = null;
  15953.  
  15954. try {
  15955. - statement = DBManager.prepareStatement("DELETE FROM players_ignored WHERE lower(player) = ? AND lower(ignored_player) = ?;");
  15956. - statement.setString(1, username.toLowerCase());
  15957. - statement.setString(2, player.toLowerCase());
  15958. + statement = DBManager.prepareStatement("DELETE FROM players_ignored WHERE player_id = ? AND ignored_player_id = ?;");
  15959. + statement.setString(1, playerId.toString());
  15960. + statement.setString(2, credentials.getUniqueId().toString());
  15961. statement.execute();
  15962. } catch (SQLException ex) {
  15963. - InnPlugin.logError("Could not remove ignored player " + player + " from " + username + "!", ex);
  15964. + InnPlugin.logError("Could not remove ignored player " + credentials.getName() + " from " + playerName + "!", ex);
  15965. } finally {
  15966. DBManager.closePreparedStatement(statement);
  15967. }
  15968. @@ -2082,11 +2182,11 @@ public class PlayerSession {
  15969. PreparedStatement statement = null;
  15970.  
  15971. try {
  15972. - statement = DBManager.prepareStatement("DELETE FROM players_ignored WHERE lower(player) = ?;");
  15973. - statement.setString(1, username.toLowerCase());
  15974. + statement = DBManager.prepareStatement("DELETE FROM players_ignored WHERE player_id = ?;");
  15975. + statement.setString(1, playerId.toString());
  15976. statement.execute();
  15977. } catch (SQLException ex) {
  15978. - InnPlugin.logError("Could not clear all ignored players from " + username + "!", ex);
  15979. + InnPlugin.logError("Could not clear all ignored players from " + playerName + "!", ex);
  15980. } finally {
  15981. DBManager.closePreparedStatement(statement);
  15982. }
  15983. @@ -2252,8 +2352,8 @@ public class PlayerSession {
  15984. ResultSet set = null;
  15985.  
  15986. try {
  15987. - statement = DBManager.prepareStatement("SELECT * FROM channel_members WHERE lower(username) = ?;");
  15988. - statement.setString(1, username.toLowerCase());
  15989. + statement = DBManager.prepareStatement("SELECT * FROM channel_members WHERE player_id = ?;");
  15990. + statement.setString(1, playerId.toString());
  15991. set = statement.executeQuery();
  15992.  
  15993. while (set.next()) {
  15994. @@ -2263,7 +2363,7 @@ public class PlayerSession {
  15995. channels.put(num, name);
  15996. }
  15997. } catch (SQLException ex) {
  15998. - InnPlugin.logError("Unable to load personal channel numbers for " + username + "!", ex);
  15999. + InnPlugin.logError("Unable to load personal channel numbers for " + playerName + "!", ex);
  16000. } finally {
  16001. DBManager.closeResultSet(set);
  16002. DBManager.closePreparedStatement(statement);
  16003. @@ -2278,7 +2378,7 @@ public class PlayerSession {
  16004. public void joinAllChatChannels() {
  16005. for (String channelName : channels.values()) {
  16006. ChatChannel channel = ChatChannelHandler.getChannel(channelName);
  16007. - channel.setMemberStatus(username, true);
  16008. + channel.setMemberStatus(playerName, true);
  16009. channel.sendGeneralMessage(getColoredName() + ChatColor.AQUA + " has joined the channel.");
  16010. }
  16011. }
  16012. @@ -2290,7 +2390,7 @@ public class PlayerSession {
  16013. for (String channelName : channels.values()) {
  16014. ChatChannel channel = ChatChannelHandler.getChannel(channelName, false);
  16015. channel.sendGeneralMessage(getColoredName() + ChatColor.AQUA + " has left the channel.");
  16016. - channel.setMemberStatus(username, false);
  16017. + channel.setMemberStatus(playerName, false);
  16018.  
  16019. if (channel.isAllOffline()) {
  16020. ChatChannelHandler.unloadChannel(channelName);
  16021. @@ -2388,7 +2488,7 @@ public class PlayerSession {
  16022. */
  16023. public IdpEditSession getEditSession() {
  16024. if (_editsession == null) {
  16025. - _editsession = new IdpEditSession(username);
  16026. + _editsession = new IdpEditSession(playerId);
  16027. }
  16028. return _editsession;
  16029. }
  16030. @@ -2584,8 +2684,10 @@ public class PlayerSession {
  16031. //<editor-fold defaultstate="collapsed" desc="Ender Chest Editing">
  16032. /**
  16033. * These are necessary to keep track of ender chest edits
  16034. - */
  16035. + */
  16036. +
  16037. private String enderchestOwner = null;
  16038. + private UUID enderchestOwnerId = null;
  16039. private EnderContentsType enderchestType = null;
  16040. private boolean isViewingEnderChest = false;
  16041.  
  16042. @@ -2606,8 +2708,7 @@ public class PlayerSession {
  16043. }
  16044.  
  16045. /**
  16046. - * Sets the owner of the ender chest being viewed
  16047. - *
  16048. + * Sets the owner of the enderchest being viewed
  16049. * @param enderchestOwner
  16050. */
  16051. public void setEnderchestOwner(String enderchestOwner) {
  16052. @@ -2615,14 +2716,31 @@ public class PlayerSession {
  16053. }
  16054.  
  16055. /**
  16056. - * Gets the owner of the ender chest being viewed
  16057. + * Sets the ID of the owner of the ender chest being viewed
  16058. *
  16059. + * @param enderchestOwnerId
  16060. + */
  16061. + public void setEnderchestOwnerId(UUID enderchestOwnerId) {
  16062. + this.enderchestOwnerId = enderchestOwnerId;
  16063. + }
  16064. +
  16065. + /**
  16066. + * Gets the owner of the enderchest being viewed
  16067. * @return
  16068. */
  16069. public String getEnderchestOwner() {
  16070. return enderchestOwner;
  16071. }
  16072.  
  16073. + /**
  16074. + * Gets the ID of the ender chest being viewed
  16075. + *
  16076. + * @return
  16077. + */
  16078. + public UUID getEnderchestOwnerId() {
  16079. + return enderchestOwnerId;
  16080. + }
  16081. +
  16082. /**
  16083. * Sets the chest type of the ender chest being viewed
  16084. *
  16085. @@ -2715,7 +2833,7 @@ public class PlayerSession {
  16086. home.setLocation(loc);
  16087. update = true;
  16088. } else {
  16089. - home = new IdpHome(username, homeNum, homeName, loc);
  16090. + home = new IdpHome(playerId, homeNum, homeName, loc);
  16091. homes.put(homeNum, home);
  16092. }
  16093. home.save();
  16094. @@ -2867,8 +2985,8 @@ public class PlayerSession {
  16095. ResultSet set = null;
  16096.  
  16097. try {
  16098. - statement = DBManager.prepareStatement("SELECT * FROM homes WHERE lower(username) = ? ORDER BY homeid ASC");
  16099. - statement.setString(1, username.toLowerCase());
  16100. + statement = DBManager.prepareStatement("SELECT * FROM homes WHERE player_id = ? ORDER BY homeid ASC");
  16101. + statement.setString(1, playerId.toString());
  16102. set = statement.executeQuery();
  16103.  
  16104. while (set.next()) {
  16105. @@ -2884,10 +3002,10 @@ public class PlayerSession {
  16106. float yaw = set.getInt("yaw");
  16107.  
  16108. Location location = new Location(world, x, y, z, yaw, 0);
  16109. - IdpHome home = new IdpHome(UID, username, homeId, (homeName != null ? homeName : ""), location);
  16110. + IdpHome home = new IdpHome(UID, playerId, homeId, (homeName != null ? homeName : ""), location);
  16111.  
  16112. if (world == null || homes.containsKey(homeId)) {
  16113. - InnPlugin.logError("Error while loading home " + homeId + " for " + username + "!");
  16114. + InnPlugin.logError("Error while loading home " + homeId + " for " + playerName + "!");
  16115. home.delete();
  16116.  
  16117. if (world == null) {
  16118. @@ -2896,14 +3014,15 @@ public class PlayerSession {
  16119. InnPlugin.logError("The home ID " + homeId + " is a duplicate!");
  16120. }
  16121.  
  16122. - MailMessage msg = new MailMessage(new Date(), "Auto Message", username, "Invalid Home", "A home in " + worldName + " (" + x + ", " + y + ", " + z + ") was removed.");
  16123. + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(playerId, true);
  16124. + MailMessage msg = new MailMessage(new Date(), Configuration.SERVER_GENERATED_CREDENTIALS, credentials, "Invalid Home", "A home in " + worldName + " (" + x + ", " + y + ", " + z + ") was removed.");
  16125. msg.save();
  16126. } else {
  16127. homes.put(homeId, home);
  16128. }
  16129. }
  16130. } catch (SQLException ex) {
  16131. - InnPlugin.logError("Unable to load homes for " + username + "!", ex);
  16132. + InnPlugin.logError("Unable to load homes for " + playerName + "!", ex);
  16133. } finally {
  16134. DBManager.closeResultSet(set);
  16135. DBManager.closePreparedStatement(statement);
  16136. @@ -3029,7 +3148,7 @@ public class PlayerSession {
  16137. */
  16138. public PlayerBackpack getBackpack() {
  16139. if (backpack == null) {
  16140. - backpack = PlayerBackpack.loadBackpackFromDB(username);
  16141. + backpack = PlayerBackpack.loadBackpackFromDB(playerId, playerName);
  16142.  
  16143. if (backpack == null) {
  16144. throw new RuntimeException("Cannot load backpack!");
  16145. @@ -3049,7 +3168,7 @@ public class PlayerSession {
  16146. */
  16147. public final ModifiablePermissions getModifiablePermissions() {
  16148. if (modifiablePermissions == null) {
  16149. - modifiablePermissions = ModifiablePermissionsHandler.loadModifiedPermissions(username);
  16150. + modifiablePermissions = ModifiablePermissionsHandler.loadModifiedPermissions(playerId);
  16151. }
  16152.  
  16153. return modifiablePermissions;
  16154. @@ -3185,15 +3304,15 @@ public class PlayerSession {
  16155. ResultSet set = null;
  16156.  
  16157. try {
  16158. - statement = DBManager.prepareStatement("SELECT timezone FROM players WHERE name = ?");
  16159. - statement.setString(1, username);
  16160. + statement = DBManager.prepareStatement("SELECT timezone FROM players WHERE player_id = ?");
  16161. + statement.setString(1, playerId.toString());
  16162. set = statement.executeQuery();
  16163.  
  16164. if (set.next() && set.getString("timezone") != null) {
  16165. timezone = TimeZone.getTimeZone(set.getString("timezone"));
  16166. }
  16167. } catch (SQLException ex) {
  16168. - InnPlugin.logError("Could not load player " + username + " timezone!", ex);
  16169. + InnPlugin.logError("Could not load player " + playerName + " timezone!", ex);
  16170. } finally {
  16171. DBManager.closeResultSet(set);
  16172. DBManager.closePreparedStatement(statement);
  16173. @@ -3216,14 +3335,14 @@ public class PlayerSession {
  16174. PreparedStatement statement = null;
  16175.  
  16176. try {
  16177. - statement = DBManager.prepareStatement("UPDATE players SET timezone = ? WHERE name = ?");
  16178. + statement = DBManager.prepareStatement("UPDATE players SET timezone = ? WHERE player_id = ?");
  16179. statement.setString(1, newZone.getID());
  16180. - statement.setString(2, username);
  16181. + statement.setString(2, playerId.toString());
  16182. statement.executeUpdate();
  16183.  
  16184. this.timezone = newZone;
  16185. } catch (SQLException ex) {
  16186. - InnPlugin.logError("Failed to save timezone for " + username + "!", ex);
  16187. + InnPlugin.logError("Failed to save timezone for " + playerName + "!", ex);
  16188. } finally {
  16189. DBManager.closePreparedStatement(statement);
  16190. }
  16191. @@ -3237,15 +3356,15 @@ public class PlayerSession {
  16192. ResultSet set = null;
  16193.  
  16194. try {
  16195. - statement = DBManager.prepareStatement("SELECT settings FROM players WHERE name = ?");
  16196. - statement.setString(1, username);
  16197. + statement = DBManager.prepareStatement("SELECT settings FROM players WHERE player_id = ?");
  16198. + statement.setString(1, playerId.toString());
  16199. set = statement.executeQuery();
  16200.  
  16201. if (set.next()) {
  16202. settingfield = set.getLong("settings");
  16203. }
  16204. } catch (SQLException ex) {
  16205. - InnPlugin.logError("Unable to load settings for " + username + "1", ex);
  16206. + InnPlugin.logError("Unable to load settings for " + playerName + "1", ex);
  16207. } finally {
  16208. DBManager.closeResultSet(set);
  16209. DBManager.closePreparedStatement(statement);
  16210. @@ -3259,12 +3378,12 @@ public class PlayerSession {
  16211. PreparedStatement statement = null;
  16212.  
  16213. try {
  16214. - statement = DBManager.prepareStatement("UPDATE players SET settings = ? WHERE name = ?");
  16215. + statement = DBManager.prepareStatement("UPDATE players SET settings = ? WHERE player_id = ?");
  16216. statement.setLong(1, settingfield);
  16217. - statement.setString(2, username);
  16218. + statement.setString(2, playerId.toString());
  16219. statement.executeUpdate();
  16220. } catch (SQLException ex) {
  16221. - InnPlugin.logError("Failed to save settings for " + username + "!", ex);
  16222. + InnPlugin.logError("Failed to save settings for " + playerName + "!", ex);
  16223. } finally {
  16224. DBManager.closePreparedStatement(statement);
  16225. }
  16226. @@ -3568,7 +3687,7 @@ public class PlayerSession {
  16227. for (IdpPlayer targetPlayer : InnPlugin.getPlugin().getOnlinePlayers()) {
  16228. IdpPlayer targetSpectatingPlayer = targetPlayer.getSession().getSpectating();
  16229. if (targetSpectatingPlayer != null) {
  16230. - if (targetSpectatingPlayer.getName().equalsIgnoreCase(username)) {
  16231. + if (targetSpectatingPlayer.getName().equalsIgnoreCase(playerName)) {
  16232. playerList.add(targetPlayer);
  16233. }
  16234. }
  16235. @@ -3630,20 +3749,31 @@ public class PlayerSession {
  16236. //</editor-fold>
  16237. //
  16238. //<editor-fold defaultstate="collapsed" desc="Inventory Viewing">
  16239. + private UUID viewedInventoryOwnerId;
  16240. private String viewedInventoryOwner;
  16241. private InventoryType viewedInventoryType;
  16242.  
  16243. /**
  16244. * Sets the inventory owner
  16245. - * @param inventoryOwner
  16246. + * @param viewedInventoryOwnerId
  16247. + * @param viewedInventoryType
  16248. */
  16249. - public void setInventoryView(String inventoryOwner, InventoryType viewedInventoryType) {
  16250. - this.viewedInventoryOwner = inventoryOwner;
  16251. + public void setInventoryView(UUID viewedInventoryOwnerId, String viewedInventoryOwner, InventoryType viewedInventoryType) {
  16252. + this.viewedInventoryOwnerId = viewedInventoryOwnerId;
  16253. + this.viewedInventoryOwner = viewedInventoryOwner;
  16254. this.viewedInventoryType = viewedInventoryType;
  16255. }
  16256.  
  16257. /**
  16258. - * Gets the inventory owner
  16259. + * Gets the ID of the inventory owner
  16260. + * @return
  16261. + */
  16262. + public UUID getViewedInventoryOwnerId() {
  16263. + return viewedInventoryOwnerId;
  16264. + }
  16265. +
  16266. + /**
  16267. + * Gets the owner of the inventory being viewed
  16268. * @return
  16269. */
  16270. public String getViewedInventoryOwner() {
  16271. @@ -3662,6 +3792,7 @@ public class PlayerSession {
  16272. * Clears the viewed inventory data
  16273. */
  16274. public void clearViewedInventory() {
  16275. + viewedInventoryOwnerId = null;
  16276. viewedInventoryOwner = null;
  16277. viewedInventoryType = null;
  16278. }
  16279. @@ -3671,23 +3802,40 @@ public class PlayerSession {
  16280. * @return
  16281. */
  16282. public boolean isViewingOtherInventory() {
  16283. - return !(viewedInventoryOwner == null || viewedInventoryOwner.isEmpty());
  16284. + return (viewedInventoryOwnerId != null);
  16285. }
  16286. //</editor-fold>
  16287. //
  16288. //<editor-fold defaultstate="collapsed" desc="Backpack viewing">
  16289. - String backpackOwner = null;
  16290. + private UUID backpackOwnerId = null;
  16291. + private String backpackOwner = null;
  16292.  
  16293. /**
  16294. * Checks if the player is viewing a backpack
  16295. * @return
  16296. */
  16297. public boolean isViewingBackpack() {
  16298. - return (backpackOwner != null);
  16299. + return (backpackOwnerId != null);
  16300. }
  16301.  
  16302. /**
  16303. - * Gets the owner of the backpack being viewed
  16304. + * Gets the player ID of the backpack being owned
  16305. + * @return
  16306. + */
  16307. + public UUID getBackpackOwnerId() {
  16308. + return backpackOwnerId;
  16309. + }
  16310. +
  16311. + /**
  16312. + * Sets the owner of the backpack being viewed
  16313. + * @param backpackOwnerId
  16314. + */
  16315. + public void setBackpackOwnerId(UUID backpackOwnerId) {
  16316. + this.backpackOwnerId = backpackOwnerId;
  16317. + }
  16318. +
  16319. + /**
  16320. + * Gets the owner of this backpack
  16321. * @return
  16322. */
  16323. public String getBackpackOwner() {
  16324. @@ -3695,7 +3843,7 @@ public class PlayerSession {
  16325. }
  16326.  
  16327. /**
  16328. - * Sets the owner of the backpack being viewed
  16329. + * Sets the owner of this backpack
  16330. * @param backpackOwner
  16331. */
  16332. public void setBackpackOwner(String backpackOwner) {
  16333. @@ -3706,6 +3854,7 @@ public class PlayerSession {
  16334. * Clears the owner of the backpack being viewed
  16335. */
  16336. public void clearBackpackOwner() {
  16337. + backpackOwnerId = null;
  16338. backpackOwner = null;
  16339. }
  16340. //</editor-fold>
  16341. @@ -3800,8 +3949,8 @@ public class PlayerSession {
  16342. ResultSet set = null;
  16343.  
  16344. try {
  16345. - statement = DBManager.prepareStatement("SELECT personalid FROM lot_respawns WHERE lower(name) = ?;");
  16346. - statement.setString(1, username.toLowerCase());
  16347. + statement = DBManager.prepareStatement("SELECT personalid FROM lot_respawns WHERE player_id = ?;");
  16348. + statement.setString(1, playerId.toString());
  16349. set = statement.executeQuery();
  16350.  
  16351. if (set.next()) {
  16352. @@ -3822,8 +3971,8 @@ public class PlayerSession {
  16353. PreparedStatement statement = null;
  16354.  
  16355. try {
  16356. - statement = DBManager.prepareStatement("DELETE FROM lot_respawns WHERE lower(name) = ?;");
  16357. - statement.setString(1, username.toLowerCase());
  16358. + statement = DBManager.prepareStatement("DELETE FROM lot_respawns WHERE player_id = ?;");
  16359. + statement.setString(1, playerId.toString());
  16360. statement.execute();
  16361. } catch (SQLException ex) {
  16362. InnPlugin.logError("Unable to delete respawn lot personal id from database!", ex);
  16363. @@ -3841,13 +3990,13 @@ public class PlayerSession {
  16364. PreparedStatement statement = null;
  16365.  
  16366. try {
  16367. - statement = DBManager.prepareStatement("DELETE FROM lot_respawns WHERE lower(name) = ?;");
  16368. - statement.setString(1, username.toLowerCase());
  16369. + statement = DBManager.prepareStatement("DELETE FROM lot_respawns WHERE player_id = ?;");
  16370. + statement.setString(1, playerId.toString());
  16371. statement.execute();
  16372. DBManager.closePreparedStatement(statement);
  16373.  
  16374. - statement = DBManager.prepareStatement("INSERT INTO lot_respawns VALUES (?, ?);");
  16375. - statement.setString(1, username.toLowerCase());
  16376. + statement = DBManager.prepareStatement("INSERT INTO lot_respawns (player_id, personalid) VALUES (?, ?);");
  16377. + statement.setString(1, playerId.toString());
  16378. statement.setInt(2, respawnLotPersonalId);
  16379. statement.execute();
  16380. } catch (SQLException ex) {
  16381. diff --git a/src/net/innectis/innplugin/Player/Request/Request.java b/src/net/innectis/innplugin/Player/Request/Request.java
  16382. index a1d625d9d..0729e9dc6 100644
  16383. --- a/src/net/innectis/innplugin/Player/Request/Request.java
  16384. +++ b/src/net/innectis/innplugin/Player/Request/Request.java
  16385. @@ -1,7 +1,9 @@
  16386. package net.innectis.innplugin.Player.Request;
  16387.  
  16388. +import java.util.UUID;
  16389. import net.innectis.innplugin.InnPlugin;
  16390. import net.innectis.innplugin.Player.IdpPlayer;
  16391. +import net.innectis.innplugin.Player.PlayerCredentials;
  16392. import net.innectis.innplugin.Player.PlayerSession;
  16393. import net.innectis.innplugin.Tasking.LimitedTask;
  16394. import net.innectis.innplugin.Tasking.RunBehaviour;
  16395. @@ -22,10 +24,14 @@ public abstract class Request {
  16396. protected final Long timeouttime;
  16397. /** The plugin */
  16398. protected final InnPlugin plugin;
  16399. - /** The player that can accept or deny this request */
  16400. + /** The ID of the player */
  16401. + protected final UUID playerId;
  16402. + /** The name of the player */
  16403. protected final String player;
  16404. /** The player that made the request */
  16405. protected final String requester;
  16406. + /** The ID of the requester */
  16407. + protected final UUID requesterId;
  16408. /** The ID of the linked delayed task */
  16409. private long taskid;
  16410.  
  16411. @@ -37,7 +43,9 @@ public abstract class Request {
  16412. this.timeouttime = currentTime + timeout;
  16413. this.plugin = plugin;
  16414. this.player = player.getName();
  16415. + this.playerId = player.getUniqueId();
  16416. this.requester = requester.getName();
  16417. + this.requesterId = requester.getUniqueId();
  16418. this.requestid = generateRequestId();
  16419. startTimeoutTask(timeout);
  16420. }
  16421. @@ -50,6 +58,14 @@ public abstract class Request {
  16422. return plugin.getPlayer(player, true);
  16423. }
  16424.  
  16425. + /**
  16426. + * Gets the ID of the player
  16427. + * @return
  16428. + */
  16429. + public UUID getPlayerId() {
  16430. + return playerId;
  16431. + }
  16432. +
  16433. /**
  16434. * Gets the name of the player who issued the request (uncoloured)
  16435. * @return
  16436. @@ -58,11 +74,19 @@ public abstract class Request {
  16437. return plugin.getPlayer(requester, true);
  16438. }
  16439.  
  16440. + /**
  16441. + * Gets the ID of the requester
  16442. + * @return
  16443. + */
  16444. + public UUID getRequesterId() {
  16445. + return requesterId;
  16446. + }
  16447. +
  16448. /**
  16449. * Starts a task to timeout the request.
  16450. */
  16451. private void startTimeoutTask(Long timeout) {
  16452. - taskid = plugin.getTaskManager().addTask(new RequestTask(timeout, plugin, player, requestid));
  16453. + taskid = plugin.getTaskManager().addTask(new RequestTask(timeout, plugin, playerId, requestid));
  16454. }
  16455.  
  16456. /** Returns the request id */
  16457. @@ -142,14 +166,13 @@ public abstract class Request {
  16458. }
  16459.  
  16460. class RequestTask extends LimitedTask {
  16461. -
  16462. private long requestid;
  16463. private InnPlugin plugin;
  16464. - private String playername;
  16465. + private UUID playerId;
  16466.  
  16467. - public RequestTask(long delay, InnPlugin plugin, String playername, long requestid) {
  16468. + public RequestTask(long delay, InnPlugin plugin, UUID playerId, long requestid) {
  16469. super(RunBehaviour.ASYNC, delay, 1);
  16470. - this.playername = playername;
  16471. + this.playerId = playerId;
  16472. this.plugin = plugin;
  16473. this.requestid = requestid;
  16474. }
  16475. @@ -160,9 +183,10 @@ class RequestTask extends LimitedTask {
  16476. }
  16477.  
  16478. public void run() {
  16479. - if (PlayerSession.hasSession(playername)) {
  16480. - PlayerSession session = PlayerSession.getSession(playername, plugin);
  16481. + if (PlayerSession.hasSession(playerId)) {
  16482. + PlayerSession session = PlayerSession.getSession_(playerId);
  16483. Request req = session.removeRequest(requestid);
  16484. +
  16485. if (req != null) {
  16486. req.onTimeout();
  16487. }
  16488. diff --git a/src/net/innectis/innplugin/Player/Request/TeleportRequest.java b/src/net/innectis/innplugin/Player/Request/TeleportRequest.java
  16489. index 0a283dc69..bfae3a89e 100644
  16490. --- a/src/net/innectis/innplugin/Player/Request/TeleportRequest.java
  16491. +++ b/src/net/innectis/innplugin/Player/Request/TeleportRequest.java
  16492. @@ -76,7 +76,7 @@ public class TeleportRequest extends Request {
  16493. }
  16494.  
  16495. if (tpCost > 0) {
  16496. - TransactionObject transaction = TransactionHandler.getTransactionObject(locRequester.getName());
  16497. + TransactionObject transaction = TransactionHandler.getTransactionObject(locRequester.getUniqueId(), locRequester.getName());
  16498. int balance = transaction.getValue(TransactionType.VALUTAS);
  16499.  
  16500. if (balance < tpCost) {
  16501. @@ -106,7 +106,7 @@ public class TeleportRequest extends Request {
  16502. } else {
  16503. // Give back what was taken from the player previously
  16504. if (tpCost > 0) {
  16505. - TransactionObject transaction = TransactionHandler.getTransactionObject(locRequester.getName());
  16506. + TransactionObject transaction = TransactionHandler.getTransactionObject(locRequester.getUniqueId(), locRequester.getName());
  16507. transaction.addValue(tpCost, TransactionType.VALUTAS);
  16508. locPlayer.printError("You are unable to accept the " + getDiscription());
  16509. locRequester.printError(locPlayer.getName() + " was unable to accept your teleport request.");
  16510. diff --git a/src/net/innectis/innplugin/Player/TinyWE/BlockBag.java b/src/net/innectis/innplugin/Player/TinyWE/BlockBag.java
  16511. index 007d40b0b..956a9712b 100644
  16512. --- a/src/net/innectis/innplugin/Player/TinyWE/BlockBag.java
  16513. +++ b/src/net/innectis/innplugin/Player/TinyWE/BlockBag.java
  16514. @@ -18,6 +18,8 @@ import net.innectis.innplugin.OwnedObjects.InnectisBookcase;
  16515. import net.innectis.innplugin.OwnedObjects.InnectisLot;
  16516. import net.innectis.innplugin.Player.IdpPlayer;
  16517. import net.innectis.innplugin.Player.Permission;
  16518. +import net.innectis.innplugin.Player.PlayerCredentials;
  16519. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  16520. import net.innectis.innplugin.Player.TinyWE.BlockCounters.*;
  16521. import net.innectis.innplugin.Player.TinyWE.BlockCounters.BlockCounterFactory.CountType;
  16522. import net.innectis.innplugin.Player.TinyWE.IdpEditSession.SpecialItemHandleResult;
  16523. @@ -129,7 +131,6 @@ public class BlockBag {
  16524. sortBlocks(blocks);
  16525.  
  16526. IdpPlayer player = session.getPlayer();
  16527. - String playername = player.getName();
  16528.  
  16529. for (Block block : blocks) {
  16530. // Max blocks checked
  16531. @@ -170,7 +171,7 @@ public class BlockBag {
  16532. Location loc = block.getLocation();
  16533.  
  16534. // Log the action when success!
  16535. - LogManager.getBlockLogger().logBlockAction(playername, mat, loc, BlockAction.WE_ACTION);
  16536. + LogManager.getBlockLogger().logBlockAction(player.getUniqueId(), mat, loc, BlockAction.WE_ACTION);
  16537. break;
  16538. }
  16539. } catch (TWEActionNotFinishedException twex) {
  16540. @@ -211,7 +212,8 @@ public class BlockBag {
  16541.  
  16542. switch (toMaterial) {
  16543. case LOCKED: // Lock the block.
  16544. - if (BlockLockHandler.lockBlock(session.getPlayer(), loc)) {
  16545. + if (BlockLockHandler.lockBlock(session.getPlayer().getUniqueId(), loc)) {
  16546. +
  16547. return 1;
  16548. } else {
  16549. return 0;
  16550. diff --git a/src/net/innectis/innplugin/Player/TinyWE/IdpEditSession.java b/src/net/innectis/innplugin/Player/TinyWE/IdpEditSession.java
  16551. index e21abd6e6..6832c050a 100644
  16552. --- a/src/net/innectis/innplugin/Player/TinyWE/IdpEditSession.java
  16553. +++ b/src/net/innectis/innplugin/Player/TinyWE/IdpEditSession.java
  16554. @@ -1,6 +1,7 @@
  16555. package net.innectis.innplugin.Player.TinyWE;
  16556.  
  16557. import java.lang.ref.WeakReference;
  16558. +import java.util.UUID;
  16559. import net.innectis.innplugin.Configuration;
  16560. import net.innectis.innplugin.Handlers.BlockHandler;
  16561. import net.innectis.innplugin.InnPlugin;
  16562. @@ -38,16 +39,16 @@ public class IdpEditSession {
  16563. SPECIAL_HANDLED;
  16564. }
  16565.  
  16566. - private String _playername;
  16567. + private UUID playerId;
  16568. private WeakReference<IdpPlayer> _player;
  16569.  
  16570. /**
  16571. * Create a new editsession
  16572. *
  16573. - * @param player
  16574. + * @param playerId
  16575. */
  16576. - public IdpEditSession(String player) {
  16577. - _playername = player;
  16578. + public IdpEditSession(UUID playerId) {
  16579. + this.playerId = playerId;
  16580. // load the player
  16581. fetchPlayer();
  16582. }
  16583. @@ -59,7 +60,7 @@ public class IdpEditSession {
  16584. * @see IdpEditSession::getPlayer()
  16585. */
  16586. private void fetchPlayer() {
  16587. - IdpPlayer player = InnPlugin.getPlugin().getPlayer(_playername, true);
  16588. + IdpPlayer player = InnPlugin.getPlugin().getPlayer(playerId);
  16589. _player = new WeakReference<IdpPlayer>(player);
  16590. }
  16591.  
  16592. diff --git a/src/net/innectis/innplugin/Player/Tools/EditSignTool.java b/src/net/innectis/innplugin/Player/Tools/EditSignTool.java
  16593. index fc380a7b5..732ce3e89 100644
  16594. --- a/src/net/innectis/innplugin/Player/Tools/EditSignTool.java
  16595. +++ b/src/net/innectis/innplugin/Player/Tools/EditSignTool.java
  16596. @@ -53,7 +53,7 @@ public class EditSignTool extends Tool {
  16597.  
  16598. InnectisLot lot = LotHandler.getLot(block.getLocation(), true);
  16599.  
  16600. - if (lot == null || lot.canPlayerAccess(player)
  16601. + if (lot == null || lot.canPlayerAccess(player.getName())
  16602. || player.hasPermission(Permission.special_edit_any_sign)) {
  16603. Sign sign = (Sign) block.getState();
  16604. Location loc = sign.getLocation();
  16605. diff --git a/src/net/innectis/innplugin/Shop/ChestShop.java b/src/net/innectis/innplugin/Shop/ChestShop.java
  16606. index 293e33370..fefc410aa 100644
  16607. --- a/src/net/innectis/innplugin/Shop/ChestShop.java
  16608. +++ b/src/net/innectis/innplugin/Shop/ChestShop.java
  16609. @@ -3,8 +3,8 @@ package net.innectis.innplugin.Shop;
  16610. import net.innectis.innplugin.Handlers.TransactionHandler;
  16611. import net.innectis.innplugin.Handlers.TransactionHandler.TransactionType;
  16612. import net.innectis.innplugin.InnPlugin;
  16613. -import net.innectis.innplugin.Inventory.IdpContainer;
  16614. import net.innectis.innplugin.InnectisObjects.TransactionObject;
  16615. +import net.innectis.innplugin.Inventory.IdpContainer;
  16616. import net.innectis.innplugin.Items.IdpItem;
  16617. import net.innectis.innplugin.Items.IdpItemStack;
  16618. import net.innectis.innplugin.Items.IdpMaterial;
  16619. @@ -12,6 +12,7 @@ import net.innectis.innplugin.Loggers.LogManager;
  16620. import net.innectis.innplugin.OwnedObjects.InnectisChest;
  16621. import net.innectis.innplugin.Player.IdpPlayer;
  16622. import net.innectis.innplugin.Player.IdpPlayerInventory;
  16623. +import net.innectis.innplugin.Player.PlayerCredentials;
  16624. import net.innectis.innplugin.Player.PlayerSettings;
  16625. import net.innectis.innplugin.SignSystem.ChestShopSign;
  16626. import net.innectis.innplugin.SignSystem.ChestShopSign.ChestShopType;
  16627. @@ -38,6 +39,7 @@ public final class ChestShop {
  16628. public void processTransaction() {
  16629. Chest bukkitChest = innChest.getChest1Chest();
  16630. boolean buyShop = (chestSign.getShopType() == ChestShopType.BUY);
  16631. + PlayerCredentials credentials = innChest.getOwnerCredentials();
  16632.  
  16633. IdpContainer senderContainer = null;
  16634. IdpContainer receiverContainer = null;
  16635. @@ -47,16 +49,16 @@ public final class ChestShop {
  16636.  
  16637. if (buyShop) {
  16638. senderContainer = new IdpContainer(customer.getInventory());
  16639. - transactionSender = TransactionHandler.getTransactionObject(innChest.getOwner());
  16640. + transactionSender = TransactionHandler.getTransactionObject(credentials.getUniqueId(), credentials.getName());
  16641.  
  16642. receiverContainer = new IdpContainer(bukkitChest.getInventory());
  16643. - transactionReceiver = TransactionHandler.getTransactionObject(customer.getName());
  16644. + transactionReceiver = TransactionHandler.getTransactionObject(customer.getUniqueId(), customer.getName());
  16645. } else {
  16646. senderContainer = new IdpContainer(bukkitChest.getInventory());
  16647. - transactionSender = TransactionHandler.getTransactionObject(customer.getName());
  16648. + transactionSender = TransactionHandler.getTransactionObject(customer.getUniqueId(), customer.getName());
  16649.  
  16650. receiverContainer = new IdpContainer(customer.getInventory());
  16651. - transactionReceiver = TransactionHandler.getTransactionObject(innChest.getOwner());
  16652. + transactionReceiver = TransactionHandler.getTransactionObject(credentials.getUniqueId(), credentials.getName());
  16653. }
  16654.  
  16655. IdpItem item = new IdpItem(chestSign.getMaterial());
  16656. diff --git a/src/net/innectis/innplugin/Shop/ShopHandler.java b/src/net/innectis/innplugin/Shop/ShopHandler.java
  16657. index b7a7caed9..eb6e1306a 100644
  16658. --- a/src/net/innectis/innplugin/Shop/ShopHandler.java
  16659. +++ b/src/net/innectis/innplugin/Shop/ShopHandler.java
  16660. @@ -15,7 +15,6 @@ import net.innectis.innplugin.Loggers.LogManager;
  16661. import net.innectis.innplugin.Player.Chat.ChatColor;
  16662. import net.innectis.innplugin.Player.IdpPlayer;
  16663. import net.innectis.innplugin.Player.IdpPlayerInventory;
  16664. -import net.innectis.innplugin.Utility.NumberUtil;
  16665. import org.bukkit.event.inventory.InventoryClickEvent;
  16666. import org.bukkit.inventory.Inventory;
  16667.  
  16668. @@ -164,7 +163,7 @@ public final class ShopHandler {
  16669. inv.setItem(i, (content[i] != null ? content[i].toBukkitItemstack() : null));
  16670. }
  16671. } else {
  16672. - TransactionObject transaction = TransactionHandler.getTransactionObject(player.getName());
  16673. + TransactionObject transaction = TransactionHandler.getTransactionObject(player.getUniqueId(), player.getName());
  16674. IdpPlayerInventory playerInventory = player.getInventory();
  16675. IdpContainer container = new IdpContainer(playerInventory);
  16676.  
  16677. diff --git a/src/net/innectis/innplugin/Tasking/AsyncTasks/MessageTask.java b/src/net/innectis/innplugin/Tasking/AsyncTasks/MessageTask.java
  16678. index f4214bb67..3205f1101 100644
  16679. --- a/src/net/innectis/innplugin/Tasking/AsyncTasks/MessageTask.java
  16680. +++ b/src/net/innectis/innplugin/Tasking/AsyncTasks/MessageTask.java
  16681. @@ -72,8 +72,8 @@ public class MessageTask extends RepeatingTask {
  16682. ResultSet result = null;
  16683.  
  16684. try {
  16685. - statement = DBManager.prepareStatement("SELECT timestamp FROM vote_log WHERE username = ?");
  16686. - statement.setString(1, player.getName());
  16687. + statement = DBManager.prepareStatement("SELECT timestamp FROM vote_log WHERE player_id = ?;");
  16688. + statement.setString(1, player.getUniqueId().toString());
  16689. result = statement.executeQuery();
  16690.  
  16691. // More than 20 hours since last vote, then display message.
  16692. diff --git a/src/net/innectis/innplugin/Tasking/SyncTasks/PlayerInfoTask.java b/src/net/innectis/innplugin/Tasking/SyncTasks/PlayerInfoTask.java
  16693. index 7a33cc52e..4d65401af 100644
  16694. --- a/src/net/innectis/innplugin/Tasking/SyncTasks/PlayerInfoTask.java
  16695. +++ b/src/net/innectis/innplugin/Tasking/SyncTasks/PlayerInfoTask.java
  16696. @@ -3,11 +3,14 @@ package net.innectis.innplugin.Tasking.SyncTasks;
  16697. import java.sql.Timestamp;
  16698. import net.innectis.innplugin.BanSystem.BanHandler;
  16699. import net.innectis.innplugin.BanSystem.UserBanObject;
  16700. +import net.innectis.innplugin.Configuration;
  16701. import net.innectis.innplugin.External.API.Interfaces.INoCheatPlusIDP;
  16702. import net.innectis.innplugin.External.LibraryType;
  16703. import net.innectis.innplugin.InnPlugin;
  16704. import net.innectis.innplugin.Player.Chat.ChatColor;
  16705. import net.innectis.innplugin.Player.IdpPlayer;
  16706. +import net.innectis.innplugin.Player.PlayerCredentials;
  16707. +import net.innectis.innplugin.Player.PlayerCredentialsManager;
  16708. import net.innectis.innplugin.Tasking.DefaultTaskDelays;
  16709. import net.innectis.innplugin.Tasking.RepeatingTask;
  16710. import net.innectis.innplugin.Tasking.RunBehaviour;
  16711. @@ -39,8 +42,10 @@ public class PlayerInfoTask extends RepeatingTask {
  16712. String[] noCheatBanned = noCheatPlus.getBannedPlayers();
  16713. if (noCheatBanned != null) {
  16714. for (String banned : noCheatBanned) {
  16715. - BanHandler.addBan(new UserBanObject(banned, "Elena", new Timestamp(System.currentTimeMillis()), 21600000, false));
  16716. - InnPlugin.getPlugin().broadCastMessage(ChatColor.RED, String.format("Player %s has been banned for 6 hours by Elena!", banned));
  16717. + PlayerCredentials credentials = PlayerCredentialsManager.getByName(banned);
  16718. +
  16719. + BanHandler.addBan(new UserBanObject(credentials, Configuration.SERVER_GENERATED_CREDENTIALS, new Timestamp(System.currentTimeMillis()), 21600000, false));
  16720. + InnPlugin.getPlugin().broadCastMessage(ChatColor.RED, String.format("Player %s has been banned for 6 hours by the console!", banned));
  16721. }
  16722. noCheatPlus.clearBannedPlayers();
  16723. }
  16724. diff --git a/src/net/innectis/innplugin/Tasking/SyncTasks/ValutaBankTransactionTask.java b/src/net/innectis/innplugin/Tasking/SyncTasks/ValutaBankTransactionTask.java
  16725. index 692f2bb11..f1e317360 100644
  16726. --- a/src/net/innectis/innplugin/Tasking/SyncTasks/ValutaBankTransactionTask.java
  16727. +++ b/src/net/innectis/innplugin/Tasking/SyncTasks/ValutaBankTransactionTask.java
  16728. @@ -1,15 +1,14 @@
  16729. package net.innectis.innplugin.Tasking.SyncTasks;
  16730.  
  16731. +import java.util.UUID;
  16732. import net.innectis.innplugin.Handlers.TransactionHandler;
  16733. import net.innectis.innplugin.Handlers.TransactionHandler.TransactionType;
  16734. import net.innectis.innplugin.InnPlugin;
  16735. import net.innectis.innplugin.InnectisObjects.TransactionObject;
  16736. -import net.innectis.innplugin.Player.Chat.ChatColor;
  16737. import net.innectis.innplugin.Player.IdpPlayer;
  16738. import net.innectis.innplugin.Player.PlayerSession;
  16739. import net.innectis.innplugin.Tasking.LimitedTask;
  16740. import net.innectis.innplugin.Tasking.RunBehaviour;
  16741. -import net.innectis.innplugin.Utility.NumberUtil;
  16742.  
  16743. /**
  16744. * A task to handle money going in or out of a player's bank
  16745. @@ -17,16 +16,18 @@ import net.innectis.innplugin.Utility.NumberUtil;
  16746. * @author AlphaBlend
  16747. */
  16748. public class ValutaBankTransactionTask extends LimitedTask {
  16749. - private String username;
  16750. + private UUID playerId;
  16751. + private String playerName;
  16752.  
  16753. - public ValutaBankTransactionTask(String username, long time) {
  16754. + public ValutaBankTransactionTask(UUID playerId, String playerName, long time) {
  16755. super(RunBehaviour.SYNCED, time, 1);
  16756. - this.username = username;
  16757. + this.playerId = playerId;
  16758. + this.playerName = playerName;
  16759. }
  16760.  
  16761. @Override
  16762. public void run() {
  16763. - IdpPlayer player = InnPlugin.getPlugin().getPlayer(username);
  16764. + IdpPlayer player = InnPlugin.getPlugin().getPlayer(playerId);
  16765.  
  16766. if (player != null) {
  16767. PlayerSession session = player.getSession();
  16768. @@ -34,7 +35,7 @@ public class ValutaBankTransactionTask extends LimitedTask {
  16769. session.setLastBankTaskTime(0);
  16770. }
  16771.  
  16772. - TransactionObject transaction = TransactionHandler.getTransactionObject(username);
  16773. + TransactionObject transaction = TransactionHandler.getTransactionObject(playerId, playerName);
  16774. int valutasToPlayer = transaction.getValue(TransactionType.VALUTAS_TO_PLAYER);
  16775.  
  16776. if (valutasToPlayer > 0) {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement