org.bukkit.inventory.PlayerInventory Java Examples

The following examples show how to use org.bukkit.inventory.PlayerInventory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShopMenuItem.java    From AnnihilationPro with MIT License 9 votes vote down vote up
@Override
public void onItemClick(ItemClickEvent event)
{
	Player player = event.getPlayer();
	PlayerInventory p = player.getInventory();
	if(p.containsAtLeast(new ItemStack(Material.GOLD_INGOT), cost))
	{
		int total = 0;
		for(ItemStack s : p.all(Material.GOLD_INGOT).values())
		{
			total += s.getAmount();
		}
		p.remove(Material.GOLD_INGOT);
		if(total-cost > 0)
			p.addItem(new ItemStack(Material.GOLD_INGOT,total-cost));
		p.addItem(product);
		player.sendMessage(Lang.PURCHASEDITEM.toString());
	}
	else player.sendMessage(Lang.COULDNOTPURCHASE.toString());
}
 
Example #2
Source File: PlayerEvents.java    From uSkyBlock with GNU General Public License v3.0 7 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onClickOnObsidian(final PlayerInteractEvent event) {
    if (!plugin.getWorldManager().isSkyWorld(event.getPlayer().getWorld())) {
        return;
    }
    long now = System.currentTimeMillis();
    Player player = event.getPlayer();
    PlayerInventory inventory = player.getInventory();
    Block block = event.getClickedBlock();
    Long lastClick = obsidianClick.get(player.getUniqueId());
    if (lastClick != null && (lastClick + OBSIDIAN_SPAM) >= now) {
        plugin.notifyPlayer(player, tr("\u00a74You can only convert obsidian once every 10 seconds"));
        return;
    }
    if (Settings.extras_obsidianToLava && plugin.playerIsOnIsland(player)
            && plugin.getWorldManager().isSkyWorld(player.getWorld())
            && event.getAction() == Action.RIGHT_CLICK_BLOCK
            && player.getItemInHand() != null
            && player.getItemInHand().getType() == Material.BUCKET
            && block != null
            && block.getType() == Material.OBSIDIAN
            && !testForObsidian(block)) {
        if (inventory.firstEmpty() != -1) {
            obsidianClick.put(player.getUniqueId(), now);
            player.sendMessage(tr("\u00a7eChanging your obsidian back into lava. Be careful!"));
            inventory.removeItem(new ItemStack(Material.BUCKET, 1));
            inventory.addItem(new ItemStack(Material.LAVA_BUCKET, 1));
            player.updateInventory();
            block.setType(Material.AIR);
            event.setCancelled(true); // Don't execute the click anymore (since that would re-place the lava).
        } else {
            player.sendMessage(tr("\u00a7eYour inventory must have another empty space!"));
        }
    }
}
 
Example #3
Source File: ClearInventoryAction.java    From UHC with MIT License 6 votes vote down vote up
@Override
protected void run(Player player) {
    final PlayerInventory inv = player.getInventory();

    // clear main inventory
    contents = inv.getContents();
    inv.clear();

    // clear armour slots
    armourContents = inv.getArmorContents();
    inv.setArmorContents(null);

    // clear if they have something on their cursour currently
    onCursor = player.getItemOnCursor();
    player.setItemOnCursor(new ItemStack(Material.AIR));

    // if they have a crafting inventory open clear items from it too
    // stops storing items in crafting slots bypassing clear inventories
    final InventoryView openInventory = player.getOpenInventory();
    if (openInventory.getType() == InventoryType.CRAFTING) {
        crafting = Optional.of(openInventory.getTopInventory().getContents());
        openInventory.getTopInventory().clear();
    } else {
        crafting = Optional.absent();
    }
}
 
Example #4
Source File: ItemStacker.java    From TabooLib with MIT License 6 votes vote down vote up
/**
 * 合并物品,不新增
 */
public static AddResult addItemAndMerge(ItemStack item, Inventory inventory, Integer[] ignore) {
    boolean changed = false;
    int count = item.getAmount();
    int size = inventory instanceof PlayerInventory || inventory instanceof CraftingInventory ? 36 : inventory.getSize();
    for (int i = 0; i < size; i++) {
        if (ArrayUtil.contains(ignore, i)) {
            continue;
        }
        ItemStack inventoryItem = inventory.getItem(i);
        if (!item.isSimilar(inventoryItem)) {
            continue;
        }
        while (count > 0 && inventoryItem.getAmount() < item.getType().getMaxStackSize()) {
            changed = true;
            inventoryItem.setAmount(inventoryItem.getAmount() + 1);
            count--;
        }
        if (count == 0) {
            return new AddResult(count, changed);
        }
    }
    return new AddResult(count, changed);
}
 
Example #5
Source File: ItemStacker.java    From TabooLib with MIT License 6 votes vote down vote up
/**
 * 添加并拆分,但不合并
 * 返回值为是否添加完成
 *
 * desc = 快捷栏逆向添加,用于工作台拟真,会忽略 start 参数
 */
public static boolean addItemAndSplit(ItemStack item, Inventory inventory, int start, boolean desc) {
    int size = inventory instanceof PlayerInventory || inventory instanceof CraftingInventory ? 36 : inventory.getSize();
    if (desc) {
        // 8 ~ 0
        for (int i = 8; i >= 0; i--) {
            if (check(item, inventory, i)) {
                return true;
            }
        }
    }
    // 9 ~ 36
    for (int i = desc ? start + 9 : start; i < size; i++) {
        if (check(item, inventory, i)) {
            return true;
        }
    }
    return false;
}
 
Example #6
Source File: ToolRepairMatchModule.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void processRepair(PlayerPickupItemEvent event) {
  ItemStack pickup = event.getItem().getItemStack();

  if (this.toRepair.contains(pickup.getType())) {
    PlayerInventory inv = event.getPlayer().getInventory();
    for (ItemStack invStack :
        Iterables.concat(
            Arrays.asList(inv.getContents()), Arrays.asList(inv.getArmorContents()))) {
      if (this.canRepair(pickup, invStack)) {
        this.doRepair(event, invStack);
        return;
      }
    }
  }
}
 
Example #7
Source File: GraphListener.java    From LagMonitor with MIT License 6 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onInteract(PlayerInteractEvent clickEvent) {
    Player player = clickEvent.getPlayer();
    PlayerInventory inventory = player.getInventory();

    ItemStack mainHandItem;
    if (mainHandSupported) {
        mainHandItem = inventory.getItemInMainHand();
    } else {
        mainHandItem = inventory.getItemInHand();
    }

    if (isOurGraph(mainHandItem)) {
        inventory.setItemInMainHand(new ItemStack(Material.AIR));
    }
}
 
Example #8
Source File: MiscUtils.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void giveItemsToPlayer(List<ItemStack> itemStackList, Player player, TeamColor teamColor) {
    for (ItemStack itemStack : itemStackList) {
        final String materialName = itemStack.getType().toString();
        final PlayerInventory playerInventory = player.getInventory();

        if (materialName.contains("HELMET")) {
            playerInventory.setHelmet(Main.applyColor(teamColor, itemStack));
        } else if (materialName.contains("CHESTPLATE")) {
            playerInventory.setChestplate(Main.applyColor(teamColor, itemStack));
        } else if (materialName.contains("LEGGINGS")) {
            playerInventory.setLeggings(Main.applyColor(teamColor, itemStack));
        } else if (materialName.contains("BOOTS")) {
            playerInventory.setBoots(Main.applyColor(teamColor, itemStack));
        } else {
            playerInventory.addItem(Main.applyColor(teamColor, itemStack));
        }
    }
}
 
Example #9
Source File: PWIPlayerManagerTest.java    From PerWorldInventory with GNU General Public License v3.0 6 votes vote down vote up
private Player mockPlayer(String name, GameMode gameMode) {
    Player mock = mock(Player.class);
    PlayerInventory inv = mock(PlayerInventory.class);
    inv.setContents(new ItemStack[39]);
    inv.setArmorContents(new ItemStack[4]);

    Inventory enderChest = mock(Inventory.class);
    enderChest.setContents(new ItemStack[27]);

    given(mock.getInventory()).willReturn(inv);
    given(mock.getEnderChest()).willReturn(enderChest);
    given(mock.getName()).willReturn(name);
    given(mock.getUniqueId()).willReturn(TestHelper.TEST_UUID);
    given(mock.getGameMode()).willReturn(gameMode);
    AttributeInstance attribute = mock(AttributeInstance.class);
    given(mock.getAttribute(Attribute.GENERIC_MAX_HEALTH)).willReturn(attribute);
    given(attribute.getBaseValue()).willReturn(20.0);

    return mock;
}
 
Example #10
Source File: ItemKeepPlayerFacet.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
public void restoreKeptInventory() {
    final List<ItemStack> displaced = new ArrayList<>();
    final PlayerInventory inv = bukkit.getInventory();

    kept.forEach((slot, keptStack) -> {
        final ItemStack invStack = slot.getItem(bukkit);

        if(invStack == null || slot instanceof Slot.Armor) {
            slot.putItem(inv, keptStack);
        } else {
            if(invStack.isSimilar(keptStack)) {
                int n = Math.min(keptStack.getAmount(), invStack.getMaxStackSize() - invStack.getAmount());
                invStack.setAmount(invStack.getAmount() + n);
                keptStack.setAmount(keptStack.getAmount() - n);
            }
            if(keptStack.getAmount() > 0) {
                displaced.add(keptStack);
            }
        }

        for(ItemStack stack : displaced) {
            inv.addItem(stack);
        }
    });
    kept.clear();
}
 
Example #11
Source File: ViewInventoryMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
public void previewInventory(Player viewer, Inventory realInventory) {
    if(viewer == null) { return; }

    if(realInventory instanceof PlayerInventory) {
        previewPlayerInventory(viewer, (PlayerInventory) realInventory);
    }else {
        Inventory fakeInventory;
        if(realInventory instanceof DoubleChestInventory) {
            if(realInventory.hasCustomName()) {
                fakeInventory = Bukkit.createInventory(viewer, realInventory.getSize(), realInventory.getName());
            } else {
                fakeInventory = Bukkit.createInventory(viewer, realInventory.getSize());
            }
        } else {
            if(realInventory.hasCustomName()) {
                fakeInventory = Bukkit.createInventory(viewer, realInventory.getType(), realInventory.getName());
            } else {
                fakeInventory = Bukkit.createInventory(viewer, realInventory.getType());
            }
        }
        fakeInventory.setContents(realInventory.contents());

        this.showInventoryPreview(viewer, realInventory, fakeInventory);
    }
}
 
Example #12
Source File: CivilianListener.java    From Civs with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onInventoryMoveEvent(InventoryMoveItemEvent event) {
    if (ConfigManager.getInstance().getAllowSharingCivsItems()) {
        return;
    }
    if (!CVItem.isCivsItem(event.getItem())) {
        return;
    }
    if (!(event.getDestination() instanceof PlayerInventory)) {
        event.setCancelled(true);
        if (!event.getSource().getViewers().isEmpty()) {
            HumanEntity humanEntity = event.getSource().getViewers().get(0);
            humanEntity.sendMessage(Civs.getPrefix() +
                    LocaleManager.getInstance().getTranslationWithPlaceholders((Player) humanEntity,
                            LocaleConstants.PREVENT_CIVS_ITEM_SHARE));
        }
    }
}
 
Example #13
Source File: InventorySerializer.java    From PerWorldInventory with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Sets the Inventory using an ItemStack array constructed from a JsonObject.
 *
 * @param player The InventoryHolder to which the Inventory will be set
 * @param inv    The reference JsonArray
 * @param format Data format being used; 0 is old, 1 is new
 */
public void setInventory(Player player, JsonObject inv, int format) {
    PlayerInventory inventory = player.getInventory();
    
    ItemStack[] armor = deserializeInventory(inv.getAsJsonArray("armor"), 4, format);
    ItemStack[] inventoryContents = deserializeInventory(inv.getAsJsonArray("inventory"), inventory.getSize(), format);

    inventory.clear();
    if (armor != null) {
    	inventory.setArmorContents(armor);
    }
    
    if (inventoryContents != null) {
    	inventory.setContents(inventoryContents);
    }
   
}
 
Example #14
Source File: EntityDamage.java    From AdditionsAPI with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityDamage(EntityDamageEvent event) {
	if (event.isCancelled())
		return;

	DamageCause cause = event.getCause();
	Entity damagee = event.getEntity();
	EntityType damageeType = damagee.getType();
	// PlayerCustomArmorDamageEvent
	if (damageeType == EntityType.PLAYER) {
		Player player = (Player) damagee;
		PlayerInventory inv = player.getInventory();
		for (ItemStack armor : inv.getArmorContents())
			// TODO: Speed up
			if (armor != null && armor.getType() != Material.AIR && AdditionsAPI.isCustomItem(armor)
					&& new CustomItemStack(armor).getCustomItem() instanceof CustomArmor
					&& new CustomItemStack(armor).getCustomItem()
							.getDurabilityMechanics() instanceof ArmorDurability) {
				CustomArmor cArmor = (CustomArmor) new CustomItemStack(armor).getCustomItem();
				Bukkit.getServer().getPluginManager().callEvent(new PlayerCustomArmorDamageEvent(player, armor,
						cArmor, cause, (float) event.getDamage(), armor.containsEnchantment(Enchantment.THORNS)));
			}
	}
}
 
Example #15
Source File: MiscUtils.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void giveItemsToPlayer(List<ItemStack> itemStackList, Player player, TeamColor teamColor) {
    for (ItemStack itemStack : itemStackList) {
        final String materialName = itemStack.getType().toString();
        final PlayerInventory playerInventory = player.getInventory();

        if (materialName.contains("HELMET")) {
            playerInventory.setHelmet(Main.applyColor(teamColor, itemStack));
        } else if (materialName.contains("CHESTPLATE")) {
            playerInventory.setChestplate(Main.applyColor(teamColor, itemStack));
        } else if (materialName.contains("LEGGINGS")) {
            playerInventory.setLeggings(Main.applyColor(teamColor, itemStack));
        } else if (materialName.contains("BOOTS")) {
            playerInventory.setBoots(Main.applyColor(teamColor, itemStack));
        } else {
            playerInventory.addItem(Main.applyColor(teamColor, itemStack));
        }
    }
}
 
Example #16
Source File: Compat19.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent e) {
    Player p = e.getPlayer();

    // Glide options
    if (!p.hasPermission("redprotect.bypass.glide")) {
        if (!RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).player_glide.allow_elytra) {
            ItemStack item = p.getInventory().getChestplate();
            if (item != null && item.getType().equals(Material.ELYTRA)) {
                PlayerInventory inv = p.getInventory();
                inv.setChestplate(new ItemStack(Material.AIR));
                if (inv.firstEmpty() == -1) {
                    p.getWorld().dropItem(p.getLocation(), item);
                } else {
                    inv.setItem(inv.firstEmpty(), item);
                }
                p.playSound(p.getLocation(), Sound.ENTITY_ITEM_PICKUP, 10, 1);
                RedProtect.get().lang.sendMessage(p, "globallistener.elytra.cantequip");
            }
        }
    }
}
 
Example #17
Source File: Main.java    From ArmorStandTools with MIT License 6 votes vote down vote up
void restoreInventory(Player p) {
    removeAllTools(p);
    UUID uuid = p.getUniqueId();
    ItemStack[] savedInv = savedInventories.get(uuid);
    if(savedInv == null) return;
    PlayerInventory plrInv = p.getInventory();
    ItemStack[] newItems = plrInv.getContents().clone();
    plrInv.setContents(savedInv);
    savedInventories.remove(uuid);
    for(ItemStack i : newItems) {
        if(i == null) continue;
        HashMap<Integer, ItemStack> couldntFit = plrInv.addItem(i);
        for (ItemStack is : couldntFit.values()) {
            p.getWorld().dropItem(p.getLocation(), is);
        }
    }
    p.sendMessage(ChatColor.GREEN + Config.invReturned);
}
 
Example #18
Source File: NewItemShop.java    From BedwarsRel with GNU General Public License v3.0 6 votes vote down vote up
private boolean hasEnoughRessource(Player player, VillagerTrade trade) {
  ItemStack item1 = trade.getItem1();
  ItemStack item2 = trade.getItem2();
  PlayerInventory inventory = player.getInventory();

  if (item2 != null) {
    if (!inventory.contains(item1.getType(), item1.getAmount())
        || !inventory.contains(item2.getType(), item2.getAmount())) {
      return false;
    }
  } else {
    if (!inventory.contains(item1.getType(), item1.getAmount())) {
      return false;
    }
  }

  return true;
}
 
Example #19
Source File: ArmorKeep.java    From CardinalPGM with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPgmSpawn(CardinalSpawnEvent event) {
    Player player = event.getPlayer();
    PlayerInventory inventory = player.getInventory();
    if (helmet.containsKey(player)) {
        if (helmet.get(player) != null) {
            inventory.setHelmet(helmet.get(player));
        }
    }
    if (chestplate.containsKey(player)) {
        if (chestplate.get(player) != null) {
            inventory.setChestplate(chestplate.get(player));
        }
    }
    if (leggings.containsKey(player)) {
        if (leggings.get(player) != null) {
            inventory.setLeggings(leggings.get(player));
        }
    }
    if (boots.containsKey(player)) {
        if (boots.get(player) != null) {
            inventory.setBoots(boots.get(player));
        }
    }
}
 
Example #20
Source File: PWIPlayerManagerTest.java    From PerWorldInventory with GNU General Public License v3.0 6 votes vote down vote up
private Player mockPlayer(String name, GameMode gameMode) {
    Player mock = mock(Player.class);
    PlayerInventory inv = mock(PlayerInventory.class);
    inv.setContents(new ItemStack[39]);
    inv.setArmorContents(new ItemStack[4]);

    Inventory enderChest = mock(Inventory.class);
    enderChest.setContents(new ItemStack[27]);

    given(mock.getInventory()).willReturn(inv);
    given(mock.getEnderChest()).willReturn(enderChest);
    given(mock.getName()).willReturn(name);
    given(mock.getUniqueId()).willReturn(TestHelper.TEST_UUID);
    given(mock.getGameMode()).willReturn(gameMode);
    AttributeInstance attribute = mock(AttributeInstance.class);
    given(mock.getAttribute(Attribute.GENERIC_MAX_HEALTH)).willReturn(attribute);
    given(attribute.getBaseValue()).willReturn(20.0);

    return mock;
}
 
Example #21
Source File: InventorySerializer.java    From PerWorldInventory with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Sets the Inventory using an ItemStack array constructed from a JsonObject.
 *
 * @param player The InventoryHolder to which the Inventory will be set
 * @param inv    The reference JsonArray
 * @param format Data format being used; 0 is old, 1 is new
 */
public void setInventory(Player player, JsonObject inv, int format) {
    PlayerInventory inventory = player.getInventory();
    
    ItemStack[] armor = deserializeInventory(inv.getAsJsonArray("armor"), 4, format);
    ItemStack[] inventoryContents = deserializeInventory(inv.getAsJsonArray("inventory"), inventory.getSize(), format);

    inventory.clear();
    if (armor != null) {
    	inventory.setArmorContents(armor);
    }
    
    if (inventoryContents != null) {
    	inventory.setContents(inventoryContents);
    }
   
}
 
Example #22
Source File: GraphListener.java    From LagMonitor with MIT License 6 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onInteract(PlayerInteractEvent clickEvent) {
    Player player = clickEvent.getPlayer();
    PlayerInventory inventory = player.getInventory();

    ItemStack mainHandItem;
    if (mainHandSupported) {
        mainHandItem = inventory.getItemInMainHand();
    } else {
        mainHandItem = inventory.getItemInHand();
    }

    if (isOurGraph(mainHandItem)) {
        inventory.setItemInMainHand(new ItemStack(Material.AIR));
    }
}
 
Example #23
Source File: InvUtils.java    From CS-CoreLib with GNU General Public License v3.0 6 votes vote down vote up
public static boolean fits(Inventory inv, ItemStack item) {
	Inventory inv2 = null;
	int size = inv.getSize();
	if (inv instanceof PlayerInventory) {
		size = 36;
		inv2 = Bukkit.createInventory(null, size);
	}
	else if (inv.getSize() % 9 == 0) {
		inv2 = Bukkit.createInventory(null, size);
	}
	else {
		inv2 = Bukkit.createInventory(null, inv.getType());
	}
	for (int i = 0; i < size; i++) {
		inv2.setItem(i, inv.getItem(i));
	}
	return inv2.addItem(item).isEmpty();
}
 
Example #24
Source File: JavaUtils.java    From StaffPlus with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the slot of the given item through iteration.
 * 
 * @param player The inventory to iterate through.
 * @param item The ItemStack to check for.
 * @return The found slot in the inventory.
 */
public static int getItemSlot(PlayerInventory inventory, ItemStack item)
{
	int slot = 0;
	ItemStack[] contents = inventory.getContents();
	
	for(int i = 0; i < contents.length; i++)
	{
		ItemStack current = contents[i];
		
		if(current == null)
		{
			continue;
		}
		
		if(current.equals(item))
		{
			slot = i;
			break;
		}
	}
	
	return slot;
}
 
Example #25
Source File: BlockIgnite.java    From AdditionsAPI with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockIgnite(BlockIgniteEvent event) {
	if (event.getPlayer() == null)
		return;
	PlayerInventory inv = event.getPlayer().getInventory();
	ItemStack item = inv.getItemInMainHand();
	if (ItemType.getItemType(item) != ItemType.FLINT_AND_STEEL) {
		item = inv.getItemInOffHand();
		if (ItemType.getItemType(item) != ItemType.FLINT_AND_STEEL)
			return;
	}
	if (AdditionsAPI.isCustomItem(item)) {
		CustomItemBlockIgniteEvent customEvent = new CustomItemBlockIgniteEvent(event, new CustomItemStack(item));
		Bukkit.getServer().getPluginManager().callEvent(customEvent);
	}
}
 
Example #26
Source File: ItemType.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets copy of storage contents, i.e. ignores armor and off hand. This is due to Spigot 1.9
 * added armor slots, and off hand to default inventory index.
 * @param invi Inventory
 * @return Copied storage contents
 */
public static ItemStack[] getStorageContents(final Inventory invi) {
	if (invi instanceof PlayerInventory) {
		ItemStack[] buf = invi.getContents();
		ItemStack[] tBuf = new ItemStack[36];
		for (int i = 0; i < 36; i++)
			if (buf[i] != null)
				tBuf[i] = buf[i].clone();
		return tBuf;
	} else return getCopiedContents(invi);
}
 
Example #27
Source File: PlayerFish.java    From AdditionsAPI with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerFishEvent(PlayerFishEvent event) {
	PlayerInventory inv = event.getPlayer().getInventory();
	ItemStack item = inv.getItemInMainHand();
	if (ItemType.getItemType(item) != ItemType.FISHING_ROD) {
		item = inv.getItemInOffHand();
		if (ItemType.getItemType(item) != ItemType.FISHING_ROD)
			return;
	}
	if (AdditionsAPI.isCustomItem(item))
		Bukkit.getServer().getPluginManager().callEvent(new CustomItemFishEvent(event, new CustomItemStack(item)));
}
 
Example #28
Source File: ScoreMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
private double redeemItems(ScoreBox box, PlayerInventory inventory) {
  ItemStack[] notArmor = inventory.getContents();
  ItemStack[] armor = inventory.getArmorContents();

  double points = redeemItems(box, notArmor) + redeemItems(box, armor);

  if (points != 0) {
    inventory.setContents(notArmor);
    inventory.setArmorContents(armor);
  }

  return points;
}
 
Example #29
Source File: PlayerShearEntity.java    From AdditionsAPI with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerShearEntity(PlayerShearEntityEvent event) {
	PlayerInventory inv = event.getPlayer().getInventory();
	ItemStack item = inv.getItemInMainHand();
	if (ItemType.getItemType(item) != ItemType.SHEARS) {
		item = inv.getItemInOffHand();
		if (ItemType.getItemType(item) != ItemType.SHEARS)
			return;
	}
	if (AdditionsAPI.isCustomItem(item)) {
		CustomItemShearEntityEvent customEvent = new CustomItemShearEntityEvent(event, new CustomItemStack(item));
		Bukkit.getServer().getPluginManager().callEvent(customEvent);
	}
}
 
Example #30
Source File: ViewInventoryMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
public void previewInventory(Player viewer, Inventory realInventory) {
  if (viewer == null) {
    return;
  }

  if (realInventory instanceof PlayerInventory) {
    previewPlayerInventory(viewer, (PlayerInventory) realInventory);
  } else {
    Inventory fakeInventory;
    if (realInventory instanceof DoubleChestInventory) {
      if (realInventory.hasCustomName()) {
        fakeInventory =
            Bukkit.createInventory(viewer, realInventory.getSize(), realInventory.getName());
      } else {
        fakeInventory = Bukkit.createInventory(viewer, realInventory.getSize());
      }
    } else {
      if (realInventory.hasCustomName()) {
        fakeInventory =
            Bukkit.createInventory(viewer, realInventory.getType(), realInventory.getName());
      } else {
        fakeInventory = Bukkit.createInventory(viewer, realInventory.getType());
      }
    }
    fakeInventory.setContents(realInventory.getContents());

    this.showInventoryPreview(viewer, realInventory, fakeInventory);
  }
}