Random teleport worldborder

Discussion in 'Spigot Plugin Development' started by Shyos, Jun 2, 2017.

  1. So I am working on a plugin that teleports a player inside the worldborder when he is outside a certain amount of blocks (takes damage from it).

    One thing I want to add is a configurable amount of blocks the player will be inside the border.
    Currently I am just checking for a valid location inside the border in a area of 5 blocks when the player is outside.
    I can't think of a way so the player is let's say 10 blocks inside of the border.

    Code (Text):
        public void onDamage(EntityDamageEvent e) {
            if (e.getEntity() instanceof Player) {

                Player p = (Player) e.getEntity();
                WorldBorder border = p.getWorld().getWorldBorder();
                Location loc = p.getLocation();

                if (border == null)

                if (e.getCause() == DamageCause.SUFFOCATION) {
                    if (loc.distance(border.getCenter()) > border.getSize() / 2) {

                      final int rangeMax = 5;
                      final int rangeMin = -5;
                        Location newLocation = p.getLocation();

                        int x = p.getLocation().getBlockX() + r.nextInt((rangeMax - rangeMin) + 1) + rangeMin;
                        int z = p.getLocation().getBlockZ() + r.nextInt((rangeMax - rangeMin) + 1) + rangeMin;
                        int highestBlock = p.getWorld().getHighestBlockYAt(x, z);

                        newLocation = new Location(p.getWorld(), x, highestBlock, z);

                        // !newLocation.getBlock().getType().isSolid()
                        if (border.isInside(newLocation))

  2. Get the world border first?
  3. I'm not sure if I understand what you mean.
    Can you elaborate?