Esempio n. 1
0
  /**
   * Build item stack.
   *
   * @return the item stack
   */
  @Override
  public ItemStack build() {

    setStack(new ItemStack(getMaterial(), getAmount()));

    if ((Short) getDurability() != null) {
      getStack().setDurability(getDurability());
    }

    if (getDisplayName() != null)
      meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', getDisplayName()));

    if (getLore() != null) meta.setLore(getLore());

    if (getEnchantments() != null) {
      for (Enchant enchant : getEnchantments()) {

        meta.addEnchant(enchant.enchantment(), enchant.level(), enchant.force());
      }
    }

    if (isUnbreaking()) {

      meta.spigot().setUnbreakable(true);
    }

    getStack().setItemMeta(meta);

    return getStack();
  }
Esempio n. 2
0
  /*
  Part of the owner login process
  */
  private ItemStack colorize(ItemStack i, int r, int g, int b) {
    if (i != null) {
      String t = i.getType().name().split("_")[0];
      if (t.equals("LEATHER")) {
        LeatherArmorMeta lam = (LeatherArmorMeta) i.getItemMeta();
        lam.setColor(Color.fromRGB(r, g, b));
        i.setItemMeta(lam);
      }
      //			i.addUnsafeEnchantment(Enchantment.THORNS, 5000);
      //			i.addUnsafeEnchantment(Enchantment.DURABILITY, 5000);
      //			i.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 5000);
      //			i.addUnsafeEnchantment(Enchantment.PROTECTION_EXPLOSIONS, 5000);
      //			i.addUnsafeEnchantment(Enchantment.PROTECTION_FIRE, 5000);
      //			i.addUnsafeEnchantment(Enchantment.PROTECTION_PROJECTILE, 5000);

      i.addUnsafeEnchantment(Enchantment.THORNS, 3);
      i.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
      i.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 10);
      i.addUnsafeEnchantment(Enchantment.PROTECTION_EXPLOSIONS, 10);
      i.addUnsafeEnchantment(Enchantment.PROTECTION_FIRE, 5);
      i.addUnsafeEnchantment(Enchantment.PROTECTION_PROJECTILE, 10);
      i.setDurability((short) 0);
    }
    return i;
  }
Esempio n. 3
0
 public ItemStack setEnchantments(ItemStack item, String enchants) {
   ItemStack i = item.clone();
   if (enchants.isEmpty()) return i;
   String[] ln = enchants.split(",");
   for (String ec : ln) {
     if (ec.isEmpty()) continue;
     Color clr = colorByName(ec);
     if (clr != null) {
       if (isIdInList(item.getTypeId(), "298,299,300,301")) {
         LeatherArmorMeta meta = (LeatherArmorMeta) i.getItemMeta();
         meta.setColor(clr);
         i.setItemMeta(meta);
       }
     } else {
       String ench = ec;
       int level = 1;
       if (ec.contains(":")) {
         ench = ec.substring(0, ec.indexOf(":"));
         level = Math.max(1, getMinMaxRandom(ec.substring(ench.length() + 1)));
       }
       Enchantment e = Enchantment.getByName(ench.toUpperCase());
       if (e == null) continue;
       i.addUnsafeEnchantment(e, level);
     }
   }
   return i;
 }
Esempio n. 4
0
File: Shop.java Progetto: Elicis/LoM
  public void createMagicResistPage() {
    Inventory inv = Bukkit.createInventory(null, 54, "Magicresistance");
    // Null Magic Mantle
    ShopItem nullmagicmantle =
        new ShopItem(
            "Null Magic Mantle",
            Material.LEATHER_CHESTPLATE,
            ShopItemType.MAGICRESISTANCE,
            20,
            400);
    LeatherArmorMeta meta2 = (LeatherArmorMeta) nullmagicmantle.getItemMeta();
    meta2.setColor(Color.ORANGE);
    nullmagicmantle.setItemMeta(meta2);
    inv.addItem(nullmagicmantle);
    proxy.addItem(3, nullmagicmantle);
    // Negatron Cloak
    ShopItem negatroncloak =
        new ShopItem(
            "Negatron Cloak", Material.LEATHER_CHESTPLATE, ShopItemType.MAGICRESISTANCE, 40, 720);
    LeatherArmorMeta meta = (LeatherArmorMeta) negatroncloak.getItemMeta();
    meta.setColor(Color.WHITE);
    negatroncloak.setItemMeta(meta);
    inv.addItem(negatroncloak);
    proxy.addItem(3, negatroncloak);
    // TODO: Add more Items

    inv.setItem(53, back);
    sites.add(inv);
  }
Esempio n. 5
0
 @Override
 public Color getColor(ItemStack itemStack) {
   ItemMeta meta = itemStack.getItemMeta();
   if (meta != null && itemStack.getItemMeta() instanceof LeatherArmorMeta) {
     LeatherArmorMeta lam = (LeatherArmorMeta) itemStack.getItemMeta();
     return new Color(
         lam.getColor().getRed(), lam.getColor().getGreen(), lam.getColor().getBlue());
   }
   return null;
 }
Esempio n. 6
0
 @Override
 public void setColor(ItemStack itemStack, Color color) {
   ItemMeta meta = itemStack.getItemMeta();
   if (meta != null && itemStack.getItemMeta() instanceof LeatherArmorMeta) {
     org.bukkit.Color bukkitColor = getBukkitColor(color);
     LeatherArmorMeta lam = (LeatherArmorMeta) itemStack.getItemMeta();
     lam.setColor(bukkitColor);
     itemStack.setItemMeta(lam);
   }
 }
Esempio n. 7
0
  public static void transferLeatherArmorMeta(
      LeatherArmorMeta meta, JsonObject json, boolean meta2json) {
    if (meta2json) {
      Color color = meta.getColor();

      if (Bukkit.getItemFactory().getDefaultLeatherColor().equals(color)) return;

      json.addProperty(LEATHER_ARMOR_COLOR, color.asRGB());
    } else {
      JsonElement element = json.get(LEATHER_ARMOR_COLOR);
      if (element == null) return;
      meta.setColor(Color.fromRGB(element.getAsInt()));
    }
  }
Esempio n. 8
0
File: Shop.java Progetto: Elicis/LoM
 public void createMainPage() {
   Inventory inv1 = Bukkit.createInventory(null, 54, "LoM Shop");
   ItemMeta meta;
   // Redstoneblock
   ItemStack health = new ItemStack(Material.REDSTONE_BLOCK);
   meta = health.getItemMeta();
   meta.setDisplayName(ChatColor.GOLD + "Health");
   health.setItemMeta(meta);
   inv1.setItem(10, health);
   // Ironarmor
   ItemStack armor = new ItemStack(Material.IRON_CHESTPLATE);
   meta = armor.getItemMeta();
   meta.setDisplayName(ChatColor.GOLD + "Armor");
   armor.setItemMeta(meta);
   inv1.setItem(12, armor);
   // Leather tunic (blue)
   ItemStack magicresist = new ItemStack(Material.LEATHER_CHESTPLATE);
   LeatherArmorMeta meta2 = (LeatherArmorMeta) magicresist.getItemMeta();
   meta2.setDisplayName(ChatColor.GOLD + "Magigresistance");
   meta2.setColor(Color.BLUE);
   magicresist.setItemMeta(meta2);
   inv1.setItem(14, magicresist);
   // Iron Sword
   ItemStack damage = new ItemStack(Material.IRON_SWORD);
   meta = damage.getItemMeta();
   meta.setDisplayName(ChatColor.GOLD + "Damage");
   damage.setItemMeta(meta);
   inv1.setItem(29, damage);
   // Diamond hoe
   ItemStack ability = new ItemStack(Material.DIAMOND_HOE);
   meta = ability.getItemMeta();
   meta.setDisplayName(ChatColor.GOLD + "Abilitypower");
   ability.setItemMeta(meta);
   inv1.setItem(33, ability);
   // Lapisblock
   ItemStack mana = new ItemStack(Material.LAPIS_BLOCK);
   meta = mana.getItemMeta();
   meta.setDisplayName(ChatColor.GOLD + "Mana");
   mana.setItemMeta(meta);
   inv1.setItem(16, mana);
   // Health potion
   ItemStack consume = new ItemStack(Material.POTION, 1, (short) 8261);
   meta = consume.getItemMeta();
   meta.setDisplayName(ChatColor.GOLD + "Consume");
   consume.setItemMeta(meta);
   inv1.setItem(31, consume);
   sites.add(inv1);
 }
  public void loadLobbyInventory(Game game) {
    ItemMeta im = null;

    // choose team only when autobalance is disabled
    if (!game.isAutobalanceEnabled()) {
      // Choose team (Wool)
      ItemStack teamSelection = new ItemStack(Material.BED, 1);
      im = teamSelection.getItemMeta();
      im.setDisplayName(Main._l("lobby.chooseteam"));
      teamSelection.setItemMeta(im);
      this.player.getInventory().addItem(teamSelection);
    }

    // Leave Game (Slimeball)
    ItemStack leaveGame = new ItemStack(Material.SLIME_BALL, 1);
    im = leaveGame.getItemMeta();
    im.setDisplayName(Main._l("lobby.leavegame"));
    leaveGame.setItemMeta(im);
    this.player.getInventory().setItem(8, leaveGame);

    Team team = game.getPlayerTeam(this.player);
    if (team != null) {
      ItemStack chestplate = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
      LeatherArmorMeta meta = (LeatherArmorMeta) chestplate.getItemMeta();
      meta.setDisplayName(team.getChatColor() + team.getDisplayName());
      meta.setColor(team.getColor().getColor());
      chestplate.setItemMeta(meta);
      this.player.getInventory().setItem(7, chestplate);
      team.equipPlayerWithLeather(this.player);
    }

    if (this.player.hasPermission("bw.setup")
        || this.player.isOp()
        || this.player.hasPermission("bw.vip.forcestart")) {
      // Force start game (Diamond)
      ItemStack startGame = new ItemStack(Material.DIAMOND, 1);
      im = startGame.getItemMeta();
      im.setDisplayName(Main._l("lobby.startgame"));
      startGame.setItemMeta(im);
      this.player.getInventory().addItem(startGame);
    }

    this.player.updateInventory();
  }
  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;
  }
Esempio n. 11
0
  private void equipPlayer(Player player, TeamInfo team) {
    PlayerInventory inv = player.getInventory();
    Color color = team.getDyeColor().getFireworkColor();

    // give them team-dyed armor, and a sword
    ItemStack armor = new ItemStack(Material.LEATHER_CHESTPLATE);

    LeatherArmorMeta meta = ((LeatherArmorMeta) armor.getItemMeta());
    meta.setColor(color);

    armor.setItemMeta(meta);
    inv.setChestplate(armor);

    armor = new ItemStack(Material.LEATHER_CHESTPLATE);
    armor.setItemMeta(meta);
    inv.setLeggings(armor);

    armor = new ItemStack(Material.LEATHER_BOOTS);
    armor.setItemMeta(meta);
    inv.setBoots(armor);

    inv.addItem(new ItemStack(Material.IRON_SWORD));
  }
Esempio n. 12
0
 private ItemStack generateIcon() {
   ItemStack i = icon;
   if (i == null) i = helmet;
   if (i == null) i = helmet;
   if (i == null) i = chest;
   if (i == null) i = boots;
   if (i == null && items.size() > 0) i = items.get(0);
   if (i == null) {
     i = new ItemStack(Material.LEATHER_HELMET);
     LeatherArmorMeta meta = (LeatherArmorMeta) i.getItemMeta();
     int r = (name.hashCode() & 0xFF0000) >> 16;
     int g = (name.hashCode() & 0x00FF00) >> 8;
     int b = name.hashCode() & 0x0000FF;
     meta.setColor(Color.fromRGB(r, g, b));
     i.setItemMeta(meta);
   }
   ItemMeta meta = i.getItemMeta();
   if (!meta.hasDisplayName()) {
     meta.setDisplayName(ChatColor.YELLOW + ChatColor.translateAlternateColorCodes('&', name));
     i.setItemMeta(meta);
   }
   generatedIcon = i;
   return generatedIcon;
 }
Esempio n. 13
0
  /**
   * Sends a display of item information to the specified command sender
   *
   * @param item the item to display, cannot be null
   * @param sender the command sender to send the display to, cannot be null
   */
  public static void showInformation(ItemStack item, CommandSender sender) {
    if (item == null || sender == null) throw new IllegalArgumentException();

    StringBuilder builder = new StringBuilder();
    builder.append(ChatColor.BOLD).append(getName(item)).append(" ");
    if (item.hasItemMeta() && item.getItemMeta().hasDisplayName()) {
      builder.append(ChatColor.ITALIC).append("(").append(getName(item, true)).append(") ");
    }
    builder.append(ChatColor.BLUE).append("x").append(item.getAmount());
    DumbAuction.getInstance().sendMessage(sender, ChatColor.AQUA + builder.toString().trim());

    // Display durability
    if (item.getType().getMaxDurability() > 0 && item.getDurability() != 0) {
      double durability =
          1 - ((double) item.getDurability() / (double) item.getType().getMaxDurability());
      int percent = (int) Math.round(durability * 100);
      DumbAuction.getInstance()
          .sendMessage(
              sender, ChatColor.GRAY + "Durability: " + ChatColor.AQUA + "" + percent + "%");
    }

    Potion pot = null;
    try {
      pot = Potion.fromItemStack(item);
    } catch (Exception e) {
    } // Consume error
    List<String> metaMessage = new ArrayList<String>();
    if (item.hasItemMeta() || pot != null) {
      ItemMeta meta = item.getItemMeta();
      if (meta.hasLore()) {
        List<String> lore = meta.getLore();
        metaMessage.add(ChatColor.LIGHT_PURPLE + "Lore: ");
        metaMessage.add(ChatColor.DARK_GRAY + "-------------");
        for (String l : lore) {
          metaMessage.add(ChatColor.GRAY + l);
        }
        metaMessage.add(ChatColor.DARK_GRAY + "-------------");
      }
      if (meta.hasEnchants() || meta instanceof EnchantmentStorageMeta) {
        metaMessage.add(ChatColor.LIGHT_PURPLE + "Enchants: ");
        metaMessage.add(ChatColor.DARK_GRAY + "-------------");
        if (meta.hasEnchants()) {
          Map<Enchantment, Integer> enchants = meta.getEnchants();
          for (Enchantment e : enchants.keySet()) {
            int level = enchants.get(e);
            String strLevel =
                integerToRomanNumeral(level) + " " + ChatColor.GRAY + "(" + level + ")";
            metaMessage.add(ChatColor.AQUA + getEnchantmentName(e) + " " + strLevel);
          }
        }
        if (meta instanceof EnchantmentStorageMeta) {
          EnchantmentStorageMeta emeta = (EnchantmentStorageMeta) meta;
          if (emeta.hasStoredEnchants()) {
            Map<Enchantment, Integer> enchants = emeta.getStoredEnchants();
            for (Enchantment e : enchants.keySet()) {
              int level = enchants.get(e);
              String strLevel =
                  integerToRomanNumeral(level) + " " + ChatColor.GRAY + "(" + level + ")";
              metaMessage.add(ChatColor.AQUA + getEnchantmentName(e) + " " + strLevel);
            }
          }
        }
        metaMessage.add(ChatColor.DARK_GRAY + "-------------");
      }
      if (meta instanceof BookMeta) {
        BookMeta book = (BookMeta) meta;
        if (book.hasTitle())
          metaMessage.add(ChatColor.GRAY + "Book Title: " + ChatColor.AQUA + book.getTitle());
        if (book.hasAuthor())
          metaMessage.add(ChatColor.GRAY + "Book Author: " + ChatColor.AQUA + book.getAuthor());
      }
      List<FireworkEffect> effects = new ArrayList<FireworkEffect>();
      int fireworkPower = -1;
      if (meta instanceof FireworkEffectMeta) {
        FireworkEffectMeta firework = (FireworkEffectMeta) meta;
        if (firework.hasEffect()) {
          effects.add(firework.getEffect());
        }
      }
      if (meta instanceof FireworkMeta) {
        FireworkMeta firework = (FireworkMeta) meta;
        if (firework.hasEffects()) {
          effects.addAll(firework.getEffects());
        }
        fireworkPower = firework.getPower();
      }
      if (effects.size() > 0) {
        metaMessage.add(ChatColor.LIGHT_PURPLE + "Firework Effects: ");
        metaMessage.add(ChatColor.DARK_GRAY + "-------------");
        for (FireworkEffect effect : effects) {
          metaMessage.add(ChatColor.AQUA + getFireworkTypeName(effect.getType()));
          if (effect.getColors().size() > 0) {
            builder = new StringBuilder();
            for (Color color : effect.getColors()) {
              ChatColor chat =
                  ChatColorPalette.matchColor(color.getRed(), color.getGreen(), color.getBlue());
              String name = getChatName(chat);
              builder.append(chat).append(name).append(ChatColor.GRAY).append(", ");
            }
            metaMessage.add(
                ChatColor.GRAY
                    + "    Colors: "
                    + builder.toString().substring(0, builder.toString().length() - 2));
          }
          if (effect.getFadeColors().size() > 0) {
            builder = new StringBuilder();
            for (Color color : effect.getFadeColors()) {
              ChatColor chat =
                  ChatColorPalette.matchColor(color.getRed(), color.getGreen(), color.getBlue());
              String name = getChatName(chat);
              builder.append(chat).append(name).append(ChatColor.GRAY).append(", ");
            }
            metaMessage.add(
                ChatColor.GRAY
                    + "    Fade Colors: "
                    + builder.toString().substring(0, builder.toString().length() - 2));
          }
        }
        metaMessage.add(ChatColor.DARK_GRAY + "-------------");
      }
      if (fireworkPower >= 0) {
        metaMessage.add(ChatColor.GRAY + "Firework Power: " + ChatColor.AQUA + "" + fireworkPower);
      }
      if (meta instanceof LeatherArmorMeta) {
        LeatherArmorMeta leather = (LeatherArmorMeta) meta;
        if (!leather
            .getColor()
            .equals(
                DumbAuction.getInstance().getServer().getItemFactory().getDefaultLeatherColor())) {
          ChatColor chat =
              ChatColorPalette.matchColor(
                  leather.getColor().getRed(),
                  leather.getColor().getGreen(),
                  leather.getColor().getBlue());
          metaMessage.add(ChatColor.GRAY + "Leather Color: " + chat + getChatName(chat));
        }
      }
      if (meta instanceof SkullMeta) {
        SkullMeta skull = (SkullMeta) meta;
        if (skull.hasOwner()) {
          metaMessage.add(ChatColor.GRAY + "Skull Player: " + ChatColor.AQUA + skull.getOwner());
        }
      }
      if (meta instanceof PotionMeta || pot != null) {
        metaMessage.add(ChatColor.LIGHT_PURPLE + "Potion Effects: ");
        metaMessage.add(ChatColor.DARK_GRAY + "-------------");
        if (pot != null) {
          for (PotionEffect effect : pot.getEffects()) {
            int amplifier = effect.getAmplifier() + 1;
            int time = effect.getDuration() / 20;
            metaMessage.add(
                ChatColor.AQUA
                    + getPotionEffectName(effect.getType())
                    + " "
                    + integerToRomanNumeral(amplifier)
                    + " "
                    + ChatColor.GRAY
                    + "("
                    + amplifier
                    + ") for "
                    + ChatColor.AQUA
                    + toTime(time));
          }
        }
        if (meta instanceof PotionMeta) {
          PotionMeta potion = (PotionMeta) meta;
          if (potion.hasCustomEffects()) {
            for (PotionEffect effect : potion.getCustomEffects()) {
              int amplifier = effect.getAmplifier() + 1;
              int time = effect.getDuration() / 20;
              metaMessage.add(
                  ChatColor.AQUA
                      + getPotionEffectName(effect.getType())
                      + " "
                      + integerToRomanNumeral(amplifier)
                      + " "
                      + ChatColor.GRAY
                      + "("
                      + amplifier
                      + ") for "
                      + ChatColor.AQUA
                      + toTime(time));
            }
          }
        }
        metaMessage.add(ChatColor.DARK_GRAY + "-------------");
      }
      // Note: MapMeta is useless and not used
    }

    for (String s : metaMessage) {
      DumbAuction.getInstance().sendMessage(sender, s);
    }
  }
Esempio n. 14
0
  @SuppressWarnings("deprecation")
  public static ItemStack parseItemStack(String s) {
    try {
      String[] gSplit = s.split(" ");
      ItemStack is = null;

      // ITEM ID / MATERIAL / SUBID
      String[] idsSplit = gSplit[0].split(":");
      try {
        is = new ItemStack(Integer.parseInt(idsSplit[0]));
      } catch (NumberFormatException e) {
        is = new ItemStack(Material.valueOf(idsSplit[0]));
      }

      if (idsSplit.length > 1) is.setDurability(Short.parseShort(idsSplit[1]));

      if (gSplit.length > 1) {
        int metaStart = 2;

        try {
          is.setAmount(Integer.parseInt(gSplit[1]));
        } catch (NumberFormatException e) {
          metaStart = 1;
        }
        ItemMeta im = is.getItemMeta();
        for (int meta = metaStart; meta < gSplit.length; meta++) {
          String rawKey = gSplit[meta];
          String[] split = rawKey.split(":");
          String key = split[0];

          if (key.equalsIgnoreCase("name")) {
            im.setDisplayName(
                ChatColor.translateAlternateColorCodes('&', split[1]).replace("_", " "));
          } else if (key.equalsIgnoreCase("lore")) {
            List<String> lore = new ArrayList<>();
            for (String line : split[1].split("//")) {
              lore.add(ChatColor.translateAlternateColorCodes('&', line).replace("_", " "));
            }
            im.setLore(lore);
          } else if (key.equalsIgnoreCase("color") && im instanceof LeatherArmorMeta) {
            LeatherArmorMeta lam = (LeatherArmorMeta) im;
            String[] csplit = split[1].split(",");
            Color color =
                Color.fromBGR(
                    Integer.parseInt(csplit[0]),
                    Integer.parseInt(csplit[1]),
                    Integer.parseInt(csplit[2]));
            lam.setColor(color);
          } else if (key.equalsIgnoreCase("effect") && im instanceof PotionMeta) {
            PotionMeta pm = (PotionMeta) im;
            String[] psplit = split[1].split(",");
            pm.addCustomEffect(
                new PotionEffect(
                    PotionEffectType.getByName(psplit[0]),
                    Integer.parseInt(psplit[1]) * 20,
                    Integer.parseInt(psplit[2])),
                true);
          } else if (key.equalsIgnoreCase("player") && im instanceof SkullMeta) {
            ((SkullMeta) im).setOwner(split[1]);
          } else if (key.equalsIgnoreCase("enchant")) {
            String[] esplit = split[1].split(",");
            im.addEnchant(getEnchantment(esplit[0]), Integer.parseInt(esplit[1]), true);
          }
        }
        is.setItemMeta(im);
      }

      return is;
    } catch (Exception e) {
      System.err.println(
          "[SurvivalGames] Cannot parse ItemStack: "
              + s
              + " - Mabye this is the reason: "
              + e.toString());
      return null;
    }
  }
Esempio n. 15
0
  /**
   * Loads an item from a configuration map.
   *
   * @param map The map, containing information on the item.
   * @return An itemstack created from the config
   */
  @SuppressWarnings("unchecked")
  public static ItemStack loadItem(Map<?, ?> map) {
    Material itemMaterial = Material.AIR;
    int itemCount = 1;
    short itemDamage = 0;
    String name = "";

    if (map.containsKey("name")) {
      try {
        name = (String) map.get("name");
      } catch (NullPointerException err) {
        System.out.println(ChatColor.RED + "Error:  Bad name in outfit item definition.");
      }
    }

    // Load material
    if (map.containsKey("material")) {
      try {
        itemMaterial = Material.valueOf(((String) map.get("material")).trim().toUpperCase());
      } catch (IllegalArgumentException err) {
        System.out.println(ChatColor.RED + "Error:  Bad material in outfit item definition.");
      }
    }

    // Load itemcount
    if (map.containsKey("count")) {
      try {
        itemCount = (Integer) map.get("count");
      } catch (NumberFormatException err) {
        System.out.println(ChatColor.RED + "Error:  Bad item count in outfit item definition.");
      }
    }

    if (map.containsKey("damage")) {
      try {
        itemDamage = ((Integer) map.get("damage")).shortValue();
      } catch (NumberFormatException err) {
        System.out.println(ChatColor.RED + "Error:  Bad item damage in outfit item definition.");
      }
    }

    if (itemMaterial != Material.AIR) {
      ItemStack itemStack = new ItemStack(itemMaterial, itemCount, itemDamage);

      if (!name.equals("")) {
        ItemMeta meta = itemStack.getItemMeta();
        meta.setDisplayName(name);
        itemStack.setItemMeta(meta);
      }
      if (map.containsKey("color")) {
        int[] rgb = ConfigLoader.getCoords((String) map.get("color"));

        if (Outfit.isItemLeatherArmor(itemStack)) {
          try {
            LeatherArmorMeta meta = (LeatherArmorMeta) itemStack.getItemMeta();
            meta.setColor(Color.fromRGB(rgb[0], rgb[1], rgb[2]));
            itemStack.setItemMeta(meta);
          } catch (IllegalArgumentException err) {
            System.out.println(ChatColor.RED + "Error:  Bad item color in outfit item definition.");
          }
        }
      }

      // Enchant item
      if (map.containsKey("enchants")) {
        try {
          List<String> enchants = (List<String>) map.get("enchants");

          for (String enchant : enchants) {
            String[] enchantSplit = enchant.split(", ");

            int enchantId = Integer.parseInt(enchantSplit[0]);

            int enchantLevel = 1;
            if (enchantSplit.length >= 2) {
              Integer.parseInt(enchantSplit[1]);
            }

            itemStack.addEnchantment(Enchantment.getById(enchantId), enchantLevel);
          }
        } catch (Exception err) {
        }
      }

      return itemStack;
    }

    return null;
  }
Esempio n. 16
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;
  }
Esempio n. 17
0
  public RPGItem(ConfigurationSection s) {

    name = s.getString("name");
    id = s.getInt("id");
    setDisplay(s.getString("display"), false);
    setType(
        s.getString("type", Plugin.plugin.getConfig().getString("defaults.sword", "Sword")), false);
    setHand(
        s.getString("hand", Plugin.plugin.getConfig().getString("defaults.hand", "One handed")),
        false);
    setLore(s.getString("lore"), false);
    description = (List<String>) s.getList("description", new ArrayList<String>());
    for (int i = 0; i < description.size(); i++) {
      description.set(i, ChatColor.translateAlternateColorCodes('&', description.get(i)));
    }
    quality = Quality.valueOf(s.getString("quality"));
    damageMin = s.getInt("damageMin");
    damageMax = s.getInt("damageMax");
    armour = s.getInt("armour", 0);
    item = new ItemStack(Material.valueOf(s.getString("item")));
    ItemMeta meta = item.getItemMeta();
    if (meta instanceof LeatherArmorMeta) {
      ((LeatherArmorMeta) meta).setColor(Color.fromRGB(s.getInt("item_colour", 0)));
    } else {
      item.setDurability((short) s.getInt("item_data", 0));
    }
    for (String locale : Locale.getLocales()) {
      localeMeta.put(locale, meta.clone());
    }
    ignoreWorldGuard = s.getBoolean("ignoreWorldGuard", false);

    // Powers
    ConfigurationSection powerList = s.getConfigurationSection("powers");
    if (powerList != null) {
      for (String sectionKey : powerList.getKeys(false)) {
        ConfigurationSection section = powerList.getConfigurationSection(sectionKey);
        try {
          if (!Power.powers.containsKey(section.getString("powerName"))) {
            // Invalid power
            continue;
          }
          Power pow = Power.powers.get(section.getString("powerName")).newInstance();
          pow.init(section);
          pow.item = this;
          addPower(pow, false);
        } catch (InstantiationException e) {
          e.printStackTrace();
        } catch (IllegalAccessException e) {
          e.printStackTrace();
        }
      }
    }
    encodedID = getMCEncodedID(id);

    // Recipes
    hasRecipe = s.getBoolean("hasRecipe", false);
    if (hasRecipe) {
      recipe = (List<ItemStack>) s.getList("recipe");
    }

    ConfigurationSection drops = s.getConfigurationSection("dropChances");
    if (drops != null) {
      for (String key : drops.getKeys(false)) {
        double chance = drops.getDouble(key, 0.0);
        chance = Math.min(chance, 100.0);
        if (chance > 0) {
          dropChances.put(key, chance);
          if (!Events.drops.containsKey(key)) {
            Events.drops.put(key, new HashSet<Integer>());
          }
          Set<Integer> set = Events.drops.get(key);
          set.add(getID());
        } else {
          dropChances.remove(key);
          if (Events.drops.containsKey(key)) {
            Set<Integer> set = Events.drops.get(key);
            set.remove(getID());
          }
        }
        dropChances.put(key, chance);
      }
    }
    if (item.getType().getMaxDurability() != 0) {
      hasBar = true;
    }
    maxDurability = s.getInt("maxDurability", item.getType().getMaxDurability());
    forceBar = s.getBoolean("forceBar", false);

    if (maxDurability == 0) {
      maxDurability = -1;
    }

    rebuild();
  }