Solved Teleporting a Player with an End Portal

Discussion in 'Plugin Development' started by KeybordPiano459, Nov 1, 2012.

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

    KeybordPiano459

    So on my server, I want to make it so that when you go through the end portal, you get teleported to a different location. How do I check if a player is going through an end portal? I can't have them teleporting to the end =/
     
  2. Offline

    fireblast709

    Dont forget to register your listener :3. http://wiki.bukkit.org/Event_API_Reference
    Code:java
    1. @EventHandler
    2. public static void onPortalTravel(PlayerPortalEvent event)
    3. {
    4. event.setTo(Location object here!);
    5. }
    6.  
     
  3. Offline

    KeybordPiano459

    That's a nether portal...

    Ok so I can't get this to work, it teleports players to the end.
    http://pastebin.com/s9kkZyLm

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  4. Offline

    SyTeck

    You might need to cancel the event before you teleport the player.
     
  5. Offline

    KeybordPiano459

    Ahh good idea :) lemme test that out...
     
  6. Offline

    fireblast709

    KeybordPiano459
    Nope.avi, It handles all world portals. CraftBukkit code, net.minecraft.src.NetServerHandler.java, line 1078
    Code:java
    1. PlayerPortalEvent event = new PlayerPortalEvent(this.player.getBukkitEntity(), this.player.getBukkitEntity().getLocation(), toLocation, pta, PlayerPortalEvent.TeleportCause.END_PORTAL);

    (link: https://github.com/Bukkit/CraftBukk.../minecraft/server/NetServerHandler.java#L1078).

    So you just use:
    Code:java
    1. @EventHandler
    2. public static void onPortalTravel(PlayerPortalEvent event)
    3. {
    4. if(event.getCause() == PlayerPortalEvent.TeleportCause.END_PORTAL)
    5. {
    6. // this will teleport them to a custom location
    7. event.setTo(Location object here!);
    8. // OR (<- note: its either one of them)
    9. // This will just block and they stay at their location
    10. event.setCancelled(true);
    11. }
    12. }
    13.  
     
    andrewgies17 likes this.
  7. Offline

    KeybordPiano459

  8. Offline

    SyTeck

  9. Offline

    KeybordPiano459

Thread Status:
Not open for further replies.

Share This Page