Player spawn event?

Discussion in 'Plugin Development' started by Mike724, Jul 10, 2012.

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

    Mike724

    What event can I use for when a player first spawns in on the server? I want to change the place they spawn in at.
     
  2. Offline

    sayaad

    Code:java
    1. @EventHandler
    2. //use the PlayerJoinEvent as the player has not yet joined the game in the PlayerLoginEvent and cannot teleport
    3. public void onPlayerJoinEvent(PlayerJoinEvent event)
    4. {
    5. Player p = event.getPlayer();
    6. //if statement gets if the player is new to the server.
    7. if(!p.hasPlayedBefore())
    8. {
    9. //to prevent lag when the player teleports
    10. yourSpawnLocation.getChunk().load();
    11. //teleport the player to the spawn location
    12. p.teleport(yourSpawnLocation);
    13. }
    14. }


    :3
     
  3. Offline

    Mike724

    I did that, but I get an error in console.

    Code:
    01:39:02 [INFO] Disconnecting ViiRuSxModz [/192.168.1.201:9404]: Internal server
    error
    01:39:02 [WARNING] Failed to handle packet: java.lang.IllegalStateException: Fai
    led to add player. net.minecraft.server.EntityPlayer@474(ViiRuSxModz at 65.36991
    184780035,62.0,135.64627202655322) already is in chunk 4, 8
    java.lang.IllegalStateException: Failed to add player. net.minecraft.server.Enti
    tyPlayer@474(ViiRuSxModz at 65.36991184780035,62.0,135.64627202655322) already i
    s in chunk 4, 8
            at net.minecraft.server.PlayerInstance.a(PlayerInstance.java:31)
            at net.minecraft.server.PlayerManager.addPlayer(PlayerManager.java:88)
            at net.minecraft.server.ServerConfigurationManager.c(ServerConfiguration
    Manager.java:143)
            at net.minecraft.server.NetLoginHandler.b(NetLoginHandler.java:129)
            at net.minecraft.server.NetLoginHandler.a(NetLoginHandler.java:41)
            at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:6
    1)
            at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:567)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:459)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    I'm trying to teleport the player to a location in a different world by the way, not a location in the same world.
     
  4. Offline

    bartboy8

    in your p.teleport(putworldnamehere, x, y, z);
    replace x y and z with ur x y and z coordinates
     
  5. Offline

    Mike724

    I use p.teleport(Location object here)

    I found out PlayerTeleportEvent is called when a player spawns, but if I use event.setTo(location), it doesn't work. The player does not spawn in the correct location.

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

    bartboy8

    Location location = new Location(worldname, x, y, z);
    p.teleport(location);
    also if you put that in and it doesnt work make sure you have @EventHandler above your method.
     
  7. Offline

    Mike724

    Tons of console errors... why can't I use event.setTo?
     
  8. Offline

    bartboy8

    I'll pm you my skype we can talk that way.
     
  9. you cant teleport players to other worlds at login, thats an craftbukkit bug
     
  10. Offline

    Mike724

    So maybe I should use scheduler and have it teleport slightly after spawning?
     
  11. yes, that the way most people do
     
Thread Status:
Not open for further replies.

Share This Page