Solved Cant teleport player when true portal?

Discussion in 'Plugin Development' started by jusjus112, Apr 28, 2016.

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

    jusjus112

    Hey guys,.

    I have a problem with teleporting players when they are going to a end_portal.
    I have tested a few times and searching everywhere but i cant get it working.

    Here is my code:
    Code:
          @EventHandler
          public void portal(PlayerPortalEvent e) {
            e.setCancelled(true);
            if (e.getCause() == PlayerTeleportEvent.TeleportCause.NETHER_PORTAL) {
                    Location loc = new Location(Bukkit.getServer().getWorld("world_nether"), -286.5D, 50.0D, 163.5D, 90, 0);
                    e.getPlayer().teleport(loc);
            }
            if (e.getCause() == PlayerTeleportEvent.TeleportCause.END_PORTAL) {
                Location loctoCheck = new Location(Bukkit.getServer().getWorld("world"), 557, 80, -48);
                Location loctoCheck2 = new Location(Bukkit.getServer().getWorld("world"), 558, 80, -48);
                //Location loctoCheck3 = new Location(Bukkit.getServer().getWorld("world"), 557, 80, -47);
               
                if ((loctoCheck.getX() == round(round(e.getPlayer().getLocation().getX()))&&
                        loctoCheck.getZ() == round(round(e.getPlayer().getLocation().getZ())))||(
                                loctoCheck2.getX() == round(round(e.getPlayer().getLocation().getX()))&&
                                    loctoCheck2.getZ() == round(round(e.getPlayer().getLocation().getZ())))) {
                   
                    e.setCancelled(true);
                    e.getPlayer().teleport(createSpawn.teleportToSpawnLoc());
                    return;
                }else {
                    Location loc = new Location(Bukkit.getServer().getWorld("world_the_end"), -47.5D, 67.0D, -36.5D, 90, 0);
                      e.getPlayer().teleport(loc);
                    e.setCancelled(true);
                }
            }
        }
    But when i check the locations, it does only work when im at 557.0 but when i'm on 557.5 it doesnt work. So, im stuck. I hope some people help me out when going to a end_portal at a given location!
     
  2. Offline

    Zombie_Striker

    This checks if the number to exact decimal is the same as the other location. You want to use ".getBlockXYZ", which returns an int without any decimals, for all your X,Y,Z checks.
     
  3. Offline

    jusjus112

    @Zombie_Striker
    Ya, i know. But when i check that. It will still not working, because sometimes it will tp me to the end but not my given location. I have now this:
    Code:
                Location loctoCheck = new Location(Bukkit.getServer().getWorld("world"), 557, 80, -49);
                Location loctoCheck2 = new Location(Bukkit.getServer().getWorld("world"), 558, 80, -49);
                Location loctoCheck3 = new Location(Bukkit.getServer().getWorld("world"), 558, 80, -48);
              
                if ((loctoCheck.getBlockX() == round(round(e.getPlayer().getLocation().getBlockX()))&&
                        loctoCheck.getBlockY() == round(round(e.getPlayer().getLocation().getBlockY()))&&
                        loctoCheck.getBlockZ() == round(round(e.getPlayer().getLocation().getBlockZ())))||(
                                loctoCheck2.getBlockX() == round(round(e.getPlayer().getLocation().getBlockX()))&&
                                        loctoCheck2.getBlockY() == round(round(e.getPlayer().getLocation().getBlockY()))&&
                                    loctoCheck2.getBlockZ() == round(round(e.getPlayer().getLocation().getBlockZ())))||(
                                            loctoCheck3.getBlockX() == round(round(e.getPlayer().getLocation().getBlockX()))&&
                                                    loctoCheck3.getBlockY() == round(round(e.getPlayer().getLocation().getBlockY()))&&
                                                    loctoCheck3.getBlockZ() == round(round(e.getPlayer().getLocation().getBlockZ())))) {
    The coords are good, when i tp to the coords it will tp me in the block
     
  4. Offline

    Zombie_Striker

    @jusjus112
    It seems as though you are trying to check if a player is inside a region. A better way of doing this is to use the following
    Code:
    if(centerLocation.distance(players location) <= max distance away){
    //This checks if the distance between the player and the center of the area is less than "max distance away"
    }
    To teleporting the player to a new world, use
    Code:
    player.teleport(new Location(END, players X, Players Y, Players Z));
     
  5. Offline

    jusjus112

    @Zombie_Striker
    I already have tried that. What my problem is, that it wil randomly teleports you to the end.
    So sometimes it will not work, it just so random. Maybe it is the loc?
    Code:
    if(loctoCheck2.distance(e.getPlayer().getLocation()) <= 10){
                    e.setCancelled(true);
                    e.getPlayer().teleport(createSpawn.teleportToSpawnLoc());
                    return;
     
  6. Offline

    Zombie_Striker

    @jusjus112
    Are you sure the chunk that contains the location 'teleportToSpawnLoc' is loaded? Are you sure that the XYZ of the location are constant (I.e have you ever printed out the XYZ of the location? Are you sure the printed numbers are always the same)?
     
Thread Status:
Not open for further replies.

Share This Page