Remove inner query in CommunityRepository
This commit is contained in:
parent
253c907ba1
commit
2fe9423196
@ -74,7 +74,7 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
||||
public final String[] BLOCKED_NAMES = new String[] {"help", "chat", "create", "description", "disband", "invite", "join", "mcs", "rename", "uninvite", "trainee", "mod", "moderator", "srmod", "seniormod", "seniormoderator", "builder", "maplead", "twitch", "youtube", "support", "admin", "administrator", "leader", "dev", "developer", "owner", "party", "mineplex", "mineplexOfficial", "staff", "mineplexstaff", "qualityassurance", "traineemanagement", "modcoordination", "forumninja", "communitymanagement", "event", "socialmedia"};
|
||||
private final CommunityRepository _repo;
|
||||
private final Map<Integer, Community> _loadedCommunities;
|
||||
|
||||
|
||||
public final List<Integer> BrowserIds = new LinkedList<>();
|
||||
|
||||
public final DataRepository<PlayerStatus> StatusRepository;
|
||||
@ -135,6 +135,13 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
||||
ServerCommandManager.getInstance().registerCommandType(CommunityUpdateName.class, new CommunityUpdateNameHandler(this));
|
||||
ServerCommandManager.getInstance().registerCommandType(CommunityUpdateSetting.class, new CommunityUpdateSettingHandler(this));
|
||||
}
|
||||
|
||||
public boolean ownsCommunity(UUID uuid)
|
||||
{
|
||||
return _loadedCommunities.values().stream()
|
||||
.flatMap(community -> community.getMembers().entrySet().stream())
|
||||
.anyMatch(entry -> entry.getKey().equals(uuid) && entry.getValue().Role == CommunityRole.LEADER);
|
||||
}
|
||||
|
||||
private void cycleBrowser()
|
||||
{
|
||||
|
@ -54,7 +54,7 @@ public class CommunityMemberButton extends CommunitiesGUIButton
|
||||
}
|
||||
if (_info.Role == CommunityRole.COLEADER && type == ClickType.SHIFT_LEFT)
|
||||
{
|
||||
if (_info.OwnsCommunity)
|
||||
if (getCommunityManager().ownsCommunity(_info.UUID))
|
||||
{
|
||||
UtilPlayer.message(_viewer, F.main(getCommunityManager().getName(), F.name(_info.Name) + " can only own one community at a time!"));
|
||||
return;
|
||||
|
@ -31,7 +31,7 @@ public class CommunityRepository extends MinecraftRepository
|
||||
private static final String GET_ALL_COMMUNITIES = "SELECT * FROM communities WHERE region=?;";
|
||||
private static final String GET_COMMUNITY_BY_ID = "SELECT * FROM communities WHERE id=?;";
|
||||
private static final String GET_COMMUNITY_BY_NAME = "SELECT * FROM communities WHERE name=? AND region=?;";
|
||||
private static final String GET_COMMUNITY_MEMBERS = "SELECT cm.accountId, cm.communityRole, ac.name, ac.uuid, ac.lastLogin, now(), cm.readingChat, (SELECT COUNT(id) FROM communityMembers WHERE accountId=cm.accountId AND communityRole='LEADER') FROM communityMembers cm INNER JOIN accounts ac ON ac.id=cm.accountId WHERE communityId=?;";
|
||||
private static final String GET_COMMUNITY_MEMBERS = "SELECT cm.accountId, cm.communityRole, ac.name, ac.uuid, ac.lastLogin, now(), cm.readingChat FROM communityMembers cm INNER JOIN accounts ac ON ac.id=cm.accountId WHERE communityId=?;";
|
||||
private static final String GET_COMMUNITY_JOIN_REQUESTS = "SELECT cjr.accountId, ac.name, ac.uuid FROM communityJoinRequests cjr INNER JOIN accounts ac ON ac.id=cjr.accountId WHERE communityId=?;";
|
||||
private static final String GET_COMMUNITY_SETTINGS = "SELECT settingId, settingValue FROM communitySettings WHERE communityId=?;";
|
||||
|
||||
@ -81,7 +81,6 @@ public class CommunityRepository extends MinecraftRepository
|
||||
final CommunityRole role = CommunityRole.parseRole(memberSet.getString("communityRole"));
|
||||
final long timeSinceOnline = memberSet.getTimestamp(6).getTime() - memberSet.getTimestamp(5).getTime();
|
||||
boolean readingChat = memberSet.getBoolean("readingChat");
|
||||
final int owns = memberSet.getInt(8);
|
||||
|
||||
CommunityMemberInfo info = new CommunityMemberInfo(name, uuid, accountId, role, timeSinceOnline);
|
||||
PlayerStatus status = _repo.getElement(name);
|
||||
@ -90,7 +89,6 @@ public class CommunityRepository extends MinecraftRepository
|
||||
info.update(name, role, timeSinceOnline, true, status.getServer());
|
||||
}
|
||||
info.ReadingChat = readingChat;
|
||||
info.OwnsCommunity = owns > 0;
|
||||
community.getMembers().put(info.UUID, info);
|
||||
}
|
||||
}, new ColumnInt("communityId", community.getId()));
|
||||
@ -154,7 +152,6 @@ public class CommunityRepository extends MinecraftRepository
|
||||
final CommunityRole role = CommunityRole.parseRole(memberSet.getString("communityRole"));
|
||||
final long timeSinceOnline = memberSet.getTimestamp(6).getTime() - memberSet.getTimestamp(5).getTime();
|
||||
boolean readingChat = memberSet.getBoolean("readingChat");
|
||||
final int owns = memberSet.getInt(8);
|
||||
|
||||
CommunityMemberInfo info = new CommunityMemberInfo(name, uuid, accountId, role, timeSinceOnline);
|
||||
PlayerStatus status = _repo.getElement(name);
|
||||
@ -163,7 +160,6 @@ public class CommunityRepository extends MinecraftRepository
|
||||
info.update(name, role, timeSinceOnline, true, status.getServer());
|
||||
}
|
||||
info.ReadingChat = readingChat;
|
||||
info.OwnsCommunity = owns > 0;
|
||||
community.getMembers().put(info.UUID, info);
|
||||
}
|
||||
}, new ColumnInt("communityId", community.getId()));
|
||||
@ -239,8 +235,7 @@ public class CommunityRepository extends MinecraftRepository
|
||||
final CommunityRole role = CommunityRole.parseRole(memberSet.getString("communityRole"));
|
||||
final long timeSinceOnline = memberSet.getTimestamp(6).getTime() - memberSet.getTimestamp(5).getTime();
|
||||
//boolean readingChat = memberSet.getBoolean("readingChat");
|
||||
final int owns = memberSet.getInt(8);
|
||||
|
||||
|
||||
if (c.getMembers().containsKey(uuid))
|
||||
{
|
||||
PlayerStatus status = _repo.getElement(name);
|
||||
@ -252,7 +247,6 @@ public class CommunityRepository extends MinecraftRepository
|
||||
server = status.getServer();
|
||||
}
|
||||
//c.getMembers().get(uuid).ReadingChat = readingChat;
|
||||
c.getMembers().get(uuid).OwnsCommunity = owns > 0;
|
||||
c.getMembers().get(uuid).update(name, role, timeSinceOnline, online, server);
|
||||
}
|
||||
}
|
||||
@ -291,8 +285,7 @@ public class CommunityRepository extends MinecraftRepository
|
||||
final CommunityRole role = CommunityRole.parseRole(memberSet.getString("communityRole"));
|
||||
final long timeSinceOnline = memberSet.getTimestamp(5).getTime() - memberSet.getTimestamp(4).getTime();
|
||||
//boolean readingChat = memberSet.getBoolean("readingChat");
|
||||
final int owns = memberSet.getInt(8);
|
||||
|
||||
|
||||
if (members.containsKey(uuid))
|
||||
{
|
||||
PlayerStatus status = _repo.getElement(name);
|
||||
@ -304,7 +297,6 @@ public class CommunityRepository extends MinecraftRepository
|
||||
server = status.getServer();
|
||||
}
|
||||
//members.get(uuid).ReadingChat = readingChat;
|
||||
members.get(uuid).OwnsCommunity = owns > 0;
|
||||
members.get(uuid).update(name, role, timeSinceOnline, online, server);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user