Fix various synchronization issues and make community creation load the new community through redis instead of a database call
This commit is contained in:
parent
66c6f66768
commit
286a9fe246
@ -1,8 +1,8 @@
|
||||
package mineplex.core.communities;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -15,8 +15,8 @@ public class Community
|
||||
private final int _id;
|
||||
private String _name;
|
||||
private String _description;
|
||||
private Map<UUID, CommunityMemberInfo> _members = new HashMap<>();
|
||||
private Map<UUID, CommunityJoinRequestInfo> _joinRequests = new HashMap<>();
|
||||
private Map<UUID, CommunityMemberInfo> _members = new ConcurrentHashMap<>();
|
||||
private Map<UUID, CommunityJoinRequestInfo> _joinRequests = new ConcurrentHashMap<>();
|
||||
private ChatColor[] _chatFormat;
|
||||
private long _chatDelay;
|
||||
private GameDisplay _favoriteGame;
|
||||
|
@ -3,6 +3,7 @@ package mineplex.core.communities;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -20,8 +21,6 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import mineplex.core.Managers;
|
||||
import mineplex.core.MiniDbClientPlugin;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
@ -87,7 +86,7 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
||||
private ServerRepository _serverRepo;
|
||||
private boolean _us;
|
||||
|
||||
private boolean _cycling = false;
|
||||
private volatile boolean _cycling = false;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public CommunityManager(JavaPlugin plugin, CoreClientManager clientManager)
|
||||
@ -204,15 +203,10 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
||||
_cycling = true;
|
||||
runAsync(() ->
|
||||
{
|
||||
final List<Integer> resultant = Lists.newArrayList();
|
||||
final List<Integer> ids = new LinkedList<>();
|
||||
_loadedCommunities.values().stream().filter(c -> c.getMembers().size() >= 5 && c.getPrivacySetting() != PrivacySetting.PRIVATE).forEach(c -> resultant.add(c.getId()));
|
||||
_loadedCommunities.values().stream().filter(c -> c.getMembers().size() >= 5 && c.getPrivacySetting() != PrivacySetting.PRIVATE).forEach(c -> ids.add(c.getId()));
|
||||
|
||||
Random random = new Random();
|
||||
while (!resultant.isEmpty())
|
||||
{
|
||||
ids.add(resultant.remove(random.nextInt(resultant.size())));
|
||||
}
|
||||
Collections.shuffle(ids);
|
||||
|
||||
runSync(() ->
|
||||
{
|
||||
@ -321,7 +315,7 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
||||
if (Bukkit.getPlayer(playerUUID) != null)
|
||||
{
|
||||
Get(Bukkit.getPlayer(playerUUID)).joinCommunity(community);
|
||||
Get(Bukkit.getPlayer(playerUUID)).Invites.remove(community.getId());
|
||||
runSync(() -> Get(Bukkit.getPlayer(playerUUID)).Invites.remove(community.getId()));
|
||||
}
|
||||
|
||||
community.message(F.main(getName(), F.name(playerName) + " has joined " + F.name(community.getName()) + "!"));
|
||||
@ -341,6 +335,8 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
||||
{
|
||||
return;
|
||||
}
|
||||
runSync(() ->
|
||||
{
|
||||
if (Bukkit.getPlayer(targetUUID) != null)
|
||||
{
|
||||
if (!Get(Bukkit.getPlayer(targetUUID)).Invites.contains(community.getId()))
|
||||
@ -354,6 +350,7 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
||||
UtilServer.CallEvent(new CommunityMemberDataUpdateEvent(Bukkit.getPlayer(targetUUID)));
|
||||
}
|
||||
}
|
||||
});
|
||||
community.message(F.main(getName(), F.name(sender) + " has invited " + F.name(targetName) + " to " + F.name(community.getName()) + "!"), CommunityRole.COLEADER);
|
||||
}
|
||||
|
||||
@ -364,6 +361,8 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
||||
{
|
||||
return;
|
||||
}
|
||||
runSync(() ->
|
||||
{
|
||||
if (Bukkit.getPlayer(targetUUID) != null)
|
||||
{
|
||||
Get(Bukkit.getPlayer(targetUUID)).Invites.remove(community.getId());
|
||||
@ -373,6 +372,7 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
||||
}
|
||||
UtilServer.CallEvent(new CommunityMemberDataUpdateEvent(Bukkit.getPlayer(targetUUID)));
|
||||
}
|
||||
});
|
||||
if (announce)
|
||||
{
|
||||
community.message(F.main(getName(), F.name(targetName) + "'s invitation to join " + F.name(community.getName()) + " has been revoked by " + F.name(sender) + "!"), CommunityRole.COLEADER);
|
||||
@ -416,11 +416,12 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
||||
UtilServer.CallEvent(new CommunityJoinRequestsUpdateEvent(community));
|
||||
}
|
||||
|
||||
public void handleCommunityCreation(Integer id, UUID leaderUUID)
|
||||
public void handleCommunityCreation(Integer id, String name, Integer leaderId, UUID leaderUUID, String leaderName)
|
||||
{
|
||||
runAsync(() ->
|
||||
{
|
||||
_repo.loadCommunity(id, _loadedCommunities);
|
||||
_loadedCommunities.put(id, new Community(id, name));
|
||||
_loadedCommunities.get(id).getMembers().put(leaderUUID, new CommunityMemberInfo(leaderName, leaderUUID, leaderId, CommunityRole.LEADER, System.currentTimeMillis()));
|
||||
runSync(() ->
|
||||
{
|
||||
Community community = _loadedCommunities.get(id);
|
||||
@ -443,7 +444,10 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
||||
}
|
||||
community.message(F.main(getName(), F.name(senderName) + " has disbanded community " + F.name(community.getName()) + "!"));
|
||||
UtilServer.CallEvent(new CommunityDisbandEvent(community));
|
||||
runSync(() ->
|
||||
{
|
||||
UtilServer.GetPlayers().stream().filter(player -> Get(player).Invites.contains(community.getId())).forEach(player -> Get(player).Invites.remove(community.getId()));
|
||||
});
|
||||
community.getMembers().keySet().stream().filter(uuid -> Bukkit.getPlayer(uuid) != null).forEach(uuid -> Get(Bukkit.getPlayer(uuid)).leaveCommunity(community));
|
||||
_loadedCommunities.remove(community.getId());
|
||||
runSync(() ->
|
||||
@ -514,7 +518,7 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
||||
}
|
||||
else
|
||||
{
|
||||
UtilPlayer.message(sender, F.main(getName(), "Either " + F.name(target) + " does not exist or you have already invited them to " + F.name(community.getName()) + "!"));
|
||||
UtilPlayer.message(sender, F.main(getName(), F.name(target) + " does not exist!"));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -645,7 +649,7 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
||||
new CommunityUpdateMemberRole(community.getId(), sender.getName(), info.UUID.toString(), role.toString()).publish();
|
||||
}
|
||||
|
||||
public void handleCreate(Player sender, int accountId, String name)
|
||||
public void handleCreate(Player sender, String senderName, int accountId, String name)
|
||||
{
|
||||
if (_creating.contains(sender.getUniqueId()))
|
||||
{
|
||||
@ -664,7 +668,7 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
||||
}
|
||||
else
|
||||
{
|
||||
new CommunityCreate(sender.getUniqueId().toString(), id).publish();
|
||||
new CommunityCreate(sender.getUniqueId().toString(), senderName, accountId, id, name).publish();
|
||||
runSync(() -> _creating.remove(sender.getUniqueId()));
|
||||
}
|
||||
});
|
||||
|
@ -1,15 +1,15 @@
|
||||
package mineplex.core.communities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import mineplex.core.Managers;
|
||||
|
||||
public class CommunityMemberData
|
||||
{
|
||||
private final Map<Integer, CommunityRole> _communities = new HashMap<>();
|
||||
private final Map<Integer, CommunityRole> _communities = new ConcurrentHashMap<>();
|
||||
|
||||
public final List<Integer> Invites = new ArrayList<>();
|
||||
|
||||
|
@ -51,16 +51,17 @@ public class CommunityCreateCommand extends CommandBase<CommunityManager>
|
||||
UtilPlayer.message(caller, F.main(Plugin.getName(), "That name is not allowed!"));
|
||||
return;
|
||||
}
|
||||
final int accountId = Managers.get(CoreClientManager.class).getAccountId(caller);
|
||||
final String senderName = Managers.get(CoreClientManager.class).Get(caller).getName();
|
||||
Plugin.runAsync(() ->
|
||||
{
|
||||
int accountId = Managers.get(CoreClientManager.class).getAccountId(caller);
|
||||
if (Managers.get(Chat.class).getFilteredMessage(caller, args[0]).contains("*"))
|
||||
{
|
||||
UtilPlayer.message(caller, F.main(Plugin.getName(), "That name is not allowed!"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Plugin.runSync(() -> Plugin.handleCreate(caller, accountId, args[0]));
|
||||
Plugin.runSync(() -> Plugin.handleCreate(caller, senderName, accountId, args[0]));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -5,12 +5,18 @@ import mineplex.serverdata.commands.ServerCommand;
|
||||
public class CommunityCreate extends ServerCommand
|
||||
{
|
||||
private String _leaderUUID;
|
||||
private String _leaderName;
|
||||
private Integer _leaderId;
|
||||
private Integer _communityId;
|
||||
private String _communityName;
|
||||
|
||||
public CommunityCreate(String leaderUUID, Integer communityId)
|
||||
public CommunityCreate(String leaderUUID, String leaderName, Integer leaderId, Integer communityId, String communityName)
|
||||
{
|
||||
_leaderUUID = leaderUUID;
|
||||
_leaderName = leaderName;
|
||||
_leaderId = leaderId;
|
||||
_communityId = communityId;
|
||||
_communityName = communityName;
|
||||
}
|
||||
|
||||
public String getLeaderUUID()
|
||||
@ -18,8 +24,23 @@ public class CommunityCreate extends ServerCommand
|
||||
return _leaderUUID;
|
||||
}
|
||||
|
||||
public String getLeaderName()
|
||||
{
|
||||
return _leaderName;
|
||||
}
|
||||
|
||||
public Integer getLeaderId()
|
||||
{
|
||||
return _leaderId;
|
||||
}
|
||||
|
||||
public Integer getCommunityId()
|
||||
{
|
||||
return _communityId;
|
||||
}
|
||||
|
||||
public String getCommunityName()
|
||||
{
|
||||
return _communityName;
|
||||
}
|
||||
}
|
@ -23,8 +23,11 @@ public class CommunityCreateHandler implements CommandCallback
|
||||
CommunityCreate update = ((CommunityCreate) command);
|
||||
UUID leaderUUID = UUID.fromString(update.getLeaderUUID());
|
||||
Integer communityId = update.getCommunityId();
|
||||
String communityName = update.getCommunityName();
|
||||
Integer leaderId = update.getLeaderId();
|
||||
String leaderName = update.getLeaderName();
|
||||
|
||||
_manager.handleCommunityCreation(communityId, leaderUUID);
|
||||
_manager.handleCommunityCreation(communityId, communityName, leaderId, leaderUUID, leaderName);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user