Solved PlayerInteractEvent Chest Problem

Discussion in 'Plugin Development' started by surtic, Apr 15, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    surtic

    Good Morning,

    For my new Plugin i use the PlayerInteractEvent to set for the Compass a new Location. But now i can't use Chest when i have a Item / Block what Ever in Hand and it makes for me no Sence then i return the Event when there is no Compass in hand.

    Any Idea? I get no Errors and i come with Item or with nothing in Hand always to TestOutput "Test 02".

    Thanks for your Time

    Code:
        @EventHandler(priority = EventPriority.NORMAL)
        public void onPlayerInteract(PlayerInteractEvent event) {
     
            plugin.getLogger().info("Test 01");
     
            if ( !plugin.getConfig().getBoolean("Settings.Compass.ShowNearPlayers") ) {
                return;
            }
     
            plugin.getLogger().info("Test 02");
     
     
            if ( event.getMaterial() != Material.COMPASS ) {
                return;
            }
     
            plugin.getLogger().info("Test 03");
     
            if ( event.getAction() != Action.RIGHT_CLICK_AIR ) {
                event.setCancelled(false);
                return;
            }
     
            plugin.getLogger().info("Test 04");
     
     
            int distance = plugin.getConfig().getInt("Settings.Compass.MaxDistance");
     
            List<Entity> nearbyEntities = event.getPlayer().getNearbyEntities(distance, distance, distance);
     
            if ( nearbyEntities.size() > 0 ) {
     
     
                plugin.getLogger().info("Test 01");
     
     
                for ( Entity entity : nearbyEntities ) {
     
                    if ( entity instanceof Player ) {
     
                        if ( !plugin.sameTeam( event.getPlayer(), (Player) entity )  ) {
     
                            event.getPlayer().setCompassTarget( entity.getLocation() );
                            event.getPlayer().sendMessage(ChatColor.GOLD + "Player found and set his last Location as Target!");
                            return;
     
                        }
     
                    }
     
                }
     
            }
     
            plugin.getLogger().info("Test 05");
     
            event.getPlayer().setCompassTarget( event.getPlayer().getWorld().getSpawnLocation() );
     
        }
    Okey it looks like there is a Problem while i have add AutoSneak and i can't open a Chest while im Sneaking with a Item in the Hand.

    Any Ideas to Resolve that?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  2. Offline

    n31ln3t

    I think this might work, it's worth a try I guess.

    This can check if player has an item in hand:
    player.getItemInHand()!=null
     
  3. Offline

    surtic

    There is now Problem about this Event :/ its a other Problem form MC or Bukkit i don't know.

    A Player can't open a Chest with a Item while he is Sneaking.
     
  4. Offline

    caelum19

    Your checking if they right click a compass... which isn't possible, instead check if the item the player is holding is a compass.


    Try and replace


    " if ( event.getMaterial() != Material.COMPASS ) {
    return;
    }
    "

    With
    "
    if(event.getPlayer().getItemInHand()!=Material.COMPASS)
    {
    return;
    }
    "
     
  5. Offline

    surtic

    That is not the Problem! It works.

    The Problem is some where else. I cant Access a Chest with a Item in the Hand while i am Sneaking.
     
  6. Offline

    caelum19

    Ohhh, sorry I didn't quite get the questions :p

    I beleive recent minecraft client-side update allowed players to hold shift and not open block inventorys by right-clicking, - This way they can place blocks on chests etc.


    if that is the case, the only solution would be client-side modding
     
    adde likes this.
Thread Status:
Not open for further replies.

Share This Page