Create data classes to handle information about join requests and community members, as well as increasing the amount of information held for online players in their MemberData

This commit is contained in:
AlexTheCoder 2016-12-14 22:12:12 -05:00 committed by cnr
parent cefc3344ab
commit 024a58e0fa
3 changed files with 161 additions and 0 deletions

View File

@ -0,0 +1,47 @@
package mineplex.core.communities;
import java.util.UUID;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemBuilder;
public class CommunityJoinRequestInfo
{
public String Name;
public final UUID UUID;
public final int AccountId;
private ItemStack _icon;
public CommunityJoinRequestInfo(String name, UUID uuid, int accountId)
{
Name = name;
UUID = uuid;
AccountId = accountId;
buildIcon();
}
private void buildIcon()
{
ItemBuilder builder = new ItemBuilder(Material.SKULL_ITEM);
builder.setTitle(C.cGold + Name);
builder.setLore(C.cGray + "Left Click to Accept", C.cGray + "Right Click to Deny");
builder.setAmount((short)3);
builder.setPlayerHead(Name);
_icon = builder.build();
}
public void update(String name)
{
Name = name;
buildIcon();
}
public ItemStack getRepresentation()
{
return _icon;
}
}

View File

@ -1,12 +1,18 @@
package mineplex.core.communities; package mineplex.core.communities;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
public class CommunityMemberData public class CommunityMemberData
{ {
private final Map<Integer, CommunityRole> _communities = new HashMap<>(); private final Map<Integer, CommunityRole> _communities = new HashMap<>();
public final List<Integer> Invites = new ArrayList<>();
private int _chattingTo = -1;
public CommunityMemberData() public CommunityMemberData()
{ {
@ -17,6 +23,21 @@ public class CommunityMemberData
return _communities.size(); return _communities.size();
} }
public boolean ownsCommunity()
{
return _communities.containsValue(CommunityRole.LEADER);
}
public int getCommunityChattingTo()
{
return _chattingTo;
}
public void setCommunityChattingTo(Community community)
{
_chattingTo = community.getId();
}
public Community[] getCommunities() public Community[] getCommunities()
{ {
return _communities.values().toArray(new Community[_communities.size()]); return _communities.values().toArray(new Community[_communities.size()]);

View File

@ -0,0 +1,93 @@
package mineplex.core.communities;
import java.util.UUID;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilTime;
import mineplex.core.itemstack.ItemBuilder;
public class CommunityMemberInfo
{
public String Name;
public final UUID UUID;
public final int AccountId;
public CommunityRole Role;
private ItemStack _memberIcon, _outsiderIcon;
private long _sinceLastLogin;
private boolean _online = false;
private String _currentServer = "";
public CommunityMemberInfo(String name, UUID uuid, int accountId, CommunityRole role, long timeSinceLastLogin)
{
Name = name;
UUID = uuid;
AccountId = accountId;
Role = role;
_sinceLastLogin = timeSinceLastLogin;
buildIcons();
}
private void buildIcons()
{
ItemBuilder builder = new ItemBuilder(Material.SKULL_ITEM).setTitle(C.cGold + Name).setLore(C.cGrayB + "Role: " + C.cDAqua + Role.getDisplay());
_outsiderIcon = builder.build();
builder.setTitle(_online ? C.cRed : C.cGreen + Name);
if (_online)
{
builder.addLore(C.cGrayB + "Server: " + C.cYellow + _currentServer);
}
else
{
builder.addLore(C.cGray + "Last seen " + UtilTime.MakeStr(_sinceLastLogin) + " ago");
}
if (_online)
{
builder.setData((short)3);
builder.setPlayerHead(Name);
}
_memberIcon = builder.build();
}
public void update(String name, CommunityRole role, long timeSinceLastLogin, boolean online, String currentServer)
{
Name = name;
Role = role;
_sinceLastLogin = timeSinceLastLogin;
_online = online;
_currentServer = currentServer;
buildIcons();
}
public boolean isOnline()
{
return _online;
}
public ItemStack getRepresentation(CommunityRole viewerRole)
{
if (viewerRole == null)
{
return _outsiderIcon;
}
ItemBuilder builder = new ItemBuilder(_memberIcon);
if (viewerRole == CommunityRole.LEADER && Role != CommunityRole.LEADER)
{
builder.addLore(C.cGreen + "Left Click to Promote");
if (Role != CommunityRole.MEMBER)
{
builder.addLore(C.cRed + "Right Click to Demote");
}
}
if (viewerRole.ordinal() < Role.ordinal())
{
builder.addLore(C.cRed + "Shift Right Click to Kick");
}
return builder.build();
}
}