Teleport player from location in config.

Discussion in 'Plugin Development' started by ItsComits, Dec 17, 2017.

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

    ItsComits

    Hello, for some reason whenever the player teleports to a location. The player is looking down in the top right corner of the block.
    The code below is 2 methods that get/set the location from the config.
    Code:
        public static String setLoc(Location l) {
            return l.getWorld().getName() + "," +
                    l.getBlockX() + "," +
                    l.getBlockY() + "," +
                    l.getBlockZ() + "," +
                    l.getPitch() + "," +
                    l.getYaw();
        }
    
        public static Location getLoc(String s) {
            String[] st = s.split(",");
            return new Location(Bukkit.getWorld(st[0]),
                                Double.parseDouble(st[1]),
                                Double.parseDouble(st[2]),
                                Double.parseDouble(st[3]),
                                Float.parseFloat(st[4]),
                                Float.parseFloat(st[5]));
        }
     
  2. Offline

    AdamDev

    @ItsComits
    Most of the time yaw and pitch don't tend to work (for me anyway). And when doing "getBlockX()" tends to always put it to the corner of the block. If you want to fix this problem add 0.5 to the "X" block and the "Z" block. That should fix the problem to spawn in the middle of the box.

    For the yaw and pitch instead of getting the location's yaw and pitch try setting it your self. Try setting the yaw and pitch to "90f" instead of splitting the string array. If that doesn't work and the problem persists, try looking at other Bukkit forums. If you can't find anything wait for someone else to come answer.
     
  3. Offline

    ItsComits

    @AdamDev The location does work but as soon as I reload/restart the server this happens. How does it work before the restart/reload but not after?
     
  4. Offline

    AdamDev

    @ItsComits
    Well, it depends if you created a default config file in your project. If you did, of course, it will reset because it's putting back the default config that you have in your project. For say you have a location saved, the minute you reset the server that default config "replaces" the saved config.
     
Thread Status:
Not open for further replies.

Share This Page