Use UUID object instead of String for PlayerStatus and FriendStatus, as well as update CommunityJoinRequestInfo on a task
This commit is contained in:
parent
74a6071d4e
commit
35a9eabf74
@ -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);
|
||||
}
|
||||
});
|
||||
|
@ -85,6 +85,8 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
||||
|
||||
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<CommunityMemberData>
|
||||
LinkedList<Community> 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, () ->
|
||||
|
@ -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<Community> 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<Integer> invites)
|
||||
{
|
||||
executeQuery("SELECT ci.communityId, c.region FROM communityInvites AS ci INNER JOIN communities AS c ON c.id=ci.communityId WHERE accountId=?;", resultSet ->
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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<FriendData>
|
||||
{
|
||||
@ -402,12 +403,12 @@ public class FriendManager extends MiniDbClientPlugin<FriendData>
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -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<String> friendUUIDS = new HashSet<String>();
|
||||
Set<String> friendUUIDS = new HashSet<>();
|
||||
for(FriendStatus status : friendData.getFriends())
|
||||
{
|
||||
friendUUIDS.add(status.UUID);
|
||||
friendUUIDS.add(status.UUID.toString());
|
||||
}
|
||||
|
||||
// Load PlayerStatus' for friends
|
||||
Collection<PlayerStatus> statuses = _repository.getElements(friendUUIDS);
|
||||
|
||||
// Load player statuses into a mapping
|
||||
Map<String, PlayerStatus> playerStatuses = new HashMap<String, PlayerStatus>();
|
||||
Map<UUID, PlayerStatus> 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());
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
/**
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user