Inventory reset and teleporting?

Discussion in 'Plugin Development' started by arielschon12, Jun 22, 2012.

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

    arielschon12

    Hello Bukkit developers :D

    I am currently messing around with a PlayerLoginEvent, and i couldn't find a way to teleport player to spawn on login.

    here is my current code:

    Code:
        public void onPlayerLogin(PlayerLoginEvent event){
            if(started){
                event.getPlayer().teleport(event.getPlayer().getWorld().getSpawnLocation());
            }else{
                event.disallow(null,ChatColor.RED + "The game has already begun, try again later");
            }
        }
    As you can see, i have only found something about the spawn teleporting but that is not working for some reason... Any help about this? :D
     
  2. Offline

    Ranil

    Something that might work for the spawn teleporting is defining the location of spawn before actually triggering the event.

    Code:
    World world = player.getWorld();
     
    Location spawn = world.getSpawnLocation();
    and then cause the players to teleport to the location spawn instead of all that other jazz.
     
  3. Offline

    arielschon12

    Ranil that didn't work as well :(
    My code looks like this now:

    Code:
        @EventHandler
        public void onPlayerLogin(PlayerLoginEvent event){
            if(started){
                World world = event.getPlayer().getWorld();
                Location spawn = world.getSpawnLocation();
                event.getPlayer().teleport(spawn);
                PlayerInventory inventory = event.getPlayer().getInventory();
                inventory.clear();
            }else{
                event.disallow(null,ChatColor.RED + "The game has already begun, try again later");
            }
        }
    Anything wrong there?
     
  4. Offline

    Ranil

    Hmm I got the inventory clearing fixed by pre-declaring the player if you were having an issue there, but I can't seem to get the player to teleport to spawn. I'll keep trying.
     
  5. Offline

    arielschon12

    The inventory clearing also worked for me, only the teleport to spawn didn't... :(
     
  6. Offline

    Firefly

    I'm pretty sure that your problem is that a PlayerLoginEvent is triggered when the player attempts to login to the server, however the player itself as an object isn't in the server. Therefore, you may get a NullPointer when you try to impose a method on it. My suggestion would be to put the teleportation in a PlayerJoinEvent instead. PlayerJoinEvent occurs when the player is actually on the server.
     
  7. Offline

    Ranil

    Firefly
    That worked. I was also wondering the same thing, thanks!
     
  8. Offline

    Firefly

    Glad I could help!
     
  9. Offline

    arielschon12

    Firefly You are so awesome, this worked!!! :D
     
  10. Offline

    Firefly

    I'm glad you got it to work :D
     
Thread Status:
Not open for further replies.

Share This Page