Skip to content
This repository was archived by the owner on Feb 17, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public void registerCommands(){
registerCommand(new JoinGroup());
registerCommand(new ListGroups());
registerCommand(new ListMembers());
registerCommand(new ListInvites());
registerCommand(new ListPermissions());
//addCommands(new MergeGroups("MergeGroups")); Disabled as it's currently semi broken
registerCommand(new ModifyPermissions());
Expand Down
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.");

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

Copy link
Author

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+?

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");
for (UUID uu: uuids){
sb.append(NameAPI.getCurrentName(uu));
sb.append(" (");
sb.append(group.getPlayerInviteType(uu));
sb.append(")\n");
}

sender.sendMessage(sb.toString());
}
}
53 changes: 43 additions & 10 deletions paper/src/main/java/vg/civcraft/mc/namelayer/group/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand All @@ -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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning null invariably leads to NPEs down the line. Instead, use java.util.Optional or the @Nullable/@NotNull annotations.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think I should change this for /nllm as well? The only reason I have it the way it is is to try and stay consistent with /nllm

Choose a reason for hiding this comment

The 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 null, but that's probably more suited to a dedicated PR.

}
return PlayerType.NOT_BLACKLISTED;
}

public PlayerType getCurrentRank(UUID uuid) {
return players.get(uuid);
Expand Down