[BUG] Teleportation

Discussion in 'Spigot Plugin Development' started by Pol_, May 15, 2016.

  1. Hello,
    Recently I started to create a plugin UHCRun but there is a problem ...
    When people are teleport; they can not move, not falling, writing in the chat, suddenly the game is not working ..
    Thank you in advance for your response :)

    POL (I am Belgian I use google translation :p )
     
  2. Can you show us your code?
     
  3. Code (Text):
    public class UHCTeleport
    {
        public static void tpRandom(Player p) {
           
            Random r = new Random();
           
            //ON CREER LES POINTS ALEATOIRES EN X EN Y ET EN Z ET ON MET LE MONDE
            int x = r.nextInt(500);
            int y = 120;
            int z = - r.nextInt(500);
            World world = p.getWorld();
           
            //ON CREER LA LOCATION EN FONCTION DES POINTS PRECEDENTS
            Location randomLoc = new Location(world, x,y,z);
           
            p.teleport(randomLoc);
           
        }
    }
     
     
  4. Try this:
    Code (Text):
    Location randomLoc = new Location(Bukkit.getWorld("world"), x, y, z);
    If this doesn't work, I got an idea. I gotta mess with it for a second though.
     
  5. @Pol_ I believe this is happening because of chunks that gotta load but won't for some reason. Try calling p.getWorld().loadChunk(x / 16, z / 16)
     
    • Like Like x 1
  6. Yeah, that's what I was thinking also. Most of the time its not a problem, so I didn't mention it.
    Ok, here was the thing I was making. Because the r.nextInt makes ints and the location takes doubles, you have to make them into doubles. Not sure if this will work also, but its a gamble.

    Code (Text):
    Location randomLoc = new Location(world,(double) x,(double) y, (double) z);
     
  7. @tokyojack actually, because there are no specific arguments that take ints, the values are automatically converted to a double
     
  8. Oh! The more you know! :oops:
     
  9. Firstly a big thank you for your help, but its still not working ... I still can not move when I tp ...
    Thank you
    Pol
    Code (Text):
    public class UHCTeleport
    {
        public static void tpRandom(Player p) {
           
            Random r = new Random();
           
            //ON CREER LES POINTS ALEATOIRES EN X EN Y ET EN Z ET ON MET LE MONDE
            int x = r.nextInt(200);
            int y = 120;
            int z = - r.nextInt(200);
            World world = p.getWorld();
           
           
            //ON CREER LA LOCATION EN FONCTION DES POINTS PRECEDENTS
            Location randomLoc = new Location(world, x,y,z);
            world.loadChunk(x/16, z/16);
            p.teleport(randomLoc);
           
        }
    }
     
     
  10. @Pol_ is it possible that you are tping the player when they die?
     
  11. The tp function when someone dies, the problem is the tp early in the game ... If you want to see your eyes, I can get you an ip I tesste my plugin :)
     
  12. I got a idea! So, when a player dies, set the players spawn with: player.setBedSpawnLocation(randomLoc, true); , so they spawn there naturally, without getting tp'ed. Not tested, but i'm just brain-storming ideas.:)
     
  13. Je suis fran├žais t'as toujours besoin d'un coup de main ? ^^
     
  14. Oui, je ne comprend pas pourquoi sa ne fonctionne pas ...
     
  15. donc tu veux que je te face un methode ?
     
  16. This is an English forum, so speak English.
     
  17. Tu m'en diras des nouvelles c'est de la bonne ;)
     
  18. Oups j'ai oublier le code ^^ / Sorry i have miss the code ^^

    Code (Text):
    public static void teleport(Player player){
            Random rand = new Random();
            int x, y = 120, z, range = 500;
            x = rand.nextInt(range) - range/2;
            z = rand.nextInt(range) - range/2;
           
            player.teleport(new Location(player.getWorld(), x, y, z));
        }
     
  19. Je repond dans les deux langue d'acc ? / I reply in two languages ?
     
  20.