Search in sources :

Example 1 with PoweredMinecart

use of org.bukkit.entity.minecart.PoweredMinecart in project modules-extra by CubeEngine.

the class ListenerPlayerEntity method onPlayerInteractEntityEvent.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {
    if (!(event.getRightClicked() instanceof LivingEntity)) {
        return;
    }
    Player player = event.getPlayer();
    Entity entity = event.getRightClicked();
    ActionPlayerEntity action;
    if (player.getItemInHand().getType() == COAL && entity instanceof PoweredMinecart) {
        action = this.newAction(UseFurnaceMinecart.class, entity.getWorld());
    } else if (player.getItemInHand().getType() == INK_SACK && entity instanceof Sheep || entity instanceof Wolf) {
        action = this.newAction(EntityDye.class, entity.getWorld());
        if (action != null) {
            ((EntityDye) action).setColor(((Dye) player.getItemInHand().getData()).getColor());
        }
    } else if (player.getItemInHand().getType().equals(BOWL) && entity instanceof MushroomCow) {
        action = this.newAction(EntityFillSoup.class, entity.getWorld());
    } else {
        return;
    }
    if (action != null) {
        action.setEntity(entity);
        action.setPlayer(player);
        action.setLocation(entity.getLocation());
        this.logAction(action);
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.spongepowered.api.entity.Entity) Dye(org.bukkit.material.Dye) Player(org.spongepowered.api.entity.player.Player) MushroomCow(org.bukkit.entity.MushroomCow) PoweredMinecart(org.bukkit.entity.minecart.PoweredMinecart) Sheep(org.bukkit.entity.Sheep) Wolf(org.bukkit.entity.Wolf) EventHandler(org.bukkit.event.EventHandler)

Example 2 with PoweredMinecart

use of org.bukkit.entity.minecart.PoweredMinecart in project Prism-Bukkit by prism.

the class PrismEntityEvents method onPlayerInteractEntityEvent.

/**
 * PlayerInteractEntityEvent.
 * @param event PlayerInteractEntityEvent
 */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerInteractEntityEvent(final PlayerInteractEntityEvent event) {
    final Player p = event.getPlayer();
    final Entity e = event.getRightClicked();
    final ItemStack hand = p.getInventory().getItemInMainHand();
    // Cancel the event if a wand is in use
    if (WandUtils.playerUsesWandOnClick(p, e.getLocation())) {
        event.setCancelled(true);
        return;
    }
    if (e instanceof ItemFrame) {
        final ItemFrame frame = (ItemFrame) e;
        // If held item doesn't equal existing item frame object type
        if (!frame.getItem().getType().equals(Material.AIR)) {
            RecordingQueue.addToQueue(ActionFactory.createPlayer("item-rotate", event.getPlayer(), frame.getRotation().name().toLowerCase()));
        }
        // Frame is empty but an item is held
        if (frame.getItem().getType().equals(Material.AIR) && hand != null) {
            if (Prism.getIgnore().event("item-insert", p)) {
                RecordingQueue.addToQueue(ActionFactory.createItemFrame("item-insert", hand, 1, frame.getAttachedFace(), null, e.getLocation(), p));
            }
        }
    }
    if (hand != null) {
        // powered minecart
        if (hand.getType() == Material.COAL && e instanceof PoweredMinecart) {
            if (!Prism.getIgnore().event("item-insert", p)) {
                return;
            }
            RecordingQueue.addToQueue(ActionFactory.createItemStack("item-insert", hand, 1, 0, null, e.getLocation(), p));
        }
        if (!Prism.getIgnore().event("entity-dye", p)) {
            return;
        }
        // Only track the event on sheep, when player holds dye
        if (MaterialTag.DYES.isTagged(hand.getType()) && e.getType() == EntityType.SHEEP) {
            final String newColor = Prism.getItems().getAlias(hand.getType(), null);
            RecordingQueue.addToQueue(ActionFactory.createEntity("entity-dye", event.getRightClicked(), event.getPlayer(), newColor));
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) PoweredMinecart(org.bukkit.entity.minecart.PoweredMinecart) ItemFrame(org.bukkit.entity.ItemFrame) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Aggregations

LivingEntity (org.bukkit.entity.LivingEntity)2 PoweredMinecart (org.bukkit.entity.minecart.PoweredMinecart)2 EventHandler (org.bukkit.event.EventHandler)2 Entity (org.bukkit.entity.Entity)1 ItemFrame (org.bukkit.entity.ItemFrame)1 MushroomCow (org.bukkit.entity.MushroomCow)1 Player (org.bukkit.entity.Player)1 Sheep (org.bukkit.entity.Sheep)1 Wolf (org.bukkit.entity.Wolf)1 ItemStack (org.bukkit.inventory.ItemStack)1 Dye (org.bukkit.material.Dye)1 Entity (org.spongepowered.api.entity.Entity)1 Player (org.spongepowered.api.entity.player.Player)1