public void setAutoAccept(UUID player, boolean accept, boolean persistToDb) { if (accept && !autoAccepts.contains(player)) { autoAccepts.add(player); if (persistToDb) { NameLayerPlugin.getGroupManagerDao().autoAcceptGroupsAsync(player); Mercury.addAutoAccept(player); } } else { if (autoAccepts.contains(player)) { autoAccepts.remove(player); if (persistToDb) { NameLayerPlugin.getGroupManagerDao().removeAutoAcceptGroupAsync(player); Mercury.removeAutoAccept(player); } } } }
/** * Creates a list of all Clickables representing members, invitees and blacklisted players, if * they are supposed to be displayed. This is whats directly fed into the middle of the gui */ private List<Clickable> constructClickables() { List<Clickable> clicks = new ArrayList<Clickable>(); if (showInheritedMembers) { if (g.hasSuperGroup()) { clicks.addAll(getRecursiveInheritedMembers(g.getSuperGroup())); } } if (showBlacklist) { final BlackList black = NameLayerPlugin.getBlackList(); for (final UUID uuid : black.getBlacklist(g)) { ItemStack is = new ItemStack(Material.LEATHER_CHESTPLATE); LeatherArmorMeta meta = (LeatherArmorMeta) is.getItemMeta(); meta.setColor(Color.BLACK); meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); is.setItemMeta(meta); ISUtils.setName(is, NameAPI.getCurrentName(uuid)); Clickable c; if (gm.hasAccess(g, p.getUniqueId(), PermissionType.getPermission("BLACKLIST"))) { ISUtils.addLore( is, ChatColor.GREEN + "Click to remove " + NameAPI.getCurrentName(uuid), ChatColor.GREEN + "from the blacklist"); c = new Clickable(is) { @Override public void clicked(Player arg0) { if (gm.hasAccess(g, p.getUniqueId(), PermissionType.getPermission("BLACKLIST"))) { NameLayerPlugin.log( Level.INFO, arg0.getName() + " removed " + NameAPI.getCurrentName(uuid) + " from the blacklist of " + g.getName() + "via gui"); black.removeBlacklistMember(g, uuid, true); p.sendMessage( ChatColor.GREEN + "You removed " + NameAPI.getCurrentName(uuid) + " from the blacklist"); } else { p.sendMessage( ChatColor.RED + "You lost permission to remove this player from the blacklist"); } showScreen(); } }; } else { ISUtils.addLore( is, ChatColor.RED + "You dont have permission to remove", ChatColor.RED + NameAPI.getCurrentName(uuid) + "from the blacklist"); c = new DecorationStack(is); } clicks.add(c); } } if (showInvites) { Map<UUID, PlayerType> invites = NameLayerPlugin.getGroupManagerDao().getInvitesForGroup(g.getName()); for (Entry<UUID, PlayerType> entry : invites.entrySet()) { ItemStack is = new ItemStack(Material.CHAINMAIL_CHESTPLATE); ItemMeta im = is.getItemMeta(); im.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); is.setItemMeta(im); final String playerName = NameAPI.getCurrentName(entry.getKey()); ISUtils.setName(is, ChatColor.GOLD + playerName); boolean canRevoke = false; switch (entry.getValue()) { case MEMBERS: ISUtils.addLore(is, ChatColor.AQUA + "Invited as: Member"); if (gm.hasAccess(g, p.getUniqueId(), PermissionType.getPermission("MEMBERS"))) { canRevoke = true; } break; case MODS: ISUtils.addLore(is, ChatColor.AQUA + "Invited as: Mod"); if (gm.hasAccess(g, p.getUniqueId(), PermissionType.getPermission("MODS"))) { canRevoke = true; } break; case ADMINS: ISUtils.addLore(is, ChatColor.AQUA + "Invited as: Admin"); if (gm.hasAccess(g, p.getUniqueId(), PermissionType.getPermission("ADMINS"))) { canRevoke = true; } break; case OWNER: ISUtils.addLore(is, ChatColor.AQUA + "Invited as: Owner"); if (gm.hasAccess(g, p.getUniqueId(), PermissionType.getPermission("OWNER"))) { canRevoke = true; } break; default: continue; } Clickable c = null; if (canRevoke) { ISUtils.addLore(is, ChatColor.GREEN + "Click to revoke this invite"); c = new Clickable(is) { @Override public void clicked(Player arg0) { UUID invitedUUID = NameAPI.getUUID(playerName); PlayerType pType = g.getInvite(invitedUUID); if (pType == null) { p.sendMessage( ChatColor.RED + "Failed to revoke invite for " + playerName + ". This player isn't invited currently."); showScreen(); } // make sure the player still has permission to do // this boolean allowed = false; switch (pType) { case MEMBERS: allowed = gm.hasAccess(g, p.getUniqueId(), PermissionType.getPermission("MEMBERS")); break; case MODS: allowed = gm.hasAccess(g, p.getUniqueId(), PermissionType.getPermission("MODS")); break; case ADMINS: allowed = gm.hasAccess(g, p.getUniqueId(), PermissionType.getPermission("ADMINS")); break; case OWNER: allowed = gm.hasAccess(g, p.getUniqueId(), PermissionType.getPermission("OWNER")); break; default: allowed = false; break; } if (!allowed) { p.sendMessage( ChatColor.RED + "You don't have permission to revoke this invite"); } else { NameLayerPlugin.log( Level.INFO, arg0.getName() + " revoked an invite for " + NameAPI.getCurrentName(invitedUUID) + " for group " + g.getName() + "via gui"); g.removeInvite(invitedUUID, true); PlayerListener.removeNotification(invitedUUID, g); Mercury.remInvite(g.getGroupId(), invitedUUID); p.sendMessage(ChatColor.GREEN + playerName + "'s invitation has been revoked."); } showScreen(); } }; } else { ISUtils.addLore(is, ChatColor.RED + "You don't have permission to revoke this invite"); c = new DecorationStack(is); } if (c != null) { clicks.add(c); } } } for (UUID uuid : g.getAllMembers()) { Clickable c = null; switch (g.getPlayerType(uuid)) { case MEMBERS: if (showMembers) { c = constructMemberClickable(Material.LEATHER_CHESTPLATE, uuid, PlayerType.MEMBERS); } break; case MODS: if (showMods) { c = constructMemberClickable(Material.GOLD_CHESTPLATE, uuid, PlayerType.MODS); } break; case ADMINS: if (showAdmins) { c = constructMemberClickable(Material.IRON_CHESTPLATE, uuid, PlayerType.ADMINS); } break; case OWNER: if (showOwners) { c = constructMemberClickable(Material.DIAMOND_CHESTPLATE, uuid, PlayerType.OWNER); } break; default: // should never happen } if (c != null) { clicks.add(c); } } return clicks; }
public class InvitePlayer extends PlayerCommandMiddle { private GroupManagerDao db = NameLayerPlugin.getGroupManagerDao(); public InvitePlayer(String name) { super(name); setIdentifier("nlip"); setDescription( "Invite a player to the PlayerType " + PlayerType.toStringName() + " of a group."); setUsage("/nlip <group> <player> (PlayerType- default MEMBERS)"); setArguments(2, 3); } @Override public boolean execute(CommandSender sender, String[] args) { if (!(sender instanceof Player)) { sender.sendMessage(ChatColor.RED + "I'm sorry baby, please run this as a player :)"); return true; } Player p = (Player) sender; Group group = gm.getGroup(args[0]); if (group == null) { p.sendMessage(ChatColor.RED + "That group does not exist."); return true; } if (group.isDisciplined()) { p.sendMessage(ChatColor.RED + "This group is disiplined."); return true; } UUID executor = NameAPI.getUUID(p.getName()); PlayerType pType = PlayerType.MEMBERS; if (args.length == 3) pType = PlayerType.getPlayerType(args[2]); if (pType == null) { PlayerType.displayPlayerTypes(p); return true; } UUID uuid = NameAPI.getUUID(args[1]); if (uuid == null) { p.sendMessage(ChatColor.RED + "The player has never played before."); return true; } GroupPermission perm = gm.getPermissionforGroup(group); PlayerType t = group.getPlayerType(executor); // playertype for the player running the command. if (t == null) { p.sendMessage(ChatColor.RED + "You are not on that group."); return true; } boolean allowed = false; switch (pType) { // depending on the type the executor wants to add the player to case MEMBERS: allowed = perm.isAccessible(t, PermissionType.MEMBERS); break; case MODS: allowed = perm.isAccessible(t, PermissionType.MODS); break; case ADMINS: allowed = perm.isAccessible(t, PermissionType.ADMINS); break; case OWNER: allowed = perm.isAccessible(t, PermissionType.OWNER); break; default: allowed = false; break; } if (!allowed) { p.sendMessage(ChatColor.RED + "You do not have permissions to modify this group."); return true; } if (group.isMember(uuid)) { // So a player can't demote someone who is above them. p.sendMessage( ChatColor.RED + "Player is already a member." + "Use /nlpp to change their PlayerType."); return true; } group.addInvite(uuid, pType); OfflinePlayer invitee = Bukkit.getOfflinePlayer(uuid); boolean shouldAutoAccept = db.shouldAutoAcceptGroups(uuid); if (invitee.isOnline()) { // invitee is online make them a player Player oInvitee = (Player) invitee; if (shouldAutoAccept) { // player auto accepts invite group.addMember(uuid, pType); group.removeRemoveInvite(uuid); if (group instanceof PrivateGroup) { PrivateGroup priv = (PrivateGroup) group; List<Group> groups = priv.getSubGroups(); for (Group g : groups) { g.addMember(uuid, PlayerType.SUBGROUP); } } p.sendMessage( ChatColor.GREEN + "The invitation has been sent." + "\n Use /nlri to Revoke an invite."); oInvitee.sendMessage( ChatColor.GREEN + " You have auto-accepted invite to the group: " + group.getName()); } else { PlayerListener.addNotification(uuid, group); oInvitee.sendMessage( ChatColor.GREEN + "You have been invited to the group " + group.getName() + " by " + p.getName() + ".\n" + "Use the command /nlag <group> to accept.\n" + "If you wish to toggle invites so they always are accepted please run /nltaai"); p.sendMessage( ChatColor.GREEN + "The invitation has been sent." + "\n Use /nlri to Revoke an invite."); } } else { // invitee is offline if (shouldAutoAccept) { group.addMember(uuid, pType); group.removeRemoveInvite(uuid); PlayerListener.addNotification(uuid, group); p.sendMessage( ChatColor.GREEN + "The invitation has been sent." + "\n Use /nlri to Revoke an invite."); } else { // Player did not auto accept PlayerListener.addNotification(uuid, group); p.sendMessage( ChatColor.GREEN + "The invitation has been sent." + "\n Use /nlri to Revoke an invite."); } } return true; } @Override public List<String> tabComplete(CommandSender sender, String[] args) { if (!(sender instanceof Player)) { sender.sendMessage(ChatColor.RED + "I'm sorry baby, please run this as a player :)"); return null; } if (args.length < 2) { if (args.length == 0) return GroupTabCompleter.complete(null, null, (Player) sender); else return GroupTabCompleter.complete(args[0], null, (Player) sender); } else if (args.length == 2) return null; else if (args.length == 3) return MemberTypeCompleter.complete(args[2]); else return null; } }