From bafec950b3edbaa82ba68a3c4f5930252ffe8b95 Mon Sep 17 00:00:00 2001 From: MrJeremyFisher <63616270+MrJeremyFisher@users.noreply.github.com> Date: Thu, 29 Feb 2024 12:41:15 -0500 Subject: [PATCH 1/2] Add nllim --- .../mc/namelayer/command/CommandHandler.java | 38 +++++++- .../command/commands/ListInvites.java | 88 +++++++++++++++++++ .../vg/civcraft/mc/namelayer/group/Group.java | 63 ++++++++++--- 3 files changed, 176 insertions(+), 13 deletions(-) create mode 100644 plugins/namelayer-paper/src/main/java/vg/civcraft/mc/namelayer/command/commands/ListInvites.java diff --git a/plugins/namelayer-paper/src/main/java/vg/civcraft/mc/namelayer/command/CommandHandler.java b/plugins/namelayer-paper/src/main/java/vg/civcraft/mc/namelayer/command/CommandHandler.java index 3ca900be4..b3ad95d69 100644 --- a/plugins/namelayer-paper/src/main/java/vg/civcraft/mc/namelayer/command/CommandHandler.java +++ b/plugins/namelayer-paper/src/main/java/vg/civcraft/mc/namelayer/command/CommandHandler.java @@ -2,16 +2,47 @@ package vg.civcraft.mc.namelayer.command; import co.aikar.commands.BukkitCommandCompletionContext; import co.aikar.commands.CommandCompletions; -import java.util.Arrays; -import java.util.stream.Collectors; import vg.civcraft.mc.civmodcore.commands.CommandManager; import vg.civcraft.mc.namelayer.GroupManager; import vg.civcraft.mc.namelayer.NameLayerPlugin; import vg.civcraft.mc.namelayer.command.TabCompleters.GroupTabCompleter; -import vg.civcraft.mc.namelayer.command.commands.*; +import vg.civcraft.mc.namelayer.command.commands.AcceptInvite; +import vg.civcraft.mc.namelayer.command.commands.AddBlacklist; +import vg.civcraft.mc.namelayer.command.commands.ChangePlayerName; +import vg.civcraft.mc.namelayer.command.commands.CreateGroup; +import vg.civcraft.mc.namelayer.command.commands.DeleteGroup; +import vg.civcraft.mc.namelayer.command.commands.DisciplineGroup; +import vg.civcraft.mc.namelayer.command.commands.GetDefaultGroup; +import vg.civcraft.mc.namelayer.command.commands.GlobalStats; +import vg.civcraft.mc.namelayer.command.commands.GroupStats; +import vg.civcraft.mc.namelayer.command.commands.InfoDump; +import vg.civcraft.mc.namelayer.command.commands.InvitePlayer; +import vg.civcraft.mc.namelayer.command.commands.JoinGroup; +import vg.civcraft.mc.namelayer.command.commands.LeaveGroup; +import vg.civcraft.mc.namelayer.command.commands.ListCurrentInvites; +import vg.civcraft.mc.namelayer.command.commands.ListGroups; +import vg.civcraft.mc.namelayer.command.commands.ListInvites; +import vg.civcraft.mc.namelayer.command.commands.ListMembers; +import vg.civcraft.mc.namelayer.command.commands.ListPermissions; +import vg.civcraft.mc.namelayer.command.commands.ListPlayerTypes; +import vg.civcraft.mc.namelayer.command.commands.ModifyPermissions; +import vg.civcraft.mc.namelayer.command.commands.NameLayerGroupGui; +import vg.civcraft.mc.namelayer.command.commands.PromotePlayer; +import vg.civcraft.mc.namelayer.command.commands.RejectInvite; +import vg.civcraft.mc.namelayer.command.commands.RemoveBlacklist; +import vg.civcraft.mc.namelayer.command.commands.RemoveMember; +import vg.civcraft.mc.namelayer.command.commands.RevokeInvite; +import vg.civcraft.mc.namelayer.command.commands.SetDefaultGroup; +import vg.civcraft.mc.namelayer.command.commands.SetPassword; +import vg.civcraft.mc.namelayer.command.commands.ShowBlacklist; +import vg.civcraft.mc.namelayer.command.commands.ToggleAutoAcceptInvites; +import vg.civcraft.mc.namelayer.command.commands.TransferGroup; +import vg.civcraft.mc.namelayer.command.commands.UpdateName; import vg.civcraft.mc.namelayer.permission.PermissionType; import javax.annotation.Nonnull; +import java.util.Arrays; +import java.util.stream.Collectors; public class CommandHandler extends CommandManager{ @@ -33,6 +64,7 @@ public class CommandHandler extends CommandManager{ 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()); diff --git a/plugins/namelayer-paper/src/main/java/vg/civcraft/mc/namelayer/command/commands/ListInvites.java b/plugins/namelayer-paper/src/main/java/vg/civcraft/mc/namelayer/command/commands/ListInvites.java new file mode 100644 index 000000000..83f9a5e71 --- /dev/null +++ b/plugins/namelayer-paper/src/main/java/vg/civcraft/mc/namelayer/command/commands/ListInvites.java @@ -0,0 +1,88 @@ +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 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; + +import java.util.List; +import java.util.UUID; + +public class ListInvites extends BaseCommandMiddle { + + @CommandAlias("nllim|listinvites|listinvitedmembers") + @Syntax(" [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; + } + + assert group != null; + 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 uuids; + if (playerType != null && playerName != null) { + List 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); + + if (!uuids.isEmpty()) { + 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"); + } + } else sb.append("No invites found"); + + sender.sendMessage(sb.toString()); + } +} \ No newline at end of file diff --git a/plugins/namelayer-paper/src/main/java/vg/civcraft/mc/namelayer/group/Group.java b/plugins/namelayer-paper/src/main/java/vg/civcraft/mc/namelayer/group/Group.java index 403357c32..c6e6c6502 100644 --- a/plugins/namelayer-paper/src/main/java/vg/civcraft/mc/namelayer/group/Group.java +++ b/plugins/namelayer-paper/src/main/java/vg/civcraft/mc/namelayer/group/Group.java @@ -3,6 +3,13 @@ package vg.civcraft.mc.namelayer.group; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; +import vg.civcraft.mc.namelayer.GroupManager; +import vg.civcraft.mc.namelayer.GroupManager.PlayerType; +import vg.civcraft.mc.namelayer.NameAPI; +import vg.civcraft.mc.namelayer.NameLayerPlugin; +import vg.civcraft.mc.namelayer.database.GroupManagerDao; + +import javax.annotation.Nullable; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -10,11 +17,6 @@ import java.util.Map; import java.util.Set; import java.util.UUID; import java.util.logging.Level; -import vg.civcraft.mc.namelayer.GroupManager; -import vg.civcraft.mc.namelayer.GroupManager.PlayerType; -import vg.civcraft.mc.namelayer.NameAPI; -import vg.civcraft.mc.namelayer.NameLayerPlugin; -import vg.civcraft.mc.namelayer.database.GroupManagerDao; public class Group { @@ -105,15 +107,38 @@ public class Group { * @return Returns all the UUIDS of the specific PlayerType. */ public List getAllMembers(PlayerType type) { - List uuids = Lists.newArrayList();; - for (Map.Entry entry : players.entrySet()) { + List uuids = Lists.newArrayList(); + for (Map.Entry entry : players.entrySet()) { if (entry.getValue() == type) { uuids.add(entry.getKey()); } } return uuids; } - + + /** + * Returns all the uuids of the invitees in this group. + * @return Returns all the uuids. + */ + public List getAllInvites() { + return Lists.newArrayList(invites.keySet()); + } + + /** + * Returns all the invited UUIDS of a group's PlayerType. + * @param type The PlayerType of a group that you want the UUIDs of. + * @return Returns all the invited UUIDS of the specific PlayerType. + */ + public List getAllInvites(PlayerType type) { + List uuids = Lists.newArrayList(); + for (Map.Entry entry : invites.entrySet()) { + if (entry.getValue() == type) { + uuids.add(entry.getKey()); + } + } + return uuids; + } + /** * Gives the uuids of the members whose name starts with the given * String, this is not case-sensitive @@ -307,8 +332,9 @@ public class Group { /** * @param uuid- The UUID of the player. - * @return Returns the PlayerType of a UUID. + * @return Returns the PlayerType of a member UUID. */ + @Nullable public PlayerType getPlayerType(UUID uuid) { PlayerType member = players.get(uuid); if (member != null) { @@ -319,7 +345,24 @@ public class Group { } return PlayerType.NOT_BLACKLISTED; } - + + /** + * @param uuid- The UUID of the player. + * @return Returns the PlayerType of an invited UUID. + */ + @Nullable + public PlayerType getPlayerInviteType(UUID uuid) { + PlayerType invitee = invites.get(uuid); + if (invitee != null) { + return invitee; + } + if (NameLayerPlugin.getBlackList().isBlacklisted(this, uuid)) { + return null; + } + return PlayerType.NOT_BLACKLISTED; + } + + public PlayerType getCurrentRank(UUID uuid) { return players.get(uuid); } From 0bcef3a2f436444a8704ef41dda2c2091fb140f9 Mon Sep 17 00:00:00 2001 From: MrJeremyFisher <63616270+MrJeremyFisher@users.noreply.github.com> Date: Mon, 1 Apr 2024 15:17:54 -0400 Subject: [PATCH 2/2] Requested changes --- .../vg/civcraft/mc/namelayer/group/Group.java | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/plugins/namelayer-paper/src/main/java/vg/civcraft/mc/namelayer/group/Group.java b/plugins/namelayer-paper/src/main/java/vg/civcraft/mc/namelayer/group/Group.java index c6e6c6502..f284ec019 100644 --- a/plugins/namelayer-paper/src/main/java/vg/civcraft/mc/namelayer/group/Group.java +++ b/plugins/namelayer-paper/src/main/java/vg/civcraft/mc/namelayer/group/Group.java @@ -29,14 +29,14 @@ public class Group { private boolean isValid = true; // if false, then group has recently been deleted and is invalid private int id; private Set ids = Sets.newConcurrentHashSet(); - + private Group supergroup; private Set subgroups = Sets.newConcurrentHashSet(); private Map players = Maps.newHashMap(); private Map invites = Maps.newHashMap(); private long activityTimestamp; - public Group(String name, UUID owner, boolean disciplined, + public Group(String name, UUID owner, boolean disciplined, String password, int id, long activityTimestamp) { if (db == null) { db = NameLayerPlugin.getGroupManagerDao(); @@ -108,7 +108,7 @@ public class Group { */ public List getAllMembers(PlayerType type) { List uuids = Lists.newArrayList(); - for (Map.Entry entry : players.entrySet()) { + for (Map.Entry entry : players.entrySet()) { if (entry.getValue() == type) { uuids.add(entry.getKey()); } @@ -121,7 +121,7 @@ public class Group { * @return Returns all the uuids. */ public List getAllInvites() { - return Lists.newArrayList(invites.keySet()); + return new ArrayList<>(invites.keySet()); } /** @@ -130,7 +130,7 @@ public class Group { * @return Returns all the invited UUIDS of the specific PlayerType. */ public List getAllInvites(PlayerType type) { - List uuids = Lists.newArrayList(); + List uuids = new ArrayList<>(invites.size()); for (Map.Entry entry : invites.entrySet()) { if (entry.getValue() == type) { uuids.add(entry.getKey()); @@ -142,7 +142,7 @@ public class Group { /** * Gives the uuids of the members whose name starts with the given * String, this is not case-sensitive - * + * * @param prefix start of the players name * @return list of all players whose name starts with the given string */ @@ -162,7 +162,7 @@ public class Group { /** * Gives the uuids of players who are in this group and whos name is - * within the given range. + * within the given range. * @param lowerLimit lexicographically lowest acceptable name * @param upperLimit lexicographically highest acceptable name * @return list of uuids of all players in the group whose name is within the given range @@ -173,7 +173,7 @@ public class Group { for (UUID member : members) { String name = NameAPI.getCurrentName(member); - if (name.compareToIgnoreCase(lowerLimit) >= 0 + if (name.compareToIgnoreCase(lowerLimit) >= 0 && name.compareToIgnoreCase(upperLimit) <= 0) { uuids.add(member); } @@ -206,7 +206,7 @@ public class Group { public List getSubgroups() { return Lists.newArrayList(subgroups); } - + /** * Checks if a sub group is on a group. * @param group- The SubGroup. @@ -215,7 +215,7 @@ public class Group { public boolean hasSubGroup(Group group){ return subgroups.contains(group); } - + /** * @return Returns the SubGroup for this group if there is one, null otherwise. */ @@ -244,7 +244,7 @@ public class Group { } return supergroup.hasSuperGroup(group); } - + /** * Adds the player to be allowed to join a group into a specific PlayerType. * @param uuid- The UUID of the player. @@ -258,7 +258,7 @@ public class Group { * Adds the player to be allowed to join a group into a specific PlayerType. * @param uuid- The UUID of the player. * @param type- The PlayerType they will be joining. - * @param saveToDB - save the invitation to the DB. + * @param saveToDB - save the invitation to the DB. */ public void addInvite(UUID uuid, PlayerType type, boolean saveToDB){ invites.put(uuid, type); @@ -290,7 +290,7 @@ public class Group { /** * Removes the invite of a Player * @param uuid- The UUID of the player. - * @param saveToDB - remove the invitation from the DB. + * @param saveToDB - remove the invitation from the DB. */ public void removeInvite(UUID uuid, boolean saveToDB){ invites.remove(uuid); @@ -370,7 +370,7 @@ public class Group { /** * Adds a member to a group. * @param uuid- The uuid of the player. - * @param type- The PlayerType to add. If a preexisting PlayerType is found, + * @param type- The PlayerType to add. If a preexisting PlayerType is found, * it will be overwritten. */ @@ -419,17 +419,17 @@ public class Group { } /** - * + * * @param supergroup the base group * @param subgroup the group to link under it - * @param saveToDb - add link to the DB. + * @param saveToDb - add link to the DB. * @return true if linking succeeded, false otherwise. */ public static boolean link(Group supergroup, Group subgroup, boolean saveToDb) { if (supergroup == null || subgroup == null) { return false; } - + if (supergroup.equals(subgroup)) { return false; } @@ -446,7 +446,7 @@ public class Group { if (!supergroup.hasSubGroup(subgroup)) { supergroup.subgroups.add(subgroup); } - if (saveToDb) { + if (saveToDb) { db.addSubGroup(supergroup.getName(), subgroup.getName()); } @@ -454,7 +454,7 @@ public class Group { } /** - * + * * @param supergroup the main group * @param subgroup the sub group to unlink * @return true if unlink succeeded, false otherwise @@ -463,18 +463,18 @@ public class Group { return unlink(supergroup,subgroup, true); } public static boolean unlink(Group supergroup, Group subgroup, boolean savetodb) { - if (supergroup == null || subgroup == null) { + if (supergroup == null || subgroup == null) { return false; } - + if (subgroup.hasSuperGroup() && subgroup.supergroup.equals(supergroup)) { subgroup.supergroup = null; } if (supergroup.hasSubGroup(subgroup)) { supergroup.subgroups.remove(subgroup); - } - + } + if (savetodb){ db.removeSubGroup(supergroup.getName(), subgroup.getName()); } @@ -507,7 +507,7 @@ public class Group { /** * Sets the default group for a player * @param uuid- The UUID of the player. - * + * */ public void setDefaultGroup(UUID uuid) { NameLayerPlugin.getDefaultGroupHandler().setDefaultGroup(uuid, this); @@ -551,14 +551,14 @@ public class Group { /** * Gets the id for a group. *

- * Note: + * Note: * Keep in mind though if you are trying to get a group_id from a GroupCreateEvent event * it will not be accurate. You must have a delay for 1 tick for it to work correctly. *

- * Also calling the GroupManager.getGroup(int) will return a group that either has that + * Also calling the GroupManager.getGroup(int) will return a group that either has that * group id or the object associated with that id. As such if a group is previously called * and which didn't have the same id as the one called now you could get a different group id. - * Example would be System.out.println(GroupManager.getGroup(1).getGroupId()) and that + * Example would be System.out.println(GroupManager.getGroup(1).getGroupId()) and that * could equal something like 2. * @return the group id for a group. */ @@ -567,7 +567,7 @@ public class Group { /** * Addresses issue above somewhat. Allows implementations that need the whole list of Ids * associated with this groupname to get them. - * + * * @return list of ids paired with this group name. */ public List getGroupIds() { return new ArrayList(this.ids); }