public static ItemStack setItemNameAndLore(ItemStack item, String name, String... lore) {
   ItemMeta im = item.getItemMeta();
   if (name != null) im.setDisplayName(name);
   im.setLore(Arrays.asList(lore));
   item.setItemMeta(im);
   return item;
 }
 public ItemType CheckItem(ItemStack stack)
     throws InvocationTargetException, IllegalAccessException {
   int ItemID = stack.getTypeId();
   byte meta = stack.getData().getData();
   Object item = nmsResolver.getItemList().get(ItemID);
   ForgePermittor.log(item.toString(), true);
   if (item != null) {
     /*  if (this.getInformationManager().HasConnectableInferface(item))
     return ItemType.Connectable;*/
     if (this.getInformationManager().HasItemBlockContainerInterface(item))
       return ItemType.Container;
     if (this.getInformationManager().HasFoodInterface(item)) return ItemType.Food;
     if (this.getInformationManager().HasSwordInterface(item)) return ItemType.Weapon;
     if (this.getInformationManager().HasItemBlockInterface(item))
       return CheckItemBlock(item, ItemID, meta);
     if (this.getInformationManager().HasItemInterface(item)) {
       if (nmsResolver
           .getItemStackHandler()
           .HasTagCompound(nmsResolver.getCraftItemStackHandler().asNMSCopy(stack)))
         return ItemType.AdvItem;
       return ItemType.Item;
     }
   }
   return ItemType.Unknown;
 }
Esempio n. 3
0
  @EventHandler
  public void onClick(PlayerInteractEvent e) {
    if (e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK) {
      if (checkName(e.getPlayer().getItemInHand(), this.name())) {
        ItemStack i = e.getPlayer().getItemInHand();
        List<String> l = i.getItemMeta().getLore();
        String s = l.get(0).replace(ChatColor.GRAY + "", "");
        if (Zephyrus.spellMap.containsKey(s)) {
          Spell spell = Zephyrus.spellMap.get(s);
          Player player = e.getPlayer();
          FileConfiguration cfg = PlayerConfigHandler.getConfig(plugin, player);
          if (!cfg.getStringList("learned").contains(spell.name())) {
            PlayerLearnSpellEvent event = new PlayerLearnSpellEvent(player, spell);
            Bukkit.getServer().getPluginManager().callEvent(event);
            if (!event.isCancelled()) {
              List<String> learned =
                  PlayerConfigHandler.getConfig(plugin, player).getStringList("learned");
              learned.add(spell.name());
              cfg.set("learned", learned);
              e.getPlayer()
                  .sendMessage("You have successfully learned " + ChatColor.GOLD + spell.name());
              e.getPlayer().setItemInHand(null);
              PlayerConfigHandler.saveConfig(plugin, player, cfg);
            }
          } else {
            e.getPlayer().sendMessage("You already know that spell!");
            return;
          }

        } else {
          e.getPlayer().sendMessage("Spell not found...");
        }
      }
    }
  }
Esempio n. 4
0
 /**
  * @param amount size to set the stack to
  * @return an item stack representing this material
  */
 public ItemStack getStack(final int amount) {
   if (amount == 0) return null;
   final ItemStack stack = new ItemStack(getMaterial(), amount, getDurability());
   if (meta == null) return stack;
   stack.setItemMeta(meta);
   return stack;
 }
Esempio n. 5
0
  public void doMake(Player player) throws IOException {
    int num = 1;
    ItemStack item = null;
    BookMeta bm = null;

    FileInputStream fstream =
        new FileInputStream(getDataFolder() + "/" + "Great Expectations-Charles Dickens.txt");
    BufferedInputStream buff = new BufferedInputStream(fstream);
    byte buffer[] = new byte[200];
    int page = 0;
    while (buff.read(buffer) != -1) {
      page++;
      if (page > 300 || bm == null) {
        if (page > 300 && bm != null) {
          page = 0;
          num++;
          item.setItemMeta(bm);
          player.getInventory().addItem(item);
        }

        item = new ItemStack(Material.WRITTEN_BOOK);
        bm = (BookMeta) item.getItemMeta();
        bm.setTitle("Great Expectations Vol. " + num);
        bm.setAuthor("Charles Dickens");
      }
      bm.addPage(new String(buffer));
    }

    item.setItemMeta(bm);
    player.getInventory().addItem(item);
  }
Esempio n. 6
0
 /**
  * Returns the ReinforcementType for a given ItemStack.
  *
  * @param The ItemStack that a player may be holding.
  * @return Returns null if no ReinforcementType is found.
  * @return Returns the ReinforcementType if found.
  */
 public static ReinforcementType getReinforcementType(ItemStack stack) {
   for (ItemStack storedStack : types.keySet())
     if (storedStack.isSimilar(stack)) {
       return types.get(storedStack);
     }
   return null;
 }
Esempio n. 7
0
 public void setInventory(int id, Inventory i) {
   List<ItemStack> actualItems = new ArrayList<ItemStack>();
   for (ItemStack is : i.getContents())
     if (is != null && is.getType() != Material.AIR) actualItems.add(is);
   this.inventory.put(
       id, new SerInventory(actualItems.toArray(new ItemStack[actualItems.size()])));
 }
Esempio n. 8
0
  @SuppressWarnings("deprecation")
  @EventHandler
  public void onInventoryClick(InventoryClickEvent e) {
    Player player = (Player) e.getWhoClicked();
    Inventory inventory = e.getInventory();
    ItemStack currentItem = e.getCurrentItem();

    if (ArenaManager.getInstance().getArena(player) == null) {
      return;
    }

    Plot plot = ArenaManager.getInstance().getArena(player).getPlot(player);

    if (!inventory.getName().equals(ChatColor.GREEN + "Options menu")) {
      return;
    }
    if (currentItem.getType() != Material.HARD_CLAY) {
      return;
    }
    if (!currentItem.hasItemMeta()) {
      return;
    }
    if (!currentItem.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Floor block")) {
      return;
    }

    for (Block block : plot.getFloor().getAllBlocks()) {
      block.setType(e.getCursor().getType());
      block.setData(e.getCursor().getData().getData());
    }

    e.setCancelled(true);
  }
Esempio n. 9
0
 // Returns true if this item matches the item from a recipe
 public static boolean ingredientsMatch(ItemStack usedItem, ItemStack recipeItem) {
   if (!recipeItem.getType().equals(usedItem.getType())) {
     return false;
   }
   return recipeItem.getDurability() == -1
       || recipeItem.getDurability() == usedItem.getDurability();
 }
Esempio n. 10
0
  @EventHandler
  public void onInventoryClick(InventoryClickEvent e) {
    Player player = (Player) e.getWhoClicked();
    Inventory inventory = e.getInventory();
    ItemStack currentItem = e.getCurrentItem();

    if (ArenaManager.getInstance().getArena(player) == null) {
      return;
    }

    Plot plot = ArenaManager.getInstance().getArena(player).getPlot(player);

    if (!inventory.getName().equals(ChatColor.GREEN + "Particles")) {
      return;
    }
    if (currentItem.getType() != Material.LAVA_BUCKET) {
      return;
    }
    if (!currentItem.hasItemMeta()) {
      return;
    }
    if (!currentItem.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Lava drip")) {
      return;
    }

    plot.addParticle(new Particle(player.getLocation(), ParticleType.LAVA_DRIP));
    e.setCancelled(true);
  }
Esempio n. 11
0
  public void applyInventory(BattlePlayer p) {
    Inventory i = p.getInventory();

    ItemStack HEALTH_POTION = new ItemStack(Material.POTION, 1, (short) 16373);
    ItemStack STEAK = new ItemStack(Material.COOKED_BEEF, 1);
    ItemStack BOW = new ItemStack(Material.BOW, 1);
    ItemStack ARROWS = new ItemStack(Material.ARROW, 64);
    ItemStack IRON_HELMET = new ItemStack(Material.IRON_HELMET, 1);
    ItemStack IRON_CHESTPLATE = new ItemStack(Material.IRON_CHESTPLATE, 1);
    ItemStack IRON_PANTS = new ItemStack(Material.IRON_LEGGINGS, 1);
    ItemStack IRON_BOOTS = new ItemStack(Material.IRON_BOOTS, 1);
    ItemStack IRON_SWORD = new ItemStack(Material.IRON_SWORD, 1);
    ItemStack EXP = new ItemStack(Material.EXP_BOTTLE, 5);
    ItemStack ENDER_PEARL = new ItemStack(Material.ENDER_PEARL, 3);
    IRON_BOOTS.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, 4);

    p.getInventory().setBoots(IRON_BOOTS);
    p.getInventory().setLeggings(IRON_PANTS);
    p.getInventory().setChestplate(IRON_CHESTPLATE);
    p.getInventory().setHelmet(IRON_HELMET);

    i.setItem(0, IRON_SWORD);
    i.setItem(1, BOW);
    i.setItem(2, STEAK);
    i.setItem(3, HEALTH_POTION);
    i.setItem(9, ARROWS);
    i.setItem(4, EXP);
    i.setItem(8, ENDER_PEARL);

    p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 1000 * 20, 2));
  }
  public boolean addLot(ItemStack item) {

    AuctionableItem ai = auctionConfig.getAuctionableItemConfig(item);

    if (null == ai) return false;

    double startingPrice = (((int) (ai.getStartingPrice() * 100)) * item.getAmount()) / 100D;
    double minimumIncrement = (((int) (ai.getMinimumIncrement() * 100)) * item.getAmount()) / 100D;

    Lot lot =
        new Lot(
            item,
            false,
            startingPrice,
            null,
            null,
            -1,
            minimumIncrement,
            System.currentTimeMillis() + ai.getPreserveTimeInSeconds() * 1000,
            ai.getAuctionDurationInSeconds() * 1000);
    lots.add(lot);

    LotShowcase.updateAll();

    return true;
  }
 private static String getTitleOfBook(ItemStack book) {
   if (book.getType() == Material.WRITTEN_BOOK && book.hasItemMeta()) {
     BookMeta meta = (BookMeta) book.getItemMeta();
     return meta.getTitle();
   }
   return null;
 }
Esempio n. 14
0
 @EventHandler
 public void onFish(PlayerFishEvent event) {
   Player player = event.getPlayer();
   ItemStack itemStack = player.getItemInHand();
   if (itemStack == null) {
     return;
   }
   if (itemStack.getType() == Material.AIR) {
     return;
   }
   ItemMeta meta = itemStack.getItemMeta();
   if (meta == null) {
     return;
   }
   Map<Enchantment, Integer> enchants = meta.getEnchants();
   if (enchants == null) {
     return;
   }
   if (enchants.isEmpty()) {
     return;
   }
   for (Entry<Enchantment, Integer> entry : enchants.entrySet()) {
     Enchantment enchantment = entry.getKey();
     if (enchantment instanceof IEnchant) {
       IEnchant enchant = (IEnchant) enchantment;
       enchant.onFish(event, entry.getValue());
     }
   }
 }
Esempio n. 15
0
 public static Potion fromItemStack(ItemStack item) {
   Validate.notNull(item, "item cannot be null");
   if (item.getType() != Material.POTION) {
     throw new IllegalArgumentException("item is not a potion");
   }
   return fromDamage(item.getDurability());
 }
  @Override
  public void serializeItemStack(DataOutputStream output, ItemStack stack) throws IOException {
    // Speed things up if the workaround is not required
    if (!isRequired()) {
      super.serializeItemStack(output, stack);
      return;
    }
    NbtCompound tag =
        stack != null && stack.getType() != Material.AIR
            ? NbtFactory.asCompound(NbtFactory.fromItemTag(stack))
            : null;

    // Note that we can't write the stack data directly, as 1.8 switched to sending a
    // item name instead of an item ID.
    if (tag != null) {
      ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
      DataOutputStream dataStream = new DataOutputStream(byteStream);
      ItemStack withoutTag =
          new ItemStack(stack.getType(), stack.getAmount(), stack.getDurability());

      // This will write the stack as normal, without its tag compound and the tag field length
      super.serializeItemStack(dataStream, withoutTag);
      output.write(byteStream.toByteArray(), 0, byteStream.size() - 2);
      serializeCompound(output, tag);

    } else {
      // Write the stack as normal
      super.serializeItemStack(output, stack);
    }
  }
Esempio n. 17
0
  public static void enchantValidate(Player p, String e, int rlvl) { // shut up for now :P
    HashMap<Enchantment, Integer> fen = new HashMap<Enchantment, Integer>();
    ItemStack i = null;
    int lvl = 0;
    Enchantment en = Enchantment.getById(getEnchantId(e));

    if (p.getItemInHand().getTypeId() == ((ItemStack) item.get(p.getName())).getTypeId()) {
      i = p.getItemInHand();
      if (i.getAmount() == 1) {
        if (i.containsEnchantment(en)) {
          int plvl = i.getEnchantmentLevel(en);
          lvl = plvl + rlvl;
        } else {
          lvl = rlvl;
        }
        fen.put(en, lvl);
        enchants.put(p.getName(), fen);
        ChatListener.add(p, 2);
        p.sendMessage(
            "The enchant will cost you: "
                + getEnchantCost(p, e.toLowerCase(), rlvl)
                + "! Should I continue? Please type \"yes\" or \"no\"!");
      } else {
        p.sendMessage(
            ChatColor.RED + "You have more then one item in your slot, please try again!");
      }
    }
  }
Esempio n. 18
0
 /** Gather a collection full of Drugs */
 public int gatherDrugs() {
   int totalDrugs = 0;
   for (String key : config.getConfigurationSection("DrugIds").getKeys(false)) {
     String path = "DrugIds." + key + ".";
     if (!drugProblem(key)) {
       Material mat = Material.getMaterial(key.split(":")[0]);
       short dmg = (key.split(":").length == 1) ? 0 : Short.parseShort(key.split(":")[1]);
       ItemStack item = new ItemStack(mat, 0, dmg);
       String name = config.getString(path + "DrugName");
       String message =
           (config.getString(path + "Message") != null) ? config.getString(path + "Message") : "";
       String type = config.getString(path + "Type");
       String[] effects = config.getString(path + "Effect").replaceAll(" ", "").split(",");
       String[] negatives = config.getString(path + "Negatives").replaceAll(" ", "").split(",");
       int negChance =
           (config.getInt(path + "NegChance") != 0) ? config.getInt(path + "NegChance") : 0;
       boolean smoke = config.getBoolean(path + "Smoke");
       boolean negative = (negChance != 0);
       boolean sneak = config.getBoolean(path + "MustSneak");
       boolean edible =
           item.getType().isEdible() || item.getType().name().equalsIgnoreCase("POTION");
       drugs.put(
           item,
           new Drug(
               item, name, message, type, effects, negatives, negChance, smoke, negative, sneak,
               edible));
       totalDrugs++;
     } else {
       plugin.log.info("Problem loading drug '" + key + "'!");
     }
   }
   return totalDrugs;
 }
Esempio n. 19
0
 public ReinforcementType(
     Material mat,
     int amount,
     double percentReturn,
     int returnValue,
     int hitpoints,
     int maturationTime,
     int acidTime,
     int scale,
     List<String> lore,
     ReinforcementEffect effect,
     Set<Material> allowsReinforceables,
     Set<Material> disallowedReinforceables) {
   this.mat = mat;
   this.amount = amount;
   this.percentReturn = percentReturn / 100;
   this.returnValue = returnValue;
   this.hitpoints = hitpoints;
   this.maturationTime = maturationTime;
   this.acidTime = acidTime;
   this.scale = scale;
   this.effect = effect;
   ItemStack stack = new ItemStack(mat, amount);
   ItemMeta meta = stack.getItemMeta();
   meta.setLore(lore);
   stack.setItemMeta(meta);
   this.stack = stack;
   types.put(stack, this);
   this.allowedReinforceables = allowsReinforceables;
   this.disallowedReinforceables = disallowedReinforceables;
 }
Esempio n. 20
0
  public boolean addEnchantmentsToPlayerInventorySlot(
      String playerName, int slot, List<Object> enchantments) {
    try {
      Player p = getPlayerExact(playerName);
      PlayerInventory inv = p.getInventory();
      ItemStack it;

      if (slot == inv.getHeldItemSlot()) it = inv.getHelmet();
      else if (slot == 102) it = inv.getChestplate();
      else if (slot == 101) it = inv.getLeggings();
      else if (slot == 100) it = inv.getBoots();
      else it = inv.getItem(slot);

      for (int i = 0; i < enchantments.size(); i++) {
        JSONObject o = (JSONObject) enchantments.get(i);
        it.addEnchantment(
            Enchantment.getById(Integer.valueOf(o.get("enchantment").toString())),
            Integer.valueOf(o.get("level").toString()));
      }

      p.saveData();

      return true;
    } catch (NullPointerException e) {
      return false;
    }
  }
  @EventHandler(priority = EventPriority.NORMAL)
  public void grapple(ProjectileHitEvent event) {
    Entity proj = event.getEntity();
    Location hit = proj.getLocation();

    if (contains(hit, x1, x2, y1, y2, z1, z2) == true) {

      if (proj instanceof Snowball) {
        Snowball fish = (Snowball) proj;
        Entity shooter = fish.getShooter();

        if (shooter instanceof Player) {
          Player p = (Player) shooter;
          Location loc = p.getLocation();
          ItemStack is = p.getItemInHand();
          Material mat = is.getType();

          if (mat == Material.FISHING_ROD) {

            p.setFallDistance(0);
            p.playSound(loc, Sound.ARROW_HIT, 1, 1);

            int hitx = hit.getBlockX();
            int hity = hit.getBlockY();
            int hitz = hit.getBlockZ();
            int locx = loc.getBlockX();
            int locy = loc.getBlockY();
            int locz = loc.getBlockZ();
            double co[] = new double[3];

            if (hitx > locx) {
              co[0] = 1.2;
            } else if (hitx < locx) {
              co[0] = -1.2;
            } else if (hitx == locx) {
              co[0] = 0;
            }

            if (hity > locy) {
              co[1] = 1.4;
            } else if (hity < locy) {
              co[1] = -0.8;
            } else if (hity == locy) {
              co[1] = 0;
            }

            if (hitz > locz) {
              co[2] = 1.2;
            } else if (hitz < locz) {
              co[2] = -1.2;
            } else if (hitz == locz) {
              co[2] = 0;
            }

            p.setVelocity(new Vector(co[0], co[1], co[2]));
          }
        }
      }
    }
  }
Esempio n. 22
0
  public boolean setPlayerInventorySlotWithDataAndDamage(
      String playerName, int slot, int blockID, final int data, int damage, int quantity) {
    try {
      if (blockID == 0) {
        return clearPlayerInventorySlot(playerName, slot);
      }

      Player p = getPlayerExact(playerName);
      PlayerInventory inv = p.getInventory();

      ItemStack it = (new MaterialData(blockID, (byte) data)).toItemStack(quantity);
      it.setDurability((short) data);

      if (slot == 103) inv.setHelmet(it);
      else if (slot == 102) inv.setChestplate(it);
      else if (slot == 101) inv.setLeggings(it);
      else if (slot == 100) inv.setBoots(it);
      else inv.setItem(slot, it);

      p.saveData();

      return true;
    } catch (NullPointerException e) {
      return false;
    }
  }
Esempio n. 23
0
 @EventHandler
 public void onInteract(PlayerInteractEvent pie) {
   if (pie.getAction().equals(Action.RIGHT_CLICK_BLOCK)
       || pie.getAction().equals(Action.RIGHT_CLICK_AIR)) {
     Player player = pie.getPlayer();
     World world = player.getWorld();
     if (player.getInventory().getItemInHand() != null) {
       ItemStack item = player.getInventory().getItemInHand();
       if (item.getType().equals(Material.DOUBLE_PLANT)) {
         pie.setCancelled(true);
         Item bomb = world.dropItem(player.getEyeLocation(), new ItemStack(Material.GOLD_BLOCK));
         bomb.setPickupDelay(Integer.MAX_VALUE);
         bomb.setVelocity(player.getLocation().getDirection().multiply(0.5));
         double radius = 1.5;
         for (double i = 0; i <= 20D; i += 0.1) {
           Item coin = world.dropItem(bomb.getLocation(), new ItemStack(Material.DOUBLE_PLANT));
           double x = Math.sin(radius * i);
           double z = Math.cos(radius * i);
           Bukkit.getScheduler()
               .scheduleSyncDelayedTask(
                   Factions.instance,
                   new Runnable() {
                     public void run() {}
                   },
                   1);
         }
       }
     }
   }
 }
Esempio n. 24
0
  @Override
  public SpellResult start(CastContext context) {
    Mage mage = context.getMage();
    MageController controller = context.getController();
    Player player = mage.getPlayer();
    if (player == null) {
      return SpellResult.PLAYER_REQUIRED;
    }

    List<Player> allPlayers = null;
    players.clear();

    if (allowCrossWorld) {
      allPlayers = new ArrayList<>(controller.getPlugin().getServer().getOnlinePlayers());
    } else {
      allPlayers = context.getLocation().getWorld().getPlayers();
    }

    Collections.sort(
        allPlayers,
        new Comparator<Player>() {
          @Override
          public int compare(Player p1, Player p2) {
            return p1.getDisplayName().compareTo(p2.getDisplayName());
          }
        });

    int index = 0;
    for (Player targetPlayer : allPlayers) {
      if (!context.getTargetsCaster() && targetPlayer == player) continue;
      if (targetPlayer.hasPotionEffect(PotionEffectType.INVISIBILITY)) continue;
      if (!context.canTarget(targetPlayer)) continue;
      players.put(index++, new WeakReference<>(targetPlayer));
    }
    if (players.size() == 0) return SpellResult.NO_TARGET;

    String inventoryTitle = context.getMessage("title", "Select Player");
    int invSize = ((players.size() + 9) / 9) * 9;
    Inventory displayInventory = CompatibilityUtils.createInventory(null, invSize, inventoryTitle);
    for (Map.Entry<Integer, WeakReference<Player>> entry : players.entrySet()) {
      Player targetPlayer = entry.getValue().get();
      if (targetPlayer == null) continue;

      String name = targetPlayer.getName();
      String displayName = targetPlayer.getDisplayName();
      ItemStack playerItem = InventoryUtils.getPlayerSkull(targetPlayer, displayName);
      if (!name.equals(displayName)) {
        ItemMeta meta = playerItem.getItemMeta();
        List<String> lore = new ArrayList<>();
        lore.add(name);
        meta.setLore(lore);
        playerItem.setItemMeta(meta);
      }
      displayInventory.setItem(entry.getKey(), playerItem);
    }
    active = true;
    mage.activateGUI(this, displayInventory);

    return SpellResult.NO_ACTION;
  }
 @EventHandler
 public void onBreak(BlockBreakEvent bbe) {
   if (!(bbe.isCancelled())) {
     Block block = bbe.getBlock();
     if (bbe.getPlayer() != null) {
       Player breaker = bbe.getPlayer();
       UUID uuid = breaker.getUniqueId();
       if (block.getState().getType().equals(Material.REDSTONE_ORE)
           || block.getType().equals(Material.REDSTONE_ORE)) {
         boolean notSilkTouch = true;
         if (breaker.getInventory().getItemInHand() != null) {
           ItemStack handItem = breaker.getInventory().getItemInHand();
           if (handItem.containsEnchantment(Enchantment.SILK_TOUCH)) {
             notSilkTouch = false;
           }
         }
         boolean lowLevel = true;
         int level = LevelManager.getLevel(breaker);
         if (level > 30) {
           lowLevel = false;
         }
         if (notSilkTouch && lowLevel) {
           int broke = LevelingXP_Breaking.get(uuid);
           broke += 1;
           if (broke >= (10 * LevelManager.getLevel(breaker))) {
             XPmanager.giveXP(breaker, 80);
           } else {
             LevelingXP_Breaking.set(uuid, broke);
           }
         }
       }
     }
   }
 }
Esempio n. 26
0
 @EventHandler(priority = EventPriority.MONITOR)
 public void onPlayerInteract(PlayerInteractEvent e) {
   ItemStack stack = e.getItem();
   if (e.getPlayer().isOp()) {
     if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)
         && stack != null
         && stack.getType().equals(wand)) {
       if (a.get(e.getPlayer().getName()) == null
           || (b.get(e.getPlayer().getName()) != null && a.get(e.getPlayer().getName()) != null)) {
         a.put(e.getPlayer().getName(), e.getClickedBlock().getLocation());
         b.remove(e.getPlayer().getName());
         e.getPlayer()
             .sendMessage(
                 ChatColor.AQUA
                     + "Selected block A: "
                     + e.getClickedBlock().getLocation().toVector().toString());
       } else if (b.get(e.getPlayer().getName()) == null) {
         b.put(e.getPlayer().getName(), e.getClickedBlock().getLocation());
         e.getPlayer()
             .sendMessage(
                 ChatColor.AQUA
                     + "Selected block B: "
                     + e.getClickedBlock().getLocation().toVector().toString());
       }
     }
   }
 }
Esempio n. 27
0
 public static ItemStack makeItem(Material material, int amount, int type, String name) {
   ItemStack item = new ItemStack(material, amount, (short) type);
   ItemMeta m = item.getItemMeta();
   m.setDisplayName(color(name));
   item.setItemMeta(m);
   return item;
 }
Esempio n. 28
0
  /*
   * @Return: True if they have an ability matching the held item. False if
   * they do not have any abilities matching held item
   */
  public boolean useAbility(Player sender, Player target) {
    // check if they're holding anything
    if (sender.getItemInHand() == null) {
      return false;
    }

    ItemStack i = sender.getItemInHand();

    // sees if they are fightclassed
    FightClass f = FightClass.get(sender);
    // goes through each ability, seeeing if any of the MID's match the
    // lore of the item
    for (Ability a : f.getAbilities()) {
      if (i.getItemMeta().hasLore()
          && i.getItemMeta().getLore().get(0).equalsIgnoreCase(a.getMID())) {
        // check if cost is able to be paid, and pay it
        if (a.useCost(sender)) {
          if (!sender.equals(target)) {
            a.effect(sender, target);
          }
        } else {
          // nothing
        }
        return true;
      }
    }
    return false;
  }
Esempio n. 29
0
 /**
  * Creates a new ItemStack of a material with a displayName
  *
  * @param type Material of the item
  * @param name DisplayName of the item
  * @return ItemStack that was created
  */
 public static ItemStack item(Material type, String name) {
   ItemStack item = new ItemStack(type);
   ItemMeta meta = item.getItemMeta();
   meta.setDisplayName(name);
   item.setItemMeta(meta);
   return item;
 }
  @SuppressWarnings("deprecation")
  private void onLobbyInventoryClick(InventoryClickEvent ice, Player player, Game game) {
    Inventory inv = ice.getInventory();
    ItemStack clickedStack = ice.getCurrentItem();

    if (!inv.getTitle().equals(Main._l("lobby.chooseteam"))) {
      ice.setCancelled(true);
      return;
    }

    if (clickedStack == null) {
      ice.setCancelled(true);
      return;
    }

    if (clickedStack.getType() != Material.WOOL) {
      return;
    }

    ice.setCancelled(true);
    Team team = game.getTeamByDyeColor(DyeColor.getByData(clickedStack.getData().getData()));
    if (team == null) {
      return;
    }

    game.playerJoinTeam(player, team);
    player.closeInventory();
  }