Java Code Examples for org.bukkit.event.player.PlayerInteractEntityEvent#getHand()

The following examples show how to use org.bukkit.event.player.PlayerInteractEntityEvent#getHand() . 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: StickInteractEvent.java    From StackMob-3 with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onStickInteract(PlayerInteractEntityEvent event){
    Player player = event.getPlayer();
    Entity entity = event.getRightClicked();
    if(!(entity instanceof Mob)){
        return;
    }
    if(event.getHand() != EquipmentSlot.HAND) {
        return;
    }
    if (sm.getStickTools().isStackingStick(player.getInventory().getItemInMainHand())) {
        if (player.isSneaking()) {
            sm.getStickTools().toggleMode(player);
        } else {
            if(!(StackTools.hasValidMetadata(player, GlobalValues.STICK_MODE))){
                player.setMetadata(GlobalValues.STICK_MODE, new FixedMetadataValue(sm, 1));
            }
            sm.getStickTools().performAction(player, entity);
        }
    }
}
 
Example 2
Source File: QuestItemHandler.java    From BetonQuest with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onItemFrameClick(final PlayerInteractEntityEvent event) {
    if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
        return;
    }
    // this prevents the journal from being placed inside of item frame
    if (event.getRightClicked() instanceof ItemFrame) {
        ItemStack item = null;
        item = (event.getHand() == EquipmentSlot.HAND) ? event.getPlayer().getInventory().getItemInMainHand()
                : event.getPlayer().getInventory().getItemInOffHand();

        final String playerID = PlayerConverter.getID(event.getPlayer());
        if (Journal.isJournal(playerID, item) || Utils.isQuestItem(item)) {
            event.setCancelled(true);
        }
    }
}
 
Example 3
Source File: PlayerInfoListener.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerClickPlayer(PlayerInteractEntityEvent event) {
	if(ConfigManager.getServerVersion().isNewerThan(ConfigManager.ServerVersion.MINECRAFT_1_8_R3) && event.getHand() == EquipmentSlot.OFF_HAND) {
		return;
	}

	Player player = event.getPlayer();
	if((event.getRightClicked() instanceof Player) && player.isSneaking()) {
		if(Permission.NOVAGUILDS_PLAYERINFO.has(player)) {
			NovaPlayer nCPlayer = PlayerManager.getPlayer(event.getRightClicked());
			plugin.getPlayerManager().sendPlayerInfo(player, nCPlayer);
		}
	}
}
 
Example 4
Source File: IronGolemListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@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);
                }
            }
        }
    }
}
 
Example 5
Source File: InteractEvent.java    From StackMob-3 with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onInteract(PlayerInteractEntityEvent event) {
    Entity entity = event.getRightClicked();
    if(!(StackTools.hasValidData(entity))){
        return;
    }
    if(event.getHand() == EquipmentSlot.OFF_HAND){
        return;
    }
    if(event.isCancelled()){
        return;
    }

    int stackSize = StackTools.getSize(entity);
    if(entity instanceof Animals){
        Animals animals = (Animals) entity;
        if(sm.getCompat().checkFood(entity, event.getPlayer().getInventory().getItemInMainHand()) && animals.canBreed()){
            if(StackTools.hasSizeMoreThanOne(entity)) {
                if (sm.getCustomConfig().getBoolean("multiply.breed")) {
                    int breedSize = stackSize;
                    int handSize = event.getPlayer().getInventory().getItemInMainHand().getAmount();
                    if (handSize < breedSize) {
                        breedSize = event.getPlayer().getInventory().getItemInMainHand().getAmount();
                        event.getPlayer().getInventory().setItemInMainHand(null);
                    }

                    int childAmount = breedSize / 2;
                    Animals child = (Animals) sm.getTools().duplicate(entity);
                    StackTools.setSize(child, childAmount);
                    child.setBaby();

                    event.getPlayer().getInventory().getItemInMainHand().setAmount(handSize - breedSize);
                    animals.setBreed(false);
                } else if (sm.getCustomConfig().getBoolean("divide-on.breed")) {
                    Entity newEntity = sm.getTools().duplicate(entity);
                    StackTools.setSize(newEntity,stackSize - 1);
                    StackTools.makeSingle(entity);
                }
                return;
            }
        }
    }
    if(sm.getCustomConfig().getBoolean("divide-on.name")) {
        ItemStack handItem = event.getPlayer().getInventory().getItemInMainHand();
        if (handItem.getType() == Material.NAME_TAG && handItem.getItemMeta().hasDisplayName()) {
            if (stackSize > 1) {
                Entity dupe = sm.getTools().duplicate(entity);
                StackTools.setSize(dupe,stackSize - 1);
            }
            StackTools.removeSize(entity);
        }
    }
}
 
Example 6
Source File: NMSHandler.java    From Shopkeepers with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean isMainHandInteraction(PlayerInteractEntityEvent event) {
	return event.getHand() == EquipmentSlot.HAND;
}
 
Example 7
Source File: NMSHandler.java    From Shopkeepers with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean isMainHandInteraction(PlayerInteractEntityEvent event) {
	return event.getHand() == EquipmentSlot.HAND;
}
 
Example 8
Source File: NMSHandler.java    From Shopkeepers with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean isMainHandInteraction(PlayerInteractEntityEvent event) {
	return event.getHand() == EquipmentSlot.HAND;
}
 
Example 9
Source File: NMSHandler.java    From Shopkeepers with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean isMainHandInteraction(PlayerInteractEntityEvent event) {
	return event.getHand() == EquipmentSlot.HAND;
}
 
Example 10
Source File: NMSHandler.java    From Shopkeepers with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean isMainHandInteraction(PlayerInteractEntityEvent event) {
	return event.getHand() == EquipmentSlot.HAND;
}
 
Example 11
Source File: PlayerInteractListener.java    From PetMaster with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Determines whether the current PlayerInteractEntityEvent should be handled.
 * 
 * @param event
 * @return true if the event should be handled, false otherwise
 */
private boolean shouldHandleEvent(PlayerInteractEntityEvent event) {
	return !plugin.getEnableDisableCommand().isDisabled() && event.getRightClicked() instanceof Tameable
			// On Minecraft 1.9+, the event is fired once per hand (HAND and OFF_HAND).
			&& (version < 9 || event.getHand() == EquipmentSlot.HAND);
}