public static ItemStack getLeatherItemStack(
      Material material, String name, short data, Color color, List<String> lore) {
    /** Item Stack * */
    ItemStack is = getItemStack(material, name, data, lore);

    /** Item meta * */
    LeatherArmorMeta meta = (LeatherArmorMeta) is.getItemMeta();

    /** Item flags * */
    meta.addItemFlags(ItemFlag.values());

    /** Set color * */
    meta.setColor(color);

    /** Set item meta * */
    is.setItemMeta(meta);

    /** Return item * */
    return is;
  }
예제 #2
0
  /**
   * 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;
  }