Package org.bukkit.event.player

Examples of org.bukkit.event.player.PlayerInteractEvent


    public static boolean canUse(Player player, Location loc, BlockFace face, Action action) {

        if (!shouldUseProtection()) return true;
        if (CraftBookPlugin.inst().getConfiguration().advancedBlockChecks) {

            PlayerInteractEvent event = new PlayerInteractEvent(player, action == null ? Action.RIGHT_CLICK_BLOCK : action, player.getItemInHand(), loc.getBlock(), face == null ? BlockFace.SELF : face);
            EventUtil.ignoreEvent(event);
            CraftBookPlugin.inst().getServer().getPluginManager().callEvent(event);
            return !event.isCancelled();
        }
        if (!CraftBookPlugin.inst().getConfiguration().obeyWorldguard) return true;
        return CraftBookPlugin.plugins.getWorldGuard() == null || CraftBookPlugin.plugins.getWorldGuard().createProtectionQuery().testBlockInteract(player, loc.getBlock());
    }
View Full Code Here


        EventExecutor executor = new EventExecutor() {
            public void execute(Listener listener, Event event) {}
        };
        TestPlugin plugin = new TestPlugin("Test");

        PlayerInteractEvent interactEvent = new PlayerInteractEvent(null, null, null, null, null);
        PlayerMoveEvent moveEvent = new PlayerMoveEvent(null, null, null);
        BlockBreakEvent breakEvent = new BlockBreakEvent(null, null);

        TimedRegisteredListener trl = new TimedRegisteredListener(listener, executor, EventPriority.NORMAL, plugin, false);
View Full Code Here

            Block eventBlock = block;
            if (player.getLocation().distanceSquared(block.getLocation()) > 36 || block.getTypeId() == 0) {
                action = Action.LEFT_CLICK_AIR;
                eventBlock = null;
            }
            PlayerInteractEvent interactEvent = EventFactory.onPlayerInteract(player, action, eventBlock, face);

            // blocks don't get interacted with on left click, so ignore that
            // attempt to use item in hand, that is, dig up the block
            if (!BlockPlacementHandler.selectResult(interactEvent.useItemInHand(), true)) {
                // the event was cancelled, get out of here
                revert = true;
            } else {
                // emit damage event - cancel by default if holding a sword
                boolean instaBreak = player.getGameMode() == GameMode.CREATIVE;
View Full Code Here

            player.sendBlockChange(clicked.getLocation(), Material.AIR, (byte) 0);
            return;
        }

        // call interact event
        PlayerInteractEvent event = EventFactory.onPlayerInteract(player, action, clicked, face);
        //GlowServer.logger.info("Interact: " + action + " " + clicked + " " + face);

        // attempt to use interacted block
        // DEFAULT is treated as ALLOW, and sneaking is always considered
        boolean useInteractedBlock = event.useInteractedBlock() != Event.Result.DENY;
        if (useInteractedBlock && clicked != null && (!player.isSneaking() || holding == null)) {
            BlockType blockType = ItemTable.instance().getBlock(clicked.getType());
            useInteractedBlock = blockType.blockInteract(player, clicked, face, clickedLoc);
        } else {
            useInteractedBlock = false;
        }

        // attempt to use item in hand
        // follows ALLOW/DENY: default to if no block was interacted with
        if (selectResult(event.useItemInHand(), !useInteractedBlock) && holding != null) {
            // call out to the item type to determine the appropriate right-click action
            ItemType type = ItemTable.instance().getItem(holding.getType());
            if (clicked == null) {
                type.rightClickAir(player, holding);
            } else {
View Full Code Here

 
  final static void test() {
   
    final Trigger t = ScriptLoader.loadTrigger(nodeFromString("on rightclick on air:\n kill player"));
    assert t != null;
    t.execute(new PlayerInteractEvent(njol, Action.LEFT_CLICK_AIR, null, null, null));
   
  }
View Full Code Here

TOP

Related Classes of org.bukkit.event.player.PlayerInteractEvent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.