Help with teleport event

Discussion in 'Plugin Development' started by TheDirtyDan, Aug 13, 2012.

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

    TheDirtyDan

    I don't know what I am doing wrong, but whenever I teleport to rworld it doesn't send me the message like it is supposed to.
    Code:
    public void onPlayerTeleport(PlayerTeleportEvent event){
            Player p = event.getPlayer();
            World world = Bukkit.getWorld("rworld");
            if(event.getTo().equals(world)){
                if(p.hasPermission("becolor.purple")){
                    p.sendMessage(ChatColor.DARK_PURPLE+"test");
                }
            }
        }
     
  2. Offline

    DrBowe

    Small question:

    Why create another World instance instead of doing this:
    Code:java
    1.  
    2. if(event.getTo().getWorld().getName().equalsIgnoreCase("rworld"))
    3. //do stuff
    4.  


    That being said, your problem lies with the fact that you're comparing a World (the world you fetch) to a Location (what getTo() returns)
     
  3. Offline

    travja

    You are only giving it a destination of a world, you need coords in there too.... unless there is like .getToWorld method, but I dunno...
     
  4. Offline

    Jogy34

    Bukkit fires the events one tick before they actually happen so if a player were to teleport to that world and you try to send them a message in the event my guess would be that they are still in the process of teleporting during that tick. I would suggest scheduling a delayed task for 1 tick then send the player the message
     
  5. Offline

    DrBowe

    That's not it, though. The issue lies with this:

    World world = Bukkit.getWorld("rworld");
    if(event.getTo().equals(world)){


    You can't compare a Location to a World. event.getTo() gives a Location, whereas 'world' is a World. In other words, his statement will never fire off as true, and people will never be sent the message.
     
Thread Status:
Not open for further replies.

Share This Page