-
Notifications
You must be signed in to change notification settings - Fork 7
Add /nllim (Name Layer List Invited Members)
#21
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| package vg.civcraft.mc.namelayer.command.commands; | ||
|
|
||
| import co.aikar.commands.annotation.CommandAlias; | ||
| import co.aikar.commands.annotation.CommandCompletion; | ||
| import co.aikar.commands.annotation.Description; | ||
| import co.aikar.commands.annotation.Optional; | ||
| import co.aikar.commands.annotation.Syntax; | ||
| import com.google.common.collect.Lists; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
| import org.bukkit.ChatColor; | ||
| import org.bukkit.entity.Player; | ||
| import vg.civcraft.mc.namelayer.GroupManager; | ||
| import vg.civcraft.mc.namelayer.GroupManager.PlayerType; | ||
| import vg.civcraft.mc.namelayer.NameAPI; | ||
| import vg.civcraft.mc.namelayer.command.BaseCommandMiddle; | ||
| import vg.civcraft.mc.namelayer.group.Group; | ||
| import vg.civcraft.mc.namelayer.permission.PermissionType; | ||
|
|
||
| public class ListInvites extends BaseCommandMiddle { | ||
|
|
||
| @CommandAlias("nllim|listinvites|listinvitedmembers") | ||
| @Syntax("<group> [rank (e.g: MEMBERS)]") | ||
| @Description("List the invitees of a group") | ||
| @CommandCompletion("@NL_Groups @NL_Ranks") | ||
| public void execute(Player sender, String groupName, @Optional String playerType, @Optional String playerName) { | ||
| UUID uuid = NameAPI.getUUID(sender.getName()); | ||
|
|
||
| Group group = GroupManager.getGroup(groupName); | ||
| if (groupIsNull(sender, groupName, group)) { | ||
| return; | ||
| } | ||
|
|
||
| if (!sender.hasPermission("namelayer.admin")) { | ||
| if (!group.isMember(uuid)) { | ||
| sender.sendMessage(ChatColor.RED + "You're not on this group."); | ||
| return; | ||
| } | ||
|
|
||
| if (!gm.hasAccess(group, uuid, PermissionType.getPermission("GROUPSTATS"))) { | ||
| sender.sendMessage(ChatColor.RED + "You don't have permission to run that command."); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| List<UUID> uuids = null; | ||
| if (playerType != null && playerName != null) { | ||
| List<UUID> invitees = group.getAllInvites(); | ||
| uuids = Lists.newArrayList(); | ||
|
|
||
| for (UUID invitee : invitees) { | ||
| String name = NameAPI.getCurrentName(invitee); | ||
| if (name.compareToIgnoreCase(playerType) >=0 | ||
| && name.compareToIgnoreCase(playerName) <= 0) { | ||
| uuids.add(invitee); | ||
| } | ||
| } | ||
| } else if (playerType != null) { | ||
| PlayerType filterType = PlayerType.getPlayerType(playerType); | ||
| if (filterType == null) { | ||
| // user entered invalid type, show them | ||
| PlayerType.displayPlayerTypes(sender); | ||
| return; | ||
| } | ||
|
|
||
| uuids = group.getAllInvites(filterType); | ||
| } else { | ||
| uuids = group.getAllInvites(); | ||
| } | ||
|
|
||
| StringBuilder sb = new StringBuilder(); | ||
| sb.append(ChatColor.GREEN); | ||
| sb.append("Invites are as follows:\n"); | ||
MrJeremyFisher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| for (UUID uu: uuids){ | ||
| sb.append(NameAPI.getCurrentName(uu)); | ||
| sb.append(" ("); | ||
| sb.append(group.getPlayerInviteType(uu)); | ||
| sb.append(")\n"); | ||
| } | ||
|
|
||
| sender.sendMessage(sb.toString()); | ||
MrJeremyFisher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,12 +3,8 @@ | |
| import com.google.common.collect.Lists; | ||
| import com.google.common.collect.Maps; | ||
| import com.google.common.collect.Sets; | ||
| import java.util.ArrayList; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.UUID; | ||
|
|
||
| import java.util.*; | ||
| import java.util.logging.Level; | ||
| import vg.civcraft.mc.namelayer.GroupManager; | ||
| import vg.civcraft.mc.namelayer.GroupManager.PlayerType; | ||
|
|
@@ -98,14 +94,36 @@ public void prepareForDeletion() { | |
| public List<UUID> getAllMembers() { | ||
| return Lists.newArrayList(players.keySet()); | ||
| } | ||
|
|
||
| /** | ||
| * Returns all the uuids of the invitees in this group. | ||
| * @return Returns all the uuids. | ||
| */ | ||
| public List<UUID> getAllInvites() { | ||
| return Lists.newArrayList(invites.keySet()); | ||
| } | ||
|
|
||
| /** | ||
| * Returns all the UUIDS of a group's PlayerType. | ||
| * @param type- The PlayerType of a group that you want the UUIDs of. | ||
| * @return Returns all the UUIDS of the specific PlayerType. | ||
| */ | ||
| public List<UUID> getAllInvites(PlayerType type) { | ||
| List<UUID> uuids = Lists.newArrayList(); | ||
| for (Map.Entry<UUID, PlayerType> entry : invites.entrySet()) { | ||
| if (entry.getValue() == type) { | ||
| uuids.add(entry.getKey()); | ||
| } | ||
| } | ||
| return uuids; | ||
| } | ||
|
|
||
| /** | ||
| * Returns all the UUIDS of a group's PlayerType. | ||
| * @param type- The PlayerType of a group that you want the UUIDs of. | ||
| * @return Returns all the UUIDS of the specific PlayerType. | ||
| */ | ||
| public List<UUID> getAllMembers(PlayerType type) { | ||
| List<UUID> uuids = Lists.newArrayList();; | ||
| List<UUID> uuids = Lists.newArrayList(); | ||
| for (Map.Entry<UUID, PlayerType> entry : players.entrySet()) { | ||
| if (entry.getValue() == type) { | ||
| uuids.add(entry.getKey()); | ||
|
|
@@ -253,7 +271,7 @@ public PlayerType getInvite(UUID uuid) { | |
| } | ||
| return invites.get(uuid); | ||
| } | ||
|
|
||
| /** | ||
| * Removes the invite of a Player | ||
| * @param uuid - The UUID of the player. | ||
|
|
@@ -307,7 +325,7 @@ public boolean isCurrentMember(UUID uuid, PlayerType rank) { | |
|
|
||
| /** | ||
| * @param uuid- The UUID of the player. | ||
| * @return Returns the PlayerType of a UUID. | ||
| * @return Returns the PlayerType of a member UUID. | ||
| */ | ||
| public PlayerType getPlayerType(UUID uuid) { | ||
| PlayerType member = players.get(uuid); | ||
|
|
@@ -319,6 +337,21 @@ public PlayerType getPlayerType(UUID uuid) { | |
| } | ||
| return PlayerType.NOT_BLACKLISTED; | ||
| } | ||
|
|
||
| /** | ||
| * @param uuid- The UUID of the player. | ||
| * @return Returns the PlayerType of an invited UUID. | ||
| */ | ||
| public PlayerType getPlayerInviteType(UUID uuid) { | ||
| PlayerType member = invites.get(uuid); | ||
| if (member != null) { | ||
| return member; | ||
| } | ||
| if (NameLayerPlugin.getBlackList().isBlacklisted(this, uuid)) { | ||
| return null; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Returning
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think I should change this for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think not introducting new pitfalls matters the most. It'd be ideal if the codebase was consistent in its patterns around |
||
| } | ||
| return PlayerType.NOT_BLACKLISTED; | ||
| } | ||
|
|
||
| public PlayerType getCurrentRank(UUID uuid) { | ||
| return players.get(uuid); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine to use, however we do want to move to use Kyoris adventure components
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume that's for future compatibility with 1.19+?