Java Code Examples for org.bukkit.inventory.PlayerInventory#getItemInOffHand()

The following examples show how to use org.bukkit.inventory.PlayerInventory#getItemInOffHand() . These examples are extracted from open source projects. 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 Project: AdditionsAPI   File: BlockIgnite.java    License: 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 2
Source Project: AdditionsAPI   File: PlayerInteract.java    License: MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
	Player player = event.getPlayer();
	PlayerInventory inv = player.getInventory();
	ItemStack item = inv.getItemInMainHand();
	if (event.getHand() != null)
		switch (event.getHand()) {
		case OFF_HAND:
			item = inv.getItemInOffHand();
			break;
		default:
			break;
		}

	if (AdditionsAPI.isCustomItem(item)) {
		CustomItemPlayerInteractEvent customEvent = new CustomItemPlayerInteractEvent(event,
				new CustomItemStack(item));
		Bukkit.getServer().getPluginManager().callEvent(customEvent);
	}
	if (event.getAction() != null && event.getAction() == Action.RIGHT_CLICK_BLOCK
			&& ToolType.getToolType(item.getType()) != null
			&& ToolType.getToolType(item.getType()).equals(ToolType.HOE)) {
		Block block = event.getClickedBlock();
		Material material = block.getType();
		Location blockLoc = block.getLocation();
		blockLoc.setY(blockLoc.getBlockY() + 1);
		Material materialUp = blockLoc.getBlock().getType();
		@SuppressWarnings("deprecation")
		byte data = block.getData();

		BlockFace face = event.getBlockFace();
		if (materialUp == Material.AIR && (face == BlockFace.UP || face == BlockFace.EAST || face == BlockFace.NORTH
				|| face == BlockFace.SOUTH || face == BlockFace.WEST))
			if (shouldPlaySound(material, item, data, player))
				player.playSound(block.getLocation(), "additionsapi.hoe.till", 1.0F, 1.0F);
	}
}
 
Example 3
Source Project: AdditionsAPI   File: PlayerShearEntity.java    License: 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 4
Source Project: AdditionsAPI   File: PlayerFish.java    License: 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 5
private ItemStack getItemInHand(PlayerInteractEvent event) {
    PlayerInventory inventory = event.getPlayer().getInventory();
    if (Version.isAtLeast(Version.MC1_9)) {
        return event.getHand() == EquipmentSlot.HAND ? inventory.getItemInMainHand() : inventory.getItemInOffHand();
    } else {
        return inventory.getItemInHand();
    }
}
 
Example 6
@Override
protected Boolean execute(String playerID) {
    PlayerInventory inv = PlayerConverter.getPlayer(playerID).getInventory();
    ItemStack item = null;
    item = (!offhand) ? inv.getItemInMainHand() : inv.getItemInOffHand();

    return questItem.compare(item);
}
 
Example 7
@EventHandler
public void onIronGolemHeal(PlayerInteractEntityEvent e) {
    if (e.getRightClicked().getType() == EntityType.IRON_GOLEM) {
        PlayerInventory inv = e.getPlayer().getInventory();
        ItemStack item = null;

        if (e.getHand() == EquipmentSlot.HAND) {
            item = inv.getItemInMainHand();
        }
        else if (e.getHand() == EquipmentSlot.OFF_HAND) {
            item = inv.getItemInOffHand();
        }

        if (item != null && item.getType() == Material.IRON_INGOT) {
            SlimefunItem sfItem = SlimefunItem.getByItem(item);

            if (sfItem != null && !(sfItem instanceof VanillaItem)) {
                e.setCancelled(true);
                SlimefunPlugin.getLocalization().sendMessage(e.getPlayer(), "messages.no-iron-golem-heal");

                // This is just there to update the Inventory...
                // Somehow cancelling it isn't enough.
                if (e.getHand() == EquipmentSlot.HAND) {
                    inv.setItemInMainHand(item);
                }
                else if (e.getHand() == EquipmentSlot.OFF_HAND) {
                    inv.setItemInOffHand(item);
                }
            }
        }
    }
}