Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/src/net/innectis/innplugin/BanSystem/BanHandler.java b/src/net/innectis/innplugin/BanSystem/BanHandler.java
- index 17bcb5e2b..6b767e729 100644
- --- a/src/net/innectis/innplugin/BanSystem/BanHandler.java
- +++ b/src/net/innectis/innplugin/BanSystem/BanHandler.java
- @@ -5,10 +5,13 @@ import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Timestamp;
- import java.util.*;
- +import net.innectis.innplugin.Configuration;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- +import net.innectis.innplugin.IdpCommandSender;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.Player.Chat.ChatColor;
- -import net.innectis.innplugin.Player.IdpPlayer;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Player.PlayerGroup;
- /**
- @@ -20,67 +23,59 @@ public class BanHandler {
- private static List<BanObject> bannedPlayers = new ArrayList<BanObject>();
- // Includes all the whitelisted players (Wrongfully IPBanned players)
- - private static List<String> whitelistPlayers = new ArrayList<String>();
- + private static List<PlayerCredentials> whitelistedPlayers = new ArrayList<PlayerCredentials>();
- private BanHandler() {
- }
- /**
- * Adds a user to the ban whitelist
- - * @param player
- + * @param credentials
- */
- - public static void addWhitelist(String player) {
- - if (!whitelistPlayers.contains(player)) {
- - whitelistPlayers.add(player);
- -
- - PreparedStatement statement = null;
- -
- - try {
- - statement = DBManager.prepareStatement("INSERT INTO ban_whitelist VALUES (?)");
- - statement.setString(1, player);
- - statement.execute();
- - } catch (SQLException ex) {
- - InnPlugin.logError("Unable to add whitelisted player to the database!", ex);
- - } finally {
- - DBManager.closePreparedStatement(statement);
- - }
- + public static void addWhitelist(PlayerCredentials credentials) {
- + whitelistedPlayers.add(credentials);
- +
- + PreparedStatement statement = null;
- +
- + try {
- + statement = DBManager.prepareStatement("INSERT INTO ban_whitelist (player_id) VALUES (?);");
- + statement.setString(1, credentials.getUniqueId().toString());
- + statement.execute();
- + } catch (SQLException ex) {
- + InnPlugin.logError("Unable to add whitelisted player to the database!", ex);
- + } finally {
- + DBManager.closePreparedStatement(statement);
- }
- }
- /**
- * Removes a player from the ban whitelist
- - * @param player
- + * @param credentials
- */
- - public static void removeWhitelist(String player) {
- - for (String name : whitelistPlayers) {
- - if (name.equalsIgnoreCase(player)) {
- - whitelistPlayers.remove(name);
- -
- - PreparedStatement statement = null;
- -
- - try {
- - statement = DBManager.prepareStatement("DELETE FROM ban_whitelist WHERE name = ?");
- - statement.setString(1, player);
- - statement.execute();
- - } catch (SQLException ex) {
- - InnPlugin.logError("Unable to remove whitelisted player from the database!", ex);
- - } finally {
- - DBManager.closePreparedStatement(statement);
- - }
- + public static void removeWhitelist(PlayerCredentials credentials) {
- + whitelistedPlayers.remove(credentials);
- - return;
- - }
- + PreparedStatement statement = null;
- +
- + try {
- + statement = DBManager.prepareStatement("DELETE FROM ban_whitelist WHERE player_id = ?");
- + statement.setString(1, credentials.getUniqueId().toString());
- + statement.execute();
- + } catch (SQLException ex) {
- + InnPlugin.logError("Unable to remove whitelisted player " + credentials.getName() + " from the database!", ex);
- + } finally {
- + DBManager.closePreparedStatement(statement);
- }
- }
- /**
- - * Checks to see if a player is whitelisted on the ban list
- - * @param name
- + * Checks to see if a player is on the ban whitelist by their unique id
- + * @param playerId
- * @return
- */
- - public static boolean isWhitelisted(String name) {
- - for (String user : whitelistPlayers) {
- - if (user.equalsIgnoreCase(name)) {
- + public static boolean isWhitelisted(UUID playerId) {
- + for (PlayerCredentials pc : whitelistedPlayers) {
- + if (pc.getUniqueId().equals(playerId)) {
- return true;
- }
- }
- @@ -89,11 +84,11 @@ public class BanHandler {
- }
- /**
- - * Gets the whitelist as an unmodifiable list
- + * Gets the whitelist as an unmodifiable list of player credentials
- * @return
- */
- - public static List<String> getWhitelist() {
- - return Collections.unmodifiableList(whitelistPlayers);
- + public static List<PlayerCredentials> getWhitelist() {
- + return Collections.unmodifiableList(whitelistedPlayers);
- }
- /**
- @@ -108,7 +103,10 @@ public class BanHandler {
- set = statement.executeQuery();
- while (set.next()) {
- - whitelistPlayers.add(set.getString("name"));
- + String playerId = set.getString("player_id");
- + UUID uuid = UUID.fromString(playerId);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(uuid, true);
- + whitelistedPlayers.add(credentials);
- }
- } catch (SQLException ex) {
- InnPlugin.logError("Unable to load ban whitelist!", ex);
- @@ -119,17 +117,17 @@ public class BanHandler {
- }
- /**
- - * Gets the ban type of the specified username, or IP
- - * @param username
- + * Gets the ban type from the player's unique ID or IP
- + * @param playerId
- * @param ip
- * @return
- */
- - public static BanTypes getBanType(String username, String ip) {
- - if (isWhitelisted(username)) {
- + public static BanTypes getBanType(UUID playerId, String ip) {
- + if (isWhitelisted(playerId)) {
- return BanTypes.WHITELISTED;
- }
- - BanObject ban = getBan(username);
- + BanObject ban = getBan(playerId);
- if (ban != null) {
- if (ban.isJoinBan()) {
- @@ -138,10 +136,8 @@ public class BanHandler {
- } else if (ban instanceof IPBanObject) {
- return BanTypes.BANNED_JOINBAN_IP;
- }
- - } else if (!ban.isIndefiniteBan() && new Timestamp(System.currentTimeMillis()).after(ban.getUnbanTime())) {
- + } else if (!ban.isIndefiniteBan() && new Timestamp(System.currentTimeMillis()).after(ban.getExpireTime())) {
- bannedPlayers.remove(ban);
- -
- - // Same method that inherited from the parent you can just call that.
- ban.delete();
- return BanTypes.UNBANNED;
- @@ -159,27 +155,28 @@ public class BanHandler {
- /**
- * Links a username and ip to an existing username's ip ban
- - * @param username
- + * @param creator
- + * @param bannedPlayerCredentials
- * @param ip
- - * @param linkedUsername
- + * @param linkedPlayerCredentials
- * @return Whether the name was linked to an existing ip ban or not
- */
- - public static LinkStatus linkIPBan(IdpPlayer creator, String username, String ip, String linkedUsername) {
- + public static LinkStatus linkIPBan(IdpCommandSender creator, PlayerCredentials bannedPlayerCredentials, String ip, PlayerCredentials linkedPlayerCredentials) {
- for (BanObject ban : bannedPlayers) {
- if (ban instanceof IPBanObject) {
- IPBanObject ipban = (IPBanObject) ban;
- IPBanGroup group = ipban.getGroup();
- - if (group.containsPlayer(linkedUsername)) {
- - if (creator != null && !ban.canModifyBan(creator)) {
- + if (group.containsPlayerId(linkedPlayerCredentials.getUniqueId())) {
- + if (!ban.canModifyBan(creator)) {
- return LinkStatus.LINK_NOT_CREATOR;
- }
- - if (group.containsPlayer(username)) {
- + if (group.containsPlayerId(bannedPlayerCredentials.getUniqueId())) {
- return LinkStatus.LINK_SAME_USER;
- }
- - group.addPlayer(username);
- + group.addPlayer(bannedPlayerCredentials);
- group.addIP(ip);
- ipban.save();
- return LinkStatus.LINK_SUCCESSFUL;
- @@ -192,22 +189,23 @@ public class BanHandler {
- /**
- * Unlinks a username and ip from an existing IPBan
- - * @param username
- + * @param creator
- + * @param credentials
- * @param ip
- * @return Whether the username was unlinked from an existing ip ban
- */
- - public static UnlinkStatus unlinkIPBan(IdpPlayer creator, String username, String ip) {
- + public static UnlinkStatus unlinkIPBan(IdpCommandSender creator, PlayerCredentials credentials, String ip) {
- for (BanObject ban : bannedPlayers) {
- if (ban instanceof IPBanObject) {
- IPBanObject ipban = (IPBanObject) ban;
- IPBanGroup group = ipban.getGroup();
- - if (group.containsPlayer(username)) {
- - if (creator != null && !ban.canModifyBan(creator)) {
- + if (group.containsPlayerId(credentials.getUniqueId())) {
- + if (!ban.canModifyBan(creator)) {
- return UnlinkStatus.UNLINK_NOT_CREATOR;
- }
- - group.removePlayer(username);
- + group.removePlayer(credentials);
- group.removeIP(ip);
- // No more players or IPs, so just remove the ban entirely
- @@ -282,33 +280,29 @@ public class BanHandler {
- }
- /**
- - * Gets the ban object of the user
- - * @param username
- - * @param ip
- + * Gets the ban object from the specified player ID, if available
- + * @param playerId
- * @return
- */
- - public static BanObject getBan(String username) {
- - BanObject ban = null;
- -
- + public static BanObject getBan(UUID playerId) {
- for (BanObject banobj : bannedPlayers) {
- if (banobj instanceof UserBanObject) {
- UserBanObject userban = (UserBanObject) banobj;
- + PlayerCredentials bannedPlayerCredentials = userban.getBannedPlayerCredentials();
- - if (userban.getUsername().equalsIgnoreCase(username)) {
- - ban = userban;
- - break;
- + if (bannedPlayerCredentials.getUniqueId().equals(playerId)) {
- + return banobj;
- }
- } else if (banobj instanceof IPBanObject) {
- IPBanObject ipban = (IPBanObject) banobj;
- - if (ipban.getGroup().containsPlayer(username)) {
- - ban = ipban;
- - break;
- + if (ipban.getGroup().containsPlayerId(playerId)) {
- + return banobj;
- }
- }
- }
- - return ban;
- + return null;
- }
- /**
- @@ -331,7 +325,7 @@ public class BanHandler {
- if (b instanceof UserBanObject) {
- UserBanObject ub = (UserBanObject) b;
- - if (ub.getUsername().equalsIgnoreCase(userban.getUsername())) {
- + if (ub.getBannedPlayerCredentials().equals(userban.getBannedPlayerCredentials())) {
- ub.setAttributesFrom(ban);
- ub.save();
- type = BanResult.BAN_EXISTING;
- @@ -339,7 +333,6 @@ public class BanHandler {
- break;
- }
- }
- -
- }
- // If there is no existing ban, just save this, and add it to the
- @@ -400,18 +393,31 @@ public class BanHandler {
- ResultSet set = null;
- try {
- - statement = DBManager.prepareStatement("SELECT * FROM banned_players WHERE expired = 0");
- + statement = DBManager.prepareStatement("SELECT * FROM banned_players WHERE expired = 0;");
- set = statement.executeQuery();
- while (set.next()) {
- int id = set.getInt("ID");
- - String username = set.getString("username");
- - String bannedBy = set.getString("banned_by");
- +
- + String playerId = set.getString("player_id");
- + UUID uuid = UUID.fromString(playerId);
- + PlayerCredentials player = PlayerCredentialsManager.getByUniqueId(uuid, true);
- +
- + String bannedByPlayerId = set.getString("banned_by_player_id");
- + UUID bannedByUUID = UUID.fromString(bannedByPlayerId);
- + PlayerCredentials bannedByPlayerCredentials = null;
- +
- + if (bannedByUUID.equals(Configuration.SERVER_GENERATED_IDENTIFIER)) {
- + bannedByPlayerCredentials = Configuration.SERVER_GENERATED_CREDENTIALS;
- + } else {
- + bannedByPlayerCredentials = PlayerCredentialsManager.getByUniqueId(bannedByUUID, true);
- + }
- +
- Timestamp bannedTime = set.getTimestamp("banned_time");
- long durationTicks = set.getLong("duration_ticks");
- boolean joinBan = set.getBoolean("joinban");
- - UserBanObject userban = new UserBanObject(id, username, bannedBy, bannedTime, durationTicks, joinBan);
- + UserBanObject userban = new UserBanObject(id, player, bannedByPlayerCredentials, bannedTime, durationTicks, joinBan);
- bannedPlayers.add(userban);
- }
- } catch (SQLException ex) {
- @@ -424,36 +430,50 @@ public class BanHandler {
- InnPlugin.logInfo("Loading ipbanned players...");
- try {
- - statement = DBManager.prepareStatement("SELECT * FROM banned_ip_players where expired = 0");
- + statement = DBManager.prepareStatement("SELECT * FROM banned_ip_players where expired = 0;");
- set = statement.executeQuery();
- while (set.next()) {
- int id = set.getInt("ID");
- - String ipliststring = set.getString("iplist");
- - String userliststring = set.getString("userlist");
- - String bannedBy = set.getString("banned_by");
- + String ipListString = set.getString("iplist");
- + String playerIdString = set.getString("player_id_list");
- +
- + String bannedByPlayerId = set.getString("banned_by_player_id");
- + UUID bannedByPlayerUUID = UUID.fromString(bannedByPlayerId);
- + PlayerCredentials bannedByPlayerCredentials = null;
- +
- + if (bannedByPlayerUUID.equals(Configuration.SERVER_GENERATED_IDENTIFIER)) {
- + bannedByPlayerCredentials = Configuration.SERVER_GENERATED_CREDENTIALS;
- + } else {
- + bannedByPlayerCredentials = PlayerCredentialsManager.getByUniqueId(bannedByPlayerUUID, true);
- + }
- +
- Timestamp bannedTime = set.getTimestamp("banned_time");
- long durationTicks = set.getLong("duration_ticks");
- boolean joinBan = set.getBoolean("joinban");
- List<String> ipList;
- - if (ipliststring != null && !ipliststring.isEmpty()) {
- - //String[] aryIPList = ipliststring.split(", ");
- - ipList = new ArrayList<String>(Arrays.asList(ipliststring.split(", ")));
- +
- + if (ipListString != null && !ipListString.isEmpty()) {
- + ipList = new ArrayList<String>(Arrays.asList(ipListString.split(", ")));
- } else {
- ipList = new ArrayList<String>(1);
- }
- - List<String> userList;
- - if (userliststring != null && !userliststring.isEmpty()) {
- - //String[] aryUserList = userliststring.split(", ");
- - userList = new ArrayList<String>(Arrays.asList(userliststring.split(", ")));
- + List<PlayerCredentials> playerList = new ArrayList<PlayerCredentials>();
- +
- + if (playerIdString != null && !playerIdString.isEmpty()) {
- + for (String playerId : playerIdString.split(", ")) {
- + UUID playerUUID = UUID.fromString(playerId);
- + PlayerCredentials player = PlayerCredentialsManager.getByUniqueId(playerUUID, true);
- + playerList.add(player);
- + }
- } else {
- - userList = new ArrayList<String>(1);
- + playerList = new ArrayList<PlayerCredentials>(1);
- }
- - IPBanGroup group = new IPBanGroup(ipList, userList);
- - IPBanObject ipban = new IPBanObject(id, group, bannedBy, bannedTime, durationTicks, joinBan);
- + IPBanGroup group = new IPBanGroup(ipList, playerList);
- + IPBanObject ipban = new IPBanObject(id, group, bannedByPlayerCredentials, bannedTime, durationTicks, joinBan);
- bannedPlayers.add(ipban);
- }
- } catch (SQLException ex) {
- @@ -466,33 +486,35 @@ public class BanHandler {
- /**
- * Gets the full username of a partial username
- - * @param username
- + * @param checkPlayer
- * @return
- */
- - public static String getPartialName(String username) {
- + public static String getPartialName(String checkPlayer) {
- for (BanObject ban : Collections.synchronizedList(bannedPlayers)) {
- if (ban instanceof UserBanObject) {
- UserBanObject userban = (UserBanObject) ban;
- - int minLen = Math.min(username.length(), userban.getUsername().length());
- + String playerName = userban.getBannedPlayerCredentials().getName();
- + int minLen = Math.min(checkPlayer.length(), playerName.length());
- - if (userban.getUsername().substring(0, minLen).equalsIgnoreCase(username)) {
- - return userban.getUsername();
- + if (playerName.substring(0, minLen).equalsIgnoreCase(checkPlayer)) {
- + return playerName;
- }
- } else if (ban instanceof IPBanObject) {
- IPBanObject ipban = (IPBanObject) ban;
- - List<String> usernames = ipban.getGroup().getPlayers();
- + List<PlayerCredentials> players = ipban.getGroup().getPlayers();
- - for (String user : usernames) {
- - int minLen = Math.min(user.length(), username.length());
- + for (PlayerCredentials player : players) {
- + String name = player.getName();
- + int minLen = Math.min(name.length(), checkPlayer.length());
- - if (user.substring(0, minLen).equalsIgnoreCase(username)) {
- - return user;
- + if (name.substring(0, minLen).equalsIgnoreCase(checkPlayer)) {
- + return name;
- }
- }
- }
- }
- - return username;
- + return checkPlayer;
- }
- /**
- @@ -514,8 +536,9 @@ public class BanHandler {
- int idx = 1;
- for (BanObject ban : Collections.synchronizedList(bannedPlayers)) {
- - String bannedBy = ban.getBannedBy();
- - PlayerGroup bannedByGroup = PlayerGroup.getGroupOfUsername(bannedBy);
- + PlayerCredentials bannedByCredentials = ban.getBannedByCredentials();
- + String bannedBy = ban.getBannedByCredentials().getName();
- + PlayerGroup bannedByGroup = PlayerGroup.getGroupOfPlayerById(bannedByCredentials.getUniqueId());
- String bannedByUserWithGroup = bannedByGroup.getPrefix().getTextColor() + bannedBy;
- String bannedTime = "";
- @@ -533,8 +556,9 @@ public class BanHandler {
- if (ban instanceof UserBanObject) {
- UserBanObject userban = (UserBanObject) ban;
- - String username = userban.getUsername();
- - PlayerGroup userGroup = PlayerGroup.getGroupOfUsername(username);
- + PlayerCredentials bannedPlayerCredentials = userban.getBannedPlayerCredentials();
- + String username = bannedPlayerCredentials.getName();
- + PlayerGroup userGroup = PlayerGroup.getGroupOfPlayerById(bannedPlayerCredentials.getUniqueId());
- String bannedUserWithGroup = userGroup.getPrefix().getTextColor() + username;
- String banString = bannedUserWithGroup + " (" + banAttributes + ")";
- @@ -552,8 +576,9 @@ public class BanHandler {
- String coloredUsernames = "";
- - for (String name : group.getPlayers()) {
- - PlayerGroup pGroup = PlayerGroup.getGroupOfUsername(name);
- + for (PlayerCredentials pc : group.getPlayers()) {
- + String name = pc.getName();
- + PlayerGroup pGroup = PlayerGroup.getGroupOfPlayerById(pc.getUniqueId());
- String nameWithGroup = pGroup.getPrefix().getTextColor() + name;
- if (coloredUsernames.isEmpty()) {
- diff --git a/src/net/innectis/innplugin/BanSystem/BanObject.java b/src/net/innectis/innplugin/BanSystem/BanObject.java
- index 43267ce50..d757cae88 100644
- --- a/src/net/innectis/innplugin/BanSystem/BanObject.java
- +++ b/src/net/innectis/innplugin/BanSystem/BanObject.java
- @@ -1,8 +1,10 @@
- package net.innectis.innplugin.BanSystem;
- import java.sql.Timestamp;
- +import net.innectis.innplugin.IdpCommandSender;
- import net.innectis.innplugin.Player.IdpPlayer;
- import net.innectis.innplugin.Player.Permission;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- import net.innectis.innplugin.Utility.DateUtil;
- /**
- @@ -13,22 +15,14 @@ import net.innectis.innplugin.Utility.DateUtil;
- */
- public abstract class BanObject {
- private int id;
- - private String bannedBy;
- + private PlayerCredentials bannedByCredentials;
- private Timestamp bannedTime;
- private long durationTicks;
- private boolean joinBan;
- - /**
- - * New constructor to construct an abstract ban object (call from subclass)
- - * Called from
- - * @param bannedBy
- - * @param bannedTime
- - * @param durationTicks
- - * @param joinBan
- - */
- - public BanObject(int id, String bannedBy, Timestamp bannedTime, long durationTicks, boolean joinBan) {
- + public BanObject(int id, PlayerCredentials bannedByCredentials, Timestamp bannedTime, long durationTicks, boolean joinBan) {
- this.id = id;
- - this.bannedBy = bannedBy;
- + this.bannedByCredentials = bannedByCredentials;
- this.bannedTime = bannedTime;
- this.durationTicks = durationTicks;
- this.joinBan = joinBan;
- @@ -39,7 +33,7 @@ public abstract class BanObject {
- * @param ban
- */
- public void setAttributesFrom(BanObject ban) {
- - setBannedBy(ban.getBannedBy());
- + setBannedBy(ban.getBannedByCredentials());
- setBannedTime(ban.getBannedTime(), ban.getDurationTicks());
- setJoinBan(ban.isJoinBan());
- }
- @@ -61,37 +55,34 @@ public abstract class BanObject {
- }
- /**
- - * Gets the person that made this ban
- + * Gets the credentials of the player that made this ban
- * @return
- */
- - public String getBannedBy() {
- - return bannedBy;
- + public PlayerCredentials getBannedByCredentials() {
- + return bannedByCredentials;
- }
- /**
- - * Specifies whether the player may modify this ban
- - * @param player
- + * Specifies whether the specified sender may modify this ban. It can
- + * either be a player or the console
- + * @param sender
- * @return
- */
- - public boolean canModifyBan(IdpPlayer player) {
- - if (bannedBy.equalsIgnoreCase(player.getName())
- - || player.hasPermission(Permission.special_modifyban_otherowner)) {
- - return true;
- - }
- -
- - return false;
- + public boolean canModifyBan(IdpCommandSender sender) {
- + return (bannedByCredentials.getName().equalsIgnoreCase(sender.getName())
- + || sender.hasPermission(Permission.special_modifyban_otherowner));
- }
- /**
- - * Sets who this ban was made by
- + * Sets the credentials of the player that made this ban
- * @param bannedBy
- */
- - public void setBannedBy(String bannedBy) {
- - this.bannedBy = bannedBy;
- + public void setBannedBy(PlayerCredentials bannedBy) {
- + this.bannedByCredentials = bannedBy;
- }
- /**
- - * Gets the time the ban was first made
- + * Gets the time the ban was created
- * @return
- */
- public Timestamp getBannedTime() {
- @@ -110,7 +101,6 @@ public abstract class BanObject {
- /**
- * Sets the new ban time of this ban
- - * @param bannedTime
- * @param durationTicks
- */
- public void setNewBannedTime(long durationTicks) {
- @@ -119,10 +109,10 @@ public abstract class BanObject {
- }
- /**
- - * Gets the timestamp of a user's unban time
- + * Gets the timestamp of when this ban will expire
- * @return
- */
- - public Timestamp getUnbanTime() {
- + public Timestamp getExpireTime() {
- if (joinBan) {
- return (new Timestamp(System.currentTimeMillis() + durationTicks));
- }
- @@ -131,8 +121,8 @@ public abstract class BanObject {
- }
- /**
- - * Gets the ban time as a time string
- - * @param time
- + * Gets the remaining expire time as a time string
- + * @param longversion
- * @return
- */
- public String getUnbanTimeString(boolean longversion) {
- @@ -140,7 +130,7 @@ public abstract class BanObject {
- }
- /**
- - * Gets whether or not this ban is indefinite
- + * Gets if this ban is an indefinite ban
- * @return
- */
- public boolean isIndefiniteBan() {
- @@ -148,7 +138,7 @@ public abstract class BanObject {
- }
- /**
- - * Gets whether or not this ban takes effect on next join
- + * Gets if this ban will take effect on the player's next join
- * @return
- */
- public boolean isJoinBan() {
- @@ -181,12 +171,10 @@ public abstract class BanObject {
- */
- public boolean isExpired() {
- return (!isIndefiniteBan() && System.currentTimeMillis() > (bannedTime.getTime() + durationTicks));
- - //return (!isPermBan() && new Timestamp(System.currentTimeMillis()).after(new Timestamp(bannedTime.getTime() + durationTicks)));
- }
- /**
- * Saves this ban object (implementation is object specific)
- - * @param update
- */
- public abstract void save();
- diff --git a/src/net/innectis/innplugin/BanSystem/IPBanGroup.java b/src/net/innectis/innplugin/BanSystem/IPBanGroup.java
- index 00158f5c9..1e6141e2c 100644
- --- a/src/net/innectis/innplugin/BanSystem/IPBanGroup.java
- +++ b/src/net/innectis/innplugin/BanSystem/IPBanGroup.java
- @@ -2,75 +2,62 @@ package net.innectis.innplugin.BanSystem;
- import java.util.ArrayList;
- import java.util.List;
- +import java.util.UUID;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- /**
- * @author AlphaBlend
- - *
- + *
- * Describes the IPs and usernames associated with an IPBan
- *
- */
- public class IPBanGroup {
- private List<String> iplist;
- - private List<String> players;
- -
- - /**
- - * Constructs a new IPBanGroup using a singular IP and playerr
- - * @param IP
- - * @param player
- - */
- - public IPBanGroup(String IP, String player) {
- + private List<PlayerCredentials> players;
- +
- + public IPBanGroup(String IP, PlayerCredentials credentials) {
- this.iplist = new ArrayList<String>(1);
- this.iplist.add(IP);
- -
- - this.players = new ArrayList<String>(1);
- - this.players.add(player);
- +
- + this.players = new ArrayList<PlayerCredentials>(1);
- + this.players.add(credentials);
- }
- - /**
- - * Constructs a new object using a list of IPs, and a single player
- - * @param iplist
- - * @param player
- - */
- - public IPBanGroup(List<String> iplist, String player) {
- + public IPBanGroup(List<String> iplist, PlayerCredentials credentials) {
- this.iplist = iplist;
- -
- - this.players = new ArrayList<String>(1);
- - this.players.add(player);
- +
- + this.players = new ArrayList<PlayerCredentials>(1);
- + this.players.add(credentials);
- }
- -
- - public IPBanGroup(String ip, List<String> players) {
- +
- + public IPBanGroup(String ip, List<PlayerCredentials> players) {
- this.iplist = new ArrayList<String>(1);
- this.iplist.add(ip);
- -
- +
- this.players = players;
- }
- -
- - /**
- - * Constructs a new object with a list of IPs and player names
- - * @param IPs
- - * @param usernames
- - */
- - public IPBanGroup(List<String> iplist, List<String> players) {
- +
- + public IPBanGroup(List<String> iplist, List<PlayerCredentials> players) {
- this.iplist = iplist;
- this.players = players;
- }
- -
- +
- /**
- * Gets the IPs associated with this IPBan
- - * @return
- + * @return
- */
- public List<String> getIPs() {
- return iplist;
- }
- -
- +
- /**
- * Gets the usernames associated with this IPBan
- - * @return
- + * @return
- */
- - public List<String> getPlayers() {
- + public List<PlayerCredentials> getPlayers() {
- return players;
- }
- -
- +
- /**
- * Adds an IP to the IP list
- * @param ip
- @@ -80,81 +67,82 @@ public class IPBanGroup {
- if (containsIP(ip)) {
- return false;
- }
- -
- +
- return iplist.add(ip);
- }
- -
- +
- /**
- * Adds a username to this IPBan
- - * @param username
- + * @param credentials
- * @return whether the username was added or not
- */
- - public boolean addPlayer(String username) {
- - if (containsPlayer(username)) {
- + public boolean addPlayer(PlayerCredentials credentials) {
- + if (containsPlayerId(credentials.getUniqueId())) {
- return false;
- }
- -
- - return players.add(username);
- +
- + return players.add(credentials);
- }
- -
- +
- /**
- * Removes the specified IP from the list of IPs
- * @param ip
- - * @return
- + * @return
- */
- public boolean removeIP(String ip) {
- if (!containsIP(ip)) {
- return false;
- }
- -
- +
- return iplist.remove(ip);
- }
- -
- +
- /**
- * Removes the specified username from the list of usernames
- - * @param username
- - * @return
- + * @param credentials
- + * @return
- */
- - public boolean removePlayer(String player) {
- - if (!containsPlayer(player)) {
- + public boolean removePlayer(PlayerCredentials credentials) {
- + if (!containsPlayerId(credentials.getUniqueId())) {
- return false;
- }
- -
- - return players.remove(player);
- +
- + return players.remove(credentials);
- }
- -
- +
- /**
- * Returns if the IP is in this group
- * @param IP
- - * @return
- + * @return
- */
- - public boolean containsIP(String checkIP) {
- - return iplist.contains(checkIP);
- + public boolean containsIP(String IP) {
- + return iplist.contains(IP);
- }
- -
- +
- /**
- - * Returns if the player is in this group
- - * @param checkPlayer
- - * @return
- + * Returns if the player represented by the unique ID
- + * is in this group
- + * @param playerId
- + * @return
- */
- - public boolean containsPlayer(String checkPlayer) {
- - for (String player : players) {
- - if (checkPlayer.equalsIgnoreCase(player)) {
- + public boolean containsPlayerId(UUID playerId) {
- + for (PlayerCredentials credentials : players) {
- + if (credentials.getUniqueId().equals(playerId)) {
- return true;
- }
- -
- +
- }
- -
- +
- return false;
- }
- -
- +
- /**
- - * Returns whether or not this group contains an IP or a player
- - * @param player
- + * Returns whether or not this group contains a player ID or IP
- + * @param playerId
- * @param ip
- - * @return
- + * @return
- */
- - public boolean containsIPOrPlayer(String player, String ip) {
- - return containsIP(ip) || containsPlayer(player);
- + public boolean containsIPOrPlayer(UUID playerId, String ip) {
- + return containsIP(ip) || containsPlayerId(playerId);
- }
- }
- diff --git a/src/net/innectis/innplugin/BanSystem/IPBanObject.java b/src/net/innectis/innplugin/BanSystem/IPBanObject.java
- index 238da8e4b..1d321ebea 100644
- --- a/src/net/innectis/innplugin/BanSystem/IPBanObject.java
- +++ b/src/net/innectis/innplugin/BanSystem/IPBanObject.java
- @@ -7,6 +7,7 @@ import java.sql.Timestamp;
- import java.util.List;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- /**
- * @author AlphaBlend
- @@ -16,30 +17,12 @@ import net.innectis.innplugin.InnPlugin;
- public class IPBanObject extends BanObject {
- private IPBanGroup group;
- - /**
- - *
- - * @param group
- - * @param bannedBy
- - * @param bannedTime
- - * @param durationTicks
- - * @param joinBan
- - */
- - public IPBanObject(IPBanGroup group, String bannedBy, Timestamp bannedTime, long durationTicks, boolean joinBan) {
- - this(0, group, bannedBy, bannedTime, durationTicks, joinBan);
- + public IPBanObject(IPBanGroup group, PlayerCredentials bannedByCredentials, Timestamp bannedTime, long durationTicks, boolean joinBan) {
- + this(0, group, bannedByCredentials, bannedTime, durationTicks, joinBan);
- }
- - /**
- - * Constructor for an existing IPBan
- - * @param ID
- - * @param groupid
- - * @param group
- - * @param bannedBy
- - * @param bannedTime
- - * @param durationTicks
- - * @param joinBan
- - */
- - public IPBanObject(int ID, IPBanGroup group, String bannedBy, Timestamp bannedTime, long durationTicks, boolean joinBan) {
- - super(ID, bannedBy, bannedTime, durationTicks, joinBan);
- + public IPBanObject(int ID, IPBanGroup group, PlayerCredentials bannedByCredentials, Timestamp bannedTime, long durationTicks, boolean joinBan) {
- + super(ID, bannedByCredentials, bannedTime, durationTicks, joinBan);
- this.group = group;
- }
- @@ -53,11 +36,11 @@ public class IPBanObject extends BanObject {
- /**
- * Copies the IPs and players from an IPBan Group to this IPBan
- - * @param object
- + * @param group
- */
- public void copyFromGroup(IPBanGroup group) {
- List<String> ips = group.getIPs();
- - List<String> players = group.getPlayers();
- + List<PlayerCredentials> players = group.getPlayers();
- for (String IP : ips) {
- if (!this.group.containsIP(IP)) {
- @@ -65,9 +48,9 @@ public class IPBanObject extends BanObject {
- }
- }
- - for (String player : players) {
- - if (!this.group.containsPlayer(player)) {
- - this.group.addPlayer(player);
- + for (PlayerCredentials credentials : players) {
- + if (!this.group.containsPlayerId(credentials.getUniqueId())) {
- + this.group.addPlayer(credentials);
- }
- }
- }
- @@ -79,7 +62,7 @@ public class IPBanObject extends BanObject {
- */
- public boolean isPartOfThis(IPBanGroup group) {
- List<String> ips = group.getIPs();
- - List<String> players = group.getPlayers();
- + List<PlayerCredentials> players = group.getPlayers();
- for (String ip : ips) {
- if (this.group.containsIP(ip)) {
- @@ -87,8 +70,8 @@ public class IPBanObject extends BanObject {
- }
- }
- - for (String player : players) {
- - if (this.group.containsPlayer(player)) {
- + for (PlayerCredentials credentials : players) {
- + if (this.group.containsPlayerId(credentials.getUniqueId())) {
- return true;
- }
- }
- @@ -115,31 +98,33 @@ public class IPBanObject extends BanObject {
- }
- }
- - String playerList = null;
- + String playerIdList = null;
- +
- + for (PlayerCredentials pc : group.getPlayers()) {
- + String playerId = pc.getUniqueId().toString();
- - for (String player : group.getPlayers()) {
- - if (playerList == null) {
- - playerList = player;
- + if (playerIdList == null) {
- + playerIdList = playerId;
- } else {
- - playerList += ", " + player;
- + playerIdList += ", " + playerId;
- }
- }
- if (getId() > 0) {
- - statement = DBManager.prepareStatement("UPDATE banned_ip_players SET iplist = ?, userlist = ?, banned_by = ?, banned_time = ?, duration_ticks = ?, joinban = ? WHERE ID = ?");
- + statement = DBManager.prepareStatement("UPDATE banned_ip_players SET iplist = ?, player_id_list = ?, banned_by_player_id = ?, banned_time = ?, duration_ticks = ?, joinban = ? WHERE ID = ?");
- statement.setString(1, ipList);
- - statement.setString(2, playerList);
- - statement.setString(3, getBannedBy());
- + statement.setString(2, playerIdList);
- + statement.setString(3, super.getBannedByCredentials().getUniqueId().toString());
- statement.setTimestamp(4, getBannedTime());
- statement.setLong(5, getDurationTicks());
- statement.setBoolean(6, isJoinBan());
- statement.setInt(7, getId());
- statement.executeUpdate();
- } else {
- - statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO banned_ip_players (iplist, userlist, banned_by, banned_time, duration_ticks, joinban) VALUES (?, ?, ?, ?, ?, ?)");
- + statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO banned_ip_players (iplist, player_id_list, banned_by_player_id, banned_time, duration_ticks, joinban) VALUES (?, ?, ?, ?, ?, ?)");
- statement.setString(1, ipList);
- - statement.setString(2, playerList);
- - statement.setString(3, getBannedBy());
- + statement.setString(2, playerIdList);
- + statement.setString(3, super.getBannedByCredentials().getUniqueId().toString());
- statement.setTimestamp(4, getBannedTime());
- statement.setLong(5, getDurationTicks());
- statement.setBoolean(6, isJoinBan());
- diff --git a/src/net/innectis/innplugin/BanSystem/UserBanObject.java b/src/net/innectis/innplugin/BanSystem/UserBanObject.java
- index 8a4f68b39..5892c02f5 100644
- --- a/src/net/innectis/innplugin/BanSystem/UserBanObject.java
- +++ b/src/net/innectis/innplugin/BanSystem/UserBanObject.java
- @@ -6,6 +6,7 @@ import java.sql.SQLException;
- import java.sql.Timestamp;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- /**
- * An object of a single username ban
- @@ -13,63 +14,63 @@ import net.innectis.innplugin.InnPlugin;
- * @author AlphaBlend
- */
- public class UserBanObject extends BanObject {
- -
- - private String username = null;
- + private PlayerCredentials bannedPlayerCredentials = null;
- /**
- * Constructor for setting up a fresh ban
- - * @param username
- - * @param bannedBy
- + * @param bannedPlayerCredentials
- + * @param bannedByPlayerCredentials
- * @param bannedTime
- * @param durationTicks
- * @param joinBan
- */
- - public UserBanObject(String username, String bannedBy, Timestamp bannedTime, long durationTicks, boolean joinBan) {
- - this(0, username, bannedBy, bannedTime, durationTicks, joinBan);
- + public UserBanObject(PlayerCredentials bannedPlayerCredentials, PlayerCredentials bannedByPlayerCredentials, Timestamp bannedTime, long durationTicks, boolean joinBan) {
- + this(0, bannedPlayerCredentials, bannedByPlayerCredentials, bannedTime, durationTicks, joinBan);
- }
- /**
- * Constructor for an already existing ban
- - * @param username
- - * @param bannedBy
- + * @paran id
- + * @param bannedPlayer
- + * @param bannedByPlayer
- * @param bannedTime
- * @param durationTicks
- * @param joinBan
- */
- - public UserBanObject(int id, String username, String bannedBy, Timestamp bannedTime, long durationTicks, boolean joinBan) {
- - super(id, bannedBy, bannedTime, durationTicks, joinBan);
- - this.username = username;
- + public UserBanObject(int id, PlayerCredentials bannedPlayer, PlayerCredentials bannedByPlayer, Timestamp bannedTime, long durationTicks, boolean joinBan) {
- + super(id, bannedByPlayer, bannedTime, durationTicks, joinBan);
- + this.bannedPlayerCredentials = bannedPlayer;
- }
- /**
- * Gets the username associated with this ban
- * @return
- */
- - public String getUsername() {
- - return username;
- + public PlayerCredentials getBannedPlayerCredentials() {
- + return bannedPlayerCredentials;
- }
- /**
- * Saves this username ban to the database
- - * @param update
- */
- + @Override
- public void save() {
- PreparedStatement statement = null;
- ResultSet set = null;
- try {
- if (getId() > 0) {
- - statement = DBManager.prepareStatement("UPDATE banned_players SET banned_by = ?, banned_time = ?, duration_ticks = ?, joinban = ? WHERE ID = ?");
- - statement.setString(1, getBannedBy());
- + statement = DBManager.prepareStatement("UPDATE banned_players SET banned_by_player_id = ?, banned_time = ?, duration_ticks = ?, joinban = ? WHERE ID = ?");
- + statement.setString(1, super.getBannedByCredentials().getUniqueId().toString());
- statement.setTimestamp(2, getBannedTime());
- statement.setLong(3, getDurationTicks());
- statement.setBoolean(4, isJoinBan());
- statement.setInt(5, getId());
- statement.executeUpdate();
- } else {
- - statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO banned_players (username, banned_by, banned_time, duration_ticks, joinban) VALUES (?, ?, ?, ?, ?)");
- - statement.setString(1, getUsername());
- - statement.setString(2, getBannedBy());
- + statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO banned_players (player_id, banned_by_player_id, banned_time, duration_ticks, joinban) VALUES (?, ?, ?, ?, ?)");
- + statement.setString(1, bannedPlayerCredentials.getUniqueId().toString());
- + statement.setString(2, super.getBannedByCredentials().getUniqueId().toString());
- statement.setTimestamp(3, getBannedTime());
- statement.setLong(4, getDurationTicks());
- statement.setBoolean(5, isJoinBan());
- @@ -82,7 +83,7 @@ public class UserBanObject extends BanObject {
- }
- }
- } catch (SQLException ex) {
- - InnPlugin.logError("Unable to save " + username + "'s ban!", ex);
- + InnPlugin.logError("Unable to save " + bannedPlayerCredentials.getName() + "'s ban!", ex);
- } finally {
- DBManager.closeResultSet(set);
- DBManager.closePreparedStatement(statement);
- @@ -102,7 +103,7 @@ public class UserBanObject extends BanObject {
- statement.setInt(2, getId());
- statement.execute();
- } catch (SQLException ex) {
- - InnPlugin.logError("Unable to save " + username + "'s ban!", ex);
- + InnPlugin.logError("Unable to save " + bannedPlayerCredentials.getName() + "'s ban!", ex);
- } finally {
- DBManager.closePreparedStatement(statement);
- }
- diff --git a/src/net/innectis/innplugin/Command/Commands/AdminCommands.java b/src/net/innectis/innplugin/Command/Commands/AdminCommands.java
- index 146ace789..d41b51c40 100644
- --- a/src/net/innectis/innplugin/Command/Commands/AdminCommands.java
- +++ b/src/net/innectis/innplugin/Command/Commands/AdminCommands.java
- @@ -390,15 +390,21 @@ public final class AdminCommands {
- hiddenCommand = true)
- public static boolean commandPerm(InnPlugin parent, IdpCommandSender<? extends CommandSender> sender, LynxyArguments args) {
- if (args.getActionSize() > 1) {
- - IdpPlayer target = parent.getPlayer(args.getString(0));
- - String username = (target != null ? target.getName() : args.getString(0));
- + String playerName = args.getString(0);
- + IdpPlayer target = parent.getPlayer(playerName);
- + PlayerSession session = null;
- - PlayerSession session = (target != null ? target.getSession() : PlayerSession.getSession(username, parent));
- + if (target != null) {
- + session = target.getSession();
- + } else {
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- - if (!session.isValidPlayer()) {
- - session.destroy();
- - sender.printError("That user doesn't exist.");
- - return true;
- + if (credentials == null) {
- + sender.printError("That player does not exist.");
- + return true;
- + }
- +
- + session = PlayerSession.getSession(credentials.getUniqueId(), credentials.getName(), parent, true);
- }
- int permID = 0;
- @@ -477,9 +483,10 @@ public final class AdminCommands {
- }
- for (ModifiablePermissions perms : permList) {
- + PlayerCredentials credentials = perms.getCredentials();
- String username = perms.getUsername();
- + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(credentials.getUniqueId());
- - PlayerGroup group = PlayerGroup.getGroupOfUsername(username);
- String coloredUsername = group.getPrefix().getTextColor() + username;
- lines.add(ChatColor.DARK_GREEN + "Showing modified permissions for " + coloredUsername);
- @@ -507,14 +514,21 @@ public final class AdminCommands {
- }
- }
- } else {
- - IdpPlayer target = InnPlugin.getPlugin().getPlayer(args.getString("list", "l"));
- - String player = (target != null ? target.getName() : args.getString("list", "l"));
- - PlayerSession session = (target != null ? target.getSession() : PlayerSession.getSession(player, parent));
- + String playerName = args.getString("list", "l");
- + IdpPlayer target = InnPlugin.getPlugin().getPlayer(playerName);
- + PlayerSession session = null;
- - if (!session.isValidPlayer()) {
- - session.destroy();
- - sender.printError("That player doesn't exist.");
- - return true;
- + if (target != null) {
- + session = target.getSession();
- + } else {
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- +
- + if (credentials == null) {
- + sender.printError("That player does not exist.");
- + return true;
- + }
- +
- + session = PlayerSession.getSession(credentials.getUniqueId(), credentials.getName(), parent, true);
- }
- ModifiablePermissions perms = session.getModifiablePermissions();
- @@ -561,16 +575,21 @@ public final class AdminCommands {
- return true;
- } else if (args.hasArgument("reset", "reload")) {
- - IdpPlayer target = InnPlugin.getPlugin().getPlayer(args.getString("reset", "reload"));
- - String playerName = (target != null ? target.getName() : args.getString("reset", "reload"));
- - PlayerSession session = (target != null ? target.getSession() : PlayerSession.getSession(playerName, parent));
- - PlayerGroup group = session.getGroup();
- + String playerName = args.getString("reset", "reload");
- + IdpPlayer target = parent.getPlayer(playerName);
- + PlayerSession session = null;
- + if (target != null) {
- + session = target.getSession();
- + } else {
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- - if (!session.isValidPlayer()) {
- - session.destroy();
- - sender.printError("That player doesn't exist.");
- - return true;
- + if (credentials == null) {
- + sender.printError("That player does not exist.");
- + return true;
- + }
- +
- + session = PlayerSession.getSession(credentials.getUniqueId(), credentials.getName(), parent, true);
- }
- ModifiablePermissions perms = session.getModifiablePermissions();
- @@ -580,6 +599,7 @@ public final class AdminCommands {
- return true;
- }
- + PlayerGroup group = session.getGroup();
- List<Integer> addedPerms = perms.getPermissionIDByType(PermissionType.ADDITIONAL);
- for (int permID : addedPerms) {
- @@ -619,18 +639,20 @@ public final class AdminCommands {
- }
- String playerName = args.getString(0);
- - IdpPlayer target = parent.getPlayer(playerName, false);
- + IdpPlayer target = parent.getPlayer(playerName);
- + PlayerCredentials credentials = null;
- - // Check for validity of player if they are not online
- - if (target == null) {
- - if (!PlayerSession.isValidPlayer(playerName)) {
- - sender.printError("That is not a valid player!");
- - return true;
- - }
- - } else {
- + if (target != null) {
- playerName = target.getName();
- }
- + credentials = PlayerCredentialsManager.getByName(playerName);
- +
- + if (credentials == null) {
- + sender.printError("That is not a valid player!");
- + return true;
- + }
- +
- boolean useLiveInventory = false;
- if (target != null && target.isOnline()) {
- @@ -656,7 +678,7 @@ public final class AdminCommands {
- if (sender.isPlayer()) {
- IdpPlayer player = (IdpPlayer) sender;
- - player.getSession().setInventoryView(playerName, type);
- + player.getSession().setInventoryView(credentials.getUniqueId(), credentials.getName(), type);
- if (useLiveInventory) {
- player.openInventory(new IdpInventory(target));
- @@ -666,7 +688,7 @@ public final class AdminCommands {
- type = player.getInventory().getType();
- }
- - IdpPlayerInventory inv = IdpPlayerInventory.load(playerName, type, parent);
- + IdpPlayerInventory inv = IdpPlayerInventory.load(credentials.getUniqueId(), playerName, type, parent);
- IdpInventory inventory = new IdpInventory(playerName + " (" + type.getName() + ")", 45);
- inventory.setContents(inv.getItems(), 0);
- @@ -674,7 +696,7 @@ public final class AdminCommands {
- player.openInventory(inventory);
- }
- } else {
- - List<String> strings = listInventoryAsString(parent, type, playerName);
- + List<String> strings = listInventoryAsString(parent, type, credentials.getUniqueId(), playerName);
- for (int i = 0; i < strings.size(); i++) {
- sender.printInfo(ChatColor.WHITE + strings.get(i));
- @@ -815,7 +837,7 @@ public final class AdminCommands {
- DBManager.closeResultSet(result);
- DBManager.closePreparedStatement(statement);
- - statement = DBManager.prepareStatement("SELECT ID, username, homeid, world, locx, locy, locz FROM homes;");
- + statement = DBManager.prepareStatement("SELECT ID, player_id, homeid, world, locx, locy, locz FROM homes;");
- result = statement.executeQuery();
- while (result.next()) {
- @@ -828,11 +850,15 @@ public final class AdminCommands {
- Location loc = new Location(world, x, y, z);
- InnectisLot lot = LotHandler.getLot(loc);
- - String username = result.getString("username");
- - if (lot != null && !lot.getOwner().equalsIgnoreCase(username) && !lot.containsMember(username) && !lot.containsOperator(username)) {
- + String playerIdString = result.getString("player_id");
- + UUID playerId = UUID.fromString(playerIdString);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(playerId);
- + String name = credentials.getName();
- +
- + if (lot != null && !lot.getOwner().equalsIgnoreCase(name) && !lot.containsMember(name) && !lot.containsOperator(name)) {
- // If player is online make sure to delete the reference to their home
- - IdpPlayer testPlayer = parent.getPlayer(username);
- + IdpPlayer testPlayer = parent.getPlayer(credentials.getUniqueId());
- if (testPlayer != null) {
- int homeId = result.getInt("homeid");
- @@ -922,8 +948,8 @@ public final class AdminCommands {
- } else if (lot.getOwner().length() == 1) {
- break;
- } else {
- - statement = DBManager.prepareStatement("SELECT onlinetime FROM players WHERE name = ?;");
- - statement.setString(1, lot.getOwner());
- + statement = DBManager.prepareStatement("SELECT onlinetime FROM players WHERE player_id = ?;");
- + statement.setString(1, lot.getOwnerCredentials().getUniqueId().toString());
- result = statement.executeQuery();
- if (!(result.next() && result.getFloat("onlinetime") > 10800000)) { //3 hours
- @@ -990,16 +1016,21 @@ public final class AdminCommands {
- }
- }
- - String username = null;
- + String playerName = null;
- + PlayerCredentials credentials = null;
- IdpPlayer targ = null;
- if (args.getString("player", "p") != null) {
- - targ = parent.getPlayer(args.getString("player", "p"));
- - username = (targ != null ? targ.getName() : args.getString("player", "p"));
- + playerName = args.getString("player", "p");
- + targ = parent.getPlayer(playerName);
- +
- + if (targ != null) {
- + playerName = targ.getName();
- + }
- - PlayerGroup group = PlayerGroup.getGroupOfUsername(username);
- + credentials = PlayerCredentialsManager.getByName(playerName);
- - if (group == PlayerGroup.NONE) {
- + if (credentials == null) {
- sender.printError("Player not found.");
- return true;
- }
- @@ -1043,7 +1074,7 @@ public final class AdminCommands {
- if (count > 0 && ((count <= amount && useAsMax) || count >= amount && !useAsMax)) {
- hasCount = true;
- - sender.print(ChatColor.LIGHT_PURPLE, "Count of items in " + username + "'s backpack matching filter: " + amount);
- + sender.print(ChatColor.LIGHT_PURPLE, "Count of items in " + playerName + "'s backpack matching filter: " + amount);
- }
- }
- @@ -1056,9 +1087,9 @@ public final class AdminCommands {
- List<InnectisChest> chests = null;
- - if (username != null) {
- - chests = ChestHandler.getChests(username);
- - sender.print(ChatColor.LIGHT_PURPLE, "Searching all " + chests.size() + " of " + username + "'s chests for " + matString + ":");
- + if (credentials != null) {
- + chests = ChestHandler.getChests(playerName);
- + sender.print(ChatColor.LIGHT_PURPLE, "Searching all " + chests.size() + " of " + playerName + "'s chests for " + matString + ":");
- } else {
- chests = ChestHandler.getAllChests();
- sender.print(ChatColor.LIGHT_PURPLE, "Searching all " + chests.size() + " chests for " + matString + ":");
- @@ -1077,18 +1108,18 @@ public final class AdminCommands {
- List<EnderChestContents> enderChestContents = new ArrayList<EnderChestContents>();
- - if (username != null) {
- + if (playerName != null) {
- List<EnderContentsType> types = EnderChestContents.getAllEnderContentTypes();
- for (EnderContentsType ect : types) {
- - EnderChestContents contents = EnderChestContents.getContents(username, ect);
- + EnderChestContents contents = EnderChestContents.getContents(credentials, ect);
- if (contents != null) {
- enderChestContents.add(contents);
- }
- }
- - sender.print(ChatColor.LIGHT_PURPLE, "Searching " + enderChestContents.size() + " of " + username + "'s ender chests for " + matString + ":");
- + sender.print(ChatColor.LIGHT_PURPLE, "Searching " + enderChestContents.size() + " of " + playerName + "'s ender chests for " + matString + ":");
- } else {
- enderChestContents = EnderChestContents.getAllChestContents();
- sender.print(ChatColor.LIGHT_PURPLE, "Searching " + enderChestContents.size() + " ender chests for " + matString + ":");
- @@ -1097,7 +1128,7 @@ public final class AdminCommands {
- final IdpCommandSender<? extends CommandSender> finalSender = sender;
- final List<ChestDetails> finalChestDetailsList = chestDetailsList;
- final List<EnderChestContents> finalEnderChestContents = enderChestContents;
- - final String finalUsername = username;
- + final String finalUsername = playerName;
- final int finalAmount = amount;
- final Thread thread = new Thread(new Runnable() {
- @@ -1204,7 +1235,7 @@ public final class AdminCommands {
- return true;
- }
- - if (BlockLockHandler.lockBlock(player, loc)) {
- + if (BlockLockHandler.lockBlock(player.getUniqueId(), loc)) {
- player.printInfo("Block (" + loc.getBlockX() + ", " + loc.getBlockY() + ", " + loc.getBlockZ() + ") is now locked!");
- } else {
- player.printError("Failed to lock, notify an Admin!");
- @@ -1248,9 +1279,22 @@ public final class AdminCommands {
- permission = Permission.command_admin_openenderchest,
- usage = "/openenderchest <player> [world]",
- serverCommand = false)
- - public static boolean commandOpenEnderChest(IdpPlayer player, ParameterArguments args) {
- + public static boolean commandOpenEnderChest(InnPlugin parent, IdpPlayer player, ParameterArguments args) {
- if (args.size() > 0) {
- - String user = args.getString(0);
- + String playerName = args.getString(0);
- + IdpPlayer target = parent.getPlayer(playerName);
- +
- + if (target != null) {
- + playerName = target.getName();
- + }
- +
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- +
- + if (credentials == null) {
- + player.printError("That player does not exist.");
- + return true;
- + }
- +
- IdpWorld world = player.getWorld();
- EnderContentsType type = world.getSettings().getEnderchestType();
- @@ -1269,13 +1313,13 @@ public final class AdminCommands {
- return true;
- }
- - EnderChestContents contents = EnderChestContents.getContents(user, world.getSettings().getEnderchestType());
- - EnderChestView view = InnPlugin.getPlugin().getEnderChestView(user, type);
- + EnderChestContents contents = EnderChestContents.getContents(credentials, world.getSettings().getEnderchestType());
- + EnderChestView view = InnPlugin.getPlugin().getEnderChestView(credentials.getUniqueId(), type);
- Inventory inventory = null;
- if (view == null) {
- - inventory = new IdpInventory(user + " (" + type.name().toLowerCase() + ")", IdpInventory.DEFAULT_CHEST_SIZE);
- - InnPlugin.getPlugin().addEnderChestView(new EnderChestView(user, type, inventory));
- + inventory = new IdpInventory(playerName + " (" + type.name().toLowerCase() + ")", IdpInventory.DEFAULT_CHEST_SIZE);
- + InnPlugin.getPlugin().addEnderChestView(new EnderChestView(credentials.getUniqueId(), type, inventory));
- int idx = 0;
- for (IdpItemStack stack : contents.getItems()) {
- @@ -1288,11 +1332,12 @@ public final class AdminCommands {
- }
- PlayerSession session = player.getSession();
- - session.setEnderchestOwner(user);
- + session.setEnderchestOwner(credentials.getName());
- + session.setEnderchestOwnerId(credentials.getUniqueId());
- session.setEnderchestType(type);
- session.setViewingEnderChest(true);
- - player.printInfo("You opened the ender chest contents of " + user + " in " + world.getName() + " (Type: " + type.name() + ")");
- + player.printInfo("You opened the ender chest contents of " + playerName + " in " + world.getName() + " (Type: " + type.name() + ")");
- player.getHandle().openInventory(inventory);
- return true;
- }
- @@ -1442,19 +1487,21 @@ public final class AdminCommands {
- hiddenCommand = true)
- public static boolean commandSetGroup(InnPlugin parent, IdpCommandSender<? extends CommandSender> sender, String[] args) {
- if (args.length == 2) {
- + String playerName = args[0];
- + IdpPlayer targetPlayer = parent.getPlayer(playerName);
- PlayerSession targetSession = null;
- - IdpPlayer targetPlayer = parent.getPlayer(args[0], false);
- - if (targetPlayer == null) {
- - targetSession = PlayerSession.getSession(args[0], parent);
- - // Stop when player has no onlinetime
- - if (!targetSession.isValidPlayer()) {
- - targetSession.destroy();
- - sender.printError("That player doesn't exist!");
- + if (targetPlayer != null) {
- + targetSession = targetPlayer.getSession();
- + } else {
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- +
- + if (credentials == null) {
- + sender.printError("That player does not exist.");
- return true;
- }
- - } else {
- - targetSession = targetPlayer.getSession();
- +
- + targetSession = PlayerSession.getSession(credentials.getUniqueId(), credentials.getName(), parent, true);
- }
- PlayerGroup group;
- @@ -1715,8 +1762,8 @@ public final class AdminCommands {
- * @param playerName
- * @return
- */
- - private static List<String> listInventoryAsString(InnPlugin parent, InventoryType type, String playerName) {
- - IdpPlayer player = parent.getPlayer(playerName);
- + private static List<String> listInventoryAsString(InnPlugin parent, InventoryType type, UUID playerId, String playerName) {
- + IdpPlayer player = parent.getPlayer(playerId);
- IdpPlayerInventory inv = null;
- if (player != null) {
- @@ -1725,10 +1772,10 @@ public final class AdminCommands {
- // Not viewing the same type, so load the specified type
- if (type != playerInventoryType) {
- - inv = IdpPlayerInventory.load(playerName, type, parent);
- + inv = IdpPlayerInventory.load(playerId, playerName, type, parent);
- }
- } else {
- - inv = IdpPlayerInventory.load(playerName, type, parent);
- + inv = IdpPlayerInventory.load(playerId, playerName, type, parent);
- }
- IdpItemStack[] items1 = inv.getItems();
- diff --git a/src/net/innectis/innplugin/Command/Commands/ChatCommands.java b/src/net/innectis/innplugin/Command/Commands/ChatCommands.java
- index 77d9d6724..1382df778 100644
- --- a/src/net/innectis/innplugin/Command/Commands/ChatCommands.java
- +++ b/src/net/innectis/innplugin/Command/Commands/ChatCommands.java
- @@ -7,6 +7,7 @@ import java.util.HashSet;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- +import java.util.UUID;
- import java.util.regex.Pattern;
- import net.innectis.innplugin.Command.CommandMethod;
- import net.innectis.innplugin.Command.CommandName;
- @@ -20,14 +21,16 @@ import net.innectis.innplugin.Loggers.ChatLogger;
- import net.innectis.innplugin.Loggers.LogManager;
- import net.innectis.innplugin.Player.Channel.ChannelSettings;
- import net.innectis.innplugin.Player.Channel.ChatChannel;
- -import net.innectis.innplugin.Player.Channel.ChatChannelHandler;
- import net.innectis.innplugin.Player.Channel.ChatChannelGroup;
- +import net.innectis.innplugin.Player.Channel.ChatChannelHandler;
- import net.innectis.innplugin.Player.Channel.MemberDetails;
- import net.innectis.innplugin.Player.Chat.ChatColor;
- import net.innectis.innplugin.Player.Chat.ChatMessage;
- import net.innectis.innplugin.Player.Chat.Prefix;
- import net.innectis.innplugin.Player.IdpPlayer;
- import net.innectis.innplugin.Player.Permission;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Player.PlayerGroup;
- import net.innectis.innplugin.Player.PlayerSession;
- import net.innectis.innplugin.Utility.LynxyArguments;
- @@ -572,8 +575,7 @@ public final class ChatCommands {
- permission = Permission.command_misc_chatchannel_join,
- usage = "/join <channel> [-setpass, -sp <password>] [-pass, -password, -p <password>] [-hide, -h]",
- serverCommand = false)
- - public static boolean commandJoin(InnPlugin parent, IdpCommandSender<? extends CommandSender> sender, LynxyArguments args) {
- - IdpPlayer player = (IdpPlayer) sender;
- + public static boolean commandJoin(InnPlugin parent, IdpPlayer player, LynxyArguments args) {
- if (args.getActionSize() == 0) {
- return false;
- }
- @@ -619,7 +621,8 @@ public final class ChatCommands {
- }
- }
- - MemberDetails details = channel.addMember(player.getName(), ChatChannelGroup.MEMBER, player.getSession().makeNextChannelAndNumber(channelName), true);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName(), true);
- + MemberDetails details = channel.addMember(credentials, ChatChannelGroup.MEMBER, player.getSession().makeNextChannelAndNumber(channelName), true);
- details.setOnline(true);
- channel.sendGeneralMessage(player.getColoredName() + ChatColor.AQUA + " has joined the channel.");
- } else {
- @@ -638,7 +641,8 @@ public final class ChatCommands {
- }
- ChatChannel channel = ChatChannelHandler.createChannel(channelName, settings, password);
- - MemberDetails details = channel.addMember(player.getName(), ChatChannelGroup.OWNER, player.getSession().makeNextChannelAndNumber(channelName), true);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName(), true);
- + MemberDetails details = channel.addMember(credentials, ChatChannelGroup.OWNER, player.getSession().makeNextChannelAndNumber(channelName), true);
- details.setOnline(true);
- channel.sendGeneralMessage(player.getColoredName() + ChatColor.AQUA + " has joined the channel.");
- }
- @@ -798,27 +802,37 @@ public final class ChatCommands {
- }
- if (args.hasArgument("giveup", "gu")) {
- - String targUser = args.getString("giveup", "gu");
- + String playerName = args.getString("giveup", "gu");
- + IdpPlayer target = parent.getPlayer(playerName);
- +
- + if (target != null) {
- + playerName = target.getName();
- + }
- +
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- - if (!PlayerSession.isValidPlayer(targUser)) {
- - sender.printError("That player doesn't exist.");
- + if (credentials == null) {
- + sender.printError("That player does not exist.");
- return true;
- + } else {
- + // Get the proper casing of the name
- + playerName = credentials.getName();
- }
- - if (!channel.containsMember(targUser)) {
- + if (!channel.containsMember(playerName)) {
- sender.printError("That player isn't part of this channel!");
- return true;
- }
- - MemberDetails details = channel.getMemberDetails(targUser);
- + MemberDetails details = channel.getMemberDetails(playerName);
- if (details.getGroup() == ChatChannelGroup.OWNER) {
- sender.printError("This player is already the owner!");
- return true;
- }
- - String coloredName = getColoredName(targUser, parent);
- - channel.switchOwner(targUser);
- + String coloredName = getColoredName(playerName, parent);
- + channel.switchOwner(credentials);
- channel.sendGeneralMessage("The owner has been changed to " + coloredName + ChatColor.AQUA + "!");
- if (!channel.containsMember(sender.getName())) {
- @@ -827,23 +841,28 @@ public final class ChatCommands {
- return true;
- } else if (args.hasArgument("op", "deop")) {
- - String targUser = args.getString("op", "deop");
- + String playerName = args.getString("op", "deop");
- + IdpPlayer target = parent.getPlayer(playerName);
- - if (!PlayerSession.isValidPlayer(targUser)) {
- - sender.printError("That player doesn't exist!");
- - return true;
- + if (target != null) {
- + playerName = target.getName();
- }
- - if (targUser.equalsIgnoreCase(sender.getName())) {
- - sender.printError("You cannot use this command on yourself!");
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- +
- + if (credentials == null) {
- + sender.printError("That player doesn't exist!");
- return true;
- + } else {
- + // Get the proper casing of the name
- + playerName = credentials.getName();
- }
- - String coloredName = getColoredName(targUser, parent);
- + String coloredName = getColoredName(playerName, parent);
- boolean doOp = args.hasArgument("op");
- - if (channel.containsMember(targUser)) {
- - MemberDetails memberDetails = channel.getMemberDetails(targUser);
- + if (channel.containsMember(playerName)) {
- + MemberDetails memberDetails = channel.getMemberDetails(playerName);
- if (memberDetails.getGroup().equals(ChatChannelGroup.OWNER)) {
- sender.printError("Cannot op or deop the channel owner.");
- @@ -857,7 +876,7 @@ public final class ChatCommands {
- return true;
- }
- - channel.modifyMemberGroup(targUser, checkGroup);
- + channel.modifyMemberGroup(playerName, checkGroup);
- if (channel.isCached()) {
- channel.sendGeneralMessage(coloredName + ChatColor.AQUA + " is " + (doOp ? "now" : "no longer") + " an operator!");
- @@ -872,28 +891,38 @@ public final class ChatCommands {
- return true;
- } else if (args.hasArgument("kick", "k")) {
- - String targUser = args.getString("kick", "k");
- + String playerName = args.getString("kick", "k");
- + IdpPlayer target = parent.getPlayer(playerName);
- - if (!PlayerSession.isValidPlayer(targUser)) {
- + if (target != null) {
- + playerName = target.getName();
- + }
- +
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- +
- + if (credentials == null) {
- sender.printError("That player doesn't exist!");
- return true;
- + } else {
- + // Get the proper casing of the name
- + playerName = credentials.getName();
- }
- - if (targUser.equalsIgnoreCase(sender.getName())) {
- + if (playerName.equalsIgnoreCase(sender.getName())) {
- sender.printError("You cannot kick yourself!");
- return true;
- }
- - if (!canModerate(targUser, parent) && !(sender.hasPermission(Permission.special_chatroom_override))) {
- + if (!canModerate(playerName, parent) && !(sender.hasPermission(Permission.special_chatroom_override))) {
- sender.printError("That player cannot be kicked.");
- return true;
- }
- - String coloredName = getColoredName(targUser, parent);
- + String coloredName = getColoredName(playerName, parent);
- - if (channel.containsMember(targUser)) {
- + if (channel.containsMember(playerName)) {
- MemberDetails senderDetails = channel.getMemberDetails(sender.getName());
- - MemberDetails memberDetails = channel.getMemberDetails(targUser);
- + MemberDetails memberDetails = channel.getMemberDetails(playerName);
- if (!memberDetails.getGroup().equalsOrInherits(ChatChannelGroup.OPERATOR)
- || (senderDetails != null && senderDetails.getGroup().equals(ChatChannelGroup.OWNER))
- @@ -903,7 +932,7 @@ public final class ChatCommands {
- channel.sendGeneralMessage(coloredName + ChatColor.AQUA + " has left the channel!");
- }
- - channel.removeMember(targUser);
- + channel.removeMember(playerName);
- if (!channel.containsMember(sender.getName())) {
- sender.printInfo(coloredName + ChatColor.AQUA + " has been kicked from channel " + channel.getName() + "!");
- @@ -923,30 +952,40 @@ public final class ChatCommands {
- return true;
- } else if (args.hasArgument("ban", "b")) {
- - String targUser = args.getString("ban", "b");
- + String playerName = args.getString("ban", "b");
- + IdpPlayer target = parent.getPlayer(playerName);
- - if (targUser.equalsIgnoreCase(sender.getName())) {
- - sender.printError("You cannot ban yourself!");
- + if (target != null) {
- + playerName = target.getName();
- + }
- +
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- +
- + if (credentials == null) {
- + sender.printError("That player does not exist.");
- return true;
- + } else {
- + // Get the proper casing of the name
- + playerName = credentials.getName();
- }
- - if (!PlayerSession.isValidPlayer(targUser)) {
- - sender.printError("That player doesn't exist.");
- + if (playerName.equalsIgnoreCase(sender.getName())) {
- + sender.printError("You cannot ban yourself!");
- return true;
- }
- - if (!canModerate(targUser, parent) && !(sender.hasPermission(Permission.special_chatroom_override))) {
- + if (!canModerate(playerName, parent) && !(sender.hasPermission(Permission.special_chatroom_override))) {
- sender.printError("That user cannot be banned.");
- return true;
- }
- - if (channel.isBanned(targUser)) {
- - sender.printError(targUser + " is already banned from that channel!");
- + if (channel.isBanned(playerName)) {
- + sender.printError(playerName + " is already banned from that channel!");
- return true;
- }
- - String coloredName = getColoredName(targUser, parent);
- - MemberDetails memberDetails = channel.getMemberDetails(targUser);
- + String coloredName = getColoredName(playerName, parent);
- + MemberDetails memberDetails = channel.getMemberDetails(playerName);
- MemberDetails senderDetails = channel.getMemberDetails(sender.getName());
- if ((memberDetails == null || !memberDetails.getGroup().equalsOrInherits(ChatChannelGroup.OPERATOR)
- @@ -956,8 +995,8 @@ public final class ChatCommands {
- channel.sendGeneralMessage(coloredName + ChatColor.RED + " has been banned from the channel!");
- }
- - if (channel.containsMember(targUser)) {
- - channel.removeMember(targUser);
- + if (channel.containsMember(playerName)) {
- + channel.removeMember(playerName);
- channel.sendGeneralMessage(coloredName + ChatColor.AQUA + " has left the channel!");
- }
- @@ -965,7 +1004,7 @@ public final class ChatCommands {
- if (channel.isEmpty()) {
- ChatChannelHandler.deleteChannel(channel);
- } else {
- - channel.addBanned(targUser);
- + channel.addBanned(credentials);
- if (!channel.containsMember(sender.getName())) {
- sender.printInfo(coloredName + ChatColor.RED + " has been banned from the channel " + channel.getName() + "!");
- @@ -977,21 +1016,31 @@ public final class ChatCommands {
- return true;
- } else if (args.hasArgument("unban", "ub")) {
- - String targUser = args.getString("unban", "ub");
- + String playerName = args.getString("unban", "ub");
- + IdpPlayer target = parent.getPlayer(playerName);
- +
- + if (target != null) {
- + playerName = target.getName();
- + }
- - if (!PlayerSession.isValidPlayer(targUser)) {
- - sender.printError("That player doesn't exist.");
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- +
- + if (credentials == null) {
- + sender.printError("That player does not exist.");
- return true;
- + } else {
- + // Get the proper casing of the name
- + playerName = credentials.getName();
- }
- - String coloredName = getColoredName(targUser, parent);
- + String coloredName = getColoredName(playerName, parent);
- - if (!channel.isBanned(targUser)) {
- + if (!channel.isBanned(playerName)) {
- sender.printError(coloredName + ChatColor.RED + " is not banned from this channel.");
- return true;
- }
- - channel.removeBanned(targUser);
- + channel.removeBanned(playerName);
- if (channel.isCached()) {
- channel.sendGeneralMessage(coloredName + ChatColor.RED + " has been unbanned from the channel!");
- @@ -1076,11 +1125,11 @@ public final class ChatCommands {
- sender.printInfo("Channel is hidden: " + ChatColor.YELLOW + isHidden);
- sender.printInfo("Channel password: " + (requiresPassword ? ChatColor.YELLOW + channelPassword : ChatColor.RED + "none set"));
- - List<String> ops = channel.getMembers(ChatChannelGroup.OPERATOR, false);
- + List<PlayerCredentials> ops = channel.getMembers(ChatChannelGroup.OPERATOR, false);
- String coloredOpsString = "";
- - for (String op : ops) {
- - String coloredOp = getColoredName(op, parent);
- + for (PlayerCredentials pc : ops) {
- + String coloredOp = getColoredName(pc.getName(), parent);
- if (coloredOpsString.isEmpty()) {
- coloredOpsString = coloredOp;
- @@ -1161,7 +1210,8 @@ public final class ChatCommands {
- StringBuilder sb = new StringBuilder();
- int playerCount = 0, onlineCount = 0;
- - for (String member : chan.getMembers()) {
- + for (PlayerCredentials pc : chan.getMembers()) {
- + String member = pc.getName();
- IdpPlayer player = parent.getPlayer(member);
- String addedTag = "";
- @@ -1267,15 +1317,16 @@ public final class ChatCommands {
- /**
- * Determines if the specified user can be moderated against with
- * channel kick/ban commands
- - * @param username
- + * @param playerName
- * @return
- */
- - private static boolean canModerate(String username, InnPlugin parent) {
- - PlayerSession session = PlayerSession.getActiveSession(username);
- + private static boolean canModerate(String playerName, InnPlugin parent) {
- + UUID playerId = getPlayerId(playerName);
- + PlayerSession session = PlayerSession.getActiveSession(playerId);
- boolean tempSession = false;
- if (session == null) {
- - session = PlayerSession.getSession(username, parent);
- + session = PlayerSession.getSession(playerId, playerName, parent, true);
- tempSession = true;
- }
- @@ -1290,16 +1341,17 @@ public final class ChatCommands {
- /**
- * Gets the colored name of the username
- - * @param username
- + * @param playerName
- * @param parent
- * @return
- */
- - private static String getColoredName(String username, InnPlugin parent) {
- - PlayerSession session = PlayerSession.getActiveSession(username);
- + private static String getColoredName(String playerName, InnPlugin parent) {
- + UUID playerId = getPlayerId(playerName);
- + PlayerSession session = PlayerSession.getActiveSession(playerId);
- boolean tempSession = false;
- if (session == null) {
- - session = PlayerSession.getSession(username, parent);
- + session = PlayerSession.getSession(playerId, playerName, parent, true);
- tempSession = true;
- }
- @@ -1311,4 +1363,14 @@ public final class ChatCommands {
- return coloredName;
- }
- +
- + /**
- + * Gets the unique ID of the specified player
- + * @param playerName
- + * @return
- + */
- + private static UUID getPlayerId(String playerName) {
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- + return credentials.getUniqueId();
- + }
- }
- diff --git a/src/net/innectis/innplugin/Command/Commands/GameCommands.java b/src/net/innectis/innplugin/Command/Commands/GameCommands.java
- index 11e0ca18b..20703ade3 100644
- --- a/src/net/innectis/innplugin/Command/Commands/GameCommands.java
- +++ b/src/net/innectis/innplugin/Command/Commands/GameCommands.java
- @@ -259,7 +259,7 @@ public final class GameCommands {
- // Check if there is a lot and if the given player is the owner, a member or operator
- InnectisLot lot = LotHandler.getLot(player.getLocation());
- - if (lot != null && !lot.canPlayerManage(player) && !lot.containsMember(player.getDisplayName())
- + if (lot != null && !lot.canPlayerManage(player.getName()) && !lot.containsMember(player.getDisplayName())
- && !player.hasPermission(Permission.game_start_anywhere)) {
- sender.printError("You cannot start a game here!");
- return true;
- diff --git a/src/net/innectis/innplugin/Command/Commands/InformationCommands.java b/src/net/innectis/innplugin/Command/Commands/InformationCommands.java
- index f51ca69cd..5a8e2b903 100644
- --- a/src/net/innectis/innplugin/Command/Commands/InformationCommands.java
- +++ b/src/net/innectis/innplugin/Command/Commands/InformationCommands.java
- @@ -5,6 +5,7 @@ import java.util.ArrayList;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.List;
- +import java.util.UUID;
- import net.innectis.innplugin.Command.CommandMethod;
- import net.innectis.innplugin.Command.ICommand;
- import net.innectis.innplugin.Configuration;
- @@ -19,6 +20,7 @@ import net.innectis.innplugin.Handlers.PagedCommandHandler;
- import net.innectis.innplugin.Handlers.TransactionHandler;
- import net.innectis.innplugin.Handlers.TransactionHandler.TransactionType;
- import net.innectis.innplugin.IdpCommandSender;
- +import net.innectis.innplugin.IdpConsole;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.InnectisObjects.*;
- import net.innectis.innplugin.Inventory.IdpContainer;
- @@ -35,6 +37,8 @@ import net.innectis.innplugin.Player.Chat.ChatColor;
- import net.innectis.innplugin.Player.IdpPlayer;
- import net.innectis.innplugin.Player.Infractions.InfractionManager;
- import net.innectis.innplugin.Player.Permission;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Player.PlayerGroup;
- import net.innectis.innplugin.Player.PlayerSession;
- import net.innectis.innplugin.Player.Request.Request;
- @@ -125,7 +129,7 @@ public final class InformationCommands {
- return true;
- }
- - if (!innchest.canPlayerAccess(player)
- + if (!innchest.canPlayerAccess(player.getName())
- && !player.hasPermission(Permission.owned_object_override)) {
- player.printError("You cannot access this chest. Unable to count contents!");
- return true;
- @@ -155,20 +159,42 @@ public final class InformationCommands {
- usage = "/statistics [player]",
- serverCommand = true)
- public static boolean commandStatistics(Server server, InnPlugin parent, IdpCommandSender<? extends CommandSender> sender, String[] args) {
- - PlayerSession session = PlayerSession.getSession(sender.getName(), parent);
- + PlayerSession session = null;
- - if (args.length == 1) {
- - session = PlayerSession.getSession(args[0], parent);
- - }
- + if (args.length > 0) {
- + String playerName = args[0];
- + IdpPlayer target = parent.getPlayer(playerName);
- - if (!session.isValidPlayer()) {
- - session.destroy();
- - sender.printError("Player not found!");
- - return true;
- + if (target != null) {
- + session = target.getSession();
- + } else {
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- +
- + if (credentials == null) {
- + sender.printError("That player does not exist.");
- + return true;
- + }
- +
- + session = PlayerSession.getSession(credentials.getUniqueId(), credentials.getName(), parent, true);
- + }
- + } else {
- + if (sender instanceof IdpConsole) {
- + sender.printError("Cannot lookup statistics for console!");
- + return true;
- + }
- +
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(sender.getName());
- +
- + if (credentials == null) {
- + sender.printError("Could not look up statistics for you!");
- + return true;
- + }
- +
- + session = PlayerSession.getSession(credentials.getUniqueId(), credentials.getName(), parent, true);
- }
- String name = session.getDisplayName();
- - TransactionObject transaction = TransactionHandler.getTransactionObject(name);
- + TransactionObject transaction = TransactionHandler.getTransactionObject(session.getUniqueId(), session.getRealName());
- List<InnectisLot> lots = LotHandler.getLots(name);
- String lotInfo;
- @@ -241,9 +267,10 @@ public final class InformationCommands {
- }
- if (sender.hasPermission(Permission.command_information_statistics_extended)) {
- - sender.print(ChatColor.GOLD, "Infraction level: " + InfractionManager.getManager().getInfractionLevel(session.getRealName()));
- + sender.print(ChatColor.GOLD, "Infraction level: " + InfractionManager.getManager().getInfractionLevel(session.getUniqueId(), session.getRealName()));
- sender.print(ChatColor.GOLD, "Status: " + session.getPlayerStatus());
- }
- +
- return true;
- }
- @@ -376,7 +403,7 @@ public final class InformationCommands {
- InnectisWaypoint wp = (InnectisWaypoint) ownedObj;
- Location waypointLocation = wp.getDestination();
- InnectisLot lot = LotHandler.getLot(waypointLocation);
- - boolean canSee = (!wp.isFlagSet(WaypointFlagType.HIDDEN) || wp.canPlayerAccess(player)
- + boolean canSee = (!wp.isFlagSet(WaypointFlagType.HIDDEN) || wp.canPlayerAccess(player.getName())
- || player.hasPermission(Permission.owned_object_override));
- if (canSee) {
- @@ -473,32 +500,27 @@ public final class InformationCommands {
- }
- //</editor-fold>
- - // Normal command
- + String playerName = args.getString(0);
- + IdpPlayer target = parent.getPlayer(playerName);
- + PlayerSession session = null;
- boolean playerOnline = false;
- - String playername = args.getString(0);
- -
- - if (playername == null) {
- - sender.printError("No player name specified!");
- - return;
- - }
- -
- - IdpPlayer player = parent.getPlayer(playername, false, true);
- - PlayerSession session = null;
- + if (target != null) {
- + playerName = target.getName();
- + session = target.getSession();
- + playerOnline = true;
- + } else {
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- - if (player == null) {
- - if (!PlayerSession.isValidPlayer(playername)) {
- - sender.printError("Player " + playername + " not found!");
- + if (credentials == null) {
- + sender.printError("That player does not exist.");
- return;
- }
- - session = PlayerSession.getSession(playername, parent);
- - } else {
- - session = player.getSession();
- - playerOnline = true;
- + session = PlayerSession.getSession(credentials.getUniqueId(), credentials.getName(), parent, true);
- }
- - TransactionObject transaction = TransactionHandler.getTransactionObject(playername);
- + TransactionObject transaction = TransactionHandler.getTransactionObject(session.getUniqueId(), session.getRealName());
- sender.printInfo("Player: " + session.getColoredDisplayName());
- @@ -519,14 +541,14 @@ public final class InformationCommands {
- }
- if (playerOnline && args.hasOption("world", "w")) {
- - sender.printInfo("World: " + ChatColor.AQUA + player.getWorld().getName());
- + sender.printInfo("World: " + ChatColor.AQUA + target.getWorld().getName());
- }
- if (playerOnline && args.hasOption("location", "loc")) {
- - sender.printInfo("Location: " + ChatColor.AQUA + LocationUtil.locationString(player.getLocation()));
- + sender.printInfo("Location: " + ChatColor.AQUA + LocationUtil.locationString(target.getLocation()));
- }
- - Player bukkitPlayer = (playerOnline ? player.getHandle() : null);
- + Player bukkitPlayer = (playerOnline ? target.getHandle() : null);
- if (playerOnline && args.hasOption("ip")) {
- sender.printInfo("IP: " + ChatColor.AQUA + bukkitPlayer.getAddress().getAddress().toString());
- @@ -578,7 +600,7 @@ public final class InformationCommands {
- // Destroys the session!
- if (args.hasOption("destroy")) {
- if (playerOnline) {
- - player.getHandle().kickPlayer("Sorry for that, please rejoin.");
- + target.getHandle().kickPlayer("Sorry for that, please rejoin.");
- }
- session.destroy();
- sender.printInfo("Session destroyed!");
- @@ -625,10 +647,10 @@ public final class InformationCommands {
- }
- if (playerOnline) {
- - if (player.getGroup() == PlayerGroup.SADMIN && !sender.hasPermission(Permission.command_admin_perm)) {
- + if (target.getGroup() == PlayerGroup.SADMIN && !sender.hasPermission(Permission.command_admin_perm)) {
- sender.printInfo("No geo info");
- } else {
- - IPAddress[] addresses = info.lookupPartialIp(player.getHandle().getAddress().getAddress().toString().substring(1));
- + IPAddress[] addresses = info.lookupPartialIp(target.getHandle().getAddress().getAddress().toString().substring(1));
- if (addresses.length > 0) {
- GeoLocation geoloc = addresses[0].getGeoLocation();
- if (geoloc != null) {
- @@ -673,7 +695,7 @@ public final class InformationCommands {
- sender.printInfo("Linked accounts: " + ChatColor.AQUA + "None");
- }
- } else {
- - sender.printError("Unable to get linked usernames for " + playername + "!");
- + sender.printError("Unable to get linked usernames for " + playerName + "!");
- }
- }
- }
- diff --git a/src/net/innectis/innplugin/Command/Commands/LocationCommands.java b/src/net/innectis/innplugin/Command/Commands/LocationCommands.java
- index 895f38578..4e2a941ba 100644
- --- a/src/net/innectis/innplugin/Command/Commands/LocationCommands.java
- +++ b/src/net/innectis/innplugin/Command/Commands/LocationCommands.java
- @@ -46,6 +46,8 @@ import net.innectis.innplugin.OwnedObjects.LotFlagType;
- import net.innectis.innplugin.Player.Chat.ChatColor;
- import net.innectis.innplugin.Player.IdpPlayer;
- import net.innectis.innplugin.Player.Permission;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Player.PlayerGroup;
- import net.innectis.innplugin.Player.PlayerSession;
- import net.innectis.innplugin.Player.Request.Request;
- @@ -305,7 +307,7 @@ public final class LocationCommands {
- }
- InnectisLot lot = LotHandler.getLot(loc);
- - if (lot != null && !lot.canPlayerAccess(player) && !lot.getHidden()
- + if (lot != null && !lot.canPlayerAccess(player.getName()) && !lot.getHidden()
- && !player.hasPermission(Permission.lot_sethome_override)) {
- player.printError("You cannot set your home here!");
- return true;
- @@ -792,12 +794,13 @@ public final class LocationCommands {
- return true;
- }
- - if (lot == null || (lot != null && (lot.canPlayerAccess(player))
- + if (lot == null || (lot != null && (lot.canPlayerAccess(player.getName()))
- || player.hasPermission(Permission.owned_object_override))) {
- boolean force = player.hasPermission(Permission.special_waypoint_nodeduct);
- if (force || player.removeItemFromInventory(IdpMaterial.LAPIS_LAZULI_BLOCK, 3)) {
- - InnectisWaypoint waypoint = WaypointHandler.createWaypoint(player, block, force);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName(), true);
- + InnectisWaypoint waypoint = WaypointHandler.createWaypoint(credentials, block, force);
- if (waypoint != null) {
- player.printInfo("Waypoint created! Use \"/wpset " + waypoint.getId() + "\" to set target location.");
- } else {
- @@ -847,11 +850,11 @@ public final class LocationCommands {
- if (waypoint == null) {
- player.printError("Waypoint not found!");
- - } else if (waypoint.canPlayerManage(player)
- + } else if (waypoint.canPlayerManage(player.getName())
- || player.hasPermission(Permission.owned_waypoint_setall)) {
- InnectisLot lot = LotHandler.getLot(player.getLocation());
- - if (lot == null || lot.canPlayerManage(player)
- + if (lot == null || lot.canPlayerManage(player.getName())
- || player.hasPermission(Permission.owned_waypoint_setanywhere)) {
- waypoint.setDestination(player.getLocation());
- @@ -1088,7 +1091,22 @@ public final class LocationCommands {
- }
- String previousOwner = obj.getOwner();
- - obj.setOwner(owner);
- +
- + PlayerCredentials credentials = null;
- +
- + // Only allow assignable owner on lots
- + if (owner.equals("#") && obj instanceof InnectisLot) {
- + credentials = Configuration.LOT_ASSIGNABLE_CREDENTIALS;
- + } else {
- + credentials = PlayerCredentialsManager.getByName(owner, true);
- +
- + if (credentials == null) {
- + player.printError("That player doesn't exist!");
- + return true;
- + }
- + }
- +
- + obj.setOwner(credentials);
- // Special cleanup for lots
- if (obj instanceof InnectisLot) {
- @@ -1231,7 +1249,7 @@ public final class LocationCommands {
- tpCost = 35;
- }
- - TransactionObject transaction = TransactionHandler.getTransactionObject(player.getName());
- + TransactionObject transaction = TransactionHandler.getTransactionObject(player.getUniqueId(), player.getName());
- int balance = transaction.getValue(TransactionType.VALUTAS);
- if (balance >= tpCost) {
- @@ -1319,7 +1337,8 @@ public final class LocationCommands {
- case WAYPOINT: {
- if (WaypointHandler.getWaypoint(loc) == null) {
- try {
- - InnectisWaypoint waypoint = WaypointHandler.createWaypoint(lot.getOwner(), block, false);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(lot.getOwner(), true);
- + InnectisWaypoint waypoint = WaypointHandler.createWaypoint(credentials, block, false);
- if (waypoint != null) {
- sender.printInfo(StringUtil.format("Unlinked waypoint at {0} -> #{1}", LocationUtil.locationString(loc), waypoint.getId()));
- break;
- @@ -1334,7 +1353,8 @@ public final class LocationCommands {
- case IRON_DOOR_BLOCK: {
- if (DoorHandler.getDoor(loc) == null) {
- try {
- - InnectisDoor door = DoorHandler.createDoor(lot.getOwner(), block);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(lot.getOwner(), true);
- + InnectisDoor door = DoorHandler.createDoor(credentials, block);
- if (door != null) {
- sender.printInfo(StringUtil.format("Unlinked door at {0} -> #{1}", LocationUtil.locationString(loc), door.getId()));
- break;
- @@ -1350,7 +1370,8 @@ public final class LocationCommands {
- case TRAPPED_CHEST: {
- if (ChestHandler.getChest(loc) == null) {
- try {
- - InnectisChest chest = ChestHandler.createChest(lot.getOwner(), block);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(lot.getOwner());
- + InnectisChest chest = ChestHandler.createChest(credentials, block);
- if (chest != null) {
- sender.printInfo(StringUtil.format("Unlinked chest at {0} -> #{1}", LocationUtil.locationString(loc), chest.getId()));
- break;
- @@ -1365,7 +1386,8 @@ public final class LocationCommands {
- case TRAP_DOOR: {
- if (TrapdoorHandler.getTrapdoor(loc) == null) {
- try {
- - InnectisTrapdoor trapdoor = TrapdoorHandler.createTrapdoor(block.getWorld(), loc, lot.getOwner());
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(lot.getOwner());
- + InnectisTrapdoor trapdoor = TrapdoorHandler.createTrapdoor(block.getWorld(), loc, credentials);
- if (trapdoor != null) {
- sender.printInfo(StringUtil.format("Unlinked trapdoor at {0} -> #{1}", LocationUtil.locationString(loc), trapdoor.getId()));
- @@ -1579,7 +1601,7 @@ public final class LocationCommands {
- InnectisLot lot = (InnectisLot) innOwnedObj;
- if (!canSet) {
- - canSet = (lot.canPlayerAccess(player) && player.hasPermission(Permission.lot_memberlot_flagset));
- + canSet = (lot.canPlayerAccess(player.getName()) && player.hasPermission(Permission.lot_memberlot_flagset));
- }
- if (!canSet) {
- @@ -1683,25 +1705,28 @@ public final class LocationCommands {
- return true;
- }
- - String targPlayer = args[1];
- + String playerName = args[1];
- - boolean modifyOperator = targPlayer.startsWith("!");
- + boolean modifyOperator = playerName.startsWith("!");
- if (modifyOperator) {
- - targPlayer = targPlayer.substring(1);
- + playerName = playerName.substring(1);
- }
- - IdpPlayer target = parent.getPlayer(targPlayer);
- + IdpPlayer target = parent.getPlayer(playerName);
- if (target != null) {
- - targPlayer = target.getName();
- + playerName = target.getName();
- }
- - PlayerGroup group = PlayerGroup.getGroupOfUsername(targPlayer);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- - if (group == PlayerGroup.NONE) {
- - player.printError("That player doesn't exist.");
- + if (credentials == null) {
- + player.printError("That player does not exist.");
- return true;
- + } else {
- + // Get the proper casing of the name
- + playerName = credentials.getName();
- }
- // Lists all checked objects in the selection. This is because multiple
- @@ -1740,62 +1765,64 @@ public final class LocationCommands {
- if (obj != null) {
- // Make sure the object isn't modified more than once
- if (!queried.contains(obj)) {
- - if (obj.canPlayerManage(player) || player.hasPermission(Permission.owned_object_override)) {
- - if (obj.getOwner().equalsIgnoreCase(targPlayer)) {
- - player.printError(targPlayer + " is owner of " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ". Cannot add!");
- + if (obj.canPlayerManage(player.getName()) || player.hasPermission(Permission.owned_object_override)) {
- + if (obj.getOwner().equalsIgnoreCase(playerName)) {
- + player.printError(playerName + " is owner of " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ". Cannot add!");
- continue;
- }
- if (action == 1) {
- - if (obj.containsMember(targPlayer) || obj.containsOperator(targPlayer)) {
- - if (modifyOperator && obj.containsMember(targPlayer)) {
- - obj.addOperator(targPlayer);
- + if (obj.containsMember(playerName) || obj.containsOperator(playerName)) {
- + if (modifyOperator && obj.containsMember(playerName)) {
- + obj.addOperator(credentials);
- save = true;
- - saveMsg = "Added " + targPlayer + " as operator to " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".";
- + saveMsg = "Added " + playerName + " as operator to " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".";
- } else {
- - player.printError(targPlayer + " is already added to " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".");
- + player.printError(playerName + " is already added to " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".");
- continue;
- }
- } else {
- if (modifyOperator) {
- - obj.addOperator(targPlayer);
- + obj.addOperator(credentials);
- } else {
- - obj.addMember(targPlayer);
- + obj.addMember(credentials);
- }
- save = true;
- - saveMsg = "Added " + targPlayer + (modifyOperator ? " as operator" : "") + " to " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".";
- + saveMsg = "Added " + playerName + (modifyOperator ? " as operator" : "") + " to " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".";
- }
- } else if (action == 2) {
- - if (obj.containsMember(targPlayer) || obj.containsOperator(targPlayer)) {
- + if (obj.containsMember(playerName) || obj.containsOperator(playerName)) {
- if (modifyOperator) {
- - if (obj.containsOperator(targPlayer)) {
- - obj.removeOperator(targPlayer);
- + if (obj.containsOperator(playerName)) {
- + obj.removeOperator(playerName);
- save = true;
- - saveMsg = "Removed " + targPlayer + " as operator of " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".";
- + saveMsg = "Removed " + playerName + " as operator of " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".";
- } else {
- - player.printError(targPlayer + " is not an operator of " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".");
- + player.printError(playerName + " is not an operator of " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".");
- continue;
- }
- } else {
- - boolean isOperator = obj.containsOperator(targPlayer);
- + boolean isOperator = obj.containsOperator(playerName);
- if (isOperator) {
- - obj.removeOperator(targPlayer);
- + obj.removeOperator(playerName);
- } else {
- - obj.removeMember(targPlayer);
- + obj.removeMember(playerName);
- }
- save = true;
- - saveMsg = "Removed " + targPlayer + (isOperator ? " as operator" : "") + " from " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".";
- + saveMsg = "Removed " + playerName + (isOperator ? " as operator" : "") + " from " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".";
- }
- } else {
- - player.printError(targPlayer + " is not added to " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".");
- + player.printError(playerName + " is not added to " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".");
- continue;
- }
- }
- if (save) {
- + PlayerCredentialsManager.addCredentialsToCache(credentials);
- +
- if (obj.save()) {
- player.printInfo(saveMsg);
- } else {
- @@ -1803,7 +1830,7 @@ public final class LocationCommands {
- }
- }
- } else {
- - player.printError("You do not have permission to" + (action == 1 ? " add " : "remove ") + targPlayer + (action == 1 ? " to " : " from ") + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".");
- + player.printError("You do not have permission to" + (action == 1 ? " add " : "remove ") + playerName + (action == 1 ? " to " : " from ") + obj.getObjectName().toLowerCase() + " #" + obj.getId() + ".");
- }
- queried.add(obj);
- @@ -1838,10 +1865,10 @@ public final class LocationCommands {
- targPlayer = target.getName();
- }
- - PlayerGroup group = PlayerGroup.getGroupOfUsername(targPlayer);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(targPlayer);
- - if (group == PlayerGroup.NONE) {
- - player.printError("That player doesn't exist.");
- + if (credentials == null) {
- + player.printError("That player does not exist.");
- return true;
- }
- @@ -1881,7 +1908,8 @@ public final class LocationCommands {
- if (!queried.contains(obj)) {
- if (!obj.getOwner().equalsIgnoreCase(targPlayer)) {
- String previousOwner = obj.getOwner();
- - obj.setOwner(targPlayer);
- + obj.setOwner(credentials);
- + PlayerCredentialsManager.addCredentialsToCache(credentials);
- if (obj.save()) {
- player.print(ChatColor.AQUA, "Set the owner of " + obj.getObjectName().toLowerCase() + " #" + obj.getId() + " from " + previousOwner + " to " + targPlayer + ".");
- diff --git a/src/net/innectis/innplugin/Command/Commands/LotCommands.java b/src/net/innectis/innplugin/Command/Commands/LotCommands.java
- index 13b4978b4..21854e202 100644
- --- a/src/net/innectis/innplugin/Command/Commands/LotCommands.java
- +++ b/src/net/innectis/innplugin/Command/Commands/LotCommands.java
- @@ -8,6 +8,7 @@ import java.util.HashMap;
- import java.util.List;
- import java.util.Random;
- import net.innectis.innplugin.Command.CommandMethod;
- +import net.innectis.innplugin.Configuration;
- import net.innectis.innplugin.Handlers.BlockHandler;
- import net.innectis.innplugin.Handlers.PagedCommandHandler;
- import net.innectis.innplugin.IdpCommandSender;
- @@ -20,6 +21,8 @@ import net.innectis.innplugin.OwnedObjects.InnectisLot;
- import net.innectis.innplugin.Player.Chat.ChatColor;
- import net.innectis.innplugin.Player.IdpPlayer;
- import net.innectis.innplugin.Player.Permission;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Player.PlayerGroup;
- import net.innectis.innplugin.Player.PlayerSession;
- import net.innectis.innplugin.Player.Request.LotRemovalRequest;
- @@ -50,52 +53,64 @@ public final class LotCommands {
- return false;
- }
- - String target = args[0];
- - PlayerGroup group = PlayerGroup.getGroupOfUsername(target);
- + String playerName = args[0];
- + IdpPlayer target = parent.getPlayer(playerName);
- - if (group == PlayerGroup.NONE) {
- - sender.printError("Target does not have a Player Group: " + target);
- + if (target != null) {
- + playerName = target.getName();
- + }
- +
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- +
- + if (credentials == null) {
- + sender.printError("That player does not exist.");
- + return true;
- } else {
- - List<InnectisLot> lots = LotHandler.getLots(target);
- - if (lots == null) {
- - sender.printError("Target does not have any lots: " + target);
- - } else {
- - sender.print(ChatColor.AQUA, "Checking lots for " + target + " (" + group.name + ")..");
- - List<String> violationsFound = new ArrayList<String>();
- - for (InnectisLot lot : lots) {
- + // Get the proper casing of the player
- + playerName = credentials.getName();
- + }
- - if (lot.containsMember("%")) {
- - violationsFound.add(ChatColor.DARK_PURPLE + "[IDP] Lot #" + lot.getId() + ": Wildcard (%) is lot allowed!");
- - }
- + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(credentials.getUniqueId());
- - for (PlayerGroup targetGroup : PlayerGroup.values()) {
- - if (group.inherits(targetGroup) && lot.containsGroup(group)) {
- - violationsFound.add(ChatColor.LIGHT_PURPLE + "[IDP] Lot #" + lot.getId() + ": Player Group " + targetGroup.color + targetGroup.name + ChatColor.LIGHT_PURPLE + " is lot allowed!");
- - }
- - }
- + List<InnectisLot> lots = LotHandler.getLots(playerName);
- - for (String operator : lot.getOperators()) {
- - PlayerGroup targetGroup = PlayerGroup.getGroupOfUsername(operator);
- - if (group != PlayerGroup.NONE && group.inherits(targetGroup)) {
- - violationsFound.add(ChatColor.DARK_RED + "[IDP] Lot #" + lot.getId() + ": " + operator + " is a lot operator!");
- - }
- + if (lots == null) {
- + sender.printError("Target does not have any lots: " + playerName);
- + } else {
- + sender.print(ChatColor.AQUA, "Checking lots for " + playerName + " (" + group.name + ")..");
- + List<String> violationsFound = new ArrayList<String>();
- + for (InnectisLot lot : lots) {
- + if (lot.containsMember("%")) {
- + violationsFound.add(ChatColor.DARK_PURPLE + "[IDP] Lot #" + lot.getId() + ": Wildcard (%) is lot allowed!");
- + }
- +
- + for (PlayerGroup targetGroup : PlayerGroup.values()) {
- + if (group.inherits(targetGroup) && lot.containsPlayerGroup(group)) {
- + violationsFound.add(ChatColor.LIGHT_PURPLE + "[IDP] Lot #" + lot.getId() + ": Player Group " + targetGroup.color + targetGroup.name + ChatColor.LIGHT_PURPLE + " is lot allowed!");
- }
- + }
- - for (String member : lot.getMembers()) {
- - PlayerGroup targetGroup = PlayerGroup.getGroupOfUsername(member);
- - if (group != PlayerGroup.NONE && group.inherits(targetGroup)) {
- - violationsFound.add(ChatColor.RED + "[IDP] Lot #" + lot.getId() + ": " + member + " is a lot member.");
- - }
- + for (PlayerCredentials pc : lot.getOperators()) {
- + PlayerGroup targetGroup = PlayerGroup.getGroupOfPlayerById(pc.getUniqueId());
- + if (group != PlayerGroup.NONE && group.inherits(targetGroup)) {
- + violationsFound.add(ChatColor.DARK_RED + "[IDP] Lot #" + lot.getId() + ": " + pc.getName() + " is a lot operator!");
- }
- }
- - if (violationsFound.isEmpty()) {
- - sender.printInfo("No violations found on targets lots!");
- - } else {
- - for (String error : violationsFound) {
- - sender.printRaw(error);
- +
- + for (PlayerCredentials pc : lot.getMembers()) {
- + PlayerGroup targetGroup = PlayerGroup.getGroupOfPlayerById(pc.getUniqueId());
- + if (group != PlayerGroup.NONE && group.inherits(targetGroup)) {
- + violationsFound.add(ChatColor.RED + "[IDP] Lot #" + lot.getId() + ": " + pc.getName() + " is a lot member.");
- }
- }
- + }
- + if (violationsFound.isEmpty()) {
- + sender.printInfo("No violations found on targets lots!");
- + } else {
- + for (String error : violationsFound) {
- + sender.printRaw(error);
- + }
- }
- }
- @@ -314,7 +329,6 @@ public final class LotCommands {
- IdpRegion region;
- World world = player.getLocation().getWorld();
- - String playername = player.getName();
- BlockCounter counter = BlockCounterFactory.getCounter(BlockCounterFactory.CountType.CUBOID);
- region = new IdpRegion(start, end);
- @@ -373,6 +387,8 @@ public final class LotCommands {
- int increment = lotWidth + lotMargin * 2 + pathWidth;
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName(), true);
- +
- Vector loc1, loc2;
- for (; x < max_x; x += increment) {
- for (int z = start_z; z < max_z; z += increment) {
- @@ -411,7 +427,7 @@ public final class LotCommands {
- // Create the lot
- try {
- - InnectisLot lot = LotHandler.addLot(world, vec1, vec2, "#", playername);
- + InnectisLot lot = LotHandler.addLot(world, vec1, vec2, Configuration.LOT_ASSIGNABLE_CREDENTIALS, credentials);
- lot.setSpawn(new Location(world, loc1.getBlockX(), loc1.getBlockY(), loc1.getBlockZ()));
- lot.save();
- player.printInfo("Lot: " + ChatColor.AQUA + lot.getId() + ChatColor.DARK_PURPLE, " " + lot.getMinimumPoint() + " " + lot.getMaximumPoint());
- @@ -423,7 +439,7 @@ public final class LotCommands {
- }
- try {
- - InnectisLot lot = LotHandler.addLot(world, new Vector(start.getBlockX(), 0, start.getBlockZ()), new Vector(end.getBlockX(), 255, end.getBlockZ()), "~", playername);
- + InnectisLot lot = LotHandler.addLot(world, new Vector(start.getBlockX(), 0, start.getBlockZ()), new Vector(end.getBlockX(), 255, end.getBlockZ()), Configuration.OTHER_CREDENTIALS, credentials);
- lot.setSpawn(new Location(player.getLocation().getWorld(), start.getBlockX(), start.getBlockY(), start.getBlockZ()));
- lot.setHidden(true);
- lot.save();
- @@ -531,14 +547,7 @@ public final class LotCommands {
- if (lastEdit > 0 && (System.currentTimeMillis() - lastEdit) >= timeLastEdited) {
- int id = lot.getId();
- - String owner = lot.getOwner();
- -
- - // Filter shop owners
- - if (owner.startsWith("#")) {
- - owner = owner.substring(2);
- - }
- -
- - PlayerGroup group = PlayerGroup.getGroupOfUsername(owner);
- + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(lot.getOwnerCredentials().getUniqueId());
- if (foundLots.containsKey(group)) {
- foundLots.get(group).add(group.getPrefix().getTextColor().toString() + id);
- @@ -836,7 +845,9 @@ public final class LotCommands {
- pos2 = pos2.setY(player.getWorld().getMaxHeight() - 1);
- }
- - InnectisLot lot = LotHandler.addLot(player.getLocation().getWorld(), pos1, pos2, username, player.getName());
- + PlayerCredentials ownerCredentials = PlayerCredentialsManager.getByName(player.getName(), true);
- + PlayerCredentials creatorCredentials = PlayerCredentialsManager.getByName(username, true);
- + InnectisLot lot = LotHandler.addLot(player.getLocation().getWorld(), pos1, pos2, creatorCredentials, ownerCredentials);
- lot.setSpawn(spawn);
- lot.save();
- LotHandler.getLots().put(lot.getId(), lot);
- @@ -881,7 +892,7 @@ public final class LotCommands {
- boolean makeAssignable = args.hasOption("makeassignable", "ma");
- if (makeAssignable) {
- - lot.setOwner("#");
- + lot.setOwner(Configuration.LOT_ASSIGNABLE_CREDENTIALS);
- lot.setLastOwnerEdit(0);
- lot.setLastMemberEdit(0);
- }
- @@ -1007,9 +1018,13 @@ public final class LotCommands {
- player.printError("To get another, please talk to a Moderator.");
- } else {
- try {
- - if (LotHandler.assignLot(player.getName()) == null) {
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName());
- +
- + if (LotHandler.assignLot(credentials) == null) {
- player.printError("There are no lots available.");
- player.printError("Please notify an Admin so they can get you one.");
- + } else {
- + PlayerCredentialsManager.addCredentialsToCache(credentials);
- }
- } catch (SQLException ex) {
- InnPlugin.logError("Error when assigning a lot! ", ex);
- @@ -1039,7 +1054,8 @@ public final class LotCommands {
- if (targetLot == null) {
- sender.printError("Lot #" + lotId + " not found!");
- } else if (targetLot.isAssignable()) {
- - lot = LotHandler.assignLot(targetName, targetLot);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(targetName, true);
- + lot = LotHandler.assignLot(credentials, targetLot);
- } else {
- sender.printError("Lot #" + lotId + " is not an assignable lot!");
- }
- @@ -1048,7 +1064,8 @@ public final class LotCommands {
- return true;
- }
- } else {
- - lot = LotHandler.assignLot(targetName);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(targetName);
- + lot = LotHandler.assignLot(credentials);
- }
- if (lot == null) {
- @@ -1100,7 +1117,7 @@ public final class LotCommands {
- player.printError("An internal server occured saving lot #" + lot.getId() + ". Contact an admin!");
- }
- } else {
- - if (!lot.canPlayerManage(player)) {
- + if (!lot.canPlayerManage(player.getName())) {
- player.printError("Cannot change spawn on this lot!");
- return true;
- }
- @@ -1312,7 +1329,7 @@ public final class LotCommands {
- }
- InnectisLot lot = null;
- - String safeUser = "";
- + String playerName = "";
- if (args.length == 2) {
- try {
- @@ -1323,10 +1340,10 @@ public final class LotCommands {
- return true;
- }
- - safeUser = args[1];
- + playerName = args[1];
- } else {
- lot = LotHandler.getLot(player.getLocation());
- - safeUser = args[0];
- + playerName = args[0];
- }
- if (lot == null) {
- @@ -1334,26 +1351,28 @@ public final class LotCommands {
- return true;
- }
- - if (!(lot.canPlayerManage(player) || player.hasPermission(Permission.lot_command_override))) {
- + if (!(lot.canPlayerManage(player.getName()) || player.hasPermission(Permission.lot_command_override))) {
- player.printError("You do not manage this lot. (ID: " + lot.getId() + ")");
- return true;
- }
- - IdpPlayer targ = parent.getPlayer(safeUser);
- + IdpPlayer target = parent.getPlayer(playerName);
- - if (targ != null) {
- - safeUser = targ.getName();
- + if (target != null) {
- + playerName = target.getName();
- }
- - if (!PlayerSession.isValidPlayer(safeUser)) {
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName, true);
- +
- + if (credentials == null) {
- player.printError("That user doesn't exist!");
- return true;
- }
- - if (lot.addSafelist(safeUser)) {
- - player.printInfo("Added " + safeUser + " to the safelist on lot #" + lot.getId() + ".");
- + if (lot.addSafelist(credentials)) {
- + player.printInfo("Added " + playerName + " to the safelist on lot #" + lot.getId() + ".");
- } else {
- - player.printError(safeUser + " is already safelisted on lot #" + lot.getId() + ".");
- + player.printError(playerName + " is already safelisted on lot #" + lot.getId() + ".");
- }
- return true;
- @@ -1392,7 +1411,7 @@ public final class LotCommands {
- return true;
- }
- - if (!(lot.canPlayerManage(player) || player.hasPermission(Permission.lot_command_override))) {
- + if (!(lot.canPlayerManage(player.getName()) || player.hasPermission(Permission.lot_command_override))) {
- player.printError("You do not manage this lot. (ID: " + lot.getId() + ")");
- return true;
- }
- @@ -1400,7 +1419,7 @@ public final class LotCommands {
- boolean clearAll = safeUser.equalsIgnoreCase("-clear");
- if (clearAll) {
- - List<String> safelist = lot.getSafelist();
- + List<PlayerCredentials> safelist = lot.getSafelist();
- if (safelist.size() > 0) {
- lot.clearSafelist();
- @@ -1409,15 +1428,17 @@ public final class LotCommands {
- player.printError("Lot #" + lot.getId() + " does not have a safelist.");
- }
- } else {
- - IdpPlayer targ = parent.getPlayer(safeUser);
- + IdpPlayer target = parent.getPlayer(safeUser);
- - if (targ != null) {
- - safeUser = targ.getName();
- - }
- + if (target != null) {
- + safeUser = target.getName();
- + } else {
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(safeUser);
- - if (!PlayerSession.isValidPlayer(safeUser)) {
- - player.printError("That user doesn't exist!");
- - return true;
- + if (credentials == null) {
- + player.printError("That player doesn't exist!");
- + return true;
- + }
- }
- if (lot.removeSafelist(safeUser)) {
- @@ -1519,7 +1540,7 @@ public final class LotCommands {
- }
- if (!lot.isValidPlayer(playerString, true)) {
- - player.printError("That players does not exist!");
- + player.printError("That player does not exist!");
- return true;
- }
- @@ -1528,6 +1549,11 @@ public final class LotCommands {
- return true;
- }
- + if (playerString.contains("@")) {
- + player.printError("You cannot lotban @!");
- + return true;
- + }
- +
- if (playerString.equalsIgnoreCase("%")) {
- for (IdpPlayer p : lot.getPlayersInsideRegion(0)) {
- // If not self or staff
- @@ -1541,13 +1567,13 @@ public final class LotCommands {
- }
- }
- - lot.banUser("%", timeout);
- -
- - String personalBanMsg = "Banned % on lot #" + lot.getId() + ".";
- + lot.banUser(Configuration.EVERYONE_CREDENTIALS, timeout);
- + String personalBanMsg = "Banned everyone on lot #" + lot.getId() + ".";
- if (timeout > 0) {
- personalBanMsg += " for " + timeString;
- }
- +
- personalBanMsg += ".";
- player.printError(personalBanMsg);
- @@ -1563,20 +1589,26 @@ public final class LotCommands {
- for (String name : targetNames) {
- IdpPlayer testPlayer = parent.getPlayer(name);
- - String actualName = null;
- + String actualName = name;
- boolean tempSession = false;
- + boolean valid = false;
- PlayerSession session = null;
- if (testPlayer != null) {
- actualName = testPlayer.getName();
- session = testPlayer.getSession();
- - } else {
- - actualName = name;
- - session = PlayerSession.getSession(name, parent);
- + valid = true;
- + }
- +
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(actualName);
- +
- + if (credentials != null) {
- + session = PlayerSession.getSession(credentials.getUniqueId(), credentials.getName(), parent, true);
- + valid = true;
- tempSession = true;
- }
- - if (session.isValidPlayer()) {
- + if (valid) {
- if (!nameCache.contains(actualName.toLowerCase())) {
- nameCache.add(actualName.toLowerCase());
- @@ -1588,7 +1620,9 @@ public final class LotCommands {
- }
- if (canBan) {
- - if (lot.banUser(actualName, timeout)) {
- + if (lot.banUser(credentials, timeout)) {
- + PlayerCredentialsManager.addCredentialsToCache(credentials);
- +
- if (timeout > 0) {
- player.printInfo("Banned " + actualName + " from lot #" + lot.getId() + " for " + timeString + ".");
- } else {
- @@ -1920,7 +1954,7 @@ public final class LotCommands {
- }
- }
- - if (lot.canPlayerManage(player)
- + if (lot.canPlayerManage(player.getName())
- || player.hasPermission(Permission.lot_command_override)) {
- String unbanName = args[args.length - 1];
- @@ -2390,7 +2424,7 @@ public final class LotCommands {
- }
- // Can only set border material if you have access to the lot
- - if (!lot.canPlayerAccess(player)
- + if (!lot.canPlayerAccess(player.getName())
- && !player.hasPermission(Permission.lot_command_override)) {
- player.printError("You cannot set a lot border here!");
- return true;
- diff --git a/src/net/innectis/innplugin/Command/Commands/MiscCommands.java b/src/net/innectis/innplugin/Command/Commands/MiscCommands.java
- index 0f9614ac9..5dadf4e49 100644
- --- a/src/net/innectis/innplugin/Command/Commands/MiscCommands.java
- +++ b/src/net/innectis/innplugin/Command/Commands/MiscCommands.java
- @@ -20,7 +20,6 @@ import net.innectis.innplugin.IdpCommandSender;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.InnectisObjects.*;
- import net.innectis.innplugin.Inventory.IdpInventory;
- -import net.innectis.innplugin.Items.IdpItem;
- import net.innectis.innplugin.Items.IdpItemStack;
- import net.innectis.innplugin.Items.IdpMaterial;
- import net.innectis.innplugin.Location.*;
- @@ -38,6 +37,8 @@ import net.innectis.innplugin.Player.Chat.ChatColor;
- import net.innectis.innplugin.Player.IdpPlayer;
- import net.innectis.innplugin.Player.IdpPlayerInventory;
- import net.innectis.innplugin.Player.Permission;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Player.PlayerEffect;
- import net.innectis.innplugin.Player.TinyWE.BlockCounters.BlockCounter;
- import net.innectis.innplugin.Player.TinyWE.BlockCounters.BlockCounterFactory;
- @@ -45,7 +46,6 @@ import net.innectis.innplugin.Tasking.LimitedTask;
- import net.innectis.innplugin.Tasking.RunBehaviour;
- import net.innectis.innplugin.Utility.LynxyArguments;
- import net.innectis.innplugin.Utility.NotANumberException;
- -import net.innectis.innplugin.Utility.NumberUtil;
- import net.innectis.innplugin.Utility.ParameterArguments;
- import net.innectis.innplugin.Utility.SmartArguments;
- import net.innectis.innplugin.Utility.StringUtil;
- @@ -78,33 +78,32 @@ public final class MiscCommands {
- usage_Admin = "/findObject <-username (-u) [username]> <-chests> <-waypoints> <-doors> <-trapdoors> <-bookcases> <-switches>",
- serverCommand = false)
- public static void commandFindObject(InnPlugin plugin, IdpPlayer player, LynxyArguments args) {
- -
- List<InnectisOwnedObject> objectList = new ArrayList<InnectisOwnedObject>();
- + String playerName = player.getName();
- - String lookupPlayer = player.getName();
- boolean extendedInfo = player.hasPermission(Permission.command_misc_findobject_extended);
- if (extendedInfo && args.hasArgument("username", "u")) {
- - lookupPlayer = (args.getString("username", "u"));
- + playerName = (args.getString("username", "u"));
- }
- if (args.hasOption("chests", "chest")) {
- - objectList.addAll(ChestHandler.getChests(lookupPlayer));
- + objectList.addAll(ChestHandler.getChests(playerName));
- }
- if (args.hasOption("waypoints", "waypoint")) {
- - objectList.addAll(WaypointHandler.getWaypoints(lookupPlayer));
- + objectList.addAll(WaypointHandler.getWaypoints(playerName));
- }
- if (args.hasOption("doors", "door")) {
- - objectList.addAll(DoorHandler.getDoors(lookupPlayer));
- + objectList.addAll(DoorHandler.getDoors(playerName));
- }
- if (args.hasOption("trapdoors", "trapdoor")) {
- - objectList.addAll(TrapdoorHandler.getTrapdoors(lookupPlayer));
- + objectList.addAll(TrapdoorHandler.getTrapdoors(playerName));
- }
- if (args.hasOption("bookcases", "bookcase", "book")) {
- - objectList.addAll(InnectisBookcase.getBookcases(lookupPlayer));
- + objectList.addAll(InnectisBookcase.getBookcases(playerName));
- }
- if (args.hasOption("switches", "switch", "levers", "lever")) {
- - objectList.addAll(InnectisSwitch.getSwitches(lookupPlayer));
- + objectList.addAll(InnectisSwitch.getSwitches(playerName));
- }
- if (objectList.isEmpty()) {
- @@ -112,7 +111,7 @@ public final class MiscCommands {
- } else {
- for (InnectisOwnedObject object : objectList) {
- player.printInfo(object.getObjectName() + " #" + object.getId() +
- - (extendedInfo ? " (" + lookupPlayer + ") " : " ")
- + (extendedInfo ? " (" + playerName + ") " : " ")
- + object.getPos1Location().toString());
- }
- }
- @@ -140,7 +139,7 @@ public final class MiscCommands {
- return true;
- }
- - TransactionObject transaction = TransactionHandler.getTransactionObject(player.getName());
- + TransactionObject transaction = TransactionHandler.getTransactionObject(player.getUniqueId(), player.getName());
- int playerValutas = transaction.getValue(TransactionType.VALUTAS);
- if (amount > playerValutas) {
- @@ -163,7 +162,7 @@ public final class MiscCommands {
- }
- transaction.subtractValue(amount, TransactionType.VALUTAS);
- - TheEndPot.addValue(player.getName(), amount);
- + TheEndPot.addValue(player.getUniqueId(), player.getName(), amount);
- player.printInfo("You have added " + amount + " valuta" + (amount != 1 ? "s" : "") + " to The End pot!");
- @@ -218,7 +217,7 @@ public final class MiscCommands {
- if (player.getSession().isTractorRunning()) {
- player.printError("Your tractor is already running!");
- } else {
- - TransactionObject transaction = TransactionHandler.getTransactionObject(player.getName());
- + TransactionObject transaction = TransactionHandler.getTransactionObject(player.getUniqueId(), player.getName());
- int valutas = transaction.getValue(TransactionType.VALUTAS);
- if (valutas >= 100) {
- @@ -251,8 +250,7 @@ public final class MiscCommands {
- if (block != null && IdpMaterial.fromBlock(block).isChest()) {
- InnectisChest chest = ChestHandler.getChest(block.getLocation());
- - if (chest.canPlayerAccess(player)) {
- -
- + if (chest.canPlayerAccess(player.getName())) {
- chest.sortContents();
- player.printInfo("You have sorted chest #" + chest.getId());
- @@ -363,8 +361,10 @@ public final class MiscCommands {
- return true;
- }
- + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(player.getUniqueId());
- +
- // Make a present
- - PresentContent present = new PresentContent(player.getName(), title);
- + PresentContent present = new PresentContent(credentials, title);
- // Make the inventory, replace spaces with underscores
- IdpInventory inventory = new IdpInventory(title.replace(" ", "_"), 9);
- @@ -527,7 +527,7 @@ public final class MiscCommands {
- InnectisLot lot = LotHandler.getLot(signBlock.getLocation());
- - if (lot == null || (lot != null && lot.canPlayerAccess(player))
- + if (lot == null || (lot != null && lot.canPlayerAccess(player.getName()))
- || player.hasPermission(Permission.special_signedit)) {
- int lineNo = 0;
- @@ -563,7 +563,7 @@ public final class MiscCommands {
- if (ChestType.isValidChestBlock(IdpMaterial.fromBlock(chestBlock))) {
- InnectisChest ichest = ChestHandler.getChest(loc);
- - if (ichest != null && !(ichest.canPlayerManage(player)
- + if (ichest != null && !(ichest.canPlayerManage(player.getName())
- || player.hasPermission(Permission.special_chestshop_override))) {
- player.printError("Cannot edit this sign. You do not own or operate the chest below.");
- return true;
- @@ -658,9 +658,11 @@ public final class MiscCommands {
- String[] targetNames = args[args.length - 1].split(",");
- String saveMsg = null;
- + PlayerCredentials credentials = null;
- + boolean saveCacheCredentials = true;
- boolean save = false;
- - if (innObj.canPlayerManage(player) || player.hasPermission(Permission.owned_object_override)) {
- + if (innObj.canPlayerManage(player.getName()) || player.hasPermission(Permission.owned_object_override)) {
- for (String name : targetNames) {
- if (!innObj.isValidPlayer(name, false)) {
- player.printError("Unknown Player or Player Group: \"" + name + "\"");
- @@ -670,7 +672,9 @@ public final class MiscCommands {
- if (innObj.getOwner().equalsIgnoreCase(player.getName())
- || player.hasPermission(Permission.lot_command_override)) {
- - if (innObj.addOperator(name)) {
- + credentials = PlayerCredentialsManager.getByName(name);
- +
- + if (innObj.addOperator(credentials)) {
- save = true;
- saveMsg = "You gave " + name + " operating access to " + innObj.getObjectName() + " #" + innObj.getId() + ".";
- } else {
- @@ -680,7 +684,22 @@ public final class MiscCommands {
- player.printError("You cannot add operators to this " + innObj.getObjectName().toLowerCase() + "!");
- }
- } else {
- - if (innObj.addMember(name)) {
- + if (name.equals("%")) {
- + credentials = Configuration.EVERYONE_CREDENTIALS;
- + saveCacheCredentials = false;
- + } else if (name.equals("@")) {
- + if (innObj instanceof InnectisLot) {
- + player.printError("You cannot allow @ on lots!");
- + return true;
- + }
- +
- + credentials = Configuration.LOT_ACCESS_CREDENTIALS;
- + saveCacheCredentials = false;
- + } else {
- + credentials = PlayerCredentialsManager.getByName(name);
- + }
- +
- + if (innObj.addMember(credentials)) {
- save = true;
- saveMsg = "You gave " + name + " access to " + innObj.getObjectName() + " #" + innObj.getId() + ".";
- } else {
- @@ -690,6 +709,10 @@ public final class MiscCommands {
- }
- if (save) {
- + if (saveCacheCredentials) {
- + PlayerCredentialsManager.addCredentialsToCache(credentials);
- + }
- +
- if (innObj.save()) {
- player.printInfo(saveMsg);
- } else {
- @@ -865,7 +888,7 @@ public final class MiscCommands {
- String saveMsg = null;
- boolean save = false;
- - if (innObj.canPlayerManage(player) || player.hasPermission(Permission.owned_object_override)) {
- + if (innObj.canPlayerManage(player.getName()) || player.hasPermission(Permission.owned_object_override)) {
- if (args[args.length - 1].equalsIgnoreCase("-all")) {
- if (!(innObj.getMembers().isEmpty() && innObj.getOperators().isEmpty())) {
- innObj.clearMembersAndOperators();
- @@ -886,8 +909,9 @@ public final class MiscCommands {
- if (innObj.getOwner().equalsIgnoreCase(player.getName())
- || player.hasPermission(Permission.lot_command_override)) {
- if (innObj.removeOperator(name)) {
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(name, true);
- // Add the name back as player
- - innObj.addMember(name);
- + innObj.addMember(credentials);
- save = true;
- saveMsg = "You removed " + name + " operating access to " + innObj.getObjectName() + " #" + innObj.getId() + ".";
- } else {
- @@ -1830,10 +1854,10 @@ public final class MiscCommands {
- Location locBelow = player.getLocation().subtract(0, 1, 0);
- if (player.hasLightSourceConditions(locBelow)) {
- - LightsourceHandler.lightBlock(player.getName(), locBelow);
- + LightsourceHandler.lightBlock(player.getUniqueId(), locBelow);
- }
- } else {
- - LightsourceHandler.unlightBlock(player.getName());
- + LightsourceHandler.unlightBlock(player.getUniqueId());
- }
- player.printInfo("Lights are now " + (enabled ? "enabled" : "disabled") + " for you.");
- @@ -1875,7 +1899,7 @@ public final class MiscCommands {
- permission = Permission.command_misc_group_create,
- usage = "/group <add,delete,create,remove,list>",
- serverCommand = false)
- - public static boolean commandGroup(IdpPlayer player, LynxyArguments args) {
- + public static boolean commandGroup(InnPlugin parent, IdpPlayer player, LynxyArguments args) {
- // <editor-fold defaultstate="collapsed" desc="No method / Help method">
- if (StringUtil.matches(args.getString(0), null, "help", "h")) {
- player.printInfo("This command allows you to manage groups");
- @@ -1887,10 +1911,26 @@ public final class MiscCommands {
- // <editor-fold defaultstate="collapsed" desc="Add method">
- } else if (StringUtil.matches(args.getString(0), "add", "a")) {
- - String username = args.getString(1);
- + String playerName = args.getString(1);
- + IdpPlayer target = parent.getPlayer(playerName);
- +
- + if (target != null) {
- + playerName = target.getName();
- + }
- +
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- +
- + if (credentials == null) {
- + player.printError("That player does not exist.");
- + return true;
- + } else {
- + // Get the proper casing of the name
- + playerName = credentials.getName();
- + }
- +
- String groupname = args.getString(2);
- - if (StringUtil.stringIsNullOrEmpty(username)) {
- + if (StringUtil.stringIsNullOrEmpty(playerName)) {
- player.printError("No username specified!");
- return true;
- }
- @@ -1900,29 +1940,47 @@ public final class MiscCommands {
- return true;
- }
- - MemberGroup group = MemberGroupHandler.getGroup(player.getName(), groupname);
- + MemberGroup group = MemberGroupHandler.getGroup(player.getUniqueId(), groupname);
- if (group == null) {
- player.printError("Member group \"" + groupname + "\" not found!");
- } else {
- - if (group.addMember(username)) {
- + if (group.addMember(credentials)) {
- + PlayerCredentialsManager.addCredentialsToCache(credentials);
- +
- if (group.save()) {
- - player.printInfo("Added " + username + " to member group \"" + group.getName() + "\"!");
- + player.printInfo("Added " + playerName + " to member group \"" + group.getName() + "\"!");
- } else {
- player.printError("Unable to save member group. Notify an admin!");
- }
- } else {
- - player.printError(username + " is already in member group \"" + group.getName() + "\"!");
- + player.printError(playerName + " is already in member group \"" + group.getName() + "\"!");
- }
- }
- //</editor-fold>
- // <editor-fold defaultstate="collapsed" desc="Remove method">
- } else if (StringUtil.matches(args.getString(0), "remove", "rem", "r")) {
- - String username = args.getString(1);
- + String playerName = args.getString(1);
- + IdpPlayer target = parent.getPlayer(playerName);
- +
- + if (target != null) {
- + playerName = target.getName();
- + }
- +
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- +
- + if (credentials == null) {
- + player.printError("That player does not exist.");
- + return true;
- + } else {
- + // Get the proper casing of the name
- + playerName = credentials.getName();
- + }
- +
- String groupname = args.getString(2);
- - if (StringUtil.stringIsNullOrEmpty(username)) {
- + if (StringUtil.stringIsNullOrEmpty(playerName)) {
- player.printError("No username specified!");
- return true;
- }
- @@ -1932,19 +1990,19 @@ public final class MiscCommands {
- return true;
- }
- - MemberGroup group = MemberGroupHandler.getGroup(player.getName(), groupname);
- + MemberGroup group = MemberGroupHandler.getGroup(player.getUniqueId(), groupname);
- if (group == null) {
- player.printError("Member group \"" + groupname + "\" not found!");
- } else {
- - if (group.removeMember(username)) {
- + if (group.removeMember(playerName)) {
- if (group.save()) {
- - player.printInfo("Removed " + username + " from member group \"" + group.getName() + "\"!");
- + player.printInfo("Removed " + playerName + " from member group \"" + group.getName() + "\"!");
- } else {
- player.printError("Unable to save member group. Nofity an admin!");
- }
- } else {
- - player.printError(username + " is not in member group \"" + group.getName() + "\"!");
- + player.printError(playerName + " is not in member group \"" + group.getName() + "\"!");
- }
- }
- //</editor-fold>
- @@ -1957,12 +2015,15 @@ public final class MiscCommands {
- return true;
- }
- - if (MemberGroupHandler.isGroup(player.getName(), groupname)) {
- + if (MemberGroupHandler.isGroup(player.getUniqueId(), groupname)) {
- player.printError("That group already exists!");
- return true;
- }
- - if (MemberGroupHandler.addGroup(player.getName(), groupname)) {
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName());
- +
- + if (MemberGroupHandler.addGroup(credentials, groupname)) {
- + PlayerCredentialsManager.addCredentialsToCache(credentials);
- player.printInfo("Member group \"" + groupname + "\" created!");
- } else {
- player.printError("Could not save member group. Nofity an admin!");
- @@ -1977,12 +2038,12 @@ public final class MiscCommands {
- return true;
- }
- - MemberGroup group = MemberGroupHandler.getGroup(player.getName(), groupname);
- + MemberGroup group = MemberGroupHandler.getGroup(player.getUniqueId(), groupname);
- if (group == null) {
- player.printError("Member group \"" + groupname + "\" not found!");
- } else {
- - if (MemberGroupHandler.removeGroup(player.getName(), groupname)) {
- + if (MemberGroupHandler.removeGroup(player.getUniqueId(), groupname)) {
- player.printInfo("Member group \"" + group.getName() + "\" deleted!");
- } else {
- player.printError("Could not delete member group. Nodify an admin!");
- @@ -1994,7 +2055,8 @@ public final class MiscCommands {
- } else if (StringUtil.matches(args.getString(0), "list", "l")) {
- String groupname = args.getString(1);
- if (StringUtil.stringIsNullOrEmpty(groupname)) {
- - List<MemberGroup> groups = MemberGroupHandler.getGroups(player.getName());
- + List<MemberGroup> groups = MemberGroupHandler.getGroups(player.getUniqueId());
- +
- if (groups == null || groups.isEmpty()) {
- player.printInfo("You have no member groups!");
- } else {
- @@ -2011,7 +2073,7 @@ public final class MiscCommands {
- return true;
- }
- - MemberGroup group = MemberGroupHandler.getGroup(player.getName(), groupname);
- + MemberGroup group = MemberGroupHandler.getGroup(player.getUniqueId(), groupname);
- if (group == null) {
- player.printError("Member group \"" + groupname + "\" not found!");
- @@ -2048,7 +2110,7 @@ public final class MiscCommands {
- return true;
- }
- - if (!bookcase.canPlayerManage(player)) {
- + if (!bookcase.canPlayerManage(player.getName())) {
- player.printError("You do not own or operate this bookcase!");
- return true;
- }
- diff --git a/src/net/innectis/innplugin/Command/Commands/ModerationCommands.java b/src/net/innectis/innplugin/Command/Commands/ModerationCommands.java
- index 41d215acb..137732e8a 100644
- --- a/src/net/innectis/innplugin/Command/Commands/ModerationCommands.java
- +++ b/src/net/innectis/innplugin/Command/Commands/ModerationCommands.java
- @@ -16,6 +16,7 @@ import net.innectis.innplugin.Configuration;
- import net.innectis.innplugin.Handlers.PagedCommandHandler;
- import net.innectis.innplugin.Handlers.WarpHandler;
- import net.innectis.innplugin.IdpCommandSender;
- +import net.innectis.innplugin.IdpConsole;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.InnectisObjects.IPLogger;
- import net.innectis.innplugin.Items.Bookinfo;
- @@ -32,6 +33,8 @@ import net.innectis.innplugin.Player.Infractions.Infraction;
- import net.innectis.innplugin.Player.Infractions.InfractionIntensity;
- import net.innectis.innplugin.Player.Infractions.InfractionManager;
- import net.innectis.innplugin.Player.Permission;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Player.PlayerGroup;
- import net.innectis.innplugin.Player.PlayerSession;
- import net.innectis.innplugin.Utility.DateUtil;
- @@ -52,17 +55,24 @@ public final class ModerationCommands {
- return false;
- }
- - String playername = args.getString(0);
- - PlayerSession session = PlayerSession.getSession(playername, parent);
- - if (session.getTotalOnlineTime() <= 0) {
- - sender.printError("Player '" + playername + "' has no onlinetime! Cannot infract!");
- + String playerName = args.getString(0);
- + IdpPlayer target = parent.getPlayer(playerName);
- +
- + if (target != null) {
- + playerName = target.getName();
- + }
- +
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- +
- + if (credentials == null) {
- + sender.printError("That player does not exist.");
- return true;
- }
- String intensityString = args.getString(1);
- // Subcommand to revoke infractions
- - if (StringUtil.matches(playername, "r", "revoke")) {
- + if (StringUtil.matches(playerName, "r", "revoke")) {
- int id;
- try {
- id = args.getInt(2);
- @@ -76,7 +86,7 @@ public final class ModerationCommands {
- sender.printError("Infraction #" + id + " not found!");
- return true;
- } else if (inf.isRevoked()) {
- - sender.printError("Infraction #" + id + " already revoked by " + inf.getRevoker());
- + sender.printError("Infraction #" + id + " already revoked by " + inf.getRevokerCredentials().getName());
- return true;
- } else {
- Date date = Calendar.getInstance(TimeZone.getTimeZone("GMT")).getTime();
- @@ -106,7 +116,7 @@ public final class ModerationCommands {
- String summary = args.getJoinedStrings(2);
- // Make an injector for the details message
- - ChatInjector injector = new InfractInjector(session.getRealName(), infIntensity, summary);
- + ChatInjector injector = new InfractInjector(credentials, infIntensity, summary);
- if (sender.isPlayer()) {
- PlayerSession currPlayer = ((IdpPlayer) sender).getSession();
- @@ -129,11 +139,27 @@ public final class ModerationCommands {
- permission = Permission.command_moderation_infract,
- usage = "/showinfraction [username [-all] [-page <page>]] [-id <id> [-book]]",
- serverCommand = true)
- - public static boolean commandShowInfraction(IdpCommandSender sender, ParameterArguments args) {
- + public static boolean commandShowInfraction(InnPlugin parent, IdpCommandSender sender, ParameterArguments args) {
- if (args.size() == 1) {
- - String name = args.getString(0);
- + String playerName = args.getString(0);
- +
- + IdpPlayer target = parent.getPlayer(playerName);
- +
- + if (target != null) {
- + playerName = target.getName();
- + }
- +
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- +
- + if (credentials == null) {
- + sender.printError("That player does not exist.");
- + return true;
- + } else {
- + // Get the proper casing of the name
- + playerName = credentials.getName();
- + }
- - List<Infraction> infractions = InfractionManager.getManager().getInfractions(name, args.hasOption("all"));
- + List<Infraction> infractions = InfractionManager.getManager().getInfractions(credentials, args.hasOption("all"));
- if (infractions.isEmpty()) {
- sender.printInfo("That player has no infractions!");
- @@ -163,7 +189,7 @@ public final class ModerationCommands {
- ph.setNewLinesPerPage(Configuration.INFRACTIONS_PER_PAGE);
- if (ph.isValidPage()) {
- - sender.printInfo("Printing infractions for " + name + " page: " + page + "/" + ph.getMaxPage());
- + sender.printInfo("Printing infractions for " + playerName + " page: " + page + "/" + ph.getMaxPage());
- for (String line : lines) {
- sender.printInfo(line);
- @@ -202,16 +228,16 @@ public final class ModerationCommands {
- // Make a new section in chat (makes it easier to seperate multiple infractios)
- sender.printInfo("----------------------------------");
- sender.printInfo("Infraction #" + inf.getId());
- - sender.printInfo("Player " + inf.getPlayer());
- + sender.printInfo("Player " + inf.getPlayerCredentials().getName());
- sender.printInfo("Intensity " + inf.getIntensity().name());
- sender.printInfo("Created on " + DateUtil.formatString(inf.getDateGMT(), DateUtil.FORMAT_DDMMYYYY_HHMM, tz) + " (" + tz.getDisplayName() + ").");
- - sender.printInfo("Infracted by " + inf.getStaffmember());
- + sender.printInfo("Infracted by " + inf.getCreatorCredentials().getName());
- sender.printInfo("Summary: " + inf.getSummary());
- // Print revoke details.
- if (inf.isRevoked()) {
- String dateString = DateUtil.formatString(inf.getDateGMT(), DateUtil.FORMAT_DDMMYYYY_HHMM, tz) + " (" + tz.getDisplayName() + ")";
- - sender.printError("Revoked on " + dateString + " by " + inf.getRevoker() + ".");
- + sender.printError("Revoked on " + dateString + " by " + inf.getRevokerCredentials().getName() + ".");
- }
- if (inf.getDetails() != null) {
- @@ -252,15 +278,15 @@ public final class ModerationCommands {
- basicInfo.append("Created on: ").append(DateUtil.formatString(date, DateUtil.FORMAT_DDMMYYYY_HHMM)).append(InfractInjector.ENTER_CHAR);
- basicInfo.append(InfractInjector.ENTER_CHAR);
- - basicInfo.append(ChatColor.BLACK).append("Username ").append(ChatColor.DARK_AQUA).append(inf.getPlayer()).append(InfractInjector.ENTER_CHAR);
- + basicInfo.append(ChatColor.BLACK).append("Username ").append(ChatColor.DARK_AQUA).append(inf.getPlayerCredentials().getUniqueId().toString()).append(InfractInjector.ENTER_CHAR);
- basicInfo.append(ChatColor.BLACK).append("Intensity ").append(ChatColor.DARK_AQUA).append(inf.getIntensity().name()).append(InfractInjector.ENTER_CHAR);
- 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);
- - basicInfo.append(ChatColor.BLACK).append("Staff ").append(ChatColor.DARK_AQUA).append(inf.getStaffmember()).append(InfractInjector.ENTER_CHAR);
- + basicInfo.append(ChatColor.BLACK).append("Staff ").append(ChatColor.DARK_AQUA).append(inf.getCreatorCredentials()).append(InfractInjector.ENTER_CHAR);
- // Revoke details
- if (inf.isRevoked()) {
- - basicInfo.append(ChatColor.BLACK).append("Revoked by: ").append(ChatColor.RED).append(inf.getRevoker()).append(InfractInjector.ENTER_CHAR);
- + basicInfo.append(ChatColor.BLACK).append("Revoked by: ").append(ChatColor.RED).append(inf.getRevokerCredentials().getUniqueId().toString()).append(InfractInjector.ENTER_CHAR);
- basicInfo.append(ChatColor.BLACK).append("Revoked on: ").append(ChatColor.RED).append(DateUtil.formatString(inf.getRevokeDate(), DateUtil.FORMAT_DDMMYYYY_HHMM)).append(InfractInjector.ENTER_CHAR);
- }
- @@ -298,15 +324,13 @@ public final class ModerationCommands {
- }
- IdpPlayer targetPlayer = parent.getPlayer(args.getString(0), false, true);
- - String username = (targetPlayer != null ? targetPlayer.getName() : args.getString(0));
- + String playerName = (targetPlayer != null ? targetPlayer.getName() : args.getString(0));
- - if (targetPlayer == null) {
- - PlayerGroup group = PlayerGroup.getGroupOfUsername(username);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- - if (group == PlayerGroup.NONE) {
- - sender.printError("That player doesn't exist! Cannot ban.");
- - return true;
- - }
- + if (credentials == null) {
- + sender.printError("That player doesn't exist! Cannot ban.");
- + return true;
- }
- if (args.hasArgument("time", "t")) {
- @@ -332,8 +356,7 @@ public final class ModerationCommands {
- return true;
- }
- - username = BanHandler.getPartialName(username);
- - BanObject ban = BanHandler.getBan(username);
- + BanObject ban = BanHandler.getBan(credentials.getUniqueId());
- if (ban != null && (sender instanceof IdpPlayer) && !ban.canModifyBan((IdpPlayer) sender)) {
- sender.printError("You did not ban this player! Unable to modify.");
- @@ -341,41 +364,41 @@ public final class ModerationCommands {
- }
- if (isLinkedBan) {
- - BanObject testBan = BanHandler.getBan(username);
- -
- if (ban != null) {
- - boolean ipbanned = (testBan instanceof IPBanObject);
- + boolean ipbanned = (ban instanceof IPBanObject);
- sender.printError("This user is already " + (ipbanned ? "ip" : "") + "banned. Unable to link!");
- return true;
- }
- String linkedUsername = args.getString("link");
- - PlayerGroup linkedGroup = PlayerGroup.getGroupOfUsername(linkedUsername);
- - String coloredLinkedUsername = linkedGroup.getPrefix().getTextColor() + linkedUsername;
- + PlayerCredentials linkedCredentials = PlayerCredentialsManager.getByName(linkedUsername);
- - if (linkedGroup == PlayerGroup.NONE) {
- - sender.printError("The username to link to does not exist!");
- + if (linkedCredentials == null) {
- + sender.printError("The username to link this ban to does not exist!");
- return true;
- }
- + PlayerGroup linkedGroup = PlayerGroup.getGroupOfPlayerById(linkedCredentials.getUniqueId());
- + String coloredLinkedUsername = linkedGroup.getPrefix().getTextColor() + linkedUsername;
- +
- String ip;
- if (targetPlayer != null) {
- ip = targetPlayer.getHandle().getAddress().getAddress().getHostAddress();
- } else {
- - ip = IPLogger.getLastUsedIP(username);
- + ip = IPLogger.getLastUsedIP(credentials.getUniqueId(), credentials.getName());
- }
- - PlayerGroup userGroup = PlayerGroup.getGroupOfUsername(username);
- - String coloredUsername = userGroup.getPrefix().getTextColor() + username;
- + PlayerGroup userGroup = PlayerGroup.getGroupOfPlayerById(credentials.getUniqueId());
- + String coloredUsername = userGroup.getPrefix().getTextColor() + playerName;
- - LinkStatus status = BanHandler.linkIPBan(((sender instanceof IdpPlayer) ? (IdpPlayer) sender : null), username, ip, linkedUsername);
- + LinkStatus status = BanHandler.linkIPBan(sender, credentials, ip, linkedCredentials);
- switch (status) {
- case LINK_SUCCESSFUL:
- sender.printInfo(coloredUsername + ChatColor.YELLOW + " was linked to " + coloredLinkedUsername + ChatColor.YELLOW + "'s ip ban.");
- - String resultMsg = username + " was linked to " + linkedUsername + "'s ip ban.";
- + String resultMsg = playerName + " was linked to " + linkedUsername + "'s ip ban.";
- parent.broadCastMessage(ChatColor.RED + Configuration.MESSAGE_PREFIX + resultMsg);
- break;
- case LINK_NOT_FOUND:
- @@ -391,47 +414,58 @@ public final class ModerationCommands {
- } else {
- if ((ban instanceof IPBanObject) && !isIPBan) {
- IPBanObject ipban = (IPBanObject) ban;
- - String ipbannedusers = "";
- - List<String> ipbanList = ipban.getGroup().getPlayers();
- + String ipBannedPlayerString = "";
- + List<PlayerCredentials> ipBannedPlayers = ipban.getGroup().getPlayers();
- - for (String user : ipbanList) {
- - PlayerGroup group = PlayerGroup.getGroupOfUsername(user);
- + for (PlayerCredentials pc : ipBannedPlayers) {
- + String name = pc.getName();
- + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(pc.getUniqueId());
- - if (ipbannedusers.isEmpty()) {
- - ipbannedusers = group.getPrefix().getTextColor() + user;
- + if (ipBannedPlayerString.isEmpty()) {
- + ipBannedPlayerString = group.getPrefix().getTextColor() + name;
- } else {
- - ipbannedusers += ChatColor.WHITE + ", " + group.getPrefix().getTextColor() + user;
- + ipBannedPlayerString += ChatColor.WHITE + ", " + group.getPrefix().getTextColor() + name;
- }
- }
- - if (ipbanList.size() > 1) {
- + if (ipBannedPlayers.size() > 1) {
- sender.print(ChatColor.YELLOW, "You switched an ipban with multiple accounts to a ban.");
- - sender.print(ChatColor.YELLOW, "IP banned users: " + ipbannedusers);
- + sender.print(ChatColor.YELLOW, "IP banned users: " + ipBannedPlayerString);
- } else {
- - sender.print(ChatColor.RED, username + " was previously ipbanned. Changing to ban. ");
- + sender.print(ChatColor.RED, playerName + " was previously ipbanned. Changing to ban. ");
- }
- BanHandler.removeBan(ban);
- } else if ((ban instanceof UserBanObject) && isIPBan) {
- - sender.print(ChatColor.RED, username + " was previously banned. Changing to ipban.");
- + sender.print(ChatColor.RED, playerName + " was previously banned. Changing to ipban.");
- BanHandler.removeBan(ban);
- }
- + PlayerCredentials bannedByPlayerCredentials = null;
- +
- + // Since console can ban players, our system won't work that way
- + // so replace the console with the name of a stored player we have
- + if (sender instanceof IdpConsole) {
- + bannedByPlayerCredentials = Configuration.SERVER_GENERATED_CREDENTIALS;
- + } else {
- + bannedByPlayerCredentials = PlayerCredentialsManager.getByName(sender.getName());
- + }
- +
- if (isIPBan) {
- List<String> IPs = new ArrayList<String>();
- - String ip = IPLogger.getLastUsedIP(username);
- + String ip = IPLogger.getLastUsedIP(credentials.getUniqueId(), credentials.getName());
- if (ip != null) {
- IPs.add(ip);
- }
- - List<String> usernames = new ArrayList<String>();
- - usernames.add(username);
- - IPBanGroup group = new IPBanGroup(IPs, usernames);
- + List<PlayerCredentials> players = new ArrayList<PlayerCredentials>();
- + players.add(credentials);
- + IPBanGroup group = new IPBanGroup(IPs, players);
- - ban = new IPBanObject(group, sender.getName(), new Timestamp(System.currentTimeMillis()), banFormula, isJoinBan);
- + ban = new IPBanObject(group, bannedByPlayerCredentials, new Timestamp(System.currentTimeMillis()), banFormula, isJoinBan);
- } else {
- - ban = new UserBanObject(username, sender.getName(), new Timestamp(System.currentTimeMillis()), banFormula, isJoinBan);
- + ban = new UserBanObject(credentials, bannedByPlayerCredentials, new Timestamp(System.currentTimeMillis()), banFormula, isJoinBan);
- }
- BanResult result = BanHandler.addBan(ban);
- @@ -440,11 +474,11 @@ public final class ModerationCommands {
- switch (result) {
- case BAN_FRESH:
- case BAN_FRESH_IP:
- - 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() + ".";
- + 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() + ".";
- break;
- case BAN_EXISTING:
- case BAN_EXISTING_IP:
- - 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() + ".";
- + 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() + ".";
- break;
- }
- @@ -457,6 +491,7 @@ public final class ModerationCommands {
- return true;
- }
- +
- return false;
- }
- @@ -467,8 +502,18 @@ public final class ModerationCommands {
- serverCommand = true)
- public static boolean commandUnBan(InnPlugin parent, IdpCommandSender sender, LynxyArguments args) {
- if (args.getActionSize() > 0) {
- - String username = BanHandler.getPartialName(args.getString(0));
- - BanObject ban = BanHandler.getBan(username);
- + String playerName = BanHandler.getPartialName(args.getString(0));
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- +
- + if (credentials == null) {
- + sender.printError("That player does not exist.");
- + return true;
- + } else {
- + // Get the proper casing of the name
- + playerName = credentials.getName();
- + }
- +
- + BanObject ban = BanHandler.getBan(credentials.getUniqueId());
- if (ban == null) {
- sender.printError("That user is not banned.");
- @@ -484,18 +529,18 @@ public final class ModerationCommands {
- boolean isUnlinkedBan = (args.hasOption("unlink"));
- if (isUnlinkedBan) {
- - String ip = IPLogger.getLastUsedIP(username);
- + String ip = IPLogger.getLastUsedIP(credentials.getUniqueId(), credentials.getName());
- - UnlinkStatus status = BanHandler.unlinkIPBan(((sender instanceof IdpPlayer) ? (IdpPlayer) sender : null), username, ip);
- - PlayerGroup group = PlayerGroup.getGroupOfUsername(username);
- - String coloredUsername = group.getPrefix().getTextColor() + username;
- + UnlinkStatus status = BanHandler.unlinkIPBan(sender, credentials, ip);
- + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(credentials.getUniqueId());
- + String coloredUsername = group.getPrefix().getTextColor() + playerName;
- switch (status) {
- case UNLINK_FOUND:
- sender.printInfo(coloredUsername + ChatColor.YELLOW + " was unlinked from a previous ip ban.");
- break;
- case UNLINK_NOT_FOUND:
- - sender.printError(username + " is not linked to any ip ban.");
- + sender.printError(playerName + " is not linked to any ip ban.");
- return true;
- case UNLINK_REMOVED_BAN:
- sender.printInfo(coloredUsername + ChatColor.DARK_GREEN + " was unlinked from a previous ip ban");
- @@ -506,21 +551,23 @@ public final class ModerationCommands {
- return true;
- }
- - parent.broadCastMessage(ChatColor.RED + Configuration.MESSAGE_PREFIX + username + " was unipbanned");
- + parent.broadCastMessage(ChatColor.RED + Configuration.MESSAGE_PREFIX + playerName + " was unipbanned");
- } else {
- if (isIPBan) {
- IPBanObject ipban = (IPBanObject) ban;
- - List<String> players = ipban.getGroup().getPlayers();
- + List<PlayerCredentials> players = ipban.getGroup().getPlayers();
- String playerList = "";
- - for (String player : players) {
- - PlayerGroup pGroup = PlayerGroup.getGroupOfUsername(player);
- + for (PlayerCredentials pc : players) {
- + String name = pc.getName();
- + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(pc.getUniqueId());
- + ChatColor textColor = group.getPrefix().getTextColor();
- if (playerList.isEmpty()) {
- - playerList += pGroup.getPrefix().getTextColor() + player;
- + playerList += textColor + name;
- } else {
- - playerList += ChatColor.WHITE + ", " + pGroup.getPrefix().getTextColor() + player;
- + playerList += ChatColor.WHITE + ", " + textColor + name;
- }
- }
- @@ -531,7 +578,7 @@ public final class ModerationCommands {
- }
- BanHandler.removeBan(ban);
- - parent.broadCastMessage(ChatColor.RED + Configuration.MESSAGE_PREFIX + username + " was un" + (isIPBan ? "ip" : "") + "banned by " + sender.getName() + "!");
- + parent.broadCastMessage(ChatColor.RED + Configuration.MESSAGE_PREFIX + playerName + " was un" + (isIPBan ? "ip" : "") + "banned by " + sender.getName() + "!");
- }
- return true;
- @@ -679,14 +726,21 @@ public final class ModerationCommands {
- if (username == null || args.hasOption("help", "h")) {
- int pageNo = args.getIntDefaultTo(1, "page", "p");
- - List<String> whitelistPlayers = BanHandler.getWhitelist();
- - PagedCommandHandler ph = new PagedCommandHandler(pageNo, whitelistPlayers);
- + List<PlayerCredentials> whitelistPlayers = BanHandler.getWhitelist();
- if (whitelistPlayers == null) {
- sender.printError("There are no whitelisted users.");
- return true;
- }
- + List<String> whitelistNames = new ArrayList<String>();
- +
- + for (PlayerCredentials credentials : whitelistPlayers) {
- + whitelistNames.add(credentials.getName());
- + }
- +
- + PagedCommandHandler ph = new PagedCommandHandler(pageNo, whitelistNames);
- +
- if (ph.isValidPage()) {
- ph.adjustEntriesPerLine(3);
- sender.printInfo("Listing " + ph.getStartLine() + "-" + ph.getEndLine() + " whitelisted players. Showing page: " + pageNo + " of " + ph.getMaxPage());
- @@ -702,14 +756,19 @@ public final class ModerationCommands {
- }
- if (args.hasOption("add", "a")) {
- - PlayerGroup group = PlayerGroup.getGroupOfUsername(username);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(username);
- - if (group == PlayerGroup.NONE) {
- + if (credentials == null) {
- sender.printError("That username doesn't exist.");
- return true;
- }
- - BanHandler.addWhitelist(username);
- + if (BanHandler.isWhitelisted(credentials.getUniqueId())) {
- + sender.printError("That username is already whitelisted.");
- + return true;
- + }
- +
- + BanHandler.addWhitelist(credentials);
- sender.printInfo("Added " + username + " to the ban whitelist.");
- @@ -717,15 +776,14 @@ public final class ModerationCommands {
- }
- if (args.hasOption("remove", "rem")) {
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(username);
- - PlayerGroup group = PlayerGroup.getGroupOfUsername(username);
- -
- - if (group == PlayerGroup.NONE) {
- + if (credentials == null) {
- sender.printError("That username doesn't exist.");
- return true;
- }
- - BanHandler.removeWhitelist(username);
- + BanHandler.removeWhitelist(credentials);
- sender.printInfo("Removed " + username + " from the ban whitelist.");
- @@ -775,16 +833,16 @@ public final class ModerationCommands {
- }
- if (args.getString(0) != null) {
- - String name = args.getString(0).toLowerCase();
- - IdpPlayer tarplayer = parent.getPlayer(name, false);
- - if (tarplayer != null && tarplayer.isOnline()) {
- + String playerName = args.getString(0);
- + IdpPlayer target = parent.getPlayer(playerName);
- - if (tarplayer.getWorld().getWorldType() == IdpWorldType.NETHER) {
- + if (target != null && target.isOnline()) {
- + if (target.getWorld().getWorldType() == IdpWorldType.NETHER) {
- boolean force = args.hasOption("force", "f")
- && sender.hasPermission(Permission.teleport_others_force);
- if (!force) {
- - String msg = tarplayer.getColoredDisplayName() + ChatColor.RED + " is in the nether.";
- + String msg = target.getColoredDisplayName() + ChatColor.RED + " is in the nether.";
- if (sender.hasPermission(Permission.teleport_others_force)) {
- msg += " Use -force to jail them.";
- @@ -797,31 +855,45 @@ public final class ModerationCommands {
- }
- }
- - if (tarplayer.getSession().isJailed()) {
- - sender.printError(tarplayer.getName() + " is already jailed!");
- + if (target.getSession().isJailed()) {
- + sender.printError(target.getName() + " is already jailed!");
- return true;
- }
- - if (tarplayer.isOnline()) {
- + if (target.isOnline()) {
- IdpWarp jail = WarpHandler.getJail();
- if (jail.getLocation() == WarpHandler.getSpawn()) {
- sender.printError("Jail warp was not found! User not jailed.");
- return true;
- }
- - if (tarplayer.teleport(jail)) {
- - tarplayer.getSession().setJailed(true);
- - sender.printInfo(tarplayer.getName() + " has been jailed!");
- - tarplayer.printError("You have been jailed.");
- + if (target.teleport(jail)) {
- + target.getSession().setJailed(true);
- + sender.printInfo(target.getName() + " has been jailed!");
- + target.printError("You have been jailed.");
- } else {
- sender.printError("Failed to teleport user to jail!");
- }
- }
- } else {
- - PlayerSession.getSession(name, parent).setJailed(true);
- - sender.printInfo(name + " has been jailed!");
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- +
- + if (credentials == null) {
- + sender.printError("That player doesn't exist!");
- + return false;
- + }
- +
- + if (PlayerSession.hasSession(playerName)) {
- + PlayerSession session = PlayerSession.getSession_(playerName);
- + session.setJailed(true);
- + sender.printInfo(playerName + " has been jailed!");
- + } else {
- + sender.printError("That player doesn't have an active session. Unable to jail!");
- + }
- }
- +
- return true;
- }
- +
- return false;
- }
- @@ -901,30 +973,31 @@ public final class ModerationCommands {
- }
- if (args.getString(0) != null) {
- - String name = args.getString(0).toLowerCase();
- - IdpPlayer tarplayer = parent.getPlayer(name, false);
- - if (tarplayer != null && tarplayer.isOnline()) {
- - name = tarplayer.getName().toLowerCase();
- - }
- -
- - if (PlayerSession.hasSession(name)) {
- - PlayerSession session = PlayerSession.getSession(name, parent);
- + String playerName = args.getString(0);
- + PlayerSession session = null;
- - if (args.hasArgument("time", "t")) {
- - long formula = DateUtil.getTimeFormula(args.getString("time", "t"));
- + if (PlayerSession.hasSession(playerName)) {
- + session = PlayerSession.getSession_(playerName);
- + } else {
- + sender.printError(playerName + " doesn't have an active session!");
- + return true;
- + }
- - if (formula == -1) {
- - sender.printError("Incorrect mute formula. (Ex. 5m3s)");
- - return true;
- - }
- + if (args.hasArgument("time", "t")) {
- + long formula = DateUtil.getTimeFormula(args.getString("time", "t"));
- - session.setMuteTicks(System.currentTimeMillis() + formula);
- - sender.printInfo(name + " is silenced for " + DateUtil.getTimeString(formula, true) + ".");
- - } else {
- - session.setMuteTicks(-1);
- - sender.printInfo(name + " is silenced.");
- + if (formula == -1) {
- + sender.printError("Incorrect mute formula. (Ex. 5m3s)");
- + return true;
- }
- +
- + session.setMuteTicks(System.currentTimeMillis() + formula);
- + sender.printInfo(playerName + " is silenced for " + DateUtil.getTimeString(formula, true) + ".");
- + } else {
- + session.setMuteTicks(-1);
- + sender.printInfo(playerName + " is silenced.");
- }
- +
- return true;
- }
- return false;
- @@ -963,36 +1036,35 @@ public final class ModerationCommands {
- serverCommand = true)
- public static boolean commandUnJail(InnPlugin parent, IdpCommandSender sender, String[] args) {
- if (args.length == 1) {
- - String name = args[0].toLowerCase();
- - IdpPlayer tarplayer = parent.getPlayer(name, false);
- - PlayerSession session;
- - if (tarplayer != null && tarplayer.isOnline()) {
- - name = tarplayer.getName();
- - session = tarplayer.getSession();
- + String playerName = args[0];
- + PlayerSession session = null;
- +
- + if (PlayerSession.hasSession(playerName)) {
- + session = PlayerSession.getSession_(playerName);
- } else {
- - if (PlayerSession.hasSession(name)) {
- - sender.printError(args[0] + " doesn't have an active session!");
- - return true;
- - } else {
- - session = PlayerSession.getSession(name, parent);
- - }
- + sender.printError(playerName + " doesn't have an active session. Cannot unjail!");
- + return true;
- }
- if (!session.isJailed()) {
- - sender.printError(args[0] + " is not jailed!");
- + sender.printError(playerName + " is not jailed!");
- return true;
- }
- session.setJailed(false);
- - sender.printInfo(name + " has been unjailed!");
- + sender.printInfo(playerName + " has been unjailed!");
- +
- + IdpPlayer tarplayer = parent.getPlayer(playerName);
- if (tarplayer != null && tarplayer.isOnline()) {
- tarplayer.teleport(WarpHandler.getSpawn(tarplayer.getGroup()));
- tarplayer.printInfo("You have been unjailed.");
- }
- +
- return true;
- }
- +
- return false;
- }
- @@ -1003,24 +1075,23 @@ public final class ModerationCommands {
- serverCommand = true)
- public static boolean commandUnMute(InnPlugin parent, IdpCommandSender sender, String[] args) {
- if (args.length == 1) {
- - String name = args[0].toLowerCase();
- - IdpPlayer tarplayer = parent.getPlayer(args[0], false);
- + String playerName = args[0];
- + PlayerSession session = null;
- - if (tarplayer != null && tarplayer.isOnline()) {
- - name = tarplayer.getName().toLowerCase();
- + if (PlayerSession.hasSession(playerName)) {
- + session = PlayerSession.getSession_(playerName);
- + } else {
- + sender.printError("That player doesn't have an active session. Cannot unmute!");
- + return true;
- }
- - if (PlayerSession.hasSession(name)) {
- - PlayerSession session = PlayerSession.getSession(name, parent);
- -
- - long muteTicks = session.getRemainingMuteTicks();
- + long muteTicks = session.getRemainingMuteTicks();
- - if (muteTicks == 0) {
- - sender.printError(name + " is not muted!");
- - } else {
- - session.setMuteTicks(0);
- - sender.printInfo(name + " is not longer muted.");
- - }
- + if (muteTicks == 0) {
- + sender.printError(playerName + " is not muted!");
- + } else {
- + session.setMuteTicks(0);
- + sender.printInfo(playerName + " is not longer muted.");
- }
- return true;
- @@ -1036,21 +1107,21 @@ public final class ModerationCommands {
- serverCommand = true)
- public static boolean commandFreeze(InnPlugin parent, IdpCommandSender sender, String[] args) {
- if (args.length == 1) {
- - String name = args[0].toLowerCase();
- - IdpPlayer tarplayer = parent.getPlayer(args[0], false);
- - if (tarplayer != null && tarplayer.isOnline()) {
- - name = tarplayer.getName().toLowerCase();
- - }
- + String playerName = args[0];
- + PlayerSession session = null;
- - if (PlayerSession.hasSession(name)) {
- - PlayerSession session = PlayerSession.getSession(name, parent);
- + if (PlayerSession.hasSession(playerName)) {
- + session = PlayerSession.getSession_(playerName);
- + } else {
- + sender.printError("That player doesn't have an active session. Unable to freeze!");
- + return true;
- + }
- - if (session.isFrozen()) {
- - sender.printError(name + " is already frozen!");
- - } else {
- - session.setFrozen(true);
- - sender.printInfo(name + " was frozen.");
- - }
- + if (session.isFrozen()) {
- + sender.printError(playerName + " is already frozen!");
- + } else {
- + session.setFrozen(true);
- + sender.printInfo(playerName + " was frozen.");
- }
- return true;
- @@ -1066,23 +1137,23 @@ public final class ModerationCommands {
- serverCommand = true)
- public static boolean commandUnFreeze(InnPlugin parent, IdpCommandSender sender, String[] args) {
- if (args.length == 1) {
- - String name = args[0].toLowerCase();
- - IdpPlayer tarplayer = parent.getPlayer(args[0], false);
- + String playerName = args[0];
- + PlayerSession session = null;
- - if (tarplayer != null && tarplayer.isOnline()) {
- - name = tarplayer.getName().toLowerCase();
- + if (PlayerSession.hasSession(playerName)) {
- + session = PlayerSession.getSession_(playerName);
- + } else {
- + sender.printError(playerName + " does not have an active session. Unable to unfreeze!");
- + return true;
- }
- - if (PlayerSession.hasSession(name)) {
- - PlayerSession session = PlayerSession.getSession(name, parent);
- -
- - if (!session.isFrozen()) {
- - sender.printError(name + " is not frozen!");
- - } else {
- - session.setFrozen(false);
- - sender.printInfo(name + " is not longer frozen.");
- - }
- + if (!session.isFrozen()) {
- + sender.printError(playerName + " is not frozen!");
- + } else {
- + session.setFrozen(false);
- + sender.printInfo(playerName + " is not longer frozen.");
- }
- +
- return true;
- }
- return false;
- diff --git a/src/net/innectis/innplugin/Command/Commands/PlayerCommands.java b/src/net/innectis/innplugin/Command/Commands/PlayerCommands.java
- index b47940c1f..1752b8d48 100644
- --- a/src/net/innectis/innplugin/Command/Commands/PlayerCommands.java
- +++ b/src/net/innectis/innplugin/Command/Commands/PlayerCommands.java
- @@ -7,6 +7,7 @@ import java.util.Date;
- import java.util.List;
- import java.util.TimeZone;
- import net.innectis.innplugin.Command.CommandMethod;
- +import net.innectis.innplugin.Configuration;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.Handlers.PagedCommandHandler;
- import net.innectis.innplugin.Handlers.StaffMessageHandler;
- @@ -160,7 +161,9 @@ public final class PlayerCommands {
- return false;
- }
- - if (!player.getName().equalsIgnoreCase(args.getString(0))) {
- + String newName = args.getString(0);
- +
- + if (!player.getName().equalsIgnoreCase(newName)) {
- player.printError("You can only change the case of your username!");
- return true;
- }
- @@ -168,12 +171,12 @@ public final class PlayerCommands {
- PreparedStatement statement = null;
- try {
- - statement = DBManager.prepareStatement(" UPDATE players SET name = ? WHERE lower(name) = ?");
- - statement.setString(1, args.getString(0));
- - statement.setString(2, player.getName());
- + statement = DBManager.prepareStatement("UPDATE players SET name = ? WHERE player_id = ?;");
- + statement.setString(1, newName);
- + statement.setString(2, player.getUniqueId().toString());
- statement.executeUpdate();
- - InnPlugin.logInfo("Player ", player.getColoredDisplayName() + " changed name into " + args.getString(0));
- + InnPlugin.logInfo("Player ", player.getColoredDisplayName() + " changed name into " + newName);
- player.getSession().refixUsername();
- player.printInfo("Name updated!");
- @@ -359,28 +362,35 @@ public final class PlayerCommands {
- return true;
- }
- - session.addIgnoredUser("%");
- + session.addIgnoredUser(Configuration.EVERYONE_CREDENTIALS);
- player.print(ChatColor.AQUA, "Added everyone to the ignore list.");
- } else {
- - String ignorePlayer = args.getString(0);
- + String playerName = args.getString(0);
- + IdpPlayer target = parent.getPlayer(playerName);
- +
- + if (target != null) {
- + playerName = target.getName();
- + }
- +
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- - if (!PlayerSession.isValidPlayer(ignorePlayer)) {
- + if (credentials == null) {
- player.printError("That player doesn't exist!");
- return true;
- }
- - if (ignorePlayer.equalsIgnoreCase(player.getName())) {
- + if (playerName.equalsIgnoreCase(player.getName())) {
- player.printError("You cannot ignore yourself!");
- return true;
- }
- - if (session.isIgnored(ignorePlayer)) {
- + if (session.isIgnored(playerName)) {
- player.printError("This player is already ignored!");
- return true;
- }
- - if (session.addIgnoredUser(ignorePlayer)) {
- - player.print(ChatColor.AQUA, "Added " + ignorePlayer + " to the ignore list.");
- + if (session.addIgnoredUser(credentials)) {
- + player.print(ChatColor.AQUA, "Added " + playerName + " to the ignore list.");
- } else {
- player.printError("That player cannot be ignored.");
- }
- @@ -395,12 +405,14 @@ public final class PlayerCommands {
- usage = "/ignored",
- serverCommand = false)
- public static void commandIgnored(IdpPlayer player) {
- - List<String> ignoredPlayers = player.getSession().getIgnoredPlayers();
- + List<PlayerCredentials> ignoredPlayers = player.getSession().getIgnoredPlayers();
- if (!ignoredPlayers.isEmpty()) {
- String ignoredPlayersString = "";
- - for (String ignoredPlayer : ignoredPlayers) {
- + for (PlayerCredentials pc : ignoredPlayers) {
- + String ignoredPlayer = pc.getName();
- +
- if (ignoredPlayersString.isEmpty()) {
- ignoredPlayersString = ignoredPlayer;
- } else {
- @@ -609,7 +621,7 @@ public final class PlayerCommands {
- m.save();
- }
- - PlayerGroup group = PlayerGroup.getGroupOfUsername(m.getCreator());
- + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(m.getCreatorCredentials().getUniqueId());
- ChatColor color = group.getPrefix().getTextColor();
- player.printInfo("From: " + color + m.getCreator() + ChatColor.DARK_GREEN + " (" + m.getTitle() + ") " + m.getMessage());
- @@ -644,23 +656,33 @@ public final class PlayerCommands {
- return true;
- }
- - String from = player.getName();
- - String title = sargs.getString(1);
- - String content = sargs.getJoinedStrings(2);
- - int lengthToCheck = 100;
- - IdpPlayer toPlayer = parent.getPlayer(sargs.getString(0), false, true);
- - String to = (toPlayer != null ? toPlayer.getName() : sargs.getString(0));
- + String toPlayer = sargs.getString(0);
- + IdpPlayer target = parent.getPlayer(toPlayer);
- - if (from.equalsIgnoreCase(to)) {
- - player.printError("You can't send mail to yourself.");
- + if (target != null) {
- + toPlayer = target.getName();
- + }
- +
- + PlayerCredentials toPlayerCredentials = PlayerCredentialsManager.getByName(toPlayer);
- +
- + if (toPlayerCredentials == null) {
- + player.printError("That player does not exist.");
- return true;
- + } else {
- + // Get the proper casing of the name
- + toPlayer = toPlayerCredentials.getName();
- }
- - PlayerGroup group = PlayerGroup.getGroupOfUsername(to);
- + String fromPlayer = player.getName();
- + PlayerCredentials fromPlayerCredentials = PlayerCredentialsManager.getByName(fromPlayer);
- +
- + String title = sargs.getString(1);
- + String content = sargs.getJoinedStrings(2);
- + int lengthToCheck = 100;
- - if (group == PlayerGroup.NONE) {
- - player.printError("That player doesn't exist.");
- + if (fromPlayer.equalsIgnoreCase(toPlayer)) {
- + player.printError("You can't send mail to yourself.");
- return true;
- }
- @@ -673,19 +695,23 @@ public final class PlayerCommands {
- return true;
- }
- - LogManager.getMailLogger().log(from, to, title, content);
- + PlayerCredentialsManager.addCredentialsToCache(fromPlayerCredentials);
- + PlayerCredentialsManager.addCredentialsToCache(toPlayerCredentials);
- - MailMessage obj = new MailMessage(new Date(), from, to, title, content);
- + LogManager.getMailLogger().log(fromPlayer, toPlayer, title, content);
- +
- + MailMessage obj = new MailMessage(new Date(), fromPlayerCredentials, toPlayerCredentials, title, content);
- obj.save();
- - if (toPlayer != null) {
- - toPlayer.getSession().addMail(obj);
- + if (target != null) {
- + target.getSession().addMail(obj);
- - if (toPlayer.isOnline()) {
- - toPlayer.printInfo(player.getColoredDisplayName() + ChatColor.DARK_GREEN + " has just sent you mail!");
- + if (target.isOnline()) {
- + target.printInfo(player.getColoredDisplayName() + ChatColor.DARK_GREEN + " has just sent you mail!");
- }
- }
- - player.printInfo("Sent a mail message to " + to + "!");
- +
- + player.printInfo("Sent a mail message to " + toPlayer + "!");
- return true;
- }
- @@ -724,7 +750,7 @@ public final class PlayerCommands {
- boolean restricted = !sender.hasPermission(Permission.command_staffrequest_special);
- for (StaffMessage sm : staffRequests) {
- - PlayerGroup group = PlayerGroup.getGroupOfUsername(sm.getCreator());
- + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(sm.getCreatorCredentials().getUniqueId());
- String coloredName = group.getPrefix().getTextColor() + sm.getCreator();
- java.sql.Date date = new java.sql.Date(sm.getDate().getTime());
- @@ -781,7 +807,7 @@ public final class PlayerCommands {
- return true;
- }
- - PlayerGroup group = PlayerGroup.getGroupOfUsername(sm.getCreator());
- + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(sm.getCreatorCredentials().getUniqueId());
- String coloredName = group.getPrefix().getTextColor() + sm.getCreator();
- java.sql.Date date = new java.sql.Date(sm.getDate().getTime());
- @@ -818,7 +844,7 @@ public final class PlayerCommands {
- StaffMessage sm = StaffMessageHandler.deleteStaffRequeustById(requestId);
- if (sm != null) {
- - PlayerGroup group = PlayerGroup.getGroupOfUsername(sm.getCreator());
- + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(sm.getCreatorCredentials().getUniqueId());
- String coloredName = group.getPrefix().getTextColor() + sm.getCreator();
- String staffMsg = sender.getColoredName() + ChatColor.DARK_GREEN + " deleted staff request ID " + requestId + " by " + coloredName + ChatColor.DARK_GREEN + ": " + ChatColor.YELLOW + sm.getMessage();
- @@ -872,7 +898,8 @@ public final class PlayerCommands {
- return true;
- }
- - StaffMessage sm = new StaffMessage(new Date(), player.getName(), request);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName());
- + StaffMessage sm = new StaffMessage(new Date(), credentials, request);
- boolean result = StaffMessageHandler.addStaffRequest(sm);
- if (result) {
- @@ -903,21 +930,21 @@ public final class PlayerCommands {
- usage = "/backpack",
- usage_Admin = "/backpack [player]",
- serverCommand = false)
- - public static boolean commandBackpack(InnPlugin plugin, IdpPlayer player, LynxyArguments args) {
- + public static boolean commandBackpack(InnPlugin parent, IdpPlayer player, LynxyArguments args) {
- boolean override = player.hasPermission(Permission.special_backpack_override);
- boolean self = true;
- - String name = player.getName();
- + String playerName = player.getName();
- if (args.getActionSize() > 0) {
- if (override) {
- - name = args.getString(0);
- + playerName = args.getString(0);
- + IdpPlayer target = parent.getPlayer(playerName);
- - if (!PlayerSession.isValidPlayer(name)) {
- - player.printError("That player doesn't exist!");
- - return true;
- + if (target != null) {
- + playerName = target.getName();
- }
- - self = name.equalsIgnoreCase(player.getName());
- + self = playerName.equalsIgnoreCase(player.getName());
- }
- }
- @@ -935,12 +962,19 @@ public final class PlayerCommands {
- }
- }
- - IdpInventory inv = plugin.getBackpackView(name);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- +
- + if (credentials == null) {
- + player.printError("That player doesn't exist!");
- + return true;
- + }
- +
- + IdpInventory inv = parent.getBackpackView(credentials.getUniqueId());
- boolean fresh = false;
- if (inv == null) {
- - inv = new IdpInventory(name + "'s backpack", 27);
- - plugin.addBackpackView(name, inv);
- + inv = new IdpInventory(playerName + "'s backpack", 27);
- + parent.addBackpackView(credentials.getUniqueId(), inv);
- fresh = true;
- }
- @@ -951,20 +985,21 @@ public final class PlayerCommands {
- if (self) {
- backpack = player.getSession().getBackpack();
- } else {
- - IdpPlayer testPlayer = plugin.getPlayer(name);
- + IdpPlayer testPlayer = parent.getPlayer(playerName);
- if (testPlayer != null) {
- backpack = testPlayer.getSession().getBackpack();
- } else {
- - backpack = PlayerBackpack.loadBackpackFromDB(name);
- + backpack = PlayerBackpack.loadBackpackFromDB(credentials.getUniqueId(), credentials.getName());
- }
- }
- inv.setContents(backpack.getItems());
- }
- - player.printInfo("You open " + (self ? "your " : name + "'s ") + "backpack!");
- - player.getSession().setBackpackOwner(name);
- + player.printInfo("You open " + (self ? "your " : playerName + "'s ") + "backpack!");
- + player.getSession().setBackpackOwnerId(credentials.getUniqueId());
- + player.getSession().setBackpackOwner(credentials.getName());
- player.openInventory(inv);
- return true;
- @@ -978,7 +1013,6 @@ public final class PlayerCommands {
- obfusticateLogging = true,
- serverCommand = false)
- public static boolean commandLogin(IdpPlayer player, ParameterArguments args) {
- -
- // Check if password was given.
- if (args.size() != 0 && args.size() != 1) {
- return false;
- @@ -992,17 +1026,16 @@ public final class PlayerCommands {
- }
- // Check password
- - if (PlayerSecurity.checkPlayerPassword(player.getName(), args.getString(0))) {
- -
- + if (PlayerSecurity.checkPlayerPassword(player.getUniqueId(), player.getName(), args.getString(0))) {
- player.printInfo("Loggin in succesfully.");
- player.getSession().setPlayerLoggedin(true);
- return true;
- } else {
- - PlayerSecurity.logBadPassword(player.getName(), player.getHandle().getAddress().getAddress().getHostAddress());
- + PlayerSecurity.logBadPassword(player.getUniqueId(), player.getName(), player.getHandle().getAddress().getAddress().getHostAddress());
- // Check if they can still try, if not kick
- - if (!PlayerSecurity.canLogin(player.getName())) {
- + if (!PlayerSecurity.canLogin(player.getUniqueId(), player.getName())) {
- player.getHandle().kickPlayer("Your password was incorrect.");
- } else {
- player.printError("Password incorrect!");
- @@ -1011,7 +1044,6 @@ public final class PlayerCommands {
- return true;
- }
- } else {
- -
- // Check if player wants to update password
- if (args.hasOption("update", "new", "u")) {
- @@ -1020,10 +1052,10 @@ public final class PlayerCommands {
- if (args.size() == 0) {
- // Check if player has a password;
- - canChange = !PlayerSecurity.hasPassword(player.getName());
- + canChange = !PlayerSecurity.hasPassword(player.getUniqueId(), player.getName());
- } else {
- // Check password
- - canChange = PlayerSecurity.checkPlayerPassword(player.getName(), args.getString(0));
- + canChange = PlayerSecurity.checkPlayerPassword(player.getUniqueId(), player.getName(), args.getString(0));
- }
- // Only do rest if the password can be changed.
- @@ -1036,7 +1068,7 @@ public final class PlayerCommands {
- }
- // Update the password.
- - if (PlayerSecurity.setPassword(player.getName(), newpass)) {
- + if (PlayerSecurity.setPassword(player.getUniqueId(), player.getName(), newpass)) {
- player.printInfo("Password was updated!");
- } else {
- player.printError("Could not update password.");
- @@ -1056,9 +1088,9 @@ public final class PlayerCommands {
- }
- // Only do rest if the password can be changed.
- - if (PlayerSecurity.checkPlayerPassword(player.getName(), args.getString("delete"))) {
- + if (PlayerSecurity.checkPlayerPassword(player.getUniqueId(), player.getName(), args.getString("delete"))) {
- // Remove the password
- - if (PlayerSecurity.removePassword(player.getName())) {
- + if (PlayerSecurity.removePassword(player.getUniqueId(), player.getName())) {
- player.printInfo("Password was removed!!");
- } else {
- player.printError("Could not remove password.");
- @@ -1085,7 +1117,7 @@ public final class PlayerCommands {
- return;
- }
- - int votePoints = TransactionHandler.getTransactionObject(player.getName()).getValue(TransactionType.VOTE_POINTS);
- + int votePoints = TransactionHandler.getTransactionObject(player.getUniqueId(), player.getName()).getValue(TransactionType.VOTE_POINTS);
- IdpInventory chest = new IdpInventory("Redeem an Item ("
- + votePoints + " remaining)", 36);
- chest.setCustom("redeemChest");
- diff --git a/src/net/innectis/innplugin/Command/Commands/Polls/AbstractPoll.java b/src/net/innectis/innplugin/Command/Commands/Polls/AbstractPoll.java
- index 93351561b..1ba74d223 100644
- --- a/src/net/innectis/innplugin/Command/Commands/Polls/AbstractPoll.java
- +++ b/src/net/innectis/innplugin/Command/Commands/Polls/AbstractPoll.java
- @@ -1,15 +1,19 @@
- package net.innectis.innplugin.Command.Commands.Polls;
- import java.sql.PreparedStatement;
- +import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.List;
- +import java.util.UUID;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.Items.StackBag;
- import net.innectis.innplugin.Player.IdpPlayer;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Player.PlayerGroup;
- import net.innectis.innplugin.Utility.DatabaseTools;
- import net.innectis.innplugin.Utility.ObjectParseException;
- @@ -143,19 +147,32 @@ abstract class AbstractPoll implements Poll {
- */
- protected final List<PlayerAnswer> loadAnswers() {
- if (pollid > 0) {
- + List<PlayerAnswer> playerAnswers = new ArrayList<PlayerAnswer>();
- +
- PreparedStatement statement = null;
- + ResultSet set = null;
- try {
- - statement = DBManager.prepareStatement(" SELECT username as playername, answer FROM poll_answers WHERE id = ? ");
- + statement = DBManager.prepareStatement(" SELECT player_id, answer FROM poll_answers WHERE id = ? ");
- statement.setInt(1, pollid);
- + set = statement.executeQuery();
- +
- + while (set.next()) {
- + String playerIdString = set.getString("player_id");
- + UUID playerId = UUID.fromString(playerIdString);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(playerId);
- +
- + String answer = set.getString("answer");
- - return DatabaseTools.parseToObjects(PlayerAnswer.class, statement.executeQuery());
- + playerAnswers.add(new PlayerAnswer(credentials, answer));
- + }
- +
- + return playerAnswers;
- } catch (SQLException ex) {
- Logger.getLogger(AbstractPoll.class.getName()).log(Level.SEVERE, null, ex);
- - } catch (ObjectParseException ex) {
- - Logger.getLogger(AbstractPoll.class.getName()).log(Level.SEVERE, null, ex);
- } finally {
- DBManager.closePreparedStatement(statement);
- + DBManager.closeResultSet(set);
- }
- }
- @@ -185,9 +202,9 @@ abstract class AbstractPoll implements Poll {
- PreparedStatement statement = null;
- try {
- - statement = DBManager.prepareStatement(" INSERT INTO poll_answers (id, username, answer) VALUES (?,?,?) ");
- + statement = DBManager.prepareStatement(" INSERT INTO poll_answers (id, player_id, answer) VALUES (?,?,?) ");
- statement.setInt(1, pollid);
- - statement.setString(2, answer.getPlayername());
- + statement.setString(2, answer.getCredentials().getUniqueId().toString());
- statement.setString(3, answer.getAnswer());
- answers.add(answer);
- diff --git a/src/net/innectis/innplugin/Command/Commands/Polls/MultipleChoicePoll.java b/src/net/innectis/innplugin/Command/Commands/Polls/MultipleChoicePoll.java
- index 633e1c587..94ab81785 100644
- --- a/src/net/innectis/innplugin/Command/Commands/Polls/MultipleChoicePoll.java
- +++ b/src/net/innectis/innplugin/Command/Commands/Polls/MultipleChoicePoll.java
- @@ -12,6 +12,8 @@ import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.Player.Chat.ChatColor;
- import net.innectis.innplugin.Player.IdpPlayer;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Player.PlayerGroup;
- import net.innectis.innplugin.Utility.DatabaseTools;
- import net.innectis.innplugin.Utility.ObjectParseException;
- @@ -73,7 +75,8 @@ public class MultipleChoicePoll extends AbstractPoll {
- return true;
- }
- - existingAnswer = new PlayerAnswer(player.getName(), chosenoption.getOptionValue());
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName());
- + existingAnswer = new PlayerAnswer(credentials, chosenoption.getOptionValue());
- addAnswer(existingAnswer);
- player.printInfo("Thank you for voting!");
- } else {
- diff --git a/src/net/innectis/innplugin/Command/Commands/Polls/OpenChoicePoll.java b/src/net/innectis/innplugin/Command/Commands/Polls/OpenChoicePoll.java
- index ad4a3ccd5..8de11db49 100644
- --- a/src/net/innectis/innplugin/Command/Commands/Polls/OpenChoicePoll.java
- +++ b/src/net/innectis/innplugin/Command/Commands/Polls/OpenChoicePoll.java
- @@ -8,6 +8,8 @@ import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.Player.Chat.ChatColor;
- import net.innectis.innplugin.Player.IdpPlayer;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Player.PlayerGroup;
- import net.innectis.innplugin.Utility.StringUtil;
- @@ -49,7 +51,8 @@ public class OpenChoicePoll extends AbstractPoll {
- }
- if (existingAnswer == null) {
- - existingAnswer = new PlayerAnswer(player.getName(), answer);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName());
- + existingAnswer = new PlayerAnswer(credentials, answer);
- addAnswer(existingAnswer);
- player.printInfo("Thank you for voting!");
- } else {
- diff --git a/src/net/innectis/innplugin/Command/Commands/Polls/PlayerAnswer.java b/src/net/innectis/innplugin/Command/Commands/Polls/PlayerAnswer.java
- index dbf9fa83b..2905b8ecc 100644
- --- a/src/net/innectis/innplugin/Command/Commands/Polls/PlayerAnswer.java
- +++ b/src/net/innectis/innplugin/Command/Commands/Polls/PlayerAnswer.java
- @@ -1,36 +1,46 @@
- package net.innectis.innplugin.Command.Commands.Polls;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +
- /**
- *
- * @author Hretsam
- - *
- + *
- * An answer by a player.
- */
- public class PlayerAnswer {
- -
- - private String playername;
- + private PlayerCredentials credentials;
- private String answer;
- public PlayerAnswer() {
- }
- - public PlayerAnswer(String playername, String answer) {
- - this.playername = playername;
- + public PlayerAnswer(PlayerCredentials credentials, String answer) {
- + this.credentials = credentials;
- this.answer = answer;
- }
- + /**
- + * Returns the credentials of the player that has the answer
- + * @return
- + */
- + public PlayerCredentials getCredentials() {
- + return credentials;
- + }
- +
- /**
- * @return the playername
- */
- public String getPlayername() {
- - return playername;
- + return credentials.getName();
- }
- /**
- - * @param playername the playername to set
- + * Sets the new credentials
- + * @param credentials
- */
- - public void setPlayername(String playername) {
- - this.playername = playername;
- + public void setCredentials(PlayerCredentials credentials) {
- + this.credentials = credentials;
- }
- /**
- @@ -46,5 +56,5 @@ public class PlayerAnswer {
- public void setAnswer(String answer) {
- this.answer = answer;
- }
- -
- +
- }
- diff --git a/src/net/innectis/innplugin/Command/Commands/Polls/PollOption.java b/src/net/innectis/innplugin/Command/Commands/Polls/PollOption.java
- index c0d9879ab..5f7fc493a 100644
- --- a/src/net/innectis/innplugin/Command/Commands/Polls/PollOption.java
- +++ b/src/net/innectis/innplugin/Command/Commands/Polls/PollOption.java
- @@ -5,7 +5,6 @@ package net.innectis.innplugin.Command.Commands.Polls;
- * @author Hretsam
- */
- public class PollOption {
- -
- private String value;
- private String answer;
- diff --git a/src/net/innectis/innplugin/Command/Commands/ShopCommands.java b/src/net/innectis/innplugin/Command/Commands/ShopCommands.java
- index 485a764a3..439b0f631 100644
- --- a/src/net/innectis/innplugin/Command/Commands/ShopCommands.java
- +++ b/src/net/innectis/innplugin/Command/Commands/ShopCommands.java
- @@ -1,25 +1,25 @@
- package net.innectis.innplugin.Command.Commands;
- import java.util.Random;
- -import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.Command.CommandMethod;
- import net.innectis.innplugin.Configuration;
- -import net.innectis.innplugin.IdpCommandSender;
- -import org.bukkit.Server;
- import net.innectis.innplugin.Handlers.TransactionHandler;
- import net.innectis.innplugin.Handlers.TransactionHandler.TransactionType;
- +import net.innectis.innplugin.IdpCommandSender;
- +import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.InnectisObjects.TransactionObject;
- import net.innectis.innplugin.Loggers.LogManager;
- import net.innectis.innplugin.Loggers.SendMoneyLogger;
- import net.innectis.innplugin.Player.Chat.ChatColor;
- import net.innectis.innplugin.Player.IdpPlayer;
- import net.innectis.innplugin.Player.Permission;
- -import net.innectis.innplugin.Player.PlayerGroup;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Player.PlayerSession;
- import net.innectis.innplugin.Tasking.SyncTasks.ValutaBankTransactionTask;
- import net.innectis.innplugin.Tasking.TaskManager;
- import net.innectis.innplugin.Utility.LynxyArguments;
- -import net.innectis.innplugin.Utility.NumberUtil;
- +import org.bukkit.Server;
- import org.bukkit.command.CommandSender;
- public final class ShopCommands {
- @@ -31,17 +31,20 @@ public final class ShopCommands {
- public static boolean commandModifyBalance(InnPlugin parent, IdpCommandSender<? extends CommandSender> sender, String[] args) {
- if (args.length > 2) {
- String playerName = args[0];
- - IdpPlayer testPlayer = parent.getPlayer(playerName);
- + IdpPlayer target = parent.getPlayer(playerName);
- - if (testPlayer != null) {
- - playerName = testPlayer.getName();
- + if (target != null) {
- + playerName = target.getName();
- }
- - PlayerGroup group = PlayerGroup.getGroupOfUsername(playerName);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- - if (group == PlayerGroup.NONE) {
- - sender.printError("That user does not exist.");
- + if (credentials == null) {
- + sender.printError("That player does not exist.");
- return true;
- + } else {
- + // Get the proper casing of the name
- + playerName = credentials.getName();
- }
- int action = 0; // 1 = add, 2 = subtract, 3 = set
- @@ -86,18 +89,18 @@ public final class ShopCommands {
- }
- }
- - TransactionObject to = TransactionHandler.getTransactionObject(playerName);
- + TransactionObject transaction = TransactionHandler.getTransactionObject(credentials.getUniqueId(), credentials.getName());
- String amtTypeName = (amount == 1 ? type.getName().toLowerCase().substring(0, type.getName().length() - 1) : type.getName().toLowerCase());
- if (action == 1) {
- - to.addValue(amount, type);
- + transaction.addValue(amount, type);
- sender.printInfo("Deposited " + amount + " " + amtTypeName + " to " + playerName + "!");
- - if (testPlayer != null && testPlayer.isOnline()) {
- - testPlayer.printInfo(amount + " " + amtTypeName + " was deposited to you!");
- + if (target != null && target.isOnline()) {
- + target.printInfo(amount + " " + amtTypeName + " was deposited to you!");
- }
- } else if (action == 2) {
- - int balance = to.getValue(type);
- + int balance = transaction.getValue(type);
- String balTypeName = (balance == 1 ? type.getName().toLowerCase().substring(0, type.getName().length() - 1) : type.getName().toLowerCase());
- if (balance < amount) {
- @@ -105,18 +108,18 @@ public final class ShopCommands {
- return true;
- }
- - to.subtractValue(amount, type);
- + transaction.subtractValue(amount, type);
- sender.printInfo("Withdrew " + amount + " " + amtTypeName + " from " + playerName + "!");
- - if (testPlayer != null && testPlayer.isOnline()) {
- - testPlayer.printInfo(amount + " " + amtTypeName + " was withdrawn from you!");
- + if (target != null && target.isOnline()) {
- + target.printInfo(amount + " " + amtTypeName + " was withdrawn from you!");
- }
- } else if (action == 3) {
- - to.setValue(amount, type);
- + transaction.setValue(amount, type);
- sender.printInfo("Set " + playerName + "'s " + type.getName().toLowerCase() + " to " + amount + "!");
- - if (testPlayer != null && testPlayer.isOnline()) {
- - testPlayer.printInfo("Your " + type.getName().toLowerCase() + " was set to " + amount + "!");
- + if (target != null && target.isOnline()) {
- + target.printInfo("Your " + type.getName().toLowerCase() + " was set to " + amount + "!");
- }
- }
- @@ -131,53 +134,60 @@ public final class ShopCommands {
- permission = Permission.command_shop_sendmoney,
- usage = "/sendmoney <player> <amount>",
- serverCommand = false)
- - public static boolean commandSendMoney(Server server, InnPlugin parent, IdpCommandSender<? extends CommandSender> sender, String args[]) {
- + public static boolean commandSendMoney(Server server, InnPlugin parent, IdpPlayer player, String args[]) {
- if (args.length > 1) {
- + String playerName = args[0];
- + IdpPlayer target = parent.getPlayer(playerName);
- +
- + if (target != null) {
- + playerName = target.getName();
- + }
- +
- + PlayerCredentials receiverCredentials = PlayerCredentialsManager.getByName(playerName);
- +
- + if (receiverCredentials == null) {
- + player.printError("That player does not exist.");
- + return true;
- + } else {
- + // Get the proper casing of the name
- + playerName = receiverCredentials.getName();
- + }
- +
- int amount = 0;
- try {
- amount = Integer.parseInt(args[1]);
- if (amount < 1) {
- - sender.printError("Amount cannot be less than 1.");
- + player.printError("Amount cannot be less than 1.");
- return true;
- }
- } catch (NumberFormatException ex) {
- - sender.printError("Amount is not a number.");
- - return true;
- - }
- -
- - IdpPlayer player = parent.getPlayer(args[0], false, true);
- - String receivePlayer = (player != null ? player.getName() : args[0]);
- -
- - PlayerGroup group = PlayerGroup.getGroupOfUsername(receivePlayer);
- -
- - if (group == PlayerGroup.NONE) {
- - sender.printError("That user does not exist.");
- + player.printError("Amount is not a number.");
- return true;
- }
- - TransactionObject transactionSender = TransactionHandler.getTransactionObject(sender.getName());
- + TransactionObject transactionSender = TransactionHandler.getTransactionObject(player.getUniqueId(), player.getName());
- int balance = transactionSender.getValue(TransactionType.VALUTAS);
- if (amount > balance) {
- - sender.printError("You cannot send more valutas than you have.");
- + player.printError("You cannot send more valutas than you have.");
- return true;
- }
- transactionSender.subtractValue(amount, TransactionType.VALUTAS);
- - TransactionObject transactionReceiver = TransactionHandler.getTransactionObject(receivePlayer);
- + TransactionObject transactionReceiver = TransactionHandler.getTransactionObject(receiverCredentials.getUniqueId(), receiverCredentials.getName());
- transactionReceiver.addValue(amount, TransactionType.VALUTAS);
- - sender.printInfo("You sent " + amount + " valuta" + (amount != 1 ? "s" : "") + " to " + receivePlayer + "!");
- + player.printInfo("You sent " + amount + " valuta" + (amount != 1 ? "s" : "") + " to " + playerName + "!");
- if (player != null && player.isOnline()) {
- - player.printInfo(sender.getName() + " sent you " + amount + " valuta" + (amount != 1 ? "s" : "") + ".");
- + player.printInfo(player.getName() + " sent you " + amount + " valuta" + (amount != 1 ? "s" : "") + ".");
- }
- SendMoneyLogger sml = LogManager.getSendMoneyLogger();
- - sml.log(sender.getName(), receivePlayer, amount);
- + sml.log(player.getName(), playerName, amount);
- return true;
- }
- @@ -192,7 +202,7 @@ public final class ShopCommands {
- serverCommand = false)
- public static boolean commandBank(InnPlugin parent, IdpPlayer player, LynxyArguments args) {
- if (args.hasArgument("deposit", "d", "withdraw", "w")) {
- - TransactionObject transaction = TransactionHandler.getTransactionObject(player.getName());
- + TransactionObject transaction = TransactionHandler.getTransactionObject(player.getUniqueId(), player.getName());
- boolean isDeposit = args.hasArgument("deposit", "d");
- int amount = 0;
- @@ -265,7 +275,7 @@ public final class ShopCommands {
- bankTaskTime = (baseTime + extendedTime);
- }
- - ValutaBankTransactionTask vbtt = new ValutaBankTransactionTask(player.getName(), bankTaskTime);
- + ValutaBankTransactionTask vbtt = new ValutaBankTransactionTask(player.getUniqueId(), player.getName(), bankTaskTime);
- long taskId = parent.getTaskManager().addTask(vbtt);
- session.setBankTaskId(taskId);
- @@ -283,36 +293,43 @@ public final class ShopCommands {
- usage = "/balance [player]",
- serverCommand = true)
- public static boolean commandBalance(Server server, InnPlugin parent, IdpCommandSender sender, String[] args) {
- - String lookupPlayer = sender.getName();
- + String playerName = sender.getName();
- if (args.length > 0) {
- - IdpPlayer playerCheck = parent.getPlayer(args[0], false, true);
- - lookupPlayer = (playerCheck != null ? playerCheck.getName() : args[0]);
- + playerName = args[0];
- + IdpPlayer target = parent.getPlayer(playerName);
- - PlayerGroup group = PlayerGroup.getGroupOfUsername(lookupPlayer);
- -
- - if (group == PlayerGroup.NONE) {
- - sender.printError("That player doesn't exist.");
- - return true;
- + if (target != null) {
- + playerName = target.getName();
- }
- - if (!lookupPlayer.equalsIgnoreCase(sender.getName().toLowerCase())
- + if (!playerName.equalsIgnoreCase(sender.getName().toLowerCase())
- && sender.isPlayer() && !((IdpPlayer) sender).hasPermission(Permission.command_shop_getallbalances)) {
- sender.printError("You are unable to view the balance of other players.");
- return true;
- }
- }
- - if (!sender.isPlayer() && lookupPlayer.equals(sender.getName())) {
- + if (!sender.isPlayer() && playerName.equals(sender.getName())) {
- sender.printError("Console can't lookup itself!");
- return true;
- }
- - TransactionObject transaction = TransactionHandler.getTransactionObject(lookupPlayer);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- +
- + if (credentials == null) {
- + sender.printError("That player does not exist.");
- + return true;
- + } else {
- + // Get the proper casing of the name
- + playerName = credentials.getName();
- + }
- +
- + TransactionObject transaction = TransactionHandler.getTransactionObject(credentials.getUniqueId(), credentials.getName());
- int balance = transaction.getValue(TransactionType.VALUTAS);
- - String responseText = lookupPlayer + "'s balance is: " + balance + " valuta" + (balance != 1 ? "s" : "");
- + String responseText = playerName + "'s balance is: " + balance + " valuta" + (balance != 1 ? "s" : "");
- - if (lookupPlayer.equalsIgnoreCase(sender.getName())
- + if (playerName.equalsIgnoreCase(sender.getName())
- || !sender.isPlayer() || ((IdpPlayer) sender).hasPermission(Permission.command_shop_getallbalances)) {
- int bank = transaction.getValue(TransactionType.VALUTAS_IN_BANK);
- responseText += " (Bank: " + bank + " valuta" + (bank != 1 ? "s" : "") + ")";
- diff --git a/src/net/innectis/innplugin/Command/Commands/SpoofCommands.java b/src/net/innectis/innplugin/Command/Commands/SpoofCommands.java
- index 1eb1d360d..3c3bc4a9b 100644
- --- a/src/net/innectis/innplugin/Command/Commands/SpoofCommands.java
- +++ b/src/net/innectis/innplugin/Command/Commands/SpoofCommands.java
- @@ -7,6 +7,8 @@ import net.innectis.innplugin.InnectisObjects.SpoofObject;
- import net.innectis.innplugin.Player.Chat.ChatColor;
- import net.innectis.innplugin.Player.IdpPlayer;
- import net.innectis.innplugin.Player.Permission;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Player.PlayerGroup;
- import net.innectis.innplugin.Utility.LynxyArguments;
- import net.innectis.innplugin.Utility.SmartArguments;
- @@ -23,16 +25,24 @@ public final class SpoofCommands {
- serverCommand = true,
- hiddenCommand = true)
- public static boolean commandLogin(InnPlugin parent, IdpCommandSender sender, String[] args) {
- - if (args.length > 0) {
- - PlayerGroup group = PlayerGroup.getGroupOfUsername(args[0]);
- - net.innectis.innplugin.Player.Chat.ChatColor color = group.getPrefix().getTextColor();
- + if (args.length == 0) {
- + return false;
- + }
- - 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.");
- - return true;
- + // Default to guest color
- + net.innectis.innplugin.Player.Chat.ChatColor color = net.innectis.innplugin.Player.Chat.ChatColor.YELLOW;
- + String playerName = args[0];
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- +
- + // Modify group color by this player's group
- + if (credentials != null) {
- + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(credentials.getUniqueId());
- + color = group.getPrefix().getTextColor();
- }
- - return false;
- + parent.broadCastMessage(color + playerName + " joined the server.");
- + return true;
- }
- @CommandMethod(aliases = {"slogout"},
- @@ -42,15 +52,24 @@ public final class SpoofCommands {
- serverCommand = true,
- hiddenCommand = true)
- public static boolean commandLogout(InnPlugin parent, IdpCommandSender sender, String[] args) {
- - if (args.length > 0) {
- - PlayerGroup group = PlayerGroup.getGroupOfUsername(args[0]);
- - net.innectis.innplugin.Player.Chat.ChatColor color = group.getPrefix().getTextColor();
- + if (args.length < 1) {
- + return false;
- + }
- - 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.");
- - return true;
- + net.innectis.innplugin.Player.Chat.ChatColor color = net.innectis.innplugin.Player.Chat.ChatColor.YELLOW;
- +
- + String playerName = args[0];
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- +
- + // Modify group color by this player's group
- + if (credentials != null) {
- + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(credentials.getUniqueId());
- + color = group.getPrefix().getTextColor();
- }
- - return false;
- +
- + parent.broadCastMessage(color + playerName + " left the server.");
- + return true;
- }
- @CommandMethod(aliases = {"sresetnames"},
- @@ -115,9 +134,12 @@ public final class SpoofCommands {
- if (target != null) {
- name = target.getName();
- }
- - group = PlayerGroup.getGroupOfUsername(name);
- - if (group == PlayerGroup.NONE) {
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(name);
- +
- + if (credentials != null) {
- + group = PlayerGroup.getGroupOfPlayerById(credentials.getUniqueId());
- + } else {
- group = PlayerGroup.GUEST;
- }
- @@ -141,9 +163,11 @@ public final class SpoofCommands {
- return true;
- }
- - group = PlayerGroup.getGroupOfUsername(name);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(name);
- - if (group == PlayerGroup.NONE) {
- + if (credentials != null) {
- + group = PlayerGroup.getGroupOfPlayerById(credentials.getUniqueId());
- + } else {
- group = PlayerGroup.GUEST;
- }
- diff --git a/src/net/innectis/innplugin/Configuration.java b/src/net/innectis/innplugin/Configuration.java
- index 4cfbe8e5f..6408e882a 100644
- --- a/src/net/innectis/innplugin/Configuration.java
- +++ b/src/net/innectis/innplugin/Configuration.java
- @@ -3,9 +3,11 @@ package net.innectis.innplugin;
- import java.io.FileNotFoundException;
- import java.util.HashSet;
- import java.util.List;
- +import java.util.UUID;
- import net.innectis.innplugin.Handlers.Datasource.FileHandler;
- import net.innectis.innplugin.Player.Chat.ChatColor;
- import net.innectis.innplugin.Player.Infractions.InfractionIntensity;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- /**
- * @author Hretsam
- @@ -32,7 +34,7 @@ public final class Configuration {
- /** Mysql username */
- public static final String MYSQL_USERNAME = "craft";
- /** Database version this plugin uses (live: 158) */
- - public static final int DATABASE_VERSION = 159;
- + public static final int DATABASE_VERSION = 160;
- /** Tells the plugin if the server is live or test */
- public static boolean PRODUCTION_SERVER = false;
- /** Indicates if the server is in maintenance mode **/
- @@ -199,6 +201,23 @@ public final class Configuration {
- // </editor-fold>
- //
- + //<editor-fold defaultstate="collapsed" desc="Fake Player IDs">
- + // These represent UUIDs of special names that do not represent actual players
- + public static final UUID EVERYONE_IDENTIFIER = UUID.nameUUIDFromBytes("%".getBytes());
- + public static final UUID LOT_ASSIGNABLE_IDENTIFIER = UUID.nameUUIDFromBytes("#".getBytes());
- + public static final UUID LOT_ACCESS_IDENTIFIER = UUID.nameUUIDFromBytes("@".getBytes());
- + public static final UUID SERVER_GENERATED_IDENTIFIER = UUID.nameUUIDFromBytes("[SERVER]".getBytes());
- + public static final UUID OTHER_IDENTIFIER = UUID.nameUUIDFromBytes("~".getBytes());
- +
- + // These represent credentials of special names that do not represent actual players
- + public static final PlayerCredentials EVERYONE_CREDENTIALS = new PlayerCredentials(EVERYONE_IDENTIFIER, "%", false);
- + public static final PlayerCredentials LOT_ASSIGNABLE_CREDENTIALS = new PlayerCredentials(LOT_ASSIGNABLE_IDENTIFIER, "#", false);
- + public static final PlayerCredentials LOT_ACCESS_CREDENTIALS = new PlayerCredentials(LOT_ACCESS_IDENTIFIER, "@", false);
- + public static final PlayerCredentials SERVER_GENERATED_CREDENTIALS = new PlayerCredentials(SERVER_GENERATED_IDENTIFIER, "[SERVER]", false);
- + public static final PlayerCredentials OTHER_CREDENTIALS = new PlayerCredentials(OTHER_IDENTIFIER, "~", false);
- +
- + //</editor-fold>
- +
- private Configuration() {
- }
- }
- diff --git a/src/net/innectis/innplugin/Economy/DroppedValutaOrbStore.java b/src/net/innectis/innplugin/Economy/DroppedValutaOrbStore.java
- index 9fa4e2a79..1d342dc95 100644
- --- a/src/net/innectis/innplugin/Economy/DroppedValutaOrbStore.java
- +++ b/src/net/innectis/innplugin/Economy/DroppedValutaOrbStore.java
- @@ -17,7 +17,6 @@ public class DroppedValutaOrbStore {
- /**
- * Adds a new dropped valuta orb class associated by its ID
- - * @param uniqueId
- * @param vorb
- */
- public static void addDroppedValutaOrb(DroppedValutaOrb vorb) {
- diff --git a/src/net/innectis/innplugin/External/API/VotifierIDP.java b/src/net/innectis/innplugin/External/API/VotifierIDP.java
- index d27b8c1e3..8ff14ff14 100644
- --- a/src/net/innectis/innplugin/External/API/VotifierIDP.java
- +++ b/src/net/innectis/innplugin/External/API/VotifierIDP.java
- @@ -9,6 +9,7 @@ import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Timestamp;
- import java.util.List;
- +import java.util.UUID;
- import net.innectis.innplugin.Configuration;
- import net.innectis.innplugin.External.API.Interfaces.IVotifierIDP;
- import net.innectis.innplugin.External.LibraryInitalizationError;
- @@ -18,6 +19,8 @@ import net.innectis.innplugin.Handlers.TransactionHandler;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.Player.Chat.ChatColor;
- import net.innectis.innplugin.Player.IdpPlayer;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Player.PlayerGroup;
- import org.bukkit.plugin.Plugin;
- @@ -65,6 +68,13 @@ public class VotifierIDP implements VoteListener, IVotifierIDP {
- return;
- }
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(name);
- +
- + // Don't allow non-existant players to vote
- + if (credentials == null) {
- + return;
- + }
- +
- // Check if service is valid
- if (!isValidService(vote)) {
- InnPlugin.logError("Unauthorized vote server \"" + vote.getServiceName() + "\" tried to send a vote!");
- @@ -75,8 +85,8 @@ public class VotifierIDP implements VoteListener, IVotifierIDP {
- ResultSet result = null;
- try {
- - statement = DBManager.prepareStatement("SELECT timestamp FROM vote_log WHERE username = ? AND service = ?");
- - statement.setString(1, name);
- + statement = DBManager.prepareStatement("SELECT timestamp FROM vote_log WHERE player_id = ? AND service = ?");
- + statement.setString(1, credentials.getUniqueId().toString());
- statement.setString(2, vote.getServiceName());
- result = statement.executeQuery();
- @@ -98,10 +108,10 @@ public class VotifierIDP implements VoteListener, IVotifierIDP {
- return;
- } else {
- - addPlayerVote(vote, true);
- + addPlayerVote(credentials.getUniqueId(), vote, true);
- }
- } else {
- - addPlayerVote(vote, false);
- + addPlayerVote(credentials.getUniqueId(), vote, false);
- }
- } catch (SQLException ex) {
- InnPlugin.logError("SQLException VotifierListener::voteMade(1) - ", ex.getMessage());
- @@ -117,7 +127,7 @@ public class VotifierIDP implements VoteListener, IVotifierIDP {
- }
- InnPlugin.logInfo("Vote received from \"" + vote.getServiceName() + "\" by voter " + name + "(" + vote.getAddress() + ")");
- - TransactionHandler.getTransactionObject(name).addValue(1, TransactionHandler.TransactionType.VOTE_POINTS);
- + TransactionHandler.getTransactionObject(credentials.getUniqueId(), credentials.getName()).addValue(1, TransactionHandler.TransactionType.VOTE_POINTS);
- if (player != null && player.isOnline()) {
- player.printInfo("You have been credited 1 vote point!");
- @@ -128,7 +138,7 @@ public class VotifierIDP implements VoteListener, IVotifierIDP {
- if (player != null) {
- nameColor = player.getGroup().getPrefix().getTextColor().toString();
- } else {
- - nameColor = PlayerGroup.getGroupOfUsername(name).getPrefix().getTextColor().toString();
- + nameColor = PlayerGroup.getGroupOfPlayerById(credentials.getUniqueId()).getPrefix().getTextColor().toString();
- }
- String service = vote.getServiceName();
- @@ -143,19 +153,19 @@ public class VotifierIDP implements VoteListener, IVotifierIDP {
- plugin.broadCastMessage(ChatColor.GREEN, "Thank you for your support!");
- }
- - private static void addPlayerVote(Vote vote, boolean update) {
- + private static void addPlayerVote(UUID playerId, Vote vote, boolean update) {
- PreparedStatement statement = null;
- try {
- if (update) {
- - statement = DBManager.prepareStatement("UPDATE vote_log SET timestamp = ? WHERE username = ? AND service = ?");
- + statement = DBManager.prepareStatement("UPDATE vote_log SET timestamp = ? WHERE player_id = ? AND service = ?");
- statement.setTimestamp(1, new Timestamp(System.currentTimeMillis()));
- - statement.setString(2, vote.getUsername().trim());
- + statement.setString(2, playerId.toString());
- statement.setString(3, vote.getServiceName());
- statement.executeUpdate();
- } else {
- - statement = DBManager.prepareStatement("INSERT INTO vote_log (username, ip, service, timestamp) VALUES (?, ?, ?, ?)");
- - statement.setString(1, vote.getUsername().trim());
- + statement = DBManager.prepareStatement("INSERT INTO vote_log (player_id, ip, service, timestamp) VALUES (?, ?, ?, ?)");
- + statement.setString(1, playerId.toString());
- statement.setString(2, vote.getAddress());
- statement.setString(3, vote.getServiceName());
- statement.setTimestamp(4, new Timestamp(System.currentTimeMillis()));
- diff --git a/src/net/innectis/innplugin/External/DynmapIDP.java b/src/net/innectis/innplugin/External/DynmapIDP.java
- index 2d327ccf6..9683b6bc3 100644
- --- a/src/net/innectis/innplugin/External/DynmapIDP.java
- +++ b/src/net/innectis/innplugin/External/DynmapIDP.java
- @@ -55,7 +55,7 @@ public class DynmapIDP {
- set.setLayerPriority(15);
- set.setHideByDefault(false);
- -
- +
- // Add the task
- plugin.getTaskManager().addTask(new DynmapUpdateTask(this));
- return true;
- @@ -99,7 +99,7 @@ public class DynmapIDP {
- z[2] = lot.getHighestZ();
- z[3] = lot.getLowestZ() + 1;
- - String ownercolor = PlayerGroup.getGroupOfUsername(lot.getOwner()).getPrefix().getTextColor().getHTMLColor();
- + String ownercolor = PlayerGroup.getGroupOfPlayerById(lot.getOwnerCredentials().getUniqueId()).getPrefix().getTextColor().getHTMLColor();
- String desc = formatInfoWindow(lot, ownercolor);
- String markerid = "lot_" + lot.getId();
- AreaMarker m = resareas.remove(markerid); /* Existing area? */
- diff --git a/src/net/innectis/innplugin/GameSystem/Gamemodes/IdpCTF.java b/src/net/innectis/innplugin/GameSystem/Gamemodes/IdpCTF.java
- index accb5b416..ec409cd09 100644
- --- a/src/net/innectis/innplugin/GameSystem/Gamemodes/IdpCTF.java
- +++ b/src/net/innectis/innplugin/GameSystem/Gamemodes/IdpCTF.java
- @@ -159,7 +159,7 @@ public class IdpCTF extends IdpRegionGame implements GameTimer {
- gamelot = ((InnectisLot) getRegion()).getParentTop();
- - if (!(gamelot.canPlayerAccess(host) || host.hasPermission(Permission.lot_command_override))) {
- + if (!(gamelot.canPlayerAccess(host.getName()) || host.hasPermission(Permission.lot_command_override))) {
- return new IdpStartResult(false, "You do not have permission to start a game here.");
- }
- diff --git a/src/net/innectis/innplugin/Handlers/BlockHandler.java b/src/net/innectis/innplugin/Handlers/BlockHandler.java
- index 548d9babb..7b9a74e00 100644
- --- a/src/net/innectis/innplugin/Handlers/BlockHandler.java
- +++ b/src/net/innectis/innplugin/Handlers/BlockHandler.java
- @@ -3,11 +3,13 @@ package net.innectis.innplugin.Handlers;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- +import java.sql.Timestamp;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.Random;
- +import java.util.UUID;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.InnectisObjects.POJO.BlockLog;
- @@ -25,12 +27,16 @@ import net.innectis.innplugin.OwnedObjects.InnectisLot;
- import net.innectis.innplugin.OwnedObjects.LotFlagType;
- import net.innectis.innplugin.Player.IdpPlayer;
- import net.innectis.innplugin.Player.Permission;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Utility.DatabaseTools;
- import net.innectis.innplugin.Utility.LocationUtil;
- import net.innectis.innplugin.Utility.ObjectParseException;
- +import org.bukkit.Bukkit;
- import org.bukkit.Color;
- import org.bukkit.FireworkEffect;
- import org.bukkit.Location;
- +import org.bukkit.World;
- import org.bukkit.block.Block;
- import org.bukkit.block.BlockFace;
- import org.bukkit.block.BlockState;
- @@ -181,7 +187,7 @@ public final class BlockHandler {
- }
- } else {
- // Check if owner, freebuild or member of lot
- - if (lot.canPlayerAccess(player)) {
- + if (lot.canPlayerAccess(player.getName())) {
- return true; //freebuild
- }
- @@ -273,8 +279,8 @@ public final class BlockHandler {
- PreparedStatement statement = null;
- try {
- - statement = DBManager.prepareStatement("INSERT DELAYED INTO block_quota_log (time,username,blockid) VALUES (NOW(),?,?);");
- - statement.setString(1, player.getName());
- + statement = DBManager.prepareStatement("INSERT DELAYED INTO block_quota_log (time, player_id, blockid) VALUES (NOW(),?,?);");
- + statement.setString(1, player.getUniqueId().toString());
- statement.setInt(2, getBlockTypeId(block));
- statement.executeUpdate();
- } catch (SQLException ex) {
- @@ -302,9 +308,9 @@ public final class BlockHandler {
- ResultSet result = null;
- try {
- - statement = DBManager.prepareStatement("SELECT COUNT(*) FROM block_quota_log WHERE time >= DATE_SUB(NOW(), INTERVAL ? SECOND) AND username = ? AND blockid = ?;");
- + statement = DBManager.prepareStatement("SELECT COUNT(*) FROM block_quota_log WHERE time >= DATE_SUB(NOW(), INTERVAL ? SECOND) AND player_id = ? AND blockid = ?;");
- statement.setInt(1, timespan);
- - statement.setString(2, player.getName());
- + statement.setString(2, player.getUniqueId().toString());
- statement.setInt(3, getBlockTypeId(block));
- result = statement.executeQuery();
- @@ -804,7 +810,7 @@ public final class BlockHandler {
- try {
- statement = DBManager.prepareStatement(
- - "SELECT logid, name, locx, locy, locz, world, Id as id, Data as data, DateTime as datetime, ActionType as actiontype "
- + "SELECT logid, player_id, locx, locy, locz, world, Id as id, Data as data, DateTime as datetime, ActionType as actiontype "
- + "FROM block_log "
- + "WHERE locx = ? AND locy = ? AND locz = ? and world = ? "
- + "ORDER BY datetime DESC "
- @@ -816,12 +822,35 @@ public final class BlockHandler {
- statement.setInt(5, (amount.length == 0 ? 10 : amount[0]));
- set = statement.executeQuery();
- - // Return the parsed list
- - return DatabaseTools.parseToObjects(BlockLog.class, set);
- + List<BlockLog> blockLogs = new ArrayList<BlockLog>();
- +
- + while (set.next()) {
- + World world = Bukkit.getWorld(set.getString("world"));
- +
- + if (world != null) {
- + int x = set.getInt("locx");
- + int y = set.getInt("locy");
- + int z = set.getInt("locz");
- +
- + int logid = set.getInt("logid");
- +
- + String playerIdString = set.getString("player_id");
- + UUID playerId = UUID.fromString(playerIdString);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(playerId);
- +
- + int id = set.getInt("id");
- + int data = set.getInt("data");
- +
- + Timestamp dateTime = set.getTimestamp("datetime");
- + int action = set.getInt("actiontype");
- +
- + blockLogs.add(new BlockLog(credentials.getName(), x, y, z, world.getName(), id, data, dateTime, action));
- + }
- + }
- +
- + return blockLogs;
- } catch (SQLException ex) {
- InnPlugin.logError("SQLException when getting chestaccess logs!", ex);
- - } catch (ObjectParseException ex) {
- - InnPlugin.logError("ObjectParseException parsing chestlogs into objects", ex.getInnerException());
- } finally {
- DBManager.closeResultSet(set);
- DBManager.closePreparedStatement(statement);
- diff --git a/src/net/innectis/innplugin/Handlers/BlockLockHandler.java b/src/net/innectis/innplugin/Handlers/BlockLockHandler.java
- index 21fbd0b7e..810ac3c54 100644
- --- a/src/net/innectis/innplugin/Handlers/BlockLockHandler.java
- +++ b/src/net/innectis/innplugin/Handlers/BlockLockHandler.java
- @@ -4,10 +4,12 @@ import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.HashMap;
- +import java.util.UUID;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.Player.Chat.ChatColor;
- -import net.innectis.innplugin.Player.IdpPlayer;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.World;
- @@ -19,9 +21,9 @@ import org.bukkit.World;
- */
- public final class BlockLockHandler {
- - private static HashMap<String, String> _lockedBlocks = new HashMap<String, String>();
- + private static HashMap<String, UUID> _lockedBlocks = new HashMap<String, UUID>();
- - public static synchronized HashMap<String, String> getLockedBlocks() {
- + public static synchronized HashMap<String, UUID> getLockedBlocks() {
- return _lockedBlocks;
- }
- @@ -36,7 +38,7 @@ public final class BlockLockHandler {
- ResultSet result = null;
- try {
- - statement = DBManager.prepareStatement("SELECT username, world, locx, locy, locz FROM block_locks;");
- + statement = DBManager.prepareStatement("SELECT player_id, world, locx, locy, locz FROM block_locks;");
- result = statement.executeQuery();
- getLockedBlocks().clear();
- @@ -44,10 +46,13 @@ public final class BlockLockHandler {
- World world = Bukkit.getWorld(result.getString("world"));
- if (world != null) {
- + String playerIdString = result.getString("player_id");
- + UUID playerId = UUID.fromString(playerIdString);
- +
- getLockedBlocks().put(world.getName() + " "
- + result.getInt("locx") + " "
- + result.getInt("locy") + " "
- - + result.getInt("locz"), result.getString("username"));
- + + result.getInt("locz"), playerId);
- }
- }
- } catch (SQLException ex) {
- @@ -76,36 +81,36 @@ public final class BlockLockHandler {
- public static String getBlockLockerName(Location location) {
- String key = getKey(location);
- if (getLockedBlocks().containsKey(key)) {
- - return getLockedBlocks().get(key);
- + UUID playerId = getLockedBlocks().get(key);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(playerId);
- + return credentials.getName();
- }
- +
- return null;
- }
- /**
- * Locks the given block.
- - * @param player
- + * @param playerId
- * @param location - the location of the block
- * @return true if succeed
- - * @throws SQLException
- */
- - public static boolean lockBlock(IdpPlayer player, Location location) {
- - String playerName = player.getName();
- + public static boolean lockBlock(UUID playerId, Location location) {
- PreparedStatement statement = null;
- + String key = getKey(location);
- try {
- - String key = getKey(location);
- -
- - statement = DBManager.prepareStatement("INSERT INTO block_locks (username, world, locx, locy, locz) VALUES (?, ?, ?, ?, ?);");
- - statement.setString(1, playerName.toLowerCase());
- + statement = DBManager.prepareStatement("INSERT INTO block_locks (player_id, world, locx, locy, locz) VALUES (?, ?, ?, ?, ?);");
- + statement.setString(1, playerId.toString());
- statement.setString(2, location.getWorld().getName());
- statement.setInt(3, location.getBlockX());
- statement.setInt(4, location.getBlockY());
- statement.setInt(5, location.getBlockZ());
- statement.executeUpdate();
- - getLockedBlocks().put(key, playerName.toLowerCase());
- + getLockedBlocks().put(key, playerId);
- } catch (SQLException ex) {
- - InnPlugin.logError("Could not lock block!", ex);
- + InnPlugin.logError("Could not lock block! (location: " + key + ")", ex);
- return false;
- } finally {
- DBManager.closePreparedStatement(statement);
- diff --git a/src/net/innectis/innplugin/Handlers/CTFHandler.java b/src/net/innectis/innplugin/Handlers/CTFHandler.java
- index ce9846e16..2ad03cd48 100644
- --- a/src/net/innectis/innplugin/Handlers/CTFHandler.java
- +++ b/src/net/innectis/innplugin/Handlers/CTFHandler.java
- @@ -11,6 +11,8 @@ import net.innectis.innplugin.Location.IdpWorldRegion;
- import net.innectis.innplugin.OwnedObjects.Handlers.LotHandler;
- import net.innectis.innplugin.OwnedObjects.InnectisLot;
- import net.innectis.innplugin.Player.IdpPlayer;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Player.TinyWE.BlockCounters.BlockCounter;
- import net.innectis.innplugin.Player.TinyWE.BlockCounters.BlockCounterFactory;
- import org.bukkit.Location;
- @@ -205,7 +207,8 @@ public final class CTFHandler {
- region.setPos2(region.getPos2().setY(255));
- try {
- - InnectisLot lot = LotHandler.addLot(player.getLocation().getWorld(), region.getPos1(), region.getPos2(), player.getName(), player.getName());
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName(), true);
- + InnectisLot lot = LotHandler.addLot(player.getLocation().getWorld(), region.getPos1(), region.getPos2(), credentials, credentials);
- lot.setLotName(baseName);
- lot.save();
- } catch (SQLException ex) {
- @@ -240,7 +243,8 @@ public final class CTFHandler {
- String flagPositionName = (isRedFlag ? "RedFlag" : "BlueFlag");
- try {
- - InnectisLot lot = LotHandler.addLot(player.getLocation().getWorld(), vector, vector, player.getName(), player.getName());
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName(), true);
- + InnectisLot lot = LotHandler.addLot(player.getLocation().getWorld(), vector, vector, credentials, credentials);
- lot.setLotName(flagPositionName);
- lot.save();
- } catch (SQLException ex) {
- diff --git a/src/net/innectis/innplugin/Handlers/Iplogging/Playerinfo.java b/src/net/innectis/innplugin/Handlers/Iplogging/Playerinfo.java
- index d876a6c75..ac985560b 100644
- --- a/src/net/innectis/innplugin/Handlers/Iplogging/Playerinfo.java
- +++ b/src/net/innectis/innplugin/Handlers/Iplogging/Playerinfo.java
- @@ -8,6 +8,7 @@ import java.util.Collections;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Set;
- +import java.util.UUID;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- @@ -19,30 +20,31 @@ import org.apache.commons.lang.NotImplementedException;
- * @author Hretsam
- *
- * This class contains some information about the player and its IP address.
- - * Also the accounts that are linked to this one (used same IP) can be found here.x
- + * Also the accounts that are linked to this one (used same IP) can be found here.
- */
- public final class Playerinfo {
- -
- - private final String username;
- - private HashSet<IPAddress> ipadresses;
- + private final UUID playerId;
- + private final String playerName;
- + private HashSet<IPAddress> ipadresses = new HashSet<IPAddress>();
- // <editor-fold defaultstate="collapsed" desc="Contructors">
- - private Playerinfo(String username) {
- - this.username = username;
- + private Playerinfo(UUID playerId, String playerName) {
- + this(playerId, playerName, null);
- }
- - private Playerinfo(String username, HashSet<IPAddress> ipadresses) {
- - this.username = username;
- + private Playerinfo(UUID playerId, String playerName, HashSet<IPAddress> ipadresses) {
- + this.playerId = playerId;
- + this.playerName = playerName;
- this.ipadresses = ipadresses;
- }
- // </editor-fold>
- /**
- - * Returns the name of the user of this object.
- + * Returns the ID of this player
- * @return
- */
- - public String getUsername() {
- - return username;
- + public UUID getUniqueId() {
- + return playerId;
- }
- /**
- @@ -97,15 +99,15 @@ public final class Playerinfo {
- ResultSet result = null;
- try {
- - statement = DBManager.prepareStatement("SELECT DISTINCT `name` FROM ip_log WHERE ip IN (SELECT distinct ip FROM ip_log WHERE name = ?);");
- - statement.setString(1, username);
- + statement = DBManager.prepareStatement("SELECT DISTINCT `name` FROM ip_log WHERE ip IN (SELECT distinct ip FROM ip_log WHERE player_id = ?);");
- + statement.setString(1, playerId.toString());
- result = statement.executeQuery();
- while (result.next()) {
- playernames.add(result.getString("name"));
- }
- } catch (SQLException ex) {
- - InnPlugin.logError("Cannot find related usernames for " + username + "!", ex);
- + InnPlugin.logError("Cannot find related usernames for player " + playerName + "!", ex);
- return null;
- } finally {
- DBManager.closeResultSet(result);
- @@ -114,41 +116,23 @@ public final class Playerinfo {
- return playernames;
- }
- -
- - /**
- - * Does the same as Playerinfo::findRelatedUsernames().
- - * The only difference is that this method returns the playerinfo objects.
- - * @return List of playerinfo objects of the players that are linked
- - * @throws SQLException
- - */
- - public List<Playerinfo> findRelatedPlayers() throws SQLException {
- - List<String> players = findRelatedUsernames();
- - ArrayList<Playerinfo> playerInfoList = new ArrayList<Playerinfo>(players.size());
- -
- - for (String name : players) {
- - // If the player is in the findRelatedUsernames list then it must have an entry in the DB.
- - playerInfoList.add(Playerinfo.findPlayer(name));
- - }
- - return playerInfoList;
- - }
- -
- // </editor-fold>
- // <editor-fold defaultstate="collapsed" desc="Static methods">
- /**
- * Looks for the playerinformation in the database.<br/>
- * If no data is found, null will be returned
- *
- - * @param username
- + * @param playerId
- * @return The info of the player or null if player not found or no IP-addresses;
- */
- - public static Playerinfo findPlayer(String username) {
- + public static Playerinfo findPlayer(UUID playerId, String playerName) {
- PreparedStatement statement = null;
- ResultSet result = null;
- try {
- // Get the addresses of the player.
- - statement = DBManager.prepareStatement("SELECT DISTINCT ip FROM `ip_log` where `name` = ?;");
- - statement.setString(1, username);
- + statement = DBManager.prepareStatement("SELECT DISTINCT ip FROM `ip_log` where `player_id` = ?;");
- + statement.setString(1, playerId.toString());
- result = statement.executeQuery();
- HashSet<IPAddress> addresses = new HashSet<IPAddress>();
- @@ -157,7 +141,7 @@ public final class Playerinfo {
- }
- // return the object
- - return new Playerinfo(username, addresses);
- + return new Playerinfo(playerId, playerName, addresses);
- } catch (SQLException ex) {
- Logger.getLogger(Playerinfo.class.getName()).log(Level.SEVERE, null, ex);
- } finally {
- diff --git a/src/net/innectis/innplugin/Handlers/LightsourceHandler.java b/src/net/innectis/innplugin/Handlers/LightsourceHandler.java
- index a6841856d..60baa3961 100644
- --- a/src/net/innectis/innplugin/Handlers/LightsourceHandler.java
- +++ b/src/net/innectis/innplugin/Handlers/LightsourceHandler.java
- @@ -2,6 +2,7 @@ package net.innectis.innplugin.Handlers;
- import java.util.HashMap;
- import java.util.Map;
- +import java.util.UUID;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.Items.IdpMaterial;
- import net.innectis.innplugin.Player.IdpPlayer;
- @@ -16,17 +17,17 @@ import org.bukkit.craftbukkit.v1_7_R2.CraftWorld;
- * @author AlphaBlend
- */
- public class LightsourceHandler {
- - private static Map<String, Location> litLocations = new HashMap<String, Location>();
- + private static Map<UUID, Location> litLocations = new HashMap<UUID, Location>();
- /**
- * Light up the specified location
- - * @param player
- + * @param playerId
- * @param location
- */
- - public static void lightBlock(String player, Location location) {
- + public static void lightBlock(UUID playerId, Location location) {
- // Check if the location is not already being lit up
- if (canLightUp(location) && !isLit(location)) {
- - Location previous = litLocations.get(player.toLowerCase());
- + Location previous = litLocations.get(playerId);
- // If the previous block was lit up, notify everyone of the original block
- if (previous != null) {
- @@ -42,16 +43,16 @@ public class LightsourceHandler {
- p.getHandle().sendBlockChange(location, Material.GLOWSTONE, (byte) 0);
- }
- - litLocations.put(player.toLowerCase(), location);
- + litLocations.put(playerId, location);
- }
- }
- /**
- * Makes the specified location unlit
- - * @param player
- + * @param playerId
- */
- - public static void unlightBlock(String player) {
- - Location litLocation = litLocations.get(player.toLowerCase());
- + public static void unlightBlock(UUID playerId) {
- + Location litLocation = litLocations.get(playerId);
- if (litLocation != null) {
- int x = litLocation.getBlockX();
- @@ -59,7 +60,7 @@ public class LightsourceHandler {
- int z = litLocation.getBlockZ();
- World world = ((CraftWorld) litLocation.getWorld()).getHandle();
- world.notify(x, y, z);
- - litLocations.remove(player.toLowerCase());
- + litLocations.remove(playerId);
- }
- }
- @@ -79,16 +80,16 @@ public class LightsourceHandler {
- }
- /**
- - * Gets a player by the location they are lighting up
- + * Gets a player's ID by the location they are lighting up
- * @param location
- * @return
- */
- - public static String getPlayerNameFromLocation(Location location) {
- - for (String player : litLocations.keySet()) {
- - Location loc = litLocations.get(player.toLowerCase());
- + public static UUID getPlayerIdFromLocation(Location location) {
- + for (UUID playerId : litLocations.keySet()) {
- + Location loc = litLocations.get(playerId);
- if (loc.equals(location)) {
- - return player;
- + return playerId;
- }
- }
- @@ -97,11 +98,11 @@ public class LightsourceHandler {
- /**
- * Determines if the player is lighting up a block
- - * @param player
- + * @param playerId
- * @return
- */
- - public static boolean isLightingBlock(String player) {
- - return litLocations.containsKey(player.toLowerCase());
- + public static boolean isLightingBlock(UUID playerId) {
- + return litLocations.containsKey(playerId);
- }
- /**
- diff --git a/src/net/innectis/innplugin/Handlers/MemberGroupHandler.java b/src/net/innectis/innplugin/Handlers/MemberGroupHandler.java
- index 879939e14..5cbee3e2f 100644
- --- a/src/net/innectis/innplugin/Handlers/MemberGroupHandler.java
- +++ b/src/net/innectis/innplugin/Handlers/MemberGroupHandler.java
- @@ -7,9 +7,12 @@ import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map.Entry;
- +import java.util.UUID;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.InnectisObjects.MemberGroup;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- /**
- *
- @@ -31,25 +34,31 @@ public final class MemberGroupHandler {
- ResultSet result2 = null;
- try {
- - statement = DBManager.prepareStatement("SELECT groupid, username, groupname FROM member_groups;");
- + statement = DBManager.prepareStatement("SELECT groupid, player_id, groupname FROM member_groups;");
- result = statement.executeQuery();
- - MemberGroup group;
- - int groupId;
- while (result.next()) {
- - group = new MemberGroup(result.getInt("groupid"), result.getString("username"), result.getString("groupname"));
- - groupId = result.getInt("groupid");
- + String playerIdString = result.getString("player_id");
- + UUID playerId = UUID.fromString(playerIdString);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(playerId, true);
- - statement2 = DBManager.prepareStatement("SELECT username FROM member_users WHERE groupid=?;");
- + int groupId = result.getInt("groupid");
- + String groupName = result.getString("groupname");
- + MemberGroup group = new MemberGroup(groupId, credentials, groupName);
- +
- + statement2 = DBManager.prepareStatement("SELECT player_id FROM member_users WHERE groupid = ?;");
- statement2.setInt(1, groupId);
- result2 = statement2.executeQuery();
- while (result2.next()) {
- - group.addMember(result2.getString("username"));
- + String memberPlayerIdString = result.getString("player_id");
- + UUID memberPlayerId = UUID.fromString(memberPlayerIdString);
- + PlayerCredentials memberCredentials = PlayerCredentialsManager.getByUniqueId(memberPlayerId, true);
- + group.addMember(memberCredentials);
- }
- group.setUpdated(false); //just loaded it from db, so nothing has changed
- - getGroups().put(getKey(group.getOwner(), group.getName()), group);
- + getGroups().put(getKey(group.getOwnerCredentials().getUniqueId(), group.getName()), group);
- }
- } catch (SQLException ex) {
- InnPlugin.logError("COULD NOT GET MEMBER GROUPS FROM DATABASE!", ex);
- @@ -64,20 +73,20 @@ public final class MemberGroupHandler {
- return true;
- }
- - private static String getKey(String owner, String groupName) {
- - return owner.toLowerCase() + ' ' + groupName.toLowerCase();
- + private static String getKey(UUID ownerId, String groupName) {
- + return ownerId.toString() + ' ' + groupName.toLowerCase();
- }
- - public static boolean isGroup(String owner, String groupName) {
- - return getGroups().containsKey(getKey(owner, groupName));
- + public static boolean isGroup(UUID ownerId, String groupName) {
- + return getGroups().containsKey(getKey(ownerId, groupName));
- }
- - public static List<MemberGroup> getGroups(String owner) {
- - ArrayList<MemberGroup> groups = new ArrayList<MemberGroup>();
- - String name;
- + public static List<MemberGroup> getGroups(UUID ownerId) {
- + List<MemberGroup> groups = new ArrayList<MemberGroup>();
- +
- for (Entry<String, MemberGroup> ent : getGroups().entrySet()) {
- - name = ent.getKey().split(" ")[0];
- - if (name.equalsIgnoreCase(owner)) {
- + String ownerIdString = ent.getKey().split(" ")[0];
- + if (ownerIdString.equals(ownerId.toString())) {
- groups.add(ent.getValue());
- }
- }
- @@ -87,27 +96,27 @@ public final class MemberGroupHandler {
- return groups;
- }
- - public static MemberGroup getGroup(String owner, String groupName) {
- - return getGroups().get(getKey(owner, groupName));
- + public static MemberGroup getGroup(UUID ownerId, String groupName) {
- + return getGroups().get(getKey(ownerId, groupName));
- }
- - public static boolean addGroup(String owner, String groupName) {
- - MemberGroup group = new MemberGroup(-1, owner, groupName);
- + public static boolean addGroup(PlayerCredentials credentials, String groupName) {
- + MemberGroup group = new MemberGroup(-1, credentials, groupName);
- if (group.save()) {
- - getGroups().put(getKey(owner, groupName), group);
- + getGroups().put(getKey(credentials.getUniqueId(), groupName), group);
- return true;
- } else {
- return false;
- }
- }
- - public static boolean removeGroup(String owner, String groupName) {
- + public static boolean removeGroup(UUID ownerId, String groupName) {
- PreparedStatement statement = null;
- try {
- - MemberGroup group = getGroup(owner, groupName);
- -
- + MemberGroup group = getGroup(ownerId, groupName);
- +
- statement = DBManager.prepareStatement("DELETE FROM member_users WHERE groupid=?;");
- statement.setInt(1, group.getId());
- statement.executeUpdate();
- diff --git a/src/net/innectis/innplugin/Handlers/ModifiablePermissionsHandler.java b/src/net/innectis/innplugin/Handlers/ModifiablePermissionsHandler.java
- index fc0d976ab..e16252e37 100644
- --- a/src/net/innectis/innplugin/Handlers/ModifiablePermissionsHandler.java
- +++ b/src/net/innectis/innplugin/Handlers/ModifiablePermissionsHandler.java
- @@ -6,10 +6,13 @@ import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- +import java.util.UUID;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.InnectisObjects.ModifiablePermissions;
- import net.innectis.innplugin.Player.Permission;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- /**
- * This handles the modifiable permissions of players.
- @@ -75,18 +78,19 @@ public final class ModifiablePermissionsHandler {
- /**
- * Loads the modifiable permissions from database for specified username
- - * @param username
- + * @param playerId
- * @return
- */
- - public static ModifiablePermissions loadModifiedPermissions(String username) {
- - ModifiablePermissions perms = new ModifiablePermissions(username);
- + public static ModifiablePermissions loadModifiedPermissions(UUID playerId) {
- + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(playerId, true);
- + ModifiablePermissions perms = new ModifiablePermissions(credentials);
- PreparedStatement statement = null;
- ResultSet set = null;
- try {
- - statement = DBManager.prepareStatement("SELECT * FROM player_permission WHERE lower(name) = ?");
- - statement.setString(1, username.toLowerCase());
- + statement = DBManager.prepareStatement("SELECT * FROM player_permission WHERE player_id = ?");
- + statement.setString(1, playerId.toString());
- set = statement.executeQuery();
- while (set.next()) {
- @@ -95,7 +99,7 @@ public final class ModifiablePermissionsHandler {
- perms.addPermissionNoSave(permID, disabled ? PermissionType.DISABLED : PermissionType.ADDITIONAL);
- }
- } catch (SQLException ex) {
- - InnPlugin.logError("Cannot load modifiable permissions for " + username + "!", ex);
- + InnPlugin.logError("Cannot load modifiable permissions for player with ID: " + playerId.toString() + "!", ex);
- } finally {
- DBManager.closeResultSet(set);
- DBManager.closePreparedStatement(statement);
- @@ -109,7 +113,7 @@ public final class ModifiablePermissionsHandler {
- * @return
- */
- public static List<ModifiablePermissions> getAllModifiedPermsFromDB() {
- - HashMap<String, ModifiablePermissions> tempMap = new HashMap<String, ModifiablePermissions>();
- + HashMap<UUID, ModifiablePermissions> tempMap = new HashMap<UUID, ModifiablePermissions>();
- List<ModifiablePermissions> permList = new ArrayList<ModifiablePermissions>();
- PreparedStatement statement = null;
- @@ -120,16 +124,18 @@ public final class ModifiablePermissionsHandler {
- set = statement.executeQuery();
- while (set.next()) {
- - String username = set.getString("name");
- + String playerIdString = set.getString("player_id");
- + UUID playerId = UUID.fromString(playerIdString);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(playerId);
- int permID = set.getInt("permissionid");
- boolean disabled = set.getBoolean("disabled");
- - if (!tempMap.containsKey(username.toLowerCase())) {
- - ModifiablePermissions perms = new ModifiablePermissions(username);
- + if (!tempMap.containsKey(playerId)) {
- + ModifiablePermissions perms = new ModifiablePermissions(credentials);
- perms.addPermissionNoSave(permID, (disabled ? PermissionType.DISABLED : PermissionType.ADDITIONAL));
- - tempMap.put(username.toLowerCase(), perms);
- + tempMap.put(playerId, perms);
- } else {
- - ModifiablePermissions perms = tempMap.get(username.toLowerCase());
- + ModifiablePermissions perms = tempMap.get(playerId);
- perms.addPermissionNoSave(permID, (disabled ? PermissionType.DISABLED : PermissionType.ADDITIONAL));
- }
- }
- diff --git a/src/net/innectis/innplugin/Handlers/PvpHandler.java b/src/net/innectis/innplugin/Handlers/PvpHandler.java
- index b42da1dbe..1f4f4110a 100644
- --- a/src/net/innectis/innplugin/Handlers/PvpHandler.java
- +++ b/src/net/innectis/innplugin/Handlers/PvpHandler.java
- @@ -111,7 +111,7 @@ public final class PvpHandler {
- // No points for killing yourself
- if (!attacker.getName().equalsIgnoreCase(defender.getName())) {
- - int kills = attacker.getSession().getPvpKillTotalOf(defender);
- + int kills = attacker.getSession().getPvpKillTotalOf(defender.getUniqueId());
- if (kills == 0) {
- points = 10;
- } else if (kills == 1) {
- @@ -139,10 +139,10 @@ public final class PvpHandler {
- //defender.dealDamage(100000); //ensure they die
- - attacker.getSession().addPvpKill(defender);
- + attacker.getSession().addPvpKill(defender.getUniqueId());
- - TransactionObject to = TransactionHandler.getTransactionObject(attacker.getName());
- - to.addValue(points, TransactionHandler.TransactionType.PVP_POINTS);
- + TransactionObject transaction = TransactionHandler.getTransactionObject(attacker.getUniqueId(), attacker.getName());
- + transaction.addValue(points, TransactionHandler.TransactionType.PVP_POINTS);
- attacker.print(ChatColor.LIGHT_PURPLE, "You have been awarded " + points + " points for killing " + defender.getColoredName());
- InnectisLot attackerLot = LotHandler.getLot(attacker.getLocation());
- diff --git a/src/net/innectis/innplugin/Handlers/StaffMessageHandler.java b/src/net/innectis/innplugin/Handlers/StaffMessageHandler.java
- index 28f099abe..20377bd9e 100644
- --- a/src/net/innectis/innplugin/Handlers/StaffMessageHandler.java
- +++ b/src/net/innectis/innplugin/Handlers/StaffMessageHandler.java
- @@ -7,6 +7,8 @@ import java.util.*;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.InnectisObjects.StaffMessage;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- /**
- * A class that handles all staff requests that players have
- @@ -36,10 +38,14 @@ public final class StaffMessageHandler {
- int id = set.getInt("id");
- java.sql.Date date = set.getDate("datecreated");
- boolean read = set.getBoolean("hasread");
- - String creator = set.getString("creator");
- +
- + String creatorId = set.getString("creator_player_id");
- + UUID creatorUUID = UUID.fromString(creatorId);
- + PlayerCredentials creatorCredentials = PlayerCredentialsManager.getByUniqueId(creatorUUID, true);
- +
- String message = set.getString("message");
- - StaffMessage sm = new StaffMessage(id, date, read, creator, message);
- + StaffMessage sm = new StaffMessage(id, date, read, creatorCredentials, message);
- staffRequests.add(sm);
- }
- } catch (SQLException ex) {
- diff --git a/src/net/innectis/innplugin/Handlers/TransactionHandler.java b/src/net/innectis/innplugin/Handlers/TransactionHandler.java
- index 69da6ba2b..49cb1918a 100644
- --- a/src/net/innectis/innplugin/Handlers/TransactionHandler.java
- +++ b/src/net/innectis/innplugin/Handlers/TransactionHandler.java
- @@ -1,13 +1,12 @@
- package net.innectis.innplugin.Handlers;
- -import java.util.HashMap;
- -
- -import net.innectis.innplugin.Handlers.Datasource.DBManager;
- -
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- +import java.util.HashMap;
- import java.util.Map;
- +import java.util.UUID;
- +import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.InnectisObjects.TransactionObject;
- import net.innectis.innplugin.Player.IdpPlayer;
- @@ -18,7 +17,7 @@ import net.innectis.innplugin.Player.IdpPlayer;
- * @author AlphaBlend
- */
- public final class TransactionHandler {
- - private static Map<String, TransactionObject> playerTransactions = new HashMap<String, TransactionObject>();
- + private static Map<UUID, TransactionObject> playerTransactions = new HashMap<UUID, TransactionObject>();
- private TransactionHandler() {
- }
- @@ -74,44 +73,44 @@ public final class TransactionHandler {
- /**
- * Removes the transaction object from the cache
- - * @param player
- + * @param playerId
- */
- - public static void removeTransactionObjectFromCache(String player) {
- - if (playerTransactions.containsKey(player.toLowerCase())) {
- - playerTransactions.remove(player.toLowerCase());
- + public static void removeTransactionObjectFromCache(UUID playerId) {
- + if (playerTransactions.containsKey(playerId)) {
- + playerTransactions.remove(playerId);
- }
- }
- /**
- - * Gets the transaction object of the player
- + * Gets the transaction object of the player by their ID
- *
- - * @param player
- + * @param playerId
- * @return the transaction object of the player
- * or null if the player doesn't exist
- */
- - public static TransactionObject getTransactionObject(String player) {
- - TransactionObject to = playerTransactions.get(player.toLowerCase());
- + public static TransactionObject getTransactionObject(UUID playerId, String playerName) {
- + TransactionObject to = playerTransactions.get(playerId);
- // If the currency is not in cache, load from database
- if (to == null) {
- - to = loadPlayerBalance(player);
- + to = loadPlayerBalance(playerId, playerName);
- }
- return to;
- }
- /**
- - * Loads the balance from the specified player into memory
- - * @param player
- + * Loads the balance from the specified player ID into memory
- + * @param playerId
- * @return
- */
- - public static TransactionObject loadPlayerBalance(String player) {
- + private static TransactionObject loadPlayerBalance(UUID playerId, String playerName) {
- PreparedStatement statement = null;
- ResultSet set = null;
- try {
- - 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) = ?");
- - statement.setString(1, player.toLowerCase());
- + 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 = ?");
- + statement.setString(1, playerId.toString());
- set = statement.executeQuery();
- if (set.next()) {
- @@ -123,19 +122,19 @@ public final class TransactionHandler {
- int referPoints = set.getInt("referral_points");
- int votePoints = set.getInt("vote_points");
- - TransactionObject transaction = new TransactionObject(player, valutas, valutasInBank, valutasToBank, valutasToPlayer, pvpPoints, referPoints, votePoints);
- + TransactionObject transaction = new TransactionObject(playerId, playerName, valutas, valutasInBank, valutasToBank, valutasToPlayer, pvpPoints, referPoints, votePoints);
- - IdpPlayer testPlayer = InnPlugin.getPlugin().getPlayer(player);
- + IdpPlayer testPlayer = InnPlugin.getPlugin().getPlayer(playerId);
- // Cache the object if we have a player online
- if (testPlayer != null) {
- - playerTransactions.put(player.toLowerCase(), transaction);
- + playerTransactions.put(playerId, transaction);
- }
- return transaction;
- }
- } catch (SQLException ex) {
- - InnPlugin.logError("Unable to load player's balance!", ex);
- + InnPlugin.logError("Unable to load player balance for " + playerName + "!", ex);
- } finally {
- DBManager.closeResultSet(set);
- DBManager.closePreparedStatement(statement);
- diff --git a/src/net/innectis/innplugin/InnPlugin.java b/src/net/innectis/innplugin/InnPlugin.java
- index 33005a0ed..1c8fe3423 100644
- --- a/src/net/innectis/innplugin/InnPlugin.java
- +++ b/src/net/innectis/innplugin/InnPlugin.java
- @@ -9,6 +9,7 @@ import java.util.HashSet;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.Map;
- +import java.util.UUID;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import net.innectis.innplugin.BanSystem.BanHandler;
- @@ -36,6 +37,8 @@ import net.innectis.innplugin.Player.Channel.ChatChannelHandler;
- import net.innectis.innplugin.Player.Chat.ChatColor;
- import net.innectis.innplugin.Player.IdpPlayer;
- import net.innectis.innplugin.Player.Permission;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Player.PlayerGroup;
- import net.innectis.innplugin.Player.TinyWE.BlockCounters.BlockCounterFactory;
- import net.innectis.innplugin.Shop.ShopHandler;
- @@ -95,7 +98,7 @@ public class InnPlugin extends JavaPlugin implements TabCompleter {
- private Map<String, Long> _adminMsgSpam = Collections.synchronizedMap(new HashMap<String, Long>(200));
- private Map<Long, LotFlagToggle> _lotFlagToggles = Collections.synchronizedMap(new HashMap<Long, LotFlagToggle>(10));
- private List<EnderChestView> _enderchestViews = new LinkedList<EnderChestView>();
- - private Map<String, IdpInventory> _backpackViews = new HashMap<String, IdpInventory>();
- + private Map<UUID, IdpInventory> _backpackViews = new HashMap<UUID, IdpInventory>();
- public CommandManager commandManager;
- public MenuItem helpMenu;
- private List<Long> timers = new LinkedList<Long>();
- @@ -460,7 +463,8 @@ public class InnPlugin extends JavaPlugin implements TabCompleter {
- if (y == height + 2) {
- if (WaypointHandler.getWaypoint(block.getLocation(), false) == null) {
- try {
- - InnectisWaypoint waypoint = WaypointHandler.createWaypoint("Hretsam", block, true);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName("Hretsam");
- + InnectisWaypoint waypoint = WaypointHandler.createWaypoint(credentials, block, true);
- waypoint.setDestination(new Location(world, block.getX() * 50, 128, block.getZ() * 50));
- waypoint.save();
- } catch (SQLException ex) {
- @@ -838,6 +842,21 @@ public class InnPlugin extends JavaPlugin implements TabCompleter {
- return null;
- }
- + /**
- + * Gets an online player from their unique ID
- + * @param playerId
- + * @return
- + */
- + public IdpPlayer getPlayer(UUID playerId) {
- + for (IdpPlayer player : getOnlinePlayers()) {
- + if (player.getUniqueId().equals(playerId)) {
- + return player;
- + }
- + }
- +
- + return null;
- + }
- +
- /**
- * Returns the given player, or null if he/she is not found (or online)
- *
- @@ -1175,16 +1194,16 @@ public class InnPlugin extends JavaPlugin implements TabCompleter {
- }
- /**
- - * Gets an ender chest view by the given owner and chest type
- - * @param name
- + * Gets an ender chest view by the ID of the given owner and chest type
- + * @param playerId
- * @param type
- * @return
- */
- - public EnderChestView getEnderChestView(String owner, EnderContentsType type) {
- + public EnderChestView getEnderChestView(UUID playerId, EnderContentsType type) {
- EnderChestView enderView = null;
- for (EnderChestView view : _enderchestViews) {
- - if (view.getOwner().equalsIgnoreCase(owner) && view.getContentsType() == type) {
- + if (view.getOwnerId().equals(playerId) && view.getContentsType() == type) {
- enderView = view;
- break;
- }
- @@ -1205,28 +1224,28 @@ public class InnPlugin extends JavaPlugin implements TabCompleter {
- //<editor-fold defaultstate="collapsed" desc="Backpack Viewing">
- /**
- * Adds a new backpack view
- - * @param owner
- + * @param playerId
- * @param inv
- */
- - public void addBackpackView(String owner, IdpInventory inv) {
- - _backpackViews.put(owner.toLowerCase(), inv);
- + public void addBackpackView(UUID playerId, IdpInventory inv) {
- + _backpackViews.put(playerId, inv);
- }
- /**
- * Gets an existing backpack view
- - * @param owner
- - * @return
- + * @param playerId
- + * playerId
- */
- - public IdpInventory getBackpackView(String owner) {
- - return _backpackViews.get(owner.toLowerCase());
- + public IdpInventory getBackpackView(UUID playerId) {
- + return _backpackViews.get(playerId);
- }
- /**
- * Removes a backpack view by the owner
- - * @param owner
- + * @param playerId
- */
- - public void removeBackpackView(String owner) {
- - _backpackViews.remove(owner.toLowerCase());
- + public void removeBackpackView(UUID playerId) {
- + _backpackViews.remove(playerId);
- }
- //</editor-fold>
- }
- diff --git a/src/net/innectis/innplugin/InnectisObjects/EnderChestContents.java b/src/net/innectis/innplugin/InnectisObjects/EnderChestContents.java
- index ecef250b1..546ec3ed1 100644
- --- a/src/net/innectis/innplugin/InnectisObjects/EnderChestContents.java
- +++ b/src/net/innectis/innplugin/InnectisObjects/EnderChestContents.java
- @@ -6,10 +6,13 @@ import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- +import java.util.UUID;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.Items.IdpItemStack;
- import net.innectis.innplugin.Items.StackBag;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- /**
- *
- @@ -22,26 +25,26 @@ public class EnderChestContents {
- private int chestid;
- private long bagid;
- private int typeid;
- - private String player;
- + private PlayerCredentials playerCredentials;
- /** The items */
- private IdpItemStack[] items;
- private EnderChestContents() {
- }
- - private EnderChestContents(int chestid, long bagid, int typeid, String player, IdpItemStack[] items) {
- + private EnderChestContents(int chestid, long bagid, int typeid, PlayerCredentials playerCredentials, IdpItemStack[] items) {
- this.chestid = chestid;
- this.bagid = bagid;
- this.typeid = typeid;
- - this.player = player;
- + this.playerCredentials = playerCredentials;
- this.items = items;
- }
- - private EnderChestContents(int chestid, int typeid, String player, IdpItemStack[] items) {
- + private EnderChestContents(int chestid, int typeid, PlayerCredentials playerCredentials, IdpItemStack[] items) {
- this.chestid = chestid;
- this.bagid = 0;
- this.typeid = typeid;
- - this.player = player;
- + this.playerCredentials = playerCredentials;
- this.items = items;
- }
- @@ -53,12 +56,20 @@ public class EnderChestContents {
- return chestid;
- }
- + /**
- + * Gets the credentials of the player these contents belong to
- + * @return
- + */
- + public PlayerCredentials getPlayerCredentials() {
- + return playerCredentials;
- + }
- +
- /**
- * Returns the name of the player where this content belongs to
- * @return
- */
- public String getPlayername() {
- - return player;
- + return playerCredentials.getName();
- }
- /**
- @@ -100,8 +111,8 @@ public class EnderChestContents {
- StackBag bag = new StackBag(items);
- bag.save();
- - statement = DBManager.prepareStatementWithAutoGeneratedKeys(" INSERT INTO enderchests (username, typeid, bagid) VALUES (?,?,?) ");
- - statement.setString(1, player);
- + statement = DBManager.prepareStatementWithAutoGeneratedKeys(" INSERT INTO enderchests (player_id, typeid, bagid) VALUES (?,?,?) ");
- + statement.setString(1, playerCredentials.getUniqueId().toString());
- statement.setInt(2, typeid);
- statement.setLong(3, bag.getBagid());
- statement.executeUpdate();
- @@ -138,10 +149,10 @@ public class EnderChestContents {
- /**
- * Gives the EnderChestContents of the enderchest for the player.
- * It will use the player's location to get the correct chest.
- - * @param player
- + * @param playerCredentials
- * @return
- */
- - public static EnderChestContents getContents(String player, EnderContentsType type) {
- + public static EnderChestContents getContents(PlayerCredentials playerCredentials, EnderContentsType type) {
- // Return null if type == NONE
- if (type == EnderContentsType.NONE) {
- return null;
- @@ -151,9 +162,9 @@ public class EnderChestContents {
- ResultSet set = null;
- try {
- - statement = DBManager.prepareStatement(" SELECT chestid, bagid FROM enderchests where lower(username) = ? and typeid = ? ");
- + statement = DBManager.prepareStatement(" SELECT chestid, bagid FROM enderchests where player_id = ? and typeid = ? ");
- - statement.setString(1, player.toLowerCase());
- + statement.setString(1, playerCredentials.getUniqueId().toString());
- statement.setInt(2, type.getTypeid());
- set = statement.executeQuery();
- @@ -165,9 +176,9 @@ public class EnderChestContents {
- }
- if (bagid > 0) {
- StackBag bag = StackBag.getContentbag(bagid);
- - return new EnderChestContents(id, bagid, type.getTypeid(), player, bag.getContents());
- + return new EnderChestContents(id, bagid, type.getTypeid(), playerCredentials, bag.getContents());
- } else {
- - return new EnderChestContents(id, type.getTypeid(), player, new IdpItemStack[27]);
- + return new EnderChestContents(id, type.getTypeid(), playerCredentials, new IdpItemStack[27]);
- }
- } catch (SQLException ex) {
- InnPlugin.logError("Error loading endercontents!", ex);
- @@ -190,18 +201,22 @@ public class EnderChestContents {
- ResultSet set = null;
- try {
- - statement = DBManager.prepareStatement("SELECT chestid, username, typeid, bagid FROM enderchests");
- + statement = DBManager.prepareStatement("SELECT chestid, player_id, typeid, bagid FROM enderchests");
- set = statement.executeQuery();
- while (set.next()) {
- int id = set.getInt("chestid");
- - String username = set.getString("username");
- +
- + String playerIdString = set.getString("player_id");
- + UUID playerId = UUID.fromString(playerIdString);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(playerId);
- +
- int typeid = set.getInt("typeid");
- long bagid = set.getLong("bagid");
- if (bagid > 0) {
- StackBag bag = StackBag.getContentbag(bagid);
- - enderChests.add(new EnderChestContents(id, bagid, typeid, username, bag.getContents()));
- + enderChests.add(new EnderChestContents(id, bagid, typeid, credentials, bag.getContents()));
- }
- }
- } catch (SQLException ex) {
- diff --git a/src/net/innectis/innplugin/InnectisObjects/EnderChestView.java b/src/net/innectis/innplugin/InnectisObjects/EnderChestView.java
- index 7f54d8adf..1c1720b8b 100644
- --- a/src/net/innectis/innplugin/InnectisObjects/EnderChestView.java
- +++ b/src/net/innectis/innplugin/InnectisObjects/EnderChestView.java
- @@ -1,5 +1,6 @@
- package net.innectis.innplugin.InnectisObjects;
- +import java.util.UUID;
- import net.innectis.innplugin.InnectisObjects.EnderChestContents.EnderContentsType;
- import org.bukkit.inventory.Inventory;
- @@ -9,41 +10,41 @@ import org.bukkit.inventory.Inventory;
- * @author AlphaBlend
- */
- public class EnderChestView {
- - private String owner;
- + private UUID ownerId;
- private EnderContentsType type;
- private Inventory inventory;
- -
- +
- /**
- * Constructs a new ender chest view of a given chest
- - * @param owner
- + * @param ownerId
- * @param type
- - * @param inventory
- + * @param inventory
- */
- - public EnderChestView(String owner, EnderContentsType type, Inventory inventory) {
- - this.owner = owner;
- + public EnderChestView(UUID ownerId, EnderContentsType type, Inventory inventory) {
- + this.ownerId = ownerId;
- this.type = type;
- this.inventory = inventory;
- }
- -
- +
- /**
- - * Gets the owner of this chest view
- - * @return
- + * Gets the ID of the owner of this chest view
- + * @return
- */
- - public String getOwner() {
- - return owner;
- + public UUID getOwnerId() {
- + return ownerId;
- }
- -
- +
- /**
- * Gets the content type of this ender chest
- - * @return
- + * @return
- */
- public EnderContentsType getContentsType() {
- return type;
- }
- -
- +
- /**
- * Gets the inventory of this ender chest
- - * @return
- + * @return
- */
- public Inventory getInventory() {
- return inventory;
- diff --git a/src/net/innectis/innplugin/InnectisObjects/IPLogger.java b/src/net/innectis/innplugin/InnectisObjects/IPLogger.java
- index b5edf39f2..6d2d1eb11 100644
- --- a/src/net/innectis/innplugin/InnectisObjects/IPLogger.java
- +++ b/src/net/innectis/innplugin/InnectisObjects/IPLogger.java
- @@ -1,20 +1,21 @@
- package net.innectis.innplugin.InnectisObjects;
- -import java.util.ArrayList;
- -import java.util.List;
- -
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Timestamp;
- +import java.util.ArrayList;
- +import java.util.List;
- +import java.util.UUID;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- /**
- *
- * @author AlphaBlend
- *
- - * Logs all IPs of banned users when they attempt to connect
- + * Logs connections from players when they join the server
- */
- public class IPLogger {
- private IPLogger() {}
- @@ -22,35 +23,35 @@ public class IPLogger {
- /**
- * Logs a connection to the database
- */
- - public static void logConnection(String username, String ip, Timestamp timestamp) {
- + public static void logConnection(UUID playerId, String playerName, String ip, Timestamp timestamp) {
- PreparedStatement statement = null;
- try {
- - statement = DBManager.prepareStatement("INSERT INTO ip_log (name, ip, logtime) VALUES (?, ?, ?) ");
- - statement.setString(1, username);
- + statement = DBManager.prepareStatement("INSERT INTO ip_log (player_id, ip, logtime) VALUES (?, ?, ?) ");
- + statement.setString(1, playerId.toString());
- statement.setString(2, ip);
- statement.setTimestamp(3, timestamp);
- statement.execute();
- } catch (SQLException ex) {
- - InnPlugin.logError("Cannot log connection from player '" + username + "' with ip '" + ip + "'", ex);
- + InnPlugin.logError("Cannot log connection from player " + playerName + " with ip " + ip + "!", ex);
- } finally {
- DBManager.closePreparedStatement(statement);
- }
- }
- /**
- * Get IPs used by a given player
- - * @param player
- + * @param playerId
- * @return
- */
- - public static List<String> getIPsByPlayer(String username) {
- + public static List<String> getIPsByPlayer(UUID playerId, String playerName) {
- List<String> IPs = new ArrayList<String>();
- PreparedStatement statement = null;
- ResultSet set = null;
- try {
- - statement = DBManager.prepareStatement("SELECT DISTINCT ip FROM ip_log WHERE lower(name) = ?");
- - statement.setString(1, username.toLowerCase());
- + statement = DBManager.prepareStatement("SELECT DISTINCT ip FROM ip_log WHERE player_id = ?;");
- + statement.setString(1, playerId.toString());
- set = statement.executeQuery();
- while (set.next()) {
- @@ -58,7 +59,7 @@ public class IPLogger {
- IPs.add(ip);
- }
- } catch (SQLException ex) {
- - InnPlugin.logError("Unable to get IPs by player!", ex);
- + InnPlugin.logError("Unable to get IPs for player " + playerName + "!", ex);
- } finally {
- DBManager.closeResultSet(set);
- DBManager.closePreparedStatement(statement);
- @@ -68,26 +69,27 @@ public class IPLogger {
- }
- /**
- - * Gets the last IP used to connect to Innectis from this username
- - * @param username
- + * Gets the last IP used to connect to Innectis from this player
- + * represented by their ID
- + * @param playerId
- * @return
- */
- - public static String getLastUsedIP(String username) {
- + public static String getLastUsedIP(UUID playerId, String playerName) {
- String ip = null;
- PreparedStatement statement = null;
- ResultSet set = null;
- try {
- - statement = DBManager.prepareStatement("SELECT DISTINCT ip FROM ip_log WHERE lower(name) = ? ORDER BY logtime DESC LIMIT 1");
- - statement.setString(1, username.toLowerCase());
- + statement = DBManager.prepareStatement("SELECT DISTINCT ip FROM ip_log WHERE player_id = ? ORDER BY logtime DESC LIMIT 1;");
- + statement.setString(1, playerId.toString());
- set = statement.executeQuery();
- if (set.next()) {
- ip = set.getString("ip");
- }
- } catch (SQLException ex) {
- - InnPlugin.logError("UNable to get last used IP for " + username + "!", ex);
- + InnPlugin.logError("Umable to get last used IP for player " + playerName + "!", ex);
- } finally {
- DBManager.closeResultSet(set);
- DBManager.closePreparedStatement(statement);
- @@ -97,18 +99,18 @@ public class IPLogger {
- }
- /**
- - * Determines if the specified user has used the specified ip to log in with
- - * @param username
- - * @param ip
- + * Determines if the specified player has used the specified ip to log in with
- + * @param playerId
- + * @param checkIP
- * @return
- */
- - public boolean isUsingIP(String username, String checkIP) {
- + public boolean isUsingIP(UUID playerId, String playerName, String checkIP) {
- PreparedStatement statement = null;
- ResultSet set = null;
- try {
- - statement = DBManager.prepareStatement("SELECT DISTINCT ip FROM ip_log WHERE lower(name) = ?");
- - statement.setString(1, username.toLowerCase());
- + statement = DBManager.prepareStatement("SELECT DISTINCT ip FROM ip_log WHERE player_id = ?");
- + statement.setString(1, playerId.toString());
- set = statement.executeQuery();
- while (set.next()) {
- @@ -119,7 +121,7 @@ public class IPLogger {
- }
- }
- } catch (SQLException ex) {
- - InnPlugin.logError("Unable to check if " + username + " is using " + checkIP + "!", ex);
- + InnPlugin.logError("Unable to check if player " + playerName + " is using " + checkIP + "!", ex);
- } finally {
- DBManager.closeResultSet(set);
- DBManager.closePreparedStatement(statement);
- diff --git a/src/net/innectis/innplugin/InnectisObjects/IdpHome.java b/src/net/innectis/innplugin/InnectisObjects/IdpHome.java
- index 062647aa0..9e68db7b4 100644
- --- a/src/net/innectis/innplugin/InnectisObjects/IdpHome.java
- +++ b/src/net/innectis/innplugin/InnectisObjects/IdpHome.java
- @@ -3,6 +3,7 @@ package net.innectis.innplugin.InnectisObjects;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- +import java.util.UUID;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- import org.bukkit.Location;
- @@ -14,33 +15,34 @@ import org.bukkit.Location;
- */
- public class IdpHome {
- private int UID;
- - private String owner;
- + private UUID playerId;
- private int homeId;
- private String homeName;
- private Location location;
- /**
- * Constructs a home object with a brand new home ID
- - * @param owner
- + * @param playerId
- * @param homeID
- * @param name
- * @param location
- */
- - public IdpHome(String owner, int homeID, String homeName, Location location) {
- - this(0, owner, homeID, homeName, location);
- + public IdpHome(UUID playerId, int homeID, String homeName, Location location) {
- + this(0, playerId, homeID, homeName, location);
- }
- /**
- * Constructs a new object to hold a player's home location
- *
- * @param UID
- + * @param playerId
- * @param homeID
- * @param name
- * @param location
- */
- - public IdpHome(int UID, String owner, int homeID, String homeName, Location location) {
- + public IdpHome(int UID, UUID playerId, int homeID, String homeName, Location location) {
- this.UID = UID;
- - this.owner = owner;
- + this.playerId = playerId;
- this.homeId = homeID;
- this.homeName = homeName;
- this.location = location;
- @@ -104,7 +106,6 @@ public class IdpHome {
- * @return
- */
- public boolean equals(Location loc) {
- -
- if (loc.getBlockX() == location.getBlockX()
- && loc.getBlockY() == location.getBlockY()
- && loc.getBlockZ() == location.getBlockZ()
- @@ -124,7 +125,7 @@ public class IdpHome {
- try {
- if (UID > 0) {
- - statement = DBManager.prepareStatement("UPDATE homes SET homeid=?, homename=?, world=?, locx=?, locy=?, locz=?, yaw=? WHERE ID = ?");
- + statement = DBManager.prepareStatement("UPDATE homes SET homeid = ?, homename = ?, world = ?, locx = ?, locy = ?, locz = ?, yaw = ? WHERE ID = ?");
- statement.setInt(1, homeId);
- statement.setString(2, homeName);
- statement.setString(3, location.getWorld().getName());
- @@ -135,8 +136,8 @@ public class IdpHome {
- statement.setInt(8, UID);
- statement.executeUpdate();
- } else {
- - statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO homes (username, homeid, homename, world, locx, locy, locz, yaw) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
- - statement.setString(1, owner);
- + statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO homes (player_id, homeid, homename, world, locx, locy, locz, yaw) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
- + statement.setString(1, playerId.toString());
- statement.setInt(2, homeId);
- statement.setString(3, homeName);
- statement.setString(4, location.getWorld().getName());
- diff --git a/src/net/innectis/innplugin/InnectisObjects/MemberGroup.java b/src/net/innectis/innplugin/InnectisObjects/MemberGroup.java
- index af03e23f3..497271b87 100644
- --- a/src/net/innectis/innplugin/InnectisObjects/MemberGroup.java
- +++ b/src/net/innectis/innplugin/InnectisObjects/MemberGroup.java
- @@ -4,9 +4,11 @@ import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.HashSet;
- +import java.util.Iterator;
- +import java.util.UUID;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- -import net.innectis.innplugin.Player.IdpPlayer;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- /**
- *
- @@ -14,15 +16,15 @@ import net.innectis.innplugin.Player.IdpPlayer;
- */
- public class MemberGroup {
- private int id;
- - private String owner;
- - private HashSet<String> members;
- + private PlayerCredentials ownerCredentials;
- + private HashSet<PlayerCredentials> members;
- private String groupName;
- private boolean updated = false;
- - public MemberGroup(int id, String owner, String groupName) {
- + public MemberGroup(int id, PlayerCredentials ownerCredentials, String groupName) {
- this.id = id;
- - this.owner = owner;
- - this.members = new HashSet<String>();
- + this.ownerCredentials = ownerCredentials;
- + this.members = new HashSet<PlayerCredentials>();
- this.groupName = groupName;
- this.updated = true;
- }
- @@ -31,23 +33,30 @@ public class MemberGroup {
- return id;
- }
- + public PlayerCredentials getOwnerCredentials() {
- + return ownerCredentials;
- + }
- +
- public String getOwner() {
- - return owner;
- + return ownerCredentials.getName();
- }
- - public HashSet<String> getMembers() {
- + public HashSet<PlayerCredentials> getMembers() {
- return members;
- }
- public String getMembersString() {
- StringBuilder sb = new StringBuilder();
- - for (String m : members) {
- - sb.append(m).append(", ");
- +
- + for (PlayerCredentials pc : members) {
- + String name = pc.getName();
- + sb.append(name).append(", ");
- }
- if (sb.length() == 0) {
- return "none";
- }
- +
- return sb.substring(0, sb.length() - 2);
- }
- @@ -63,44 +72,40 @@ public class MemberGroup {
- this.updated = updated;
- }
- - public boolean addMember(String username) {
- - boolean ret = members.add(username.toLowerCase());
- - if (ret) {
- - updated = true;
- - }
- - return ret;
- - }
- + public boolean addMember(PlayerCredentials credentials) {
- + boolean ret = members.add(credentials);
- - public boolean addMember(IdpPlayer player) {
- - boolean ret = members.add(player.getName().toLowerCase());
- if (ret) {
- updated = true;
- }
- - return ret;
- - }
- - public boolean removeMember(String username) {
- - boolean ret = members.remove(username.toLowerCase());
- - if (ret) {
- - updated = true;
- - }
- return ret;
- }
- - public boolean removeMember(IdpPlayer player) {
- - boolean ret = members.remove(player.getName().toLowerCase());
- - if (ret) {
- - updated = true;
- + public boolean removeMember(String playerName) {
- + boolean ret = false;
- +
- + for (Iterator<PlayerCredentials> it = members.iterator(); it.hasNext();) {
- + PlayerCredentials pc = it.next();
- +
- + if (pc.getName().equalsIgnoreCase(playerName)) {
- + it.remove();
- + updated = true;
- + break;
- + }
- }
- +
- return ret;
- }
- - public boolean containsMember(String username) {
- - return members.contains(username.toLowerCase());
- - }
- + public boolean containsMember(String playerName) {
- + for (PlayerCredentials pc : members) {
- + if (pc.getName().equalsIgnoreCase(playerName)) {
- + return true;
- + }
- + }
- - public boolean containsMember(IdpPlayer player) {
- - return members.contains(player.getName().toLowerCase());
- + return false;
- }
- public boolean save() {
- @@ -109,8 +114,8 @@ public class MemberGroup {
- try {
- if (getId() == -1) {
- - statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT IGNORE INTO member_groups (username, groupname) VALUES (?, ?);");
- - statement.setString(1, owner);
- + statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT IGNORE INTO member_groups (player_id, groupname) VALUES (?, ?);");
- + statement.setString(1, ownerCredentials.getUniqueId().toString());
- statement.setString(2, groupName);
- statement.executeUpdate();
- result = statement.getGeneratedKeys();
- @@ -128,10 +133,10 @@ public class MemberGroup {
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- - for (String s : getMembers()) {
- - statement = DBManager.prepareStatement("INSERT INTO member_users (groupid, username) VALUES (?, ?);");
- + for (PlayerCredentials pc : getMembers()) {
- + statement = DBManager.prepareStatement("INSERT INTO member_users (groupid, player_id) VALUES (?, ?);");
- statement.setInt(1, getId());
- - statement.setString(2, s);
- + statement.setString(2, pc.getUniqueId().toString());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- }
- diff --git a/src/net/innectis/innplugin/InnectisObjects/Message.java b/src/net/innectis/innplugin/InnectisObjects/Message.java
- index 3f0203f4d..e0eac4c1a 100644
- --- a/src/net/innectis/innplugin/InnectisObjects/Message.java
- +++ b/src/net/innectis/innplugin/InnectisObjects/Message.java
- @@ -1,6 +1,7 @@
- package net.innectis.innplugin.InnectisObjects;
- import java.util.Date;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- /**
- * An abstract class that defines a basic message
- @@ -11,55 +12,49 @@ public abstract class Message {
- protected int id;
- protected Date date;
- protected boolean read;
- - protected String creator;
- + protected PlayerCredentials creatorCredentials;
- protected String message;
- -
- - /**
- - * Constructs an abstract class of a simple message
- - * @param id
- - * @param date
- - * @param message
- - */
- - public Message(int id, Date date, boolean read, String creator, String message) {
- +
- + public Message(int id, Date date, boolean read, PlayerCredentials creatorCredentials, String message) {
- this.id = id;
- this.date = date;
- this.read = read;
- - this.creator = creator;
- + this.creatorCredentials = creatorCredentials;
- this.message = message;
- }
- -
- +
- /**
- * Gets the ID of this message
- - * @return
- + * @return
- */
- public int getId() {
- return id;
- }
- -
- +
- /**
- * Gets this message
- - * @return
- + * @return
- */
- public String getMessage() {
- return message;
- }
- -
- +
- /**
- * Gets the date this message was created
- - * @return
- + * @return
- */
- public Date getDate() {
- return date;
- }
- -
- +
- /**
- * Sets whether or not this message has been read
- - * @param read
- + * @param read
- */
- public void setRead(Boolean read) {
- this.read = read;
- }
- -
- +
- /**
- * Gets whether or not this message has been read
- * @return
- @@ -67,20 +62,24 @@ public abstract class Message {
- public boolean hasRead() {
- return read;
- }
- -
- +
- + public PlayerCredentials getCreatorCredentials() {
- + return creatorCredentials;
- + }
- +
- /**
- * Gets the creator of the message
- - * @return
- + * @return
- */
- public String getCreator() {
- - return creator;
- + return creatorCredentials.getName();
- }
- -
- +
- /**
- * Saves this message
- */
- public abstract void save();
- -
- +
- /**
- * Deletes this message
- */
- diff --git a/src/net/innectis/innplugin/InnectisObjects/ModifiablePermissions.java b/src/net/innectis/innplugin/InnectisObjects/ModifiablePermissions.java
- index 97239450b..3d65fb988 100644
- --- a/src/net/innectis/innplugin/InnectisObjects/ModifiablePermissions.java
- +++ b/src/net/innectis/innplugin/InnectisObjects/ModifiablePermissions.java
- @@ -10,6 +10,7 @@ import java.util.Map;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.Handlers.ModifiablePermissionsHandler.PermissionType;
- import net.innectis.innplugin.InnPlugin;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- /**
- * Class that manages additional / disabled permissions for a player
- @@ -17,8 +18,8 @@ import net.innectis.innplugin.InnPlugin;
- * @author AlphaBlend
- */
- public class ModifiablePermissions {
- - // The username these permissions apply to
- - private String username;
- + // The player credentials these permissions apply to
- + private PlayerCredentials credentials;
- // A map that associates a permission with its type
- private Map<Integer, PermissionType> permissions = new HashMap<Integer, PermissionType>();
- @@ -27,8 +28,16 @@ public class ModifiablePermissions {
- * Constructs a new modifiable permissions object with just the username
- * they are associated with
- */
- - public ModifiablePermissions(String username) {
- - this.username = username;
- + public ModifiablePermissions(PlayerCredentials credentials) {
- + this.credentials = credentials;
- + }
- +
- + /**
- + * Gets the credentials of the player these modified permissions belong to
- + * @return
- + */
- + public PlayerCredentials getCredentials() {
- + return credentials;
- }
- /**
- @@ -36,16 +45,16 @@ public class ModifiablePermissions {
- * @return
- */
- public String getUsername() {
- - return username;
- + return credentials.getName();
- }
- /**
- * Constructs a modifiable permissions object with existing permissions
- - * @param username
- + * @param credentials
- * @param permissions
- */
- - public ModifiablePermissions(String username, Map<Integer, PermissionType> permissions) {
- - this.username = username;
- + public ModifiablePermissions(PlayerCredentials credentials, Map<Integer, PermissionType> permissions) {
- + this.credentials = credentials;
- this.permissions = permissions;
- }
- @@ -136,8 +145,8 @@ public class ModifiablePermissions {
- PreparedStatement statement = null;
- try {
- - statement = DBManager.prepareStatement("INSERT INTO player_permission VALUES (?, ?, ?)");
- - statement.setString(1, username);
- + statement = DBManager.prepareStatement("INSERT INTO player_permission (player_id, permissionid, disabled) VALUES (?, ?, ?)");
- + statement.setString(1, credentials.getUniqueId().toString());
- statement.setInt(2, id);
- statement.setBoolean(3, type == PermissionType.DISABLED);
- statement.execute();
- @@ -156,8 +165,8 @@ public class ModifiablePermissions {
- PreparedStatement statement = null;
- try {
- - statement = DBManager.prepareStatement("DELETE FROM player_permission WHERE lower(name) = ? AND permissionid = ?");
- - statement.setString(1, username.toLowerCase());
- + statement = DBManager.prepareStatement("DELETE FROM player_permission WHERE player_id = ? AND permissionid = ?");
- + statement.setString(1, credentials.getUniqueId().toString());
- statement.setInt(2, id);
- statement.execute();
- } catch (SQLException ex) {
- diff --git a/src/net/innectis/innplugin/InnectisObjects/PresentContent.java b/src/net/innectis/innplugin/InnectisObjects/PresentContent.java
- index 08c0b89cd..d1e36354f 100644
- --- a/src/net/innectis/innplugin/InnectisObjects/PresentContent.java
- +++ b/src/net/innectis/innplugin/InnectisObjects/PresentContent.java
- @@ -3,12 +3,15 @@ package net.innectis.innplugin.InnectisObjects;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- +import java.util.UUID;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.Items.IdpItemStack;
- import net.innectis.innplugin.Items.IdpMaterial;
- import net.innectis.innplugin.Items.SpecialItemType;
- import net.innectis.innplugin.Items.StackBag;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Utility.StringUtil;
- /**
- @@ -25,8 +28,8 @@ public class PresentContent {
- public static final IdpMaterial PRESENT_MATERIAL = IdpMaterial.REDSTONE_LAMP_ON;
- //
- private int presentid;
- - /** The name of the player who created the present */
- - private String creator;
- + /** The credentials of the player who created the present */
- + private PlayerCredentials creatorCredentials;
- private String title;
- private long bagid;
- private boolean opened;
- @@ -38,16 +41,16 @@ public class PresentContent {
- /**
- * Makes a new present without items
- - * @param creator
- + * @param creatorCredentials
- * @param title
- */
- - public PresentContent(String creator, String title) {
- - this(-1, creator, title, false, -1, null);
- + public PresentContent(PlayerCredentials creatorCredentials, String title) {
- + this(-1, creatorCredentials, title, false, -1, null);
- }
- - private PresentContent(int presentid, String creator, String title, boolean opened, long bagid, IdpItemStack[] items) {
- + private PresentContent(int presentid, PlayerCredentials creatorCredentials, String title, boolean opened, long bagid, IdpItemStack[] items) {
- this.presentid = presentid;
- - this.creator = creator;
- + this.creatorCredentials = creatorCredentials;
- this.title = title;
- this.opened = opened;
- this.bagid = bagid;
- @@ -62,12 +65,20 @@ public class PresentContent {
- return presentid;
- }
- + /**
- + * Gets the credentials of the creator of this present
- + * @return
- + */
- + public PlayerCredentials getCreatorCredentials() {
- + return creatorCredentials;
- + }
- +
- /**
- * The name of the player who made the present.
- * @return
- */
- public String getCreator() {
- - return creator;
- + return creatorCredentials.getName();
- }
- /**
- @@ -148,8 +159,8 @@ public class PresentContent {
- bag.save();
- this.bagid = bag.getBagid();
- - statement = DBManager.prepareStatementWithAutoGeneratedKeys(" INSERT INTO presents (creator, title, bagid) VALUES (?,?,?) ");
- - statement.setString(1, creator);
- + statement = DBManager.prepareStatementWithAutoGeneratedKeys(" INSERT INTO presents (creator_id, title, bagid) VALUES (?,?,?) ");
- + statement.setString(1, creatorCredentials.getUniqueId().toString());
- statement.setString(2, title);
- statement.setLong(3, bag.getBagid());
- statement.executeUpdate();
- @@ -202,24 +213,32 @@ public class PresentContent {
- ResultSet set = null;
- try {
- - statement = DBManager.prepareStatement(" SELECT creator, title, bagid, opened FROM presents WHERE presentid = ? ");
- + statement = DBManager.prepareStatement(" SELECT creator_id, title, bagid, opened FROM presents WHERE presentid = ? ");
- statement.setInt(1, presentid);
- set = statement.executeQuery();
- long bagid = 0;
- - String creator = "";
- + String creatorIdString = "";
- + UUID creatorId = null;
- + PlayerCredentials creatorCredentials = null;
- String title = "";
- boolean opened = false;
- +
- if (set.next()) {
- bagid = set.getLong("bagid");
- - creator = set.getString("creator");
- +
- + creatorIdString = set.getString("creator_id");
- + creatorId = UUID.fromString(creatorIdString);
- + creatorCredentials = PlayerCredentialsManager.getByUniqueId(creatorId);
- +
- title = set.getString("title");
- opened = set.getBoolean("opened");
- }
- +
- if (bagid > 0) {
- StackBag bag = StackBag.getContentbag(bagid);
- - return new PresentContent(presentid, creator, title, opened, bagid, bag.getContents());
- + return new PresentContent(presentid, creatorCredentials, title, opened, bagid, bag.getContents());
- }
- } catch (SQLException ex) {
- InnPlugin.logError("Error loading present!", ex);
- @@ -242,7 +261,6 @@ public class PresentContent {
- }
- if (item.getItemdata().getSpecialItem() == SpecialItemType.PRESENT) {
- -
- String presentid = item.getItemdata().getValue(PresentContent.PRESENT_TAG);
- if (StringUtil.stringIsNullOrEmpty(presentid)) {
- @@ -256,6 +274,7 @@ public class PresentContent {
- return null;
- }
- }
- +
- return null;
- }
- diff --git a/src/net/innectis/innplugin/InnectisObjects/StaffMessage.java b/src/net/innectis/innplugin/InnectisObjects/StaffMessage.java
- index 976e7a6cb..772e0e94c 100644
- --- a/src/net/innectis/innplugin/InnectisObjects/StaffMessage.java
- +++ b/src/net/innectis/innplugin/InnectisObjects/StaffMessage.java
- @@ -6,6 +6,7 @@ import java.sql.SQLException;
- import java.util.Date;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- /**
- * A simple message for staff members to read
- @@ -16,20 +17,23 @@ public class StaffMessage extends Message {
- /**
- * Constructs a new staff message (no ID present)
- * @param date
- + * @param creatorCredentials
- * @param message
- */
- - public StaffMessage(Date date, String creator, String message) {
- - this(0, date, false, creator, message);
- + public StaffMessage(Date date, PlayerCredentials creatorCredentials, String message) {
- + this(0, date, false, creatorCredentials, message);
- }
- /**
- * Constructs a staff message from the given parameters
- * @param id
- * @param date
- + * @param read
- + * @param creatorCredentials
- * @param message
- */
- - public StaffMessage(int id, Date date, boolean read, String creator, String message) {
- - super(id, date, read, creator, message);
- + public StaffMessage(int id, Date date, boolean read, PlayerCredentials creatorCredentials, String message) {
- + super(id, date, read, creatorCredentials, message);
- }
- /**
- @@ -47,10 +51,10 @@ public class StaffMessage extends Message {
- statement.setInt(2, id);
- statement.executeUpdate();
- } else {
- - statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO staff_requests (datecreated, hasread, creator, message) VALUES (?, ?, ?, ?)");
- + statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO staff_requests (datecreated, hasread, creator_player_id, message) VALUES (?, ?, ?, ?)");
- statement.setDate(1, new java.sql.Date(date.getTime()));
- statement.setBoolean(2, read);
- - statement.setString(3, creator);
- + statement.setString(3, super.getCreatorCredentials().getUniqueId().toString());
- statement.setString(4, message);
- statement.execute();
- diff --git a/src/net/innectis/innplugin/InnectisObjects/TheEndPot.java b/src/net/innectis/innplugin/InnectisObjects/TheEndPot.java
- index 101af6f92..fa5772055 100644
- --- a/src/net/innectis/innplugin/InnectisObjects/TheEndPot.java
- +++ b/src/net/innectis/innplugin/InnectisObjects/TheEndPot.java
- @@ -4,6 +4,7 @@ import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.HashMap;
- +import java.util.UUID;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- @@ -15,28 +16,30 @@ import net.innectis.innplugin.InnPlugin;
- * @author AlphaBlend
- */
- public class TheEndPot {
- - private static HashMap<String, Integer> valutaPot = new HashMap<String, Integer>();
- + private static HashMap<UUID, Integer> valutaPot = new HashMap<UUID, Integer>();
- /**
- - * Adds a value to the pot by the specified player
- - * @param player
- + * Adds a value to the pot by the specified player represented by their ID
- + * @param playerId
- + * @param playerName
- * @param amount
- + * @return
- */
- - public static boolean addValue(String player, int amount) {
- + public static boolean addValue(UUID playerId, String playerName, int amount) {
- int total = amount;
- boolean update = false;
- - if (valutaPot.containsKey(player.toLowerCase())) {
- - total += valutaPot.get(player.toLowerCase());
- + if (valutaPot.containsKey(playerId)) {
- + total += valutaPot.get(playerId);
- update = true;
- }
- - boolean result = addValueToDatabase(player, amount, update);
- + boolean result = addValueToDatabase(playerId, playerName, amount, update);
- // Make sure there are no errors adding to the database, then add
- // to the map if the operation is successful
- if (result) {
- - valutaPot.put(player.toLowerCase(), total);
- + valutaPot.put(playerId, total);
- }
- return result;
- @@ -44,14 +47,14 @@ public class TheEndPot {
- /**
- * Gets the value of the pot contributed from the specified player
- - * @param player
- + * @param playerId
- * @return
- */
- - public int getValue(String player) {
- + public int getValue(UUID playerId) {
- int value = 0;
- - if (valutaPot.containsKey(player.toLowerCase())) {
- - value = valutaPot.get(player.toLowerCase());
- + if (valutaPot.containsKey(playerId)) {
- + value = valutaPot.get(playerId);
- }
- return value;
- @@ -106,9 +109,10 @@ public class TheEndPot {
- set = statement.executeQuery();
- while (set.next()) {
- - String player = set.getString("player");
- + String playerIdString = set.getString("player_id");
- + UUID playerId = UUID.fromString(playerIdString);
- int amount = set.getInt("value");
- - valutaPot.put(player, amount);
- + valutaPot.put(playerId, amount);
- }
- } catch (SQLException ex) {
- InnPlugin.logError("Could not load The End pot!", ex);
- @@ -120,27 +124,27 @@ public class TheEndPot {
- /**
- * Adds the specified player's valuta value to the database
- - * @param player
- + * @param playerId
- * @param value
- * @param update
- */
- - private static boolean addValueToDatabase(String player, int value, boolean update) {
- + private static boolean addValueToDatabase(UUID playerId, String playerName, int value, boolean update) {
- PreparedStatement statement = null;
- try {
- if (update) {
- - statement = DBManager.prepareStatement("UPDATE the_end_pot SET value = value + ? WHERE lower(player) = ?;");
- + statement = DBManager.prepareStatement("UPDATE the_end_pot SET value = value + ? WHERE player_id = ?;");
- statement.setInt(1, value);
- - statement.setString(2, player.toLowerCase());
- + statement.setString(2, playerId.toString());
- statement.executeUpdate();
- } else {
- - statement = DBManager.prepareStatement("INSERT INTO the_end_pot VALUES (?, ?);");
- - statement.setString(1, player.toLowerCase());
- + statement = DBManager.prepareStatement("INSERT INTO the_end_pot (player_id, value) VALUES (?, ?);");
- + statement.setString(1, playerId.toString());
- statement.setInt(2, value);
- statement.execute();
- }
- } catch (SQLException ex) {
- - InnPlugin.logError("Unable to update The End pot value for " + player + "!", ex);
- + InnPlugin.logError("Unable to update The End pot value for player " + playerName + "!", ex);
- return false;
- } finally {
- DBManager.closePreparedStatement(statement);
- diff --git a/src/net/innectis/innplugin/InnectisObjects/TransactionObject.java b/src/net/innectis/innplugin/InnectisObjects/TransactionObject.java
- index 22a190fee..b801cccf0 100644
- --- a/src/net/innectis/innplugin/InnectisObjects/TransactionObject.java
- +++ b/src/net/innectis/innplugin/InnectisObjects/TransactionObject.java
- @@ -2,6 +2,7 @@ package net.innectis.innplugin.InnectisObjects;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- +import java.util.UUID;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.Handlers.TransactionHandler.TransactionType;
- import net.innectis.innplugin.InnPlugin;
- @@ -12,8 +13,8 @@ import net.innectis.innplugin.InnPlugin;
- * @author AlphaBlend
- */
- public class TransactionObject {
- -
- - private String player;
- + private UUID playerId;
- + private String playerName;
- private int valutas;
- private int valutasInBank;
- private int valutasToBank;
- @@ -22,8 +23,9 @@ public class TransactionObject {
- private int referralPoints;
- private int votePoints;
- - public TransactionObject(String player, int valutas, int valutasInBank, int valutasToBank, int valutasToPlayer, int pvpPoints, int referPoints, int votePoints) {
- - this.player = player;
- + public TransactionObject(UUID playerId, String playerName, int valutas, int valutasInBank, int valutasToBank, int valutasToPlayer, int pvpPoints, int referPoints, int votePoints) {
- + this.playerId = playerId;
- + this.playerName = playerName;
- this.valutas = valutas;
- this.valutasInBank = valutasInBank;
- this.valutasToBank = valutasToBank;
- @@ -120,8 +122,7 @@ public class TransactionObject {
- * This immediately updates to the database, so no need to do it manually
- *
- * @param value a value greater than zero
- - * @param currency
- - * @return
- + * @param tt
- */
- public void subtractValue(int value, TransactionType tt) {
- int targetValue;
- @@ -167,8 +168,7 @@ public class TransactionObject {
- * This immediately updates to the database, so no need to do it manually
- *
- * @param value a value greater than zero
- - * @param transaction
- - * @return
- + * @param tt
- */
- public void setValue(int value, TransactionType tt) {
- switch (tt) {
- @@ -204,7 +204,7 @@ public class TransactionObject {
- * Updates the value of the specified transaction type to the database
- *
- * @param value
- - * @param currency
- + * @param tt
- */
- private void updateDatabase(Number value, TransactionType tt) {
- PreparedStatement statement = null;
- @@ -238,12 +238,12 @@ public class TransactionObject {
- throw new IllegalStateException("TransactionType " + tt + " not supported");
- }
- - statement = DBManager.prepareStatement("UPDATE players SET " + columnName + " = ? WHERE lower(name) = ?");
- + statement = DBManager.prepareStatement("UPDATE players SET " + columnName + " = ? WHERE player_id = ?");
- statement.setInt(1, value.intValue());
- - statement.setString(2, player.toLowerCase());
- + statement.setString(2, playerId.toString());
- statement.execute();
- } catch (SQLException ex) {
- - InnPlugin.logError("Unable to update " + tt.getName() + "!", ex);
- + InnPlugin.logError("Unable to update " + tt.getName() + " in database for player " + playerName + "!", ex);
- } finally {
- DBManager.closePreparedStatement(statement);
- }
- diff --git a/src/net/innectis/innplugin/Listeners/Bukkit/BukkitEntityListner.java b/src/net/innectis/innplugin/Listeners/Bukkit/BukkitEntityListner.java
- index e30d9c523..eb5e11f00 100644
- --- a/src/net/innectis/innplugin/Listeners/Bukkit/BukkitEntityListner.java
- +++ b/src/net/innectis/innplugin/Listeners/Bukkit/BukkitEntityListner.java
- @@ -40,12 +40,15 @@ import net.innectis.innplugin.Player.IdpPlayerInventory;
- import net.innectis.innplugin.Player.InventoryType;
- import net.innectis.innplugin.Player.Permission;
- import net.innectis.innplugin.Player.PlayerBackpack;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Player.PlayerGroup;
- import net.innectis.innplugin.Player.PlayerSession;
- import net.innectis.innplugin.Player.PlayerSession.PlayerStatus;
- import net.innectis.innplugin.Player.PlayerSettings;
- import net.innectis.innplugin.Tasking.SyncTasks.TheEndUnloadTask;
- import net.innectis.innplugin.Utility.StringUtil;
- +import org.bukkit.Bukkit;
- import org.bukkit.DyeColor;
- import org.bukkit.Location;
- import org.bukkit.Material;
- @@ -220,6 +223,7 @@ public class BukkitEntityListner implements InnBukkitListener {
- location.setY(location.getWorld().getHighestBlockYAt(location) + 2);
- player.teleport(location);
- + Bukkit.broadcastMessage("Teleporting to somewhere in main world!");
- }
- } else {
- if (event.getEntityType() == EntityType.DROPPED_ITEM) {
- @@ -440,7 +444,7 @@ public class BukkitEntityListner implements InnBukkitListener {
- if (getId > 0) {
- InnectisWaypoint waypoint = WaypointHandler.getWaypoint(getId);
- - if (waypoint != null && (waypoint.canPlayerAccess(player)
- + if (waypoint != null && (waypoint.canPlayerAccess(player.getName())
- || player.hasPermission(Permission.owned_object_override))) {
- loc = waypoint.getDestination();
- }
- @@ -966,7 +970,7 @@ public class BukkitEntityListner implements InnBukkitListener {
- }
- if (dropValutas) {
- - TransactionObject transaction = TransactionHandler.getTransactionObject(player.getName());
- + TransactionObject transaction = TransactionHandler.getTransactionObject(player.getUniqueId(), player.getName());
- int valutas = transaction.getValue(TransactionType.VALUTAS);
- if (valutas > 0) {
- @@ -1003,7 +1007,7 @@ public class BukkitEntityListner implements InnBukkitListener {
- // Set inventory and save
- try {
- - IdpPlayerInventory inv = new IdpPlayerInventory(player.getName(), player.getInventory().getType(), items,
- + IdpPlayerInventory inv = new IdpPlayerInventory(player.getUniqueId(), player.getName(), player.getInventory().getType(), items,
- IdpItemStack.fromBukkitItemStack(player.getInventory().getBukkitArmorItems()),
- bukkitPlayer.getExp(),
- bukkitPlayer.getLevel(), -1, player.getFoodLevel());
- @@ -1016,7 +1020,8 @@ public class BukkitEntityListner implements InnBukkitListener {
- // If Hardcore is set, lets ban the player
- if (lot != null && lot.isFlagSet(LotFlagType.HARDCORE)) {
- - lot.banUser(player.getName());
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName(), true);
- + lot.banUser(credentials);
- }
- // Update player status
- @@ -1187,7 +1192,7 @@ public class BukkitEntityListner implements InnBukkitListener {
- // not have the nodamage flag
- if (lot == null || !lot.isFlagSet(LotFlagType.NODAMAGE)) {
- int pts = getPointTakenByGroup(player.getGroup());
- - TransactionObject transaction = TransactionHandler.getTransactionObject(player.getName());
- + TransactionObject transaction = TransactionHandler.getTransactionObject(player.getUniqueId(), player.getName());
- int votepts = transaction.getValue(TransactionType.VOTE_POINTS);
- if (votepts >= pts) {
- diff --git a/src/net/innectis/innplugin/Listeners/Bukkit/BukkitHangingListener.java b/src/net/innectis/innplugin/Listeners/Bukkit/BukkitHangingListener.java
- index a8cb840e7..f444e7415 100644
- --- a/src/net/innectis/innplugin/Listeners/Bukkit/BukkitHangingListener.java
- +++ b/src/net/innectis/innplugin/Listeners/Bukkit/BukkitHangingListener.java
- @@ -72,7 +72,7 @@ public class BukkitHangingListener implements InnBukkitListener {
- // Unrestrict reszone
- IdpWorld world = IdpWorldFactory.getWorld(loc.getWorld().getName());
- if (world.getActingWorldType() == IdpWorldType.RESWORLD
- - && (lot == null || lot.canPlayerAccess(player) || player.hasPermission(Permission.world_build_unrestricted))) {
- + && (lot == null || lot.canPlayerAccess(player.getName()) || player.hasPermission(Permission.world_build_unrestricted))) {
- return;
- }
- @@ -131,7 +131,7 @@ public class BukkitHangingListener implements InnBukkitListener {
- }
- }
- - LogManager.getBlockLogger().logEntityAction(player.getName(), event.getEntity(), BlockLogger.BlockAction.ENTITY_BREAK);
- + LogManager.getBlockLogger().logEntityAction(player.getUniqueId(), event.getEntity(), BlockLogger.BlockAction.ENTITY_BREAK);
- return;
- }
- }
- @@ -157,7 +157,7 @@ public class BukkitHangingListener implements InnBukkitListener {
- IdpWorld world = IdpWorldFactory.getWorld(loc.getWorld().getName());
- if (world.getActingWorldType() == IdpWorldType.RESWORLD
- - && (lot == null || lot.canPlayerAccess(player) || player.hasPermission(Permission.world_build_unrestricted))) {
- + && (lot == null || lot.canPlayerAccess(player.getName()) || player.hasPermission(Permission.world_build_unrestricted))) {
- return;
- }
- @@ -181,6 +181,6 @@ public class BukkitHangingListener implements InnBukkitListener {
- event.setCancelled(true);
- return;
- }
- - LogManager.getBlockLogger().logEntityAction(player.getName(), event.getEntity(), BlockLogger.BlockAction.ENTITY_PLACE);
- + LogManager.getBlockLogger().logEntityAction(player.getUniqueId(), event.getEntity(), BlockLogger.BlockAction.ENTITY_PLACE);
- }
- }
- diff --git a/src/net/innectis/innplugin/Listeners/Bukkit/BukkitInventoryListener.java b/src/net/innectis/innplugin/Listeners/Bukkit/BukkitInventoryListener.java
- index fd523d826..e871cd225 100644
- --- a/src/net/innectis/innplugin/Listeners/Bukkit/BukkitInventoryListener.java
- +++ b/src/net/innectis/innplugin/Listeners/Bukkit/BukkitInventoryListener.java
- @@ -4,6 +4,7 @@ import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- import java.util.Map.Entry;
- +import java.util.UUID;
- import net.innectis.innplugin.Handlers.TransactionHandler;
- import net.innectis.innplugin.Handlers.TransactionHandler.TransactionType;
- import net.innectis.innplugin.InnPlugin;
- @@ -37,6 +38,8 @@ import net.innectis.innplugin.Player.IdpPlayerInventory;
- import net.innectis.innplugin.Player.InventoryType;
- import net.innectis.innplugin.Player.Permission;
- import net.innectis.innplugin.Player.PlayerBackpack;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Player.PlayerSession;
- import net.innectis.innplugin.Player.PlayerSession.PlayerStatus;
- import net.innectis.innplugin.Shop.ShopHandler;
- @@ -191,7 +194,9 @@ public final class BukkitInventoryListener implements InnBukkitListener {
- if (player != null) {
- session = player.getSession();
- } else {
- - session = PlayerSession.getSession(ownedEntity.getOwner(), plugin);
- + PlayerCredentials credentials = ownedEntity.getOwnerCredentials();
- +
- + session = PlayerSession.getSession(credentials.getUniqueId(), credentials.getName(), plugin, true);
- tempSession = true;
- }
- @@ -254,7 +259,8 @@ public final class BukkitInventoryListener implements InnBukkitListener {
- if (testPlayer != null) {
- session = testPlayer.getSession();
- } else {
- - session = PlayerSession.getSession(ownedEntity.getOwner(), plugin);
- + PlayerCredentials credentials = ownedEntity.getOwnerCredentials();
- + session = PlayerSession.getSession(credentials.getUniqueId(), credentials.getName(), plugin, true);
- tempSession = true;
- }
- @@ -434,7 +440,7 @@ public final class BukkitInventoryListener implements InnBukkitListener {
- if (!error && rawSlot < 54 && event.isLeftClick()) {
- RewardItem reward = RewardItem.fromSlot(rawSlot);
- if (reward != null) {
- - TransactionObject transaction = TransactionHandler.getTransactionObject(player.getName());
- + TransactionObject transaction = TransactionHandler.getTransactionObject(player.getUniqueId(), player.getName());
- int votePoints = transaction.getValue(TransactionType.VOTE_POINTS);
- if (votePoints >= reward.getCost()) {
- @@ -628,8 +634,9 @@ public final class BukkitInventoryListener implements InnBukkitListener {
- }
- if (session.isViewingBackpack()) {
- + UUID backpackOwnerId = session.getBackpackOwnerId();
- String backpackOwner = session.getBackpackOwner();
- - boolean self = backpackOwner.equalsIgnoreCase(player.getName());
- + boolean self = backpackOwnerId.equals(player.getUniqueId());
- ItemStack[] stack = event.getInventory().getContents();
- IdpItemStack[] newStack = new IdpItemStack[stack.length];
- @@ -643,19 +650,19 @@ public final class BukkitInventoryListener implements InnBukkitListener {
- if (self) {
- backpack = session.getBackpack();
- } else {
- - IdpPlayer testPlayer = plugin.getPlayer(backpackOwner);
- + IdpPlayer testPlayer = plugin.getPlayer(backpackOwnerId);
- if (testPlayer != null) {
- backpack = testPlayer.getSession().getBackpack();
- } else {
- - backpack = PlayerBackpack.loadBackpackFromDB(backpackOwner);
- + backpack = PlayerBackpack.loadBackpackFromDB(backpackOwnerId, backpackOwner);
- }
- }
- backpack.setItems(newStack);
- backpack.save();
- - IdpInventory inv = plugin.getBackpackView(backpackOwner);
- + IdpInventory inv = plugin.getBackpackView(backpackOwnerId);
- if (inv == null) {
- player.printError("Internal server error.");
- @@ -666,7 +673,7 @@ public final class BukkitInventoryListener implements InnBukkitListener {
- inv.getViewers().remove(event.getPlayer());
- if (inv.getViewers().isEmpty()) {
- - plugin.removeBackpackView(backpackOwner);
- + plugin.removeBackpackView(backpackOwnerId);
- }
- session.clearBackpackOwner();
- @@ -677,9 +684,11 @@ public final class BukkitInventoryListener implements InnBukkitListener {
- session.setViewingEnderChest(false);
- String name = session.getEnderchestOwner();
- + UUID ownerId = session.getEnderchestOwnerId();
- EnderContentsType type = session.getEnderchestType();
- session.setEnderchestOwner(null);
- + session.setEnderchestOwnerId(null);
- session.setEnderchestType(null);
- IdpItemStack[] items = new IdpItemStack[27];
- @@ -693,7 +702,8 @@ public final class BukkitInventoryListener implements InnBukkitListener {
- }
- // If no one is viewing this ender chest, remove it from our list
- - EnderChestView view = plugin.getEnderChestView(name, type);
- + EnderChestView view = plugin.getEnderChestView(ownerId, type);
- +
- if (view == null) {
- StrangeErrorLogger serrorLogger = LogManager.getStrangeErrorLogger();
- @@ -713,7 +723,8 @@ public final class BukkitInventoryListener implements InnBukkitListener {
- }
- // Get the chestobject
- - EnderChestContents contents = EnderChestContents.getContents(name, type);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(ownerId);
- + EnderChestContents contents = EnderChestContents.getContents(credentials, type);
- if (contents != null) {
- // Set the new items and update
- @@ -787,11 +798,12 @@ public final class BukkitInventoryListener implements InnBukkitListener {
- if (session.isViewingOtherInventory()) {
- IdpContainer container = new IdpContainer(event.getInventory());
- + UUID inventoryOwnerId = session.getViewedInventoryOwnerId();
- String inventoryOwner = session.getViewedInventoryOwner();
- InventoryType type = session.getViewedInventoryType();
- boolean updated = false;
- - IdpPlayer testPlayer = plugin.getPlayer(inventoryOwner);
- + IdpPlayer testPlayer = plugin.getPlayer(inventoryOwnerId);
- // They came online after we were viewing their inventory
- if (testPlayer != null) {
- if (testPlayer.getSession().getPlayerStatus() == PlayerStatus.DEAD_PLAYER) {
- @@ -814,7 +826,7 @@ public final class BukkitInventoryListener implements InnBukkitListener {
- // If the inventory hasn't yet been updated, let's save it
- if (!updated && type != InventoryType.NO_SAVE) {
- - IdpPlayerInventory inv = IdpPlayerInventory.load(inventoryOwner, type, plugin);
- + IdpPlayerInventory inv = IdpPlayerInventory.load(inventoryOwnerId, inventoryOwner, type, plugin);
- inv.setItems(container.getNonArmorItems());
- inv.setArmorItems(container.getArmorItems());
- inv.store();
- diff --git a/src/net/innectis/innplugin/Listeners/Bukkit/BukkitPlayerActionListener.java b/src/net/innectis/innplugin/Listeners/Bukkit/BukkitPlayerActionListener.java
- index 28ee1bbec..dd10dc117 100644
- --- a/src/net/innectis/innplugin/Listeners/Bukkit/BukkitPlayerActionListener.java
- +++ b/src/net/innectis/innplugin/Listeners/Bukkit/BukkitPlayerActionListener.java
- @@ -39,7 +39,6 @@ import net.innectis.innplugin.Player.PlayerSession.PlayerStatus;
- import net.innectis.innplugin.Tasking.LimitedTask;
- import net.innectis.innplugin.Tasking.RunBehaviour;
- import net.innectis.innplugin.Utility.DateUtil;
- -import net.innectis.innplugin.Utility.NumberUtil;
- import net.innectis.innplugin.Utility.StringUtil;
- import org.bukkit.GameMode;
- import org.bukkit.Location;
- @@ -89,13 +88,13 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
- // are allowed to light up blocks
- Location locBelow = player.getLocation().subtract(0, 1, 0);
- if (player.hasLightSourceConditions(locBelow, stack)) {
- - if (!LightsourceHandler.isLightingBlock(player.getName())) {
- - LightsourceHandler.lightBlock(player.getName(), locBelow);
- + if (!LightsourceHandler.isLightingBlock(player.getUniqueId())) {
- + LightsourceHandler.lightBlock(player.getUniqueId(), locBelow);
- }
- } else {
- // Turn their light off if they're currently lighting a block
- - if (LightsourceHandler.isLightingBlock(player.getName())) {
- - LightsourceHandler.unlightBlock(player.getName());
- + if (LightsourceHandler.isLightingBlock(player.getUniqueId())) {
- + LightsourceHandler.unlightBlock(player.getUniqueId());
- }
- }
- }
- @@ -217,7 +216,7 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
- if (!event.getItem().hasMetadata(EntityConstants.METAKEY_DROPPED_ITEM)) {
- //only lot members can pick up
- if (itemLot != null && !itemLot.isFlagSet(LotFlagType.ITEMPICKUP)
- - && !playerLot.canPlayerAccess(player)
- + && !playerLot.canPlayerAccess(player.getName())
- && !player.hasPermission(Permission.lot_ignoreflag_itempickup)) {
- event.setCancelled(true);
- }
- @@ -234,7 +233,7 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
- if (vorb != null) {
- int value = vorb.getAmount();
- - TransactionObject transaction = TransactionHandler.getTransactionObject(player.getName());
- + TransactionObject transaction = TransactionHandler.getTransactionObject(player.getUniqueId(), player.getName());
- transaction.addValue(value, TransactionType.VALUTAS);
- player.printInfo("You have picked up " + value + " valuta" + (value != 1 ? "s" : "") + "!");
- }
- @@ -579,7 +578,7 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
- int z = locTo.getBlockZ();
- Location newLoc = new Location(bworld, x, y - 1, z);
- - LightsourceHandler.lightBlock(player.getName(), newLoc);
- + LightsourceHandler.lightBlock(player.getUniqueId(), newLoc);
- }
- }
- @@ -816,19 +815,35 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
- @EventHandler(priority = EventPriority.HIGH)
- public void onPlayerPreLogin(AsyncPlayerPreLoginEvent event) {
- String ipAddress = event.getAddress().getHostAddress();
- - String username = event.getName();
- - PlayerGroup group = PlayerGroup.getGroupOfUsername(username);
- - String coloredName = group.getPrefix().getTextColor() + username;
- -
- + UUID playerId = event.getUniqueId();
- + String playerName = event.getName();
- + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(playerId);
- + String coloredName = group.getPrefix().getTextColor() + playerName;
- IdpPlayer testPlayer = null;
- - if ((testPlayer = plugin.getPlayer(username, true)) != null) { //player is online!
- + PlayerCredentials testCredentials = PlayerCredentialsManager.getByUniqueId(playerId);
- +
- + // This player renamed themselves, so let's update their credentials
- + // If they are new, don't do anything, as they have no credentials yet
- + if (testCredentials != null && !playerName.equalsIgnoreCase(testCredentials.getName())) {
- + String oldColoredName = group.getPrefix().getTextColor() + testCredentials.getName();
- +
- + plugin.broadCastMessage(ChatColor.DARK_AQUA, "NOTICE: " + coloredName
- + + ChatColor.DARK_AQUA + " has renamed themselves from " + oldColoredName
- + + ChatColor.DARK_AQUA + ".");
- +
- + testCredentials.setName(playerName);
- + testCredentials.update();
- + // TODO: Log name changes
- + }
- +
- + if ((testPlayer = plugin.getPlayer(playerId)) != null) { //player is online!
- // If IP is the same, kick right away. Else kick if AFK
- if (testPlayer.getSession().isAFK() || testPlayer.getHandle().getAddress().getAddress().getHostAddress().equals(ipAddress)) {
- testPlayer.getHandle().kickPlayer("You logged in from another location!");
- try {
- // Get the playerfile and try to delete it
- - File playerfile = new File(IdpWorldFactory.getWorld(IdpWorldType.INNECTIS).getHandle().getWorldFolder() + File.separator + "players" + File.separator + username + ".dat");
- + File playerfile = new File(IdpWorldFactory.getWorld(IdpWorldType.INNECTIS).getHandle().getWorldFolder() + File.separator + "playerdata" + File.separator + playerId.toString() + ".dat");
- if (playerfile.exists()) {
- InnPlugin.logError("Deleting playerfile of '" + testPlayer.getName() + "' due to double login.");
- playerfile.delete();
- @@ -845,9 +860,12 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
- return;
- }
- + // Skip login check if the player is new (has no credentials)
- + boolean skipLoginCheck = (testCredentials == null);
- - if (!PlayerSecurity.canLogin(username)) {
- - event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_FULL, "Your entered your password wrong too many times...");
- + // Only check if valid credentials (player might be new)
- + if (!skipLoginCheck && !PlayerSecurity.canLogin(playerId, playerName)) {
- + event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_FULL, "You entered your password wrong too many times...");
- return;
- }
- @@ -858,15 +876,15 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
- }
- Timestamp stamp = new Timestamp(System.currentTimeMillis());
- - IPLogger.logConnection(username, ipAddress, stamp);
- + IPLogger.logConnection(playerId, playerName, ipAddress, stamp);
- - BanTypes bannedType = BanHandler.getBanType(username, ipAddress);
- + BanTypes bannedType = BanHandler.getBanType(playerId, ipAddress);
- if (bannedType == BanTypes.NONE) {
- return;
- }
- - BanObject ban = BanHandler.getBan(username);
- + BanObject ban = BanHandler.getBan(playerId);
- boolean isIPBan = ban != null && (ban instanceof IPBanObject);
- switch (bannedType) {
- @@ -896,15 +914,17 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
- IPBanGroup ipGroup = BanHandler.getIPBanGroup(ipAddress);
- StringBuilder sb = new StringBuilder();
- - for (String player : ipGroup.getPlayers()) {
- - PlayerGroup playerGroup = PlayerGroup.getGroupOfUsername(player);
- - sb.append(playerGroup.getPrefix().getTextColor()).append(player).append(ChatColor.YELLOW).append(", ");
- + for (PlayerCredentials pc : ipGroup.getPlayers()) {
- + PlayerGroup playerGroup = PlayerGroup.getGroupOfPlayerById(pc.getUniqueId());
- + sb.append(playerGroup.getPrefix().getTextColor()).append(pc.getName()).append(ChatColor.YELLOW).append(", ");
- }
- - String finalString = username + " shares an IP with the following IPBanned players: " + sb.toString().substring(0, sb.length() - 2);
- +
- + String finalString = playerName + " shares an IP with the following IPBanned players: " + sb.toString().substring(0, sb.length() - 2);
- for (IdpPlayer p : plugin.getOnlineStaff(false)) {
- p.printError("NOTICE: " + finalString);
- }
- +
- InnPlugin.logInfo(ChatColor.RED + "NOTICE: " + finalString);
- break;
- @@ -1134,7 +1154,7 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
- }
- // Check if the player needs to login
- - if (PlayerSecurity.hasPassword(innPlayer.getName())) {
- + if (PlayerSecurity.hasPassword(innPlayer.getUniqueId(), innPlayer.getName())) {
- session.setPlayerLoggedin(false);
- }
- @@ -1168,7 +1188,6 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
- * Simple task that will check the security status of a player after 5ms.
- */
- private class CheckPlayerTask extends LimitedTask {
- -
- private IdpPlayer player;
- public CheckPlayerTask(IdpPlayer player) {
- @@ -1409,14 +1428,14 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
- if (player.getHandle().getVehicle() != null) {
- // If the player is in a vehicle while logging out, make sure to eject
- // them if they are in a lot they do not own or operate, to prevent taking a vehicle
- - if (lot != null && !(lot.canPlayerManage(player)
- + if (lot != null && !(lot.canPlayerManage(player.getName())
- || player.hasPermission(Permission.world_build_unrestricted))) {
- player.getHandle().leaveVehicle();
- }
- }
- if (lot != null && lot.isFlagSet(LotFlagType.NOMEMBERLOGOUTSPAWN)
- - && !lot.canPlayerAccessIgnoreGeneric(player)
- + && !lot.canPlayerAccessIgnoreGeneric(player.getName())
- && !player.hasPermission(Permission.lot_ignoreflag_nomemberlogoutspawn)) {
- player.teleport(WarpHandler.getSpawn());
- }
- @@ -1493,12 +1512,12 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
- }
- public static void handlePlayerLogout(IdpPlayer player) {
- - if (LightsourceHandler.isLightingBlock(player.getName())) {
- - LightsourceHandler.unlightBlock(player.getName());
- + if (LightsourceHandler.isLightingBlock(player.getUniqueId())) {
- + LightsourceHandler.unlightBlock(player.getUniqueId());
- }
- // Remove this from the cache, as it's no longer really needed unless requested
- - TransactionHandler.removeTransactionObjectFromCache(player.getName());
- + TransactionHandler.removeTransactionObjectFromCache(player.getUniqueId());
- if (ChatChannelHandler.isGlobalListener(player.getName())) {
- ChatChannelHandler.removeGlobalListener(player.getName());
- @@ -1556,7 +1575,7 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
- InnectisLot lot = LotHandler.getLot(entity.getLocation());
- if (lot != null && lot.isFlagSet(LotFlagType.FARM)
- - && !lot.canPlayerManage(player)
- + && !lot.canPlayerManage(player.getName())
- && !player.hasPermission(Permission.entity_canleadanywhere)) {
- player.printError("Cannot leash entities here!");
- event.setCancelled(true);
- @@ -1583,7 +1602,7 @@ public class BukkitPlayerActionListener implements InnBukkitListener {
- InnectisLot lot = LotHandler.getLot(entity.getLocation());
- if (lot != null && lot.isFlagSet(LotFlagType.FARM)
- - && !lot.canPlayerManage(player)
- + && !lot.canPlayerManage(player.getName())
- && !player.hasPermission(Permission.entity_canleadanywhere)) {
- player.printError("Cannot unleash entities here!");
- event.setCancelled(true);
- diff --git a/src/net/innectis/innplugin/Listeners/Bukkit/BukkitPlayerInteractionListener.java b/src/net/innectis/innplugin/Listeners/Bukkit/BukkitPlayerInteractionListener.java
- index e5a6cd743..b11f85032 100644
- --- a/src/net/innectis/innplugin/Listeners/Bukkit/BukkitPlayerInteractionListener.java
- +++ b/src/net/innectis/innplugin/Listeners/Bukkit/BukkitPlayerInteractionListener.java
- @@ -406,7 +406,7 @@ public class BukkitPlayerInteractionListener implements InnBukkitListener {
- // Prevent fire from being extinguished by anyone but lot members or owner
- if (IdpMaterial.fromBlock(block.getRelative(idpEvent.getBlockFace())) == IdpMaterial.FIRE) {
- - if (lot != null && !lot.canPlayerAccess(player)
- + if (lot != null && !lot.canPlayerAccess(player.getName())
- && !player.hasPermission(Permission.build_block_fire)) {
- event.setCancelled(true);
- return;
- @@ -683,7 +683,7 @@ public class BukkitPlayerInteractionListener implements InnBukkitListener {
- && player.getItemStackInHand().getMaterial() == IdpMaterial.FISHING_ROD) {
- InnectisLot lot = LotHandler.getLot(entity.getLocation());
- - if (lot == null || lot.canPlayerManage(player)
- + if (lot == null || lot.canPlayerManage(player.getName())
- || player.hasPermission(Permission.entity_catchentitiesoverride)) {
- String typeName = "thing";
- @@ -731,7 +731,7 @@ public class BukkitPlayerInteractionListener implements InnBukkitListener {
- InnectisLot lot = LotHandler.getLot(kickPlayer.getLocation());
- if (lot != null && !kickPlayer.getSession().isStaff()
- - && !lot.canPlayerManage(kickPlayer)) {
- + && !lot.canPlayerManage(kickPlayer.getName())) {
- kickPlayer.teleport(WarpHandler.getSpawn(kickPlayer.getGroup()));
- player.printInfo("Kicked " + kickPlayer.getName() + " to spawn!");
- return;
- @@ -889,7 +889,7 @@ public class BukkitPlayerInteractionListener implements InnBukkitListener {
- case WHEAT: {
- if (!player.hasPermission(Permission.entity_canfeedanywhere)) {
- InnectisLot lot = LotHandler.getLot(clickLocation, true);
- - boolean canFeedAnimals = (lot == null || !lot.isFlagSet(LotFlagType.FARM) ? true : lot.canPlayerAccess(player));
- + boolean canFeedAnimals = (lot == null || !lot.isFlagSet(LotFlagType.FARM) ? true : lot.canPlayerAccess(player.getName()));
- if (!canFeedAnimals) {
- player.printError("You cannot feed animals here!");
- event.setCancelled(true);
- @@ -901,7 +901,7 @@ public class BukkitPlayerInteractionListener implements InnBukkitListener {
- case NAME_TAG: {
- if (!player.hasPermission(Permission.entity_cannameanywhere)) {
- InnectisLot lot = LotHandler.getLot(clickLocation, true);
- - boolean canName = (lot == null || !lot.isFlagSet(LotFlagType.FARM) ? true : lot.canPlayerAccess(player));
- + boolean canName = (lot == null || !lot.isFlagSet(LotFlagType.FARM) ? true : lot.canPlayerAccess(player.getName()));
- if (!canName) {
- player.printError("You cannot name animals here!");
- event.setCancelled(true);
- @@ -930,7 +930,7 @@ public class BukkitPlayerInteractionListener implements InnBukkitListener {
- case LEAD: {
- if (!player.hasPermission(Permission.entity_canleadanywhere)) {
- InnectisLot lot = LotHandler.getLot(clickLocation, true);
- - boolean canLead = (lot == null || !lot.isFlagSet(LotFlagType.FARM) ? true : lot.canPlayerAccess(player));
- + boolean canLead = (lot == null || !lot.isFlagSet(LotFlagType.FARM) ? true : lot.canPlayerAccess(player.getName()));
- if (!canLead) {
- player.printError("You cannot leash animals here!");
- event.setCancelled(true);
- @@ -960,7 +960,7 @@ public class BukkitPlayerInteractionListener implements InnBukkitListener {
- if ((entity instanceof Sheep || entity instanceof MushroomCow)
- && !player.hasPermission(Permission.entity_canshearanywhere)) {
- InnectisLot lot = LotHandler.getLot(clickLocation, true);
- - boolean canShearAnimals = (lot == null || !lot.isFlagSet(LotFlagType.FARM) ? true : lot.canPlayerAccess(player));
- + boolean canShearAnimals = (lot == null || !lot.isFlagSet(LotFlagType.FARM) ? true : lot.canPlayerAccess(player.getName()));
- if (!canShearAnimals) {
- player.printError("You cannot shear animals here!");
- event.setCancelled(true);
- @@ -990,7 +990,7 @@ public class BukkitPlayerInteractionListener implements InnBukkitListener {
- // Check lot for farm flag
- if (lot != null && lot.isFlagSet(LotFlagType.FARM)
- - && !(lot.canPlayerAccess(player) || player.hasPermission(Permission.entity_recolourallsheeps))
- + && !(lot.canPlayerAccess(player.getName()) || player.hasPermission(Permission.entity_recolourallsheeps))
- && entity instanceof Sheep) {
- player.printError("Go and brand your own sheep!");
- diff --git a/src/net/innectis/innplugin/Listeners/Bukkit/IdpBlockListener.java b/src/net/innectis/innplugin/Listeners/Bukkit/IdpBlockListener.java
- index e6a79d1b2..f103c22ee 100644
- --- a/src/net/innectis/innplugin/Listeners/Bukkit/IdpBlockListener.java
- +++ b/src/net/innectis/innplugin/Listeners/Bukkit/IdpBlockListener.java
- @@ -6,6 +6,7 @@ import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- import java.util.Random;
- +import java.util.UUID;
- import net.innectis.innplugin.Configuration;
- import net.innectis.innplugin.Economy.BlockEconomy;
- import net.innectis.innplugin.Handlers.BlockHandler;
- @@ -20,7 +21,6 @@ import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.InnectisObjects.EnchantmentType;
- import net.innectis.innplugin.InnectisObjects.PresentContent;
- import net.innectis.innplugin.InnectisObjects.TransactionObject;
- -import net.innectis.innplugin.SignSystem.WallSignType;
- import net.innectis.innplugin.Inventory.IdpContainer;
- import net.innectis.innplugin.Inventory.IdpInventory;
- import net.innectis.innplugin.Items.IdpItem;
- @@ -48,10 +48,13 @@ import net.innectis.innplugin.Player.Chat.ChatColor;
- import net.innectis.innplugin.Player.IdpPlayer;
- import net.innectis.innplugin.Player.InventoryType;
- import net.innectis.innplugin.Player.Permission;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Player.PlayerSession;
- import net.innectis.innplugin.Player.PlayerSettings;
- import net.innectis.innplugin.SignSystem.ChestShopSign;
- import net.innectis.innplugin.SignSystem.SignValidator;
- +import net.innectis.innplugin.SignSystem.WallSignType;
- import net.innectis.innplugin.Utility.NumberUtil;
- import org.bukkit.Bukkit;
- import org.bukkit.GameMode;
- @@ -730,7 +733,7 @@ public class IdpBlockListener implements Listener {
- }
- // Log the action
- - LogManager.getBlockLogger().logBlockAction(player.getName(), mat, loc, BlockAction.BLOCK_PLACE);
- + LogManager.getBlockLogger().logBlockAction(player.getUniqueId(), mat, loc, BlockAction.BLOCK_PLACE);
- // Clear the data
- BlockHandler.getIdpBlockData(loc).clear();
- // Only in pixel world
- @@ -894,7 +897,11 @@ public class IdpBlockListener implements Listener {
- player.getInventory().updateBukkitInventory();
- return;
- }
- - if (ChestHandler.createChest(player, block) != null) {
- +
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName());
- +
- + if (ChestHandler.createChest(credentials, block) != null) {
- + PlayerCredentialsManager.addCredentialsToCache(credentials);
- player.printInfo("You lock the chest. Only you can access this chest.");
- } else {
- event.setCancelled(true);
- @@ -912,7 +919,10 @@ public class IdpBlockListener implements Listener {
- // Iron Door
- if (mat == IdpMaterial.IRON_DOOR_BLOCK) {
- try {
- - if (DoorHandler.createDoor(player, block) == null) {
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName());
- +
- + if (DoorHandler.createDoor(credentials, block) == null) {
- + PlayerCredentialsManager.addCredentialsToCache(credentials);
- event.setCancelled(true);
- player.getInventory().updateBukkitInventory();
- return;
- @@ -928,7 +938,9 @@ public class IdpBlockListener implements Listener {
- // Trap Door
- if (mat == IdpMaterial.TRAP_DOOR) {
- try {
- - TrapdoorHandler.createTrapdoor(world.getHandle(), loc, player.getName());
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName());
- + TrapdoorHandler.createTrapdoor(world.getHandle(), loc, credentials);
- + PlayerCredentialsManager.addCredentialsToCache(credentials);
- } catch (SQLException ex) {
- event.setCancelled(true);
- player.getInventory().updateBukkitInventory();
- @@ -985,13 +997,13 @@ public class IdpBlockListener implements Listener {
- if (lot != null) {
- if (lot.getOwner().equalsIgnoreCase(player.getName())) {
- lot.setLastOwnerEdit(System.currentTimeMillis());
- - } else if (lot.canPlayerAccess(player)) {
- + } else if (lot.canPlayerAccess(player.getName())) {
- lot.setLastMemberEdit(System.currentTimeMillis());
- }
- }
- // Log the action
- - LogManager.getBlockLogger().logBlockAction(player.getName(), mat, loc, BlockAction.BLOCK_PLACE);
- + LogManager.getBlockLogger().logBlockAction(player.getUniqueId(), mat, loc, BlockAction.BLOCK_PLACE);
- }
- @EventHandler(priority = EventPriority.LOW)
- @@ -1159,8 +1171,8 @@ public class IdpBlockListener implements Listener {
- // LIGHTING UP A BLOCK. IF SOMEONE ELSE PUNCHES IT OUT, REPLACE WITH
- // ORIGINAL BLOCK
- if (LightsourceHandler.isLit(block.getLocation())) {
- - String name = LightsourceHandler.getPlayerNameFromLocation(loc);
- - IdpPlayer litPlayer = plugin.getPlayer(name);
- + UUID playerId = LightsourceHandler.getPlayerIdFromLocation(loc);
- + IdpPlayer litPlayer = plugin.getPlayer(playerId);
- if (litPlayer.equals(player)) {
- player.printInfo("You punched out your light!");
- @@ -1169,7 +1181,7 @@ public class IdpBlockListener implements Listener {
- litPlayer.printInfo(player.getName() + " punched out your light!");
- }
- - LightsourceHandler.unlightBlock(name);
- + LightsourceHandler.unlightBlock(playerId);
- event.setCancelled(true);
- return;
- }
- @@ -1220,7 +1232,7 @@ public class IdpBlockListener implements Listener {
- }
- // Log the action in pixel world
- - LogManager.getBlockLogger().logBlockAction(player.getName(), mat, loc, BlockAction.BLOCK_BREAK);
- + LogManager.getBlockLogger().logBlockAction(player.getUniqueId(), mat, loc, BlockAction.BLOCK_BREAK);
- BlockHandler.setBlock(block, IdpMaterial.AIR);
- @@ -1415,8 +1427,8 @@ public class IdpBlockListener implements Listener {
- PreparedStatement statement = null;
- try {
- - statement = DBManager.prepareStatement("INSERT DELAYED INTO block_breaks (time, username, blockid, world, x, y, z) VALUES (NOW(), ?, ?, ?, ?, ?, ?);");
- - statement.setString(1, player.getName());
- + statement = DBManager.prepareStatement("INSERT DELAYED INTO block_breaks (time, player_id, blockid, world, x, y, z) VALUES (NOW(), ?, ?, ?, ?, ?, ?);");
- + statement.setString(1, player.getUniqueId().toString());
- statement.setInt(2, BlockHandler.getBlockTypeId(block));
- statement.setString(3, loc.getWorld().getName());
- statement.setInt(4, loc.getBlockX());
- @@ -1453,7 +1465,7 @@ public class IdpBlockListener implements Listener {
- if (lot != null) {
- if (lot.getOwner().equalsIgnoreCase(player.getName())) {
- lot.setLastOwnerEdit(System.currentTimeMillis());
- - } else if (lot.canPlayerAccess(player)) {
- + } else if (lot.canPlayerAccess(player.getName())) {
- lot.setLastMemberEdit(System.currentTimeMillis());
- }
- }
- @@ -1482,7 +1494,7 @@ public class IdpBlockListener implements Listener {
- }
- if (giveValue) {
- - TransactionObject transaction = TransactionHandler.getTransactionObject(player.getName());
- + TransactionObject transaction = TransactionHandler.getTransactionObject(player.getUniqueId(), player.getName());
- transaction.addValue(valutas, TransactionType.VALUTAS);
- player.printInfo("You have gained " + valutas + " valuta" + (valutas != 1 ? "s" : "") + " from this " + mat.getName() + "!");
- @@ -1503,7 +1515,7 @@ public class IdpBlockListener implements Listener {
- }
- // Log the action
- - LogManager.getBlockLogger().logBlockAction(player.getName(), mat, loc, BlockAction.BLOCK_BREAK);
- + LogManager.getBlockLogger().logBlockAction(player.getUniqueId(), mat, loc, BlockAction.BLOCK_BREAK);
- }
- /**
- @@ -1720,7 +1732,7 @@ public class IdpBlockListener implements Listener {
- InnectisChest chest = ChestHandler.getChest(blockBelow.getLocation());
- if (chest != null) {
- - if (!chest.canPlayerManage(player)
- + if (!chest.canPlayerManage(player.getName())
- && !player.hasPermission(Permission.owned_object_override)) {
- player.printError("You do not own or operate the chest under this sign!");
- event.setCancelled(true);
- diff --git a/src/net/innectis/innplugin/Listeners/Bukkit/IdpEntityDamageListener.java b/src/net/innectis/innplugin/Listeners/Bukkit/IdpEntityDamageListener.java
- index 422ed1ab2..8212fee58 100644
- --- a/src/net/innectis/innplugin/Listeners/Bukkit/IdpEntityDamageListener.java
- +++ b/src/net/innectis/innplugin/Listeners/Bukkit/IdpEntityDamageListener.java
- @@ -95,7 +95,7 @@ public class IdpEntityDamageListener {
- }
- }
- - if (lot == null || lot.canPlayerManage(player)
- + if (lot == null || lot.canPlayerManage(player.getName())
- || player.hasPermission(Permission.entity_catchentitiesoverride)) {
- EntityTraits traits = EntityTraits.getEntityTraits(entity);
- @@ -121,7 +121,7 @@ public class IdpEntityDamageListener {
- return true;
- } else if ((entity instanceof Animals || entity instanceof Golem || entity instanceof Squid
- || entity instanceof Bat || entity instanceof Villager) && lot != null && lot.isFlagSet(LotFlagType.FARM)
- - && !lot.canPlayerManage(player)) {
- + && !lot.canPlayerManage(player.getName())) {
- if (entity instanceof Tameable) {
- Tameable tameable = (Tameable) entity;
- diff --git a/src/net/innectis/innplugin/Listeners/Bukkit/IdpPlayerInteractListener.java b/src/net/innectis/innplugin/Listeners/Bukkit/IdpPlayerInteractListener.java
- index 870aff0df..7775a2cc7 100644
- --- a/src/net/innectis/innplugin/Listeners/Bukkit/IdpPlayerInteractListener.java
- +++ b/src/net/innectis/innplugin/Listeners/Bukkit/IdpPlayerInteractListener.java
- @@ -149,7 +149,7 @@ public class IdpPlayerInteractListener {
- // copying sign text
- if (event.getBlockMaterial() == IdpMaterial.WALL_SIGN || event.getBlockMaterial() == IdpMaterial.SIGN_POST) {
- if (event.getBlockLot() == null
- - || event.getBlockLot().canPlayerAccess(player)
- + || event.getBlockLot().canPlayerAccess(player.getName())
- || player.hasPermission(Permission.special_edit_any_sign)) {
- Sign newSign = (Sign) event.getBlock().getState();
- player.getSession().setSignLines(newSign.getLines());
- @@ -163,7 +163,7 @@ public class IdpPlayerInteractListener {
- Block oppositeBlock = event.getBlock().getRelative(event.getBlockFace());
- InnectisLot lot = LotHandler.getLot(oppositeBlock.getLocation(), true);
- - if (lot == null || lot.canPlayerManage(player)
- + if (lot == null || lot.canPlayerManage(player.getName())
- || player.hasPermission(Permission.special_signcopy)) {
- IdpMaterial oppositeMaterial = IdpMaterial.fromBlock(oppositeBlock);
- @@ -263,7 +263,7 @@ public class IdpPlayerInteractListener {
- //(excluding Chests as they have their own protection system [chestallow])
- //The interaction check above SHOULD catch these - this is a failsafe!
- if (event.getBlockLot() != null
- - && !event.getBlockLot().canPlayerAccess(event.getPlayer())
- + && !event.getBlockLot().canPlayerAccess(event.getPlayer().getName())
- && mat != IdpMaterial.CHEST && mat != IdpMaterial.TRAPPED_CHEST
- && !event.getPlayer().hasPermission(Permission.command_admin_open_any_container)) {
- event.getPlayer().printError("Try as you might, you are unable to open this " + mat.getName() + "!");
- @@ -275,7 +275,7 @@ public class IdpPlayerInteractListener {
- public boolean playerFlintAndSteelUse(InnPlayerInteractEvent event) {
- if (event.getBlockLot() != null
- - && event.getBlockLot().canPlayerManage(event.getPlayer())
- + && event.getBlockLot().canPlayerManage(event.getPlayer().getName())
- && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
- event.getPlayer().getSession().setUsingFintSteel(true);
- @@ -293,7 +293,7 @@ public class IdpPlayerInteractListener {
- IdpPlayer player = event.getPlayer();
- if ((event.getBlockLot() != null
- - && event.getBlockLot().canPlayerManage(player))
- + && event.getBlockLot().canPlayerManage(player.getName()))
- || player.hasPermission(Permission.entity_catchentitiesoverride)) {
- List<EntityTraits> caughtEntityTraits = player.getSession().getCaughtEntityTraits();
- boolean renameOwners = player.getSession().getRenameOwners();
- @@ -346,7 +346,7 @@ public class IdpPlayerInteractListener {
- IdpPlayer player = event.getPlayer();
- InnectisLot lot = LotHandler.getLot(placeBlock.getLocation(), true);
- - if ((lot != null && !lot.canPlayerAccess(player))) {
- + if ((lot != null && !lot.canPlayerAccess(player.getName()))) {
- player.printError("You may not use a firework here!");
- return true;
- }
- @@ -357,7 +357,7 @@ public class IdpPlayerInteractListener {
- public boolean playerFireChargeUse(InnPlayerInteractEvent event) {
- InnectisLot lot = event.getBlockLot();
- IdpPlayer player = event.getPlayer();
- - if (lot != null && !lot.canPlayerAccess(player) && !player.hasPermission(Permission.world_build_unrestricted)) {
- + if (lot != null && !lot.canPlayerAccess(player.getName()) && !player.hasPermission(Permission.world_build_unrestricted)) {
- player.printError("You cannot place a fire charge here!");
- return true;
- }
- @@ -372,7 +372,7 @@ public class IdpPlayerInteractListener {
- || mat == IdpMaterial.REDSTONE_REPEATER_ON);
- //prevent redstone repeater/comparator tampering
- - if (lot != null && !lot.canPlayerAccess(player) && !player.hasPermission(Permission.world_build_unrestricted)) {
- + if (lot != null && !lot.canPlayerAccess(player.getName()) && !player.hasPermission(Permission.world_build_unrestricted)) {
- player.printError("You cannot change the state of someone elses " + (isRepeater ? "repeater" : "comparator") + "!");
- return true;
- }
- @@ -526,7 +526,7 @@ public class IdpPlayerInteractListener {
- InnectisChest innChest = ChestHandler.getChest(chestBlock.getLocation());
- if (innChest != null) {
- - if (innChest.canPlayerAccess(player)
- + if (innChest.canPlayerAccess(player.getName())
- || player.hasPermission(Permission.special_chest_stashall)) {
- mat = IdpMaterial.fromString(sign.getLine(1));
- boolean useArmor = false;
- @@ -819,7 +819,7 @@ public class IdpPlayerInteractListener {
- return true;
- }
- - TransactionObject transactionSender = TransactionHandler.getTransactionObject(player.getName());
- + TransactionObject transactionSender = TransactionHandler.getTransactionObject(player.getUniqueId(), player.getName());
- int balance = transactionSender.getValue(TransactionType.VALUTAS);
- if (balance < amount) {
- @@ -827,7 +827,8 @@ public class IdpPlayerInteractListener {
- return true;
- }
- - TransactionObject transactionReceiver = TransactionHandler.getTransactionObject(lot.getOwner());
- + PlayerCredentials credentials = lot.getOwnerCredentials();
- + TransactionObject transactionReceiver = TransactionHandler.getTransactionObject(credentials.getUniqueId(), credentials.getName());
- // Lot owner did not represent an actual player
- if (transactionReceiver == null) {
- @@ -877,7 +878,7 @@ public class IdpPlayerInteractListener {
- && !player.hasPermission(Permission.owned_object_override)) {
- Jukebox box = (Jukebox) event.getBlock().getState();
- - if (lot != null && !lot.canPlayerAccess(player) && box.isPlaying()) {
- + if (lot != null && !lot.canPlayerAccess(player.getName()) && box.isPlaying()) {
- player.printError("You may not eject this disc!");
- return true;
- }
- @@ -891,7 +892,7 @@ public class IdpPlayerInteractListener {
- //prevent note block tweaking
- if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
- - if (lot != null && !lot.canPlayerAccess(player) && !player.hasPermission(Permission.world_build_unrestricted)) {
- + if (lot != null && !lot.canPlayerAccess(player.getName()) && !player.hasPermission(Permission.world_build_unrestricted)) {
- player.printError("Tisk tisk, don't tamper with someone else's tunes!");
- return true;
- }
- @@ -922,7 +923,7 @@ public class IdpPlayerInteractListener {
- }
- // Check access
- - if ((lot != null && !lot.canPlayerAccess(player))) {
- + if ((lot != null && !lot.canPlayerAccess(player.getName()))) {
- player.printError("You may not use bonemeal here!");
- return true;
- }
- @@ -980,7 +981,7 @@ public class IdpPlayerInteractListener {
- IdpItemStack itemStack = event.getItem();
- if (lot != null && lot.isFlagSet(LotFlagType.RESTRICTMINECART)
- - && !lot.canPlayerAccess(player)
- + && !lot.canPlayerAccess(player.getName())
- && !player.hasPermission(Permission.world_build_unrestricted)) {
- player.printError("You may not place a minecart here.");
- return true;
- @@ -990,7 +991,8 @@ public class IdpPlayerInteractListener {
- // (this is not available in VehicleCreateEvent, so we do it here instead)
- if (itemStack.getMaterial() == IdpMaterial.HOPPER_MINECART) {
- HopperMinecart hopperMinecart = (HopperMinecart) player.getLocation().getWorld().spawnEntity(block.getLocation(), EntityType.MINECART_HOPPER);
- - OwnedEntityHandler.addOwnedEntity(hopperMinecart.getUniqueId(), player.getName(), EntityType.MINECART_HOPPER);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(player.getUniqueId());
- + OwnedEntityHandler.addOwnedEntity(hopperMinecart.getUniqueId(), credentials, EntityType.MINECART_HOPPER);
- player.setItemStackInHand(new IdpItemStack(IdpMaterial.AIR, 1));
- return true;
- @@ -1058,14 +1060,14 @@ public class IdpPlayerInteractListener {
- // Now we are sure there is a chest and a player owns it
- // --------------------------------------------------
- - if (chest.canPlayerAccess(player)
- + if (chest.canPlayerAccess(player.getName())
- || (chest.isFlagSet(ChestFlagType.LOT_MEMBER_CHEST) && chestlot != null
- && (chestlot.containsMember(player.getName()) || chestlot.containsOperator(player.getName())))) {
- player.getSession().setCheckSignUpdate(true);
- // Auto-refill chests
- if (chest.isFlagSet(ChestFlagType.AUTO_REFILL)) {
- - chest.logChestAccess(player);
- + chest.logChestAccess(player.getUniqueId());
- IdpInventory checkInv = chest.getInventory("Auto-refill");
- checkInv.setCustom("autofill:" + checkInv.getSize());
- @@ -1082,7 +1084,7 @@ public class IdpPlayerInteractListener {
- // Auto-refill chests
- if (chest.isFlagSet(ChestFlagType.AUTO_REFILL)) {
- - chest.logChestAccess(player);
- + chest.logChestAccess(player.getUniqueId());
- IdpInventory checkInv = chest.getInventory("Auto-refill");
- checkInv.setCustom("autofill:" + checkInv.getSize());
- @@ -1092,7 +1094,7 @@ public class IdpPlayerInteractListener {
- return true;
- }
- - } else if (chestlot != null && chestlot.canPlayerManage(player)) {
- + } else if (chestlot != null && chestlot.canPlayerManage(player.getName())) {
- // Lets open up a read-only chest.
- IdpInventory showcase = chest.getInventory("Read-Only Chest");
- showcase.setCustom("showcase");
- @@ -1120,7 +1122,7 @@ public class IdpPlayerInteractListener {
- // --------------------------------------------------
- // Log the access
- - chest.logChestAccess(player);
- + chest.logChestAccess(player.getUniqueId());
- if (!player.getSession().isVisible()
- || player.getSession().getSpectating() != null) {
- @@ -1153,8 +1155,9 @@ public class IdpPlayerInteractListener {
- if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
- IdpPlayer player = event.getPlayer();
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName());
- EnderContentsType type = player.getWorld().getSettings().getEnderchestType();
- - EnderChestContents chestcontents = EnderChestContents.getContents(player.getName(), type);
- + EnderChestContents chestcontents = EnderChestContents.getContents(credentials, type);
- IdpMaterial mat = IdpMaterial.fromBlock(event.getBlock());
- @@ -1173,12 +1176,12 @@ public class IdpPlayerInteractListener {
- // If an ender chest of this player is currently being viewed let's use that instead!
- // (it is viewed if an admin is already viewing their ender chest
- - EnderChestView view = plugin.getEnderChestView(player.getName(), type);
- + EnderChestView view = plugin.getEnderChestView(player.getUniqueId(), type);
- Inventory virtualChest;
- if (view == null) {
- virtualChest = new IdpInventory("container.enderchest", 27);
- - plugin.addEnderChestView(new EnderChestView(player.getName(), type, virtualChest));
- + plugin.addEnderChestView(new EnderChestView(player.getUniqueId(), type, virtualChest));
- // Update the contents of the ender chest
- IdpItemStack[] items = chestcontents.getItems();
- @@ -1216,7 +1219,7 @@ public class IdpPlayerInteractListener {
- if (mat == IdpMaterial.IRON_DOOR_BLOCK) {
- if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
- InnectisDoor door = DoorHandler.getDoor(event.getBlock().getLocation());
- - if ((door == null || !door.canPlayerAccess(player))
- + if ((door == null || !door.canPlayerAccess(player.getName()))
- && !player.hasPermission(Permission.owned_object_override)) {
- player.printError("This door is locked!");
- } else {
- @@ -1253,7 +1256,7 @@ public class IdpPlayerInteractListener {
- return true;
- }
- - if ((waypoint == null || !waypoint.canPlayerAccess(player))
- + if ((waypoint == null || !waypoint.canPlayerAccess(player.getName()))
- && !player.hasPermission(Permission.owned_object_override)) {
- player.printError("You cannot use that waypoint!");
- } else {
- @@ -1266,7 +1269,7 @@ public class IdpPlayerInteractListener {
- } else {
- player.printError("This waypoint does not go anywhere!");
- - if (waypoint.canPlayerManage(player)
- + if (waypoint.canPlayerManage(player.getName())
- || player.hasPermission(Permission.owned_object_override)) {
- player.printInfo("Set a location with /wpset " + waypoint.getId() + ".");
- }
- @@ -1294,7 +1297,8 @@ public class IdpPlayerInteractListener {
- // Switches
- if (event.getItem().getMaterial() == IdpMaterial.REDSTONE_BLOCK) {
- - InnectisSwitch.createOrGetSwitch(loc, event.getPlayer().getName());
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(event.getPlayer().getName());
- + InnectisSwitch.createOrGetSwitch(loc, credentials);
- } else {
- InnectisSwitch st = InnectisSwitch.getSwitch(loc);
- if (st != null) {
- @@ -1446,7 +1450,7 @@ public class IdpPlayerInteractListener {
- //Prevents a player from putting a fire out on a lot
- //they do not have build rights on
- if (lot != null) {
- - if (!lot.canPlayerAccess(player)) {
- + if (!lot.canPlayerAccess(player.getName())) {
- return true;
- }
- }
- @@ -1602,7 +1606,7 @@ public class IdpPlayerInteractListener {
- // Only check access for trapdoors that are owned
- if (trapdoor != null) {
- - if (!(trapdoor.canPlayerAccess(player) || player.hasPermission(Permission.owned_object_override))) {
- + if (!(trapdoor.canPlayerAccess(player.getName()) || player.hasPermission(Permission.owned_object_override))) {
- player.printError("You may not access this trapdoor.");
- return true;
- }
- @@ -1626,7 +1630,7 @@ public class IdpPlayerInteractListener {
- InnectisBookcase bookcase = InnectisBookcase.getBookcase(loc);
- if (bookcase != null) {
- - if (bookcase.canPlayerAccess(player) || player.hasPermission(Permission.owned_object_override)) {
- + if (bookcase.canPlayerAccess(player.getName()) || player.hasPermission(Permission.owned_object_override)) {
- // if holding an written book, just store it.
- if (player.getMaterialInHand() == IdpMaterial.WRITTEN_BOOK) {
- IdpItemStack item = player.getItemStackInHand();
- @@ -1658,13 +1662,15 @@ public class IdpPlayerInteractListener {
- if (action == Action.LEFT_CLICK_BLOCK && player.getMaterialInHand() == IdpMaterial.CHEST) {
- InnectisLot lot = LotHandler.getLot(loc);
- - if (lot == null || lot.canPlayerAccess(player) || player.hasPermission(Permission.owned_object_override)) {
- + if (lot == null || lot.canPlayerAccess(player.getName()) || player.hasPermission(Permission.owned_object_override)) {
- InnectisBookcase bookcase = InnectisBookcase.getBookcase(loc);
- if (bookcase == null) {
- - bookcase = new InnectisBookcase(block.getWorld(), block, player.getName());
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(player.getName());
- + bookcase = new InnectisBookcase(block.getWorld(), block, credentials);
- if (bookcase.save()) {
- + PlayerCredentialsManager.addCredentialsToCache(credentials);
- player.printInfo("That bookcase has been given an inventory.");
- } else {
- player.printError("Unable to save bookcase. Notify an admin!");
- diff --git a/src/net/innectis/innplugin/Loggers/BlockLogger.java b/src/net/innectis/innplugin/Loggers/BlockLogger.java
- index a09bcb6db..3845c52d8 100644
- --- a/src/net/innectis/innplugin/Loggers/BlockLogger.java
- +++ b/src/net/innectis/innplugin/Loggers/BlockLogger.java
- @@ -1,6 +1,7 @@
- package net.innectis.innplugin.Loggers;
- import java.util.Date;
- +import java.util.UUID;
- import net.innectis.innplugin.Handlers.BlockHandler;
- import net.innectis.innplugin.Items.IdpMaterial;
- import org.bukkit.Location;
- @@ -14,7 +15,7 @@ import org.bukkit.entity.Entity;
- public class BlockLogger extends IdpDBLogger {
- BlockLogger() {
- - super("block_log", "name", "locx", "locy", "locz", "world", "Id", "Data", "DateTime", "ActionType");
- + super("block_log", "player_id", "locx", "locy", "locz", "world", "Id", "Data", "DateTime", "ActionType");
- }
- /**
- @@ -69,12 +70,12 @@ public class BlockLogger extends IdpDBLogger {
- * For the <b>REVERTION</b> action the block is the block after it got reverted.
- * @param action - The action that was done
- */
- - public void logBlockAction(String username, IdpMaterial mat, Location loc, BlockAction action) {
- + public void logBlockAction(UUID playerId, IdpMaterial mat, Location loc, BlockAction action) {
- int id = mat.getId();
- byte dat = (byte) mat.getData();
- addToCache(
- - username,
- + playerId.toString(),
- loc.getBlockX(),
- loc.getBlockY(),
- loc.getBlockZ(),
- @@ -87,11 +88,11 @@ public class BlockLogger extends IdpDBLogger {
- /**
- * Log an blockaction.
- - * @param username - The name of the user that done the action.
- + * @param playerId - The ID of the player that did the action
- * @param entity - the entity interacted with
- * @param action - The action that was done
- */
- - public void logEntityAction(String username, Entity entity, BlockAction action) {
- + public void logEntityAction(UUID playerId, Entity entity, BlockAction action) {
- IdpMaterial mat = null;
- switch (entity.getType()) {
- @@ -106,7 +107,7 @@ public class BlockLogger extends IdpDBLogger {
- Location loc = entity.getLocation();
- addToCache(
- - username,
- + playerId.toString(),
- loc.getBlockX(),
- loc.getBlockY(),
- loc.getBlockZ(),
- diff --git a/src/net/innectis/innplugin/MailSystem/MailHandler.java b/src/net/innectis/innplugin/MailSystem/MailHandler.java
- index 574db4c00..a769ab42e 100644
- --- a/src/net/innectis/innplugin/MailSystem/MailHandler.java
- +++ b/src/net/innectis/innplugin/MailSystem/MailHandler.java
- @@ -4,9 +4,14 @@ import java.sql.Date;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- +import java.util.List;
- +import java.util.UUID;
- +import net.innectis.innplugin.Configuration;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.Player.IdpPlayer;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- /**
- * Handles the mail for each user
- @@ -19,27 +24,37 @@ public class MailHandler {
- /**
- * Loads player's mail to the session
- *
- - * @param player
- - * @return true if the player has mail, false otherwise
- + * @param playerId
- */
- public static void loadPlayerMailToSession(IdpPlayer player) {
- + PlayerCredentials toPlayerCredentials = PlayerCredentialsManager.getByUniqueId(player.getUniqueId());
- PreparedStatement statement = null;
- ResultSet set = null;
- try {
- - statement = DBManager.prepareStatement("SELECT * FROM playermail WHERE lower(toplayer) = ?");
- - statement.setString(1, player.getName().toLowerCase());
- + statement = DBManager.prepareStatement("SELECT * FROM playermail WHERE to_player_id = ?");
- + statement.setString(1, player.getUniqueId().toString());
- set = statement.executeQuery();
- while (set.next()) {
- int ID = set.getInt("ID");
- Date date = set.getDate("datecreated");
- boolean read = set.getBoolean("readmail");
- - String from = set.getString("fromplayer");
- +
- + String fromPlayerIdString = set.getString("from_player_id");
- + UUID fromPlayerId = UUID.fromString(fromPlayerIdString);
- + PlayerCredentials fromPlayerCredentials = null;
- +
- + if (fromPlayerId.equals(Configuration.SERVER_GENERATED_IDENTIFIER)) {
- + fromPlayerCredentials = Configuration.SERVER_GENERATED_CREDENTIALS;
- + } else {
- + fromPlayerCredentials = PlayerCredentialsManager.getByUniqueId(fromPlayerId);
- + }
- +
- String title = set.getString("title");
- String content = set.getString("content");
- - MailMessage obj = new MailMessage(ID, date, read, from, player.getName(), title, content);
- + MailMessage obj = new MailMessage(ID, date, read, fromPlayerCredentials, toPlayerCredentials, title, content);
- player.getSession().addMail(obj);
- }
- } catch (SQLException ex) {
- diff --git a/src/net/innectis/innplugin/MailSystem/MailMessage.java b/src/net/innectis/innplugin/MailSystem/MailMessage.java
- index 9be2bc028..c8dbe8e30 100644
- --- a/src/net/innectis/innplugin/MailSystem/MailMessage.java
- +++ b/src/net/innectis/innplugin/MailSystem/MailMessage.java
- @@ -7,6 +7,7 @@ import java.util.Date;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.InnectisObjects.Message;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- /**
- * Contains a single mail entry for a player
- @@ -14,33 +15,37 @@ import net.innectis.innplugin.InnectisObjects.Message;
- * @author AlphaBlend
- */
- public class MailMessage extends Message {
- - private String to;
- + private PlayerCredentials fromPlayerCredentials;
- private String title;
- /**
- * Sets up a mail object for a new message
- *
- - * @param from
- - * @param to
- + * @param date
- + * @param fromCredentials
- + * @param toPlayerCredentials
- * @param title
- * @param message
- */
- - public MailMessage(Date date, String from, String to, String title, String message) {
- - this(0, date, false, from, to, title, message);
- + public MailMessage(Date date, PlayerCredentials fromCredentials, PlayerCredentials toPlayerCredentials, String title, String message) {
- + this(0, date, false, fromCredentials, toPlayerCredentials, title, message);
- }
- /**
- * Sets up the mail object
- *
- * @param ID
- - * @param from
- + * @param date
- + * @param read
- + * @param fromPlayerCredentials
- + * @param toPlayerCredentials
- * @param title
- - * @param contents
- + * @param message
- */
- - public MailMessage(int ID, Date date, boolean read, String from, String to, String title, String message) {
- - super(ID, date, read, from, message);
- + public MailMessage(int ID, Date date, boolean read, PlayerCredentials fromPlayerCredentials, PlayerCredentials toPlayerCredentials, String title, String message) {
- + super(ID, date, read, fromPlayerCredentials, message);
- - this.to = to;
- + this.fromPlayerCredentials = toPlayerCredentials;
- this.title = title;
- }
- @@ -67,11 +72,11 @@ public class MailMessage extends Message {
- statement.setInt(2, id);
- statement.executeUpdate();
- } else {
- - statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO playermail (datecreated, readmail, toplayer, fromplayer, title, content) VALUES (?, ?, ?, ?, ?, ?)");
- + statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO playermail (datecreated, readmail, to_player_id, from_player_id, title, content) VALUES (?, ?, ?, ?, ?, ?)");
- statement.setDate(1, new java.sql.Date(date.getTime()));
- statement.setBoolean(2, read);
- - statement.setString(3, to);
- - statement.setString(4, creator);
- + statement.setString(3, fromPlayerCredentials.getUniqueId().toString());
- + statement.setString(4, creatorCredentials.getUniqueId().toString());
- statement.setString(5, title);
- statement.setString(6, message);
- statement.execute();
- diff --git a/src/net/innectis/innplugin/OwnedObjects/Handlers/ChestHandler.java b/src/net/innectis/innplugin/OwnedObjects/Handlers/ChestHandler.java
- index 3eb464db5..e303b4d02 100644
- --- a/src/net/innectis/innplugin/OwnedObjects/Handlers/ChestHandler.java
- +++ b/src/net/innectis/innplugin/OwnedObjects/Handlers/ChestHandler.java
- @@ -7,6 +7,8 @@ import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.List;
- +import java.util.UUID;
- +import net.innectis.innplugin.Configuration;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.Items.IdpMaterial;
- @@ -15,6 +17,8 @@ import net.innectis.innplugin.OwnedObjects.InnectisLot;
- import net.innectis.innplugin.Player.Chat.ChatColor;
- import net.innectis.innplugin.Player.IdpPlayer;
- import net.innectis.innplugin.Player.Permission;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Utility.LocationUtil;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- @@ -204,12 +208,12 @@ public class ChestHandler {
- return null;
- }
- - public static List<InnectisChest> getChests(String owner) {
- + public static List<InnectisChest> getChests(String playerName) {
- List<InnectisChest> chests = new ArrayList<InnectisChest>();
- InnectisChest chest;
- for (Iterator<InnectisChest> it = getChests().values().iterator(); it.hasNext();) {
- chest = it.next();
- - if (chest.getOwner().equalsIgnoreCase(owner) && chest.isValid()) {
- + if (chest.getOwner().equalsIgnoreCase(playerName) && chest.isValid()) {
- chests.add(chest);
- }
- }
- @@ -249,48 +253,71 @@ public class ChestHandler {
- return null;
- }
- - PreparedStatement statement = DBManager.prepareStatement("SELECT username, isop FROM chests_members WHERE chestid = ?;");
- + String ownerIdString = result.getString("owner_id");
- + UUID ownerId = UUID.fromString(ownerIdString);
- + PlayerCredentials ownerCredentials = PlayerCredentialsManager.getByUniqueId(ownerId, true);
- +
- + PreparedStatement statement = DBManager.prepareStatement("SELECT player_id, isop FROM chests_members WHERE chestid = ?;");
- statement.setInt(1, result.getInt("chestid"));
- + List<PlayerCredentials> members = new ArrayList<PlayerCredentials>();
- + List<PlayerCredentials> operators = new ArrayList<PlayerCredentials>();
- ResultSet result2 = statement.executeQuery();
- - List<String> members = new ArrayList<String>();
- - List<String> operators = new ArrayList<String>();
- +
- while (result2.next()) {
- - if (result2.getBoolean("isop")) {
- - operators.add(result2.getString("username"));
- + String memberIdString = result2.getString("player_id");
- + UUID memberId = UUID.fromString(memberIdString);
- +
- + if (memberId.equals(Configuration.EVERYONE_IDENTIFIER)) {
- + members.add(Configuration.EVERYONE_CREDENTIALS);
- + } else if (memberId.equals(Configuration.LOT_ACCESS_IDENTIFIER)) {
- + members.add(Configuration.LOT_ACCESS_CREDENTIALS);
- } else {
- - members.add(result2.getString("username"));
- + boolean isOp = result2.getBoolean("isop");
- +
- + PlayerCredentials memberCredentials = PlayerCredentialsManager.getByUniqueId(memberId, true);
- +
- + if (isOp) {
- + operators.add(memberCredentials);
- + } else {
- + members.add(memberCredentials);
- + }
- }
- }
- DBManager.closeResultSet(result2);
- DBManager.closePreparedStatement(statement);
- - return new InnectisChest(type, world, primaryChest, optionalChest, result.getInt("chestid"), result.getString("owner"), members, operators, result.getLong("flags"));
- + return new InnectisChest(type, world, primaryChest, optionalChest, result.getInt("chestid"), ownerCredentials, members, operators, result.getLong("flags"));
- }
- - public static boolean hasChest(IdpPlayer player) {
- + public static boolean hasChest(String playerName) {
- InnectisChest chest;
- for (Iterator<InnectisChest> it = getChests().values().iterator(); it.hasNext();) {
- chest = it.next();
- - if (chest.getOwner().equalsIgnoreCase(player.getName())) {
- +
- + if (chest.getOwner().equalsIgnoreCase(playerName)) {
- return true;
- }
- }
- +
- return false;
- }
- - public static boolean isOwnChest(IdpPlayer player, Location location) {
- + public static boolean isOwnChest(String playerName, Location location) {
- InnectisChest chest = getChest(location);
- +
- if (chest == null) {
- return false;
- }
- - if (chest.getOwner().equalsIgnoreCase(player.getName())) {
- +
- + if (chest.getOwner().equalsIgnoreCase(playerName)) {
- return true;
- }
- +
- return false;
- }
- - public static InnectisChest createChest(IdpPlayer player, Block block) throws SQLException {
- + public static InnectisChest createChest(PlayerCredentials ownerCredentials, Block block) throws SQLException {
- InnectisChest existingChest = getChest(block.getLocation());
- // Allow placement, original owner is assumed
- @@ -303,7 +330,7 @@ public class ChestHandler {
- if (attached == null) { //no adjacent chests
- //all is good, make the chest
- - InnectisChest innchest = new InnectisChest(ChestType.fromMaterial(IdpMaterial.fromBlock(block)), block.getWorld(), block, null, -1, player.getName(), null, null, 0);
- + InnectisChest innchest = new InnectisChest(ChestType.fromMaterial(IdpMaterial.fromBlock(block)), block.getWorld(), block, null, -1, ownerCredentials, null, null, 0);
- innchest.save();
- ChestHandler.getChests().put(innchest.getId(), innchest);
- return innchest;
- @@ -320,8 +347,15 @@ public class ChestHandler {
- return null; //already an double chest
- }
- - if (!innAttached.getOwner().equalsIgnoreCase(player.getName())) {
- - player.printError("You cannot place a chest next to a chest you do not own.");
- + String ownerName = ownerCredentials.getName();
- +
- + if (!innAttached.getOwner().equalsIgnoreCase(ownerName)) {
- + IdpPlayer player = InnPlugin.getPlugin().getPlayer(ownerCredentials.getUniqueId());
- +
- + if (player != null) {
- + player.printError("You cannot place a chest next to a chest you do not own.");
- + }
- +
- return null;
- }
- @@ -331,71 +365,23 @@ public class ChestHandler {
- }
- }
- - /**
- - * Creates a new chest with the given name as owner. <br/>
- - * <b> This does not check the max chest size! </b>
- - * @param playername
- - * Name of the owner of the chest
- - * @param block
- - * The chest itself
- - * @return
- - * The innectischest or null if invalid
- - * @throws SQLException
- - */
- - public static InnectisChest createChest(String playername, Block block) throws SQLException {
- - InnectisChest existingChest = getChest(block.getLocation());
- -
- - // Allow placement, original owner is assumed
- - if (existingChest != null) {
- - return existingChest;
- - }
- -
- - //check for adjacent chests
- - Block attached = getAttachedChest(block);
- -
- - if (attached != null) {
- - InnectisChest innAttached = getChest(attached.getLocation());
- -
- - // Check if the attached chest is already an innectis chest
- - if (innAttached != null) {
- -
- - if (innAttached.isDoubleChest()) {
- - return null; //already an double chest
- - }
- -
- - if (!innAttached.getOwner().equalsIgnoreCase(playername)) {
- - return null;
- - }
- -
- - innAttached.setChest2(block);
- - innAttached.save();
- - return innAttached;
- - }
- - }
- -
- - //all is good, make the chest
- - InnectisChest innchest = new InnectisChest(ChestType.fromMaterial(IdpMaterial.fromBlock(block)), block.getWorld(), block, null, -1, playername, null, null, 0);
- - innchest.save();
- - ChestHandler.getChests().put(innchest.getId(), innchest);
- - return innchest;
- - }
- -
- public static boolean removeChest(IdpPlayer player, Block block) throws SQLException {
- if (!ChestType.isValidChestBlock(IdpMaterial.fromBlock(block))) {
- return true;
- }
- Location loc = block.getLocation();
- -
- InnectisChest chest = getChest(loc);
- +
- if (chest == null || chest.getOwner() == null) {
- return true;
- }
- InnectisLot lot = LotHandler.getLot(loc);
- +
- //you can remove a chest if you own it or if its on your lot
- - if (chest.getOwner().equalsIgnoreCase(player.getName())
- - || (lot != null && lot.getOwner().equalsIgnoreCase(player.getName()))
- + if (chest.getOwnerCredentials().getUniqueId().equals(player.getUniqueId())
- + || (lot != null && lot.getOwnerCredentials().getUniqueId().equals(player.getUniqueId()))
- || player.hasPermission(Permission.owned_object_override)) {
- removeChestForcibly(block, chest.getId(), true);
- return true;
- diff --git a/src/net/innectis/innplugin/OwnedObjects/Handlers/DoorHandler.java b/src/net/innectis/innplugin/OwnedObjects/Handlers/DoorHandler.java
- index a798af9b1..20aa95359 100644
- --- a/src/net/innectis/innplugin/OwnedObjects/Handlers/DoorHandler.java
- +++ b/src/net/innectis/innplugin/OwnedObjects/Handlers/DoorHandler.java
- @@ -7,15 +7,19 @@ import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.List;
- +import java.util.UUID;
- +import net.innectis.innplugin.Configuration;
- import net.innectis.innplugin.Handlers.BlockHandler;
- -import net.innectis.innplugin.Items.IdpMaterial;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- +import net.innectis.innplugin.Items.IdpMaterial;
- import net.innectis.innplugin.OwnedObjects.InnectisDoor;
- import net.innectis.innplugin.OwnedObjects.InnectisLot;
- import net.innectis.innplugin.Player.Chat.ChatColor;
- import net.innectis.innplugin.Player.IdpPlayer;
- import net.innectis.innplugin.Player.Permission;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.World;
- @@ -163,48 +167,71 @@ public class DoorHandler {
- return null;
- }
- - PreparedStatement statement = DBManager.prepareStatement("SELECT username, isop FROM doors_members WHERE doorid = ?;");
- + String ownerIdString = result.getString("owner_id");
- + UUID ownerId = UUID.fromString(ownerIdString);
- + PlayerCredentials ownerCredentials = PlayerCredentialsManager.getByUniqueId(ownerId, true);
- +
- + PreparedStatement statement = DBManager.prepareStatement("SELECT player_id, isop FROM doors_members WHERE doorid = ?;");
- statement.setInt(1, result.getInt("doorid"));
- ResultSet result2 = statement.executeQuery();
- - List<String> members = new ArrayList<String>();
- - List<String> operators = new ArrayList<String>();
- +
- + List<PlayerCredentials> members = new ArrayList<PlayerCredentials>();
- + List<PlayerCredentials> operators = new ArrayList<PlayerCredentials>();
- +
- while (result2.next()) {
- - if (result2.getBoolean("isop")) {
- - operators.add(result2.getString("username"));
- + String memberIdString = result2.getString("player_id");
- + UUID memberId = UUID.fromString(memberIdString);
- +
- + if (memberId.equals(Configuration.EVERYONE_IDENTIFIER)) {
- + members.add(Configuration.EVERYONE_CREDENTIALS);
- + } else if (memberId.equals(Configuration.LOT_ACCESS_IDENTIFIER)) {
- + members.add(Configuration.LOT_ACCESS_CREDENTIALS);
- } else {
- - members.add(result2.getString("username"));
- + boolean isOp = result2.getBoolean("isop");
- +
- + PlayerCredentials memberCredentials = PlayerCredentialsManager.getByUniqueId(memberId, true);
- +
- + if (isOp) {
- + operators.add(memberCredentials);
- + } else {
- + members.add(memberCredentials);
- + }
- }
- }
- DBManager.closeResultSet(result2);
- DBManager.closePreparedStatement(statement);
- - return new InnectisDoor(world, primaryDoor, optionalDoor, result.getInt("doorid"), result.getString("owner"), members, operators, result.getLong("flags"));
- + return new InnectisDoor(world, primaryDoor, optionalDoor, result.getInt("doorid"), ownerCredentials, members, operators, result.getLong("flags"));
- }
- - public static boolean hasDoor(IdpPlayer player) {
- - InnectisDoor door;
- + public static boolean hasDoor(String playerName) {
- for (Iterator<InnectisDoor> it = getDoors().values().iterator(); it.hasNext();) {
- - door = it.next();
- - if (door.getOwner().equalsIgnoreCase(player.getName())) {
- + InnectisDoor door = it.next();
- +
- + if (door.getOwner().equalsIgnoreCase(playerName)) {
- return true;
- }
- }
- +
- return false;
- }
- - public static boolean isOwnDoor(IdpPlayer player, Location location) {
- + public static boolean isOwnDoor(String playerName, Location location) {
- InnectisDoor door = getDoor(location);
- +
- if (door == null) {
- return false;
- }
- - if (door.getOwner().equalsIgnoreCase(player.getName())) {
- +
- + if (door.getOwner().equalsIgnoreCase(playerName)) {
- return true;
- }
- +
- return false;
- }
- - public static InnectisDoor createDoor(IdpPlayer player, Block block) throws SQLException {
- + public static InnectisDoor createDoor(PlayerCredentials ownerCredentials, Block block) throws SQLException {
- Location loc = block.getLocation();
- InnectisDoor door = getDoor(loc);
- @@ -220,64 +247,25 @@ public class DoorHandler {
- if (attached == null) { //no adjacent doors
- //all is good, make the door
- - InnectisDoor inndoor = new InnectisDoor(block.getWorld(), block, null, -1, player.getName(), null, null, 0);
- + InnectisDoor inndoor = new InnectisDoor(block.getWorld(), block, null, -1, ownerCredentials, null, null, 0);
- inndoor.save();
- DoorHandler.getDoors().put(inndoor.getId(), inndoor);
- return inndoor;
- } else {
- InnectisDoor innAttached = getDoor(attached.getLocation());
- if (innAttached.isDoubleDoor()) {
- - return null; //already an double door
- - }
- - if (!innAttached.getOwner().equalsIgnoreCase(player.getName())) {
- - player.printError("You cannot place a door next to a door you do not own.");
- - return null;
- + return null; //already a double door
- }
- - innAttached.setDoor2(block);
- - innAttached.save();
- - return innAttached;
- - }
- - }
- + String ownerName = ownerCredentials.getName();
- - /**
- - * Creates an innectis door at the given location
- - * @param playername
- - * @param block
- - * @return
- - * The innectisdoor is succeeded, else null
- - * @throws SQLException
- - */
- - public static InnectisDoor createDoor(String playername, Block block) throws SQLException {
- - if (getDoor(block.getLocation()) != null) { //prevent hijacking a door
- - return null;
- - }
- + if (!innAttached.getOwner().equalsIgnoreCase(ownerName)) {
- + IdpPlayer player = InnPlugin.getPlugin().getPlayer(ownerCredentials.getUniqueId());
- - //check for adjacent doors
- - Block attached = getAdjacentDoor(block);
- -
- - if (attached == null) { //no adjacent doors
- - //all is good, make the door
- - InnectisDoor inndoor = new InnectisDoor(block.getWorld(), block, null, -1, playername, null, null, 0);
- - inndoor.save();
- - DoorHandler.getDoors().put(inndoor.getId(), inndoor);
- - return inndoor;
- - } else {
- - InnectisDoor innAttached = getDoor(attached.getLocation());
- -
- - // Other door doesn't exist either
- - if (innAttached == null) {
- - // Create new double door
- - InnectisDoor inndoor = new InnectisDoor(block.getWorld(), block, attached, -1, playername, null, null, 0);
- - inndoor.save();
- - return inndoor;
- - }
- -
- - if (innAttached.isDoubleDoor()) {
- - return null; //already an double door
- - }
- - if (!innAttached.getOwner().equalsIgnoreCase(playername)) {
- - return null;
- + if (player != null && player.isOnline()) {
- + player.printError("You cannot place a door next to a door you do not own.");
- + return null;
- + }
- }
- innAttached.setDoor2(block);
- @@ -302,8 +290,8 @@ public class DoorHandler {
- InnectisLot lot = LotHandler.getLot(loc);
- //you can remove a door if you own it or if its on your lot
- - if (door.getOwner().equalsIgnoreCase(player.getName())
- - || (lot != null && lot.getOwner().equalsIgnoreCase(player.getName()))
- + if (door.getOwnerCredentials().getUniqueId().equals(player.getUniqueId())
- + || (lot != null && lot.getOwnerCredentials().getUniqueId().equals(player.getUniqueId()))
- || player.hasPermission(Permission.owned_object_override)) {
- removeDoorForcibly(block, door.getId(), true);
- return true;
- diff --git a/src/net/innectis/innplugin/OwnedObjects/Handlers/LotHandler.java b/src/net/innectis/innplugin/OwnedObjects/Handlers/LotHandler.java
- index 061e4a030..5c1b2f4dc 100644
- --- a/src/net/innectis/innplugin/OwnedObjects/Handlers/LotHandler.java
- +++ b/src/net/innectis/innplugin/OwnedObjects/Handlers/LotHandler.java
- @@ -12,6 +12,8 @@ import java.util.HashMap;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Map;
- +import java.util.UUID;
- +import net.innectis.innplugin.Configuration;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.Location.IdpWorld;
- @@ -20,6 +22,8 @@ import net.innectis.innplugin.Location.IdpWorldRegion;
- import net.innectis.innplugin.OwnedObjects.InnectisLot;
- import net.innectis.innplugin.Player.Chat.ChatColor;
- import net.innectis.innplugin.Player.IdpPlayer;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Player.PlayerGroup;
- import net.innectis.innplugin.Player.PlayerSession;
- import org.bukkit.Bukkit;
- @@ -93,8 +97,6 @@ public final class LotHandler {
- /**
- * Clears the cache and reload all lots from the database. <br/>
- * <b>Additionally it will check for disabled lots and fix lot nr's.</b>
- - *
- - * @throws SQLException
- */
- public static boolean loadLots() {
- getLots().clear();
- @@ -166,16 +168,46 @@ public final class LotHandler {
- Location spawn = new Location(world, result.getInt("sx"), result.getInt("sy"), result.getInt("sz"), result.getInt("yaw"), 0);
- - PreparedStatement statement = DBManager.prepareStatement("SELECT username, isop FROM lot_members WHERE lotid = ?;");
- + String ownerIdString = result.getString("owner_id");
- + UUID ownerId = UUID.fromString(ownerIdString);
- + PlayerCredentials ownerCredentials = null;
- +
- + // Owner credentials are different if this lot is assignable
- + if (ownerId.equals(Configuration.LOT_ASSIGNABLE_IDENTIFIER)) {
- + ownerCredentials = Configuration.LOT_ASSIGNABLE_CREDENTIALS;
- + } else if (ownerId.equals(Configuration.OTHER_IDENTIFIER)) {
- + ownerCredentials = Configuration.OTHER_CREDENTIALS;
- + } else {
- + ownerCredentials = PlayerCredentialsManager.getByUniqueId(ownerId, true);
- + }
- +
- + String creatorIdString = result.getString("creator_id");
- + UUID creatorId = UUID.fromString(creatorIdString);
- + PlayerCredentials creatorCredentials = PlayerCredentialsManager.getByUniqueId(creatorId, true);
- +
- + PreparedStatement statement = DBManager.prepareStatement("SELECT player_id, isop FROM lot_members WHERE lotid = ?;");
- statement.setInt(1, lotId);
- ResultSet result2 = statement.executeQuery();
- - List<String> members = new ArrayList<String>();
- - List<String> operators = new ArrayList<String>();
- +
- + List<PlayerCredentials> members = new ArrayList<PlayerCredentials>();
- + List<PlayerCredentials> operators = new ArrayList<PlayerCredentials>();
- +
- while (result2.next()) {
- - if (result2.getBoolean("isop")) {
- - operators.add(result2.getString("username"));
- + String memberIdString = result2.getString("player_id");
- + UUID memberId = UUID.fromString(memberIdString);
- +
- + if (memberId.equals(Configuration.EVERYONE_IDENTIFIER)) {
- + members.add(Configuration.EVERYONE_CREDENTIALS);
- } else {
- - members.add(result2.getString("username"));
- + boolean isOp = result2.getBoolean("isop");
- +
- + PlayerCredentials memberCredentials = PlayerCredentialsManager.getByUniqueId(memberId, true);
- +
- + if (isOp) {
- + operators.add(memberCredentials);
- + } else {
- + members.add(memberCredentials);
- + }
- }
- }
- @@ -185,44 +217,61 @@ public final class LotHandler {
- statement = DBManager.prepareStatement("SELECT * FROM lot_safelist WHERE lotid = ?;");
- statement.setInt(1, lotId);
- result2 = statement.executeQuery();
- - List<String> safelist = new ArrayList<String>();
- + List<PlayerCredentials> safelist = new ArrayList<PlayerCredentials>();
- +
- while(result2.next()) {
- - safelist.add(result2.getString("username"));
- + String playerIdString = result2.getString("player_id");
- + UUID playerId = UUID.fromString(playerIdString);
- + PlayerCredentials playerCredentials = PlayerCredentialsManager.getByUniqueId(playerId, true);
- + safelist.add(playerCredentials);
- }
- DBManager.closeResultSet(result2);
- DBManager.closePreparedStatement(statement);
- - statement = DBManager.prepareStatement("SELECT username, timeout FROM lot_banned WHERE lotid = ?;");
- + statement = DBManager.prepareStatement("SELECT player_id, timeout FROM lot_banned WHERE lotid = ?;");
- statement.setInt(1, lotId);
- result2 = statement.executeQuery();
- - Map<String, Long> banned = new HashMap<String, Long>();
- + Map<PlayerCredentials, Long> banned = new HashMap<PlayerCredentials, Long>();
- +
- while (result2.next()) {
- - banned.put(result2.getString("username"), result2.getLong("timeout"));
- + String playerIdString = result2.getString("player_id");
- + UUID playerId = UUID.fromString(playerIdString);
- + PlayerCredentials playerCredentials = null;
- +
- + if (playerId.equals(Configuration.EVERYONE_IDENTIFIER)) {
- + playerCredentials = Configuration.EVERYONE_CREDENTIALS;
- + } else {
- + playerCredentials = PlayerCredentialsManager.getByUniqueId(playerId);
- + }
- +
- + long timeout = result2.getLong("timeout");
- +
- + banned.put(playerCredentials, timeout);
- }
- DBManager.closeResultSet(result2);
- DBManager.closePreparedStatement(statement);
- - String owner = result.getString("owner");
- -
- - 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"));
- + 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"));
- }
- /**
- * This method will get a list all owners with lots and fix the lotnumbers so they are ordered correctly.
- */
- private static void fixLotNumbers() {
- - List<String> owners = new ArrayList<String>();
- - InnectisLot lot;
- + List<PlayerCredentials> owners = new ArrayList<PlayerCredentials>();
- +
- for (Iterator<InnectisLot> it = getLots().values().iterator(); it.hasNext();) {
- - lot = it.next();
- - if (!owners.contains(lot.getOwner().toLowerCase())) {
- - owners.add(lot.getOwner().toLowerCase());
- + InnectisLot lot = it.next();
- + PlayerCredentials ownerCredentials = lot.getOwnerCredentials();
- +
- + if (!owners.contains(ownerCredentials)) {
- + owners.add(ownerCredentials);
- }
- }
- - for (String owner : owners) {
- - fixLotNumber(owner);
- + for (PlayerCredentials pc : owners) {
- + fixLotNumber(pc.getName());
- }
- saveLots();
- }
- @@ -260,10 +309,7 @@ public final class LotHandler {
- */
- private static void cleanLots(Collection<InnectisLot> lots) {
- InnectisLot lot;
- - HashMap<String, Integer> lotCount = new HashMap<String, Integer>();
- - PlayerGroup group;
- - String ownername;
- - PlayerSession session;
- + HashMap<PlayerCredentials, Integer> lotCount = new HashMap<PlayerCredentials, Integer>();
- int count;
- Date targetdate = new Date(System.currentTimeMillis() - 1209600000);
- @@ -273,17 +319,20 @@ public final class LotHandler {
- // Check if its a top lot (not a sublot)
- if (lot.getParent() == null || lot.getParent() == mainLot) {
- - ownername = lot.getOwner().toLowerCase();
- - group = PlayerGroup.getGroupOfUsername(lot.getOwner());
- + PlayerCredentials ownerCredentials = lot.getOwnerCredentials();
- + UUID playerId = ownerCredentials.getUniqueId();
- + String name = ownerCredentials.getName();
- +
- + PlayerGroup group = PlayerGroup.getGroupOfPlayerById(playerId);
- // Check for inactive lots of guest players who left
- if (lot.getLastOwnerEdit() == 0 && group == PlayerGroup.GUEST) {
- - session = PlayerSession.getSession(ownername, InnPlugin.getPlugin());
- + PlayerSession session = PlayerSession.getSession(playerId, name, InnPlugin.getPlugin(), true);
- if (session != null) {
- // Check date
- if (session.getLastLogin().before(targetdate)) {
- - lot.setOwner("#");
- + lot.setOwner(Configuration.LOT_ASSIGNABLE_CREDENTIALS);
- InnPlugin.logInfo("Lot #" + lot.getId() + " (" + lot.getOwner() + ") set to assignable; player innactive, never editted lot!");
- }
- }
- @@ -291,7 +340,7 @@ public final class LotHandler {
- // Dont disable lots whose player names are invalid (I.E. #, %, or ~)
- if (group != PlayerGroup.NONE) {
- - count = (lotCount.get(ownername) == null ? 0 : lotCount.get(ownername));
- + count = (lotCount.get(ownerCredentials) == null ? 0 : lotCount.get(ownerCredentials));
- if (count + 1 > group.getMaxLots()) {
- lot.setDisabled(true);
- @@ -300,7 +349,7 @@ public final class LotHandler {
- lot.setDisabled(true);
- InnPlugin.logInfo("Lot #" + lot.getId() + " (" + lot.getOwner() + ") disabled; width/length too large! (" + lot.getWidth() + " or " + lot.getLength() + ")>" + group.getMaxLotSize());
- } else {
- - lotCount.put(ownername, ++count);
- + lotCount.put(ownerCredentials, ++count);
- }
- }
- @@ -319,12 +368,12 @@ public final class LotHandler {
- }
- /**
- - * This method will check all lots of the given player and remove lots if he's a guests that
- + * This method will check all lots of the given player by ID and remove lots if he's a guests that
- * hasn't used them in a while. It will also check if the size and amount of lots for this
- * player are still accepted.
- */
- - public static void cleanLots(String username) {
- - cleanLots(getLots(username));
- + public static void cleanLots(String playerName) {
- + cleanLots(getLots(playerName));
- }
- //</editor-fold>
- @@ -361,87 +410,55 @@ public final class LotHandler {
- if (lots == null) {
- return null;
- }
- +
- return lots.get(0);
- }
- /**
- * This method will look for a lot with the given string as the owner aswell as the lotnumber
- - * @param owner
- - * The owner's name, either be the exact name or a partial name.
- + * @param playerName
- + * The ID of the owner
- * @param lotNumber
- * The lotnumber to look for.
- * @return
- */
- - public static InnectisLot getLot(String owner, int lotNumber) {
- - InnectisLot lot, partialMatchStart = null, partialMatchAny = null;
- + public static InnectisLot getLot(String playerName, int lotNumber) {
- for (Iterator<InnectisLot> it = getLots().values().iterator(); it.hasNext();) {
- - lot = it.next();
- + InnectisLot lot = it.next();
- +
- if (lot.getLotNumber() == lotNumber) {
- // Check for exact match
- - if (lot.getOwner().equalsIgnoreCase(owner)) {
- + if (lot.getOwner().equalsIgnoreCase(playerName)) {
- return lot;
- }
- -
- - // Check for partial matches
- - if (partialMatchStart == null && owner.length() > 1
- - && lot.getOwner().length() >= owner.length()
- - && lot.getOwner().toLowerCase().substring(0, owner.length()).equalsIgnoreCase(owner.toLowerCase())) {
- -
- - partialMatchStart = lot;
- - } else if (partialMatchAny == null && owner.length() > 1
- - && lot.getOwner().length() >= owner.length()
- - && lot.getOwner().toLowerCase().contains(owner.toLowerCase())) {
- - partialMatchAny = lot;
- - }
- }
- }
- - // Check if there is a partial match on string start.
- - if (partialMatchStart != null) {
- - return partialMatchStart;
- - }
- - return partialMatchAny;
- +
- + return null;
- }
- /**
- - * This will look for a lot with the given owner and the given lotname
- - * @param owner
- - * The owner's name, either be the exact name or a partial name.
- + * This will look for a lot with the given owner by ID and the given lotname
- + * @param playerName
- + * The owner's ID
- * @param lotName
- * The exact name of the lot
- * @return
- */
- - public static InnectisLot getLot(String owner, String lotName) {
- - InnectisLot lot, partialMatchStart = null, partialMatchAny = null;
- + public static InnectisLot getLot(String playerName, String lotName) {
- for (Iterator<InnectisLot> it = getLots().values().iterator(); it.hasNext();) {
- - lot = it.next();
- + InnectisLot lot = it.next();
- if (lot.getLotName().equalsIgnoreCase(lotName)) {
- -
- // Check exact match
- - if (lot.getOwner().equalsIgnoreCase(owner)) {
- + if (lot.getOwner().equalsIgnoreCase(playerName)) {
- return lot;
- }
- -
- - // Check partial match
- - if (partialMatchStart == null && owner.length() > 1
- - && lot.getOwner().length() >= owner.length()
- - && lot.getOwner().toLowerCase().substring(0, owner.length()).equalsIgnoreCase(owner.toLowerCase())) {
- -
- - partialMatchStart = lot;
- - } else if (partialMatchAny == null && owner.length() > 1
- - && lot.getOwner().length() >= owner.length()
- - && lot.getOwner().toLowerCase().contains(owner.toLowerCase())) {
- -
- - partialMatchAny = lot;
- - }
- }
- }
- - // Check if there is a partial match on string start.
- - if (partialMatchStart != null) {
- - return partialMatchStart;
- - }
- - return partialMatchAny;
- +
- + return null;
- }
- /**
- @@ -511,44 +528,26 @@ public final class LotHandler {
- /**
- * This will return a list with all lots that are owned by the player with the given name.
- - * @param owner
- + * @param playerName
- * @return
- */
- - public static List<InnectisLot> getLots(String owner) {
- + public static List<InnectisLot> getLots(String playerName) {
- List<InnectisLot> lots = new ArrayList<InnectisLot>();
- InnectisLot lot;
- - String ownerMatchStart = null, ownerMatchAny = null;
- // Find all lots that match the given name (partial or exact).
- for (Iterator<InnectisLot> it = getLots().values().iterator(); it.hasNext();) {
- lot = it.next();
- - if (lot.getOwner().equalsIgnoreCase(owner)) {
- + if (lot.getOwner().equalsIgnoreCase(playerName)) {
- lots.add(lot);
- - } else if (ownerMatchStart != null
- - && lot.getOwner().length() >= owner.length()
- - && lot.getOwner().toLowerCase().substring(0, owner.length()).equalsIgnoreCase(owner.toLowerCase())) {
- - ownerMatchStart = lot.getOwner();
- - } else if (ownerMatchAny != null
- - && lot.getOwner().length() >= owner.length()
- - && lot.getOwner().toLowerCase().contains(owner.toLowerCase())) {
- - ownerMatchAny = lot.getOwner();
- - }
- - }
- -
- - // If no lots found, check for partial matches
- - if (lots.isEmpty()) {
- - if (ownerMatchStart != null) {
- - return getLots(ownerMatchStart);
- - } else if (ownerMatchAny != null) {
- - return getLots(ownerMatchAny);
- }
- - return null;
- }
- // Sort if bigger then 1
- if (lots.size() > 1) {
- Collections.sort(lots, getLotNumberComparator());
- }
- +
- return lots;
- }
- @@ -740,7 +739,7 @@ public final class LotHandler {
- * Removes the lot with the given id from the database.
- * <p/>
- * This will not remove sublots that are not owned by the owner of the removed lot.
- - * @param lot
- + * @param lotId
- * @return
- * @throws SQLException
- */
- @@ -805,6 +804,7 @@ public final class LotHandler {
- return remCount;
- }
- +
- return 0;
- }
- //</editor-fold>
- @@ -813,44 +813,47 @@ public final class LotHandler {
- /**
- * Randomly assigns a lot the the given player
- *
- - * @param name - name of the player
- + * @param ownerCredentials credentials of the player the lot will be assigned to
- * @return InnectisLot - the newly created lot
- * @throws SQLException - Is thrown when something happens when saving the
- * lot in the database.
- */
- - public static InnectisLot assignLot(String name) throws SQLException {
- - return assignLot(name, getLot(ASSIGNABLE_LOT_OWNER, 1));
- + public static InnectisLot assignLot(PlayerCredentials ownerCredentials) throws SQLException {
- + return assignLot(ownerCredentials, getLot(ASSIGNABLE_LOT_OWNER, 1));
- }
- /**
- * Assigns the given lot the player with the given name
- *
- - * @param name - name of the player
- + * @param ownerCredentials - name of the player
- * @param lot - The lot that needs to be assigned to the player
- * @return InnectisLot - the newly created lot
- * @throws SQLException - Is thrown when something happens when saving the
- * lot in the database.
- */
- - public static InnectisLot assignLot(String name, InnectisLot lot) throws SQLException {
- + public static InnectisLot assignLot(PlayerCredentials ownerCredentials, InnectisLot lot) throws SQLException {
- if (lot == null) {
- return null;
- }
- - lot.setOwner(name);
- + String name = ownerCredentials.getName();
- + lot.setOwner(ownerCredentials);
- lot.setLotNumber(0);
- lot.save();
- InnPlugin.logInfo("Assigning lot #" + lot.getId() + " to " + name);
- - LotHandler.cleanLots(name);
- + LotHandler.cleanLots(ownerCredentials.getName());
- fixLotNumber(ASSIGNABLE_LOT_OWNER); //reorder lotnr for available lots
- - IdpPlayer target = InnPlugin.getPlugin().getPlayer(name, true);
- + IdpPlayer target = InnPlugin.getPlugin().getPlayer(ownerCredentials.getUniqueId());
- +
- if (target != null) {
- name = target.getName();
- target.printInfo("You have been assigned a lot!");
- target.printInfo("Type " + ChatColor.AQUA + "/mylot" + (lot.getLotNumber() > 1 ? " " + lot.getLotNumber() : "") + ChatColor.GREEN + " to go to it.");
- target.teleport(lot.getSpawn());
- }
- +
- InnPlugin.getPlugin().sendModeratorMessage(null, "Lot #" + lot.getId() + " assigned to " + name);
- return lot;
- @@ -859,31 +862,31 @@ public final class LotHandler {
- //<editor-fold defaultstate="collapsed" desc="Get lotcount">
- /**
- - * Gets the amount of lots the given name has. <b>This will not count
- + * Gets the amount of lots the given player has. <b>This will not count
- * sublots.</b>
- *
- - * @param name
- - * @return The amount of lots the given name has
- + * @param playerName
- + * @return The amount of lots the given player by ID has
- */
- - public static int getLotCount(String name) {
- - return getLotCount(name, 0);
- + public static int getLotCount(String playerName) {
- + return getLotCount(playerName, 0);
- }
- /**
- - * Gets the amount of lots the given name has. <b>This will not count
- + * Gets the amount of lots the given player by ID has. <b>This will not count
- * sublots.</b>
- *
- - * @param name
- + * @param playerName
- * @param sublotCount - acts as an output parameter. This value will be set
- - * to the amount of sublots the 'name' has. Doesn't matter if the 'name' is
- + * to the amount of sublots the player by ID has. Doesn't matter if the 'name' is
- * the owner of the parent or not.
- * @return The amount of lots the given name has
- */
- - public static int getLotCount(String name, int sublotCount) {
- + public static int getLotCount(String playerName, int sublotCount) {
- int count = 0;
- sublotCount = 0;
- - List<InnectisLot> lots = getLots(name);
- + List<InnectisLot> lots = getLots(playerName);
- if (lots != null) {
- for (InnectisLot lot : lots) {
- @@ -947,17 +950,17 @@ public final class LotHandler {
- /**
- * This will recount the lotnumbers and set the correctly.
- - * @param owner
- + * @param playerName
- * The owner of the lots
- */
- - private static void fixLotNumber(String owner) {
- + private static void fixLotNumber(String playerName) {
- // Do Hretsam's lot differently
- - if (owner.equalsIgnoreCase("Hretsam")) {
- - fixHretLotNumber(owner);
- + if (playerName.equalsIgnoreCase("hretsam")) {
- + fixHretLotNumber(playerName);
- return;
- }
- - List<InnectisLot> lots = getLots(owner);
- + List<InnectisLot> lots = getLots(playerName);
- InnectisLot lot;
- int curI = 1;
- @@ -986,10 +989,10 @@ public final class LotHandler {
- /**
- * Alt method for setting lotnumber for 'Hretsam'.
- - * @param owner
- + * @param playerName
- */
- - private static void fixHretLotNumber(String owner) {
- - List<InnectisLot> lots = getLots(owner);
- + private static void fixHretLotNumber(String playerName) {
- + List<InnectisLot> lots = getLots(playerName);
- InnectisLot lot;
- int normalInx = 1;
- @@ -1104,13 +1107,13 @@ public final class LotHandler {
- * @param world
- * @param point1
- * @param point2
- - * @param owner
- - * @param creator
- + * @param ownerCredentials
- + * @param creatorCredentials
- * @return
- * @throws SQLException
- */
- - public static InnectisLot addLot(World world, Vector point1, Vector point2, String owner, String creator) throws SQLException {
- - InnectisLot lot = new InnectisLot(world, point1, point2, owner, creator, mainLot);
- + public static InnectisLot addLot(World world, Vector point1, Vector point2, PlayerCredentials ownerCredentials, PlayerCredentials creatorCredentials) throws SQLException {
- + InnectisLot lot = new InnectisLot(world, point1, point2, ownerCredentials, creatorCredentials, mainLot);
- lot.save();
- LotHandler.getLots().put(lot.getId(), lot);
- @@ -1178,7 +1181,7 @@ public final class LotHandler {
- saveLots();
- }
- -
- +
- return true;
- }
- diff --git a/src/net/innectis/innplugin/OwnedObjects/Handlers/OwnedEntityHandler.java b/src/net/innectis/innplugin/OwnedObjects/Handlers/OwnedEntityHandler.java
- index bfdbaa3be..04f4e3e74 100644
- --- a/src/net/innectis/innplugin/OwnedObjects/Handlers/OwnedEntityHandler.java
- +++ b/src/net/innectis/innplugin/OwnedObjects/Handlers/OwnedEntityHandler.java
- @@ -9,6 +9,8 @@ import java.util.UUID;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.OwnedObjects.OwnedEntity;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import org.bukkit.entity.EntityType;
- /**
- @@ -31,19 +33,21 @@ public class OwnedEntityHandler {
- ResultSet set = null;
- try {
- - statement = DBManager.prepareStatement("SELECT * FROM owned_entities");
- + statement = DBManager.prepareStatement("SELECT * FROM owned_entities;");
- set = statement.executeQuery();
- while (set.next()) {
- - String owner = set.getString("owner");
- + String playerIdString = set.getString("owner_id");
- + UUID playerId = UUID.fromString(playerIdString);
- + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(playerId, true);
- EntityType type = EntityType.fromId(set.getInt("entityid"));
- long mostSigBits = set.getLong("mostsigbits");
- long leastSigBits = set.getLong("leastsigbits");
- - UUID uniqueId = new UUID(mostSigBits, leastSigBits);
- + UUID ownedEntityId = new UUID(mostSigBits, leastSigBits);
- - OwnedEntity ownedEntity = new OwnedEntity(owner, type);
- - ownedEntities.put(uniqueId, ownedEntity);
- + OwnedEntity ownedEntity = new OwnedEntity(credentials, type);
- + ownedEntities.put(ownedEntityId, ownedEntity);
- }
- } catch (SQLException ex) {
- InnPlugin.logError("COULD NOT GET OWNED ENTITIES FROM DATABASE!", ex);
- @@ -67,22 +71,22 @@ public class OwnedEntityHandler {
- /**
- * Adds an owned entity to the list
- - * @param uniqueId
- - * @param owner
- + * @param entityId
- + * @param ownerCredentials
- * @param type
- */
- - public static void addOwnedEntity(UUID uniqueId, String owner, EntityType type) {
- - OwnedEntity ownedEntity = new OwnedEntity(owner, type);
- - ownedEntities.put(uniqueId, ownedEntity);
- + public static void addOwnedEntity(UUID entityId, PlayerCredentials ownerCredentials, EntityType type) {
- + OwnedEntity ownedEntity = new OwnedEntity(ownerCredentials ,type);
- + ownedEntities.put(entityId, ownedEntity);
- - long mostSigBits = uniqueId.getMostSignificantBits();
- - long leastSigBits = uniqueId.getLeastSignificantBits();
- + long mostSigBits = entityId.getMostSignificantBits();
- + long leastSigBits = entityId.getLeastSignificantBits();
- PreparedStatement statement = null;
- try {
- - statement = DBManager.prepareStatement("INSERT INTO owned_entities VALUES (?, ?, ?, ?)");
- - statement.setString(1, owner);
- + statement = DBManager.prepareStatement("INSERT INTO owned_entities (owner_id, entityid, mostsigbits, leastsigbits) VALUES (?, ?, ?, ?);");
- + statement.setString(1, ownerCredentials.getUniqueId().toString());
- statement.setInt(2, type.getTypeId());
- statement.setLong(3, mostSigBits);
- statement.setLong(4, leastSigBits);
- @@ -95,25 +99,24 @@ public class OwnedEntityHandler {
- }
- /**
- - * Removes the specified owned entity from the database
- - * @param uniqueId
- - * @param type
- + * Removes the specified owned entityId from the database
- + * @param entityId
- */
- - public static void removeOwnedEntity(UUID uniqueId) {
- - OwnedEntity ownedEntity = ownedEntities.remove(uniqueId);
- + public static void removeOwnedEntity(UUID entityId) {
- + OwnedEntity ownedEntity = ownedEntities.remove(entityId);
- // Doesn't exist, so don't attempt to remove
- if (ownedEntity == null) {
- return;
- }
- - long mostSigBits = uniqueId.getMostSignificantBits();
- - long leastSigBits = uniqueId.getLeastSignificantBits();
- + long mostSigBits = entityId.getMostSignificantBits();
- + long leastSigBits = entityId.getLeastSignificantBits();
- PreparedStatement statement = null;
- try {
- - statement = DBManager.prepareStatement("DELETE FROM owned_entities WHERE mostsigbits = ? AND leastsigbits = ?");
- + statement = DBManager.prepareStatement("DELETE FROM owned_entities WHERE mostsigbits = ? AND leastsigbits = ?;");
- statement.setLong(1, mostSigBits);
- statement.setLong(2, leastSigBits);
- statement.execute();
- diff --git a/src/net/innectis/innplugin/OwnedObjects/Handlers/TrapdoorHandler.java b/src/net/innectis/innplugin/OwnedObjects/Handlers/TrapdoorHandler.java
- index c1574a449..a64638fc7 100644
- --- a/src/net/innectis/innplugin/OwnedObjects/Handlers/TrapdoorHandler.java
- +++ b/src/net/innectis/innplugin/OwnedObjects/Handlers/TrapdoorHandler.java
- @@ -6,9 +6,13 @@ import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- +import java.util.UUID;
- +import net.innectis.innplugin.Configuration;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.OwnedObjects.InnectisTrapdoor;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.World;
- @@ -19,7 +23,6 @@ import org.bukkit.World;
- * @author AlphaBlend
- */
- public class TrapdoorHandler {
- -
- private static HashMap<Integer, InnectisTrapdoor> trapdoors = new HashMap<Integer, InnectisTrapdoor>();
- public TrapdoorHandler() {
- @@ -29,20 +32,20 @@ public class TrapdoorHandler {
- * Adds a new trapdoor to the list of trapdoors
- * @param world
- * @param loc
- - * @param owner
- + * @param ownerCredentials
- * @return The owned Trapdoor object
- * @throws SQLException
- */
- - public static InnectisTrapdoor createTrapdoor(World world, Location loc, String owner) throws SQLException {
- + public static InnectisTrapdoor createTrapdoor(World world, Location loc, PlayerCredentials ownerCredentials) throws SQLException {
- // Allow placement, original owner is assumed
- if (isTrapdoorAtLocation(loc)) {
- return null;
- }
- - List<String> members = new ArrayList<String>();
- - members.add("%");
- + List<PlayerCredentials> members = new ArrayList<PlayerCredentials>();
- + members.add(Configuration.EVERYONE_CREDENTIALS);
- - InnectisTrapdoor trapdoor = new InnectisTrapdoor(world, loc, 0, owner, members, null, 0);
- + InnectisTrapdoor trapdoor = new InnectisTrapdoor(world, loc, 0, ownerCredentials, members, null, 0);
- trapdoor.save();
- trapdoors.put(trapdoor.getId(), trapdoor);
- return trapdoor;
- @@ -115,14 +118,14 @@ public class TrapdoorHandler {
- /**
- * Gets the trapdoors owned by the specified owner
- - * @param owner
- + * @param playerName
- * @return
- */
- - public static List<InnectisTrapdoor> getTrapdoors(String owner) {
- + public static List<InnectisTrapdoor> getTrapdoors(String playerName) {
- List<InnectisTrapdoor> tdlist = new ArrayList<InnectisTrapdoor>();
- for (InnectisTrapdoor trapdoor : trapdoors.values()) {
- - if (trapdoor.getOwner().equalsIgnoreCase(owner)) {
- + if (trapdoor.getOwner().equalsIgnoreCase(playerName)) {
- tdlist.add(trapdoor);
- }
- }
- @@ -150,7 +153,9 @@ public class TrapdoorHandler {
- */
- public static boolean loadTrapdoors() {
- PreparedStatement statement = null;
- + PreparedStatement statement2 = null;
- ResultSet set = null;
- + ResultSet set2 = null;
- try {
- // First, load all the trapdoors into memory
- @@ -162,7 +167,10 @@ public class TrapdoorHandler {
- if (world != null) {
- int id = set.getInt("trapdoorid");
- - String owner = set.getString("owner");
- +
- + String ownerIdString = set.getString("owner_id");
- + UUID ownerId = UUID.fromString(ownerIdString);
- + PlayerCredentials ownerCredentials = PlayerCredentialsManager.getByUniqueId(ownerId, true);
- int x = set.getInt("locx");
- int y = set.getInt("locy");
- @@ -171,26 +179,39 @@ public class TrapdoorHandler {
- long flags = set.getLong("flags");
- - DBManager.closeResultSet(set);
- - DBManager.closePreparedStatement(statement);
- -
- // Load the members of the trapdoor
- - statement = DBManager.prepareStatement("SELECT username, isop FROM trapdoors_members WHERE trapdoorid = ?;");
- - statement.setInt(1, id);
- - set = statement.executeQuery();
- + statement2 = DBManager.prepareStatement("SELECT player_id, isop FROM trapdoors_members WHERE trapdoorid = ?;");
- + statement2.setInt(1, id);
- + set2 = statement2.executeQuery();
- +
- + List<PlayerCredentials> members = new ArrayList<PlayerCredentials>();
- + List<PlayerCredentials> operators = new ArrayList<PlayerCredentials>();
- - List<String> members = new ArrayList<String>();
- - List<String> operators = new ArrayList<String>();
- + while (set2.next()) {
- + String memberIdString = set2.getString("player_id");
- + UUID memberId = UUID.fromString(memberIdString);
- - while (set.next()) {
- - if (set.getBoolean("isop")) {
- - operators.add(set.getString("username"));
- + if (memberId.equals(Configuration.EVERYONE_IDENTIFIER)) {
- + members.add(Configuration.EVERYONE_CREDENTIALS);
- + } else if (memberId.equals(Configuration.LOT_ACCESS_IDENTIFIER)) {
- + members.add(Configuration.LOT_ACCESS_CREDENTIALS);
- } else {
- - members.add(set.getString("username"));
- + boolean isOp = set2.getBoolean("isop");
- +
- + PlayerCredentials memberCredentials = PlayerCredentialsManager.getByUniqueId(memberId, true);
- +
- + if (isOp) {
- + operators.add(memberCredentials);
- + } else {
- + members.add(memberCredentials);
- + }
- }
- }
- - trapdoors.put(id, new InnectisTrapdoor(world, loc, id, owner, members, operators, flags));
- + DBManager.closeResultSet(set2);
- + DBManager.closePreparedStatement(statement2);
- +
- + trapdoors.put(id, new InnectisTrapdoor(world, loc, id, ownerCredentials, members, operators, flags));
- }
- }
- } catch (SQLException ex) {
- @@ -198,7 +219,9 @@ public class TrapdoorHandler {
- return false;
- } finally {
- DBManager.closeResultSet(set);
- + DBManager.closeResultSet(set2);
- DBManager.closePreparedStatement(statement);
- + DBManager.closePreparedStatement(statement2);
- }
- return true;
- diff --git a/src/net/innectis/innplugin/OwnedObjects/Handlers/WaypointHandler.java b/src/net/innectis/innplugin/OwnedObjects/Handlers/WaypointHandler.java
- index e1d9a9f18..18e42f3e7 100644
- --- a/src/net/innectis/innplugin/OwnedObjects/Handlers/WaypointHandler.java
- +++ b/src/net/innectis/innplugin/OwnedObjects/Handlers/WaypointHandler.java
- @@ -7,6 +7,8 @@ import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.List;
- +import java.util.UUID;
- +import net.innectis.innplugin.Configuration;
- import net.innectis.innplugin.Handlers.BlockHandler;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- @@ -16,6 +18,8 @@ import net.innectis.innplugin.OwnedObjects.InnectisWaypoint;
- import net.innectis.innplugin.Player.Chat.ChatColor;
- import net.innectis.innplugin.Player.IdpPlayer;
- import net.innectis.innplugin.Player.Permission;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.World;
- @@ -121,12 +125,14 @@ public class WaypointHandler {
- return null;
- }
- - public static List<InnectisWaypoint> getWaypoints(String owner) {
- + public static List<InnectisWaypoint> getWaypoints(String playerName) {
- List<InnectisWaypoint> waypoints = new ArrayList<InnectisWaypoint>();
- InnectisWaypoint waypoint;
- +
- for (Iterator<InnectisWaypoint> it = getWaypoints().values().iterator(); it.hasNext();) {
- waypoint = it.next();
- - if (waypoint.getOwner().equalsIgnoreCase(owner)) {
- +
- + if (waypoint.getOwner().equalsIgnoreCase(playerName)) {
- waypoints.add(waypoint);
- }
- }
- @@ -156,48 +162,71 @@ public class WaypointHandler {
- return null;
- }
- - PreparedStatement statement = DBManager.prepareStatement("SELECT username, isop FROM waypoints_members WHERE waypointid = ?;");
- + String ownerIdString = result.getString("owner_id");
- + UUID ownerId = UUID.fromString(ownerIdString);
- + PlayerCredentials ownerCredentials = PlayerCredentialsManager.getByUniqueId(ownerId, true);
- +
- + PreparedStatement statement = DBManager.prepareStatement("SELECT player_id, isop FROM waypoints_members WHERE waypointid = ?;");
- statement.setInt(1, result.getInt("waypointid"));
- ResultSet result2 = statement.executeQuery();
- - List<String> members = new ArrayList<String>();
- - List<String> operators = new ArrayList<String>();
- +
- + List<PlayerCredentials> members = new ArrayList<PlayerCredentials>();
- + List<PlayerCredentials> operators = new ArrayList<PlayerCredentials>();
- +
- while (result2.next()) {
- - if (result2.getBoolean("isop")) {
- - operators.add(result2.getString("username"));
- + String memberIdString = result2.getString("player_id");
- + UUID memberId = UUID.fromString(memberIdString);
- +
- + if (memberId.equals(Configuration.EVERYONE_IDENTIFIER)) {
- + members.add(Configuration.EVERYONE_CREDENTIALS);
- + } else if (memberId.equals(Configuration.LOT_ACCESS_IDENTIFIER)) {
- + members.add(Configuration.LOT_ACCESS_CREDENTIALS);
- } else {
- - members.add(result2.getString("username"));
- + boolean isOp = result2.getBoolean("isop");
- +
- + PlayerCredentials memberCredentials = PlayerCredentialsManager.getByUniqueId(memberId, true);
- +
- + if (isOp) {
- + operators.add(memberCredentials);
- + } else {
- + members.add(memberCredentials);
- + }
- }
- }
- DBManager.closeResultSet(result2);
- DBManager.closePreparedStatement(statement);
- - return new InnectisWaypoint(world, waypoint, destination, result.getInt("waypointid"), result.getString("owner"), members, operators, result.getLong("flags"), result.getBoolean("forced"));
- + return new InnectisWaypoint(world, waypoint, destination, result.getInt("waypointid"), ownerCredentials, members, operators, result.getLong("flags"), result.getBoolean("forced"));
- }
- - public static boolean hasWaypoint(IdpPlayer player) {
- + public static boolean hasWaypoint(String playerName) {
- InnectisWaypoint waypoint;
- for (Iterator<InnectisWaypoint> it = getWaypoints().values().iterator(); it.hasNext();) {
- waypoint = it.next();
- - if (waypoint.getOwner().equalsIgnoreCase(player.getName())) {
- +
- + if (waypoint.getOwner().equalsIgnoreCase(playerName)) {
- return true;
- }
- }
- return false;
- }
- - public static boolean isOwnWaypoint(IdpPlayer player, Location location) {
- + public static boolean isOwnWaypoint(String playerName, Location location) {
- InnectisWaypoint waypoint = getWaypoint(location);
- +
- if (waypoint == null) {
- return false;
- }
- - if (waypoint.getOwner().equalsIgnoreCase(player.getName())) {
- +
- + if (waypoint.getOwner().equalsIgnoreCase(playerName)) {
- return true;
- }
- +
- return false;
- }
- - public static InnectisWaypoint createWaypoint(IdpPlayer player, Block block, boolean force) throws SQLException {
- + public static InnectisWaypoint createWaypoint(PlayerCredentials ownerCredentials, Block block, boolean force) throws SQLException {
- Location loc = block.getLocation();
- InnectisWaypoint existingWaypoint = getWaypoint(loc);
- @@ -206,35 +235,10 @@ public class WaypointHandler {
- return existingWaypoint;
- }
- - InnectisWaypoint innwaypoint = new InnectisWaypoint(block.getWorld(), block, loc, -1, player.getName(), null, null, 0, force);
- - innwaypoint.addMember("%");
- - innwaypoint.save();
- - WaypointHandler.getWaypoints().put(innwaypoint.getId(), innwaypoint);
- -
- - BlockHandler.setBlock(block, IdpMaterial.WAYPOINT);
- -
- - return innwaypoint;
- - }
- -
- - /**
- - * Creates a waypoint at the given location
- - * @param playername
- - * @param block
- - * @return
- - * The waypoint if success else null
- - * @throws SQLException
- - */
- - public static InnectisWaypoint createWaypoint(String playername, Block block, boolean force) throws SQLException {
- - Location loc = block.getLocation();
- - InnectisWaypoint existingWaypoint = getWaypoint(loc);
- -
- - // Allow placement, original owner is assumed
- - if (existingWaypoint != null) {
- - return existingWaypoint;
- - }
- + List<PlayerCredentials> members = new ArrayList<PlayerCredentials>();
- + members.add(Configuration.EVERYONE_CREDENTIALS);
- - InnectisWaypoint innwaypoint = new InnectisWaypoint(block.getWorld(), block, loc, -1, playername, null, null, 0, force);
- - innwaypoint.addMember("%");
- + InnectisWaypoint innwaypoint = new InnectisWaypoint(block.getWorld(), block, loc, -1, ownerCredentials, members, null, 0, force);
- innwaypoint.save();
- WaypointHandler.getWaypoints().put(innwaypoint.getId(), innwaypoint);
- diff --git a/src/net/innectis/innplugin/OwnedObjects/InnectisBookcase.java b/src/net/innectis/innplugin/OwnedObjects/InnectisBookcase.java
- index 8f8db1996..ed7b446df 100644
- --- a/src/net/innectis/innplugin/OwnedObjects/InnectisBookcase.java
- +++ b/src/net/innectis/innplugin/OwnedObjects/InnectisBookcase.java
- @@ -5,16 +5,17 @@ import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- -import java.util.Arrays;
- import java.util.List;
- +import java.util.UUID;
- +import net.innectis.innplugin.Configuration;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.Items.IdpItemStack;
- import net.innectis.innplugin.Items.IdpMaterial;
- import net.innectis.innplugin.Items.StackBag;
- import net.innectis.innplugin.OwnedObjects.Handlers.LotHandler;
- -import net.innectis.innplugin.Player.IdpPlayer;
- -import net.innectis.innplugin.Utility.StringUtil;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.World;
- @@ -25,7 +26,7 @@ import org.bukkit.block.Block;
- * @author Hretsam
- *
- */
- -public class InnectisBookcase extends InnectisOwnedObject<Long> {
- +public class InnectisBookcase extends InnectisOwnedObject {
- private Block bookcase;
- private long bagid;
- private IdpItemStack[] items = null;
- @@ -35,19 +36,19 @@ public class InnectisBookcase extends InnectisOwnedObject<Long> {
- * Makes a new InnectisBookcase object
- * @param world
- * @param bookcase
- - * @param owner
- + * @param ownerCredentials
- */
- - public InnectisBookcase(World world, Block bookcase, String owner) {
- - super(world, bookcase.getLocation().toVector(), bookcase.getLocation().toVector(), -1l, owner, new ArrayList<String>(0), new ArrayList<String>(0), 0);
- + public InnectisBookcase(World world, Block bookcase, PlayerCredentials ownerCredentials) {
- + super(world, bookcase.getLocation().toVector(), bookcase.getLocation().toVector(), -1, ownerCredentials, new ArrayList<PlayerCredentials>(0), new ArrayList<PlayerCredentials>(0), 0);
- this.bookcase = bookcase;
- - this.caseTitle = "Bookcase";
- - this.bagid = -1l;
- + caseTitle = "Bookcase";
- + bagid = -1l;
- }
- - private InnectisBookcase(World world, Block bookcase, long id, long bagid, String owner, String casetitle, List<String> members, List<String> operators, long flags) {
- - super(world, bookcase.getLocation().toVector(), bookcase.getLocation().toVector(), id, owner, members, operators, flags);
- + private InnectisBookcase(World world, Block bookcase, int id, long bagid, PlayerCredentials ownerCredentials, String caseTitle, List<PlayerCredentials> members, List<PlayerCredentials> operators, long flags) {
- + super(world, bookcase.getLocation().toVector(), bookcase.getLocation().toVector(), id, ownerCredentials, members, operators, flags);
- this.bookcase = bookcase;
- - this.caseTitle = casetitle;
- + this.caseTitle = caseTitle;
- this.bagid = bagid;
- }
- @@ -73,11 +74,11 @@ public class InnectisBookcase extends InnectisOwnedObject<Long> {
- */
- public void setCaseTitle(String caseTitle) {
- this.caseTitle = caseTitle;
- - setUpdated(true);
- + super.setUpdated(true);
- }
- public Block getBookcase() {
- - return this.bookcase;
- + return bookcase;
- }
- /**
- @@ -109,7 +110,7 @@ public class InnectisBookcase extends InnectisOwnedObject<Long> {
- */
- public void setItems(IdpItemStack[] items) {
- this.items = items;
- - setUpdated(true);
- + super.setUpdated(true);
- }
- /**
- @@ -126,7 +127,7 @@ public class InnectisBookcase extends InnectisOwnedObject<Long> {
- for (int i = 0; i < getItems().length; i++) {
- if (getItem(i) == null || getItem(i).getMaterial() == IdpMaterial.AIR) {
- items[i] = item;
- - setUpdated(true);
- + super.setUpdated(true);
- return true;
- }
- }
- @@ -167,13 +168,14 @@ public class InnectisBookcase extends InnectisOwnedObject<Long> {
- * @param player
- */
- @Override
- - public boolean canPlayerAccess(IdpPlayer player) {
- - if (super.canPlayerAccess(player)) {
- + public boolean canPlayerAccess(String playerName) {
- + if (super.canPlayerAccess(playerName)) {
- return true;
- }
- +
- if (containsMember("@")) { //allow lot members
- InnectisLot lot = LotHandler.getLot(bookcase.getLocation());
- - if (lot != null && (lot.containsMember(player.getName()) || lot.containsOperator(player.getName()))) {
- + if (lot != null && (lot.containsMember(playerName) || lot.containsOperator(playerName))) {
- return true;
- }
- }
- @@ -191,21 +193,21 @@ public class InnectisBookcase extends InnectisOwnedObject<Long> {
- try {
- statement = DBManager.prepareStatementWithAutoGeneratedKeys("REPLACE INTO bookcase "
- - + "(bagid, owner, world, locx, locy, locz, flags, casetitle) VALUES (?,?,?,?,?,?,?,?) ");
- + + "(bagid, owner_id, world, locx, locy, locz, flags, casetitle) VALUES (?,?,?,?,?,?,?,?);");
- statement.setLong(1, bagid);
- - statement.setString(2, getOwner());
- - statement.setString(3, getWorld().getName());
- + statement.setString(2, super.getOwnerCredentials().getUniqueId().toString());
- + statement.setString(3, super.getWorld().getName());
- statement.setInt(4, getBookcase().getX());
- statement.setInt(5, getBookcase().getY());
- statement.setInt(6, getBookcase().getZ());
- - statement.setLong(7, getFlags());
- + statement.setLong(7, super.getFlags());
- statement.setString(8, getCaseTitle());
- statement.executeUpdate();
- result = statement.getGeneratedKeys();
- if (result.next()) {
- - setId(result.getLong(1));
- - setUpdated(false);
- + setId(result.getInt(1));
- + super.setUpdated(false);
- } else {
- InnPlugin.logError("New bookcase not found in the database!");
- return false;
- @@ -240,43 +242,43 @@ public class InnectisBookcase extends InnectisOwnedObject<Long> {
- conn.setAutoCommit(false);
- statement = conn.prepareStatement(
- - "UPDATE bookcase SET bagid = ?, owner = ?, world = ?, locx = ?, "
- - + "locy = ?, locz = ?, flags = ?, casetitle = ? WHERE bookcaseid = ? ");
- + "UPDATE bookcase SET bagid = ?, owner_id = ?, world = ?, locx = ?, "
- + + "locy = ?, locz = ?, flags = ?, casetitle = ? WHERE bookcaseid = ?;");
- statement.setLong(1, bagid);
- - statement.setString(2, getOwner());
- - statement.setString(3, getWorld().getName());
- + statement.setString(2, super.getOwnerCredentials().getUniqueId().toString());
- + statement.setString(3, super.getWorld().getName());
- statement.setInt(4, getBookcase().getX());
- statement.setInt(5, getBookcase().getY());
- statement.setInt(6, getBookcase().getZ());
- - statement.setLong(7, getFlags());
- + statement.setLong(7, super.getFlags());
- statement.setString(8, getCaseTitle());
- - statement.setLong(9, getId());
- + statement.setInt(9, super.getId());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- statement = conn.prepareStatement("DELETE FROM bookcase_members WHERE bookcaseid = ?; ");
- - statement.setLong(1, getId());
- + statement.setLong(1, super.getId());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- - for (String s : getMembers()) {
- - statement = conn.prepareStatement("INSERT INTO bookcase_members (bookcaseid, username, isop) VALUES (?, ?, 0);");
- - statement.setLong(1, getId());
- - statement.setString(2, s);
- + for (PlayerCredentials pc : super.getMembers()) {
- + statement = conn.prepareStatement("INSERT INTO bookcase_members (bookcaseid, player_id, isop) VALUES (?, ?, 0);");
- + statement.setInt(1, super.getId());
- + statement.setString(2, pc.getUniqueId().toString());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- }
- - for (String s : getOperators()) {
- - statement = conn.prepareStatement("INSERT INTO bookcase_members (bookcaseid, username, isop) VALUES (?, ?, 1);");
- - statement.setLong(1, getId());
- - statement.setString(2, s);
- + for (PlayerCredentials pc : super.getOperators()) {
- + statement = conn.prepareStatement("INSERT INTO bookcase_members (bookcaseid, player_id, isop) VALUES (?, ?, 1);");
- + statement.setInt(1, super.getId());
- + statement.setString(2, pc.getUniqueId().toString());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- }
- conn.commit();
- - setUpdated(false);
- + super.setUpdated(false);
- } catch (SQLException ex) {
- InnPlugin.logError("Unable to save bookcase!", ex);
- return false;
- @@ -301,19 +303,19 @@ public class InnectisBookcase extends InnectisOwnedObject<Long> {
- * @param bookcaseid
- * @return the bookcase or null if not found
- */
- - public static InnectisBookcase getBookcase(long bookcaseid) {
- + public static InnectisBookcase getBookcase(int bookcaseid) {
- PreparedStatement statement = null;
- ResultSet set = null;
- try {
- statement = DBManager.prepareStatement(""
- - + "SELECT b.bookcaseid, bagid, owner, world, locx, locy, locz, flags, casetitle, "
- - + " (SELECT group_concat(bmem.username SEPARATOR ';') "
- - + " FROM bookcase_members as bmem where b.bookcaseid = bmem.bookcaseid and isop = 0 ) as members, "
- - + " (SELECT group_concat(bop.username SEPARATOR ';') "
- - + " FROM bookcase_members as bop where b.bookcaseid = bop.bookcaseid and isop = 1 ) as operators "
- - + "FROM bookcase as b WHERE b.bookcaseid = ? ");
- - statement.setLong(1, bookcaseid);
- + + "SELECT b.bookcaseid, bagid, owner_id, world, locx, locy, locz, flags, casetitle, "
- + + " (SELECT group_concat(bmem.owner_id SEPARATOR ';') "
- + + " FROM bookcase_members as bmem where b.bookcaseid = bmem.bookcaseid and isop = 0 ) as member_id_list, "
- + + " (SELECT group_concat(bop.player_id SEPARATOR ';') "
- + + " FROM bookcase_members as bop where b.bookcaseid = bop.bookcaseid and isop = 1 ) as operator_id_list "
- + + "FROM bookcase as b WHERE b.bookcaseid = ?;");
- + statement.setInt(1, bookcaseid);
- set = statement.executeQuery();
- if (set.next()) {
- @@ -340,12 +342,12 @@ public class InnectisBookcase extends InnectisOwnedObject<Long> {
- try {
- statement = DBManager.prepareStatement(""
- - + "SELECT b.bookcaseid, bagid, owner, world, locx, locy, locz, flags, casetitle, "
- - + " (SELECT group_concat(bmem.username SEPARATOR ';') "
- - + " FROM bookcase_members as bmem where b.bookcaseid = bmem.bookcaseid and isop = 0 ) as members, "
- - + " (SELECT group_concat(bop.username SEPARATOR ';') "
- - + " FROM bookcase_members as bop where b.bookcaseid = bop.bookcaseid and isop = 1 ) as operators "
- - + "FROM bookcase as b WHERE world = ? AND locx = ? AND locy = ? AND locz = ? ");
- + + "SELECT b.bookcaseid, bagid, owner_id, world, locx, locy, locz, flags, casetitle, "
- + + " (SELECT group_concat(bmem.player_id SEPARATOR ';') "
- + + " FROM bookcase_members as bmem where b.bookcaseid = bmem.bookcaseid and isop = 0 ) as member_id_list, "
- + + " (SELECT group_concat(bop.player_id SEPARATOR ';') "
- + + " FROM bookcase_members as bop where b.bookcaseid = bop.bookcaseid and isop = 1 ) as operator_id_list "
- + + "FROM bookcase as b WHERE world = ? AND locx = ? AND locy = ? AND locz = ?;");
- statement.setString(1, location.getWorld().getName());
- statement.setInt(2, location.getBlockX());
- statement.setInt(3, location.getBlockY());
- @@ -366,23 +368,26 @@ public class InnectisBookcase extends InnectisOwnedObject<Long> {
- }
- /**
- - * Looks up all the bookcases owned by the given player.
- - * @param owner
- + * Looks up all the bookcases owned by the player represented by their ID
- + * @param playerName
- * @return List of the bookcases or null is none.
- */
- - public static List<InnectisBookcase>getBookcases(String owner) {
- + public static List<InnectisBookcase> getBookcases(String playerName) {
- + // TODO: Load these trapdoors in another way, this method isn't the best
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- +
- PreparedStatement statement = null;
- ResultSet set = null;
- try {
- statement = DBManager.prepareStatement(""
- - + "SELECT b.bookcaseid, bagid, owner, world, locx, locy, locz, flags, casetitle, "
- - + " (SELECT group_concat(bmem.username SEPARATOR ';') "
- + + "SELECT b.bookcaseid, bagid, owner_id, world, locx, locy, locz, flags, casetitle, "
- + + " (SELECT group_concat(bmem.player_id SEPARATOR ';') "
- + " FROM bookcase_members as bmem where b.bookcaseid = bmem.bookcaseid and isop = 0 ) as members, "
- - + " (SELECT group_concat(bop.username SEPARATOR ';') "
- + + " (SELECT group_concat(bop.player_id SEPARATOR ';') "
- + " FROM bookcase_members as bop where b.bookcaseid = bop.bookcaseid and isop = 1 ) as operators "
- - + "FROM bookcase as b WHERE lower(owner) = ? ");
- - statement.setString(1, owner.toLowerCase());
- + + "FROM bookcase as b WHERE owner_id = ?;");
- + statement.setString(1, credentials.getUniqueId().toString());
- set = statement.executeQuery();
- List<InnectisBookcase> bookcases = new ArrayList<InnectisBookcase>(set.getFetchSize());
- @@ -415,31 +420,49 @@ public class InnectisBookcase extends InnectisOwnedObject<Long> {
- return null;
- }
- - long bookcaseid = set.getLong("bookcaseid");
- + int bookcaseid = set.getInt("bookcaseid");
- long bagid = set.getLong("bagid");
- - String owner = set.getString("owner");
- +
- + String ownerIdString = set.getString("owner_id");
- + UUID ownerId = UUID.fromString(ownerIdString);
- + PlayerCredentials ownerCredentials = PlayerCredentialsManager.getByUniqueId(ownerId, true);
- +
- String casetitle = set.getString("casetitle");
- int x = set.getInt("locx");
- int y = set.getInt("locy");
- int z = set.getInt("locz");
- long flags = set.getLong("flags");
- - List<String> members;
- - String memberString = set.getString("members");
- - if (!StringUtil.stringIsNullOrEmpty(memberString)) {
- - members = new ArrayList<String>(Arrays.asList(memberString.split(";")));
- - } else {
- - members = new ArrayList<String>();
- +
- + List<PlayerCredentials> members = new ArrayList<PlayerCredentials>();
- + String memberIdStringList = set.getString("member_id_list");
- +
- + if (memberIdStringList != null) {
- + for (String memberIdString : memberIdStringList.split(";")) {
- + UUID memberId = UUID.fromString(memberIdString);
- +
- + if (memberId.equals(Configuration.EVERYONE_IDENTIFIER)) {
- + members.add(Configuration.EVERYONE_CREDENTIALS);
- + } else if (memberId.equals(Configuration.LOT_ACCESS_IDENTIFIER)) {
- + members.add(Configuration.LOT_ACCESS_CREDENTIALS);
- + } else {
- + PlayerCredentials memberCredentials = PlayerCredentialsManager.getByUniqueId(memberId, true);
- + members.add(memberCredentials);
- + }
- + }
- }
- - List<String> operators;
- - String operatorString = set.getString("operators");
- - if (!StringUtil.stringIsNullOrEmpty(operatorString)) {
- - operators = new ArrayList<String>(Arrays.asList(operatorString.split(";")));
- - } else {
- - operators = new ArrayList<String>();
- + List<PlayerCredentials> operators = new ArrayList<PlayerCredentials>();
- + String operatorIdStringList = set.getString("operator_id_list");
- +
- + if (operatorIdStringList != null) {
- + for (String operatorIdString : operatorIdStringList.split(";")) {
- + UUID operatorId = UUID.fromString(operatorIdString);
- + PlayerCredentials operatorCredentials = PlayerCredentialsManager.getByUniqueId(operatorId);
- + operators.add(operatorCredentials);
- + }
- }
- - return new InnectisBookcase(world, world.getBlockAt(x, y, z), bookcaseid, bagid, owner, casetitle, members, operators, flags);
- + return new InnectisBookcase(world, world.getBlockAt(x, y, z), bookcaseid, bagid, ownerCredentials, casetitle, members, operators, flags);
- }
- /**
- @@ -452,12 +475,12 @@ public class InnectisBookcase extends InnectisOwnedObject<Long> {
- StackBag.delete(bagid);
- statement = DBManager.prepareStatement("DELETE FROM bookcase WHERE bookcaseid = ? ");
- - statement.setLong(1, getId());
- + statement.setInt(1, super.getId());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- statement = DBManager.prepareStatement("DELETE FROM bookcase_members WHERE bookcaseid = ? ");
- - statement.setLong(1, getId());
- + statement.setInt(1, super.getId());
- statement.executeUpdate();
- } catch (SQLException ex) {
- InnPlugin.logError("Cant remove get bookcase! ", ex);
- @@ -476,7 +499,7 @@ public class InnectisBookcase extends InnectisOwnedObject<Long> {
- return false;
- }
- }
- - return true;
- + return true;
- }
- }
- diff --git a/src/net/innectis/innplugin/OwnedObjects/InnectisChest.java b/src/net/innectis/innplugin/OwnedObjects/InnectisChest.java
- index 84d203e12..6404cbe58 100644
- --- a/src/net/innectis/innplugin/OwnedObjects/InnectisChest.java
- +++ b/src/net/innectis/innplugin/OwnedObjects/InnectisChest.java
- @@ -6,6 +6,7 @@ import java.sql.SQLException;
- import java.util.Arrays;
- import java.util.Comparator;
- import java.util.List;
- +import java.util.UUID;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- @@ -16,7 +17,7 @@ import net.innectis.innplugin.Items.IdpItemStack;
- import net.innectis.innplugin.Items.IdpMaterial;
- import net.innectis.innplugin.OwnedObjects.Handlers.ChestHandler;
- import net.innectis.innplugin.OwnedObjects.Handlers.ChestHandler.ChestType;
- -import net.innectis.innplugin.Player.IdpPlayer;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- import net.innectis.innplugin.Utility.DatabaseTools;
- import net.innectis.innplugin.Utility.ObjectParseException;
- import org.bukkit.Location;
- @@ -30,7 +31,7 @@ import org.bukkit.inventory.Inventory;
- *
- * @author Lynxy
- */
- -public class InnectisChest extends InnectisOwnedObject<Integer> {
- +public class InnectisChest extends InnectisOwnedObject {
- // Cached comparator for IdpItemStacks in chests
- private static Comparator<IdpItemStack> chestComparator = null;
- @@ -38,8 +39,8 @@ public class InnectisChest extends InnectisOwnedObject<Integer> {
- private Block chest2;
- private ChestType type;
- - public InnectisChest(ChestType type, World world, Block chest1, Block chest2, int id, String owner, List<String> members, List<String> operators, long flags) {
- - super(world, chest1.getLocation().toVector(), (chest2 == null ? chest1.getLocation().toVector() : chest2.getLocation().toVector()), id, owner, members, operators, flags);
- + public InnectisChest(ChestType type, World world, Block chest1, Block chest2, int id, PlayerCredentials ownerCredentials, List<PlayerCredentials> members, List<PlayerCredentials> operators, long flags) {
- + super(world, chest1.getLocation().toVector(), (chest2 == null ? chest1.getLocation().toVector() : chest2.getLocation().toVector()), id, ownerCredentials, members, operators, flags);
- this.chest1 = chest1;
- this.chest2 = chest2;
- this.type = type;
- @@ -187,25 +188,16 @@ public class InnectisChest extends InnectisOwnedObject<Integer> {
- }
- /**
- - * 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
- - * @ and player is a member of the Lot this chest is on
- - * @param player
- + * Logs chest access from the following player represented by ID
- + * @param playerId
- */
- - @Override
- - public boolean canPlayerAccess(IdpPlayer player) {
- - if (super.canPlayerAccess(player)) {
- - return true;
- - }
- - return false;
- - }
- -
- - public void logChestAccess(IdpPlayer player) {
- + public void logChestAccess(UUID playerId) {
- PreparedStatement statement = null;
- try {
- - statement = DBManager.prepareStatement("INSERT DELAYED INTO chestlog (chestid,username) VALUES (?,?);");
- - statement.setInt(1, getId());
- - statement.setString(2, player.getName().toLowerCase());
- + statement = DBManager.prepareStatement("INSERT DELAYED INTO chestlog (chestid, player_id) VALUES (?,?);");
- + statement.setInt(1, super.getId());
- + statement.setString(2, playerId.toString());
- statement.executeUpdate();
- } catch (SQLException ex) {
- Logger.getLogger(ChestHandler.class.getName()).log(Level.SEVERE, null, ex);
- @@ -225,7 +217,7 @@ public class InnectisChest extends InnectisOwnedObject<Integer> {
- try {
- statement = DBManager.prepareStatement("SELECT * FROM chestlog WHERE chestid = ? ORDER BY DATE desc LIMIT ?;");
- - statement.setInt(1, getId());
- + statement.setInt(1, super.getId());
- statement.setInt(2, (amount.length == 0 ? 10 : amount[0]));
- // Return the parsed list
- @@ -241,30 +233,32 @@ public class InnectisChest extends InnectisOwnedObject<Integer> {
- return null;
- }
- + // TODO: Add lot member access checks
- +
- private boolean createChestInDB() {
- PreparedStatement statement = null;
- ResultSet result = null;
- try {
- statement = DBManager.prepareStatementWithAutoGeneratedKeys("REPLACE INTO chests "
- - + "(typeid, owner, world, locx1, locy1, locz1, locx2, locy2, locz2, flags)"
- + + "(typeid, owner_id, world, locx1, locy1, locz1, locx2, locy2, locz2, flags)"
- + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
- statement.setInt(1, getType().getId());
- - statement.setString(2, getOwner());
- - statement.setString(3, getWorld().getName());
- + statement.setString(2, super.getOwnerCredentials().getUniqueId().toString());
- + statement.setString(3, super.getWorld().getName());
- statement.setInt(4, getChest1().getX());
- statement.setInt(5, getChest1().getY());
- statement.setInt(6, getChest1().getZ());
- statement.setInt(7, getChest2() == null ? 0 : getChest2().getX());
- statement.setInt(8, getChest2() == null ? 0 : getChest2().getY());
- statement.setInt(9, getChest2() == null ? 0 : getChest2().getZ());
- - statement.setLong(10, getFlags());
- + statement.setLong(10, super.getFlags());
- statement.executeUpdate();
- result = statement.getGeneratedKeys();
- if (result.next()) {
- - setId(result.getInt(1));
- - setUpdated(false);
- + super.setId(result.getInt(1));
- + super.setUpdated(false);
- } else {
- InnPlugin.logError("New chest was not found in the database!");
- return false;
- @@ -291,52 +285,45 @@ public class InnectisChest extends InnectisOwnedObject<Integer> {
- }
- statement = DBManager.prepareStatement("UPDATE chests SET "
- - + "typeid = ?, "
- - + "owner = ?, "
- - + "world = ?, "
- - + "locx1 = ?, "
- - + "locy1 = ?, "
- - + "locz1 = ?, "
- - + "locx2 = ?, "
- - + "locy2 = ?, "
- - + "locz2 = ?, "
- - + "flags = ? "
- - + "WHERE chestid = ?;");
- + + "typeid = ?, owner_id = ?, world = ?, "
- + + "locx1 = ?, locy1 = ?, locz1 = ?, "
- + + "locx2 = ?, locy2 = ?, locz2 = ?, "
- + + "flags = ? WHERE chestid = ?;");
- statement.setInt(1, getType().getId());
- - statement.setString(2, getOwner());
- - statement.setString(3, getWorld().getName());
- + statement.setString(2, super.getOwnerCredentials().getUniqueId().toString());
- + statement.setString(3, super.getWorld().getName());
- statement.setInt(4, getChest1().getX());
- statement.setInt(5, getChest1().getY());
- statement.setInt(6, getChest1().getZ());
- statement.setInt(7, getChest2() == null ? 0 : getChest2().getX());
- statement.setInt(8, getChest2() == null ? 0 : getChest2().getY());
- statement.setInt(9, getChest2() == null ? 0 : getChest2().getZ());
- - statement.setLong(10, getFlags());
- - statement.setInt(11, getId());
- + statement.setLong(10, super.getFlags());
- + statement.setInt(11, super.getId());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- statement = DBManager.prepareStatement("DELETE FROM chests_members WHERE chestid = ?;");
- - statement.setInt(1, getId());
- + statement.setInt(1, super.getId());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- - for (String s : getMembers()) {
- - statement = DBManager.prepareStatement("INSERT INTO chests_members (chestid, username, isop) VALUES (?, ?, 0);");
- - statement.setInt(1, getId());
- - statement.setString(2, s);
- + for (PlayerCredentials pc : getMembers()) {
- + statement = DBManager.prepareStatement("INSERT INTO chests_members (chestid, player_id, isop) VALUES (?, ?, 0);");
- + statement.setInt(1, super.getId());
- + statement.setString(2, pc.getUniqueId().toString());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- }
- - for (String s : getOperators()) {
- - statement = DBManager.prepareStatement("INSERT INTO chests_members (chestid, username, isop) VALUES (?, ?, 1);");
- - statement.setInt(1, getId());
- - statement.setString(2, s);
- + for (PlayerCredentials pc : getOperators()) {
- + statement = DBManager.prepareStatement("INSERT INTO chests_members (chestid, player_id, isop) VALUES (?, ?, 1);");
- + statement.setInt(1, super.getId());
- + statement.setString(2, pc.getUniqueId().toString());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- }
- - setUpdated(false);
- + super.setUpdated(false);
- } catch (SQLException ex) {
- InnPlugin.logError("Unable to save chest!", ex);
- return false;
- diff --git a/src/net/innectis/innplugin/OwnedObjects/InnectisDoor.java b/src/net/innectis/innplugin/OwnedObjects/InnectisDoor.java
- index bb80fa765..f61f3fb54 100644
- --- a/src/net/innectis/innplugin/OwnedObjects/InnectisDoor.java
- +++ b/src/net/innectis/innplugin/OwnedObjects/InnectisDoor.java
- @@ -8,7 +8,7 @@ import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.Items.IdpMaterial;
- import net.innectis.innplugin.OwnedObjects.Handlers.LotHandler;
- -import net.innectis.innplugin.Player.IdpPlayer;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- import org.bukkit.Location;
- import org.bukkit.World;
- import org.bukkit.block.Block;
- @@ -17,12 +17,12 @@ import org.bukkit.block.Block;
- *
- * @author Lynxy
- */
- -public class InnectisDoor extends InnectisOwnedObject<Integer> {
- +public class InnectisDoor extends InnectisOwnedObject {
- private Block door1;
- private Block door2;
- - public InnectisDoor(World world, Block door1, Block door2, int id, String owner, List<String> members,List<String> operators, long flags) {
- - super(world, door1.getLocation().toVector(), (door2 == null ? door1.getLocation().toVector() : door2.getLocation().toVector()), id, owner, members, operators, flags);
- + public InnectisDoor(World world, Block door1, Block door2, int id, PlayerCredentials ownerCredentials, List<PlayerCredentials> members, List<PlayerCredentials> operators, long flags) {
- + super(world, door1.getLocation().toVector(), (door2 == null ? door1.getLocation().toVector() : door2.getLocation().toVector()), id, ownerCredentials, members, operators, flags);
- this.door1 = door1;
- this.door2 = door2;
- }
- @@ -109,13 +109,14 @@ public class InnectisDoor extends InnectisOwnedObject<Integer> {
- * @param player
- */
- @Override
- - public boolean canPlayerAccess(IdpPlayer player) {
- - if (super.canPlayerAccess(player)) {
- + public boolean canPlayerAccess(String playerName) {
- + if (super.canPlayerAccess(playerName)) {
- return true;
- }
- +
- if (containsMember("@")) { //allow lot members
- InnectisLot lot = LotHandler.getLot(door1.getLocation());
- - if (lot != null && (lot.containsMember(player.getName()) || lot.containsOperator(player.getName()))) {
- + if (lot != null && (lot.containsMember(playerName) || lot.containsOperator(playerName))) {
- return true;
- }
- }
- @@ -128,23 +129,23 @@ public class InnectisDoor extends InnectisOwnedObject<Integer> {
- try {
- statement = DBManager.prepareStatementWithAutoGeneratedKeys("REPLACE INTO doors "
- - + "(owner, world, locx1, locy1, locz1, locx2, locy2, locz2, flags)"
- + + "(owner_id, world, locx1, locy1, locz1, locx2, locy2, locz2, flags)"
- + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
- - statement.setString(1, getOwner());
- - statement.setString(2, getWorld().getName());
- + statement.setString(1, super.getOwnerCredentials().getUniqueId().toString());
- + statement.setString(2, super.getWorld().getName());
- statement.setInt(3, getDoor1().getX());
- statement.setInt(4, getDoor1().getY());
- statement.setInt(5, getDoor1().getZ());
- statement.setInt(6, getDoor2() == null ? 0 : getDoor2().getX());
- statement.setInt(7, getDoor2() == null ? 0 : getDoor2().getY());
- statement.setInt(8, getDoor2() == null ? 0 : getDoor2().getZ());
- - statement.setLong(9, getFlags());
- + statement.setLong(9, super.getFlags());
- statement.executeUpdate();
- result = statement.getGeneratedKeys();
- if (result.next()) {
- - setId(result.getInt(1));
- - setUpdated(false);
- + super.setId(result.getInt(1));
- + super.setUpdated(false);
- } else {
- InnPlugin.logError("New door not found in the database!");
- return false;
- @@ -170,50 +171,44 @@ public class InnectisDoor extends InnectisOwnedObject<Integer> {
- }
- statement = DBManager.prepareStatement("UPDATE doors SET "
- - + "owner = ?, "
- - + "world = ?, "
- - + "locx1 = ?, "
- - + "locy1 = ?, "
- - + "locz1 = ?, "
- - + "locx2 = ?, "
- - + "locy2 = ?, "
- - + "locz2 = ?, "
- - + "flags = ? "
- + + "owner_id = ?, world = ?, locx1 = ?, "
- + + "locy1 = ?, locz1 = ?, locx2 = ?, "
- + + "locy2 = ?, locz2 = ?, flags = ? "
- + "WHERE doorid = ?;");
- - statement.setString(1, getOwner());
- - statement.setString(2, getWorld().getName());
- + statement.setString(1, super.getOwnerCredentials().getUniqueId().toString());
- + statement.setString(2, super.getWorld().getName());
- statement.setInt(3, getDoor1().getX());
- statement.setInt(4, getDoor1().getY());
- statement.setInt(5, getDoor1().getZ());
- statement.setInt(6, getDoor2() == null ? 0 : getDoor2().getX());
- statement.setInt(7, getDoor2() == null ? 0 : getDoor2().getY());
- statement.setInt(8, getDoor2() == null ? 0 : getDoor2().getZ());
- - statement.setLong(9, getFlags());
- - statement.setInt(10, getId());
- + statement.setLong(9, super.getFlags());
- + statement.setInt(10, super.getId());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- statement = DBManager.prepareStatement("DELETE FROM doors_members WHERE doorid = ?;");
- - statement.setInt(1, getId());
- + statement.setInt(1, super.getId());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- - for (String s : getMembers()) {
- - statement = DBManager.prepareStatement("INSERT INTO doors_members (doorid, username, isop) VALUES (?, ?, 0);");
- - statement.setInt(1, getId());
- - statement.setString(2, s);
- + for (PlayerCredentials pc : getMembers()) {
- + statement = DBManager.prepareStatement("INSERT INTO doors_members (doorid, player_id, isop) VALUES (?, ?, 0);");
- + statement.setInt(1, super.getId());
- + statement.setString(2, pc.getUniqueId().toString());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- }
- - for (String s : getOperators()) {
- - statement = DBManager.prepareStatement("INSERT INTO doors_members (doorid, username, isop) VALUES (?, ?, 1);");
- - statement.setInt(1, getId());
- - statement.setString(2, s);
- + for (PlayerCredentials pc : getOperators()) {
- + statement = DBManager.prepareStatement("INSERT INTO doors_members (doorid, player_id, isop) VALUES (?, ?, 1);");
- + statement.setInt(1, super.getId());
- + statement.setString(2, pc.getUniqueId().toString());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- }
- - setUpdated(false);
- + super.setUpdated(false);
- } catch (SQLException ex) {
- InnPlugin.logError("Unable to save door #" + super.getId() + "!", ex);
- return false;
- diff --git a/src/net/innectis/innplugin/OwnedObjects/InnectisLot.java b/src/net/innectis/innplugin/OwnedObjects/InnectisLot.java
- index a0442ed3b..763786286 100644
- --- a/src/net/innectis/innplugin/OwnedObjects/InnectisLot.java
- +++ b/src/net/innectis/innplugin/OwnedObjects/InnectisLot.java
- @@ -7,6 +7,7 @@ import java.util.ArrayList;
- import java.util.Calendar;
- import java.util.Collections;
- import java.util.HashMap;
- +import java.util.Iterator;
- import java.util.List;
- import java.util.Map;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- @@ -17,6 +18,7 @@ import net.innectis.innplugin.Location.IdpWorldRegion;
- import net.innectis.innplugin.OwnedObjects.Handlers.LotHandler;
- import net.innectis.innplugin.Player.Chat.ChatColor;
- import net.innectis.innplugin.Player.IdpPlayer;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- import net.innectis.innplugin.Utility.DateUtil;
- import org.bukkit.Location;
- import org.bukkit.World;
- @@ -26,16 +28,15 @@ import org.bukkit.util.Vector;
- /**
- * @author Lynxy
- */
- -public class InnectisLot extends InnectisOwnedObject<Integer> {
- -
- +public class InnectisLot extends InnectisOwnedObject {
- private int lotnr;
- - private String lotname;
- + private String lotName;
- private int timesWarpUsed;
- - private Map<String, Long> banned;
- - private List<String> safelist;
- + private Map<PlayerCredentials, Long> banned;
- + private List<PlayerCredentials> safelist;
- private Location spawn;
- private InnectisLot parent;
- - private String creator;
- + private PlayerCredentials creatorCredentials;
- private String enterMsg;
- private String exitMsg;
- private long lastOwnerEdit;
- @@ -45,23 +46,23 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
- private boolean disabled;
- private List<InnectisLot> sublots;
- - public InnectisLot(World world, Vector point1, Vector point2, String owner, String creator, InnectisLot parent) {
- - this(-1, world, point1, point2, point1, owner, null, null, new HashMap<String, Long>(), new ArrayList<String>(), 0, 0, parent, creator, 0, 0);
- + public InnectisLot(World world, Vector point1, Vector point2, PlayerCredentials ownerCredentials, PlayerCredentials creatorCredentials, InnectisLot parent) {
- + this(-1, world, point1, point2, point1, ownerCredentials, null, null, new HashMap<PlayerCredentials, Long>(), new ArrayList<PlayerCredentials>(), 0, 0, parent, creatorCredentials, 0, 0);
- }
- - 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) {
- - 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);
- + 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) {
- + 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);
- }
- - 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) {
- - super(world, point1, point2, id, owner, members, operators, flags);
- - this.lotname = lotname;
- + 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) {
- + super(world, point1, point2, id, ownerCredentials, members, operators, flags);
- + this.lotName = lotname;
- this.banned = banned;
- this.safelist = safelist;
- this.spawn = spawn;
- this.lotnr = lotnr;
- this.sublots = new ArrayList<InnectisLot>();
- - this.creator = creator;
- + this.creatorCredentials = creatorCredentials;
- this.enterMsg = enterMsg;
- this.exitMsg = exitMsg;
- this.lastOwnerEdit = lastOwnerEdit;
- @@ -96,31 +97,35 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
- * Returns true if this lot or any of its parents have a flag bit set.
- * If both child and parent lot have the flag set, it is negated.
- * @param flag
- + * @return
- */
- @Override
- public boolean isFlagSet(FlagType flag) {
- InnectisLot curLot = this;
- boolean isSet = false;
- +
- while (curLot != null && curLot != LotHandler.getMainLot()) {
- if (curLot.isFlagSetNoInheritance(flag)) {
- isSet = !isSet;
- }
- +
- curLot = curLot.getParentAllowHidden();
- }
- +
- return isSet;
- }
- public int getLotNumber() {
- - return this.lotnr;
- + return lotnr;
- }
- public void setLotNumber(int lotnr) {
- this.lotnr = lotnr;
- - setUpdated(true);
- + super.setUpdated(true);
- }
- public String getLotName() {
- - return this.lotname;
- + return lotName;
- }
- /**
- @@ -132,20 +137,20 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
- try {
- statement = DBManager.prepareStatement("DELETE FROM lot_names WHERE lotid=?;");
- - statement.setInt(1, getId());
- + statement.setInt(1, super.getId());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- if (!lotName.equalsIgnoreCase("")) {
- statement = DBManager.prepareStatement("INSERT INTO lot_names (lotname, lotid, time) VALUES (?, ?, ?);");
- statement.setString(1, lotName);
- - statement.setInt(2, getId());
- + statement.setInt(2, super.getId());
- statement.setLong(3, Calendar.getInstance().getTimeInMillis());
- statement.executeUpdate();
- }
- - this.lotname = lotName;
- - setUpdated(true);
- + this.lotName = lotName;
- + super.setUpdated(true);
- } catch (SQLException ex) {
- InnPlugin.logError("Unable to set name of lot #" + getId() + "!", ex);
- return false;
- @@ -161,7 +166,14 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
- */
- public List<String> getBannedList() {
- reloadBanned();
- - return new ArrayList<String>(this.banned.keySet());
- +
- + List<String> bannedPlayers = new ArrayList<String>(banned.size());
- +
- + for (PlayerCredentials pc : banned.keySet()) {
- + bannedPlayers.add(pc.getName());
- + }
- +
- + return bannedPlayers;
- }
- /**
- @@ -169,67 +181,85 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
- */
- public String getBannedString(ChatColor colour) {
- StringBuilder sb = new StringBuilder("" + colour);
- - for (String s : getBannedList()) {
- - long timeout = this.banned.get(s) - System.currentTimeMillis();
- +
- + for (PlayerCredentials pc : banned.keySet()) {
- + long timeout = banned.get(pc) - System.currentTimeMillis();
- + String name = pc.getName();
- +
- if (timeout > 0) {
- - sb.append("[").append(s).append(":").append(DateUtil.getTimeString(timeout, false)).append(colour).append("]");
- + sb.append("[").append(name).append(":").append(DateUtil.getTimeString(timeout, false)).append(colour).append("]");
- } else {
- - sb.append(s);
- + sb.append(name);
- }
- +
- sb.append(", ");
- }
- +
- if (sb.length() == 0) {
- return "none";
- }
- +
- return sb.substring(0, sb.length() - 2);
- }
- /**
- - * Adds the specified user to the safelist
- - * @param name
- + * Adds the credentials of the specified player to this lot's safelist
- + * @param credentials
- * @return true if added, false if already added
- */
- - public boolean addSafelist(String name) {
- - name = name.toLowerCase();
- -
- - if (safelist.contains(name)) {
- + public boolean addSafelist(PlayerCredentials credentials) {
- + if (containsSafelist(credentials.getName())) {
- return false;
- }
- - if (banned.containsKey(name)) {
- - banned.remove(name);
- + if (isBanned(credentials.getName())) {
- + banned.remove(credentials);
- }
- - safelist.add(name);
- - setUpdated(true);
- + safelist.add(credentials);
- + super.setUpdated(true);
- return true;
- }
- /**
- - * Removes the specified user from the safelist
- - * @param name
- - * @return true if removed, false if they do not exist
- + * Removes the specified player from the safelist
- + * @param playerName
- + * @return true if removed, false otherwise
- */
- - public boolean removeSafelist(String name) {
- - name = name.toLowerCase();
- + public boolean removeSafelist(String playerName) {
- + boolean removed = false;
- - if (!safelist.contains(name)) {
- - return false;
- + for (Iterator<PlayerCredentials> it = safelist.iterator(); it.hasNext();) {
- + PlayerCredentials pc = it.next();
- +
- + if (pc.getName().equalsIgnoreCase(playerName)) {
- + it.remove();
- + removed = true;
- + break;
- + }
- }
- - safelist.remove(name);
- - setUpdated(true);
- - return true;
- + if (removed) {
- + super.setUpdated(true);
- + return true;
- + } else {
- + return false;
- + }
- }
- /**
- - * Checks if the specified name is on the safelist
- - * @param name
- + * Checks if the player represented by their ID is on this lot's safelist
- + * @param playerName
- * @return
- */
- - public boolean containsSafelist(String name) {
- - name = name.toLowerCase();
- - return safelist.contains(name);
- + public boolean containsSafelist(String playerName) {
- + for (PlayerCredentials pc : safelist) {
- + if (pc.getName().equalsIgnoreCase(playerName)) {
- + return true;
- + }
- + }
- +
- + return false;
- }
- /**
- @@ -237,14 +267,14 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
- */
- public void clearSafelist() {
- safelist.clear();
- - setUpdated(true);
- + super.setUpdated(true);
- }
- /**
- * Returns an unmodifiable list of the safelist
- * @return
- */
- - public List<String> getSafelist() {
- + public List<PlayerCredentials> getSafelist() {
- return Collections.unmodifiableList(safelist);
- }
- @@ -256,12 +286,14 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
- StringBuilder sb = new StringBuilder();
- int idx = 0;
- - for (String s : getSafelist()) {
- + for (PlayerCredentials pc : safelist) {
- + String name = pc.getName();
- +
- if (idx > 0) {
- sb.append(", ");
- }
- - sb.append(s);
- + sb.append(name);
- idx++;
- }
- @@ -269,105 +301,128 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
- }
- /**
- - * Adds a username to the banned list perm and returns true. If username is already banned, returns false
- - * @param name
- + * Adds the credentials of a player to this lot's ban list
- + * If they are already banned, returns false
- + * @param credentials
- */
- - public boolean banUser(String name) {
- - return banUser(name, (long) 0);
- + public boolean banUser(PlayerCredentials credentials) {
- + return banUser(credentials, 0L);
- }
- /**
- * Adds a username to the banned list until the entered time and returns true. If username is already banned, returns false.
- * If time is put as '0' then perm.
- - * @param name
- + * @param credentials
- * @param timeout
- * @return
- */
- - public boolean banUser(String name, long timeout) {
- - String name2 = name.toLowerCase();
- - if (getBannedList().contains(name2)) {
- + public boolean banUser(PlayerCredentials credentials, long timeout) {
- + String name = credentials.getName();
- +
- + if (isBanned(name)) {
- return false;
- }
- - if (safelist.contains(name2)) {
- - safelist.remove(name2);
- + if (containsSafelist(name)) {
- + removeSafelist(name);
- }
- - this.banned.put(name2, timeout);
- - setUpdated(true);
- + banned.put(credentials, timeout);
- + super.setUpdated(true);
- return true;
- }
- /**
- - * If a username is banned, removes it and returns true
- - * @param name
- + * Removes the player from this lot's ban list
- + * not banned
- + * @param playerName
- */
- - public boolean unbanUser(String name) {
- - String name2 = name.toLowerCase();
- - if (getBannedList().contains(name2)) {
- - this.banned.remove(name2);
- - setUpdated(true);
- + public boolean unbanUser(String playerName) {
- + boolean removed = false;
- +
- + for (Iterator<PlayerCredentials> it = banned.keySet().iterator(); it.hasNext();) {
- + PlayerCredentials pc = it.next();
- +
- + if (pc.getName().equalsIgnoreCase(playerName)) {
- + it.remove();
- + removed = true;
- + break;
- + }
- + }
- +
- + if (removed) {
- + super.setUpdated(true);
- return true;
- + } else {
- + return false;
- }
- - return false;
- }
- /**
- - * Returns true if a user is banned, false otherwise
- - * @param name
- + * Returns true if a player is banned, false otherwise
- + * @param playerName
- * @return
- */
- - public boolean isBanned(String name) {
- - return getBannedList().contains(name.toLowerCase());
- + public boolean isBanned(String playerName) {
- + for (PlayerCredentials pc : banned.keySet()) {
- + if (pc.getName().equalsIgnoreCase(playerName)) {
- + return true;
- + }
- + }
- +
- + return false;
- }
- /**
- * Clears the banned user list of this lot
- */
- public void clearBanned() {
- - this.banned.clear();
- - setUpdated(true);
- + banned.clear();
- + super.setUpdated(true);
- }
- /**
- * Checks through all lot bans, and removes them if they have timed out.
- */
- public void reloadBanned() {
- - for (String s : this.banned.keySet()) {
- - long banTime = this.banned.get(s);
- + for (PlayerCredentials pc : banned.keySet()) {
- + long banTime = banned.get(pc);
- if (banTime > 0 && banTime < System.currentTimeMillis()) {
- + String name = pc.getName();
- +
- // Log auto-unbans.
- IdpPlayer player = InnPlugin.getPlugin().getPlayer(getOwner(), true);
- if (player != null) {
- - player.printInfo(s + "'s ban has automatically expired on lot #" + getId());
- + player.printInfo(name + "'s ban has automatically expired on lot #" + getId());
- }
- - InnPlugin.logInfo(s + "'s ban has automatically expired on lot #" + getId() + " (" + getOwner() + ")");
- - this.banned.remove(s);
- + InnPlugin.logInfo(name + "'s ban has automatically expired on lot #" + getId() + " (" + getOwner() + ")");
- + banned.remove(pc);
- }
- }
- }
- public Location getSpawn() {
- - return this.spawn;
- + return spawn;
- }
- public void setSpawn(Location spawn) {
- this.spawn = spawn;
- - setUpdated(true);
- + super.setUpdated(true);
- }
- /**
- * Returns the parent lot. If no parent, or parent is hidden, returns null
- */
- public InnectisLot getParent() {
- - if (this.parent == LotHandler.getMainLot()
- - || (this.parent != null && this.parent.getHidden())) {
- + if (parent == LotHandler.getMainLot()
- + || (parent != null && parent.getHidden())) {
- return null;
- }
- - return this.parent;
- +
- + return parent;
- }
- /**
- @@ -375,17 +430,18 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
- * @return
- */
- public boolean isYaxis() {
- - return (this.getLowestY() > 0 || this.getHighestY() < 256);
- + return (super.getLowestY() > 0 || super.getHighestY() < 256);
- }
- /**
- * Returns the parent lot. If no parent, returns null
- */
- public InnectisLot getParentAllowHidden() {
- - if (this.parent == LotHandler.getMainLot()) {
- + if (parent == LotHandler.getMainLot()) {
- return null;
- }
- - return this.parent;
- +
- + return parent;
- }
- /**
- @@ -393,12 +449,15 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
- */
- public InnectisLot getParentNotHidden() {
- InnectisLot par = getParent();
- +
- if (par == null) {
- return null;
- }
- +
- if (par.getHidden()) {
- return null;
- }
- +
- return par;
- }
- @@ -409,13 +468,16 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
- public final boolean setParent(InnectisLot parent) {
- if (parent == null) {
- parent = LotHandler.getMainLot();
- +
- if (parent == null) {
- return false;
- }
- }
- +
- if (parent == this) {
- return false;
- }
- +
- if (!LotHandler.isSublotWithinLot(this, parent)) {
- return false;
- }
- @@ -428,7 +490,8 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
- if (parent.addSublot(this)) {
- this.parent = parent;
- }
- - setUpdated(true);
- +
- + super.setUpdated(true);
- return true;
- }
- @@ -445,14 +508,15 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
- || (checkLot.parent != null && checkLot.parent.getHidden())) {
- return checkLot;
- }
- +
- return getParentTop(checkLot.parent);
- }
- public List<InnectisLot> getSublots() {
- - if (this.sublots.contains(this)) { //sanity check
- - this.sublots.remove(this);
- + if (sublots.contains(this)) { //sanity check
- + sublots.remove(this);
- }
- - return this.sublots;
- + return sublots;
- }
- /**
- @@ -460,9 +524,9 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
- * @param sublot
- */
- private boolean addSublot(InnectisLot sublot) {
- - if (this != sublot && !this.sublots.contains(sublot)) {
- + if (this != sublot && !sublots.contains(sublot)) {
- if (LotHandler.isSublotWithinLot(sublot, this)) {
- - this.sublots.add(sublot);
- + sublots.add(sublot);
- return true;
- }
- }
- @@ -474,76 +538,82 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
- * @param sublot
- */
- private boolean removeSublot(InnectisLot sublot) {
- - if (this.sublots.contains(sublot)) {
- - this.sublots.remove(sublot);
- + if (sublots.contains(sublot)) {
- + sublots.remove(sublot);
- return true;
- }
- return false;
- }
- + public PlayerCredentials getCreatorCredentials() {
- + return creatorCredentials;
- + }
- +
- public String getCreator() {
- - return this.creator;
- + return creatorCredentials.getName();
- }
- - public void setCreator(String creator) {
- - this.creator = creator;
- - setUpdated(true);
- + public void setCreator(PlayerCredentials creatorCredentials) {
- + this.creatorCredentials = creatorCredentials;
- + super.setUpdated(true);
- }
- public long getLastOwnerEdit() {
- - return this.lastOwnerEdit;
- + return lastOwnerEdit;
- }
- public String getLastOwnerEditString() {
- - if (this.lastOwnerEdit == 0) {
- + if (lastOwnerEdit == 0) {
- return "Never";
- }
- - long timeDiff = (System.currentTimeMillis() - this.lastOwnerEdit) / 1000;
- +
- + long timeDiff = (System.currentTimeMillis() - lastOwnerEdit) / 1000;
- return DateUtil.getTimeDifferenceString(timeDiff) + " ago";
- }
- public void setLastOwnerEdit(long lastEdit) {
- - this.lastOwnerEdit = lastEdit;
- - setUpdated(true);
- + lastOwnerEdit = lastEdit;
- + super.setUpdated(true);
- }
- public long getLastMemberEdit() {
- - return this.lastMemberEdit;
- + return lastMemberEdit;
- }
- public String getLastMemberEditString() {
- - if (this.lastMemberEdit == 0) {
- + if (lastMemberEdit == 0) {
- return "Never";
- }
- - long timeDiff = (System.currentTimeMillis() - this.lastMemberEdit) / 1000;
- +
- + long timeDiff = (System.currentTimeMillis() - lastMemberEdit) / 1000;
- return DateUtil.getTimeDifferenceString(timeDiff) + " ago";
- }
- public void setLastMemberEdit(long lastEdit) {
- - this.lastMemberEdit = lastEdit;
- - setUpdated(true);
- + lastMemberEdit = lastEdit;
- + super.setUpdated(true);
- }
- public boolean getHidden() {
- - return this.hidden;
- + return hidden;
- }
- public void setHidden(boolean hidden) {
- this.hidden = hidden;
- - setUpdated(true);
- + super.setUpdated(true);
- }
- public boolean getDeleted() {
- - return this.deleted;
- + return deleted;
- }
- public void setDeleted(boolean deleted) {
- this.deleted = deleted;
- - setUpdated(true);
- + super.setUpdated(true);
- }
- public boolean getDisabled() {
- - return this.disabled;
- + return disabled;
- }
- public void setDisabled(boolean disabled) {
- @@ -566,13 +636,13 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
- * @return
- */
- public boolean equals(IdpWorldRegion region, boolean yaxis) {
- - if (this.getLowestX() == region.getLowestX()
- - && this.getLowestZ() == region.getLowestZ()
- - && this.getHighestX() == region.getHighestX()
- - && this.getHighestZ() == region.getHighestZ()
- - && (!yaxis || (region.getLowestY() == this.getLowestY()
- - && region.getHighestY() == this.getHighestY()))
- - && this.getWorld().getName().equalsIgnoreCase(region.getWorld().getName())) {
- + if (super.getLowestX() == region.getLowestX()
- + && super.getLowestZ() == region.getLowestZ()
- + && super.getHighestX() == region.getHighestX()
- + && super.getHighestZ() == region.getHighestZ()
- + && (!yaxis || (super.getLowestY() == region.getLowestY()
- + && super.getHighestY() == region.getHighestY()))
- + && super.getWorld().getName().equalsIgnoreCase(region.getWorld().getName())) {
- return true;
- }
- @@ -613,8 +683,7 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
- * Sets the flag on the lot, then sends leave/enter events for every player on the lot
- *
- * @param flag
- - * @param toggle
- - * @throws SQLException
- + * @param disable
- */
- public void setLotFlag(FlagType flag, boolean disable) {
- //before we update the flag, we need ot simulate every user on the lot leaving it
- @@ -633,14 +702,17 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
- private int getFreeLotNumber() throws SQLException {
- int highestLotNr = 0;
- List<InnectisLot> lots = LotHandler.getLots(getOwner());
- +
- if (lots == null) {
- return 1;
- }
- +
- for (InnectisLot lot : lots) {
- if (lot.getLotNumber() > highestLotNr) {
- highestLotNr = lot.getLotNumber();
- }
- }
- +
- return highestLotNr + 1;
- }
- @@ -649,42 +721,42 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
- ResultSet result = null;
- try {
- - if (this.lotnr == 0) {
- - this.lotnr = getFreeLotNumber();
- + if (lotnr == 0) {
- + lotnr = getFreeLotNumber();
- }
- statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO lots "
- - + "(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)"
- + + "(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)"
- + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
- - statement.setString(1, super.getOwner());
- - statement.setInt(2, this.lotnr);
- - statement.setString(3, getWorld().getName());
- - statement.setString(4, this.lotname);
- - statement.setInt(5, getPos1().getBlockX());
- - statement.setInt(6, getPos1().getBlockY());
- - statement.setInt(7, getPos1().getBlockZ());
- - statement.setInt(8, getPos2().getBlockX());
- - statement.setInt(9, getPos2().getBlockY());
- - statement.setInt(10, getPos2().getBlockZ());
- - statement.setInt(11, this.spawn.getBlockX());
- - statement.setInt(12, this.spawn.getBlockY());
- - statement.setInt(13, this.spawn.getBlockZ());
- - statement.setInt(14, Math.round(this.spawn.getYaw()));
- - statement.setLong(15, getFlags());
- - statement.setString(16, this.creator);
- - statement.setString(17, this.enterMsg);
- - statement.setString(18, this.exitMsg);
- - statement.setLong(19, this.lastOwnerEdit);
- - statement.setLong(20, this.lastMemberEdit);
- - statement.setInt(21, this.timesWarpUsed);
- - statement.setBoolean(22, this.hidden);
- - statement.setBoolean(23, this.deleted);
- + statement.setString(1, super.getOwnerCredentials().getUniqueId().toString());
- + statement.setInt(2, lotnr);
- + statement.setString(3, super.getWorld().getName());
- + statement.setString(4, lotName);
- + statement.setInt(5, super.getPos1().getBlockX());
- + statement.setInt(6, super.getPos1().getBlockY());
- + statement.setInt(7, super.getPos1().getBlockZ());
- + statement.setInt(8, super.getPos2().getBlockX());
- + statement.setInt(9, super.getPos2().getBlockY());
- + statement.setInt(10, super.getPos2().getBlockZ());
- + statement.setInt(11, spawn.getBlockX());
- + statement.setInt(12, spawn.getBlockY());
- + statement.setInt(13, spawn.getBlockZ());
- + statement.setInt(14, Math.round(spawn.getYaw()));
- + statement.setLong(15, super.getFlags());
- + statement.setString(16, creatorCredentials.getUniqueId().toString());
- + statement.setString(17, enterMsg);
- + statement.setString(18, exitMsg);
- + statement.setLong(19, lastOwnerEdit);
- + statement.setLong(20, lastMemberEdit);
- + statement.setInt(21, timesWarpUsed);
- + statement.setBoolean(22, hidden);
- + statement.setBoolean(23, deleted);
- statement.executeUpdate();
- result = statement.getGeneratedKeys();
- if (result.next()) {
- - setId(result.getInt(1));
- - setUpdated(false);
- + super.setId(result.getInt(1));
- + super.setUpdated(false);
- } else {
- InnPlugin.logError("New lot not found in the database!");
- return false;
- @@ -702,125 +774,111 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
- @Override
- public boolean save() {
- - if (getId() == 0) { //main lot (virtual)
- - setUpdated(false);
- + if (super.getId() == 0) { //main lot (virtual)
- + super.setUpdated(false);
- return true;
- }
- - if (getId() == -1) {
- + if (super.getId() == -1) {
- return createLotInDB();
- }
- PreparedStatement statement = null;
- try {
- - if (this.lotnr == 0) {
- - this.lotnr = getFreeLotNumber();
- + if (lotnr == 0) {
- + lotnr = getFreeLotNumber();
- }
- statement = DBManager.prepareStatement("UPDATE lots SET "
- - + "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 = ? "
- - + "WHERE lotid = ?;");
- - statement.setString(1, super.getOwner());
- - statement.setInt(2, this.lotnr);
- - statement.setString(3, getWorld().getName());
- - statement.setString(4, this.lotname);
- - statement.setInt(5, getPos1().getBlockX());
- - statement.setInt(6, getPos1().getBlockY());
- - statement.setInt(7, getPos1().getBlockZ());
- - statement.setInt(8, getPos2().getBlockX());
- - statement.setInt(9, getPos2().getBlockY());
- - statement.setInt(10, getPos2().getBlockZ());
- - statement.setInt(11, this.spawn.getBlockX());
- - statement.setInt(12, this.spawn.getBlockY());
- - statement.setInt(13, this.spawn.getBlockZ());
- - statement.setInt(14, Math.round(this.spawn.getYaw()));
- - statement.setLong(15, getFlags());
- - statement.setString(16, this.creator);
- - statement.setString(17, this.enterMsg);
- - statement.setString(18, this.exitMsg);
- - statement.setLong(19, this.lastOwnerEdit);
- - statement.setLong(20, this.lastMemberEdit);
- - statement.setInt(21, this.timesWarpUsed);
- - statement.setBoolean(22, this.hidden);
- - statement.setBoolean(23, this.deleted);
- - statement.setInt(24, getId());
- + + "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 = ? WHERE lotid = ?;");
- + statement.setString(1, super.getOwnerCredentials().getUniqueId().toString());
- + statement.setInt(2, lotnr);
- + statement.setString(3, super.getWorld().getName());
- + statement.setString(4, lotName);
- + statement.setInt(5, super.getPos1().getBlockX());
- + statement.setInt(6, super.getPos1().getBlockY());
- + statement.setInt(7, super.getPos1().getBlockZ());
- + statement.setInt(8, super.getPos2().getBlockX());
- + statement.setInt(9, super.getPos2().getBlockY());
- + statement.setInt(10, super.getPos2().getBlockZ());
- + statement.setInt(11, spawn.getBlockX());
- + statement.setInt(12, spawn.getBlockY());
- + statement.setInt(13, spawn.getBlockZ());
- + statement.setInt(14, Math.round(spawn.getYaw()));
- + statement.setLong(15, super.getFlags());
- + statement.setString(16, creatorCredentials.getUniqueId().toString());
- + statement.setString(17, enterMsg);
- + statement.setString(18, exitMsg);
- + statement.setLong(19, lastOwnerEdit);
- + statement.setLong(20, lastMemberEdit);
- + statement.setInt(21, timesWarpUsed);
- + statement.setBoolean(22, hidden);
- + statement.setBoolean(23, deleted);
- + statement.setInt(24, super.getId());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- statement = DBManager.prepareStatement("DELETE FROM lot_members WHERE lotid = ?;");
- - statement.setInt(1, getId());
- + statement.setInt(1, super.getId());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- statement = DBManager.prepareStatement("DELETE FROM lot_banned WHERE lotid = ?;");
- - statement.setInt(1, getId());
- + statement.setInt(1, super.getId());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- statement = DBManager.prepareStatement("DELETE FROM lot_safelist WHERE lotid = ?;");
- - statement.setInt(1, getId());
- + statement.setInt(1, super.getId());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- - for (String s : getMembers()) {
- - statement = DBManager.prepareStatement("INSERT INTO lot_members (lotid, username, isop) VALUES (?, ?, 0);");
- - statement.setInt(1, getId());
- - statement.setString(2, s);
- + for (PlayerCredentials pc : super.getMembers()) {
- + statement = DBManager.prepareStatement("INSERT INTO lot_members (lotid, player_id, isop) VALUES (?, ?, 0);");
- + statement.setInt(1, super.getId());
- + statement.setString(2, pc.getUniqueId().toString());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- }
- - for (String s : getOperators()) {
- - statement = DBManager.prepareStatement("INSERT INTO lot_members (lotid, username, isop) VALUES (?, ?, 1);");
- - statement.setInt(1, getId());
- - statement.setString(2, s);
- + for (PlayerCredentials pc : super.getOperators()) {
- + statement = DBManager.prepareStatement("INSERT INTO lot_members (lotid, player_id, isop) VALUES (?, ?, 1);");
- + statement.setInt(1, super.getId());
- + statement.setString(2, pc.getUniqueId().toString());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- }
- - for (String s : this.banned.keySet()) {
- - statement = DBManager.prepareStatement("INSERT INTO lot_banned (lotid, username, timeout) VALUES (?, ?, ?);");
- - statement.setInt(1, getId());
- - statement.setString(2, s);
- - statement.setLong(3, this.banned.get(s));
- + for (PlayerCredentials pc : banned.keySet()) {
- + long time = banned.get(pc);
- +
- + statement = DBManager.prepareStatement("INSERT INTO lot_banned (lotid, player_id, timeout) VALUES (?, ?, ?);");
- + statement.setInt(1, super.getId());
- + statement.setString(2, pc.getUniqueId().toString());
- + statement.setLong(3, time);
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- }
- - for (String s : getSafelist()) {
- - statement = DBManager.prepareStatement("INSERT INTO lot_safelist (lotid, username) VALUES (?, ?);");
- - statement.setInt(1, getId());
- - statement.setString(2, s);
- + for (PlayerCredentials pc : getSafelist()) {
- + statement = DBManager.prepareStatement("INSERT INTO lot_safelist (lotid, player_id) VALUES (?, ?);");
- + statement.setInt(1, super.getId());
- + statement.setString(2, pc.getUniqueId().toString());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- }
- - setUpdated(false);
- + super.setUpdated(false);
- } catch (SQLException ex) {
- - InnPlugin.logError("Unable to save lot #" + getId() + "!", ex);
- + InnPlugin.logError("Unable to save lot #" + super.getId() + "!", ex);
- return false;
- } finally {
- DBManager.closePreparedStatement(statement);
- @@ -831,7 +889,7 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
- public void setEnterMsg(String msg) {
- enterMsg = msg;
- - setUpdated(true);
- + super.setUpdated(true);
- }
- /**
- @@ -933,7 +991,7 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
- public void setExitMsg(String msg) {
- exitMsg = msg;
- - setUpdated(true);
- + super.setUpdated(true);
- }
- public String getExitMsg() {
- @@ -956,12 +1014,12 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
- setDisabled(false);
- setLotName("");
- - setUpdated(true);
- + super.setUpdated(true);
- }
- public void addWarpTimeUsed() {
- timesWarpUsed++;
- - setUpdated(true);
- + super.setUpdated(true);
- }
- public int getTimesWarpUsed() {
- @@ -970,6 +1028,6 @@ public class InnectisLot extends InnectisOwnedObject<Integer> {
- public void resetWarpTimesUsed() {
- timesWarpUsed = 0;
- - setUpdated(true);
- + super.setUpdated(true);
- }
- }
- diff --git a/src/net/innectis/innplugin/OwnedObjects/InnectisOwnedObject.java b/src/net/innectis/innplugin/OwnedObjects/InnectisOwnedObject.java
- index d8c579a9b..3dac3c104 100644
- --- a/src/net/innectis/innplugin/OwnedObjects/InnectisOwnedObject.java
- +++ b/src/net/innectis/innplugin/OwnedObjects/InnectisOwnedObject.java
- @@ -1,14 +1,15 @@
- package net.innectis.innplugin.OwnedObjects;
- -import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.Collections;
- +import java.util.Iterator;
- import java.util.List;
- import net.innectis.innplugin.Handlers.MemberGroupHandler;
- import net.innectis.innplugin.InnectisObjects.MemberGroup;
- import net.innectis.innplugin.Location.IdpWorldRegion;
- import net.innectis.innplugin.Player.Chat.ChatColor;
- -import net.innectis.innplugin.Player.IdpPlayer;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Player.PlayerGroup;
- import org.bukkit.Location;
- import org.bukkit.World;
- @@ -17,29 +18,31 @@ import org.bukkit.util.Vector;
- /**
- *
- * @author Lynxy
- + *
- + * TODO: remove player groups and public group support
- */
- -public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
- +public abstract class InnectisOwnedObject extends IdpWorldRegion {
- /** Status of the object. Is true when a value has been changed */
- private boolean updated = false;
- /** The ID of the given object (0 means no owner, as DB begins at 1) */
- - private IDType id;
- - /** The name of the owner of the object */
- - private String owner;
- + private int id;
- + /** The credentials of the owner of this object */
- + private PlayerCredentials ownerCredentials;
- /** List of members of this object */
- - private List<String> members;
- + private List<PlayerCredentials> members;
- /** List of operators of this object */
- - private List<String> operators;
- + private List<PlayerCredentials> operators;
- /** Long containing all the flags (set bitwise) */
- private long flags;
- /** Creates a new InnectisOwnedObject */
- - protected InnectisOwnedObject(World world, Vector pos1, Vector pos2, IDType id, String owner, List<String> members, List<String> operators, long flags) {
- + protected InnectisOwnedObject(World world, Vector pos1, Vector pos2, int id, PlayerCredentials ownerCredentials, List<PlayerCredentials> members, List<PlayerCredentials> operators, long flags) {
- super(world, pos1, pos2);
- this.id = id;
- - this.owner = owner;
- - this.members = (members == null ? new ArrayList<String>() : members);
- - this.operators = (operators == null ? new ArrayList<String>() : operators);
- + this.ownerCredentials = ownerCredentials;
- + this.members = (members == null ? new ArrayList<PlayerCredentials>() : members);
- + this.operators = (operators == null ? new ArrayList<PlayerCredentials>() : operators);
- this.flags = flags;
- }
- @@ -48,7 +51,7 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
- * @return boolean
- */
- public boolean getUpdated() {
- - return this.updated;
- + return updated;
- }
- /**
- @@ -63,33 +66,41 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
- * Returns the ID of the object
- * @return ID
- */
- - public IDType getId() {
- - return this.id;
- + public int getId() {
- + return id;
- }
- /**
- * Sets the ID of the owned object
- * @param id
- */
- - protected void setId(IDType id) {
- + protected void setId(int id) {
- this.id = id;
- }
- + /**
- + * Gets the credentials of the owner of this object
- + * @return
- + */
- + public PlayerCredentials getOwnerCredentials() {
- + return ownerCredentials;
- + }
- +
- /**
- * Returns the owner of the owned object
- * @return
- */
- public String getOwner() {
- - return this.owner;
- + return ownerCredentials.getName();
- }
- /**
- - * Sets the owner of the owned object
- - * @param owner
- + * Sets the owner credentials of this owned object
- + * @param ownerCredentials
- */
- - public void setOwner(String owner) {
- - this.owner = owner;
- - this.updated = true;
- + public void setOwner(PlayerCredentials ownerCredentials) {
- + this.ownerCredentials = ownerCredentials;
- + updated = true;
- }
- //<editor-fold defaultstate="collapsed" desc="Object members">
- @@ -99,9 +110,8 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
- * @return
- */
- public boolean isValidPlayer(String check, boolean playerOnly) {
- -
- - // Allow Wildcard
- - if (check.equalsIgnoreCase("%")) {
- + // Allow Wildcard and @ characters
- + if (check.equals("%") || check.equals("@")) {
- return true;
- }
- @@ -111,8 +121,10 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
- check = check.substring(1, check.length());
- }
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(check);
- +
- // Check if the player is valid.
- - if (PlayerGroup.getGroupOfUsername(check) != PlayerGroup.NONE) {
- + if (credentials != null) {
- return true;
- }
- @@ -125,7 +137,7 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
- return true;
- }
- - if (subString.equalsIgnoreCase("[") && MemberGroupHandler.getGroup(owner, check.substring(0, check.length() - 1)) != null) {
- + if (subString.equalsIgnoreCase("[") && MemberGroupHandler.getGroup(ownerCredentials.getUniqueId(), check.substring(0, check.length() - 1)) != null) {
- return true;
- }
- @@ -136,8 +148,8 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
- * Clears the members and operators list for this owned object
- */
- public void clearMembersAndOperators() {
- - this.members.clear();
- - this.operators.clear();
- + members.clear();
- + operators.clear();
- setUpdated(true);
- }
- @@ -145,7 +157,7 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
- * Clears the flags for this owned object
- */
- public void clearFlags() {
- - this.flags = 0;
- + flags = 0;
- setUpdated(true);
- }
- @@ -161,16 +173,16 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
- * Returns a List of each member.
- * <br /><b>This list can't be modified!</b>
- */
- - public List<String> getMembers() {
- - return Collections.unmodifiableList(this.members);
- + public List<PlayerCredentials> getMembers() {
- + return Collections.unmodifiableList(members);
- }
- /**
- * Returns a List of each operator.
- * <br /><b>This list can't be modified!</b>
- */
- - public List<String> getOperators() {
- - return Collections.unmodifiableList(this.operators);
- + public List<PlayerCredentials> getOperators() {
- + return Collections.unmodifiableList(operators);
- }
- /**
- @@ -178,18 +190,20 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
- */
- public List<MemberGroup> getMemberGroups() {
- List<MemberGroup> groups = new ArrayList<MemberGroup>();
- - MemberGroup group;
- - String groupName;
- - for (String member : members) {
- + for (PlayerCredentials pc : members) {
- + String member = pc.getName();
- +
- if (member.substring(0, 1).equalsIgnoreCase("[")
- && member.substring(member.length() - 1, member.length()).equalsIgnoreCase("]")) {
- - groupName = member.substring(1, member.length() - 1);
- - group = MemberGroupHandler.getGroup(owner, groupName);
- + String groupName = member.substring(1, member.length() - 1);
- + MemberGroup group = MemberGroupHandler.getGroup(ownerCredentials.getUniqueId(), groupName);
- +
- if (group != null) {
- groups.add(group);
- }
- }
- }
- +
- return groups;
- }
- @@ -200,47 +214,25 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
- StringBuilder sb = new StringBuilder();
- String groupName;
- MemberGroup group;
- - PlayerGroup playerGroup;
- // First print operators!
- - for (String name : this.operators) {
- + for (PlayerCredentials pc : operators) {
- + String name = pc.getName();
- +
- if (userColor != null) {
- sb.append(opColor);
- }
- sb.append(name).append(", ");
- }
- - // After operators, lets print player groups.
- - for (String name : this.members) {
- - if (name.substring(0, 1).equalsIgnoreCase("#")) {
- - playerGroup = PlayerGroup.getGroup(name.substring(1, name.length()));
- -
- - switch (playerGroup) {
- - case NONE:
- - if (userColor != null) {
- - sb.append(userColor);
- - }
- - sb.append(name).append(", ");
- - continue;
- - }
- - if (groupColor != null) {
- - sb.append(playerGroup.color);
- - }
- - // sb.append(groupColor);
- - sb.append(playerGroup.name);
- - if (userColor != null) {
- - sb.append(userColor);
- - }
- - sb.append(", ");
- - }
- - }
- -
- // Print members
- - for (String name : this.members) {
- + for (PlayerCredentials pc : members) {
- + String name = pc.getName();
- +
- if (name.substring(0, 1).equalsIgnoreCase("[")
- && name.substring(name.length() - 1, name.length()).equalsIgnoreCase("]")) {
- groupName = name.substring(1, name.length() - 1);
- - group = MemberGroupHandler.getGroup(owner, groupName);
- + group = MemberGroupHandler.getGroup(ownerCredentials.getUniqueId(), groupName);
- if (group == null) {
- if (customGroupColor != null) {
- sb.append(customGroupColor);
- @@ -259,6 +251,7 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
- sb.append(name).append(", ");
- }
- }
- +
- if (sb.length() == 0) {
- return "none";
- }
- @@ -266,83 +259,122 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
- }
- /**
- - * Adds the given name as member of this object.
- + * Adds the credentials of the given player as member of this object.
- * If the given name is already a member or operator, this method will return false;
- - * @param name
- + * @param credentials
- */
- - public boolean addMember(String name) {
- - name = name.toLowerCase();
- - if (this.containsMember(name) || this.containsOperator(name)) {
- + public boolean addMember(PlayerCredentials credentials) {
- + if (containsMember(credentials.getName()) || containsOperator(credentials.getName())) {
- return false;
- }
- - this.members.add(name);
- - this.updated = true;
- +
- + members.add(credentials);
- + updated = true;
- return true;
- }
- /**
- - * Removes a member and returns true. If member didn't exist in first place, returns false
- - * @param name
- + * Removes the specified player from this owned object.
- + * If member didn't exist in first place, returns false
- + * @param playerName
- */
- - public boolean removeMember(String name) {
- - String name2 = name.toLowerCase();
- - if (this.members.contains(name2)) {
- - this.members.remove(name2);
- - this.updated = true;
- + public boolean removeMember(String playerName) {
- + boolean removed = false;
- +
- + for (Iterator<PlayerCredentials> it = members.iterator(); it.hasNext();) {
- + PlayerCredentials pc = it.next();
- +
- + if (pc.getName().equalsIgnoreCase(playerName)) {
- + it.remove();
- + removed = true;
- + break;
- + }
- +
- + }
- +
- + if (removed) {
- + updated = true;
- return true;
- + } else {
- + return false;
- }
- - return false;
- }
- /**
- - * This method add an operator.
- - * If the given name is a member, it will be removed from the member list and added to the operator list.
- - * @param name
- + * Adds the credentials of the specified player as an operator
- + * if this is a member already added, it will be removed from
- + * the member list and added to the operator list.
- + * @param credentials
- */
- - public boolean addOperator(String name) {
- - name = name.toLowerCase();
- - if (this.containsOperator(name)) {
- + public boolean addOperator(PlayerCredentials credentials) {
- + if (containsOperator(credentials.getName())) {
- return false;
- }
- +
- // Remove from members, if given name is a member
- - if (this.containsMember(name)) {
- - this.members.remove(name);
- + if (containsMember(credentials.getName())) {
- + members.remove(credentials);
- }
- - this.operators.add(name);
- - this.updated = true;
- +
- + operators.add(credentials);
- + updated = true;
- return true;
- }
- /**
- - * Removes an operator and returns true. If operator didn't exist in first place, returns false
- - * @param name
- + * Removes the given player from this object.
- + * If operator didn't exist in first place, returns false
- + * @param playerName
- */
- - public boolean removeOperator(String name) {
- - String name2 = name.toLowerCase();
- - if (this.operators.contains(name2)) {
- - this.operators.remove(name2);
- - this.updated = true;
- + public boolean removeOperator(String playerName) {
- + boolean removed = false;
- +
- + for (Iterator<PlayerCredentials> it = operators.iterator(); it.hasNext();) {
- + PlayerCredentials pc = it.next();
- +
- + if (pc.getName().equalsIgnoreCase(playerName)) {
- + it.remove();
- + removed = true;
- + break;
- + }
- + }
- +
- + if (removed) {
- + updated = true;
- return true;
- + } else {
- + return false;
- }
- - return false;
- }
- /**
- - * Checks if the given name is a member or of the object.
- - * @param name
- + * Checks if the player is a valid member
- + * @param playerName
- * @return
- */
- - public boolean containsMember(String name) {
- - return name != null && this.members.contains(name.toLowerCase());
- + public boolean containsMember(String playerName) {
- + for (PlayerCredentials pc : members) {
- + if (pc.getName().equalsIgnoreCase(playerName)) {
- + return true;
- + }
- + }
- +
- + return false;
- }
- /**
- - * Checks if the given name is an operator of the object.
- - * @param name
- + * Checks if the player is a valid operator
- + * @param playerName
- * @return
- */
- - public boolean containsOperator(String name) {
- - return name != null && this.operators.contains(name.toLowerCase());
- + public boolean containsOperator(String playerName) {
- + for (PlayerCredentials pc : operators) {
- + if (pc.getName().equalsIgnoreCase(playerName)) {
- + return true;
- + }
- + }
- +
- + return false;
- }
- /**
- @@ -351,39 +383,35 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
- * @param group
- * @return
- */
- - public boolean containsGroup(PlayerGroup group) {
- - return this.members.contains("#" + group.name.replace(" ", "_").toLowerCase());
- + public boolean containsPlayerGroup(PlayerGroup group) {
- + return members.contains("#" + group.name.replace(" ", "_").toLowerCase());
- }
- //</editor-fold>
- /**
- - * 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
- - * @param player
- - */
- - public boolean canPlayerAccess(IdpPlayer player) {
- - return canPlayerAccess(player.getName());
- - }
- -
- - /**
- - * 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
- - * @param name
- + * Returns true if the player represented by the ID is the owner
- + * or member, the object has % as a special member, the player is
- + * an operator, or whose player group is part of this lot
- + * on this object
- + * @param playerName
- */
- - public boolean canPlayerAccess(String name) {
- - name = name.toLowerCase();
- - if (this.owner.equalsIgnoreCase("%") || this.owner.equalsIgnoreCase(name)) {
- + public boolean canPlayerAccess(String playerName) {
- + if (ownerCredentials.getName().equalsIgnoreCase(playerName)) {
- return true;
- }
- - if (this.containsMember("%") || this.containsMember(name) || this.containsOperator(name)) {
- + if (containsMember("%") || containsMember(playerName) || containsOperator(playerName)) {
- return true;
- }
- - if (this.containsGroup(PlayerGroup.getGroupOfUsername(name))) {
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- +
- + if (containsPlayerGroup(PlayerGroup.getGroupOfPlayerById(credentials.getUniqueId()))) {
- return true;
- }
- for (MemberGroup group : getMemberGroups()) {
- - if (group != null && group.containsMember(name)) {
- + if (group != null && group.containsMember(playerName)) {
- return true;
- }
- }
- @@ -392,47 +420,29 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
- }
- /**
- - * Checks if the given player can manage the object
- - * @param name
- - * @return
- - */
- - public boolean canPlayerManage(IdpPlayer player) {
- - return canPlayerManage(player.getName());
- - }
- -
- - /**
- - * Checks if the given playername can manage the object
- - * @param name
- + * Checks if the player player can manage this object
- + * @param playerName
- * @return
- */
- - public boolean canPlayerManage(String name) {
- - return this.owner.equalsIgnoreCase(name) || this.containsOperator(name);
- + public boolean canPlayerManage(String playerName) {
- + return ownerCredentials.getUniqueId().equals(playerName) || containsOperator(playerName);
- }
- /**
- - * Returns true if the player is the owner,contains operator, a member or is part of a member group on this object.
- + * Returns true if the player represented by the ID is the owner,
- + * contains operator, a member or is part of a member group on
- + * this object.
- * <p/>
- * This ignores the generic lotmember '%'
- - * @param player
- + * @param playerName
- */
- - public boolean canPlayerAccessIgnoreGeneric(IdpPlayer player) {
- - return canPlayerAccessIgnoreGeneric(player.getName());
- - }
- -
- - /**
- - * Returns true if the player is the owner,contains operator, a member or is part of a member group on this object.
- - * <p/>
- - * This ignores the generic lotmember '%'
- - * @param name
- - */
- - public boolean canPlayerAccessIgnoreGeneric(String name) {
- - name = name.toLowerCase();
- - if (this.owner.equalsIgnoreCase(name) || this.containsMember(name) || this.containsOperator(name)) {
- + public boolean canPlayerAccessIgnoreGeneric(String playerName) {
- + if (ownerCredentials.getName().equalsIgnoreCase(playerName) || containsMember(playerName) || containsOperator(playerName)) {
- return true;
- }
- for (MemberGroup group : getMemberGroups()) {
- - if (group != null && group.containsMember(name)) {
- + if (group != null && group.containsMember(playerName)) {
- return true;
- }
- }
- @@ -560,22 +570,22 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
- * @param flag
- */
- public boolean isFlagSetNoInheritance(FlagType flag) {
- - return ((this.flags & flag.getFlagBit()) == flag.getFlagBit());
- + return ((flags & flag.getFlagBit()) == flag.getFlagBit());
- }
- /**
- * Returns all flags set on this object
- */
- public long getFlags() {
- - return this.flags;
- + return flags;
- }
- /**
- * Sets the flags on this object. Note: this does not turn a flag on or off! Use setFlag() for that
- */
- public void setFlags(long flags) {
- - this.flags = flags;
- - this.updated = true;
- + flags = flags;
- + updated = true;
- }
- /**
- @@ -594,30 +604,30 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
- */
- public void setFlag(long flag, boolean disable) {
- if (disable) {
- - this.flags &= ~flag;
- + flags &= ~flag;
- } else {
- - this.flags |= flag;
- + flags |= flag;
- }
- - this.updated = true;
- + updated = true;
- }
- //</editor-fold>
- @Override
- public void setPos1(Vector point) {
- super.setPos1(point);
- - this.updated = true;
- + updated = true;
- }
- @Override
- public void setPos2(Vector point) {
- super.setPos2(point);
- - this.updated = true;
- + updated = true;
- }
- @Override
- public void setWorld(World world) {
- super.setWorld(world);
- - this.updated = true;
- + updated = true;
- }
- /** Returns the name of the owned object */
- @@ -625,7 +635,6 @@ public abstract class InnectisOwnedObject<IDType> extends IdpWorldRegion {
- /**
- * Saves the object object to the database
- - * @throws SQLException
- * @return true if the method had no errors, false if there
- * was an error saving to the database. Behavior modified
- * for design simplicity
- diff --git a/src/net/innectis/innplugin/OwnedObjects/InnectisSwitch.java b/src/net/innectis/innplugin/OwnedObjects/InnectisSwitch.java
- index 83fb20bf0..d7f37eb63 100644
- --- a/src/net/innectis/innplugin/OwnedObjects/InnectisSwitch.java
- +++ b/src/net/innectis/innplugin/OwnedObjects/InnectisSwitch.java
- @@ -10,6 +10,7 @@ import java.util.Iterator;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.Map;
- +import java.util.UUID;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import net.innectis.innplugin.Handlers.BlockHandler;
- @@ -17,6 +18,8 @@ import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.InnectisObjects.MemberGroup;
- import net.innectis.innplugin.Player.Chat.ChatColor;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.World;
- @@ -30,23 +33,23 @@ import org.bukkit.util.Vector;
- *
- * A switch in the IDP which can be owned and linked.
- */
- -public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- +public class InnectisSwitch extends InnectisOwnedObject {
- private static final Map<Integer, InnectisSwitch> switchChache = Collections.synchronizedMap(new HashMap<Integer, InnectisSwitch>());
- private List<Integer> links;
- - public InnectisSwitch(Location loc, String owner) {
- - this(loc.getWorld(), loc.toVector(), owner);
- - this.setUpdated(true);
- + public InnectisSwitch(Location loc, PlayerCredentials ownerCredentials) {
- + this(loc.getWorld(), loc.toVector(), ownerCredentials);
- + super.setUpdated(true);
- }
- - public InnectisSwitch(World world, Vector loc, String owner) {
- - super(world, loc, loc, -1, owner, null, null, 0);
- - this.links = new ArrayList<Integer>();
- - this.setUpdated(true);
- + public InnectisSwitch(World world, Vector loc, PlayerCredentials ownerCredentials) {
- + super(world, loc, loc, -1, ownerCredentials, null, null, 0);
- + links = new ArrayList<Integer>();
- + super.setUpdated(true);
- }
- - private InnectisSwitch(Integer id, String owner, World world, Vector loc, long flags, List<Integer> links) {
- - super(world, loc, loc, id, owner, null, null, flags);
- + private InnectisSwitch(Integer id, PlayerCredentials ownerCredentials, World world, Vector loc, long flags, List<Integer> links) {
- + super(world, loc, loc, id, ownerCredentials, null, null, flags);
- this.links = links;
- }
- @@ -54,7 +57,7 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- * Not supported
- */
- @Override
- - public List<String> getMembers() {
- + public List<PlayerCredentials> getMembers() {
- return Collections.emptyList();
- }
- @@ -62,7 +65,7 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- * Not supported
- */
- @Override
- - public List<String> getOperators() {
- + public List<PlayerCredentials> getOperators() {
- return Collections.emptyList();
- }
- @@ -78,7 +81,7 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- * Not supported
- */
- @Override
- - public boolean containsMember(String name) {
- + public boolean containsMember(String playerName) {
- return false; // No members
- }
- @@ -86,7 +89,7 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- * Not supported
- */
- @Override
- - public boolean containsOperator(String name) {
- + public boolean containsOperator(String playerName) {
- return false; // No ops
- }
- @@ -94,7 +97,7 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- * Not supported
- */
- @Override
- - public boolean addMember(String name) {
- + public boolean addMember(PlayerCredentials credentials) {
- return false; // No members
- }
- @@ -102,7 +105,7 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- * Not supported
- */
- @Override
- - public boolean addOperator(String name) {
- + public boolean addOperator(PlayerCredentials credentials) {
- return false;
- }
- @@ -126,16 +129,16 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- * Not supported
- */
- @Override
- - public boolean removeMember(String name) {
- - return super.removeMember(name);
- + public boolean removeMember(String playerName) {
- + return super.removeMember(playerName);
- }
- /**
- * Not supported
- */
- @Override
- - public boolean removeOperator(String name) {
- - return super.removeOperator(name);
- + public boolean removeOperator(String playerName) {
- + return super.removeOperator(playerName);
- }
- /**
- @@ -163,7 +166,7 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- */
- @Override
- public boolean isAtLocation(Location location) {
- - return this.getPos1().equals(location.toVector());
- + return super.getPos1().equals(location.toVector());
- }
- /**
- @@ -172,9 +175,9 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- * @param switchid
- */
- public boolean addLink(int switchid) {
- - if (!links.contains(switchid) && switchid != getId()) {
- + if (!links.contains(switchid) && switchid != super.getId()) {
- // Add link both directions
- - this.links.add(switchid);
- + links.add(switchid);
- createDBLink(getId(), switchid);
- InnectisSwitch temp = getSwitch(switchid);
- @@ -185,22 +188,23 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- for (int id : links) {
- temp = getSwitch(id);
- if (temp != null) {
- - temp.updateLinks(this.links);
- + temp.updateLinks(links);
- }
- }
- // Update other switch and their links
- - temp.updateLinks(this.links);
- + temp.updateLinks(links);
- // Share the new link with all switches that are already linked
- for (int id : temp.links) {
- temp = getSwitch(id);
- if (temp != null) {
- - temp.updateLinks(this.links);
- + temp.updateLinks(links);
- }
- }
- return true;
- }
- +
- return false;
- }
- @@ -210,9 +214,9 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- */
- public void updateLinks(List<Integer> newLinks) {
- for (int id : newLinks) {
- - if (!this.links.contains(id) && id != getId()) {
- - this.links.add(id);
- - createDBLink(id, this.getId());
- + if (!links.contains(id) && id != super.getId()) {
- + links.add(id);
- + createDBLink(id, super.getId());
- }
- }
- }
- @@ -242,7 +246,7 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- * @return TRUE if ON
- */
- public boolean getOnState() {
- - byte dat = BlockHandler.getBlockData(getPos1Location().getBlock());
- + byte dat = BlockHandler.getBlockData(super.getPos1Location().getBlock());
- return dat > 8;
- }
- @@ -250,7 +254,7 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- * Toggles this switch and all coppled switches
- */
- public void toggleAll() {
- - toggleSwitch(this.getPos1Location());
- + toggleSwitch(super.getPos1Location());
- toggleLinkedSwitches();
- }
- @@ -285,17 +289,17 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- /**
- * This method will try to find a switch at the given location, or create one if not.
- * @param location
- - * @param playername
- + * @param credentials
- * @return the existing or new switch
- */
- - public static InnectisSwitch createOrGetSwitch(Location location, String playername) {
- + public static InnectisSwitch createOrGetSwitch(Location location, PlayerCredentials credentials) {
- InnectisSwitch sw = getSwitch(location);
- if (sw == null) {
- - sw = new InnectisSwitch(location, playername);
- + sw = new InnectisSwitch(location, credentials);
- if (!sw.save()) {
- - InnPlugin.logError("Could not create switch on location: " + location + " for " + playername + "!");
- + InnPlugin.logError("Could not create switch on location: " + location + " for " + credentials + "!");
- }
- }
- return sw;
- @@ -305,11 +309,11 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- * Creates a switch at the given location, or gets the switch on the given
- * location and returns the ID of this switch.
- * @param location
- - * @param playername
- + * @param credentials
- * @return
- */
- - public static int createOrGetSwitchId(Location location, String playername) {
- - return createOrGetSwitch(location, playername).getId();
- + public static int createOrGetSwitchId(Location location, PlayerCredentials credentials) {
- + return createOrGetSwitch(location, credentials).getId();
- }
- /**
- @@ -327,7 +331,7 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- ResultSet result = null;
- try {
- - statement = DBManager.prepareStatement("SELECT switchid, owner, locx, locy, locz, world, flags FROM switches WHERE switchid = ? ");
- + statement = DBManager.prepareStatement("SELECT switchid, owner_id, locx, locy, locz, world, flags FROM switches WHERE switchid = ? ");
- statement.setInt(1, id);
- result = statement.executeQuery();
- @@ -346,16 +350,18 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- /**
- * Looks up all the switches owned by the given player.
- - * @param owner
- + * @param playerName
- * @return List of the switches or null is none.
- */
- - public static List<InnectisSwitch> getSwitches(String owner) {
- + public static List<InnectisSwitch> getSwitches(String playerName) {
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(playerName);
- +
- PreparedStatement statement = null;
- ResultSet set = null;
- try {
- - statement = DBManager.prepareStatement("SELECT switchid, owner, locx, locy, locz, world, flags FROM switches WHERE owner = ? ");
- - statement.setString(1, owner.toLowerCase());
- + statement = DBManager.prepareStatement("SELECT switchid, owner_id, locx, locy, locz, world, flags FROM switches WHERE owner_id = ? ");
- + statement.setString(1, credentials.getUniqueId().toString());
- set = statement.executeQuery();
- List<InnectisSwitch> switches = new ArrayList<InnectisSwitch>(set.getFetchSize());
- @@ -393,7 +399,10 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- Vector loc = new Vector(result.getInt("locx"), result.getInt("locy"), result.getInt("locz"));
- long flags = result.getLong("flags");
- - String owner = result.getString("owner");
- +
- + String ownerIdString = result.getString("owner_id");
- + UUID ownerId = UUID.fromString(ownerIdString);
- + PlayerCredentials ownerCredentials = PlayerCredentialsManager.getByUniqueId(ownerId, true);
- // Load the links
- PreparedStatement statement = DBManager.prepareStatement("SELECT switcha, switchb FROM switches_links WHERE switcha = ? OR switchb = ? ");
- @@ -421,7 +430,7 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- DBManager.closePreparedStatement(statement);
- // Create the switch
- - InnectisSwitch returnvalue = new InnectisSwitch(switchid, owner, world, loc, flags, links);
- + InnectisSwitch returnvalue = new InnectisSwitch(switchid, ownerCredentials, world, loc, flags, links);
- // Add to chache
- synchronized (switchChache) {
- @@ -449,7 +458,7 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- ResultSet result = null;
- try {
- - statement = DBManager.prepareStatement("SELECT switchid, owner, locx, locy, locz, world, flags FROM switches "
- + statement = DBManager.prepareStatement("SELECT switchid, owner_id, locx, locy, locz, world, flags FROM switches "
- + " WHERE locx = ? AND locy = ? AND locz = ? AND world = ? ");
- statement.setInt(1, location.getBlockX());
- statement.setInt(2, location.getBlockY());
- @@ -475,8 +484,8 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- */
- @Override
- public boolean save() {
- - if (this.getUpdated()) {
- - if (this.getId() < 0) {
- + if (super.getUpdated()) {
- + if (super.getId() < 0) {
- return createInDB();
- } else {
- return updateInDB();
- @@ -497,19 +506,19 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- try {
- statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO switches "
- - + " (owner, locx, locy, locz, world, flags) VALUES (?, ?, ?, ?, ?, ?) ");
- - statement.setString(1, super.getOwner());
- - statement.setInt(2, getPos1().getBlockX());
- - statement.setInt(3, getPos1().getBlockY());
- - statement.setInt(4, getPos1().getBlockZ());
- - statement.setString(5, getWorld().getName());
- - statement.setLong(6, getFlags());
- + + " (owner_id, locx, locy, locz, world, flags) VALUES (?, ?, ?, ?, ?, ?) ");
- + statement.setString(1, super.getOwnerCredentials().getUniqueId().toString());
- + statement.setInt(2, super.getPos1().getBlockX());
- + statement.setInt(3, super.getPos1().getBlockY());
- + statement.setInt(4, super.getPos1().getBlockZ());
- + statement.setString(5, super.getWorld().getName());
- + statement.setLong(6, super.getFlags());
- statement.executeUpdate();
- result = statement.getGeneratedKeys();
- if (result.next()) {
- - setId(result.getInt(1));
- - setUpdated(false);
- + super.setId(result.getInt(1));
- + super.setUpdated(false);
- } else {
- InnPlugin.logError("New switch not found in the database!");
- return false;
- @@ -535,8 +544,8 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- try {
- statement = DBManager.prepareStatement("UPDATE switches SET flags = ? WHERE switchid = ?;");
- - statement.setLong(1, getFlags());
- - statement.setInt(2, getId());
- + statement.setLong(1, super.getFlags());
- + statement.setInt(2, super.getId());
- statement.executeUpdate();
- setUpdated(false);
- } catch (SQLException ex) {
- @@ -559,8 +568,8 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- try {
- // Remove the DB links
- statement = DBManager.prepareStatement(" DELETE FROM switches_links WHERE switcha = ? OR switchb = ? ");
- - statement.setInt(1, getId());
- - statement.setInt(2, getId());
- + statement.setInt(1, super.getId());
- + statement.setInt(2, super.getId());
- statement.executeUpdate();
- // Remove the link of other switches
- @@ -568,12 +577,12 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- for (int id : links) {
- tmp = getSwitch(id);
- if (tmp != null) {
- - tmp.removeFromLinksList(getId());
- + tmp.removeFromLinksList(super.getId());
- }
- }
- // Clear own links
- - this.links.clear();
- + links.clear();
- } catch (SQLException ex) {
- Logger.getLogger(InnectisSwitch.class.getName()).log(Level.SEVERE, null, ex);
- } finally {
- @@ -587,24 +596,25 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- * @return true if the ID was in the list.
- */
- private boolean removeFromLinksList(int id) {
- - if (this.links.contains(id)) {
- + if (links.contains(id)) {
- for (Iterator<Integer> it = links.iterator(); it.hasNext();) {
- Integer currid = it.next();
- if (currid == id) {
- it.remove();
- }
- }
- +
- return true;
- }
- +
- return false;
- }
- /**
- - * Deletes an switch
- - * @throws SQLException
- + * Deletes a switch
- */
- public void delete() {
- - if (getId() <= 0) {
- + if (super.getId() <= 0) {
- return;
- }
- @@ -613,19 +623,19 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- try {
- // Remove the switch
- statement = DBManager.prepareStatement(" DELETE FROM switches WHERE switchid = ? ");
- - statement.setInt(1, getId());
- + statement.setInt(1, super.getId());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- // Remove all links
- statement = DBManager.prepareStatement(" DELETE FROM switches_links WHERE switcha = ? OR switchb = ? ");
- - statement.setInt(1, getId());
- - statement.setInt(2, getId());
- + statement.setInt(1, super.getId());
- + statement.setInt(2, super.getId());
- statement.executeUpdate();
- // Remove from chache
- synchronized (switchChache) {
- - switchChache.remove(this.getId());
- + switchChache.remove(super.getId());
- }
- // Unlink their links
- @@ -633,11 +643,11 @@ public class InnectisSwitch extends InnectisOwnedObject<Integer> {
- for (int id : links) {
- tmp = getSwitch(id);
- if (tmp != null) {
- - tmp.removeFromLinksList(getId());
- + tmp.removeFromLinksList(super.getId());
- }
- }
- - this.setId(-1);
- + super.setId(-1);
- } catch (SQLException sqle) {
- InnPlugin.logError("Could not remove Switch", sqle);
- } finally {
- diff --git a/src/net/innectis/innplugin/OwnedObjects/InnectisTrapdoor.java b/src/net/innectis/innplugin/OwnedObjects/InnectisTrapdoor.java
- index 417370bc3..117c0e28a 100644
- --- a/src/net/innectis/innplugin/OwnedObjects/InnectisTrapdoor.java
- +++ b/src/net/innectis/innplugin/OwnedObjects/InnectisTrapdoor.java
- @@ -6,6 +6,7 @@ import java.sql.SQLException;
- import java.util.List;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- import org.bukkit.Location;
- import org.bukkit.World;
- import org.bukkit.block.Block;
- @@ -15,11 +16,11 @@ import org.bukkit.block.Block;
- *
- * @author AlphaBlend
- */
- -public class InnectisTrapdoor extends InnectisOwnedObject<Integer> {
- - Block trapdoor;
- +public class InnectisTrapdoor extends InnectisOwnedObject {
- + private Block trapdoor;
- - public InnectisTrapdoor(World world, Location loc, int id, String owner, List<String> members, List<String> operators, long flags) {
- - super(world, loc.toVector(), loc.toVector(), id, owner, members, operators, flags);
- + public InnectisTrapdoor(World world, Location loc, int id, PlayerCredentials ownerCredentials, List<PlayerCredentials> members, List<PlayerCredentials> operators, long flags) {
- + super(world, loc.toVector(), loc.toVector(), id, ownerCredentials, members, operators, flags);
- trapdoor = loc.getBlock();
- }
- @@ -44,18 +45,18 @@ public class InnectisTrapdoor extends InnectisOwnedObject<Integer> {
- int y = loc.getBlockY();
- int z = loc.getBlockZ();
- - statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO trapdoors (owner, world, locx, locy, locz, flags) VALUES (?, ?, ?, ?, ?, ?)");
- - statement.setString(1, this.getOwner());
- + statement = DBManager.prepareStatementWithAutoGeneratedKeys("INSERT INTO trapdoors (owner_id, world, locx, locy, locz, flags) VALUES (?, ?, ?, ?, ?, ?)");
- + statement.setString(1, super.getOwnerCredentials().getUniqueId().toString());
- statement.setString(2, loc.getWorld().getName());
- statement.setInt(3, x);
- statement.setInt(4, y);
- statement.setInt(5, z);
- - statement.setLong(6, getFlags());
- + statement.setLong(6, super.getFlags());
- statement.execute();
- set = statement.getGeneratedKeys();
- if (set.next()) {
- - setId(set.getInt(1));
- + super.setId(set.getInt(1));
- } else {
- InnPlugin.logError("New trapdoor not found in the database!");
- return false;
- @@ -79,9 +80,11 @@ public class InnectisTrapdoor extends InnectisOwnedObject<Integer> {
- return trapdoor.getLocation();
- }
- + // TODO: Add check for lot access
- +
- @Override
- public boolean save() {
- - if (getId() == 0) {
- + if (super.getId() == 0) {
- return createTrapdoorInDB();
- }
- @@ -94,34 +97,34 @@ public class InnectisTrapdoor extends InnectisOwnedObject<Integer> {
- PreparedStatement statement = null;
- try {
- - statement = DBManager.prepareStatement("UPDATE trapdoors SET owner = ?, world = ?, locx = ?, locy = ?, locz = ?, flags = ? WHERE trapdoorid = ?");
- - statement.setString(1, getOwner());
- + statement = DBManager.prepareStatement("UPDATE trapdoors SET owner_id = ?, world = ?, locx = ?, locy = ?, locz = ?, flags = ? WHERE trapdoorid = ?");
- + statement.setString(1, super.getOwnerCredentials().getUniqueId().toString());
- statement.setString(2, loc.getWorld().getName());
- statement.setInt(3, x);
- statement.setInt(4, y);
- statement.setInt(5, z);
- - statement.setLong(6, getFlags());
- - statement.setInt(7, getId());
- + statement.setLong(6, super.getFlags());
- + statement.setInt(7, super.getId());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- statement = DBManager.prepareStatement("DELETE FROM trapdoors_members WHERE trapdoorid = ?");
- - statement.setInt(1, getId());
- + statement.setInt(1, super.getId());
- statement.execute();
- DBManager.closePreparedStatement(statement);
- - for (String member : getMembers()) {
- - statement = DBManager.prepareStatement("INSERT INTO trapdoors_members (trapdoorid, username, isop) VALUES (?, ?, 0)");
- - statement.setInt(1, getId());
- - statement.setString(2, member);
- + for (PlayerCredentials pc : getMembers()) {
- + statement = DBManager.prepareStatement("INSERT INTO trapdoors_members (trapdoorid, player_id, isop) VALUES (?, ?, 0)");
- + statement.setInt(1, super.getId());
- + statement.setString(2, pc.getUniqueId().toString());
- statement.execute();
- DBManager.closePreparedStatement(statement);
- }
- - for (String member : getOperators()) {
- - statement = DBManager.prepareStatement("INSERT INTO trapdoors_members (trapdoorid, username, isop) VALUES (?, ?, 1)");
- - statement.setInt(1, getId());
- - statement.setString(2, member);
- + for (PlayerCredentials pc : getOperators()) {
- + statement = DBManager.prepareStatement("INSERT INTO trapdoors_members (trapdoorid, player_id, isop) VALUES (?, ?, 1)");
- + statement.setInt(1, super.getId());
- + statement.setString(2, pc.getUniqueId().toString());
- statement.execute();
- DBManager.closePreparedStatement(statement);
- }
- diff --git a/src/net/innectis/innplugin/OwnedObjects/InnectisWaypoint.java b/src/net/innectis/innplugin/OwnedObjects/InnectisWaypoint.java
- index ff62394a7..5fe1271a3 100644
- --- a/src/net/innectis/innplugin/OwnedObjects/InnectisWaypoint.java
- +++ b/src/net/innectis/innplugin/OwnedObjects/InnectisWaypoint.java
- @@ -8,7 +8,7 @@ import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.Items.IdpMaterial;
- import net.innectis.innplugin.OwnedObjects.Handlers.LotHandler;
- -import net.innectis.innplugin.Player.IdpPlayer;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- import org.bukkit.Location;
- import org.bukkit.World;
- import org.bukkit.block.Block;
- @@ -17,20 +17,20 @@ import org.bukkit.block.Block;
- *
- * @author Lynxy
- */
- -public class InnectisWaypoint extends InnectisOwnedObject<Integer> {
- +public class InnectisWaypoint extends InnectisOwnedObject {
- private Block waypoint;
- private Location destination;
- private boolean forced;
- - public InnectisWaypoint(World world, Block waypoint, Location destination, int id, String owner, List<String> members, List<String> operators, long flags, boolean forced) {
- - super(world, waypoint.getLocation().toVector(), waypoint.getLocation().toVector(), id, owner, members, operators, flags);
- + public InnectisWaypoint(World world, Block waypoint, Location destination, int id, PlayerCredentials ownerCredentials, List<PlayerCredentials> members, List<PlayerCredentials> operators, long flags, boolean forced) {
- + super(world, waypoint.getLocation().toVector(), waypoint.getLocation().toVector(), id, ownerCredentials, members, operators, flags);
- this.waypoint = waypoint;
- this.destination = destination;
- this.forced = forced;
- }
- - public InnectisWaypoint(Block waypoint, Location destination, int id, String owner, List<String> members, List<String> operators, long flags, boolean forced) {
- - this(waypoint.getWorld(), waypoint, destination, id, owner, members, operators, flags, forced);
- + public InnectisWaypoint(Block waypoint, Location destination, int id, PlayerCredentials ownerCredentials, List<PlayerCredentials> members, List<PlayerCredentials> operators, long flags, boolean forced) {
- + this(waypoint.getWorld(), waypoint, destination, id, ownerCredentials, members, operators, flags, forced);
- }
- @Override
- @@ -72,6 +72,7 @@ public class InnectisWaypoint extends InnectisOwnedObject<Integer> {
- && waypoint.getLocation().getBlockZ() == location.getBlockZ()) {
- return true;
- }
- +
- return false;
- }
- @@ -86,18 +87,20 @@ public class InnectisWaypoint extends InnectisOwnedObject<Integer> {
- }
- /**
- - * 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
- + * 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
- * @ and player is a member of the Lot this waypoint is on
- - * @param player
- + * @param playerName
- */
- @Override
- - public boolean canPlayerAccess(IdpPlayer player) {
- - if (super.canPlayerAccess(player)) {
- + public boolean canPlayerAccess(String playerName) {
- + if (super.canPlayerAccess(playerName)) {
- return true;
- }
- +
- if (containsMember("@")) { //allow lot members
- InnectisLot lot = LotHandler.getLot(waypoint.getLocation());
- - if (lot != null && (lot.containsMember(player.getName()) || lot.containsOperator(player.getName()))) {
- + if (lot != null && (lot.containsMember(playerName) || lot.containsOperator(playerName))) {
- return true;
- }
- }
- @@ -118,10 +121,10 @@ public class InnectisWaypoint extends InnectisOwnedObject<Integer> {
- try {
- statement = DBManager.prepareStatementWithAutoGeneratedKeys("REPLACE INTO waypoints "
- - + "(owner, world, locx, locy, locz, tworld, tlocx, tlocy, tlocz, tyaw, flags, forced)"
- + + "(owner_id, world, locx, locy, locz, tworld, tlocx, tlocy, tlocz, tyaw, flags, forced)"
- + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
- - statement.setString(1, getOwner());
- - statement.setString(2, getWorld().getName());
- + statement.setString(1, super.getOwnerCredentials().getUniqueId().toString());
- + statement.setString(2, super.getWorld().getName());
- statement.setInt(3, getWaypoint().getX());
- statement.setInt(4, getWaypoint().getY());
- statement.setInt(5, getWaypoint().getZ());
- @@ -130,14 +133,14 @@ public class InnectisWaypoint extends InnectisOwnedObject<Integer> {
- statement.setInt(8, getDestination().getBlockY());
- statement.setInt(9, getDestination().getBlockZ());
- statement.setFloat(10, getDestination().getYaw());
- - statement.setLong(11, getFlags());
- + statement.setLong(11, super.getFlags());
- statement.setBoolean(12, isForced());
- statement.executeUpdate();
- result = statement.getGeneratedKeys();
- if (result.next()) {
- - setId(result.getInt(1));
- - setUpdated(false);
- + super.setId(result.getInt(1));
- + super.setUpdated(false);
- } else {
- InnPlugin.logError("New waypoint not found in the database!");
- return false;
- @@ -155,7 +158,7 @@ public class InnectisWaypoint extends InnectisOwnedObject<Integer> {
- @Override
- public boolean save() {
- - if (getId() == -1) {
- + if (super.getId() == -1) {
- return createWaypointInDB();
- }
- @@ -163,21 +166,13 @@ public class InnectisWaypoint extends InnectisOwnedObject<Integer> {
- try {
- statement = DBManager.prepareStatement("UPDATE waypoints SET "
- - + "owner = ?, "
- - + "world = ?, "
- - + "locx = ?, "
- - + "locy = ?, "
- - + "locz = ?, "
- - + "tworld = ?, "
- - + "tlocx = ?, "
- - + "tlocy = ?, "
- - + "tlocz = ?, "
- - + "tyaw = ?, "
- - + "flags = ?, "
- - + "forced = ? "
- + + "owner_id = ?, world = ?, locx = ?, "
- + + "locy = ?, locz = ?, tworld = ?, "
- + + "tlocx = ?, tlocy = ?, tlocz = ?, "
- + + "tyaw = ?, flags = ?, forced = ? "
- + "WHERE waypointid = ?;");
- - statement.setString(1, getOwner());
- - statement.setString(2, getWorld().getName());
- + statement.setString(1, super.getOwnerCredentials().getUniqueId().toString());
- + statement.setString(2, super.getWorld().getName());
- statement.setInt(3, getWaypoint().getX());
- statement.setInt(4, getWaypoint().getY());
- statement.setInt(5, getWaypoint().getZ());
- @@ -186,34 +181,34 @@ public class InnectisWaypoint extends InnectisOwnedObject<Integer> {
- statement.setInt(8, getDestination().getBlockY());
- statement.setInt(9, getDestination().getBlockZ());
- statement.setFloat(10, getDestination().getYaw());
- - statement.setLong(11, getFlags());
- + statement.setLong(11, super.getFlags());
- statement.setBoolean(12, isForced());
- - statement.setInt(13, getId());
- + statement.setInt(13, super.getId());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- statement = DBManager.prepareStatement("DELETE FROM waypoints_members WHERE waypointid = ?;");
- - statement.setInt(1, getId());
- + statement.setInt(1, super.getId());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- - for (String s : getMembers()) {
- - statement = DBManager.prepareStatement("INSERT INTO waypoints_members (waypointid, username, isop) VALUES (?, ?, 0);");
- - statement.setInt(1, getId());
- - statement.setString(2, s);
- + for (PlayerCredentials pc : getMembers()) {
- + statement = DBManager.prepareStatement("INSERT INTO waypoints_members (waypointid, player_id, isop) VALUES (?, ?, 0);");
- + statement.setInt(1, super.getId());
- + statement.setString(2, pc.getUniqueId().toString());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- }
- - for (String s : getOperators()) {
- - statement = DBManager.prepareStatement("INSERT INTO waypoints_members (waypointid, username, isop) VALUES (?, ?, 1);");
- - statement.setInt(1, getId());
- - statement.setString(2, s);
- + for (PlayerCredentials pc : getOperators()) {
- + statement = DBManager.prepareStatement("INSERT INTO waypoints_members (waypointid, player_id, isop) VALUES (?, ?, 1);");
- + statement.setInt(1, super.getId());
- + statement.setString(2, pc.getUniqueId().toString());
- statement.executeUpdate();
- DBManager.closePreparedStatement(statement);
- }
- - setUpdated(false);
- + super.setUpdated(false);
- } catch (SQLException ex) {
- InnPlugin.logError("Unable to save waypoint #" + getId() + "!", ex);
- return false;
- diff --git a/src/net/innectis/innplugin/OwnedObjects/LotFlagType.java b/src/net/innectis/innplugin/OwnedObjects/LotFlagType.java
- index 0723cda17..8569bc065 100644
- --- a/src/net/innectis/innplugin/OwnedObjects/LotFlagType.java
- +++ b/src/net/innectis/innplugin/OwnedObjects/LotFlagType.java
- @@ -46,7 +46,7 @@ public enum LotFlagType implements FlagType {
- CREATIVEWATER (35 , "CreativeWater" , PlayerGroup.ADMIN),
- RESTRICTMINECART (36 , "RestrictMinecart" , PlayerGroup.GUEST),
- LOCKINPUT (37 , "LockInput" , PlayerGroup.GUEST),
- - NOMELT (38 , "NoMelt" , PlayerGroup.GUEST),
- + NOMELT (38 , "NoMelt" , PlayerGroup.GUEST),
- LOCKOUTPUT (39 , "LockOutput" , PlayerGroup.GUEST),
- NOSTRUCTURE (40 , "NoBridge" , PlayerGroup.GUEST),
- INVISIBLE (41 , "Invisible" , PlayerGroup.MODERATOR),
- diff --git a/src/net/innectis/innplugin/OwnedObjects/OwnedEntity.java b/src/net/innectis/innplugin/OwnedObjects/OwnedEntity.java
- index 8f40d129e..3fc2579b6 100644
- --- a/src/net/innectis/innplugin/OwnedObjects/OwnedEntity.java
- +++ b/src/net/innectis/innplugin/OwnedObjects/OwnedEntity.java
- @@ -1,5 +1,6 @@
- package net.innectis.innplugin.OwnedObjects;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- import org.bukkit.entity.EntityType;
- /**
- @@ -8,20 +9,28 @@ import org.bukkit.entity.EntityType;
- * @author AlphaBlend
- */
- public class OwnedEntity {
- - private String owner;
- + private PlayerCredentials ownerCredentials;
- private EntityType type;
- - public OwnedEntity(String owner, EntityType type) {
- - this.owner = owner;
- + public OwnedEntity(PlayerCredentials ownerCredentials, EntityType type) {
- + this.ownerCredentials = ownerCredentials;
- this.type = type;
- }
- + /**
- + * Gets the credentials of the player that owns this entity
- + * @return
- + */
- + public PlayerCredentials getOwnerCredentials() {
- + return ownerCredentials;
- + }
- +
- /**
- * Returns the owner of this entity
- * @return
- */
- public String getOwner() {
- - return owner;
- + return ownerCredentials.getName();
- }
- /**
- diff --git a/src/net/innectis/innplugin/Player/Channel/ChatChannel.java b/src/net/innectis/innplugin/Player/Channel/ChatChannel.java
- index de12d4f6a..b41b614eb 100644
- --- a/src/net/innectis/innplugin/Player/Channel/ChatChannel.java
- +++ b/src/net/innectis/innplugin/Player/Channel/ChatChannel.java
- @@ -5,13 +5,16 @@ import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.HashMap;
- +import java.util.Iterator;
- import java.util.List;
- import java.util.Set;
- +import java.util.UUID;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.Loggers.LogManager;
- import net.innectis.innplugin.Player.Chat.ChatMessage;
- import net.innectis.innplugin.Player.IdpPlayer;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- import net.innectis.innplugin.Player.PlayerSession;
- import org.bukkit.ChatColor;
- @@ -28,9 +31,9 @@ public class ChatChannel {
- private String name;
- private long settings = 0;
- private String password = null;
- - private String owner = null;
- - private HashMap<String, MemberDetails> members = new HashMap<String, MemberDetails>();
- - private List<String> banned = new ArrayList<String>();
- + private PlayerCredentials ownerCredentials = null;
- + private HashMap<PlayerCredentials, MemberDetails> members = new HashMap<PlayerCredentials, MemberDetails>();
- + private List<PlayerCredentials> banned = new ArrayList<PlayerCredentials>();
- public ChatChannel(String name, long settings, String password, long lastActivity) {
- this(0, name, settings, password, lastActivity);
- @@ -100,7 +103,7 @@ public class ChatChannel {
- /**
- * Checks if the channel has the specified setting
- - * @param flagBit
- + * @param settomg
- * @return
- */
- public boolean hasSetting(ChannelSettings setting) {
- @@ -109,7 +112,7 @@ public class ChatChannel {
- /**
- * Clears the channel setting
- - * @param flagBit
- + * @param setting
- */
- public void clearSetting(ChannelSettings setting) {
- settings &= ~setting.getBit();
- @@ -118,7 +121,7 @@ public class ChatChannel {
- /**
- * Sets the channel setting
- - * @param flagBit
- + * @param setting
- */
- public void setSetting(ChannelSettings setting) {
- settings |= setting.getBit();
- @@ -150,30 +153,38 @@ public class ChatChannel {
- return (password != null && !password.isEmpty());
- }
- + /**
- + * Gets the credentials of the owner of this channel
- + * @return
- + */
- + public PlayerCredentials getOwnerCredentials() {
- + return ownerCredentials;
- + }
- +
- /**
- * Gets the owner of this channel
- * @return
- */
- public String getOwner() {
- - return owner;
- + return ownerCredentials.getName();
- }
- /**
- - * Adds the specified member to this channel and returns their member
- + * Adds the credentials of a member to this channel and returns their member
- * details object. If they are the owner then it sets the owner
- * string to them
- - * @param username
- + * @param credentials
- * @param group
- * @param personalnum
- * @param save This will save the member table if true
- * @return
- */
- - public MemberDetails addMember(String username, ChatChannelGroup group, int personalnum, boolean save) {
- + public MemberDetails addMember(PlayerCredentials credentials, ChatChannelGroup group, int personalnum, boolean save) {
- MemberDetails details = new MemberDetails(personalnum, group);
- - members.put(username.toLowerCase(), details);
- + members.put(credentials, details);
- if (group == ChatChannelGroup.OWNER) {
- - owner = username;
- + ownerCredentials = credentials;
- }
- if (save) {
- @@ -187,13 +198,25 @@ public class ChatChannel {
- * Removes the member and returns their member group. This will
- * also promote the next user to owner if the person that left
- * was the current owner
- - * @param username
- + * @param playerName
- * @return
- */
- - public MemberDetails removeMember(String username) {
- - MemberDetails details = members.remove(username.toLowerCase());
- + public MemberDetails removeMember(String playerName) {
- + MemberDetails details = null;
- + UUID playerId = null;
- - PlayerSession session = PlayerSession.getActiveSession(username);
- + for (Iterator<PlayerCredentials> it = members.keySet().iterator(); it.hasNext();) {
- + PlayerCredentials pc = it.next();
- +
- + if (pc.getName().equalsIgnoreCase(playerName)) {
- + details = members.get(pc);
- + playerId = pc.getUniqueId();
- + it.remove();
- + break;
- + }
- + }
- +
- + PlayerSession session = PlayerSession.getActiveSession(playerId);
- // Make sure to remove their personal channel number when they leave
- if (session != null) {
- @@ -203,10 +226,10 @@ public class ChatChannel {
- // If this channel still has members, check if there needs to be a new owner
- if (members.size() > 0) {
- if (details.getGroup() == ChatChannelGroup.OWNER) {
- - String nextOwner = members.keySet().iterator().next();
- + PlayerCredentials nextOwner = members.keySet().iterator().next();
- MemberDetails nextOwnerDetails = members.get(nextOwner);
- nextOwnerDetails.setGroup(ChatChannelGroup.OWNER);
- - owner = nextOwner;
- + ownerCredentials = nextOwner;
- }
- updateMembersTable();
- @@ -216,25 +239,30 @@ public class ChatChannel {
- }
- /**
- - * Modifies the member group of this user
- - * @param username
- + * Modifies the playerName group the member
- + * @param playerName
- * @param group
- */
- - public void modifyMemberGroup(String username, ChatChannelGroup group) {
- - MemberDetails details = members.get(username.toLowerCase());
- - details.setGroup(group);
- - updateMembersTable();
- + public void modifyMemberGroup(String playerName, ChatChannelGroup group) {
- + for (PlayerCredentials pc : members.keySet()) {
- + if (pc.getName().equalsIgnoreCase(playerName)) {
- + MemberDetails details = members.get(pc);
- + details.setGroup(group);
- + updateMembersTable();
- + break;
- + }
- + }
- }
- /**
- * Sets the online/offline status of the member
- - *
- + * @param playerName
- * @param online
- */
- - public void setMemberStatus(String username, boolean online) {
- - for (String member : members.keySet()) {
- - if (member.equalsIgnoreCase(username)) {
- - MemberDetails details = members.get(member);
- + public void setMemberStatus(String playerName, boolean online) {
- + for (PlayerCredentials pc : members.keySet()) {
- + if (pc.getName().equalsIgnoreCase(playerName)) {
- + MemberDetails details = members.get(pc);
- details.setOnline(online);
- break;
- }
- @@ -243,40 +271,52 @@ public class ChatChannel {
- /**
- * Switches the current owner with the specified member
- - * @param username
- + * @param credentials
- */
- - public void switchOwner(String username) {
- - MemberDetails previousOwnerDetails = members.get(owner.toLowerCase());
- - MemberDetails newOwnerDetails = members.get(username.toLowerCase());
- + public void switchOwner(PlayerCredentials credentials) {
- + MemberDetails previousOwnerDetails = members.get(ownerCredentials);
- + MemberDetails newOwnerDetails = members.get(credentials);
- previousOwnerDetails.setGroup(ChatChannelGroup.MEMBER);
- newOwnerDetails.setGroup(ChatChannelGroup.OWNER);
- - owner = username;
- + ownerCredentials = credentials;
- updateMembersTable();
- }
- /**
- * Checks if the specified user is in this channel
- - * @param username
- + * @param playerName
- * @return
- */
- - public boolean containsMember(String username) {
- - return members.containsKey(username.toLowerCase());
- + public boolean containsMember(String playerName) {
- + for (PlayerCredentials pc : members.keySet()) {
- + if (pc.getName().equalsIgnoreCase(playerName)) {
- + return true;
- + }
- + }
- +
- + return false;
- }
- /**
- * Gets the details of the specified member
- - * @param username
- + * @param playerName
- * @return
- */
- - public MemberDetails getMemberDetails(String username) {
- - return members.get(username.toLowerCase());
- + public MemberDetails getMemberDetails(String playerName) {
- + for (PlayerCredentials pc : members.keySet()) {
- + if (pc.getName().equalsIgnoreCase(playerName)) {
- + return members.get(pc);
- + }
- + }
- +
- + return null;
- }
- /**
- * Returns a list of all members with the specified group
- * @return
- */
- - public List<String> getMembers() {
- + public List<PlayerCredentials> getMembers() {
- return getMembers(ChatChannelGroup.MEMBER, true);
- }
- @@ -286,16 +326,16 @@ public class ChatChannel {
- * @param inherited If true, returns if the member inherits the group
- * @return
- */
- - public List<String> getMembers(ChatChannelGroup group, boolean inherited) {
- - List<String> memberList = new ArrayList<String>();
- + public List<PlayerCredentials> getMembers(ChatChannelGroup group, boolean inherited) {
- + List<PlayerCredentials> memberList = new ArrayList<PlayerCredentials>();
- - for (String member : members.keySet()) {
- - MemberDetails details = members.get(member);
- + for (PlayerCredentials pc : members.keySet()) {
- + MemberDetails details = members.get(pc);
- ChatChannelGroup memberGroup = details.getGroup();
- boolean isRequisite = (inherited ? memberGroup.equalsOrInherits(group) : memberGroup.equals(group));
- if (isRequisite) {
- - memberList.add(member);
- + memberList.add(pc);
- }
- }
- @@ -320,29 +360,48 @@ public class ChatChannel {
- /**
- * Adds the user to the banned list
- - * @param username
- + * @param credentials
- */
- - public void addBanned(String username) {
- - banned.add(username.toLowerCase());
- + public void addBanned(PlayerCredentials credentials) {
- + banned.add(credentials);
- updateBannedMembersTable();
- }
- /**
- * Removes the user from the banned list
- - * @param username
- + * @param playerName
- */
- - public void removeBanned(String username) {
- - banned.remove(username.toLowerCase());
- - updateBannedMembersTable();
- + public void removeBanned(String playerName) {
- + boolean removed = false;
- +
- + for (Iterator<PlayerCredentials> it = banned.iterator(); it.hasNext();) {
- + PlayerCredentials pc = it.next();
- +
- + if (pc.getName().equalsIgnoreCase(playerName)) {
- + it.remove();
- + removed = true;
- + break;
- + }
- + }
- +
- + if (removed) {
- + updateBannedMembersTable();
- + }
- }
- /**
- * Checks if the user is banned from this channel
- - * @param username
- + * playerName playerName
- * @return
- */
- - public boolean isBanned(String username) {
- - return banned.contains(username.toLowerCase());
- + public boolean isBanned(String playerName) {
- + for (PlayerCredentials pc : banned) {
- + if (pc.getName().equalsIgnoreCase(playerName)) {
- + return true;
- + }
- + }
- +
- + return false;
- }
- /**
- @@ -350,12 +409,17 @@ public class ChatChannel {
- * @return
- */
- public List<String> getBanned() {
- - return banned;
- + List<String> bannedMembers = new ArrayList<String>();
- +
- + for (PlayerCredentials pc : banned) {
- + bannedMembers.add(pc.getName());
- + }
- +
- + return bannedMembers;
- }
- /**
- * Sends a general channel message to the specified channel
- - * @param channel
- * @param msg
- */
- public void sendGeneralMessage(String msg) {
- @@ -367,8 +431,9 @@ public class ChatChannel {
- /**
- * Sends a chat message to the channel
- + * @param player
- * @param msg
- - * @param additionalRecipients
- + * @param globalListeners
- */
- public void sendChatMessage(IdpPlayer player, String msg, Set<String> globalListeners) {
- msg = player.getColoredName() + ChatColor.AQUA + ": " + msg;
- @@ -423,12 +488,14 @@ public class ChatChannel {
- public List<IdpPlayer> getPlayers() {
- List<IdpPlayer> players = new ArrayList<IdpPlayer>();
- IdpPlayer tmpPlayer;
- - for (String member : members.keySet()) {
- - tmpPlayer = InnPlugin.getPlugin().getPlayer(member, true);
- + for (PlayerCredentials pc : members.keySet()) {
- + tmpPlayer = InnPlugin.getPlugin().getPlayer(pc.getUniqueId());
- +
- if (tmpPlayer != null) {
- players.add(tmpPlayer);
- }
- }
- +
- return players;
- }
- @@ -575,12 +642,12 @@ public class ChatChannel {
- DBManager.closePreparedStatement(statement);
- }
- - statement = DBManager.prepareStatement("INSERT INTO channel_members VALUES (?, ?, ?, ?)");
- + statement = DBManager.prepareStatement("INSERT INTO channel_members (channelid, player_id, personalnum, membergroup) VALUES (?, ?, ?, ?)");
- - for (String member : members.keySet()) {
- - MemberDetails details = members.get(member);
- + for (PlayerCredentials pc : members.keySet()) {
- + MemberDetails details = members.get(pc);
- statement.setInt(1, id);
- - statement.setString(2, member);
- + statement.setString(2, pc.getUniqueId().toString());
- statement.setInt(3, details.getPersonalNumber());
- statement.setInt(4, details.getGroup().getId());
- statement.execute();
- @@ -610,11 +677,11 @@ public class ChatChannel {
- }
- if (banned.size() > 0) {
- - statement = DBManager.prepareStatement("INSERT INTO channel_bans VALUES (?, ?);");
- + statement = DBManager.prepareStatement("INSERT INTO channel_bans (channelid, player_id) VALUES (?, ?);");
- - for (String bannedMember : banned) {
- + for (PlayerCredentials pc : banned) {
- statement.setInt(1, id);
- - statement.setString(2, bannedMember);
- + statement.setString(2, pc.getUniqueId().toString());
- statement.execute();
- }
- }
- diff --git a/src/net/innectis/innplugin/Player/Channel/ChatChannelHandler.java b/src/net/innectis/innplugin/Player/Channel/ChatChannelHandler.java
- index b0c1fae4f..093a1f101 100644
- --- a/src/net/innectis/innplugin/Player/Channel/ChatChannelHandler.java
- +++ b/src/net/innectis/innplugin/Player/Channel/ChatChannelHandler.java
- @@ -9,8 +9,11 @@ import java.util.HashMap;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Set;
- +import java.util.UUID;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Player.PlayerSession;
- /**
- @@ -136,16 +139,16 @@ public class ChatChannelHandler {
- /**
- * Deletes the channel by its channel object
- - * @param channelName
- + * @param channel
- */
- public static void deleteChannel(ChatChannel channel) {
- _channels.remove(channel.getName().toLowerCase());
- idNameMap.remove(channel.getId());
- - for (String member : channel.getMembers()) {
- - MemberDetails details = channel.getMemberDetails(member);
- + for (PlayerCredentials pc : channel.getMembers()) {
- + MemberDetails details = channel.getMemberDetails(pc.getName());
- + PlayerSession session = PlayerSession.getActiveSession(pc.getUniqueId());
- - PlayerSession session = PlayerSession.getActiveSession(member);
- if (session != null) {
- session.removeChannelNumber(details.getPersonalNumber());
- }
- @@ -249,10 +252,13 @@ public class ChatChannelHandler {
- set = statement.executeQuery();
- while (set.next()) {
- - String name = set.getString("username");
- + String playerIdString = set.getString("player_id");
- + UUID playerId = UUID.fromString(playerIdString);
- + PlayerCredentials memberCredentials = PlayerCredentialsManager.getByUniqueId(playerId, true);
- +
- int personalNumber = set.getInt("personalnum");
- ChatChannelGroup group = ChatChannelGroup.fromId(set.getInt("membergroup"));
- - channel.addMember(name, group, personalNumber, false);
- + channel.addMember(memberCredentials, group, personalNumber, false);
- }
- DBManager.closeResultSet(set);
- @@ -263,7 +269,11 @@ public class ChatChannelHandler {
- set = statement.executeQuery();
- while (set.next()) {
- - channel.addBanned(set.getString("username"));
- + String playerIdString = set.getString("player_id");
- + UUID playerId = UUID.fromString(playerIdString);
- + PlayerCredentials playerCredentials = PlayerCredentialsManager.getByUniqueId(playerId, true);
- +
- + channel.addBanned(playerCredentials);
- }
- }
- diff --git a/src/net/innectis/innplugin/Player/IdpPlayer.java b/src/net/innectis/innplugin/Player/IdpPlayer.java
- index 5f6d08783..a1d444f51 100644
- --- a/src/net/innectis/innplugin/Player/IdpPlayer.java
- +++ b/src/net/innectis/innplugin/Player/IdpPlayer.java
- @@ -5,6 +5,7 @@ import java.util.HashSet;
- import java.util.List;
- import java.util.Map;
- import java.util.NoSuchElementException;
- +import java.util.UUID;
- import net.innectis.innplugin.Configuration;
- import net.innectis.innplugin.Economy.ValutaSinkManager;
- import net.innectis.innplugin.External.API.Interfaces.IWorldEditIDP;
- @@ -91,6 +92,14 @@ public class IdpPlayer extends IdpCommandSender<CraftPlayer> {
- return CommandSenderType.PLAYER;
- }
- + /**
- + * Gets the unique ID of this player
- + * @return
- + */
- + public UUID getUniqueId() {
- + return player.getUniqueId();
- + }
- +
- /**
- * Returns the players name
- *
- @@ -160,8 +169,9 @@ public class IdpPlayer extends IdpCommandSender<CraftPlayer> {
- */
- public PlayerSession getSession() {
- if (session == null) {
- - session = PlayerSession.getSession(getName(), plugin);
- + session = PlayerSession.getSession(getUniqueId(), getName(), plugin);
- }
- +
- return session;
- }
- @@ -254,7 +264,6 @@ public class IdpPlayer extends IdpCommandSender<CraftPlayer> {
- public void resetFoodLevel() {
- player.setFoodLevel(20);
- }
- -
- //</editor-fold>
- //
- // <editor-fold defaultstate="collapsed" desc="Location">
- @@ -547,7 +556,7 @@ public class IdpPlayer extends IdpCommandSender<CraftPlayer> {
- if (getWorld().getWorldType() == IdpWorldType.NETHER && restrictIfNether
- && !hasPermission(Permission.special_nether_tp_no_cost)) {
- int requiredCost = Configuration.WARP_OUT_NETHER_COST;
- - TransactionObject transaction = TransactionHandler.getTransactionObject(getName());
- + TransactionObject transaction = TransactionHandler.getTransactionObject(getUniqueId(), getName());
- int valutas = transaction.getValue(TransactionType.VALUTAS);
- if (valutas >= requiredCost) {
- @@ -621,8 +630,8 @@ public class IdpPlayer extends IdpCommandSender<CraftPlayer> {
- // Before the teleport, make sure the player isn't lighting up any blocks.
- // If they are, restore the original block
- - if (LightsourceHandler.isLightingBlock(getName())) {
- - LightsourceHandler.unlightBlock(getName());
- + if (LightsourceHandler.isLightingBlock(getUniqueId())) {
- + LightsourceHandler.unlightBlock(getUniqueId());
- }
- // if (worldFrom != worldTo) //fix tp going to wrong coords
- @@ -931,7 +940,7 @@ public class IdpPlayer extends IdpCommandSender<CraftPlayer> {
- * @return
- */
- public IdpPlayerInventory getInventory() {
- - IdpPlayerInventory inventory = new IdpPlayerInventory(player.getName(), getCurrentInventoryType());
- + IdpPlayerInventory inventory = new IdpPlayerInventory(getUniqueId(), getName(), getCurrentInventoryType());
- inventory.setContents(player.getInventory().getContents(), player.getInventory().getArmorContents());
- inventory.setExperience(player.getExp());
- inventory.setLevel(player.getLevel());
- @@ -976,7 +985,7 @@ public class IdpPlayer extends IdpCommandSender<CraftPlayer> {
- public void setInventory(InventoryType newType) {
- clearInventory();
- clearPotionEffects();
- - IdpPlayerInventory inventory = IdpPlayerInventory.load(player.getName(), newType, plugin);
- + IdpPlayerInventory inventory = IdpPlayerInventory.load(getUniqueId(), getName(), newType, plugin);
- setCurrentInventoryType(inventory.getType());
- player.getInventory().setContents(inventory.getBukkitItems());
- player.getInventory().setArmorContents(inventory.getBukkitArmorItems());
- @@ -1558,7 +1567,7 @@ public class IdpPlayer extends IdpCommandSender<CraftPlayer> {
- }
- InnectisLot lot = LotHandler.getLot(loc);
- - mainConditionMet = ((lot == null || lot.canPlayerAccess(this))
- + mainConditionMet = ((lot == null || lot.canPlayerAccess(getName()))
- && hasPermission(Permission.special_lightsource_torch));
- }
- diff --git a/src/net/innectis/innplugin/Player/IdpPlayerInventory.java b/src/net/innectis/innplugin/Player/IdpPlayerInventory.java
- index 9a205676c..edd06510c 100644
- --- a/src/net/innectis/innplugin/Player/IdpPlayerInventory.java
- +++ b/src/net/innectis/innplugin/Player/IdpPlayerInventory.java
- @@ -5,6 +5,7 @@ import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.List;
- +import java.util.UUID;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.IdpRuntimeException;
- import net.innectis.innplugin.InnPlugin;
- @@ -25,9 +26,13 @@ public class IdpPlayerInventory {
- private static final int DEFAULT_ITEM_SIZE = 36;
- private static final int DEFAULT_ARMOR_SIZE = 4;
- /**
- - * Owner of the inventory
- + * ID of the owner of this inventory
- */
- - private String username;
- + private UUID playerId;
- + /**
- + * Owner of this inventory
- + */
- + private String playerName;
- /**
- * The type of the inventory
- */
- @@ -64,12 +69,13 @@ public class IdpPlayerInventory {
- /**
- * Creates a new empty inventory
- *
- - * @param username
- + * @param playerId
- + * @param playerName
- * @param type
- - * @param plugin
- */
- - public IdpPlayerInventory(String username, InventoryType type) {
- - this.username = username;
- + public IdpPlayerInventory(UUID playerId, String playerName, InventoryType type) {
- + this.playerId = playerId;
- + this.playerName = playerName;
- this.type = type;
- items = new IdpItemStack[DEFAULT_ITEM_SIZE];
- armor = new IdpItemStack[DEFAULT_ARMOR_SIZE];
- @@ -83,14 +89,19 @@ public class IdpPlayerInventory {
- /**
- * Creates a new empty inventory
- *
- - * @param username
- + * @param playerId
- + * @param playerName
- * @param type
- - * @param plugin
- * @param items
- * @param armor
- - */
- - public IdpPlayerInventory(String username, InventoryType type, IdpItemStack[] items, IdpItemStack[] armor, float experience, int level, double health, int hunger) {
- - this.username = username;
- + * @param experience
- + * @param level
- + * @param health
- + * @param hunger
- + */
- + public IdpPlayerInventory(UUID playerId, String playerName, InventoryType type, IdpItemStack[] items, IdpItemStack[] armor, float experience, int level, double health, int hunger) {
- + this.playerId = playerId;
- + this.playerName = playerName;
- this.type = type;
- this.items = new IdpItemStack[DEFAULT_ITEM_SIZE];
- for (int i = 0; i < this.items.length && i < items.length; i++) {
- @@ -238,7 +249,7 @@ public class IdpPlayerInventory {
- public boolean store() {
- // Dont save the none type inventory
- if (type == InventoryType.NONE) {
- - InnPlugin.logError("Trying to store a 'none' inventory for player " + username + " - is player new?");
- + InnPlugin.logError("Trying to store a 'none' inventory for player " + playerName + " - is player new?");
- return true;
- }
- @@ -251,8 +262,8 @@ public class IdpPlayerInventory {
- ResultSet resultset = null;
- try {
- - statement = DBManager.prepareStatement(" SELECT bagid FROM player_inventory where name = ? and inventorytype = ? ");
- - statement.setString(1, username);
- + statement = DBManager.prepareStatement(" SELECT bagid FROM player_inventory where player_id = ? and inventorytype = ? ");
- + statement.setString(1, playerId.toString());
- statement.setInt(2, type.getId());
- long bagid = 0;
- @@ -282,9 +293,9 @@ public class IdpPlayerInventory {
- DBManager.closeResultSet(resultset);
- DBManager.closePreparedStatement(statement);
- - statement = DBManager.prepareStatement(" insert into player_inventory (name, inventorytype, level, experience, bagid, health, hunger, potioneffects) values "
- - + "(?,?,?,?,?,?,?, ?) on duplicate key update level = ?, experience = ?, bagid = ?, health = ?, hunger = ?, potioneffects = ?;");
- - statement.setString(1, username);
- + statement = DBManager.prepareStatement("INSERT INTO player_inventory (player_id, inventorytype, level, experience, bagid, health, hunger, potioneffects) VALUES "
- + + "(?,?,?,?,?,?,?, ?) ON DUPLICATE KEY UPDATE level = ?, experience = ?, bagid = ?, health = ?, hunger = ?, potioneffects = ?;");
- + statement.setString(1, playerId.toString());
- statement.setInt(2, type.getId());
- statement.setInt(3, level);
- statement.setFloat(DEFAULT_ARMOR_SIZE, experience);
- @@ -301,7 +312,7 @@ public class IdpPlayerInventory {
- statement.executeUpdate();
- return true;
- } catch (SQLException ex) {
- - InnPlugin.logError("Failed to store inventory for player " + username, ex);
- + InnPlugin.logError("Failed to store inventory for player " + playerName + "!", ex);
- } finally {
- DBManager.closeResultSet(resultset);
- DBManager.closePreparedStatement(statement);
- @@ -313,9 +324,12 @@ public class IdpPlayerInventory {
- /**
- * Loads the inventory from the database
- *
- + * @param playerCredentials
- * @param type
- + * @param plugin
- + * @return
- */
- - public static IdpPlayerInventory load(String username, InventoryType type, InnPlugin plugin) {
- + public static IdpPlayerInventory load(UUID playerId, String playerName, InventoryType type, InnPlugin plugin) {
- PreparedStatement statement = null;
- ResultSet resultset = null;
- @@ -327,8 +341,8 @@ public class IdpPlayerInventory {
- long bagid = 0;
- String potionEffects = "";
- - statement = DBManager.prepareStatement(" SELECT level, experience, bagid, health, hunger, potioneffects FROM player_inventory WHERE name = ? and inventorytype = ? LIMIT 1 ");
- - statement.setString(1, username);
- + statement = DBManager.prepareStatement("SELECT level, experience, bagid, health, hunger, potioneffects FROM player_inventory WHERE player_id = ? and inventorytype = ? LIMIT 1;");
- + statement.setString(1, playerId.toString());
- statement.setInt(2, type.getId());
- resultset = statement.executeQuery();
- @@ -344,7 +358,7 @@ public class IdpPlayerInventory {
- if (bagid > 0) {
- StackBag bag = StackBag.getContentbag(bagid);
- - IdpPlayerInventory inv = new IdpPlayerInventory(username, type);
- + IdpPlayerInventory inv = new IdpPlayerInventory(playerId, playerName, type);
- inv.experience = exp;
- inv.level = level;
- inv.health = health;
- @@ -359,7 +373,7 @@ public class IdpPlayerInventory {
- }
- }
- } catch (NumberFormatException ex) {
- - InnPlugin.logError("Error loading inventory potion effects of player " + username, ex);
- + InnPlugin.logError("Error loading inventory potion effects of player " + playerName + "!", ex);
- }
- System.arraycopy(itemarr, 0, inv.items, 0, DEFAULT_ITEM_SIZE);
- @@ -368,13 +382,13 @@ public class IdpPlayerInventory {
- return inv;
- }
- } catch (SQLException ex) {
- - InnPlugin.logError("Error getting group of player " + username, ex);
- + InnPlugin.logError("Error getting group of player " + playerName + "!", ex);
- } finally {
- DBManager.closeResultSet(resultset);
- DBManager.closePreparedStatement(statement);
- }
- - return new IdpPlayerInventory(username, type);
- + return new IdpPlayerInventory(playerId, playerName, type);
- }
- /**
- @@ -443,7 +457,7 @@ public class IdpPlayerInventory {
- * Updates bukkit's inventory with this one
- */
- public void updateBukkitInventory() {
- - IdpPlayer idpplayer = InnPlugin.getPlugin().getPlayer(username, false);
- + IdpPlayer idpplayer = InnPlugin.getPlugin().getPlayer(playerId);
- if (idpplayer == null) {
- InnPlugin.logError("Trying to update inventory of offline player.");
- diff --git a/src/net/innectis/innplugin/Player/Infractions/InfractInjector.java b/src/net/innectis/innplugin/Player/Infractions/InfractInjector.java
- index 103d2dad2..a020dbe99 100644
- --- a/src/net/innectis/innplugin/Player/Infractions/InfractInjector.java
- +++ b/src/net/innectis/innplugin/Player/Infractions/InfractInjector.java
- @@ -3,10 +3,14 @@ package net.innectis.innplugin.Player.Infractions;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.TimeZone;
- +import net.innectis.innplugin.Configuration;
- import net.innectis.innplugin.IdpCommandSender;
- +import net.innectis.innplugin.IdpConsole;
- import net.innectis.innplugin.Player.Chat.ChatColor;
- import net.innectis.innplugin.Player.Chat.ChatInjector;
- import net.innectis.innplugin.Player.IdpPlayer;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Utility.StringUtil;
- /**
- @@ -18,37 +22,45 @@ import net.innectis.innplugin.Utility.StringUtil;
- public final class InfractInjector extends ChatInjector {
- public static final String ENTER_CHAR = "\n";
- - private final String player;
- + private final PlayerCredentials playerCredentials;
- private final InfractionIntensity intensity;
- private final String summary;
- private StringBuilder details;
- /**
- * Creates a new infractioninjector with the given details
- - * @param player
- + * @param playerCredentials
- * @param intensity
- * @param summary
- */
- - public InfractInjector(String player, InfractionIntensity intensity, String summary) {
- - this.player = player;
- + public InfractInjector(PlayerCredentials playerCredentials, InfractionIntensity intensity, String summary) {
- + this.playerCredentials = playerCredentials;
- this.intensity = intensity;
- this.summary = summary;
- }
- @Override
- public void onChat(IdpCommandSender sender, String message) {
- -
- // Close the injector and save the infraction
- if (StringUtil.matches(message, "q", "quit", "exit", "save")) {
- Date date = Calendar.getInstance(TimeZone.getTimeZone("GMT")).getTime();
- - Infraction inf = new Infraction(player, intensity, summary, details == null ? null : details.toString(), date, sender.getName());
- + PlayerCredentials credentials = null;
- +
- + // Determine if we should use server generated credentials or player's
- + if (sender instanceof IdpConsole) {
- + credentials = Configuration.SERVER_GENERATED_CREDENTIALS;
- + } else {
- + credentials = PlayerCredentialsManager.getByName(sender.getName());
- + }
- +
- + Infraction inf = new Infraction(playerCredentials, intensity, summary, details == null ? null : details.toString(), date, credentials);
- // Save the infraction and report
- int level = InfractionManager.getManager().saveInfraction(inf);
- if (inf.getId() != Infraction.DEFAULT_ID) {
- sender.printInfo("Infraction #" + inf.getId() + " saved!");
- - sender.printInfo("Player '" + player + "' infraction level: " + level);
- + sender.printInfo("Player '" + playerCredentials.getName() + "' infraction level: " + level);
- } else {
- sender.printError("Could not save infraction!");
- }
- diff --git a/src/net/innectis/innplugin/Player/Infractions/Infraction.java b/src/net/innectis/innplugin/Player/Infractions/Infraction.java
- index 355f30195..c93fe74ee 100644
- --- a/src/net/innectis/innplugin/Player/Infractions/Infraction.java
- +++ b/src/net/innectis/innplugin/Player/Infractions/Infraction.java
- @@ -1,6 +1,8 @@
- package net.innectis.innplugin.Player.Infractions;
- import java.util.Date;
- +import java.util.UUID;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- /**
- *
- @@ -12,20 +14,20 @@ public final class Infraction {
- protected static final int DEFAULT_ID = -1;
- private int id;
- - private final String player;
- + private final PlayerCredentials playerCredentials;
- private final InfractionIntensity intensity;
- private final String summary;
- private final String details;
- private final Date dateGMT;
- - private final String staffmember;
- + private final PlayerCredentials creatorCredentials;
- private final boolean revoked;
- - private final String revoker;
- + private final PlayerCredentials revokerCredentials;
- private final Date revokeDate;
- /**
- * Creates a new infraction with the given details.
- - * @param player
- - * The player this infraction is given to
- + * @param credentials
- + * The credentials of the player this infraction is given to
- * @param intensity
- * The intensity of the infraction
- * @param summary
- @@ -34,45 +36,45 @@ public final class Infraction {
- * Optional list of details about the infraction and further information about the context.
- * @param dateGMT
- * The date in GMT when the infraction was created
- - * @param staffmember
- - * The staffmember that created the infraction or <b>[SERVER]</b> for server generated infractions.
- + * @param creatorCredentials
- + * The creatpr of the infraction or <b>[SERVER]</b> for server generated infractions.
- */
- - public Infraction(String player, InfractionIntensity intensity, String summary, String details, Date dateGMT, String staffmember) {
- + public Infraction(PlayerCredentials credentials, InfractionIntensity intensity, String summary, String details, Date dateGMT, PlayerCredentials creatorCredentials) {
- this.id = DEFAULT_ID;
- - this.player = player;
- + this.playerCredentials = credentials;
- this.intensity = intensity;
- this.summary = summary;
- this.details = details;
- this.dateGMT = dateGMT;
- - this.staffmember = staffmember;
- + this.creatorCredentials = creatorCredentials;
- this.revoked = false;
- - this.revoker = null;
- + this.revokerCredentials = null;
- this.revokeDate = null;
- }
- /**
- * Created a new infraction with all details possible to be given.
- * @param id
- - * @param player
- + * @param credentials
- * @param intensity
- * @param summary
- * @param details
- * @param dateGMT
- - * @param staffmember
- + * @param creatorCredentials
- * @param revoked
- - * @param revoker
- + * @param revokerCredentials
- * @param revokeDate
- */
- - protected Infraction(int id, String player, InfractionIntensity intensity, String summary, String details, Date dateGMT, String staffmember, boolean revoked, String revoker, Date revokeDate) {
- + protected Infraction(int id, PlayerCredentials credentials, InfractionIntensity intensity, String summary, String details, Date dateGMT, PlayerCredentials creatorCredentials, boolean revoked, PlayerCredentials revokerCredentials, Date revokeDate) {
- this.id = id;
- - this.player = player;
- + this.playerCredentials = credentials;
- this.intensity = intensity;
- this.summary = summary;
- this.details = details;
- this.dateGMT = dateGMT;
- - this.staffmember = staffmember;
- + this.creatorCredentials = creatorCredentials;
- this.revoked = revoked;
- - this.revoker = revoker;
- + this.revokerCredentials = revokerCredentials;
- this.revokeDate = revokeDate;
- }
- @@ -94,11 +96,11 @@ public final class Infraction {
- }
- /**
- - * The player to whom the infraction is listed to.
- + * The credentials of the player to whom the infraction is listed to.
- * @return
- */
- - public String getPlayer() {
- - return player;
- + public PlayerCredentials getPlayerCredentials() {
- + return playerCredentials;
- }
- /**
- @@ -118,11 +120,11 @@ public final class Infraction {
- }
- /**
- - * The staffmember that did the infraction.
- + * The credentials of the creator that did the infraction.
- * @return
- */
- - public String getStaffmember() {
- - return staffmember;
- + public PlayerCredentials getCreatorCredentials() {
- + return creatorCredentials;
- }
- /**
- @@ -150,11 +152,11 @@ public final class Infraction {
- }
- /**
- - * The name of the player that has revoked the infraction
- + * The credentials of the player that has revoked the infraction
- * @return
- */
- - public String getRevoker() {
- - return revoker;
- + public PlayerCredentials getRevokerCredentials() {
- + return revokerCredentials;
- }
- /**
- diff --git a/src/net/innectis/innplugin/Player/Infractions/InfractionBan.java b/src/net/innectis/innplugin/Player/Infractions/InfractionBan.java
- index 19c79c111..02b586e70 100644
- --- a/src/net/innectis/innplugin/Player/Infractions/InfractionBan.java
- +++ b/src/net/innectis/innplugin/Player/Infractions/InfractionBan.java
- @@ -4,6 +4,7 @@ import java.util.Date;
- import net.innectis.innplugin.BanSystem.BanHandler;
- import net.innectis.innplugin.BanSystem.BanObject;
- import net.innectis.innplugin.BanSystem.UserBanObject;
- +import net.innectis.innplugin.Configuration;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.Player.Chat.ChatColor;
- import net.innectis.innplugin.Player.IdpPlayer;
- @@ -50,20 +51,20 @@ class InfractionBan {
- * @param infraction the infraction that caused the ban
- */
- public void banPlayer(Infraction infraction) {
- - BanObject obj = BanHandler.getBan(infraction.getPlayer());
- + BanObject obj = BanHandler.getBan(infraction.getPlayerCredentials().getUniqueId());
- // Only ban if not already banned!
- if (obj == null) {
- InnPlugin plugin = InnPlugin.getPlugin();
- // Create the ban
- - obj = new UserBanObject(infraction.getPlayer(), "[SERVER]", DatabaseTools.dateToTimeStamp(new Date()), bantimeSec * 1000, true);
- + obj = new UserBanObject(infraction.getPlayerCredentials(), Configuration.SERVER_GENERATED_CREDENTIALS, DatabaseTools.dateToTimeStamp(new Date()), bantimeSec * 1000, true);
- BanHandler.addBan(obj);
- // Broadcast the ban
- - plugin.broadCastMessage(ChatColor.RED, StringUtil.format(BAN_BROAD_MESSAGE, infraction.getPlayer(), DateUtil.getTimeDifferenceString(bantimeSec)));
- + plugin.broadCastMessage(ChatColor.RED, StringUtil.format(BAN_BROAD_MESSAGE, infraction.getPlayerCredentials().getName(), DateUtil.getTimeDifferenceString(bantimeSec)));
- // Find the player and kick if online
- - IdpPlayer player = plugin.getPlayer(infraction.getPlayer());
- + IdpPlayer player = plugin.getPlayer(infraction.getPlayerCredentials().getUniqueId());
- if (player != null && player.isOnline()) {
- player.getHandle().kickPlayer(StringUtil.format(BAN_KICK_MESSAGE, DateUtil.getTimeDifferenceString(bantimeSec)));
- }
- diff --git a/src/net/innectis/innplugin/Player/Infractions/InfractionManager.java b/src/net/innectis/innplugin/Player/Infractions/InfractionManager.java
- index 2b6d61bc2..54984e949 100644
- --- a/src/net/innectis/innplugin/Player/Infractions/InfractionManager.java
- +++ b/src/net/innectis/innplugin/Player/Infractions/InfractionManager.java
- @@ -8,8 +8,12 @@ import java.util.Calendar;
- import java.util.Collections;
- import java.util.Date;
- import java.util.List;
- +import java.util.UUID;
- +import net.innectis.innplugin.Configuration;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Utility.DateUtil;
- /**
- @@ -68,14 +72,14 @@ public class InfractionManager {
- // Save the infraction
- try {
- statement = DBManager.prepareStatementWithAutoGeneratedKeys(
- - "INSERT INTO player_infracts (name, intensity, dateGMT, summary, details, staff)"
- + "INSERT INTO player_infracts (player_id, intensity, dateGMT, summary, details, staff_id)"
- + " VALUES (?,?,?,?,?,?); ");
- - statement.setString(1, infraction.getPlayer());
- + statement.setString(1, infraction.getPlayerCredentials().getUniqueId().toString());
- statement.setInt(2, infraction.getIntensity().getIntensityLevel());
- statement.setLong(3, infraction.getDateGMT().getTime());
- statement.setString(4, infraction.getSummary());
- statement.setString(5, infraction.getDetails());
- - statement.setString(6, infraction.getStaffmember());
- + statement.setString(6, infraction.getCreatorCredentials().getUniqueId().toString());
- statement.execute();
- set = statement.getGeneratedKeys();
- @@ -84,14 +88,15 @@ public class InfractionManager {
- }
- } catch (SQLException ex) {
- - InnPlugin.logError("Could not save infraction for '" + infraction.getPlayer() + "'", ex);
- + InnPlugin.logError("Could not save infraction for '" + infraction.getPlayerCredentials().getName() + "'", ex);
- } finally {
- DBManager.closeResultSet(set);
- DBManager.closePreparedStatement(statement);
- }
- + PlayerCredentials credentials = infraction.getPlayerCredentials();
- // Check if the player needs to be banned
- - int infractionLevel = getInfractionLevel(infraction.getPlayer());
- + int infractionLevel = getInfractionLevel(credentials.getUniqueId(), credentials.getName());
- checkBans(infraction, infractionLevel);
- return infractionLevel;
- @@ -100,11 +105,12 @@ public class InfractionManager {
- /**
- * This will get the infraction level of the player.
- * The level is the sum of the intesity of all recent infractions.
- - * @param player - The name of the player to lookup.
- + * @param playerId - The ID of the player to lookup.
- + * @param playerName - The name of the player to lookup.
- * @return 0 or higher according to the infraction levle of the player. If an error occured -1
- * will be returend instead.
- */
- - public int getInfractionLevel(String player) {
- + public int getInfractionLevel(UUID playerId, String playerName) {
- PreparedStatement statement = null;
- ResultSet set = null;
- @@ -112,8 +118,8 @@ public class InfractionManager {
- Calendar cal = Calendar.getInstance(DateUtil.TIMEZONE_GMT);
- cal.add(Calendar.DAY_OF_WEEK, -INFRACTION_GRACE_DAYS);
- - statement = DBManager.prepareStatement("SELECT sum(intensity) FROM player_infracts WHERE name = ? and dateGMT > ? AND revoker IS NULL");
- - statement.setString(1, player);
- + statement = DBManager.prepareStatement("SELECT sum(intensity) FROM player_infracts WHERE player_id = ? and dateGMT > ? AND revoker_id IS NULL");
- + statement.setString(1, playerId.toString());
- statement.setLong(2, cal.getTimeInMillis());
- set = statement.executeQuery();
- @@ -123,7 +129,7 @@ public class InfractionManager {
- return 0;
- }
- } catch (SQLException ex) {
- - InnPlugin.logError("Could not get infractionlevel for '" + player + "'", ex);
- + InnPlugin.logError("Could not get infractionlevel for '" + playerName + "'", ex);
- } finally {
- DBManager.closeResultSet(set);
- DBManager.closePreparedStatement(statement);
- @@ -164,7 +170,7 @@ public class InfractionManager {
- // Return the updated infraction
- return getInfraction(infraction.getId());
- } catch (SQLException ex) {
- - InnPlugin.logError("Could not save infraction for '" + infraction.getPlayer() + "'", ex);
- + InnPlugin.logError("Could not save infraction for '" + infraction.getPlayerCredentials().getName() + "'", ex);
- } finally {
- DBManager.closePreparedStatement(statement);
- }
- @@ -174,14 +180,14 @@ public class InfractionManager {
- /**
- * This will get a list with the infractions on the given player.
- - * @param player - The player to lookup.
- + * @param credentials - The credentials of the player to lookup.
- * @param all - When true all infractions will be returned instead of the infractions that comply
- * with the INFRACTION_GRACE_DAYS time setting.
- * @return A new list with the infracitons for the given player.
- * If an error occured Collections.EMPTY_LIST will be returned instead. The error itself will be
- * reported to the error logger.
- */
- - public List<Infraction> getInfractions(String player, boolean all) {
- + public List<Infraction> getInfractions(PlayerCredentials credentials, boolean all) {
- PreparedStatement statement = null;
- ResultSet set = null;
- @@ -190,15 +196,15 @@ public class InfractionManager {
- cal.add(Calendar.DAY_OF_WEEK, -INFRACTION_GRACE_DAYS);
- // Construct the SQL
- - String sql = "SELECT id, name, intensity, dateGMT, summary, details, staff, revoker, revokeDateGMT FROM player_infracts ";
- + String sql = "SELECT id, player_id, intensity, dateGMT, summary, details, staff_id, revoker_id, revokeDateGMT FROM player_infracts ";
- if (all) {
- - sql += " WHERE name = ? ";
- + sql += " WHERE player_id = ? ";
- } else {
- - sql += " WHERE name = ? and dateGMT > ? AND revoker IS NULL ";
- + sql += " WHERE player_id = ? and dateGMT > ? AND revoker_id IS NULL ";
- }
- statement = DBManager.prepareStatement(sql);
- - statement.setString(1, player);
- + statement.setString(1, credentials.getUniqueId().toString());
- if (!all) {
- statement.setLong(2, cal.getTimeInMillis());
- @@ -215,7 +221,7 @@ public class InfractionManager {
- return infractions;
- } catch (SQLException ex) {
- - InnPlugin.logError("Could not get infractions for '" + player + "'", ex);
- + InnPlugin.logError("Could not get infractions for '" + credentials.getName() + "'", ex);
- } finally {
- DBManager.closeResultSet(set);
- DBManager.closePreparedStatement(statement);
- @@ -235,8 +241,8 @@ public class InfractionManager {
- ResultSet set = null;
- try {
- - statement = DBManager.prepareStatement("SELECT id, name, intensity, dateGMT, "
- - + " summary, details, staff, revoker, revokeDateGMT FROM player_infracts WHERE id = ? ");
- + statement = DBManager.prepareStatement("SELECT id, player_id, intensity, dateGMT, "
- + + " summary, details, staff_id, revoker_id, revokeDateGMT FROM player_infracts WHERE id = ?;");
- statement.setInt(1, id);
- set = statement.executeQuery();
- @@ -265,17 +271,35 @@ public class InfractionManager {
- private static Infraction infFromCurrentRow(ResultSet set) throws SQLException {
- // Get normal information
- int id = set.getInt("id");
- - String name = set.getString("name");
- +
- + String playerIdString = set.getString("player_id");
- + UUID playerId = UUID.fromString(playerIdString);
- + PlayerCredentials playerCredentials = PlayerCredentialsManager.getByUniqueId(playerId);
- +
- int intensity = set.getInt("intensity");
- String summary = set.getString("summary");
- String details = set.getString("details");
- Date dateGMT = new Date(set.getLong("dateGMT"));
- - String staffmember = set.getString("staff");
- +
- + String staffIdString = set.getString("staff_id");
- + UUID staffId = UUID.fromString(staffIdString);
- + PlayerCredentials staffCredentials = null;
- +
- + if (staffId.equals(Configuration.SERVER_GENERATED_IDENTIFIER)) {
- + staffCredentials = Configuration.SERVER_GENERATED_CREDENTIALS;
- + } else {
- + staffCredentials = PlayerCredentialsManager.getByUniqueId(staffId);
- + }
- // Get revoking details;
- - String revoker = set.getString("revoker");
- + String revokerIdString = set.getString("revoker_id");
- + PlayerCredentials revokerCredentials = null;
- Date revokeDate = null;
- - if (revoker != null) {
- +
- + if (revokerIdString != null) {
- + UUID revokerId = UUID.fromString(revokerIdString);
- + revokerCredentials = PlayerCredentialsManager.getByUniqueId(revokerId);
- +
- revokeDate = new Date(set.getLong("revokeDateGMT"));
- }
- @@ -287,7 +311,7 @@ public class InfractionManager {
- }
- }
- - return new Infraction(id, name, infInt, summary, details, dateGMT, staffmember, revoker != null, revoker, revokeDate);
- + return new Infraction(id, playerCredentials, infInt, summary, details, dateGMT, staffCredentials, revokerCredentials != null, revokerCredentials, revokeDate);
- }
- /**
- diff --git a/src/net/innectis/innplugin/Player/PlayerBackpack.java b/src/net/innectis/innplugin/Player/PlayerBackpack.java
- index faf0112af..4a8436093 100644
- --- a/src/net/innectis/innplugin/Player/PlayerBackpack.java
- +++ b/src/net/innectis/innplugin/Player/PlayerBackpack.java
- @@ -3,6 +3,7 @@ package net.innectis.innplugin.Player;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- +import java.util.UUID;
- import net.innectis.innplugin.Configuration;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- @@ -24,27 +25,35 @@ import net.innectis.innplugin.Items.StackBag;
- public class PlayerBackpack extends IdpContainer {
- private static final int BACKPACK_SIZE = Configuration.BACKPACK_SIZE;
- - private final String owner;
- + private final PlayerCredentials ownerCredentials;
- private long bagid;
- /** Makes an empty backpack */
- - private PlayerBackpack(String owner) {
- + private PlayerBackpack(PlayerCredentials ownerCredentials) {
- super(new IdpItemStack[BACKPACK_SIZE], BACKPACK_SIZE);
- - this.owner = owner;
- + this.ownerCredentials = ownerCredentials;
- }
- - private PlayerBackpack(String owner, long bagid, IdpItemStack[] contents) {
- + private PlayerBackpack(PlayerCredentials ownerCredentials, long bagid, IdpItemStack[] contents) {
- super(contents, BACKPACK_SIZE);
- - this.owner = owner;
- + this.ownerCredentials = ownerCredentials;
- this.bagid = bagid;
- }
- + /**
- + * Gets the credentials of the owner of this backpack
- + * @return
- + */
- + public PlayerCredentials getOwnerCredentials() {
- + return ownerCredentials;
- + }
- +
- /**
- * The name of the player that owns this backpack.
- * @return
- */
- public String getOwner() {
- - return owner;
- + return ownerCredentials.getName();
- }
- /**
- @@ -53,8 +62,9 @@ public class PlayerBackpack extends IdpContainer {
- */
- public void setItems(IdpItemStack[] items) {
- if (items.length > BACKPACK_SIZE) {
- - throw new RuntimeException("Backpack to large!");
- + throw new RuntimeException("Backpack too large!");
- }
- +
- this.items = items;
- }
- @@ -69,13 +79,13 @@ public class PlayerBackpack extends IdpContainer {
- StackBag bag = new StackBag(bagid, getItems());
- bag.save();
- - statement = DBManager.prepareStatement("UPDATE players SET backpack = ? WHERE name = ?");
- + statement = DBManager.prepareStatement("UPDATE players SET backpack = ? WHERE player_id = ?");
- statement.setLong(1, bag.getBagid());
- - statement.setString(2, owner);
- + statement.setString(2, ownerCredentials.getUniqueId().toString());
- statement.execute();
- return true;
- } catch (SQLException ex) {
- - InnPlugin.logError("Unable to save " + owner + "'s backpack!", ex);
- + InnPlugin.logError("Unable to save " + getOwner() + "'s backpack!", ex);
- } finally {
- DBManager.closePreparedStatement(statement);
- }
- @@ -84,36 +94,37 @@ public class PlayerBackpack extends IdpContainer {
- }
- /**
- - * Loads the player's backpack from the database
- - * @param username
- - * The name of the user it should look up
- + * Loads a backpack from the database by the specified player ID
- + * @param playerId
- + * The ID of the player's backpack to load
- * @return The backpack of the player or a new one.
- * If it returns null something went wrong.
- */
- - public static PlayerBackpack loadBackpackFromDB(String username) {
- + public static PlayerBackpack loadBackpackFromDB(UUID playerId, String playerName) {
- PreparedStatement statement = null;
- ResultSet set = null;
- try {
- - statement = DBManager.prepareStatement(" SELECT backpack FROM players WHERE name = ? AND backpack IS NOT NULL ");
- - statement.setString(1, username);
- + statement = DBManager.prepareStatement("SELECT backpack FROM players WHERE player_id = ? AND backpack IS NOT NULL;");
- + statement.setString(1, playerId.toString());
- set = statement.executeQuery();
- + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(playerId, true);
- PlayerBackpack pack = null;
- if (set.next()) {
- long bagid = set.getLong("backpack");
- if (bagid > 0) {
- - pack = new PlayerBackpack(username, bagid, StackBag.getContentbag(bagid).getContents());
- + pack = new PlayerBackpack(credentials, bagid, StackBag.getContentbag(bagid).getContents());
- }
- }
- if (pack == null) {
- - pack = new PlayerBackpack(username);
- + pack = new PlayerBackpack(credentials);
- }
- return pack;
- } catch (SQLException ex) {
- - InnPlugin.logError("Unable to load " + username + "'s backpack!", ex);
- + InnPlugin.logError("Unable to load backpack for player " + playerName + "!", ex);
- } finally {
- DBManager.closeResultSet(set);
- DBManager.closePreparedStatement(statement);
- diff --git a/src/net/innectis/innplugin/Player/PlayerCredentials.java b/src/net/innectis/innplugin/Player/PlayerCredentials.java
- new file mode 100644
- index 000000000..baca3f284
- --- /dev/null
- +++ b/src/net/innectis/innplugin/Player/PlayerCredentials.java
- @@ -0,0 +1,89 @@
- +package net.innectis.innplugin.Player;
- +
- +import java.sql.PreparedStatement;
- +import java.sql.SQLException;
- +import java.util.UUID;
- +import net.innectis.innplugin.Handlers.Datasource.DBManager;
- +import net.innectis.innplugin.InnPlugin;
- +
- +/**
- + * Describes a player, both by name, and by unique ID
- + *
- + * @author AlphaBlend
- + */
- +public class PlayerCredentials {
- + private UUID uniqueId;
- + private String name;
- + private boolean isValidPlayer = false;
- +
- + public PlayerCredentials(UUID uniqueId, String name) {
- + this(uniqueId, name, true);
- + }
- +
- + public PlayerCredentials(UUID uniqueId, String name, boolean isValidPlayer) {
- + this.uniqueId = uniqueId;
- + this.name = name;
- + this.isValidPlayer = isValidPlayer;
- + }
- +
- + /**
- + * Gets the unique ID of this player
- + * @return
- + */
- + public UUID getUniqueId() {
- + return uniqueId;
- + }
- +
- + /**
- + * Gets the name of this player
- + * @return
- + */
- + public String getName() {
- + return name;
- + }
- +
- + /**
- + * Sets the name of this player
- + * @param name
- + */
- + public void setName(String name) {
- + this.name = name;
- + }
- +
- + /**
- + * Gets if these credentials belong to a valid player
- + * @return
- + */
- + public boolean isValidPlayer() {
- + return isValidPlayer;
- + }
- +
- + /**
- + * Updates the player's name in database according to their unique ID
- + */
- + public void update() {
- + PreparedStatement statement = null;
- +
- + try {
- + statement = DBManager.prepareStatement("UPDATE players SET name = ? WHERE player_id = ?;");
- + statement.setString(1, name);
- + statement.setString(2, uniqueId.toString());
- + statement.executeUpdate();
- + } catch (SQLException ex) {
- + InnPlugin.logError("Unable to update player with UUID " + uniqueId + "!", ex);
- + } finally {
- + DBManager.closePreparedStatement(statement);
- + }
- + }
- +
- + @Override
- + public boolean equals(Object obj) {
- + if (!(obj instanceof PlayerCredentials)) {
- + return false;
- + }
- +
- + PlayerCredentials credentials = (PlayerCredentials) obj;
- +
- + return credentials.getUniqueId().equals(uniqueId);
- + }
- +}
- diff --git a/src/net/innectis/innplugin/Player/PlayerCredentialsManager.java b/src/net/innectis/innplugin/Player/PlayerCredentialsManager.java
- new file mode 100644
- index 000000000..0a9b4113e
- --- /dev/null
- +++ b/src/net/innectis/innplugin/Player/PlayerCredentialsManager.java
- @@ -0,0 +1,155 @@
- +package net.innectis.innplugin.Player;
- +
- +import java.sql.PreparedStatement;
- +import java.sql.ResultSet;
- +import java.sql.SQLException;
- +import java.util.ArrayList;
- +import java.util.List;
- +import java.util.UUID;
- +import net.innectis.innplugin.Handlers.Datasource.DBManager;
- +import net.innectis.innplugin.InnPlugin;
- +
- +/**
- + * A manager that keeps track of all the player credentials
- + *
- + * @author AlphaBlend
- + */
- +public class PlayerCredentialsManager {
- + private static List<PlayerCredentials> playerCredentialsList = new ArrayList<PlayerCredentials>();
- +
- + /**
- + * Gets a player credentials object by player name
- + * @param name
- + * @return
- + */
- + public static PlayerCredentials getByName(String name) {
- + return getByName(name, false);
- + }
- +
- + /**
- + * Gets a player credentials object by player name
- + * @param name
- + * @param cacheIfLoaded if true, then if this requires a database query, the
- + * resulting player credentials object will be cached
- + * @return
- + */
- + public static PlayerCredentials getByName(String name, boolean cacheIfLoaded) {
- + for (PlayerCredentials playerCredentials : playerCredentialsList) {
- + if (playerCredentials.getName().equalsIgnoreCase(name)) {
- + return playerCredentials;
- + }
- + }
- +
- + // If we're at this point, then it was not found, so check from database
- + PlayerCredentials playerCredentials = loadFromDatabaseByName(name);
- +
- + if (cacheIfLoaded && playerCredentials != null) {
- + playerCredentialsList.add(playerCredentials);
- + }
- +
- + return playerCredentials;
- + }
- +
- + /**
- + * Gets a player credentials object by unique ID
- + * @param playerId
- + * @return
- + */
- + public static PlayerCredentials getByUniqueId(UUID playerId) {
- + return getByUniqueId(playerId, false);
- + }
- +
- + /**
- + * Gets a player credentials object by unique ID
- + * @param playerId
- + * @param cacheIfLoaded if true, then if this requires a database query, the
- + * resulting player credentials object will be cached
- + * @return
- + */
- + public static PlayerCredentials getByUniqueId(UUID playerId, boolean cacheIfLoaded) {
- + for (PlayerCredentials credentials : playerCredentialsList) {
- + if (credentials.getUniqueId().equals(playerId)) {
- + return credentials;
- + }
- + }
- +
- + // If we're at this point, then it was not found, so check from database
- + PlayerCredentials credentials = loadFromDatabaseByUniqueId(playerId);
- +
- + if (credentials != null && cacheIfLoaded) {
- + playerCredentialsList.add(credentials);
- + }
- +
- + return credentials;
- + }
- +
- + /**
- + * Adds the specified credentials to the list
- + * @param credentials
- + */
- + public static void addCredentialsToCache(PlayerCredentials credentials) {
- + playerCredentialsList.add(credentials);
- + }
- +
- + /**
- + * Loads player's credentials from database by name
- + * @param name
- + * @return
- + */
- + private static PlayerCredentials loadFromDatabaseByName(String playerName) {
- + PreparedStatement statement = null;
- + ResultSet set = null;
- +
- + try {
- + statement = DBManager.prepareStatement("SELECT player_id FROM players WHERE lower(name) = ?;");
- + statement.setString(1, playerName.toLowerCase());
- + set = statement.executeQuery();
- +
- + if (set.next()) {
- + String uuidString = set.getString("player_id");
- + UUID uuid = UUID.fromString(uuidString);
- + PlayerCredentials credentials = new PlayerCredentials(uuid, playerName);
- +
- + return credentials;
- + }
- + } catch (SQLException ex) {
- + InnPlugin.logError("Unable to load player credentials from player name " + playerName + "!", ex);
- + } finally {
- + DBManager.closePreparedStatement(statement);
- + DBManager.closeResultSet(set);
- + }
- +
- + return null;
- + }
- +
- + /**
- + * Loads player's credentials from database by unique ID
- + * @param playerId
- + * @return
- + */
- + private static PlayerCredentials loadFromDatabaseByUniqueId(UUID playerId) {
- + PreparedStatement statement = null;
- + ResultSet set = null;
- +
- + try {
- + statement = DBManager.prepareStatement("SELECT name FROM players WHERE player_id = ?;");
- + statement.setString(1, playerId.toString());
- + set = statement.executeQuery();
- +
- + if (set.next()) {
- + String name = set.getString("name");
- + UUID uuid = UUID.fromString(playerId.toString());
- + PlayerCredentials credentials = new PlayerCredentials(uuid, name);
- +
- + return credentials;
- + }
- + } catch (SQLException ex) {
- + InnPlugin.logError("Unable to load player credentials from player ID " + playerId.toString() + "!", ex);
- + } finally {
- + DBManager.closePreparedStatement(statement);
- + DBManager.closeResultSet(set);
- + }
- +
- + return null;
- + }
- +}
- diff --git a/src/net/innectis/innplugin/Player/PlayerGroup.java b/src/net/innectis/innplugin/Player/PlayerGroup.java
- index 895127dba..2c05fa0ad 100644
- --- a/src/net/innectis/innplugin/Player/PlayerGroup.java
- +++ b/src/net/innectis/innplugin/Player/PlayerGroup.java
- @@ -6,6 +6,7 @@ import java.sql.SQLException;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.Set;
- +import java.util.UUID;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.Player.Chat.ChatColor;
- @@ -266,20 +267,20 @@ public enum PlayerGroup {
- }
- /**
- - * This method will look in the database for the group of the player with the given name.<br />
- + * This method will look in the database for the group of the player with the given ID.<br />
- * <b>If the player is online dont use this method, but look in their session object.</b>
- * @param playerName
- * @return PlayerGroup or PlayerGroup.NONE if not found
- */
- - public static PlayerGroup getGroupOfUsername(String playerName) {
- + public static PlayerGroup getGroupOfPlayerById(UUID playerId) {
- PlayerGroup group = PlayerGroup.NONE;
- PreparedStatement statement = null;
- ResultSet result = null;
- try {
- - statement = DBManager.prepareStatement("SELECT playergroup FROM players WHERE name = ? LIMIT 1;");
- - statement.setString(1, playerName);
- + statement = DBManager.prepareStatement("SELECT playergroup FROM players WHERE player_id = ?;");
- + statement.setString(1, playerId.toString());
- result = statement.executeQuery();
- if (result.next()) {
- @@ -287,7 +288,7 @@ public enum PlayerGroup {
- group = PlayerGroup.getGroup(groupId);
- }
- } catch (SQLException ex) {
- - InnPlugin.logError("Error getting group of player " + playerName, ex);
- + InnPlugin.logError("Error getting group of player with ID: " + playerId, ex);
- } finally {
- DBManager.closeResultSet(result);
- DBManager.closePreparedStatement(statement);
- diff --git a/src/net/innectis/innplugin/Player/PlayerSecurity.java b/src/net/innectis/innplugin/Player/PlayerSecurity.java
- index 7b6a21f4e..17cc16d96 100644
- --- a/src/net/innectis/innplugin/Player/PlayerSecurity.java
- +++ b/src/net/innectis/innplugin/Player/PlayerSecurity.java
- @@ -10,6 +10,7 @@ import java.text.DecimalFormatSymbols;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.Locale;
- +import java.util.UUID;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.Handlers.Iplogging.GeoLocation;
- import net.innectis.innplugin.Handlers.Iplogging.IPAddress;
- @@ -48,7 +49,7 @@ public class PlayerSecurity {
- */
- public static void checkPlayer(IdpPlayer player) {
- String currentip = player.getHandle().getAddress().getAddress().getHostAddress();
- - String lastIp = getLastIp(player.getName());
- + String lastIp = getLastIp(player.getUniqueId(), player.getName());
- // Check if there is a previous ip
- if (lastIp == null) {
- @@ -84,23 +85,22 @@ public class PlayerSecurity {
- InnPlugin.logInfo("Previous IP: " + lastIp + " - " + lastIpGeo.getCity() + " (" + lastIpGeo.getCountryCode() + ")");
- DecimalFormat format = new DecimalFormat("###,###", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
- InnPlugin.logInfo("Distance: " + format.format(distanceKM).replace(",", ".") + " KM");
- -
- }
- }
- /**
- - * This will lookup the IP the player has used <u>before</u> the current one.
- + * This will lookup the IP the player represented by their ID has used <u>before</u> the current one.
- * Meaning that this method will skip the first IP it finds.
- - * @param playername
- + * @param playerId
- * @return the IP used before the current IP, otherwise null
- */
- - private static String getLastIp(String playername) {
- + private static String getLastIp(UUID playerId, String playerName) {
- PreparedStatement statement = null;
- ResultSet result = null;
- try {
- - statement = DBManager.prepareStatement(" SELECT ip, logtime FROM innectis_db.ip_log WHERE name = ? ORDER BY logid DESC LIMIT 2; ");
- - statement.setString(1, playername);
- + statement = DBManager.prepareStatement("SELECT ip, logtime FROM ip_log WHERE player_id = ? ORDER BY logid DESC LIMIT 2;");
- + statement.setString(1, playerId.toString());
- result = statement.executeQuery();
- Calendar cal = Calendar.getInstance();
- @@ -117,7 +117,7 @@ public class PlayerSecurity {
- }
- }
- } catch (SQLException ex) {
- - InnPlugin.logError("Can't get previous IP of player ", ex);
- + InnPlugin.logError("Can't get previous IP of " + playerName + "!", ex);
- } finally {
- DBManager.closeResultSet(result);
- DBManager.closePreparedStatement(statement);
- @@ -128,13 +128,13 @@ public class PlayerSecurity {
- /**
- * This will check the password of a player
- - * @param playername
- - * @param teststring
- + * @param playerId
- + * @param password
- * @return
- */
- - public static boolean checkPlayerPassword(String playername, String teststring) {
- - byte[] inputpass = calculateSecurityHash(playername, teststring, DEFAULT_MULTI);
- - byte[] pass = getPlayerPassword(playername);
- + public static boolean checkPlayerPassword(UUID playerId, String playerName, String password) {
- + byte[] inputpass = calculateSecurityHash(playerId, password, DEFAULT_MULTI);
- + byte[] pass = getPlayerPassword(playerId, playerName);
- if (pass == null || inputpass == null) {
- return false;
- @@ -152,10 +152,9 @@ public class PlayerSecurity {
- /**
- * This will log a bad password for a player
- - * @param playername
- - * @param ip
- + * @param playerId
- */
- - public static boolean canLogin(String playername) {
- + public static boolean canLogin(UUID playerId, String playerName) {
- PreparedStatement statement = null;
- ResultSet set = null;
- @@ -163,11 +162,16 @@ public class PlayerSecurity {
- Calendar cal = Calendar.getInstance();
- cal.add(Calendar.HOUR, -BADLOGIN_HOURSCHECK);
- - statement = DBManager.prepareStatement(" SELECT logid FROM player_failedlogin WHERE logdate > ? AND username = ?");
- + statement = DBManager.prepareStatement("SELECT logid FROM player_failedlogin WHERE logdate > ? AND player_id = ?;");
- statement.setTimestamp(1, new Timestamp(cal.getTimeInMillis()));
- - statement.setString(2, playername);
- + statement.setString(2, playerId.toString());
- set = statement.executeQuery();
- + // No record, player is new, so allow login
- + if (!set.next()) {
- + return true;
- + }
- +
- int counter = 0;
- while (set.next()) {
- @@ -176,7 +180,7 @@ public class PlayerSecurity {
- return counter < BADLOGIN_MAXTIMES;
- } catch (SQLException ex) {
- - InnPlugin.logError("Cannot check if player can login, disallowing player. ", ex);
- + InnPlugin.logError("Cannot check if player " + playerName + " can login, disallowing login.", ex);
- } finally {
- DBManager.closeResultSet(set);
- DBManager.closePreparedStatement(statement);
- @@ -187,22 +191,22 @@ public class PlayerSecurity {
- /**
- * This will check if the player has a password setup.
- - * @param playername
- + * @param playerId
- */
- - public static boolean hasPassword(String playername) {
- + public static boolean hasPassword(UUID playerId, String playerName) {
- PreparedStatement statement = null;
- ResultSet result = null;
- try {
- - statement = DBManager.prepareStatement(" SELECT username FROM player_password WHERE username = ? ");
- - statement.setString(1, playername);
- + statement = DBManager.prepareStatement("SELECT player_id FROM player_password WHERE player_id = ?;");
- + statement.setString(1, playerId.toString());
- result = statement.executeQuery();
- if (result.next()) {
- return true;
- }
- } catch (SQLException ex) {
- - InnPlugin.logError("Error checking for player password... ", ex);
- + InnPlugin.logError("Error checking password for player " + playerName + "!", ex);
- } finally {
- DBManager.closeResultSet(result);
- DBManager.closePreparedStatement(statement);
- @@ -213,10 +217,10 @@ public class PlayerSecurity {
- /**
- * This will log a bad password for a player
- - * @param playername
- - * @param ip
- + * @param playerId
- + * @param password
- */
- - public static boolean setPassword(String playername, String password) {
- + public static boolean setPassword(UUID playerId, String playerName, String password) {
- PreparedStatement statement = null;
- try {
- @@ -224,18 +228,18 @@ public class PlayerSecurity {
- return false;
- }
- - byte[] pass = calculateSecurityHash(playername, password, DEFAULT_MULTI);
- + byte[] pass = calculateSecurityHash(playerId, password, DEFAULT_MULTI);
- - statement = DBManager.prepareStatement(" INSERT INTO player_password (username, password, dateset) "
- + statement = DBManager.prepareStatement(" INSERT INTO player_password (player_id, password, dateset) "
- + " values (?,?, CURRENT_TIMESTAMP) ON DUPLICATE KEY update password = ?, dateset = CURRENT_TIMESTAMP; ");
- - statement.setString(1, playername);
- + statement.setString(1, playerId.toString());
- statement.setBytes(2, pass);
- statement.setBytes(3, pass);
- statement.executeUpdate();
- return true;
- } catch (SQLException ex) {
- - InnPlugin.logError("Error setting player password... ", ex);
- + InnPlugin.logError("Error setting password of " + playerName + "!", ex);
- } finally {
- DBManager.closePreparedStatement(statement);
- }
- @@ -244,21 +248,21 @@ public class PlayerSecurity {
- }
- /**
- - * This will delete the password for the given player
- - * @param playername
- + * This will delete the password by the specified player ID
- + * @param playerId
- * @return true if password was removed
- */
- - public static boolean removePassword(String playername) {
- + public static boolean removePassword(UUID playerId, String playerName) {
- PreparedStatement statement = null;
- try {
- - statement = DBManager.prepareStatement(" DELETE FROM player_password WHERE username = ? ");
- - statement.setString(1, playername);
- -
- + statement = DBManager.prepareStatement("DELETE FROM player_password WHERE player_id = ?;");
- + statement.setString(1, playerId.toString());
- statement.executeUpdate();
- +
- return true;
- } catch (SQLException ex) {
- - InnPlugin.logError("Error removing player password... ", ex);
- + InnPlugin.logError("Error removing password for player " + playerName + "!", ex);
- } finally {
- DBManager.closePreparedStatement(statement);
- }
- @@ -268,20 +272,20 @@ public class PlayerSecurity {
- /**
- * This will log a bad password for a player
- - * @param playername
- + * @param playerId
- * @param ip
- */
- - public static void logBadPassword(String playername, String ip) {
- + public static void logBadPassword(UUID playerId, String playerName, String ip) {
- PreparedStatement statement = null;
- try {
- - statement = DBManager.prepareStatement(" INSERT INTO player_failedlogin (username, ip, logdate) VALUES (?,?,?) ; ");
- - statement.setString(1, playername);
- + statement = DBManager.prepareStatement("INSERT INTO player_failedlogin (player_id, ip, logdate) VALUES (?,?,?);");
- + statement.setString(1, playerId.toString());
- statement.setString(2, ip);
- statement.setTimestamp(3, new Timestamp(new Date().getTime()));
- statement.executeUpdate();
- } catch (SQLException ex) {
- - InnPlugin.logError("Cannot log bad password.. ('" + playername + "', '" + ip + "','" + new Date().getTime() + "') ", ex);
- + InnPlugin.logError("Cannot log bad password! (Player " + playerName + " trying pass with IP of " + ip + " on " + new Date().getTime() + ")", ex);
- } finally {
- DBManager.closePreparedStatement(statement);
- }
- @@ -295,8 +299,11 @@ public class PlayerSecurity {
- * Amount of times the hash must rewrite itself.
- * @return
- */
- - private static byte[] calculateSecurityHash(String salt, String input, int multiplyer) {
- + private static byte[] calculateSecurityHash(UUID playerId, String input, int multiplyer) {
- try {
- + // Add salt using player's name
- + String salt = playerId.toString();
- +
- java.security.MessageDigest messageDigest = java.security.MessageDigest.getInstance("SHA-256");
- messageDigest.update(salt.getBytes());
- byte[] buffer = messageDigest.digest(input.getBytes());
- @@ -306,30 +313,30 @@ public class PlayerSecurity {
- }
- return buffer;
- } catch (NoSuchAlgorithmException ex) {
- - InnPlugin.logError("Error digesting password... ", ex);
- + InnPlugin.logError("Error digesting password for player ID: " + playerId.toString() + "!", ex);
- return null;
- }
- }
- /**
- - * Looks up the encrypted password of the player in the database
- - * @param playername
- + * Looks up the encrypted password based on the player ID
- + * @param playerId
- * @return
- */
- - private static byte[] getPlayerPassword(String playername) {
- + private static byte[] getPlayerPassword(UUID playerId, String playerName) {
- PreparedStatement statement = null;
- ResultSet result = null;
- try {
- - statement = DBManager.prepareStatement(" SELECT password FROM player_password WHERE username = ? ");
- - statement.setString(1, playername);
- + statement = DBManager.prepareStatement("SELECT password FROM player_password WHERE player_id = ?;");
- + statement.setString(1, playerId.toString());
- result = statement.executeQuery();
- if (result.next()) {
- return result.getBytes("password");
- }
- } catch (SQLException ex) {
- - InnPlugin.logError("Error getting player password... ", ex);
- + InnPlugin.logError("Error getting password of " + playerName + "!", ex);
- } finally {
- DBManager.closeResultSet(result);
- DBManager.closePreparedStatement(statement);
- diff --git a/src/net/innectis/innplugin/Player/PlayerSession.java b/src/net/innectis/innplugin/Player/PlayerSession.java
- index 4b848f23f..6e1fb05ab 100644
- --- a/src/net/innectis/innplugin/Player/PlayerSession.java
- +++ b/src/net/innectis/innplugin/Player/PlayerSession.java
- @@ -4,7 +4,6 @@ import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- -import java.util.Arrays;
- import java.util.Collections;
- import java.util.Date;
- import java.util.HashMap;
- @@ -14,6 +13,7 @@ import java.util.List;
- import java.util.Map;
- import java.util.Map.Entry;
- import java.util.TimeZone;
- +import java.util.UUID;
- import net.innectis.innplugin.Configuration;
- import net.innectis.innplugin.Handlers.Datasource.DBManager;
- import net.innectis.innplugin.Handlers.Iplogging.Playerinfo;
- @@ -61,31 +61,53 @@ import org.bukkit.util.Vector;
- public class PlayerSession {
- // <editor-fold defaultstate="collapsed" desc="Static methods and objects">
- - private static Map<String, PlayerSession> sessions = Collections.synchronizedMap(new HashMap<String, PlayerSession>());
- + private static Map<UUID, PlayerSession> sessions = Collections.synchronizedMap(new HashMap<UUID, PlayerSession>());
- private static final Object _synclock = new Object();
- /**
- * Checks if there is a session for the player
- *
- - * @param playername
- + * @param playerName
- * @return
- */
- - public static boolean hasSession(String playername) {
- - return sessions.containsKey(playername.toLowerCase());
- + public static boolean hasSession(String playerName) {
- + for (PlayerSession session : sessions.values()) {
- + if (session.getRealName().equalsIgnoreCase(playerName)) {
- + return true;
- + }
- + }
- +
- + return false;
- + }
- +
- + /**
- + * Checks if there is a session for the player by ID
- + *
- + * @param playerName
- + * @return
- + */
- + public static boolean hasSession(UUID playerId) {
- + for (PlayerSession session : sessions.values()) {
- + if (session.getUniqueId().equals(playerId)) {
- + return true;
- + }
- + }
- +
- + return false;
- }
- /**
- * Cleans up expired sessions
- *
- - * @param currentTimeMillis
- + * @param now
- */
- - public static void cleanup(Long now) {
- + public static void cleanup(long now) {
- for (PlayerSession session : getSessions()) {
- if (session.getExpireTime() > 0 && now > session.getExpireTime()) {
- session.destroy();
- } else if (session.getExpireTime() == 0) {
- // Check if session got stuck.
- - if (InnPlugin.getPlugin().getPlayer(session.username) == null) {
- + if (InnPlugin.getPlugin().getPlayer(session.playerName) == null) {
- session.expireSession(5);
- }
- }
- @@ -95,32 +117,81 @@ public class PlayerSession {
- /**
- * Returns an active session. This will be null if the session had
- * already expired.
- - * @param playername
- + * @param uniqueId
- + * @return
- + */
- + public static PlayerSession getActiveSession(UUID uniqueId) {
- + return sessions.get(uniqueId);
- + }
- +
- + /**
- + * Gets a session from the specified player ID
- + * @param playerName
- + * @return
- + */
- + public static PlayerSession getSession_(UUID playerId) {
- + for (PlayerSession session : sessions.values()) {
- + if (session.getUniqueId().equals(playerId)) {
- + return session;
- + }
- + }
- +
- + return null;
- + }
- +
- + /**
- + * Gets a session from the specified player name
- + * @param playerName
- * @return
- */
- - public static PlayerSession getActiveSession(String playername) {
- - return sessions.get(playername.toLowerCase());
- + public static PlayerSession getSession_(String playerName) {
- + for (PlayerSession session : sessions.values()) {
- + if (session.getDisplayName().equalsIgnoreCase(playerName)) {
- + return session;
- + }
- + }
- +
- + return null;
- }
- /**
- - * Retuns the session of the given player. If there is no session for the
- - * player, a new one is created. If the player of the session is not online,
- - * it will expire automaticly in 10 minutes
- + * Retuns the session of the player represented by name and ID.
- + * If there is no session for the player, a new one is created. If the
- + * player of the session is not online, it will expire automaticly in
- + * 10 minutes
- *
- - * @param playername
- + * @param playerId
- + * @param playerName
- * @param server
- * @return session for the given player
- */
- - public static PlayerSession getSession(String playername, InnPlugin server) {
- + public static PlayerSession getSession(UUID playerId, String playerName, InnPlugin server) {
- + return getSession(playerId, playerName, server, false);
- + }
- +
- + /**
- + * Retuns the session of the player represented by name and ID.
- + * If there is no session for the player, a new one is created. If the
- + * player of the session is not online, it will expire automaticly in
- + * 10 minutes
- + *
- + * @param playerId
- + * @param playerName
- + * @param server
- + * @param isFixedName if true, then this name is fixed and does not need to
- + * be updated from the database
- + * @return session for the given player
- + */
- + public static PlayerSession getSession(UUID playerId, String playerName, InnPlugin server, boolean isFixedName) {
- synchronized (_synclock) {
- // Get the session
- - PlayerSession session = sessions.get(playername.toLowerCase());
- + PlayerSession session = sessions.get(playerId);
- if (session != null) {
- // Check if object was about to expire
- if (session.getExpireTime() > 0) {
- // Check if player is still online
- - if (server.getPlayer(playername.toLowerCase(), true) == null) {
- + if (server.getPlayer(playerId) == null) {
- // Reset expire time
- session.expireSession(10);
- } else {
- @@ -130,31 +201,34 @@ public class PlayerSession {
- }
- } else {
- if (InnPlugin.isDebugEnabled()) {
- - InnPlugin.logDebug("Creating new session for " + playername);
- + InnPlugin.logDebug("Creating new session for " + playerName + ".");
- + }
- +
- + // If this name is not fixed (according to the player's chatname setting)
- + // then get the fixed name from the database
- + if (!isFixedName) {
- + String testName = getFixedPlayerName(playerId);
- +
- + // Player might be new, so there is no name in the database yet
- + if (testName != null) {
- + playerName = testName;
- + }
- }
- +
- // Create new session
- - session = new PlayerSession(playername, server);
- + session = new PlayerSession(playerId, playerName, server);
- // Register the session!
- - sessions.put(playername.toLowerCase(), session);
- + sessions.put(playerId, session);
- // Expire session in 10 minutes if player not online
- - if (server.getPlayer(playername.toLowerCase(), true) == null) {
- + if (server.getPlayer(playerId) == null) {
- session.expireSession(10);
- }
- }
- +
- return session;
- }
- }
- - /**
- - * Checks if the player is valid
- - * @param username
- - * @return
- - */
- - public static boolean isValidPlayer(String username) {
- - PlayerGroup group = PlayerGroup.getGroupOfUsername(username);
- - return (group != PlayerGroup.NONE);
- - }
- -
- /**
- * Returns a list with all sessions Note: some session can contain players
- * that are offline!
- @@ -171,27 +245,28 @@ public class PlayerSession {
- * Will do a call to the database to get the fixed name.
- */
- public void refixUsername() {
- - this.username = getFixedUsername(username);
- + this.playerName = getFixedPlayerName(playerId);
- }
- /**
- * Looks up the username from the database.
- *
- - * @param username
- + * @param playerId
- * @return The username as in the database
- */
- - private static String getFixedUsername(String username) {
- + private static String getFixedPlayerName(UUID playerId) {
- + String fixedName = null;
- PreparedStatement statement = null;
- ResultSet set = null;
- try {
- // Check the username for caps
- - statement = DBManager.prepareStatement("SELECT name FROM players WHERE lower(name) = ?");
- - statement.setString(1, username);
- + statement = DBManager.prepareStatement("SELECT name FROM players WHERE player_id = ?");
- + statement.setString(1, playerId.toString());
- set = statement.executeQuery();
- if (set.next()) {
- - username = set.getString("name");
- + fixedName = set.getString("name");
- }
- } catch (SQLException ex) {
- InnPlugin.logError("Cannot get the fixed username from the database.", ex);
- @@ -200,7 +275,7 @@ public class PlayerSession {
- DBManager.closePreparedStatement(statement);
- }
- - return username;
- + return fixedName;
- }
- //</editor-fold>
- //
- @@ -217,10 +292,16 @@ public class PlayerSession {
- }
- //</editor-fold>
- //
- + /**
- + * The ID of the owner of this session
- + */
- + protected UUID playerId;
- +
- /**
- * The playername of the owner of this session
- */
- - protected String username;
- + protected String playerName;
- +
- private InnPlugin server;
- /**
- * The type of inventory the player has
- @@ -228,15 +309,15 @@ public class PlayerSession {
- protected InventoryType invType;
- /**
- - * @param username
- + * @param playerId
- * @param server
- */
- - private PlayerSession(String username, InnPlugin server) {
- + private PlayerSession(UUID playerId, String playerName, InnPlugin server) {
- // Reset session time.
- sessionStart = System.currentTimeMillis();
- - // Get the (fixed) chat name.
- - this.username = getFixedUsername(username);
- + this.playerId = playerId;
- + this.playerName = playerName;
- this.server = server;
- loadSettings();
- @@ -305,8 +386,8 @@ public class PlayerSession {
- // This is not inside a method as it should never be fired for any other reason...
- try {
- // Set the logout time.
- - statement = DBManager.prepareStatement("UPDATE ip_log SET logouttime = CURRENT_TIMESTAMP where name = ? AND logouttime is null order by logtime desc limit 1;");
- - statement.setString(1, username);
- + statement = DBManager.prepareStatement("UPDATE ip_log SET logouttime = CURRENT_TIMESTAMP WHERE player_id = ? AND logouttime IS NULL ORDER BY logtime DESC LIMIT 1;");
- + statement.setString(1, playerId.toString());
- statement.execute();
- } catch (SQLException ex) {
- InnPlugin.logError("SqlException updating logouttime", ex);
- @@ -365,16 +446,30 @@ public class PlayerSession {
- */
- public String getDisplayName() {
- if (spoofObject == null) {
- - return this.username;
- + return playerName;
- }
- +
- return spoofObject.getSpoofName();
- }
- +
- + public void setUsername(String username) {
- + this.playerName = username;
- + }
- +
- + /**
- + * Gets the ID of this player
- + * @return
- + */
- + public UUID getUniqueId() {
- + return playerId;
- + }
- +
- /**
- * Gets the real name of the current player.
- */
- public String getRealName() {
- - return this.username;
- + return this.playerName;
- }
- /**
- @@ -382,7 +477,7 @@ public class PlayerSession {
- */
- public String getColoredDisplayName() {
- if (spoofObject == null) {
- - return this.nameColor + this.username;
- + return this.nameColor + this.playerName;
- }
- return spoofObject.getSpoofNameColor();
- }
- @@ -514,8 +609,8 @@ public class PlayerSession {
- ResultSet result = null;
- try {
- - statement = DBManager.prepareStatement("SELECT onlinetime FROM players WHERE name = ?;");
- - statement.setString(1, username);
- + statement = DBManager.prepareStatement("SELECT onlinetime FROM players WHERE player_id = ?;");
- + statement.setString(1, playerId.toString());
- result = statement.executeQuery();
- if (result.next()) {
- @@ -553,9 +648,9 @@ public class PlayerSession {
- return; //dont increment played time if they're afk
- }
- - statement = DBManager.prepareStatement("update players set onlinetime = ? where name = ?");
- + statement = DBManager.prepareStatement("UPDATE players SET onlinetime = ? WHERE player_id = ?");
- statement.setFloat(1, newvalue);
- - statement.setString(2, username);
- + statement.setString(2, playerId.toString());
- statement.executeUpdate();
- _totalOnlineTime = newvalue;
- @@ -581,9 +676,10 @@ public class PlayerSession {
- PreparedStatement statement = null;
- try {
- - statement = DBManager.prepareStatement("INSERT INTO players (name, playergroup) VALUES (?,?) ON DUPLICATE KEY UPDATE lastlogin = CURRENT_TIMESTAMP");
- - statement.setString(1, username);
- - statement.setInt(2, PlayerGroup.GUEST.id);
- + statement = DBManager.prepareStatement("INSERT INTO players (player_id, name, playergroup) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE lastlogin = CURRENT_TIMESTAMP");
- + statement.setString(1, playerId.toString());
- + statement.setString(2, playerName);
- + statement.setInt(3, PlayerGroup.GUEST.id);
- statement.executeUpdate();
- } catch (SQLException ex) {
- server.logError("SQLException setLastLogin() " + getColoredName() + ChatColor.RED + " " + ex.getMessage());
- @@ -604,8 +700,8 @@ public class PlayerSession {
- ResultSet result = null;
- try {
- - statement = DBManager.prepareStatement("SELECT lastlogin FROM players WHERE name = ? LIMIT 1;");
- - statement.setString(1, username);
- + statement = DBManager.prepareStatement("SELECT lastlogin FROM players WHERE player_id = ? LIMIT 1;");
- + statement.setString(1, playerId.toString());
- result = statement.executeQuery();
- if (result.next()) {
- @@ -636,8 +732,8 @@ public class PlayerSession {
- ResultSet result = null;
- try {
- - statement = DBManager.prepareStatement(" SELECT logouttime FROM ip_log where name = ? and logouttime is not null order by logtime desc LIMIT 1;");
- - statement.setString(1, username);
- + statement = DBManager.prepareStatement(" SELECT logouttime FROM ip_log WHERE player_id = ? AND logouttime IS NOT NULL ORDER BY logtime DESC LIMIT 1;");
- + statement.setString(1, playerId.toString());
- result = statement.executeQuery();
- if (result.next()) {
- @@ -661,7 +757,7 @@ public class PlayerSession {
- * @return
- */
- public Playerinfo getPlayerinfo() {
- - return Playerinfo.findPlayer(username);
- + return Playerinfo.findPlayer(playerId, playerName);
- }
- // </editor-fold>
- //
- @@ -707,7 +803,7 @@ public class PlayerSession {
- public void destroy() {
- synchronized (_synclock) {
- expire();
- - sessions.remove(username.toLowerCase());
- + sessions.remove(playerId);
- }
- }
- // </editor-fold>
- @@ -724,7 +820,7 @@ public class PlayerSession {
- */
- public final PlayerGroup getGroup() {
- if (group == null) {
- - group = PlayerGroup.getGroupOfUsername(username);
- + group = PlayerGroup.getGroupOfPlayerById(playerId);
- // Group not found
- if (group == PlayerGroup.NONE) {
- @@ -742,7 +838,7 @@ public class PlayerSession {
- * @return
- */
- public boolean isValidPlayer() {
- - PlayerGroup tempGroup = PlayerGroup.getGroupOfUsername(username);
- + PlayerGroup tempGroup = PlayerGroup.getGroupOfPlayerById(playerId);
- return (tempGroup != PlayerGroup.NONE);
- }
- @@ -757,9 +853,9 @@ public class PlayerSession {
- PreparedStatement statement = null;
- try {
- - statement = DBManager.prepareStatement("update players set playergroup = ? where name = ?;");
- + statement = DBManager.prepareStatement("UPDATE players set playergroup = ? WHERE player_id = ?;");
- statement.setInt(1, newGroup.id);
- - statement.setString(2, username);
- + statement.setString(2, playerId.toString());
- statement.executeUpdate();
- setGroupWithoutUpdate(newGroup);
- @@ -853,9 +949,9 @@ public class PlayerSession {
- PreparedStatement statement = null;
- try {
- - statement = DBManager.prepareStatement("insert into prefix (name, subid, text, color1, color2) values "
- - + "(?,?,?,?,?) on duplicate key update text = ?, color1 = ?, color2 = ? ;");
- - statement.setString(1, username);
- + statement = DBManager.prepareStatement("INSERT INTO prefix (player_id, subid, text, color1, color2) values "
- + + "(?,?,?,?,?) on duplicate key update text = ?, color1 = ?, color2 = ?;");
- + statement.setString(1, playerId.toString());
- statement.setInt(2, id);
- statement.setString(3, text);
- statement.setString(4, bracketcolor.getCode());
- @@ -884,8 +980,8 @@ public class PlayerSession {
- ResultSet result = null;
- try {
- - statement = DBManager.prepareStatement("SELECT text, color1, color2, subid FROM prefix WHERE name = ? ;");
- - statement.setString(1, username);
- + statement = DBManager.prepareStatement("SELECT text, color1, color2, subid FROM prefix WHERE player_id = ?;");
- + statement.setString(1, playerId.toString());
- result = statement.executeQuery();
- while (result.next()) {
- @@ -941,12 +1037,12 @@ public class PlayerSession {
- * Gets the coloured name of the player
- */
- public String getColoredName() {
- - return nameColor + username;
- + return nameColor + playerName;
- }
- public void setColoredName(ChatColor color, String username) {
- this.nameColor = color;
- - this.username = username;
- + this.playerName = username;
- }
- // </editor-fold>
- //
- @@ -1462,7 +1558,9 @@ public class PlayerSession {
- if (name == null) {
- return;
- }
- - IdpPlayer player = InnPlugin.getPlugin().getPlayer(username, true);
- +
- + IdpPlayer player = InnPlugin.getPlugin().getPlayer(playerId);
- +
- if (player != null) {
- player.getHandle().getHandle().playerConnection.sendIDPPacketPlayOutPlayerInfo(new PacketPlayOutPlayerInfo(name, online, ping));
- }
- @@ -1514,59 +1612,47 @@ public class PlayerSession {
- private long lastDamageTick = 0L;
- private long lastPvPTick = 0L;
- private long pvpImmuneTime = 0L;
- - private Map<String, List<Long>> pvpList = new HashMap<String, List<Long>>();
- + private Map<UUID, List<Long>> pvpList = new HashMap<UUID, List<Long>>();
- /**
- * Adds a kill to the pvp kill list
- *
- - * @param target
- + * @param playerId
- */
- - public void addPvpKill(IdpPlayer target) {
- - String nameLower = target.getName().toLowerCase();
- -
- - if (!pvpList.containsKey(nameLower)) {
- + public void addPvpKill(UUID playerId) {
- + if (!pvpList.containsKey(playerId)) {
- List<Long> pvpTimes = new ArrayList<Long>();
- pvpTimes.add(System.currentTimeMillis());
- - pvpList.put(nameLower, pvpTimes);
- + pvpList.put(playerId, pvpTimes);
- } else {
- - List<Long> pvpTimes = new ArrayList<Long>(pvpList.get(nameLower));
- + List<Long> pvpTimes = new ArrayList<Long>(pvpList.get(playerId));
- pvpTimes.add(System.currentTimeMillis());
- - pvpList.put(nameLower, pvpTimes);
- + pvpList.put(playerId, pvpTimes);
- }
- }
- - /**
- - * Gets the amount of times this player has killed the target player.
- - *
- - * @param target
- - * @return amount of kills
- - */
- - public int getPvpKillTotalOf(IdpPlayer target) {
- - return getPvpKillTotalOf(target.getName());
- - }
- -
- /**
- * Gets the amount of times this player has killed the target player.
- * Kills past the PvP retention time will not be counted.
- *
- - * @param username of the target
- + * @param playerId ID of the player
- * @return amount of kills
- */
- - public int getPvpKillTotalOf(String username) {
- - String nameLower = username.toLowerCase();
- -
- - if (!pvpList.containsKey(nameLower)) {
- + public int getPvpKillTotalOf(UUID playerId) {
- + if (!pvpList.containsKey(playerId)) {
- return 0;
- }
- int count = 0;
- long now = System.currentTimeMillis();
- - ArrayList<Long> pvpTimes = new ArrayList<Long>(pvpList.get(nameLower));
- + ArrayList<Long> pvpTimes = new ArrayList<Long>(pvpList.get(playerId));
- +
- for (long time : pvpTimes) {
- if (now - time < Configuration.PLAYER_PVP_KILL_RETENTION) {
- count++;
- }
- }
- +
- return count;
- }
- @@ -1575,8 +1661,8 @@ public class PlayerSession {
- */
- public void cleanupPvpKills() {
- long time, now = System.currentTimeMillis();
- - for (Iterator<Entry<String, List<Long>>> it = pvpList.entrySet().iterator(); it.hasNext();) {
- - Entry<String, List<Long>> entry = it.next();
- + for (Iterator<Entry<UUID, List<Long>>> it = pvpList.entrySet().iterator(); it.hasNext();) {
- + Entry<UUID, List<Long>> entry = it.next();
- for (Iterator<Long> it2 = entry.getValue().iterator(); it2.hasNext();) {
- time = it2.next();
- @@ -1899,12 +1985,14 @@ public class PlayerSession {
- if (requests == null) {
- requests = new HashMap<Long, Request>(1);
- }
- - String currentRequestPlayer = request.getRequester().getName();
- - IdpPlayer requester;
- +
- + UUID currentRequesterId = request.getRequesterId();
- +
- for (Request req : requests.values()) {
- if (req != null) {
- - requester = req.getRequester();
- - if (requester != null && currentRequestPlayer.equalsIgnoreCase(requester.getName())) {
- + IdpPlayer requester = req.getRequester();
- +
- + if (requester != null && currentRequesterId.equals(requester.getUniqueId())) {
- return false;
- }
- }
- @@ -1916,25 +2004,25 @@ public class PlayerSession {
- //
- // <editor-fold defaultstate="collapsed" desc="Chat">
- // Holds the list of ignored players
- - private List<String> ignoredPlayers = new ArrayList<String>();
- + private List<PlayerCredentials> ignoredPlayers = new ArrayList<PlayerCredentials>();
- private ChatInjector injector = null;
- /**
- * Adds a new player to the ignored list
- *
- - * @param player
- + * @param credentials
- * @return false if the player cannot be ignored
- */
- - public boolean addIgnoredUser(String player) {
- + public boolean addIgnoredUser(PlayerCredentials credentials) {
- PlayerSession session = null;
- boolean isTempSession = false;
- - IdpPlayer p = server.getPlayer(player);
- + IdpPlayer p = server.getPlayer(credentials.getUniqueId());
- if (p != null) {
- session = p.getSession();
- } else {
- - session = PlayerSession.getSession(player, server);
- + session = PlayerSession.getSession(credentials.getUniqueId(), credentials.getName(), server, true);
- isTempSession = true;
- }
- @@ -1947,8 +2035,8 @@ public class PlayerSession {
- return false;
- }
- - ignoredPlayers.add(player);
- - addIgnoredPlayerToDB(player);
- + ignoredPlayers.add(credentials);
- + addIgnoredPlayerToDB(credentials.getUniqueId(), credentials.getName());
- return true;
- }
- @@ -1956,19 +2044,26 @@ public class PlayerSession {
- /**
- * This removes a player from the ignore list lowercase
- *
- - * @param player
- + * @param playerName
- */
- - public void removeIgnoredUser(String player) {
- - for (Iterator<String> it = ignoredPlayers.iterator(); it.hasNext();) {
- - String p = it.next();
- + public void removeIgnoredUser(String playerName) {
- + PlayerCredentials removeCredentials = null;
- - if (p.equalsIgnoreCase(player)) {
- + for (Iterator<PlayerCredentials> it = ignoredPlayers.iterator(); it.hasNext();) {
- + PlayerCredentials credentials = it.next();
- +
- + if (credentials.getName().equalsIgnoreCase(playerName)) {
- + removeCredentials = credentials;
- it.remove();
- break;
- }
- }
- - removeIgnoredPlayerFromDB(player);
- + if (removeCredentials == null) {
- + return;
- + }
- +
- + removeIgnoredPlayerFromDB(removeCredentials);
- }
- /**
- @@ -1980,14 +2075,13 @@ public class PlayerSession {
- }
- /**
- - * Checks if the player is ignored or not. The name is automaticly set to
- - * lowercase
- + * Checks if the player is ignored or not
- *
- - * @param player
- + * @param playerName
- * @return
- */
- - public boolean isIgnored(String player) {
- - IdpPlayer testPlayer = server.getPlayer(player);
- + public boolean isIgnored(String playerName) {
- + IdpPlayer testPlayer = server.getPlayer(playerName);
- // If a staff member is on the ignore list somehow and they have ignore override
- // then return false because they can't be ignored
- @@ -1995,8 +2089,8 @@ public class PlayerSession {
- return false;
- }
- - for (String checkPlayer : ignoredPlayers) {
- - if (checkPlayer.equalsIgnoreCase(player)) {
- + for (PlayerCredentials pc : ignoredPlayers) {
- + if (pc.getName().equalsIgnoreCase(playerName)) {
- return true;
- }
- }
- @@ -2009,29 +2103,35 @@ public class PlayerSession {
- *
- * @return unmodifiable list of ignored players
- */
- - public List<String> getIgnoredPlayers() {
- + public List<PlayerCredentials> getIgnoredPlayers() {
- return Collections.unmodifiableList(ignoredPlayers);
- }
- /**
- * Loads the ignored players from database
- - * @todo: use a separate table for ignored users, this is ugly
- */
- private void loadIgnoredPlayersFromDB() {
- PreparedStatement statement = null;
- ResultSet set = null;
- try {
- - statement = DBManager.prepareStatement("SELECT * FROM players_ignored where lower(player) = ?;");
- - statement.setString(1, username);
- + statement = DBManager.prepareStatement("SELECT * FROM players_ignored where player_id = ?;");
- + statement.setString(1, playerId.toString());
- set = statement.executeQuery();
- while (set.next()) {
- - String ignoredPlayer = set.getString("ignored_player");
- - ignoredPlayers.add(ignoredPlayer);
- + String ignoredPlayerIdString = set.getString("ignored_player_id");
- + UUID ignoredPlayerId = UUID.fromString(ignoredPlayerIdString);
- +
- + if (ignoredPlayerId.equals(Configuration.EVERYONE_IDENTIFIER)) {
- + ignoredPlayers.add(Configuration.EVERYONE_CREDENTIALS);
- + } else {
- + PlayerCredentials ignoredPlayerCredentials = PlayerCredentialsManager.getByUniqueId(ignoredPlayerId, true);
- + ignoredPlayers.add(ignoredPlayerCredentials);
- + }
- }
- } catch (SQLException ex) {
- - InnPlugin.logError("Unable to load ignore list for " + username + "!", ex);
- + InnPlugin.logError("Unable to load ignore list for " + playerName + "!", ex);
- } finally {
- DBManager.closeResultSet(set);
- DBManager.closePreparedStatement(statement);
- @@ -2041,35 +2141,35 @@ public class PlayerSession {
- /**
- * Adds the ignored player to the database
- */
- - private void addIgnoredPlayerToDB(String player) {
- + private void addIgnoredPlayerToDB(UUID ignoredPlayerId, String ignoredPlayerName) {
- PreparedStatement statement = null;
- try {
- - statement = DBManager.prepareStatement("INSERT INTO players_ignored VALUES (?, ?);");
- - statement.setString(1, username);
- - statement.setString(2, player);
- + statement = DBManager.prepareStatement("INSERT INTO players_ignored (player_id, ignored_player_id) VALUES (?, ?);");
- + statement.setString(1, playerId.toString());
- + statement.setString(2, ignoredPlayerId.toString());
- statement.execute();
- } catch (SQLException ex) {
- - InnPlugin.logError("Failed to add ignored player " + player + " for " + username + "!", ex);
- + InnPlugin.logError("Failed to add ignored player " + ignoredPlayerName + " for " + playerName + "!", ex);
- } finally {
- DBManager.closePreparedStatement(statement);
- }
- }
- /**
- - * Removes the ignored player from the database
- + * playerId the ignored player from the database
- * @param player
- */
- - private void removeIgnoredPlayerFromDB(String player) {
- + private void removeIgnoredPlayerFromDB(PlayerCredentials credentials) {
- PreparedStatement statement = null;
- try {
- - statement = DBManager.prepareStatement("DELETE FROM players_ignored WHERE lower(player) = ? AND lower(ignored_player) = ?;");
- - statement.setString(1, username.toLowerCase());
- - statement.setString(2, player.toLowerCase());
- + statement = DBManager.prepareStatement("DELETE FROM players_ignored WHERE player_id = ? AND ignored_player_id = ?;");
- + statement.setString(1, playerId.toString());
- + statement.setString(2, credentials.getUniqueId().toString());
- statement.execute();
- } catch (SQLException ex) {
- - InnPlugin.logError("Could not remove ignored player " + player + " from " + username + "!", ex);
- + InnPlugin.logError("Could not remove ignored player " + credentials.getName() + " from " + playerName + "!", ex);
- } finally {
- DBManager.closePreparedStatement(statement);
- }
- @@ -2082,11 +2182,11 @@ public class PlayerSession {
- PreparedStatement statement = null;
- try {
- - statement = DBManager.prepareStatement("DELETE FROM players_ignored WHERE lower(player) = ?;");
- - statement.setString(1, username.toLowerCase());
- + statement = DBManager.prepareStatement("DELETE FROM players_ignored WHERE player_id = ?;");
- + statement.setString(1, playerId.toString());
- statement.execute();
- } catch (SQLException ex) {
- - InnPlugin.logError("Could not clear all ignored players from " + username + "!", ex);
- + InnPlugin.logError("Could not clear all ignored players from " + playerName + "!", ex);
- } finally {
- DBManager.closePreparedStatement(statement);
- }
- @@ -2252,8 +2352,8 @@ public class PlayerSession {
- ResultSet set = null;
- try {
- - statement = DBManager.prepareStatement("SELECT * FROM channel_members WHERE lower(username) = ?;");
- - statement.setString(1, username.toLowerCase());
- + statement = DBManager.prepareStatement("SELECT * FROM channel_members WHERE player_id = ?;");
- + statement.setString(1, playerId.toString());
- set = statement.executeQuery();
- while (set.next()) {
- @@ -2263,7 +2363,7 @@ public class PlayerSession {
- channels.put(num, name);
- }
- } catch (SQLException ex) {
- - InnPlugin.logError("Unable to load personal channel numbers for " + username + "!", ex);
- + InnPlugin.logError("Unable to load personal channel numbers for " + playerName + "!", ex);
- } finally {
- DBManager.closeResultSet(set);
- DBManager.closePreparedStatement(statement);
- @@ -2278,7 +2378,7 @@ public class PlayerSession {
- public void joinAllChatChannels() {
- for (String channelName : channels.values()) {
- ChatChannel channel = ChatChannelHandler.getChannel(channelName);
- - channel.setMemberStatus(username, true);
- + channel.setMemberStatus(playerName, true);
- channel.sendGeneralMessage(getColoredName() + ChatColor.AQUA + " has joined the channel.");
- }
- }
- @@ -2290,7 +2390,7 @@ public class PlayerSession {
- for (String channelName : channels.values()) {
- ChatChannel channel = ChatChannelHandler.getChannel(channelName, false);
- channel.sendGeneralMessage(getColoredName() + ChatColor.AQUA + " has left the channel.");
- - channel.setMemberStatus(username, false);
- + channel.setMemberStatus(playerName, false);
- if (channel.isAllOffline()) {
- ChatChannelHandler.unloadChannel(channelName);
- @@ -2388,7 +2488,7 @@ public class PlayerSession {
- */
- public IdpEditSession getEditSession() {
- if (_editsession == null) {
- - _editsession = new IdpEditSession(username);
- + _editsession = new IdpEditSession(playerId);
- }
- return _editsession;
- }
- @@ -2584,8 +2684,10 @@ public class PlayerSession {
- //<editor-fold defaultstate="collapsed" desc="Ender Chest Editing">
- /**
- * These are necessary to keep track of ender chest edits
- - */
- + */
- +
- private String enderchestOwner = null;
- + private UUID enderchestOwnerId = null;
- private EnderContentsType enderchestType = null;
- private boolean isViewingEnderChest = false;
- @@ -2606,8 +2708,7 @@ public class PlayerSession {
- }
- /**
- - * Sets the owner of the ender chest being viewed
- - *
- + * Sets the owner of the enderchest being viewed
- * @param enderchestOwner
- */
- public void setEnderchestOwner(String enderchestOwner) {
- @@ -2615,14 +2716,31 @@ public class PlayerSession {
- }
- /**
- - * Gets the owner of the ender chest being viewed
- + * Sets the ID of the owner of the ender chest being viewed
- *
- + * @param enderchestOwnerId
- + */
- + public void setEnderchestOwnerId(UUID enderchestOwnerId) {
- + this.enderchestOwnerId = enderchestOwnerId;
- + }
- +
- + /**
- + * Gets the owner of the enderchest being viewed
- * @return
- */
- public String getEnderchestOwner() {
- return enderchestOwner;
- }
- + /**
- + * Gets the ID of the ender chest being viewed
- + *
- + * @return
- + */
- + public UUID getEnderchestOwnerId() {
- + return enderchestOwnerId;
- + }
- +
- /**
- * Sets the chest type of the ender chest being viewed
- *
- @@ -2715,7 +2833,7 @@ public class PlayerSession {
- home.setLocation(loc);
- update = true;
- } else {
- - home = new IdpHome(username, homeNum, homeName, loc);
- + home = new IdpHome(playerId, homeNum, homeName, loc);
- homes.put(homeNum, home);
- }
- home.save();
- @@ -2867,8 +2985,8 @@ public class PlayerSession {
- ResultSet set = null;
- try {
- - statement = DBManager.prepareStatement("SELECT * FROM homes WHERE lower(username) = ? ORDER BY homeid ASC");
- - statement.setString(1, username.toLowerCase());
- + statement = DBManager.prepareStatement("SELECT * FROM homes WHERE player_id = ? ORDER BY homeid ASC");
- + statement.setString(1, playerId.toString());
- set = statement.executeQuery();
- while (set.next()) {
- @@ -2884,10 +3002,10 @@ public class PlayerSession {
- float yaw = set.getInt("yaw");
- Location location = new Location(world, x, y, z, yaw, 0);
- - IdpHome home = new IdpHome(UID, username, homeId, (homeName != null ? homeName : ""), location);
- + IdpHome home = new IdpHome(UID, playerId, homeId, (homeName != null ? homeName : ""), location);
- if (world == null || homes.containsKey(homeId)) {
- - InnPlugin.logError("Error while loading home " + homeId + " for " + username + "!");
- + InnPlugin.logError("Error while loading home " + homeId + " for " + playerName + "!");
- home.delete();
- if (world == null) {
- @@ -2896,14 +3014,15 @@ public class PlayerSession {
- InnPlugin.logError("The home ID " + homeId + " is a duplicate!");
- }
- - MailMessage msg = new MailMessage(new Date(), "Auto Message", username, "Invalid Home", "A home in " + worldName + " (" + x + ", " + y + ", " + z + ") was removed.");
- + PlayerCredentials credentials = PlayerCredentialsManager.getByUniqueId(playerId, true);
- + MailMessage msg = new MailMessage(new Date(), Configuration.SERVER_GENERATED_CREDENTIALS, credentials, "Invalid Home", "A home in " + worldName + " (" + x + ", " + y + ", " + z + ") was removed.");
- msg.save();
- } else {
- homes.put(homeId, home);
- }
- }
- } catch (SQLException ex) {
- - InnPlugin.logError("Unable to load homes for " + username + "!", ex);
- + InnPlugin.logError("Unable to load homes for " + playerName + "!", ex);
- } finally {
- DBManager.closeResultSet(set);
- DBManager.closePreparedStatement(statement);
- @@ -3029,7 +3148,7 @@ public class PlayerSession {
- */
- public PlayerBackpack getBackpack() {
- if (backpack == null) {
- - backpack = PlayerBackpack.loadBackpackFromDB(username);
- + backpack = PlayerBackpack.loadBackpackFromDB(playerId, playerName);
- if (backpack == null) {
- throw new RuntimeException("Cannot load backpack!");
- @@ -3049,7 +3168,7 @@ public class PlayerSession {
- */
- public final ModifiablePermissions getModifiablePermissions() {
- if (modifiablePermissions == null) {
- - modifiablePermissions = ModifiablePermissionsHandler.loadModifiedPermissions(username);
- + modifiablePermissions = ModifiablePermissionsHandler.loadModifiedPermissions(playerId);
- }
- return modifiablePermissions;
- @@ -3185,15 +3304,15 @@ public class PlayerSession {
- ResultSet set = null;
- try {
- - statement = DBManager.prepareStatement("SELECT timezone FROM players WHERE name = ?");
- - statement.setString(1, username);
- + statement = DBManager.prepareStatement("SELECT timezone FROM players WHERE player_id = ?");
- + statement.setString(1, playerId.toString());
- set = statement.executeQuery();
- if (set.next() && set.getString("timezone") != null) {
- timezone = TimeZone.getTimeZone(set.getString("timezone"));
- }
- } catch (SQLException ex) {
- - InnPlugin.logError("Could not load player " + username + " timezone!", ex);
- + InnPlugin.logError("Could not load player " + playerName + " timezone!", ex);
- } finally {
- DBManager.closeResultSet(set);
- DBManager.closePreparedStatement(statement);
- @@ -3216,14 +3335,14 @@ public class PlayerSession {
- PreparedStatement statement = null;
- try {
- - statement = DBManager.prepareStatement("UPDATE players SET timezone = ? WHERE name = ?");
- + statement = DBManager.prepareStatement("UPDATE players SET timezone = ? WHERE player_id = ?");
- statement.setString(1, newZone.getID());
- - statement.setString(2, username);
- + statement.setString(2, playerId.toString());
- statement.executeUpdate();
- this.timezone = newZone;
- } catch (SQLException ex) {
- - InnPlugin.logError("Failed to save timezone for " + username + "!", ex);
- + InnPlugin.logError("Failed to save timezone for " + playerName + "!", ex);
- } finally {
- DBManager.closePreparedStatement(statement);
- }
- @@ -3237,15 +3356,15 @@ public class PlayerSession {
- ResultSet set = null;
- try {
- - statement = DBManager.prepareStatement("SELECT settings FROM players WHERE name = ?");
- - statement.setString(1, username);
- + statement = DBManager.prepareStatement("SELECT settings FROM players WHERE player_id = ?");
- + statement.setString(1, playerId.toString());
- set = statement.executeQuery();
- if (set.next()) {
- settingfield = set.getLong("settings");
- }
- } catch (SQLException ex) {
- - InnPlugin.logError("Unable to load settings for " + username + "1", ex);
- + InnPlugin.logError("Unable to load settings for " + playerName + "1", ex);
- } finally {
- DBManager.closeResultSet(set);
- DBManager.closePreparedStatement(statement);
- @@ -3259,12 +3378,12 @@ public class PlayerSession {
- PreparedStatement statement = null;
- try {
- - statement = DBManager.prepareStatement("UPDATE players SET settings = ? WHERE name = ?");
- + statement = DBManager.prepareStatement("UPDATE players SET settings = ? WHERE player_id = ?");
- statement.setLong(1, settingfield);
- - statement.setString(2, username);
- + statement.setString(2, playerId.toString());
- statement.executeUpdate();
- } catch (SQLException ex) {
- - InnPlugin.logError("Failed to save settings for " + username + "!", ex);
- + InnPlugin.logError("Failed to save settings for " + playerName + "!", ex);
- } finally {
- DBManager.closePreparedStatement(statement);
- }
- @@ -3568,7 +3687,7 @@ public class PlayerSession {
- for (IdpPlayer targetPlayer : InnPlugin.getPlugin().getOnlinePlayers()) {
- IdpPlayer targetSpectatingPlayer = targetPlayer.getSession().getSpectating();
- if (targetSpectatingPlayer != null) {
- - if (targetSpectatingPlayer.getName().equalsIgnoreCase(username)) {
- + if (targetSpectatingPlayer.getName().equalsIgnoreCase(playerName)) {
- playerList.add(targetPlayer);
- }
- }
- @@ -3630,20 +3749,31 @@ public class PlayerSession {
- //</editor-fold>
- //
- //<editor-fold defaultstate="collapsed" desc="Inventory Viewing">
- + private UUID viewedInventoryOwnerId;
- private String viewedInventoryOwner;
- private InventoryType viewedInventoryType;
- /**
- * Sets the inventory owner
- - * @param inventoryOwner
- + * @param viewedInventoryOwnerId
- + * @param viewedInventoryType
- */
- - public void setInventoryView(String inventoryOwner, InventoryType viewedInventoryType) {
- - this.viewedInventoryOwner = inventoryOwner;
- + public void setInventoryView(UUID viewedInventoryOwnerId, String viewedInventoryOwner, InventoryType viewedInventoryType) {
- + this.viewedInventoryOwnerId = viewedInventoryOwnerId;
- + this.viewedInventoryOwner = viewedInventoryOwner;
- this.viewedInventoryType = viewedInventoryType;
- }
- /**
- - * Gets the inventory owner
- + * Gets the ID of the inventory owner
- + * @return
- + */
- + public UUID getViewedInventoryOwnerId() {
- + return viewedInventoryOwnerId;
- + }
- +
- + /**
- + * Gets the owner of the inventory being viewed
- * @return
- */
- public String getViewedInventoryOwner() {
- @@ -3662,6 +3792,7 @@ public class PlayerSession {
- * Clears the viewed inventory data
- */
- public void clearViewedInventory() {
- + viewedInventoryOwnerId = null;
- viewedInventoryOwner = null;
- viewedInventoryType = null;
- }
- @@ -3671,23 +3802,40 @@ public class PlayerSession {
- * @return
- */
- public boolean isViewingOtherInventory() {
- - return !(viewedInventoryOwner == null || viewedInventoryOwner.isEmpty());
- + return (viewedInventoryOwnerId != null);
- }
- //</editor-fold>
- //
- //<editor-fold defaultstate="collapsed" desc="Backpack viewing">
- - String backpackOwner = null;
- + private UUID backpackOwnerId = null;
- + private String backpackOwner = null;
- /**
- * Checks if the player is viewing a backpack
- * @return
- */
- public boolean isViewingBackpack() {
- - return (backpackOwner != null);
- + return (backpackOwnerId != null);
- }
- /**
- - * Gets the owner of the backpack being viewed
- + * Gets the player ID of the backpack being owned
- + * @return
- + */
- + public UUID getBackpackOwnerId() {
- + return backpackOwnerId;
- + }
- +
- + /**
- + * Sets the owner of the backpack being viewed
- + * @param backpackOwnerId
- + */
- + public void setBackpackOwnerId(UUID backpackOwnerId) {
- + this.backpackOwnerId = backpackOwnerId;
- + }
- +
- + /**
- + * Gets the owner of this backpack
- * @return
- */
- public String getBackpackOwner() {
- @@ -3695,7 +3843,7 @@ public class PlayerSession {
- }
- /**
- - * Sets the owner of the backpack being viewed
- + * Sets the owner of this backpack
- * @param backpackOwner
- */
- public void setBackpackOwner(String backpackOwner) {
- @@ -3706,6 +3854,7 @@ public class PlayerSession {
- * Clears the owner of the backpack being viewed
- */
- public void clearBackpackOwner() {
- + backpackOwnerId = null;
- backpackOwner = null;
- }
- //</editor-fold>
- @@ -3800,8 +3949,8 @@ public class PlayerSession {
- ResultSet set = null;
- try {
- - statement = DBManager.prepareStatement("SELECT personalid FROM lot_respawns WHERE lower(name) = ?;");
- - statement.setString(1, username.toLowerCase());
- + statement = DBManager.prepareStatement("SELECT personalid FROM lot_respawns WHERE player_id = ?;");
- + statement.setString(1, playerId.toString());
- set = statement.executeQuery();
- if (set.next()) {
- @@ -3822,8 +3971,8 @@ public class PlayerSession {
- PreparedStatement statement = null;
- try {
- - statement = DBManager.prepareStatement("DELETE FROM lot_respawns WHERE lower(name) = ?;");
- - statement.setString(1, username.toLowerCase());
- + statement = DBManager.prepareStatement("DELETE FROM lot_respawns WHERE player_id = ?;");
- + statement.setString(1, playerId.toString());
- statement.execute();
- } catch (SQLException ex) {
- InnPlugin.logError("Unable to delete respawn lot personal id from database!", ex);
- @@ -3841,13 +3990,13 @@ public class PlayerSession {
- PreparedStatement statement = null;
- try {
- - statement = DBManager.prepareStatement("DELETE FROM lot_respawns WHERE lower(name) = ?;");
- - statement.setString(1, username.toLowerCase());
- + statement = DBManager.prepareStatement("DELETE FROM lot_respawns WHERE player_id = ?;");
- + statement.setString(1, playerId.toString());
- statement.execute();
- DBManager.closePreparedStatement(statement);
- - statement = DBManager.prepareStatement("INSERT INTO lot_respawns VALUES (?, ?);");
- - statement.setString(1, username.toLowerCase());
- + statement = DBManager.prepareStatement("INSERT INTO lot_respawns (player_id, personalid) VALUES (?, ?);");
- + statement.setString(1, playerId.toString());
- statement.setInt(2, respawnLotPersonalId);
- statement.execute();
- } catch (SQLException ex) {
- diff --git a/src/net/innectis/innplugin/Player/Request/Request.java b/src/net/innectis/innplugin/Player/Request/Request.java
- index a1d625d9d..0729e9dc6 100644
- --- a/src/net/innectis/innplugin/Player/Request/Request.java
- +++ b/src/net/innectis/innplugin/Player/Request/Request.java
- @@ -1,7 +1,9 @@
- package net.innectis.innplugin.Player.Request;
- +import java.util.UUID;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.Player.IdpPlayer;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- import net.innectis.innplugin.Player.PlayerSession;
- import net.innectis.innplugin.Tasking.LimitedTask;
- import net.innectis.innplugin.Tasking.RunBehaviour;
- @@ -22,10 +24,14 @@ public abstract class Request {
- protected final Long timeouttime;
- /** The plugin */
- protected final InnPlugin plugin;
- - /** The player that can accept or deny this request */
- + /** The ID of the player */
- + protected final UUID playerId;
- + /** The name of the player */
- protected final String player;
- /** The player that made the request */
- protected final String requester;
- + /** The ID of the requester */
- + protected final UUID requesterId;
- /** The ID of the linked delayed task */
- private long taskid;
- @@ -37,7 +43,9 @@ public abstract class Request {
- this.timeouttime = currentTime + timeout;
- this.plugin = plugin;
- this.player = player.getName();
- + this.playerId = player.getUniqueId();
- this.requester = requester.getName();
- + this.requesterId = requester.getUniqueId();
- this.requestid = generateRequestId();
- startTimeoutTask(timeout);
- }
- @@ -50,6 +58,14 @@ public abstract class Request {
- return plugin.getPlayer(player, true);
- }
- + /**
- + * Gets the ID of the player
- + * @return
- + */
- + public UUID getPlayerId() {
- + return playerId;
- + }
- +
- /**
- * Gets the name of the player who issued the request (uncoloured)
- * @return
- @@ -58,11 +74,19 @@ public abstract class Request {
- return plugin.getPlayer(requester, true);
- }
- + /**
- + * Gets the ID of the requester
- + * @return
- + */
- + public UUID getRequesterId() {
- + return requesterId;
- + }
- +
- /**
- * Starts a task to timeout the request.
- */
- private void startTimeoutTask(Long timeout) {
- - taskid = plugin.getTaskManager().addTask(new RequestTask(timeout, plugin, player, requestid));
- + taskid = plugin.getTaskManager().addTask(new RequestTask(timeout, plugin, playerId, requestid));
- }
- /** Returns the request id */
- @@ -142,14 +166,13 @@ public abstract class Request {
- }
- class RequestTask extends LimitedTask {
- -
- private long requestid;
- private InnPlugin plugin;
- - private String playername;
- + private UUID playerId;
- - public RequestTask(long delay, InnPlugin plugin, String playername, long requestid) {
- + public RequestTask(long delay, InnPlugin plugin, UUID playerId, long requestid) {
- super(RunBehaviour.ASYNC, delay, 1);
- - this.playername = playername;
- + this.playerId = playerId;
- this.plugin = plugin;
- this.requestid = requestid;
- }
- @@ -160,9 +183,10 @@ class RequestTask extends LimitedTask {
- }
- public void run() {
- - if (PlayerSession.hasSession(playername)) {
- - PlayerSession session = PlayerSession.getSession(playername, plugin);
- + if (PlayerSession.hasSession(playerId)) {
- + PlayerSession session = PlayerSession.getSession_(playerId);
- Request req = session.removeRequest(requestid);
- +
- if (req != null) {
- req.onTimeout();
- }
- diff --git a/src/net/innectis/innplugin/Player/Request/TeleportRequest.java b/src/net/innectis/innplugin/Player/Request/TeleportRequest.java
- index 0a283dc69..bfae3a89e 100644
- --- a/src/net/innectis/innplugin/Player/Request/TeleportRequest.java
- +++ b/src/net/innectis/innplugin/Player/Request/TeleportRequest.java
- @@ -76,7 +76,7 @@ public class TeleportRequest extends Request {
- }
- if (tpCost > 0) {
- - TransactionObject transaction = TransactionHandler.getTransactionObject(locRequester.getName());
- + TransactionObject transaction = TransactionHandler.getTransactionObject(locRequester.getUniqueId(), locRequester.getName());
- int balance = transaction.getValue(TransactionType.VALUTAS);
- if (balance < tpCost) {
- @@ -106,7 +106,7 @@ public class TeleportRequest extends Request {
- } else {
- // Give back what was taken from the player previously
- if (tpCost > 0) {
- - TransactionObject transaction = TransactionHandler.getTransactionObject(locRequester.getName());
- + TransactionObject transaction = TransactionHandler.getTransactionObject(locRequester.getUniqueId(), locRequester.getName());
- transaction.addValue(tpCost, TransactionType.VALUTAS);
- locPlayer.printError("You are unable to accept the " + getDiscription());
- locRequester.printError(locPlayer.getName() + " was unable to accept your teleport request.");
- diff --git a/src/net/innectis/innplugin/Player/TinyWE/BlockBag.java b/src/net/innectis/innplugin/Player/TinyWE/BlockBag.java
- index 007d40b0b..956a9712b 100644
- --- a/src/net/innectis/innplugin/Player/TinyWE/BlockBag.java
- +++ b/src/net/innectis/innplugin/Player/TinyWE/BlockBag.java
- @@ -18,6 +18,8 @@ import net.innectis.innplugin.OwnedObjects.InnectisBookcase;
- import net.innectis.innplugin.OwnedObjects.InnectisLot;
- import net.innectis.innplugin.Player.IdpPlayer;
- import net.innectis.innplugin.Player.Permission;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Player.TinyWE.BlockCounters.*;
- import net.innectis.innplugin.Player.TinyWE.BlockCounters.BlockCounterFactory.CountType;
- import net.innectis.innplugin.Player.TinyWE.IdpEditSession.SpecialItemHandleResult;
- @@ -129,7 +131,6 @@ public class BlockBag {
- sortBlocks(blocks);
- IdpPlayer player = session.getPlayer();
- - String playername = player.getName();
- for (Block block : blocks) {
- // Max blocks checked
- @@ -170,7 +171,7 @@ public class BlockBag {
- Location loc = block.getLocation();
- // Log the action when success!
- - LogManager.getBlockLogger().logBlockAction(playername, mat, loc, BlockAction.WE_ACTION);
- + LogManager.getBlockLogger().logBlockAction(player.getUniqueId(), mat, loc, BlockAction.WE_ACTION);
- break;
- }
- } catch (TWEActionNotFinishedException twex) {
- @@ -211,7 +212,8 @@ public class BlockBag {
- switch (toMaterial) {
- case LOCKED: // Lock the block.
- - if (BlockLockHandler.lockBlock(session.getPlayer(), loc)) {
- + if (BlockLockHandler.lockBlock(session.getPlayer().getUniqueId(), loc)) {
- +
- return 1;
- } else {
- return 0;
- diff --git a/src/net/innectis/innplugin/Player/TinyWE/IdpEditSession.java b/src/net/innectis/innplugin/Player/TinyWE/IdpEditSession.java
- index e21abd6e6..6832c050a 100644
- --- a/src/net/innectis/innplugin/Player/TinyWE/IdpEditSession.java
- +++ b/src/net/innectis/innplugin/Player/TinyWE/IdpEditSession.java
- @@ -1,6 +1,7 @@
- package net.innectis.innplugin.Player.TinyWE;
- import java.lang.ref.WeakReference;
- +import java.util.UUID;
- import net.innectis.innplugin.Configuration;
- import net.innectis.innplugin.Handlers.BlockHandler;
- import net.innectis.innplugin.InnPlugin;
- @@ -38,16 +39,16 @@ public class IdpEditSession {
- SPECIAL_HANDLED;
- }
- - private String _playername;
- + private UUID playerId;
- private WeakReference<IdpPlayer> _player;
- /**
- * Create a new editsession
- *
- - * @param player
- + * @param playerId
- */
- - public IdpEditSession(String player) {
- - _playername = player;
- + public IdpEditSession(UUID playerId) {
- + this.playerId = playerId;
- // load the player
- fetchPlayer();
- }
- @@ -59,7 +60,7 @@ public class IdpEditSession {
- * @see IdpEditSession::getPlayer()
- */
- private void fetchPlayer() {
- - IdpPlayer player = InnPlugin.getPlugin().getPlayer(_playername, true);
- + IdpPlayer player = InnPlugin.getPlugin().getPlayer(playerId);
- _player = new WeakReference<IdpPlayer>(player);
- }
- diff --git a/src/net/innectis/innplugin/Player/Tools/EditSignTool.java b/src/net/innectis/innplugin/Player/Tools/EditSignTool.java
- index fc380a7b5..732ce3e89 100644
- --- a/src/net/innectis/innplugin/Player/Tools/EditSignTool.java
- +++ b/src/net/innectis/innplugin/Player/Tools/EditSignTool.java
- @@ -53,7 +53,7 @@ public class EditSignTool extends Tool {
- InnectisLot lot = LotHandler.getLot(block.getLocation(), true);
- - if (lot == null || lot.canPlayerAccess(player)
- + if (lot == null || lot.canPlayerAccess(player.getName())
- || player.hasPermission(Permission.special_edit_any_sign)) {
- Sign sign = (Sign) block.getState();
- Location loc = sign.getLocation();
- diff --git a/src/net/innectis/innplugin/Shop/ChestShop.java b/src/net/innectis/innplugin/Shop/ChestShop.java
- index 293e33370..fefc410aa 100644
- --- a/src/net/innectis/innplugin/Shop/ChestShop.java
- +++ b/src/net/innectis/innplugin/Shop/ChestShop.java
- @@ -3,8 +3,8 @@ package net.innectis.innplugin.Shop;
- import net.innectis.innplugin.Handlers.TransactionHandler;
- import net.innectis.innplugin.Handlers.TransactionHandler.TransactionType;
- import net.innectis.innplugin.InnPlugin;
- -import net.innectis.innplugin.Inventory.IdpContainer;
- import net.innectis.innplugin.InnectisObjects.TransactionObject;
- +import net.innectis.innplugin.Inventory.IdpContainer;
- import net.innectis.innplugin.Items.IdpItem;
- import net.innectis.innplugin.Items.IdpItemStack;
- import net.innectis.innplugin.Items.IdpMaterial;
- @@ -12,6 +12,7 @@ import net.innectis.innplugin.Loggers.LogManager;
- import net.innectis.innplugin.OwnedObjects.InnectisChest;
- import net.innectis.innplugin.Player.IdpPlayer;
- import net.innectis.innplugin.Player.IdpPlayerInventory;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- import net.innectis.innplugin.Player.PlayerSettings;
- import net.innectis.innplugin.SignSystem.ChestShopSign;
- import net.innectis.innplugin.SignSystem.ChestShopSign.ChestShopType;
- @@ -38,6 +39,7 @@ public final class ChestShop {
- public void processTransaction() {
- Chest bukkitChest = innChest.getChest1Chest();
- boolean buyShop = (chestSign.getShopType() == ChestShopType.BUY);
- + PlayerCredentials credentials = innChest.getOwnerCredentials();
- IdpContainer senderContainer = null;
- IdpContainer receiverContainer = null;
- @@ -47,16 +49,16 @@ public final class ChestShop {
- if (buyShop) {
- senderContainer = new IdpContainer(customer.getInventory());
- - transactionSender = TransactionHandler.getTransactionObject(innChest.getOwner());
- + transactionSender = TransactionHandler.getTransactionObject(credentials.getUniqueId(), credentials.getName());
- receiverContainer = new IdpContainer(bukkitChest.getInventory());
- - transactionReceiver = TransactionHandler.getTransactionObject(customer.getName());
- + transactionReceiver = TransactionHandler.getTransactionObject(customer.getUniqueId(), customer.getName());
- } else {
- senderContainer = new IdpContainer(bukkitChest.getInventory());
- - transactionSender = TransactionHandler.getTransactionObject(customer.getName());
- + transactionSender = TransactionHandler.getTransactionObject(customer.getUniqueId(), customer.getName());
- receiverContainer = new IdpContainer(customer.getInventory());
- - transactionReceiver = TransactionHandler.getTransactionObject(innChest.getOwner());
- + transactionReceiver = TransactionHandler.getTransactionObject(credentials.getUniqueId(), credentials.getName());
- }
- IdpItem item = new IdpItem(chestSign.getMaterial());
- diff --git a/src/net/innectis/innplugin/Shop/ShopHandler.java b/src/net/innectis/innplugin/Shop/ShopHandler.java
- index b7a7caed9..eb6e1306a 100644
- --- a/src/net/innectis/innplugin/Shop/ShopHandler.java
- +++ b/src/net/innectis/innplugin/Shop/ShopHandler.java
- @@ -15,7 +15,6 @@ import net.innectis.innplugin.Loggers.LogManager;
- import net.innectis.innplugin.Player.Chat.ChatColor;
- import net.innectis.innplugin.Player.IdpPlayer;
- import net.innectis.innplugin.Player.IdpPlayerInventory;
- -import net.innectis.innplugin.Utility.NumberUtil;
- import org.bukkit.event.inventory.InventoryClickEvent;
- import org.bukkit.inventory.Inventory;
- @@ -164,7 +163,7 @@ public final class ShopHandler {
- inv.setItem(i, (content[i] != null ? content[i].toBukkitItemstack() : null));
- }
- } else {
- - TransactionObject transaction = TransactionHandler.getTransactionObject(player.getName());
- + TransactionObject transaction = TransactionHandler.getTransactionObject(player.getUniqueId(), player.getName());
- IdpPlayerInventory playerInventory = player.getInventory();
- IdpContainer container = new IdpContainer(playerInventory);
- diff --git a/src/net/innectis/innplugin/Tasking/AsyncTasks/MessageTask.java b/src/net/innectis/innplugin/Tasking/AsyncTasks/MessageTask.java
- index f4214bb67..3205f1101 100644
- --- a/src/net/innectis/innplugin/Tasking/AsyncTasks/MessageTask.java
- +++ b/src/net/innectis/innplugin/Tasking/AsyncTasks/MessageTask.java
- @@ -72,8 +72,8 @@ public class MessageTask extends RepeatingTask {
- ResultSet result = null;
- try {
- - statement = DBManager.prepareStatement("SELECT timestamp FROM vote_log WHERE username = ?");
- - statement.setString(1, player.getName());
- + statement = DBManager.prepareStatement("SELECT timestamp FROM vote_log WHERE player_id = ?;");
- + statement.setString(1, player.getUniqueId().toString());
- result = statement.executeQuery();
- // More than 20 hours since last vote, then display message.
- diff --git a/src/net/innectis/innplugin/Tasking/SyncTasks/PlayerInfoTask.java b/src/net/innectis/innplugin/Tasking/SyncTasks/PlayerInfoTask.java
- index 7a33cc52e..4d65401af 100644
- --- a/src/net/innectis/innplugin/Tasking/SyncTasks/PlayerInfoTask.java
- +++ b/src/net/innectis/innplugin/Tasking/SyncTasks/PlayerInfoTask.java
- @@ -3,11 +3,14 @@ package net.innectis.innplugin.Tasking.SyncTasks;
- import java.sql.Timestamp;
- import net.innectis.innplugin.BanSystem.BanHandler;
- import net.innectis.innplugin.BanSystem.UserBanObject;
- +import net.innectis.innplugin.Configuration;
- import net.innectis.innplugin.External.API.Interfaces.INoCheatPlusIDP;
- import net.innectis.innplugin.External.LibraryType;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.Player.Chat.ChatColor;
- import net.innectis.innplugin.Player.IdpPlayer;
- +import net.innectis.innplugin.Player.PlayerCredentials;
- +import net.innectis.innplugin.Player.PlayerCredentialsManager;
- import net.innectis.innplugin.Tasking.DefaultTaskDelays;
- import net.innectis.innplugin.Tasking.RepeatingTask;
- import net.innectis.innplugin.Tasking.RunBehaviour;
- @@ -39,8 +42,10 @@ public class PlayerInfoTask extends RepeatingTask {
- String[] noCheatBanned = noCheatPlus.getBannedPlayers();
- if (noCheatBanned != null) {
- for (String banned : noCheatBanned) {
- - BanHandler.addBan(new UserBanObject(banned, "Elena", new Timestamp(System.currentTimeMillis()), 21600000, false));
- - InnPlugin.getPlugin().broadCastMessage(ChatColor.RED, String.format("Player %s has been banned for 6 hours by Elena!", banned));
- + PlayerCredentials credentials = PlayerCredentialsManager.getByName(banned);
- +
- + BanHandler.addBan(new UserBanObject(credentials, Configuration.SERVER_GENERATED_CREDENTIALS, new Timestamp(System.currentTimeMillis()), 21600000, false));
- + InnPlugin.getPlugin().broadCastMessage(ChatColor.RED, String.format("Player %s has been banned for 6 hours by the console!", banned));
- }
- noCheatPlus.clearBannedPlayers();
- }
- diff --git a/src/net/innectis/innplugin/Tasking/SyncTasks/ValutaBankTransactionTask.java b/src/net/innectis/innplugin/Tasking/SyncTasks/ValutaBankTransactionTask.java
- index 692f2bb11..f1e317360 100644
- --- a/src/net/innectis/innplugin/Tasking/SyncTasks/ValutaBankTransactionTask.java
- +++ b/src/net/innectis/innplugin/Tasking/SyncTasks/ValutaBankTransactionTask.java
- @@ -1,15 +1,14 @@
- package net.innectis.innplugin.Tasking.SyncTasks;
- +import java.util.UUID;
- import net.innectis.innplugin.Handlers.TransactionHandler;
- import net.innectis.innplugin.Handlers.TransactionHandler.TransactionType;
- import net.innectis.innplugin.InnPlugin;
- import net.innectis.innplugin.InnectisObjects.TransactionObject;
- -import net.innectis.innplugin.Player.Chat.ChatColor;
- import net.innectis.innplugin.Player.IdpPlayer;
- import net.innectis.innplugin.Player.PlayerSession;
- import net.innectis.innplugin.Tasking.LimitedTask;
- import net.innectis.innplugin.Tasking.RunBehaviour;
- -import net.innectis.innplugin.Utility.NumberUtil;
- /**
- * A task to handle money going in or out of a player's bank
- @@ -17,16 +16,18 @@ import net.innectis.innplugin.Utility.NumberUtil;
- * @author AlphaBlend
- */
- public class ValutaBankTransactionTask extends LimitedTask {
- - private String username;
- + private UUID playerId;
- + private String playerName;
- - public ValutaBankTransactionTask(String username, long time) {
- + public ValutaBankTransactionTask(UUID playerId, String playerName, long time) {
- super(RunBehaviour.SYNCED, time, 1);
- - this.username = username;
- + this.playerId = playerId;
- + this.playerName = playerName;
- }
- @Override
- public void run() {
- - IdpPlayer player = InnPlugin.getPlugin().getPlayer(username);
- + IdpPlayer player = InnPlugin.getPlugin().getPlayer(playerId);
- if (player != null) {
- PlayerSession session = player.getSession();
- @@ -34,7 +35,7 @@ public class ValutaBankTransactionTask extends LimitedTask {
- session.setLastBankTaskTime(0);
- }
- - TransactionObject transaction = TransactionHandler.getTransactionObject(username);
- + TransactionObject transaction = TransactionHandler.getTransactionObject(playerId, playerName);
- int valutasToPlayer = transaction.getValue(TransactionType.VALUTAS_TO_PLAYER);
- if (valutasToPlayer > 0) {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement