Make community button refresh with join requests
This commit is contained in:
parent
9acd6b7832
commit
8e9336ad23
@ -178,15 +178,24 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
||||
|
||||
public void updateAllMemberData(UUID uuid, String name)
|
||||
{
|
||||
if (uuid == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_loadedCommunities.values().stream().filter(community -> community.getMembers().containsKey(uuid) && !community.getMembers().get(uuid).Name.equalsIgnoreCase(name)).forEach(community ->
|
||||
{
|
||||
community.getMembers().get(uuid).updateName(name);
|
||||
community.getMembers().get(uuid).update(System.currentTimeMillis(), false, "");
|
||||
UtilServer.CallEvent(new CommunityMembershipUpdateEvent(community));
|
||||
});
|
||||
}
|
||||
|
||||
public void updateAllJoinRequests(UUID uuid, String name)
|
||||
{
|
||||
if (uuid == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_loadedCommunities.values().stream().filter(community -> community.getJoinRequests().containsKey(uuid) && !community.getJoinRequests().get(uuid).Name.equalsIgnoreCase(name)).forEach(community ->
|
||||
{
|
||||
community.getJoinRequests().get(uuid).update(name);
|
||||
@ -269,7 +278,7 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
|
||||
return;
|
||||
}
|
||||
CommunityMemberInfo member = community.getMembers().get(uuid);
|
||||
member.Role = role;
|
||||
member.updateRole(role);
|
||||
if (Bukkit.getPlayer(uuid) != null)
|
||||
{
|
||||
if (role.ordinal() > CommunityRole.COLEADER.ordinal())
|
||||
|
@ -17,17 +17,17 @@ public class CommunityMemberInfo
|
||||
public CommunityRole Role;
|
||||
public boolean ReadingChat = true;
|
||||
private ItemStack _memberIcon, _outsiderIcon;
|
||||
private long _sinceLastLogin;
|
||||
private long _lastLogin;
|
||||
private boolean _online = false;
|
||||
private String _currentServer = "";
|
||||
|
||||
public CommunityMemberInfo(String name, UUID uuid, int accountId, CommunityRole role, long timeSinceLastLogin)
|
||||
public CommunityMemberInfo(String name, UUID uuid, int accountId, CommunityRole role, long lastLogin)
|
||||
{
|
||||
Name = name;
|
||||
UUID = uuid;
|
||||
AccountId = accountId;
|
||||
Role = role;
|
||||
_sinceLastLogin = timeSinceLastLogin;
|
||||
_lastLogin = lastLogin;
|
||||
|
||||
buildIcons();
|
||||
}
|
||||
@ -43,7 +43,7 @@ public class CommunityMemberInfo
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.addLore(C.cYellow + "Last Seen " + C.cWhite + UtilTime.MakeStr(_sinceLastLogin) + " Ago");
|
||||
builder.addLore(C.cYellow + "Last Seen " + C.cWhite + UtilTime.MakeStr(System.currentTimeMillis() - _lastLogin) + " Ago");
|
||||
}
|
||||
if (_online)
|
||||
{
|
||||
@ -66,9 +66,15 @@ public class CommunityMemberInfo
|
||||
buildIcons();
|
||||
}
|
||||
|
||||
public void update(long timeSinceLastLogin, boolean online, String currentServer)
|
||||
public void updateRole(CommunityRole role)
|
||||
{
|
||||
_sinceLastLogin = timeSinceLastLogin;
|
||||
Role = role;
|
||||
buildIcons();
|
||||
}
|
||||
|
||||
public void update(long lastLogin, boolean online, String currentServer)
|
||||
{
|
||||
_lastLogin = lastLogin;
|
||||
_online = online;
|
||||
_currentServer = currentServer;
|
||||
|
||||
|
@ -10,11 +10,13 @@ import org.bukkit.event.EventHandler;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.communities.Community;
|
||||
import mineplex.core.communities.CommunityDisbandEvent;
|
||||
import mineplex.core.communities.CommunityJoinRequestsUpdateEvent;
|
||||
import mineplex.core.communities.CommunityMemberDataUpdateEvent;
|
||||
import mineplex.core.communities.CommunityMemberInfo;
|
||||
import mineplex.core.communities.CommunityMembershipUpdateEvent;
|
||||
import mineplex.core.communities.CommunityRole;
|
||||
import mineplex.core.communities.gui.ActionButton;
|
||||
import mineplex.core.communities.gui.CommunitiesGUIButton;
|
||||
import mineplex.core.communities.gui.CommunitiesGUIPage;
|
||||
import mineplex.core.communities.gui.overview.CommunityOverviewPage;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
@ -142,6 +144,19 @@ public class CommunityMembersPage extends CommunitiesGUIPage
|
||||
Viewer.updateInventory();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onRequestsUpdate(CommunityJoinRequestsUpdateEvent event)
|
||||
{
|
||||
if (event.getCommunity().getId().intValue() != _community.getId().intValue())
|
||||
{
|
||||
return;
|
||||
}
|
||||
CommunitiesGUIButton button = Buttons.get(4);
|
||||
button.update();
|
||||
Inv.setItem(4, button.Button);
|
||||
Viewer.updateInventory();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onMembershipUpdate(CommunityMembershipUpdateEvent event)
|
||||
{
|
||||
|
@ -7,12 +7,14 @@ import org.bukkit.event.EventHandler;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.communities.Community;
|
||||
import mineplex.core.communities.CommunityDisbandEvent;
|
||||
import mineplex.core.communities.CommunityJoinRequestsUpdateEvent;
|
||||
import mineplex.core.communities.CommunityMemberDataUpdateEvent;
|
||||
import mineplex.core.communities.CommunityMembershipUpdateEvent;
|
||||
import mineplex.core.communities.CommunityRole;
|
||||
import mineplex.core.communities.CommunitySetting;
|
||||
import mineplex.core.communities.CommunitySettingUpdateEvent;
|
||||
import mineplex.core.communities.gui.ActionButton;
|
||||
import mineplex.core.communities.gui.CommunitiesGUIButton;
|
||||
import mineplex.core.communities.gui.CommunitiesGUIPage;
|
||||
import mineplex.core.communities.gui.overview.CommunityOverviewPage;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
@ -104,6 +106,19 @@ public class CommunitySettingsPage extends CommunitiesGUIPage
|
||||
Viewer.updateInventory();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onRequestsUpdate(CommunityJoinRequestsUpdateEvent event)
|
||||
{
|
||||
if (event.getCommunity().getId().intValue() != _community.getId().intValue())
|
||||
{
|
||||
return;
|
||||
}
|
||||
CommunitiesGUIButton button = Buttons.get(4);
|
||||
button.update();
|
||||
Inv.setItem(4, button.Button);
|
||||
Viewer.updateInventory();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onMembershipUpdate(CommunityMembershipUpdateEvent event)
|
||||
{
|
||||
|
@ -77,14 +77,14 @@ public class CommunityRepository extends MinecraftRepository
|
||||
final String name = memberSet.getString("name");
|
||||
final UUID uuid = UUID.fromString(memberSet.getString("uuid"));
|
||||
final CommunityRole role = CommunityRole.parseRole(memberSet.getString("communityRole"));
|
||||
final long timeSinceOnline = memberSet.getTimestamp(6).getTime() - memberSet.getTimestamp(5).getTime();
|
||||
final long lastLogin = memberSet.getTimestamp("lastLogin").getTime();
|
||||
boolean readingChat = memberSet.getBoolean("readingChat");
|
||||
|
||||
CommunityMemberInfo info = new CommunityMemberInfo(name, uuid, accountId, role, timeSinceOnline);
|
||||
CommunityMemberInfo info = new CommunityMemberInfo(name, uuid, accountId, role, lastLogin);
|
||||
PlayerStatus status = _repo.getElement(name);
|
||||
if (status != null)
|
||||
{
|
||||
info.update(timeSinceOnline, true, status.getServer());
|
||||
info.update(lastLogin, true, status.getServer());
|
||||
}
|
||||
info.ReadingChat = readingChat;
|
||||
community.getMembers().put(info.UUID, info);
|
||||
@ -148,14 +148,14 @@ public class CommunityRepository extends MinecraftRepository
|
||||
final String name = memberSet.getString("name");
|
||||
final UUID uuid = UUID.fromString(memberSet.getString("uuid"));
|
||||
final CommunityRole role = CommunityRole.parseRole(memberSet.getString("communityRole"));
|
||||
final long timeSinceOnline = memberSet.getTimestamp(6).getTime() - memberSet.getTimestamp(5).getTime();
|
||||
final long lastLogin = memberSet.getTimestamp("lastLogin").getTime();
|
||||
boolean readingChat = memberSet.getBoolean("readingChat");
|
||||
|
||||
CommunityMemberInfo info = new CommunityMemberInfo(name, uuid, accountId, role, timeSinceOnline);
|
||||
CommunityMemberInfo info = new CommunityMemberInfo(name, uuid, accountId, role, lastLogin);
|
||||
PlayerStatus status = _repo.getElement(name);
|
||||
if (status != null)
|
||||
{
|
||||
info.update(timeSinceOnline, true, status.getServer());
|
||||
info.update(lastLogin, true, status.getServer());
|
||||
}
|
||||
info.ReadingChat = readingChat;
|
||||
community.getMembers().put(info.UUID, info);
|
||||
|
Loading…
Reference in New Issue
Block a user