org.bukkit.WorldBorder Java Examples

The following examples show how to use org.bukkit.WorldBorder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WorldBorders.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
static boolean clampToBorder(Location location) {
  WorldBorder border = location.getWorld().getWorldBorder();
  Location center = border.getCenter();
  double radius = border.getSize() / 2d;
  double xMin = center.getX() - radius;
  double xMax = center.getX() + radius;
  double zMin = center.getZ() - radius;
  double zMax = center.getZ() + radius;

  boolean moved = false;

  if (location.getX() < xMin) {
    location.setX(xMin);
    moved = true;
  }

  if (location.getX() > xMax) {
    location.setX(xMax);
    moved = true;
  }

  if (location.getZ() < zMin) {
    location.setZ(zMin);
    moved = true;
  }

  if (location.getZ() > zMax) {
    location.setZ(zMax);
    moved = true;
  }

  return moved;
}
 
Example #2
Source File: WorldBorderUtils.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public static boolean isInsideBorder(Location location) {
    WorldBorder border = location.getWorld().getWorldBorder();
    Location center = border.getCenter();
    double radius = border.getSize() / 2d;
    return Math.abs(location.getX() - center.getX()) < radius &&
           Math.abs(location.getZ() - center.getZ()) < radius;
}
 
Example #3
Source File: WorldBorderUtils.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public static boolean clampToBorder(Location location) {
    WorldBorder border = location.getWorld().getWorldBorder();
    Location center = border.getCenter();
    double radius = border.getSize() / 2d;
    double xMin = center.getX() - radius;
    double xMax = center.getX() + radius;
    double zMin = center.getZ() - radius;
    double zMax = center.getZ() + radius;

    boolean moved = false;

    if(location.getX() < xMin) {
        location.setX(xMin);
        moved = true;
    }

    if(location.getX() > xMax) {
        location.setX(xMax);
        moved = true;
    }

    if(location.getZ() < zMin) {
        location.setZ(zMin);
        moved = true;
    }

    if(location.getZ() > zMax) {
        location.setZ(zMax);
        moved = true;
    }

    return moved;
}
 
Example #4
Source File: UhcWorldBorder.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
public void setBukkitWorldBorderSize(World world, int centerX, int centerZ, double edgeSize){
	Validate.notNull(world);

	WorldBorder worldborder = world.getWorldBorder();
	worldborder.setCenter(centerX,centerZ);
	worldborder.setSize(edgeSize);
}
 
Example #5
Source File: WorldBorderThread.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
private void startMoving(){
	GameManager.getGameManager().broadcastInfoMessage(Lang.GAME_BORDER_START_SHRINKING);
	
	World overworld = Bukkit.getWorld(GameManager.getGameManager().getConfiguration().getOverworldUuid());
	WorldBorder overworldBorder = overworld.getWorldBorder();
	overworldBorder.setSize(2*endSize, timeToShrink);
	
	World nether = Bukkit.getWorld(GameManager.getGameManager().getConfiguration().getNetherUuid());
	if (nether != null) {
		WorldBorder netherBorder = nether.getWorldBorder();
		netherBorder.setSize(endSize, timeToShrink);
	}
}
 
Example #6
Source File: AsyncWorld.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public WorldBorder getWorldBorder() {
    return TaskManager.IMP.sync(new RunnableVal<WorldBorder>() {
        @Override
        public void run(WorldBorder value) {
            this.value = parent.getWorldBorder();
        }
    });
}
 
Example #7
Source File: ShrinkingBorderEvent.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void doEvent() {
	if (gMap.getMatchState() == MatchState.PLAYING) {
		this.fired = true;
		sendTitle();
		WorldBorder wb = getGameMap().getCurrentWorld().getWorldBorder();
		wb.setCenter(getGameMap().getSpectateSpawn().getX(), getGameMap().getSpectateSpawn().getZ());
		wb.setSize(borderSize);
		br = new BukkitRunnable() {
			@Override
			public void run() {
				if (length != -1) {
					if (count >= length) {
						endEvent(false);
					}
				}
				if (gMap.getMatchState().equals(MatchState.PLAYING)) {
					if (gMap.getAlivePlayers().size() > 1) {
			    		wb.setSize(wb.getSize() - 1);
			    	}
					count++;
				} else {
					endEvent(false);
				}
			}
		}.runTaskTimer(SkyWarsReloaded.get(), delay * 20, 20);
	}
}
 
Example #8
Source File: WorldBorders.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
static boolean isInsideBorder(Location location) {
  WorldBorder border = location.getWorld().getWorldBorder();
  Location center = border.getCenter();
  double radius = border.getSize() / 2d;
  return Math.abs(location.getX() - center.getX()) < radius
      && Math.abs(location.getZ() - center.getZ()) < radius;
}
 
Example #9
Source File: WorldBorderCommand.java    From UHC with MIT License 4 votes vote down vote up
@Override
protected boolean runCommand(CommandSender sender, OptionSet options) {
    final World world;
    // grab the world
    if (options.has(worldSpec)) {
        world = worldSpec.value(options);
    } else {
        final Optional<World> optionalWorld = getWorld(sender);

        if (optionalWorld.isPresent()) {
            world = optionalWorld.get();
        } else {
            sender.sendMessage(messages.getRaw("provide world"));
            return true;
        }
    }

    // check for reset first
    if (options.has(resetSpec)) {
        world.getWorldBorder().reset();
        sender.sendMessage(messages.evalTemplate("reset", ImmutableMap.of("world", world.getName())));
        return true;
    }

    final List<Double> coords = centreSpec.values(options);
    final List<Double> radii = sizeSpec.values(options);

    if (coords.size() != 2) {
        sender.sendMessage(messages.getRaw("invalid coords"));
        return true;
    }

    if (radii.size() == 0) {
        sender.sendMessage(messages.getRaw("provide radius"));
        return true;
    }

    final double radius = radii.get(0);
    final Optional<Double> targetRadius;
    long time = 0;

    if (radii.size() == 1) {
        targetRadius = Optional.absent();
    } else {
        if (!options.has(timeSpec)) {
            sender.sendMessage(messages.getRaw("provide time"));
            return true;
        }

        targetRadius = Optional.of(radii.get(1));
        time = timeSpec.value(options);
    }

    final WorldBorder border = world.getWorldBorder();

    // set centre
    border.setCenter(coords.get(0), coords.get(1));

    // set initial size
    border.setSize(radius * 2.0D);
    sender.sendMessage(messages.evalTemplate(
            "set regular",
            ImmutableMap.of(
                    "world", world.getName(),
                    "radius", radius,
                    "x", coords.get(0),
                    "z", coords.get(1)
            )
    ));

    if (targetRadius.isPresent()) {
        border.setSize(radii.get(1) * 2.0D, time);
        sender.sendMessage(messages.evalTemplate(
                "set shrinking",
                ImmutableMap.of("radius", radii.get(1), "seconds", time))
        );
    }

    return true;
}
 
Example #10
Source File: BukkitWorldBorder.java    From PlotMe-Core with GNU General Public License v3.0 4 votes vote down vote up
public BukkitWorldBorder(WorldBorder border) {
    this.border = border;
}