Ensure the community is always loaded for MCS
This commit is contained in:
parent
48d705290b
commit
c5f29533b7
@ -23,6 +23,7 @@ public class Community
|
|||||||
private PrivacySetting _privacy;
|
private PrivacySetting _privacy;
|
||||||
|
|
||||||
private transient boolean unloaded = false;
|
private transient boolean unloaded = false;
|
||||||
|
private transient boolean persist = false;
|
||||||
|
|
||||||
public Community(int id, String name)
|
public Community(int id, String name)
|
||||||
{
|
{
|
||||||
@ -135,6 +136,16 @@ public class Community
|
|||||||
return unloaded;
|
return unloaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void persist()
|
||||||
|
{
|
||||||
|
this.persist = persist;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPersistent()
|
||||||
|
{
|
||||||
|
return persist;
|
||||||
|
}
|
||||||
|
|
||||||
public static enum PrivacySetting
|
public static enum PrivacySetting
|
||||||
{
|
{
|
||||||
OPEN("Open to Join"),
|
OPEN("Open to Join"),
|
||||||
|
@ -8,6 +8,7 @@ import java.util.LinkedList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@ -65,10 +66,12 @@ import mineplex.core.communities.storage.CommunityRepository;
|
|||||||
import mineplex.core.preferences.Preference;
|
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.serverdata.Region;
|
import mineplex.serverdata.Region;
|
||||||
import mineplex.serverdata.commands.ServerCommandManager;
|
import mineplex.serverdata.commands.ServerCommandManager;
|
||||||
import mineplex.serverdata.data.DataRepository;
|
import mineplex.serverdata.data.DataRepository;
|
||||||
import mineplex.serverdata.data.PlayerStatus;
|
import mineplex.serverdata.data.PlayerStatus;
|
||||||
|
import mineplex.serverdata.data.ServerGroup;
|
||||||
import mineplex.serverdata.redis.RedisDataRepository;
|
import mineplex.serverdata.redis.RedisDataRepository;
|
||||||
import mineplex.serverdata.servers.ServerManager;
|
import mineplex.serverdata.servers.ServerManager;
|
||||||
|
|
||||||
@ -193,7 +196,7 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
|||||||
|
|
||||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(_plugin, this::cycleBrowser, 0L, 20 * 30);
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(_plugin, this::cycleBrowser, 0L, 20 * 30);
|
||||||
|
|
||||||
// _repo.loadCommunities(_loadedCommunities);
|
// _repo.handlePlayerJoin(_loadedCommunities);
|
||||||
|
|
||||||
addCommand(new CommunityCommand(this));
|
addCommand(new CommunityCommand(this));
|
||||||
|
|
||||||
@ -210,12 +213,23 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
|||||||
ServerCommandManager.getInstance().registerCommandType(CommunityUpdateName.class, new CommunityUpdateNameHandler(this));
|
ServerCommandManager.getInstance().registerCommandType(CommunityUpdateName.class, new CommunityUpdateNameHandler(this));
|
||||||
ServerCommandManager.getInstance().registerCommandType(CommunityUpdateSetting.class, new CommunityUpdateSettingHandler(this));
|
ServerCommandManager.getInstance().registerCommandType(CommunityUpdateSetting.class, new CommunityUpdateSettingHandler(this));
|
||||||
|
|
||||||
|
// Load and keep community for MCS
|
||||||
|
ServerGroup group = require(ServerConfiguration.class).getServerGroup();
|
||||||
|
if (group.getName().startsWith("COM-"))
|
||||||
|
{
|
||||||
|
int comId = Integer.parseInt(group.getName().split("-")[1]);
|
||||||
|
Community community = getLoadedCommunity(comId);
|
||||||
|
if (community == null)
|
||||||
|
community = _repo.loadCommunity(_loadedCommunities, comId);
|
||||||
|
|
||||||
|
community.persist();
|
||||||
|
}
|
||||||
|
|
||||||
generatePermissions();
|
generatePermissions();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generatePermissions()
|
private void generatePermissions()
|
||||||
{
|
{
|
||||||
|
|
||||||
PermissionGroup.ETERNAL.setPermission(Perm.OWN_COMMUNITY, true, true);
|
PermissionGroup.ETERNAL.setPermission(Perm.OWN_COMMUNITY, true, true);
|
||||||
PermissionGroup.PLAYER.setPermission(Perm.COMMUNITY_CHAT_COMMAND, true, true);
|
PermissionGroup.PLAYER.setPermission(Perm.COMMUNITY_CHAT_COMMAND, true, true);
|
||||||
PermissionGroup.PLAYER.setPermission(Perm.COMMUNITY_COMMAND, true, true);
|
PermissionGroup.PLAYER.setPermission(Perm.COMMUNITY_COMMAND, true, true);
|
||||||
@ -849,7 +863,7 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
|||||||
|
|
||||||
runAsync(() ->
|
runAsync(() ->
|
||||||
{
|
{
|
||||||
_repo.loadCommunities(_loadedCommunities, load, accountId);
|
_repo.handlePlayerJoin(_loadedCommunities, load, accountId);
|
||||||
System.out.println("Loaded communities: " + load + "; Total: " + _loadedCommunities.size());
|
System.out.println("Loaded communities: " + load + "; Total: " + _loadedCommunities.size());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -860,14 +874,11 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
|||||||
// Remove their communities from memory if they're the last player
|
// Remove their communities from memory if they're the last player
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
List<Community> communities = Get(player).getCommunities();
|
List<Community> communities = Get(player).getCommunities();
|
||||||
com: for (Community community : communities)
|
for (Community community : communities)
|
||||||
{
|
{
|
||||||
for (UUID uuid : community.getMembers().keySet())
|
if (community.isPersistent()
|
||||||
{
|
|| community.getMembers().keySet().stream().anyMatch(uuid -> !player.getUniqueId().equals(uuid) && Bukkit.getPlayer(uuid) != null))
|
||||||
// See if there's anyone else online other than our quitting player
|
continue;
|
||||||
if (!player.getUniqueId().equals(uuid) && Bukkit.getPlayer(uuid) != null)
|
|
||||||
continue com;
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("Unloading community: " + community.getId());
|
System.out.println("Unloading community: " + community.getId());
|
||||||
|
|
||||||
|
@ -2,11 +2,10 @@ package mineplex.core.communities.storage;
|
|||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.HashMap;
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
@ -70,7 +69,18 @@ public class CommunityRepository extends RepositoryBase
|
|||||||
return nums.stream().map(i -> new ColumnInt(colName, i)).toArray(ColumnInt[]::new);
|
return nums.stream().map(i -> new ColumnInt(colName, i)).toArray(ColumnInt[]::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadCommunities(final Map<Integer, Community> store, final List<Integer> load, final int accountId)
|
public Community loadCommunity(final Map<Integer, Community> store, final int id)
|
||||||
|
{
|
||||||
|
loadInternal(store, Collections.singletonList(id), -1);
|
||||||
|
return store.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handlePlayerJoin(final Map<Integer, Community> store, final List<Integer> load, final int accountId)
|
||||||
|
{
|
||||||
|
loadInternal(store, load, accountId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadInternal(final Map<Integer, Community> store, final List<Integer> load, final int accountId)
|
||||||
{
|
{
|
||||||
try (Connection connection = getConnection())
|
try (Connection connection = getConnection())
|
||||||
{
|
{
|
||||||
@ -126,6 +136,8 @@ public class CommunityRepository extends RepositoryBase
|
|||||||
}
|
}
|
||||||
}, idColumns);
|
}, idColumns);
|
||||||
|
|
||||||
|
if (accountId != -1)
|
||||||
|
{
|
||||||
executeQuery(connection, GET_COMMUNITY_JOIN_REQUESTS, requestSet ->
|
executeQuery(connection, GET_COMMUNITY_JOIN_REQUESTS, requestSet ->
|
||||||
{
|
{
|
||||||
while (requestSet.next())
|
while (requestSet.next())
|
||||||
@ -142,6 +154,7 @@ public class CommunityRepository extends RepositoryBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, new ColumnInt("cjr.accountId", accountId));
|
}, new ColumnInt("cjr.accountId", accountId));
|
||||||
|
}
|
||||||
|
|
||||||
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"), settingSet ->
|
||||||
|
Loading…
Reference in New Issue
Block a user