Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class WallBorderListener implements Listener {
- private static final int WALL_HEIGHT_DOWN_DIST = 3;
- private static final int WALL_HEIGHT_UP_DIST = 4;
- private static final int WALL_HORIZONTAL_DIST = 7;
- private final HCF plugin;
- public WallBorderListener(final HCF plugin) {
- this.plugin = plugin;
- }
- @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
- public void onPlayerJoin(final PlayerSpawnLocationEvent event) {
- final Player player = event.getPlayer();
- Location location = event.getSpawnLocation();
- updateVisualWalls(player, location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ());
- }
- @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
- public void onPlayerMove(final PlayerMoveEvent event) {
- final Location to = event.getTo();
- final int toX = to.getBlockX();
- final int toY = to.getBlockY();
- final int toZ = to.getBlockZ();
- final Location from = event.getFrom();
- if (from.getBlockX() != toX || from.getBlockY() != toY || from.getBlockZ() != toZ) {
- this.updateVisualWalls(event.getPlayer(), to.getWorld(), toX, toY, toZ);
- }
- }
- @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
- public void onPlayerTeleport(final PlayerTeleportEvent event) {
- this.onPlayerMove(event);
- }
- private void updateVisualWalls(Player player, final World toWorld, final int toX, final int toY, final int toZ) {
- BlockGenerator blockGenerator;
- if (plugin.getTimerManager().getCombatTimer().getRemaining(player) > 0L) {
- blockGenerator = Constants.SPAWN_TAG_WALL;
- } else {
- if (this.plugin.getTimerManager().getPvPProtectionTimer().getRemaining(player) > 0L) {
- blockGenerator = Constants.CLAIM_BORDER_WALL;
- } else {
- return;
- }
- }
- this.plugin.getBlockSender().clearBlocks(player, fakeBlock -> {
- Location location = fakeBlock.getLocation();
- return location.getWorld().equals(toWorld) && fakeBlock.getGenerator().equals(blockGenerator)
- && (Math.abs(toX - location.getBlockX()) > WALL_HORIZONTAL_DIST
- || Math.abs(toZ - location.getBlockZ()) > WALL_HORIZONTAL_DIST
- || Math.abs(toY - location.getBlockY()) > WALL_HEIGHT_UP_DIST); //TODO WALL_HEIGHT_DOWN_DIST
- });
- final int minX = toX - WALL_HORIZONTAL_DIST;
- final int maxX = toX + WALL_HORIZONTAL_DIST;
- final int minY = toY - WALL_HEIGHT_UP_DIST; //TODO WALL_HEIGHT_DOWN_DIST
- final int maxY = toY + WALL_HEIGHT_UP_DIST;
- final int minZ = toZ - WALL_HORIZONTAL_DIST;
- final int maxZ = toZ + WALL_HORIZONTAL_DIST;
- Collection<Location> locations = null;
- for (int x = minX; x <= maxX; ++x) {
- for (int z = minZ; z <= maxZ; ++z) {
- final Faction faction = this.plugin.getFactionsManager().getFactionAt(toWorld, x, z);
- if (blockGenerator == Constants.SPAWN_TAG_WALL) {
- if (!(faction instanceof SpawnFaction)) {
- continue;
- }
- } else if (blockGenerator == Constants.CLAIM_BORDER_WALL) {
- if (faction instanceof RoadFaction) {
- continue;
- }
- if (faction instanceof SpawnFaction) {
- continue;
- }
- //TODO ignore for own faction.
- }
- final Collection<Claim> claims = faction.getClaim();
- for (Claim claim : claims) {
- if (toWorld.equals(claim.getWorld())) {
- final Location[] edges = claim.edges(minY, maxY);
- for (final Location edge : edges) {
- if (Math.abs(edge.getBlockX() - toX) > WALL_HORIZONTAL_DIST || Math.abs(edge.getBlockZ() - toZ) > WALL_HORIZONTAL_DIST) {
- continue;
- }
- if (locations == null) locations = new ArrayList<>();
- locations.add(edge);
- }
- }
- }
- }
- }
- if (locations != null) {
- plugin.getBlockSender().sendBlocks(player, blockGenerator, locations);
- locations.clear();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement