PlayerMove and PlayerTeleportEvent cancel each other

Discussion in 'Plugin Development' started by Oneric-1st, May 13, 2013.

Thread Status:
Not open for further replies.
  1. Hello,

    I'm working on a Plugin adding The Team-PVP Game "The Walls".
    At now there's a conflict between my PlayerTeleportEvent (which prevent Players teleport away while InGame) and my PlayerMoveEvent (While waiting for enough people to start the game, the others shall not be able to move or do anything else).

    I can't find a way to get both events working correctly.
    More Informations in the code in the comments.

    Here is the code:
    Code:
    //TODO
    @EventHandler
    //This Event works with this code
    public void onPlayerTeleport(PlayerTeleportEvent event)
    {
      if(plugin.isWallsPlayer( event.getPlayer() ))
    {
    event.getPlayer().sendMessage(ChatColor.RED + "You are in a Walls Game, you can't teleport ! Use /wallsLeave instead.");
    event.setCancelled(true);
    }
     
    //TODO
    @EventHandler(priority=EventPriority.HIGHEST)
    //This will be canceled from the TeleportEvent and so Players can still move and get spammed with "You can't teleport in a Game..."
    public void onPlayerMove(PlayerMoveEvent event) {
    int[] indexes = plugin.getWallsPlayer(event.getPlayer());
    if (indexes != null)
    {
    if(!plugin.wallsRounds.get(indexes[0]).canInteract)
    {
    //But if I only use "event.setCancelled(true); it create an infinite loop"
    if (((event.getTo().getX() != event.getFrom().getX()) || (event.getTo().getZ() != event.getFrom().getZ()))) {
    event.setTo(event.getFrom());
    //event.setCancelled(true);
    return;
    }
    }
    }
    }
    }
    
    Thanks !
     
  2. Offline

    WhatAaCow

    Make a hashMap or arrayList with all players which are in the game and then check with:
    Code:java
    1. //in your event listener:
    2. if (hashmap.contains(playerName)) {
    3. setCancelled(true);
    4. }
     
  3. if you change the location of a player move event, a player teleport event wil be thrown to move the player to that spot
     
  4. WhatAaCow
    ähhh... this is done yet, look in the code

    ferrybig
    Yes I know. But how can I prevent this so that both work like they shall ?
     
  5. Please if you know any way to get both working as they shall, leave a post.
    I relly need help with this
     
  6. Nobody knows ?
     
Thread Status:
Not open for further replies.

Share This Page