prevent Players from logging in outside of the worldborder

Discussion in 'Spigot Plugin Help' started by Nikiii, May 21, 2015.

  1. 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)
     
  2. * Listen for PlayerJoinEvent
    * Check whether player is outside of worldborder
    * if so, teleport to spawn

    Which of this points causes your trouble?
     
  3. Thx for the respons. I don't know how to check if the player is outside of the worldborder
     
  4. https://hub.spigotmc.org/javadocs/bukkit/
    world.getWorldBorder().getCenter()
    world.getWorldBorder().getSize()
    this should help you with that
     
  5. 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?
     
    #5 Nikiii, May 21, 2015
    Last edited: May 22, 2015
  6. There's your mistake:
    It's WorldBorder not Worldborder :p 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));
        }
     
     
    • Like Like x 1
  7. I know i'm a bit late here, but what if I want to teleport them to the edge of the border?
     
  8. WorldBorder wb = insert your worldborder.
    p.teleport(new Location(p.getWorld(), wb.getSize()/2, 100, wb.getSize()/2));