Example #1
0
  /**
   * Process the Shroom Thumb ability.
   *
   * @param blockState The {@link BlockState} to check ability activation for
   * @return true if the ability was successful, false otherwise
   */
  public boolean processShroomThumb(BlockState blockState) {
    Player player = getPlayer();
    PlayerInventory playerInventory = player.getInventory();

    if (!playerInventory.contains(Material.BROWN_MUSHROOM)) {
      player.sendMessage(
          LocaleLoader.getString(
              "Skills.NeedMore", StringUtils.getPrettyItemString(Material.BROWN_MUSHROOM)));
      return false;
    }

    if (!playerInventory.contains(Material.RED_MUSHROOM)) {
      player.sendMessage(
          LocaleLoader.getString(
              "Skills.NeedMore", StringUtils.getPrettyItemString(Material.RED_MUSHROOM)));
      return false;
    }

    playerInventory.removeItem(new ItemStack(Material.BROWN_MUSHROOM));
    playerInventory.removeItem(new ItemStack(Material.RED_MUSHROOM));
    player.updateInventory();

    if (!SkillUtils.activationSuccessful(
        SecondaryAbility.SHROOM_THUMB, getPlayer(), getSkillLevel(), activationChance)) {
      player.sendMessage(LocaleLoader.getString("Herbalism.Ability.ShroomThumb.Fail"));
      return false;
    }

    return Herbalism.convertShroomThumb(blockState);
  }
Example #2
0
 public void jobOrientation(Player p) {
   p.setGameMode(GameMode.SURVIVAL);
   if (this.equals(TimeProfession.OFFICER)) {
     PlayerInventory pi = p.getInventory();
     ItemStack inv_item = pi.getItem(0);
     String display_name = "";
     if (inv_item != null) {
       display_name = inv_item.getItemMeta().getDisplayName();
       if (display_name == null) display_name = "";
     }
     if (inv_item == null
         || !inv_item.getType().equals(Material.STICK)
         || !display_name.equals("Baton")) {
       ItemStack is = new ItemStack(Material.STICK, 1);
       ItemStack is_backup = null;
       if (inv_item != null) is_backup = inv_item.clone();
       ItemMeta im = is.getItemMeta();
       im.setDisplayName("Baton");
       ArrayList<String> lore = new ArrayList();
       lore.add("Arrests bountied players");
       im.setLore(lore);
       is.setItemMeta(im);
       pi.setItem(0, is);
       if (inv_item != null) pi.addItem(is_backup);
       p.updateInventory();
     }
   }
 }
Example #3
0
 public static ItemStack getBoots(Inventory inventory) {
   PlayerInventory playerInventory = asPlayerInventory(inventory);
   if (playerInventory == null) return null;
   ItemStack ret = playerInventory.getBoots();
   ret = clean(ret);
   return ret;
 }
  public boolean playerHasBook(Player player, InfoBook infobook) {

    final PlayerInventory invent = player.getInventory();

    if (invent.contains(Material.WRITTEN_BOOK)) {
      for (ItemStack item : invent.getContents()) {
        if (item == null) {
          continue;
        }

        if (item.getType() == Material.WRITTEN_BOOK) {
          final BookMeta bookmeta = (BookMeta) item.getItemMeta();

          if (!infobook.getAuthor().equalsIgnoreCase(bookmeta.getAuthor())) {
            continue;
          }

          if (!infobook.getName().equalsIgnoreCase(bookmeta.getTitle())) {
            continue;
          }

          // The player already has a copy of the given book
          return true;
        }
      }
    }

    return false;
  }
  public void updateSpectatorOnInventory(Player spec) {
    Player player = getPlayer().getPlayer();
    if (player == null) return;

    PlayerInventory inv = player.getInventory();
    int goldIngots = 0;
    int goldenApples = 0;
    int notchApples = 0;
    for (ItemStack is : inv.getContents()) {
      if (is != null) {
        if (is.getType() == Material.GOLD_INGOT) goldIngots += is.getAmount();
        if (is.getType() == Material.GOLD_BLOCK) goldIngots += is.getAmount() * 9;
        if (is.getType() == Material.GOLD_NUGGET) goldIngots += is.getAmount() / 9;

        if (is.getType() == Material.GOLDEN_APPLE) {
          if (is.getDurability() == 0) goldenApples += is.getAmount();
          if (is.getDurability() == 1) notchApples += is.getAmount();
        }
      }
    }

    PluginChannelUtils.messageSpectator(
        spec, "player", getName(), "itemcount", "266", Integer.toString(goldIngots));
    PluginChannelUtils.messageSpectator(
        spec, "player", getName(), "itemcount", "322,0", Integer.toString(goldenApples));
    PluginChannelUtils.messageSpectator(
        spec, "player", getName(), "itemcount", "322,1", Integer.toString(notchApples));
  }
  public GraveInventory(PlayerInventory inventory) {
    this.items = new ItemStack[inventory.getSize()];

    for (int i = 0; i < inventory.getSize(); i++) {
      items[i] = inventory.getItem(i);
    }
  }
Example #7
0
 public static void deduct(ArrayList<ItemStack> reqItems, Player player) {
   PlayerInventory inven = player.getInventory();
   for (int i = 1; i < reqItems.size(); i++) {
     ItemStack currItem = new ItemStack(reqItems.get(i).getTypeId(), reqItems.get(i).getAmount());
     int neededAmount = reqItems.get(i).getAmount();
     int smallestSlot = AlchemySupport.findSmallest(currItem, player);
     while (neededAmount > 0) {
       smallestSlot = AlchemySupport.findSmallest(currItem, player);
       ItemStack smallestItem = inven.getItem(smallestSlot);
       if (neededAmount < smallestItem.getAmount()) {
         // got enough in smallest stack deal and done
         ItemStack newSize =
             new ItemStack(currItem.getType(), smallestItem.getAmount() - neededAmount);
         inven.setItem(smallestSlot, newSize);
         neededAmount = 0;
       } else {
         // need to remove from more than one stack, deal and continue
         neededAmount -= smallestItem.getAmount();
         inven.clear(smallestSlot);
       }
     }
   }
   ItemStack reward = new ItemStack(reqItems.get(0).getTypeId(), reqItems.get(0).getAmount());
   player.sendMessage("§3You have made " + reward.getAmount() + " " + reward.getType());
   inven.addItem(reward);
 }
Example #8
0
 @SuppressWarnings("deprecation")
 private void rewind() {
   player.getInventory().setContents(previousPlayerInv.getContents());
   npc.getInventory().setContents(previousTraderInv.getContents());
   player.updateInventory();
   npc.getPlayer().updateInventory();
 }
  public void clean() {

    PlayerInventory inv = this.player.getInventory();
    inv.setArmorContents(new ItemStack[4]);
    inv.setContents(new ItemStack[] {});

    this.player.setAllowFlight(false);
    this.player.setFlying(false);
    this.player.setExp(0.0F);
    this.player.setLevel(0);
    this.player.setSneaking(false);
    this.player.setSprinting(false);
    this.player.setFoodLevel(20);
    this.player.setMaxHealth(20.0D);
    this.player.setHealth(20.0D);
    this.player.setFireTicks(0);
    this.player.setGameMode(GameMode.SURVIVAL);

    boolean teamnameOnTab = Main.getInstance().getBooleanConfig("teamname-on-tab", true);
    boolean overwriteNames = Main.getInstance().getBooleanConfig("overwrite-names", false);
    if (overwriteNames) {
      Game game = Main.getInstance().getGameManager().getGameOfPlayer(this.player);
      if (game != null) {
        Team team = game.getPlayerTeam(this.player);
        if (team != null) {
          this.player.setDisplayName(team.getChatColor() + this.player.getName());
        } else {
          this.player.setDisplayName(this.player.getName());
        }
      }
    }

    if (teamnameOnTab && Utils.isSupportingTitles()) {
      Game game = Main.getInstance().getGameManager().getGameOfPlayer(this.player);
      if (game != null) {
        Team team = game.getPlayerTeam(this.player);
        if (team != null) {
          this.player.setPlayerListName(
              team.getChatColor()
                  + team.getName()
                  + ChatColor.WHITE
                  + " | "
                  + team.getChatColor()
                  + this.player.getName());
        } else {
          this.player.setPlayerListName(this.player.getName());
        }
      }
    }

    if (this.player.isInsideVehicle()) {
      this.player.leaveVehicle();
    }

    for (PotionEffect e : this.player.getActivePotionEffects()) {
      this.player.removePotionEffect(e.getType());
    }

    this.player.updateInventory();
  }
 private boolean hasEmptyWaterBottle() {
   PlayerInventory inventory = player.getInventory();
   if (inventory.contains(Material.GLASS_BOTTLE)) {
     return true;
   }
   return false;
 }
Example #11
0
 public static void removeTeamHead(final int color, Player p) {
   ItemStack item = getTeamHead(color);
   final PlayerInventory inv = p.getInventory();
   if (inv != null && inv.getHelmet() != null && inv.getHelmet().getType() == item.getType()) {
     inv.setHelmet(new ItemStack(Material.AIR));
   }
 }
 @SuppressWarnings("deprecation")
 public void remoteDonations(Player player) {
   SuperNPlayer snplayer = SuperNManager.get(player);
   PlayerInventory inv = player.getInventory();
   ItemStack[] items = inv.getContents();
   double delta = 0;
   invCheck:
   for (Material mat : SNConfigHandler.priestDonationMap.keySet()) {
     for (ItemStack itemStack : items) {
       if (itemStack != null) {
         if (itemStack.getType().equals(mat)) {
           delta = SNConfigHandler.priestDonationMap.get(mat);
           if (itemStack.getAmount() == 1) {
             inv.clear(inv.first(itemStack.getType()));
           } else {
             itemStack.setAmount(itemStack.getAmount() - 1);
           }
           break invCheck;
         }
       }
     }
   }
   if (delta == 0) {
     SuperNManager.sendMessage(
         snplayer, "The Church only accepts donations of Bread, Fish, Grilled Pork and Apples.");
   } else {
     player.updateInventory();
     SuperNManager.sendMessage(snplayer, "You receive some power for your remote donations.");
     SuperNManager.alterPower(snplayer, delta * .5, "Donations!");
   }
 }
Example #13
0
 // NOTE: We make sure to convert AIR into null due to a Bukkit API inconsistency.
 @SuppressWarnings("deprecation")
 public static ItemStack getWeapon(Inventory inventory) {
   PlayerInventory playerInventory = asPlayerInventory(inventory);
   if (playerInventory == null) return null;
   ItemStack ret = playerInventory.getItemInHand();
   ret = clean(ret);
   return ret;
 }
Example #14
0
  /**
   * Adds items from grave into Player's Inventory Also removes tombstone
   *
   * @param graveRobber The Player taking the items
   */
  public void robGrave(Player graveRobber) {
    PlayerInventory sack = graveRobber.getInventory();

    for (ItemStack item : grave) sack.addItem(item);

    graveRobber.sendMessage(PvPRewardMessages.getGraveRobMsg());
    signLocation.getBlock().setTypeId(0);
    signLocation = null;
  }
Example #15
0
  // Armor contents has always been implemented the same way and can be used directly.
  public static ItemStack[] getContentsArmor(Inventory inventory) {
    PlayerInventory playerInventory = asPlayerInventory(inventory);
    if (playerInventory == null) return null;

    ItemStack[] ret = playerInventory.getArmorContents();

    clean(ret);
    return ret;
  }
Example #16
0
  public static void setShield(Inventory inventory, ItemStack shield) {
    PlayerInventory playerInventory = asPlayerInventory(inventory);
    if (playerInventory == null) return;
    ItemStack[] contents = playerInventory.getContents();

    if (contents.length <= INDEX_PLAYER_SHIELD) return;

    inventory.setItem(INDEX_PLAYER_SHIELD, shield);
  }
Example #17
0
  @Override
  public void run() {
    final PlayerInventory pi = p.getInventory();
    int newAmmount = 0;
    for (final Entry<Integer, ? extends ItemStack> entry : pi.all(targetType.getType()).entrySet())
      newAmmount += entry.getValue().getAmount();

    final int finalItems = newAmmount - currentAmmount;
    mp.addMythicality(value / 100 * finalItems / targetType.getAmount());
  }
Example #18
0
 public static boolean addHead(Player player, String skullOwner, int quantity) {
   PlayerInventory inv = player.getInventory();
   int firstEmpty = inv.firstEmpty();
   if (firstEmpty == -1) {
     return false;
   } else {
     inv.setItem(firstEmpty, Tools.Skull(skullOwner, quantity));
     return true;
   }
 }
Example #19
0
 @SuppressWarnings("deprecation")
 private void handlePlayerClick(int slot, PlayerInventory playerInv) {
   playerInv.setItem(slot, previousPlayerInv.getItem(slot));
   Stockable stockable = getStockable(playerInv.getItem(slot), "bought", true);
   if (stockable == null) {
     return;
   }
   if (prevPlayerSlot != slot) {
     prevPlayerSlot = slot;
     sendStockableMessage(stockable);
     return;
   }
   prevPlayerSlot = slot;
   prevTraderSlot = -1;
   if (checkMiscellaneous(playerInv, stockable, false)) {
     return;
   }
   ItemStack selling = stockable.getStocking().clone();
   if (mode != Mode.INFINITE) {
     EconomyHandler.pay(new Payment(stockable.getPrice()), npc, -1);
   }
   EconomyHandler.pay(new Payment(selling), player, slot);
   HashMap<Integer, ItemStack> unsold = new HashMap<Integer, ItemStack>();
   if (mode != Mode.INFINITE) {
     unsold = npc.getInventory().addItem(selling);
   }
   if (unsold.size() >= 1) {
     rewind();
     player.sendMessage(
         ChatColor.RED
             + "Not enough room available to add "
             + MessageUtils.getStackString(selling, ChatColor.RED)
             + " to the trader's stock.");
     return;
   }
   if (!stockable.isEconPlugin()) {
     ItemStack temp = stockable.getPrice().getItemStack().clone();
     unsold = player.getInventory().addItem(temp);
     if (unsold.size() >= 1) {
       rewind();
       player.sendMessage(
           ChatColor.RED
               + "Not enough room in your inventory to add "
               + MessageUtils.getStackString(stockable.getPrice().getItemStack(), ChatColor.RED)
               + ".");
       return;
     }
   } else {
     double price = stockable.getPrice().getPrice();
     ServerEconomyInterface.add(player.getName(), price);
   }
   npc.getPlayer().updateInventory();
   player.updateInventory();
   player.sendMessage(ChatColor.GREEN + "Transaction successful.");
 }
Example #20
0
 @SuppressWarnings("deprecation")
 private void handleTraderClick(int slot, PlayerInventory npcInv) {
   npcInv.setItem(slot, previousTraderInv.getItem(slot));
   Stockable stockable = getStockable(npcInv.getItem(slot), "sold", false);
   if (stockable == null) {
     return;
   }
   if (prevTraderSlot != slot) {
     prevTraderSlot = slot;
     sendStockableMessage(stockable);
     return;
   }
   prevTraderSlot = slot;
   prevPlayerSlot = -1;
   if (checkMiscellaneous(npcInv, stockable, true)) {
     return;
   }
   // /trader sell 1:1 1:5
   // stocking is 1 stone
   // price is 5 stone
   ItemStack buying = stockable.getStocking().clone();
   EconomyHandler.pay(new Payment(stockable.getPrice()), player, -1);
   if (mode != Mode.INFINITE) {
     EconomyHandler.pay(new Payment(buying), npc, slot);
   }
   HashMap<Integer, ItemStack> unbought = player.getInventory().addItem(buying);
   if (unbought.size() >= 1) {
     rewind();
     player.sendMessage(
         ChatColor.RED
             + "Not enough room in your inventory to add "
             + MessageUtils.getStackString(buying, ChatColor.RED)
             + ".");
     return;
   }
   if (!stockable.isEconPlugin() && mode != Mode.INFINITE) {
     ItemStack temp = stockable.getPrice().getItemStack().clone();
     unbought = npc.getInventory().addItem(temp);
     if (unbought.size() >= 1) {
       rewind();
       player.sendMessage(
           ChatColor.RED
               + "Not enough room in the npc's inventory to add "
               + MessageUtils.getStackString(stockable.getPrice().getItemStack(), ChatColor.RED)
               + ".");
       return;
     }
   } else {
     double price = stockable.getPrice().getPrice();
     npc.setBalance(npc.getBalance() + price);
   }
   npc.getPlayer().updateInventory();
   player.updateInventory();
   player.sendMessage(ChatColor.GREEN + "Transaction successful.");
 }
  @Override
  public void armorCheck(Player player) {
    if (!player.hasPermission("supernatural.player.ignorearmor")) {
      PlayerInventory inv = player.getInventory();
      ItemStack helmet = inv.getHelmet();
      ItemStack chest = inv.getChestplate();
      ItemStack leggings = inv.getLeggings();
      ItemStack boots = inv.getBoots();

      if (helmet != null) {
        if (!SNConfigHandler.priestArmor.contains(helmet.getType())) {
          inv.setHelmet(null);
          dropItem(player, helmet);
        }
      }
      if (chest != null) {
        if (!SNConfigHandler.priestArmor.contains(chest.getType())) {
          inv.setChestplate(null);
          dropItem(player, chest);
        }
      }
      if (leggings != null) {
        if (!SNConfigHandler.priestArmor.contains(leggings.getType())) {
          inv.setLeggings(null);
          dropItem(player, leggings);
        }
      }
      if (boots != null) {
        if (!SNConfigHandler.priestArmor.contains(boots.getType())) {
          inv.setBoots(null);
          dropItem(player, boots);
        }
      }
    }
  }
Example #22
0
  public static ItemStack getShield(Inventory inventory) {
    PlayerInventory playerInventory = asPlayerInventory(inventory);
    if (playerInventory == null) return null;
    ItemStack[] contents = playerInventory.getContents();

    if (contents.length <= INDEX_PLAYER_SHIELD) return null;

    ItemStack ret = contents[INDEX_PLAYER_SHIELD];
    ret = clean(ret);
    return ret;
  }
Example #23
0
  public static int countItemsInInventory(PlayerInventory inventory, ItemStack item) {
    int totalAmount = 0;
    boolean isDurable = Items.itemByStack(item).isDurable();

    for (Integer i : inventory.all(item.getType()).keySet()) {
      ItemStack thisStack = inventory.getItem(i);
      if (!isDurable && thisStack.getDurability() != item.getDurability()) {
        continue;
      }
      totalAmount += thisStack.getAmount();
    }
    return totalAmount;
  }
Example #24
0
  public static void setContentsExtra(Inventory intentory, ItemStack[] extra) {
    PlayerInventory playerInventory = asPlayerInventory(intentory);
    if (playerInventory == null) return;
    ItemStack[] contents = playerInventory.getContents();

    int max = SIZE_PLAYER_EXTRA;
    max = Math.min(max, contents.length - INDEX_PLAYER_EXTRA_FROM);
    max = Math.min(max, extra.length);

    for (int i = 0; i < max; i++) {
      playerInventory.setItem(INDEX_PLAYER_EXTRA_FROM + i, extra[i]);
    }
  }
Example #25
0
  // All content varies over versions.
  // Before 1.9 it was getContents() + getArmorContents() + new ItemStack[1].
  // From and including 1.9 it's just getContents().
  public static ItemStack[] getContentsAll(Inventory inventory) {
    if (inventory == null) return null;
    ItemStack[] contents = inventory.getContents();
    ItemStack[] ret = contents;

    PlayerInventory playerInventory = asPlayerInventory(inventory);
    if (playerInventory != null && contents.length == SIZE_PLAYER_STORAGE) {
      ret = concat(contents, playerInventory.getArmorContents(), new ItemStack[SIZE_PLAYER_EXTRA]);
    }

    clean(ret);
    return ret;
  }
Example #26
0
 @EventHandler
 public void onPlayerJoin(PlayerJoinEvent e) {
   Player player = e.getPlayer();
   PlayerInventory in = player.getInventory();
   String locale = Locale.getPlayerLocale(player);
   for (int i = 0; i < in.getSize(); i++) {
     ItemStack item = in.getItem(i);
     if (ItemManager.toRPGItem(item) != null) RPGItem.updateItem(item, locale);
   }
   for (ItemStack item : player.getInventory().getArmorContents()) {
     if (ItemManager.toRPGItem(item) != null) RPGItem.updateItem(item, locale);
   }
 }
  @SuppressWarnings("deprecation")
  public void PlayerSpawn() {
    player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 8000, 2));

    PlayerInventory i = player.getInventory();
    i.clear();

    i.setHelmet(Colorizer.setColor(new ItemStack(Material.LEATHER_HELMET), 250, 250, 250));
    i.setChestplate(Colorizer.setColor(new ItemStack(Material.LEATHER_CHESTPLATE), 250, 250, 250));

    ItemStack legs = Colorizer.setColor(new ItemStack(Material.LEATHER_LEGGINGS), 250, 250, 250);
    legs.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2);
    i.setLeggings(legs);

    ItemStack boot = Colorizer.setColor(new ItemStack(Material.LEATHER_BOOTS), 250, 250, 250);
    boot.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, 10);
    i.setBoots(boot);

    ItemStack i1 = new ItemStack(Material.BOW);
    i1.addUnsafeEnchantment(Enchantment.ARROW_KNOCKBACK, 3);
    i1.addUnsafeEnchantment(Enchantment.ARROW_INFINITE, 1);
    i.addItem(i1);

    i.addItem(new ItemStack(Material.ARROW, 1));

    player.updateInventory();
  }
Example #28
0
  public static void setAllContents(Inventory from, Inventory to) {
    to.setContents(from.getContents());
    if (from instanceof PlayerInventory) {
      PlayerInventory pfrom = (PlayerInventory) from;
      if (to instanceof PlayerInventory) {
        PlayerInventory pto = (PlayerInventory) to;

        pto.setHelmet(pfrom.getHelmet());
        pto.setChestplate(pfrom.getChestplate());
        pto.setLeggings(pfrom.getLeggings());
        pto.setBoots(pfrom.getBoots());
      }
    }
  }
Example #29
0
 public static boolean equals(Inventory one, Inventory two) {
   if (one == null) return two == null;
   if (two == null) return false;
   if (!equals(one.getContents(), two.getContents())) return false;
   if (one instanceof PlayerInventory) {
     PlayerInventory pone = (PlayerInventory) one;
     if (two instanceof PlayerInventory) {
       PlayerInventory ptwo = (PlayerInventory) two;
       return equals(pone.getArmorContents(), ptwo.getArmorContents());
     } else {
       return false;
     }
   }
   return true;
 }
Example #30
0
  // The extra contents was added in 1.9.
  // It is then at the very end of all of the contents.
  // Slot 40 and forward even though it currently is just a single slot.
  public static ItemStack[] getContentsExtra(Inventory inventory) {
    PlayerInventory playerInventory = asPlayerInventory(inventory);
    if (playerInventory == null) return null;
    ItemStack[] contents = playerInventory.getContents();
    ItemStack[] ret = new ItemStack[SIZE_PLAYER_EXTRA];

    int max = SIZE_PLAYER_EXTRA;
    max = Math.min(max, contents.length - INDEX_PLAYER_EXTRA_FROM);

    for (int i = 0; i < max; i++) {
      ret[i] = contents[INDEX_PLAYER_EXTRA_FROM + i];
    }

    clean(ret);
    return ret;
  }