Horse teleportation Long distance

Discussion in 'Plugin Development' started by NoLiver92, Jul 17, 2013.

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

    NoLiver92

    I have coded a horse teleport plugin which works just fine if it is over a short distance but when i try to teleport the horse a long distance everything in the code works i get the noise my messages all work but the horse never moves. i am using this to move the horse:
    Code:
    horse.teleport((Entity)player)
    horse is an entity variable which the horse is stored as.

    is there a way of getting the horse to teleport long distances?
     
  2. Offline

    ERROR372

    NoLiver92

    What exactly do you mean?

    1) You are near/next to the horse and you teleport somewhere far away, and the horse doesn't follow
    2) You are quite a bit away ( < 250 blocks) from the horse, and teleport it to you
    3) You are extremely far away (over 250 blocks) and teleport it to you

    Which of those are you referencing by saying the horse won't teleport over long distances.
     
  3. Offline

    NoLiver92

    ERROR372 Sorry i thought it was clear, umm i would say number 1.

    this is the orser of what i do:
    1. eject player from horse
    2. teleport player to new location over 250 blocks away
    3. teleport the horse to the same place

    the horse never gets to the new location, it doesnt even move from where it was
     
  4. Offline

    ERROR372

    NoLiver92

    I mean, I did a plugin just like this, so I'll post it here (pretty short) and you can take a look and see if you can find out what's going on in yours. Granted mine is specific to my server based on the commands players can use to teleport around the worlds

    Code:java
    1. public class HorseTeleport implements Listener
    2. {
    3. @EventHandler
    4. public void onHorseTP(PlayerCommandPreprocessEvent event)
    5. {
    6. String input = event.getMessage();
    7. if(input.startsWith("/tp") || input.startsWith("/warp") || input.startsWith("/home") || input.startsWith("/spawn"))
    8. {
    9. Player p = event.getPlayer();
    10. if(p.isInsideVehicle() && p.getVehicle().getType() == EntityType.HORSE)
    11. {
    12. Horse h = (Horse) p.getVehicle();
    13. if(h.isTamed())
    14. {
    15. p.leaveVehicle();
    16. String message = event.getMessage().substring(1);
    17. p.performCommand(message);
    18. h.teleport(p);
    19. event.setCancelled(true);
    20. return;
    21. }
    22. return;
    23. }
    24. }
    25. return;
    26. }
    27.  
    28. }
    29.  
    30.  


    You can post your code if you want, that'd help us see what might be going wrong.
     
  5. Offline

    ShadowDog007

    ERROR372

    So you cancel the command? So the player isn't teleported. Then teleport the horse to the player. When the horse. Is underneath the player already?

    :p
     
  6. Offline

    ERROR372

    ShadowDog007

    Nope, the event.setCancelled(true) prevents the command they typed from executing, which I handled with the player.performCommand(message).

    The player does teleport, and the horse is teleported to the player.
     
  7. Offline

    ShadowDog007

    ERROR372

    Why not just listen for a teleport event. You don't even have know if the player has permission to use the command.
     
  8. Offline

    ERROR372

    ShadowDog007

    Because when you are riding a vehicle, and you do a command that teleports you, you don't get teleported, so the event won't fire. Go ahead and try it yourself. Get on a horse and do "/tp <yourname> 0 100 0". I promise you won't go anywhere =P
     
  9. Offline

    ShadowDog007

    ERROR372

    I know that. Its not hard to get around though. Just set a boolean in the listener to ignore the next teleport event. Easy.
     
  10. Offline

    ERROR372

    ShadowDog007

    Not sure that I see what the problem is really... my code works, and executes just fine. If you are saying, don't use player.performCommand(message), I ask then how will you teleport the horse after the command gets executed. PlayerCommandPreprocessEvent does things before the command executes.

    I suppose you could set the horse teleport task to run 1 second later, but why do the extra code when it's just as easy and simple to do player.performCommand(message) and then cancel the event?
     
  11. Offline

    ShadowDog007

    ERROR372

    You didn't read what I said. PlayerTeleportEvent - > If the player is on a horse set a field in the listener and have the listener ignore Teleport events when the field is set to true.

    Much better way to do it. Else you have to include every command which teleports players. Which is much harder and less efficient to do..
     
  12. Offline

    ERROR372

    ShadowDog007

    You cannot use PlayerTeleportEvent for this... Go ahead and try, it won't work, I already have.
     
  13. Offline

    ShadowDog007


    Yes you can. I have done it. And it works fine. IF you do what I said. Q_Q
     
  14. Offline

    ERROR372

    ShadowDog007

    So you solely use PlayerTeleportEvent to do this?
     
  15. Offline

    ShadowDog007


    Yes. Please read what I said earlier. You obviously misunderstood.
     
  16. Offline

    ERROR372

    ShadowDog007

    Unless I'm still misunderstanding... you said to (psuedocode):

    Code:
    PlayerTeleportEvent
    {
        if(player is on horse)
        {
            //do stuff here
        }
    }
    I have tried doing such things, but if the player does not get teleported, this event won't throw. If the player is in a vehicle, they won't be teleported... It will say "<name> teleported to <x> <y> <z>", but it won't actually teleport them
     
  17. Offline

    ShadowDog007

    ERROR372

    Code:
    private boolean teleporting = false;
     
    @EventHandler
    public void onPlayerTeleport(PlayerTeleportEvent event)
    {
        if (teleporting)
            return;
     
        if (/* player is on horse */)
        {
            teleporting = true;
            // Do stuff
            teleporting = false;
        }
    }
     
  18. Offline

    ERROR372

    ShadowDog007

    Doesn't work.

    Proof:

    My code just for testing:

    Code:java
    1. private boolean teleporting = false;
    2.  
    3. @EventHandler
    4. public void onPlayerTeleport(PlayerTeleportEvent event)
    5. {
    6. if (teleporting)
    7. return;
    8.  
    9. if(event.getPlayer().isInsideVehicle() && event.getPlayer().getVehicle() instanceof Horse)
    10. {
    11. teleporting = true;
    12. System.out.println("hi");
    13. teleporting = false;
    14. }
    15. }


    Console log (should output "hi" when teleport event fires, it does when you mount a horse):

    Code:
    00:45:43 [INFO] ERROR372 issued server command: /tp ERROR372 0 67 0
    00:45:43 [INFO] ERROR372: Teleported ERROR372 to 0.50, 67.50, 0.50
    Photo evidence:

    http://i1322.photobucket.com/albums/u572/ERROR372/2013-07-20_004548_zps05584646.png

    Notice I didn't teleport to 0,67,0 (current coords at the top of the screen).
     
Thread Status:
Not open for further replies.

Share This Page