Fix browser player counts and interaction

This commit is contained in:
Dan Mulloy 2018-06-19 21:22:47 -04:00 committed by Alexander Meech
parent 3786cb480d
commit 73674d56f7
5 changed files with 67 additions and 27 deletions

View File

@ -82,6 +82,7 @@ import mineplex.core.preferences.Preference;
import mineplex.core.preferences.PreferencesManager; import mineplex.core.preferences.PreferencesManager;
import mineplex.core.recharge.Recharge; import mineplex.core.recharge.Recharge;
import mineplex.core.serverConfig.ServerConfiguration; import mineplex.core.serverConfig.ServerConfiguration;
import mineplex.core.treasure.animation.animations.reward.CommonRewardAnimation;
import mineplex.serverdata.Region; import mineplex.serverdata.Region;
import mineplex.serverdata.commands.ServerCommandManager; import mineplex.serverdata.commands.ServerCommandManager;
import mineplex.serverdata.data.PlayerStatus; import mineplex.serverdata.data.PlayerStatus;
@ -165,7 +166,7 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
return _prefManager; return _prefManager;
} }
private CustomDataManager getCustomDataManager() public CustomDataManager getCustomDataManager()
{ {
if (_customDataManager == null) if (_customDataManager == null)
{ {
@ -219,7 +220,7 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
if (!data.Invites.isEmpty()) if (!data.Invites.isEmpty())
{ {
loadBrowserCommunities(data.Invites, null); runAsync(() -> loadBrowserCommunities(data.Invites, null));
} }
} }
@ -400,7 +401,22 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
return; return;
} }
runAsync(() -> consumer.accept(_repo.loadCommunity(new HashMap<>(1), id))); runAsync(() ->
{
try
{
final Map<Integer, Community> store = new HashMap<>();
_repo.loadCommunity(store, id);
if (!store.isEmpty())
{
runSync(() -> consumer.accept(store.get(id)));
}
} catch (Exception ex)
{
ex.printStackTrace();
}
});
} }
public ICommunity getBrowserCommunity(int id) public ICommunity getBrowserCommunity(int id)
@ -423,20 +439,30 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
{ {
return _loadedCommunities.get(id); return _loadedCommunities.get(id);
} }
public ICommunity getCommunity(String name)
{
return getByName(_loadedCommunities, name, getByName(_browserCommunities, name, null));
}
public Community getLoadedCommunity(String name) public Community getLoadedCommunity(String name)
{ {
for (Entry<Integer, Community> entry : _loadedCommunities.entrySet()) return (Community) getByName(_loadedCommunities, name, null);
}
private ICommunity getByName(Map<Integer, ? extends ICommunity> map, String name, ICommunity def)
{
for (Entry<Integer, ? extends ICommunity> entry : map.entrySet())
{ {
if (entry.getValue().getName().equalsIgnoreCase(name)) if (entry.getValue().getName().equalsIgnoreCase(name))
{ {
return entry.getValue(); return entry.getValue();
} }
} }
return null; return def;
} }
public void handleCommunitySettingUpdate(Integer id, String sender, CommunitySetting setting, String newValue) public void handleCommunitySettingUpdate(Integer id, String sender, CommunitySetting setting, String newValue)
{ {
Community community = _loadedCommunities.get(id); Community community = _loadedCommunities.get(id);
@ -955,8 +981,12 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
if (!load.isEmpty()) if (!load.isEmpty())
{ {
_browserCommunities.keySet().removeAll(load); _browserCommunities.keySet().removeAll(load);
_repo.handlePlayerJoin(_loadedCommunities, load, accountId);
System.out.println("Loaded communities: " + load + "; Total: " + _loadedCommunities.size()); runAsync(() ->
{
_repo.handlePlayerJoin(_loadedCommunities, load, accountId);
System.out.println("Loaded communities: " + load + "; Total: " + _loadedCommunities.size());
});
} }
} }

View File

@ -12,8 +12,6 @@ import java.util.function.Consumer;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.timing.TimingManager; import mineplex.core.common.timing.TimingManager;
import mineplex.core.common.util.Callback; import mineplex.core.common.util.Callback;
import mineplex.core.communities.data.BrowserCommunity; import mineplex.core.communities.data.BrowserCommunity;
@ -38,7 +36,7 @@ public class CommunityRepository extends RepositoryBase
{ {
private static final String GET_COMMUNITIES_BY_ID = "SELECT * FROM communities"; private static final String GET_COMMUNITIES_BY_ID = "SELECT * FROM communities";
private static final String GET_COMMUNITY_MEMBERS = "SELECT cm.communityId, cm.accountId, cm.communityRole, ac.name, ac.uuid, ac.lastLogin, cm.readingChat FROM communityMembers cm INNER JOIN accounts ac ON ac.id=cm.accountId"; private static final String GET_COMMUNITY_MEMBERS = "SELECT cm.communityId, cm.accountId, cm.communityRole, ac.name, ac.uuid, ac.lastLogin, cm.readingChat FROM communityMembers cm INNER JOIN accounts ac ON ac.id=cm.accountId";
private static final String GET_COMMUNITY_SIZE = "SELECT COUNT(accountId) AS total, communityId FROM communityMembers"; private static final String GET_COMMUNITY_SIZE = "SELECT communityId FROM communityMembers";
private static final String GET_COMMUNITY_JOIN_REQUESTS = "SELECT cjr.communityId, cjr.accountId, ac.name, ac.uuid FROM communityJoinRequests cjr INNER JOIN accounts ac ON ac.id=cjr.accountId WHERE cjr.accountId=?;"; private static final String GET_COMMUNITY_JOIN_REQUESTS = "SELECT cjr.communityId, cjr.accountId, ac.name, ac.uuid FROM communityJoinRequests cjr INNER JOIN accounts ac ON ac.id=cjr.accountId WHERE cjr.accountId=?;";
private static final String GET_COMMUNITY_SETTINGS = "SELECT communityId, settingId, settingValue FROM communitySettings"; private static final String GET_COMMUNITY_SETTINGS = "SELECT communityId, settingId, settingValue FROM communitySettings";
private static final String GET_PUBLIC_COMMUNITIES = "SELECT communityId FROM communitySettings WHERE settingId=8 AND settingValue='true';"; private static final String GET_PUBLIC_COMMUNITIES = "SELECT communityId FROM communitySettings WHERE settingId=8 AND settingValue='true';";
@ -134,19 +132,19 @@ public class CommunityRepository extends RepositoryBase
{ {
while (resultSet.next()) while (resultSet.next())
{ {
int members = resultSet.getInt("total"); int communityId = resultSet.getInt("communityId");
int id = resultSet.getInt("communityId"); BrowserCommunity com = store.get(communityId);
BrowserCommunity com = store.get(id);
if (com != null) if (com != null)
{ {
com.setMembers(members); com.addMember();
} }
} }
}, idColumns); }, idColumns);
idColumns = genIdColumns("communityId", load); idColumns = genIdColumns("communityId", load);
executeQuery(connection, GET_COMMUNITY_SETTINGS + inClause.replace("%col", "communityId"), settingSet -> executeQuery(connection, GET_COMMUNITY_SETTINGS
+ inClause.replace("%col", "communityId").replace(";", "")
+ " AND (settingId=5 OR settingId=6 OR settingId=7);", settingSet ->
{ {
while (settingSet.next()) while (settingSet.next())
{ {
@ -177,9 +175,9 @@ public class CommunityRepository extends RepositoryBase
/** /**
* Loads and stores a single community. * Loads and stores a single community.
*/ */
public Community loadCommunity(final Map<Integer, Community> store, final int id) public void loadCommunity(final Map<Integer, Community> store, final int id)
{ {
return loadInternal(store, Collections.singletonList(id), -1).get(0); loadInternal(store, Collections.singletonList(id), -1);
} }
/** /**

View File

@ -49,6 +49,7 @@ public class CommunityCommand extends MultiCommandBase<CommunityManager>
UtilPlayer.message(caller, F.help("/com disband <community>", "Disbands a community you own", ChatColor.DARK_AQUA)); UtilPlayer.message(caller, F.help("/com disband <community>", "Disbands a community you own", ChatColor.DARK_AQUA));
return; return;
} }
Community community = Plugin.getLoadedCommunity(args[0]); Community community = Plugin.getLoadedCommunity(args[0]);
if (community == null) if (community == null)
{ {

View File

@ -9,6 +9,7 @@ import mineplex.core.common.util.UtilPlayer;
import mineplex.core.communities.data.Community; import mineplex.core.communities.data.Community;
import mineplex.core.communities.data.Community.PrivacySetting; import mineplex.core.communities.data.Community.PrivacySetting;
import mineplex.core.communities.CommunityManager; import mineplex.core.communities.CommunityManager;
import mineplex.core.communities.data.ICommunity;
public class CommunityJoinCommand extends CommandBase<CommunityManager> public class CommunityJoinCommand extends CommandBase<CommunityManager>
{ {
@ -25,22 +26,27 @@ public class CommunityJoinCommand extends CommandBase<CommunityManager>
UtilPlayer.message(caller, F.help("/com join <community>", "Joins a community that is open or you have been invited to", ChatColor.DARK_AQUA)); UtilPlayer.message(caller, F.help("/com join <community>", "Joins a community that is open or you have been invited to", ChatColor.DARK_AQUA));
return; return;
} }
Community c = Plugin.getLoadedCommunity(args[0]);
ICommunity c = Plugin.getCommunity(args[0]);
if (c == null) if (c == null)
{ {
UtilPlayer.message(caller, F.main(Plugin.getName(), "That community was not found!")); UtilPlayer.message(caller, F.main(Plugin.getName(), "That community was not found!"));
return; return;
} }
if (c.getMembers().containsKey(caller.getUniqueId()))
{ // edge case someone can try if they really want: open communities with less than 5 members are forgotten here
UtilPlayer.message(caller, F.main(Plugin.getName(), "You are already in " + F.name(c.getName()) + "!"));
return;
}
if (c.getPrivacySetting() != PrivacySetting.OPEN && !Plugin.Get(caller).Invites.contains(c.getId())) if (c.getPrivacySetting() != PrivacySetting.OPEN && !Plugin.Get(caller).Invites.contains(c.getId()))
{ {
UtilPlayer.message(caller, F.main(Plugin.getName(), "You are have not been invited to " + F.name(c.getName()) + "!")); UtilPlayer.message(caller, F.main(Plugin.getName(), "You are have not been invited to " + F.name(c.getName()) + "!"));
return; return;
} }
if (c instanceof Community && ((Community) c).getMembers().containsKey(caller.getUniqueId()))
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "You are already in " + F.name(c.getName()) + "!"));
return;
}
Plugin.handleJoin(caller, c, Plugin.Get(caller).Invites.contains(c.getId())); Plugin.handleJoin(caller, c, Plugin.Get(caller).Invites.contains(c.getId()));
} }
} }

View File

@ -64,6 +64,11 @@ public class BrowserCommunity implements ICommunity
return this; return this;
} }
public void addMember()
{
_members++;
}
public BrowserCommunity setDescription(String description) public BrowserCommunity setDescription(String description)
{ {
_description = Preconditions.checkNotNull(description); _description = Preconditions.checkNotNull(description);