From 024a58e0fab170a30554dc665780422b04d75792 Mon Sep 17 00:00:00 2001 From: AlexTheCoder Date: Wed, 14 Dec 2016 22:12:12 -0500 Subject: [PATCH] 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 --- .../communities/CommunityJoinRequestInfo.java | 47 ++++++++++ .../core/communities/CommunityMemberData.java | 21 +++++ .../core/communities/CommunityMemberInfo.java | 93 +++++++++++++++++++ 3 files changed, 161 insertions(+) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityJoinRequestInfo.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityMemberInfo.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityJoinRequestInfo.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityJoinRequestInfo.java new file mode 100644 index 000000000..1d09fe23c --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityJoinRequestInfo.java @@ -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; + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityMemberData.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityMemberData.java index 282e97f46..a7c87eb00 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityMemberData.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityMemberData.java @@ -1,12 +1,18 @@ package mineplex.core.communities; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; public class CommunityMemberData { private final Map _communities = new HashMap<>(); + public final List Invites = new ArrayList<>(); + + private int _chattingTo = -1; + public CommunityMemberData() { @@ -17,6 +23,21 @@ public class CommunityMemberData 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() { return _communities.values().toArray(new Community[_communities.size()]); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityMemberInfo.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityMemberInfo.java new file mode 100644 index 000000000..c68b78cd4 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityMemberInfo.java @@ -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(); + } +} \ No newline at end of file