Hey there, I'm doing a little battle with my friends, where the worldborder gets closer to the spawn each hour. Now I have the problem, that if someone loggs out inside of the border and later loggs in when the border has moved. => Now he/she dies cause of the 'outsideborderdamage'. Do u know how I can do, that if someone loggs in outside of the border, that he is going to be teleported to spawn or somewhere inside of the border? Thx (sry for my bad english)
* Listen for PlayerJoinEvent * Check whether player is outside of worldborder * if so, teleport to spawn Which of this points causes your trouble?
https://hub.spigotmc.org/javadocs/bukkit/ world.getWorldBorder().getCenter() world.getWorldBorder().getSize() this should help you with that
PHP: public boolean isOutsideOfBorder(Player p) { Location loc = p.getLocation(); Worldborder border = Bukkit.getWorld("world").getWorldBorder(); if(loc.getX() > border.getSize() || loc.getZ() > border.getSize()) { return true; } else return false; } I don't know wich method is returning border. The method I exspected it could be (Worldborder border = Bukkit.getWorld("world").getWorldBorder();) is wrong. Do u know how this should be?
There's your mistake: It's WorldBorder not Worldborder Also make sure to use the correct import of the org.bukkit package. Also your check code only works for players at positive coordinates, you have to check if the opposite of the number is bigger, too. Code (Text): public boolean isOutsideOfBorder(Player p) { Location loc = p.getLocation(); WorldBorder border = p.getWorld().getWorldBorder(); double x = loc.getX(); double z = loc.getZ(); double size = border.getSize(); return ((x > size || (-x) > size) || (z > size || (-z) > size)); }
WorldBorder wb = insert your worldborder. p.teleport(new Location(p.getWorld(), wb.getSize()/2, 100, wb.getSize()/2));