diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerTracker/PlayerTracker.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerTracker/PlayerTracker.java index aa387b0a8..923f627a0 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerTracker/PlayerTracker.java +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerTracker/PlayerTracker.java @@ -60,7 +60,7 @@ public class PlayerTracker implements Listener { public void run() { - PlayerStatus snapshot = new PlayerStatus(event.getPlayer().getUniqueId().toString(), event.getPlayer().getName(), event.getServer().getInfo().getName()); + PlayerStatus snapshot = new PlayerStatus(event.getPlayer().getUniqueId(), event.getPlayer().getName(), event.getServer().getInfo().getName()); _repository.addElement(snapshot, DEFAULT_STATUS_TIMEOUT); } }); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityManager.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityManager.java index 236b94fbd..c465a7ce8 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityManager.java @@ -85,6 +85,8 @@ public class CommunityManager extends MiniDbClientPlugin private volatile boolean _cycling = false; + private volatile boolean _updateJoinRequests = false; + @SuppressWarnings("deprecation") public CommunityManager(JavaPlugin plugin, CoreClientManager clientManager) { @@ -140,6 +142,11 @@ public class CommunityManager extends MiniDbClientPlugin LinkedList communities = new LinkedList<>(); _loadedCommunities.values().forEach(community -> communities.add(community)); _repo.updateMembers(communities); + if (_updateJoinRequests) + { + _repo.updateJoinRequests(communities); + } + _updateJoinRequests = !_updateJoinRequests; }, 0L, 20 * 7); Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> diff --git a/Plugins/Mineplex.Core/src/mineplex/core/communities/storage/CommunityRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/storage/CommunityRepository.java index 4801bebb0..6b814c0c9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/communities/storage/CommunityRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/communities/storage/CommunityRepository.java @@ -220,7 +220,7 @@ public class CommunityRepository extends MinecraftRepository online = true; server = status.getServer(); info.update(System.currentTimeMillis(), online, server); - if (!info.Name.equalsIgnoreCase(status.getName())) + if (!info.Name.equals(status.getName())) { info.updateName(status.getName()); } @@ -236,6 +236,28 @@ public class CommunityRepository extends MinecraftRepository } } + public void updateJoinRequests(LinkedList communities) + { + if (communities.isEmpty()) + { + return; + } + for (Community c : communities) + { + for (CommunityJoinRequestInfo info : c.getJoinRequests().values()) + { + PlayerStatus status = _repo.getElement(info.UUID.toString()); + if (status != null) + { + if (!info.Name.equals(status.getName())) + { + info.update(status.getName()); + } + } + } + } + } + public void loadInvites(int accountId, List invites) { executeQuery("SELECT ci.communityId, c.region FROM communityInvites AS ci INNER JOIN communities AS c ON c.id=ci.communityId WHERE accountId=?;", resultSet -> diff --git a/Plugins/Mineplex.Core/src/mineplex/core/disguise/playerdisguise/PlayerDisguiseManager.java b/Plugins/Mineplex.Core/src/mineplex/core/disguise/playerdisguise/PlayerDisguiseManager.java index 20beec367..fd1b44c80 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/disguise/playerdisguise/PlayerDisguiseManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/disguise/playerdisguise/PlayerDisguiseManager.java @@ -392,8 +392,8 @@ public class PlayerDisguiseManager extends MiniPlugin implements IPacketHandler CoreClient client = getClientManager().Get(caller); client.undisguise(); - require(FriendManager.class).updatePlayerStatus(disguisedProfile.getId().toString(), null); - require(FriendManager.class).updatePlayerStatus(originalProfile.getId().toString(), new PlayerStatus(originalProfile.getId().toString(), originalProfile.getName(), _serverName)); + require(FriendManager.class).updatePlayerStatus(disguisedProfile.getId(), null); + require(FriendManager.class).updatePlayerStatus(originalProfile.getId(), new PlayerStatus(originalProfile.getId(), originalProfile.getName(), _serverName)); getPreferencesManager().handlePlayerJoin(caller, true); require(ScoreboardManager.class).handlePlayerJoin(disguise.getOriginalProfile().getName()); @@ -539,8 +539,8 @@ public class PlayerDisguiseManager extends MiniPlugin implements IPacketHandler callerProfile.getProperties().removeAll(ORIGINAL_UUID_KEY); callerProfile.getProperties().put(ORIGINAL_UUID_KEY, new Property(ORIGINAL_UUID_KEY, caller.getUniqueId().toString())); - require(FriendManager.class).updatePlayerStatus(disguisePlayer.getOriginalProfile().getId().toString(), null); - require(FriendManager.class).updatePlayerStatus(disguisePlayer.getProfile().getId().toString(), new PlayerStatus(disguisePlayer.getProfile().getId().toString(), requestedUsername, _serverName)); + require(FriendManager.class).updatePlayerStatus(disguisePlayer.getOriginalProfile().getId(), null); + require(FriendManager.class).updatePlayerStatus(disguisePlayer.getProfile().getId(), new PlayerStatus(disguisePlayer.getProfile().getId(), requestedUsername, _serverName)); getPreferencesManager().handlePlayerJoin(caller, true); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/FriendManager.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/FriendManager.java index d48fcea85..32effd24c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/friend/FriendManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/FriendManager.java @@ -1,5 +1,19 @@ package mineplex.core.friend; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.plugin.java.JavaPlugin; + import mineplex.core.MiniDbClientPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.common.Rank; @@ -22,19 +36,6 @@ import mineplex.core.preferences.PreferencesManager; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.serverdata.data.PlayerStatus; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.plugin.java.JavaPlugin; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.UUID; public class FriendManager extends MiniDbClientPlugin { @@ -402,12 +403,12 @@ public class FriendManager extends MiniDbClientPlugin } - public void updatePlayerStatus(String playerUUID, PlayerStatus status) + public void updatePlayerStatus(UUID playerUUID, PlayerStatus status) { _repository.updatePlayerStatus(playerUUID, status); } - public PlayerStatus getStatus(String playerUUID) + public PlayerStatus getStatus(UUID playerUUID) { return _repository.getStatus(playerUUID); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendRepository.java index 91f165215..12432b50e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendRepository.java @@ -7,6 +7,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.UUID; import mineplex.core.database.MinecraftRepository; import org.bukkit.entity.Player; @@ -95,7 +96,7 @@ public class FriendRepository extends MinecraftRepository friend.Name = resultSet.getString(2); friend.Status = Enum.valueOf(FriendStatusType.class, resultSet.getString(3)); friend.LastSeenOnline = resultSet.getTimestamp(5).getTime() - resultSet.getTimestamp(4).getTime(); - friend.UUID = resultSet.getString(6); + friend.UUID = UUID.fromString(resultSet.getString(6)); if (!friends.containsKey(uuidSource)) friends.put(uuidSource, new FriendData()); @@ -127,7 +128,7 @@ public class FriendRepository extends MinecraftRepository friend.Name = resultSet.getString(1); friend.Status = Enum.valueOf(FriendStatusType.class, resultSet.getString(2)); friend.LastSeenOnline = resultSet.getTimestamp(4).getTime() - resultSet.getTimestamp(3).getTime(); - friend.UUID = resultSet.getString(5); + friend.UUID = UUID.fromString(resultSet.getString(5)); friend.ServerName = null; friend.Online = (friend.ServerName != null); friendData.getFriends().add(friend); @@ -146,17 +147,17 @@ public class FriendRepository extends MinecraftRepository public void loadFriendStatuses(FriendData friendData) { // Generate a set of all friend names - Set friendUUIDS = new HashSet(); + Set friendUUIDS = new HashSet<>(); for(FriendStatus status : friendData.getFriends()) { - friendUUIDS.add(status.UUID); + friendUUIDS.add(status.UUID.toString()); } // Load PlayerStatus' for friends Collection statuses = _repository.getElements(friendUUIDS); // Load player statuses into a mapping - Map playerStatuses = new HashMap(); + Map playerStatuses = new HashMap<>(); for(PlayerStatus status : statuses) { playerStatuses.put(status.getUUID(), status); @@ -176,14 +177,14 @@ public class FriendRepository extends MinecraftRepository * @return the name that the player matching {@code playerName} * is currently online on, if they are online, null otherwise. */ - public String fetchPlayerServer(String playerUUID) + public String fetchPlayerServer(UUID playerUUID) { - PlayerStatus status = _repository.getElement(playerUUID); + PlayerStatus status = _repository.getElement(playerUUID.toString()); return (status == null) ? null : status.getServer(); } - public void updatePlayerStatus(String playerUUID, PlayerStatus status) + public void updatePlayerStatus(UUID playerUUID, PlayerStatus status) { if (status != null) { @@ -191,12 +192,12 @@ public class FriendRepository extends MinecraftRepository } else { - _repository.removeElement(playerUUID); + _repository.removeElement(playerUUID.toString()); } } - public PlayerStatus getStatus(String playerUUID) + public PlayerStatus getStatus(UUID playerUUID) { - return _repository.getElement(playerUUID); + return _repository.getElement(playerUUID.toString()); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendStatus.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendStatus.java index cabc1c7f7..fa5f10870 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendStatus.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendStatus.java @@ -1,11 +1,13 @@ package mineplex.core.friend.data; +import java.util.UUID; + import mineplex.core.friend.FriendStatusType; public class FriendStatus { public String Name; - public String UUID; + public UUID UUID; public String ServerName; public boolean Online; /** diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/data/PlayerStatus.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/data/PlayerStatus.java index 44039f23b..ee9eb3eca 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/data/PlayerStatus.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/data/PlayerStatus.java @@ -1,12 +1,12 @@ package mineplex.serverdata.data; -import mineplex.serverdata.data.Data; +import java.util.UUID; public class PlayerStatus implements Data { // The uuid of this player. - private String _uuid; - public String getUUID() { return _uuid; } + private UUID _uuid; + public UUID getUUID() { return _uuid; } // The name of this player. private String _name; @@ -21,7 +21,7 @@ public class PlayerStatus implements Data * @param name * @param server */ - public PlayerStatus(String uuid, String name, String server) + public PlayerStatus(UUID uuid, String name, String server) { _uuid = uuid; _name = name; @@ -33,6 +33,6 @@ public class PlayerStatus implements Data */ public String getDataId() { - return _uuid; + return _uuid.toString(); } } \ No newline at end of file