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.recharge.Recharge;
import mineplex.core.serverConfig.ServerConfiguration;
import mineplex.core.treasure.animation.animations.reward.CommonRewardAnimation;
import mineplex.serverdata.Region;
import mineplex.serverdata.commands.ServerCommandManager;
import mineplex.serverdata.data.PlayerStatus;
@ -165,7 +166,7 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
return _prefManager;
}
private CustomDataManager getCustomDataManager()
public CustomDataManager getCustomDataManager()
{
if (_customDataManager == null)
{
@ -219,7 +220,7 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
if (!data.Invites.isEmpty())
{
loadBrowserCommunities(data.Invites, null);
runAsync(() -> loadBrowserCommunities(data.Invites, null));
}
}
@ -400,7 +401,22 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
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)
@ -424,9 +440,19 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
return _loadedCommunities.get(id);
}
public ICommunity getCommunity(String name)
{
return getByName(_loadedCommunities, name, getByName(_browserCommunities, name, null));
}
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))
{
@ -434,7 +460,7 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
}
}
return null;
return def;
}
public void handleCommunitySettingUpdate(Integer id, String sender, CommunitySetting setting, String newValue)
@ -955,8 +981,12 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
if (!load.isEmpty())
{
_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.Stream;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.timing.TimingManager;
import mineplex.core.common.util.Callback;
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_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_SETTINGS = "SELECT communityId, settingId, settingValue FROM communitySettings";
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())
{
int members = resultSet.getInt("total");
int id = resultSet.getInt("communityId");
BrowserCommunity com = store.get(id);
int communityId = resultSet.getInt("communityId");
BrowserCommunity com = store.get(communityId);
if (com != null)
{
com.setMembers(members);
com.addMember();
}
}
}, idColumns);
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())
{
@ -177,9 +175,9 @@ public class CommunityRepository extends RepositoryBase
/**
* 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));
return;
}
Community community = Plugin.getLoadedCommunity(args[0]);
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.PrivacySetting;
import mineplex.core.communities.CommunityManager;
import mineplex.core.communities.data.ICommunity;
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));
return;
}
Community c = Plugin.getLoadedCommunity(args[0]);
ICommunity c = Plugin.getCommunity(args[0]);
if (c == null)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "That community was not found!"));
return;
}
if (c.getMembers().containsKey(caller.getUniqueId()))
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "You are already in " + F.name(c.getName()) + "!"));
return;
}
// edge case someone can try if they really want: open communities with less than 5 members are forgotten here
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()) + "!"));
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()));
}
}

View File

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