Solved onPlayerMoveEvent no detection

Discussion in 'Plugin Development' started by Guitarax, Apr 19, 2014.

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

    Guitarax

    I am trying to make a plugin that will teleport any player that gets to the border across the world, like an infinite world. All other methodss work, commands, data storage, enabling and disabling. However the actual functional segment of code isn't causing a teleport when crossing the radius or at any point after that. No errors, just isn't teleporting. "radius" is set to 20 and I check this in debugging. Center may be off, but even if it was, player's would be teleported regardless of their position.

    Thinking players aren't being defined properly...

    Code:java
    1. public void onPlayerMoveEvent(PlayerMoveEvent p){
    2. Player player = p.getPlayer();
    3. if (p.getTo().getX() > radius + center_x){
    4. int x = -1 * radius + 5 + center_x;
    5. int y = p.getTo().getBlockY();
    6. int z = p.getTo().getBlockZ();
    7. Location Tele_loc = new Location(world, x, y ,z);
    8. p.setTo(Tele_loc);
    9. player.sendMessage(ChatColor.GREEN + "[Infiniteworld] You have traveled around the world.");
    10. }
    11. else if (p.getTo().getX() < -radius + center_x){
    12. int x = radius - 5 + center_x;
    13. int y = p.getTo().getBlockY();
    14. int z = p.getTo().getBlockZ();
    15. Location Tele_loc = new Location(world, x, y ,z);
    16. p.setTo(Tele_loc);
    17. player.sendMessage(ChatColor.GREEN + "[Infiniteworld] You have traveled around the world.");
    18. }
    19. else if (p.getTo().getZ() > radius + center_y){
    20. int x = p.getTo().getBlockX();
    21. int y = p.getTo().getBlockY();
    22. int z = -1 * radius + 5 + center_y;
    23. Location Tele_loc = new Location(world, x, y ,z);
    24. p.setTo(Tele_loc);
    25. player.sendMessage(ChatColor.GREEN + "[Infiniteworld] You have traveled around the world.");
    26. }
    27. else if (p.getTo().getZ() < -radius + center_y){
    28. int x = p.getTo().getBlockX();
    29. int y = p.getTo().getBlockY();
    30. int z = 1 * radius + 5 + center_y;
    31. Location Tele_loc = new Location(world, x, y ,z);
    32. p.setTo(Tele_loc);
    33. player.sendMessage(ChatColor.GREEN + "[Infiniteworld] You have traveled around the world.");
    34. }
    35. }
     
  2. Offline

    W&L-Craft

    Guitarax have you implemented the Listener and registered your events?
     
  3. Offline

    Nateb1121

    Be sure to register it and annotate it. (Which means make sure there's an @EventHanlder above it) I've forgotten to do that at least a hundred times.
     
  4. Offline

    Bobit

    Registering it means that you have in the onenable() of your main class:

    Code:java
    1. getServer().getPluginManager().registerEvents(this, this);


    Annotating it means that your have above your code

    Code:java
    1. @EventHandler
     
  5. Offline

    Guitarax


    This worked, is throwing errors like hell but that's on my end to fix. I'm 100% new to all this and missed registering and annotation while learning. Thanks.
     
Thread Status:
Not open for further replies.

Share This Page