Teleport player when login. I need help.

Discussion in 'Plugin Development' started by xFoundation, Aug 26, 2015.

Thread Status:
Not open for further replies.
  1. Hey guys,

    I need help for teleport player to coords. But nothing happends.

    Code:
    package com.hugo.server;
    
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.player.PlayerJoinEvent;
    
    public class InGame {
    
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
            Player p = event.getPlayer();
            World w = p.getWorld();
            Location l = new Location(w, -2479, 38, 740);
            p.teleport(l);
        }
    }
    Thanks !
     
  2. Offline

    mine-care

    @xFoundation Use a delayed task to delay the teleportation by a few ticks (1 or 2 should do)
     
  3. Have you a fix ?
     
  4. Offline

    au2001

    @xFoundation
    That is your fix
     
  5. Yes but i want the code.
     
  6. Offline

    au2001

  7. Offline

    mine-care

    @xFoundation
    as @au2001 said, spoonfeeding isnt gonna happend by most if not all members on these forums.
    The reason is simply because people tend to just copy the code entirely and just paste it without even bothering to read it. That is firstly not good for them since they arent gaining knowledge and for us as well because the same or similar question will be asked again and again... Not to mention the possibilities of errors in the code or inefficiencies such pieces of code have. Moreover we prefer to post the structure of the code and make references to docs for further information therefore i would sugest you take a look here:
    http://wiki.bukkit.org/Scheduler_Programming
     
    au2001 likes this.
  8. Offline

    caderape

    @xFoundation
    Or you can try to implements Listener. That should work too ;)
     
    au2001 likes this.
  9. Offline

    oceantheskatr

    As caderape said, you should make sure that class implements listener like so:

    public class InGame implements Listener {
     
  10. Offline

    au2001

    @oceantheskatr @caderape And since his class doesn't implement Listener, he mustn't have registered his events.


    @xFoundation You also have to use PluginManager#registerEvents(Listener, Plugin)
     
  11. Offline

    xMrPoi

    Are you sure the code is being ran? Make sure the class implements Listener and register the class as a listener in your main class as well.
     
  12. Offline

    oceantheskatr

    Ahh yes, that too.

    So @xFoundation You need to implement Listener and register events.

    Code:
        public InGame() {
            Bukkit.getServer().getPluginManager().registerEvents(this, plugin);
            }
     
  13. Offline

    sionzee

    Firstly, Is this your main class?
    Did you registered it with PluginManager?
    Do your main class extends JavaPlugin?
    Do your main class implements Listener?
    Do you have filled plugin.yml?

    Code:
    package com.hugo.server;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.player.PlayerJoinEvent;
    public class InGame extends JavaPlugin implements Listener {
    
        @Override
        public void onEnable() {
            Bukkit.getPluginManager().registerEvents(this, this);
        }
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
            World world = p.getWorld();
            Location location = new Location(world, -2479, 38, 740);
            player.teleport(location);
        }
    }
     
Thread Status:
Not open for further replies.

Share This Page