From 5341015cb1538280f8e05b9154541cf0783735d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Fri, 10 Jul 2020 12:21:29 +0200 Subject: [PATCH] Finalize immutable locations and add a platform world implementation --- .../plotsquared/bukkit/BukkitPlatform.java | 5 + .../bukkit/listener/ChunkListener.java | 10 +- .../bukkit/listener/PaperListener.java | 2 +- .../bukkit/listener/PlayerEvents.java | 28 ++--- .../bukkit/player/BukkitPlayer.java | 4 +- .../plotsquared/bukkit/queue/GenChunk.java | 6 +- .../bukkit/util/BukkitRegionManager.java | 16 +-- .../plotsquared/bukkit/util/BukkitUtil.java | 24 ++-- .../plotsquared/bukkit/util/BukkitWorld.java | 85 +++++++++++++ .../com/plotsquared/core/PlotPlatform.java | 9 ++ .../com/plotsquared/core/PlotSquared.java | 13 +- .../com/plotsquared/core/command/Area.java | 14 +-- .../com/plotsquared/core/command/Claim.java | 2 +- .../com/plotsquared/core/command/Cluster.java | 10 +- .../com/plotsquared/core/command/Comment.java | 2 +- .../com/plotsquared/core/command/Debug.java | 2 +- .../com/plotsquared/core/command/Delete.java | 2 +- .../com/plotsquared/core/command/Deny.java | 2 +- .../plotsquared/core/command/Download.java | 2 +- .../com/plotsquared/core/command/Kick.java | 2 +- .../com/plotsquared/core/command/ListCmd.java | 2 +- .../com/plotsquared/core/command/Load.java | 2 +- .../com/plotsquared/core/command/Save.java | 6 +- .../com/plotsquared/core/command/Target.java | 2 +- .../core/generator/AugmentedUtils.java | 4 +- .../core/generator/ClassicPlotManager.java | 112 +++++++++--------- .../core/generator/HybridPlotManager.java | 32 +++-- .../core/generator/HybridPlotWorld.java | 10 +- .../core/generator/HybridUtils.java | 4 +- .../core/generator/SingleWorldGenerator.java | 13 +- .../core/generator/SquarePlotManager.java | 11 +- .../plotsquared/core/location/Location.java | 93 ++++++++++++++- .../com/plotsquared/core/location/World.java | 84 +++++++++++++ .../core/player/ConsolePlayer.java | 4 +- .../plotsquared/core/player/PlotPlayer.java | 4 +- .../java/com/plotsquared/core/plot/Plot.java | 8 +- .../com/plotsquared/core/plot/PlotArea.java | 2 +- .../plotsquared/core/plot/PlotCluster.java | 17 +-- .../plot/world/DefaultPlotAreaManager.java | 2 +- .../core/plot/world/SinglePlotArea.java | 8 +- .../plot/world/SinglePlotAreaManager.java | 4 +- .../core/plot/world/SinglePlotManager.java | 9 +- .../core/queue/ChunkBlockQueue.java | 11 +- .../core/queue/LocalBlockQueue.java | 2 +- .../core/queue/ScopedLocalBlockQueue.java | 23 ++-- .../plotsquared/core/util/ChunkManager.java | 12 +- .../com/plotsquared/core/util/MainUtil.java | 18 ++- .../plotsquared/core/util/OperationUtil.java | 2 +- .../plotsquared/core/util/RegionManager.java | 4 +- .../com/plotsquared/core/util/WEManager.java | 2 +- .../com/plotsquared/core/util/WorldUtil.java | 2 +- 51 files changed, 503 insertions(+), 246 deletions(-) create mode 100644 Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitWorld.java create mode 100644 Core/src/main/java/com/plotsquared/core/location/World.java diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java index 7e12c08b9..cfa3c55e8 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java @@ -50,6 +50,7 @@ import com.plotsquared.bukkit.util.BukkitRegionManager; import com.plotsquared.bukkit.util.BukkitSetupUtils; import com.plotsquared.bukkit.util.BukkitTaskManager; import com.plotsquared.bukkit.util.BukkitUtil; +import com.plotsquared.bukkit.util.BukkitWorld; import com.plotsquared.bukkit.util.SetGenCB; import com.plotsquared.bukkit.util.UpdateUtility; import com.plotsquared.bukkit.uuid.BungeePermsUUIDService; @@ -1168,4 +1169,8 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl return this.playerManager; } + @Override @NotNull public com.plotsquared.core.location.World getPlatformWorld(@NotNull final String worldName) { + return BukkitWorld.of(worldName); + } + } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java index 3ace06fd9..bbecc56c2 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java @@ -150,23 +150,23 @@ public class ChunkListener implements Listener { int z = chunkZ << 4; int x2 = x + 15; int z2 = z + 15; - Plot plot = new Location(world, x, 1, z).getOwnedPlotAbs(); + Plot plot = Location.at(world, x, 1, z).getOwnedPlotAbs(); if (plot != null && plot.hasOwner()) { return true; } - plot = new Location(world, x2, 1, z2).getOwnedPlotAbs(); + plot = Location.at(world, x2, 1, z2).getOwnedPlotAbs(); if (plot != null && plot.hasOwner()) { return true; } - plot = new Location(world, x2, 1, z).getOwnedPlotAbs(); + plot = Location.at(world, x2, 1, z).getOwnedPlotAbs(); if (plot != null && plot.hasOwner()) { return true; } - plot = new Location(world, x, 1, z2).getOwnedPlotAbs(); + plot = Location.at(world, x, 1, z2).getOwnedPlotAbs(); if (plot != null && plot.hasOwner()) { return true; } - plot = new Location(world, x + 7, 1, z + 7).getOwnedPlotAbs(); + plot = Location.at(world, x + 7, 1, z + 7).getOwnedPlotAbs(); return plot != null && plot.hasOwner(); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java index 9816709e3..ed116f051 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java @@ -305,7 +305,7 @@ public class PaperListener implements Listener { return; } Location location = BukkitUtil.getLocation(entity); - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorld())) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorldName())) { return; } PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java index e4461ad90..0989605de 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java @@ -256,7 +256,7 @@ public class PlayerEvents extends PlotListener implements Listener { for (final PlotPlayer player : PlotSquared.platform().getPlayerManager().getPlayers()) { Location location = player.getLocation(); - if (location.getWorld().equals(world)) { + if (location.getWorldName().equals(world)) { if (16 * Math.abs(location.getX() - x) / 16 > distance || 16 * Math.abs(location.getZ() - z) / 16 > distance) { continue; @@ -455,16 +455,16 @@ public class PlayerEvents extends PlotListener implements Listener { } switch (piston.getFacing()) { case EAST: - location.setX(location.getX() + 1); + location = location.add(1, 0, 0); break; case SOUTH: - location.setX(location.getX() - 1); + location = location.add(-1, 0, 0); break; case WEST: - location.setZ(location.getZ() + 1); + location = location.add(0, 0, 1); break; case NORTH: - location.setZ(location.getZ() - 1); + location = location.add(0, 0, -1); break; } Plot newPlot = area.getOwnedPlotAbs(location); @@ -490,7 +490,7 @@ public class PlayerEvents extends PlotListener implements Listener { return; } Location location = BukkitUtil.getLocation(entity); - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorld())) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorldName())) { return; } PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter); @@ -504,7 +504,7 @@ public class PlayerEvents extends PlotListener implements Listener { @EventHandler public boolean onProjectileHit(ProjectileHitEvent event) { Projectile entity = event.getEntity(); Location location = BukkitUtil.getLocation(entity); - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorld())) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorldName())) { return true; } PlotArea area = location.getPlotArea(); @@ -1078,7 +1078,7 @@ public class PlayerEvents extends PlotListener implements Listener { PlotArea area = location.getPlotArea(); boolean plotArea = location.isPlotArea(); if (!plotArea) { - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorld())) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorldName())) { return; } return; @@ -1505,7 +1505,7 @@ public class PlayerEvents extends PlotListener implements Listener { Vector relative = new Vector(face.getModX(), face.getModY(), face.getModZ()); PlotArea area = location.getPlotArea(); if (area == null) { - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorld())) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorldName())) { return; } for (Block block1 : event.getBlocks()) { @@ -1542,7 +1542,7 @@ public class PlayerEvents extends PlotListener implements Listener { Location location = BukkitUtil.getLocation(block.getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorld())) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorldName())) { return; } if (this.pistonBlocks) { @@ -1840,7 +1840,7 @@ public class PlayerEvents extends PlotListener implements Listener { public void onPotionSplash(LingeringPotionSplashEvent event) { Projectile entity = event.getEntity(); Location location = BukkitUtil.getLocation(entity); - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorld())) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorldName())) { return; } if (!this.onProjectileHit(event)) { @@ -1907,7 +1907,7 @@ public class PlayerEvents extends PlotListener implements Listener { public void onBigBoom(BlockExplodeEvent event) { Block block = event.getBlock(); Location location = BukkitUtil.getLocation(block.getLocation()); - String world = location.getWorld(); + String world = location.getWorldName(); if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) { return; } @@ -2707,7 +2707,7 @@ public class PlayerEvents extends PlotListener implements Listener { public void onPotionSplash(PotionSplashEvent event) { ThrownPotion damager = event.getPotion(); Location location = BukkitUtil.getLocation(damager); - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorld())) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorldName())) { return; } int count = 0; @@ -2737,7 +2737,7 @@ public class PlayerEvents extends PlotListener implements Listener { public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) { Entity damager = event.getDamager(); Location location = BukkitUtil.getLocation(damager); - if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorld())) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorldName())) { return; } Entity victim = event.getEntity(); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java index 6f7284e5a..9e069adf9 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java @@ -241,7 +241,7 @@ public class BukkitPlayer extends PlotPlayer { return; } final org.bukkit.Location bukkitLocation = - new org.bukkit.Location(BukkitUtil.getWorld(location.getWorld()), location.getX() + 0.5, + new org.bukkit.Location(BukkitUtil.getWorld(location.getWorldName()), location.getX() + 0.5, location.getY(), location.getZ() + 0.5, location.getYaw(), location.getPitch()); PaperLib.teleportAsync(player, bukkitLocation, getTeleportCause(cause)); } @@ -259,7 +259,7 @@ public class BukkitPlayer extends PlotPlayer { @Override public void setCompassTarget(Location location) { this.player.setCompassTarget( - new org.bukkit.Location(BukkitUtil.getWorld(location.getWorld()), location.getX(), + new org.bukkit.Location(BukkitUtil.getWorld(location.getWorldName()), location.getX(), location.getY(), location.getZ())); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/queue/GenChunk.java b/Bukkit/src/main/java/com/plotsquared/bukkit/queue/GenChunk.java index c20815e1e..cfd21bf4c 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/queue/GenChunk.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/queue/GenChunk.java @@ -62,7 +62,7 @@ public class GenChunk extends ScopedLocalBlockQueue { @Getter @Setter private ChunkData chunkData = null; public GenChunk() { - super(null, new Location(null, 0, 0, 0), new Location(null, 15, 255, 15)); + super(null, Location.at("", 0, 0, 0), Location.at("", 15, 255, 15)); this.biomes = Biome.values(); } @@ -196,11 +196,11 @@ public class GenChunk extends ScopedLocalBlockQueue { } @Override public Location getMax() { - return new Location(getWorld(), 15 + (getX() << 4), 255, 15 + (getZ() << 4)); + return Location.at(getWorld(), 15 + (getX() << 4), 255, 15 + (getZ() << 4)); } @Override public Location getMin() { - return new Location(getWorld(), getX() << 4, 0, getZ() << 4); + return Location.at(getWorld(), getX() << 4, 0, getZ() << 4); } public GenChunk clone() { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java index 0f32ba37a..7a989a4cd 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java @@ -198,9 +198,9 @@ public class BukkitRegionManager extends RegionManager { final CuboidRegion region = RegionUtil.createRegion(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ()); - final World oldWorld = Bukkit.getWorld(pos1.getWorld()); + final World oldWorld = Bukkit.getWorld(pos1.getWorldName()); final BukkitWorld oldBukkitWorld = new BukkitWorld(oldWorld); - final World newWorld = Bukkit.getWorld(newPos.getWorld()); + final World newWorld = Bukkit.getWorld(newPos.getWorldName()); assert newWorld != null; assert oldWorld != null; final String newWorldName = newWorld.getName(); @@ -248,7 +248,7 @@ public class BukkitRegionManager extends RegionManager { @Override public boolean regenerateRegion(final Location pos1, final Location pos2, final boolean ignoreAugment, final Runnable whenDone) { - final String world = pos1.getWorld(); + final String world = pos1.getWorldName(); final int p1x = pos1.getX(); final int p1z = pos1.getZ(); @@ -401,7 +401,7 @@ public class BukkitRegionManager extends RegionManager { } @Override public void clearAllEntities(Location pos1, Location pos2) { - String world = pos1.getWorld(); + String world = pos1.getWorldName(); List entities = BukkitUtil.getEntities(world); int bx = pos1.getX(); int bz = pos1.getZ(); @@ -428,8 +428,8 @@ public class BukkitRegionManager extends RegionManager { RegionUtil.createRegion(bot1.getX(), top1.getX(), bot1.getZ(), top1.getZ()); CuboidRegion region2 = RegionUtil.createRegion(bot2.getX(), top2.getX(), bot2.getZ(), top2.getZ()); - final World world1 = Bukkit.getWorld(bot1.getWorld()); - final World world2 = Bukkit.getWorld(bot2.getWorld()); + final World world1 = Bukkit.getWorld(bot1.getWorldName()); + final World world2 = Bukkit.getWorld(bot2.getWorldName()); checkNotNull(world1, "Critical error during swap."); checkNotNull(world2, "Critical error during swap."); int relX = bot2.getX() - bot1.getX(); @@ -456,9 +456,9 @@ public class BukkitRegionManager extends RegionManager { @Override public void setBiome(final CuboidRegion region, final int extendBiome, final BiomeType biome, final String world, final Runnable whenDone) { - Location pos1 = new Location(world, region.getMinimumPoint().getX() - extendBiome, + Location pos1 = Location.at(world, region.getMinimumPoint().getX() - extendBiome, region.getMinimumPoint().getY(), region.getMinimumPoint().getZ() - extendBiome); - Location pos2 = new Location(world, region.getMaximumPoint().getX() + extendBiome, + Location pos2 = Location.at(world, region.getMaximumPoint().getX() + extendBiome, region.getMaximumPoint().getY(), region.getMaximumPoint().getZ() + extendBiome); final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(world, false); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java index 6c35a542f..8ace34d92 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java @@ -276,18 +276,18 @@ public class BukkitUtil extends WorldUtil { } public static Location getLocation(@NonNull final org.bukkit.Location location) { - return new Location(location.getWorld().getName(), MathMan.roundInt(location.getX()), - MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ())); + return Location.at(com.plotsquared.bukkit.util.BukkitWorld.of(location.getWorld()), + MathMan.roundInt(location.getX()), MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ())); } public static Location getLocationFull(@NonNull final org.bukkit.Location location) { - return new Location(location.getWorld().getName(), MathMan.roundInt(location.getX()), - MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ()), location.getYaw(), + return Location.at(com.plotsquared.bukkit.util.BukkitWorld.of(location.getWorld()), + MathMan.roundInt(location.getX()), MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ()), location.getYaw(), location.getPitch()); } public static org.bukkit.Location getLocation(@NonNull final Location location) { - return new org.bukkit.Location(getWorld(location.getWorld()), location.getX(), + return new org.bukkit.Location((World) location.getWorld().getPlatformWorld(), location.getX(), location.getY(), location.getZ()); } @@ -311,13 +311,13 @@ public class BukkitUtil extends WorldUtil { public static Location getLocation(@NonNull final Entity entity) { final org.bukkit.Location location = entity.getLocation(); String world = location.getWorld().getName(); - return new Location(world, location.getBlockX(), location.getBlockY(), + return Location.at(world, location.getBlockX(), location.getBlockY(), location.getBlockZ()); } @NotNull public static Location getLocationFull(@NonNull final Entity entity) { final org.bukkit.Location location = entity.getLocation(); - return new Location(location.getWorld().getName(), MathMan.roundInt(location.getX()), + return Location.at(location.getWorld().getName(), MathMan.roundInt(location.getX()), MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ()), location.getYaw(), location.getPitch()); } @@ -409,7 +409,7 @@ public class BukkitUtil extends WorldUtil { } @Override @Nullable public String[] getSignSynchronous(@NonNull final Location location) { - Block block = getWorld(location.getWorld()) + Block block = getWorld(location.getWorldName()) .getBlockAt(location.getX(), location.getY(), location.getZ()); return TaskManager.IMP.sync(new RunnableVal() { @Override public void run(String[] value) { @@ -423,12 +423,12 @@ public class BukkitUtil extends WorldUtil { @Override public Location getSpawn(@NonNull final String world) { final org.bukkit.Location temp = getWorld(world).getSpawnLocation(); - return new Location(world, temp.getBlockX(), temp.getBlockY(), temp.getBlockZ(), + return Location.at(world, temp.getBlockX(), temp.getBlockY(), temp.getBlockZ(), temp.getYaw(), temp.getPitch()); } @Override public void setSpawn(@NonNull final Location location) { - final World world = getWorld(location.getWorld()); + final World world = getWorld(location.getWorldName()); if (world != null) { world.setSpawnLocation(location.getX(), location.getY(), location.getZ()); } @@ -526,14 +526,14 @@ public class BukkitUtil extends WorldUtil { @Override public void getBlock(@NonNull final Location location, final Consumer result) { ensureLoaded(location, chunk -> { - final World world = getWorld(location.getWorld()); + final World world = getWorld(location.getWorldName()); final Block block = world.getBlockAt(location.getX(), location.getY(), location.getZ()); result.accept(BukkitAdapter.asBlockType(block.getType()).getDefaultState()); }); } @Override public BlockState getBlockSynchronous(@NonNull final Location location) { - final World world = getWorld(location.getWorld()); + final World world = getWorld(location.getWorldName()); final Block block = world.getBlockAt(location.getX(), location.getY(), location.getZ()); return BukkitAdapter.asBlockType(block.getType()).getDefaultState(); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitWorld.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitWorld.java new file mode 100644 index 000000000..07fd49e4c --- /dev/null +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitWorld.java @@ -0,0 +1,85 @@ +/* + * _____ _ _ _____ _ + * | __ \| | | | / ____| | | + * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| | + * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` | + * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| | + * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_| + * | | + * |_| + * PlotSquared plot management system for Minecraft + * Copyright (C) 2020 IntellectualSites + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.plotsquared.bukkit.util; + +import com.google.common.collect.Maps; +import com.plotsquared.core.location.World; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import org.bukkit.Bukkit; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +@EqualsAndHashCode @ToString public class BukkitWorld implements World { + + private static final Map worldMap = Maps.newHashMap(); + + private final org.bukkit.World world; + + private BukkitWorld(@NotNull final org.bukkit.World world) { + this.world = world; + } + + /** + * Get a new {@link BukkitWorld} from a world name + * + * @param worldName World name + * @return World instance + */ + @NotNull public static BukkitWorld of(@NotNull final String worldName) { + final org.bukkit.World bukkitWorld = Bukkit.getWorld(worldName); + if (bukkitWorld == null) { + throw new IllegalArgumentException(String.format("There is no world with the name '%s'", worldName)); + } + return of(bukkitWorld); + } + + /** + * Get a new {@link BukkitWorld} from a Bukkit world + * + * @param world Bukkit world + * @return World instance + */ + @NotNull public static BukkitWorld of(@NotNull final org.bukkit.World world) { + BukkitWorld bukkitWorld = worldMap.get(world.getName()); + if (bukkitWorld != null && bukkitWorld.getPlatformWorld().equals(world)) { + return bukkitWorld; + } + bukkitWorld = new BukkitWorld(world); + worldMap.put(world.getName(), bukkitWorld); + return bukkitWorld; + } + + @NotNull @Override public org.bukkit.World getPlatformWorld() { + return this.world; + } + + @Override public @NotNull String getName() { + return this.world.getName(); + } + +} diff --git a/Core/src/main/java/com/plotsquared/core/PlotPlatform.java b/Core/src/main/java/com/plotsquared/core/PlotPlatform.java index da7b116e2..81ffa5210 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotPlatform.java +++ b/Core/src/main/java/com/plotsquared/core/PlotPlatform.java @@ -29,6 +29,7 @@ import com.plotsquared.core.backup.BackupManager; import com.plotsquared.core.generator.GeneratorWrapper; import com.plotsquared.core.generator.HybridUtils; import com.plotsquared.core.generator.IndependentPlotGenerator; +import com.plotsquared.core.location.World; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.queue.QueueProvider; import com.plotsquared.core.util.ChatManager; @@ -302,4 +303,12 @@ public interface PlotPlatform

extends ILogger { */ @NotNull PlayerManager, ? extends P> getPlayerManager(); + /** + * Get a platform world wrapper from a world name + * + * @param worldName World name + * @return Platform world wrapper + */ + @NotNull World getPlatformWorld(@NotNull final String worldName); + } diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java index 49fe35c43..fb77cb6d5 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java +++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java @@ -129,13 +129,13 @@ import java.util.zip.ZipInputStream; * An implementation of the core, with a static getter for easy access. */ @SuppressWarnings({"WeakerAccess"}) -public class PlotSquared

{ +public class PlotSquared { private static final Set EMPTY_SET = Collections.unmodifiableSet(Collections.emptySet()); - private static PlotSquared instance; + private static PlotSquared instance; // Implementation - private final PlotPlatform

platform; + private final PlotPlatform platform; // Current thread private final Thread thread; // UUID pipelines @@ -174,7 +174,7 @@ public class PlotSquared

{ * @param iPlotMain Implementation of {@link PlotPlatform} used * @param platform The platform being used */ - public PlotSquared(final PlotPlatform

iPlotMain, final String platform) { + public PlotSquared(final PlotPlatform iPlotMain, final String platform) { if (instance != null) { throw new IllegalStateException("Cannot re-initialize the PlotSquared singleton"); } @@ -375,11 +375,10 @@ public class PlotSquared

{ * * @return instance of PlotSquared */ - public static PlotSquared get() { + public static PlotSquared get() { return PlotSquared.instance; } - /** * Get the platform specific implementation of PlotSquared * @@ -1700,7 +1699,7 @@ public class PlotSquared

{ */ public boolean isNonStandardGeneration(@NotNull final String world, @NotNull final BlockVector2 chunkCoordinates) { - final Location location = new Location(world, chunkCoordinates.getBlockX() << 4, 64, chunkCoordinates.getBlockZ() << 4); + final Location location = Location.at(world, chunkCoordinates.getBlockX() << 4, 64, chunkCoordinates.getBlockZ() << 4); final PlotArea area = plotAreaManager.getApplicablePlotArea(location); if (area == null) { return true; diff --git a/Core/src/main/java/com/plotsquared/core/command/Area.java b/Core/src/main/java/com/plotsquared/core/command/Area.java index 7f7e2bb1c..9ebfca78b 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Area.java +++ b/Core/src/main/java/com/plotsquared/core/command/Area.java @@ -104,7 +104,7 @@ public class Area extends SubCommand { MainUtil.sendMessage(player, Captions.SINGLE_AREA_NEEDS_NAME); return false; } - final PlotArea existingArea = PlotSquared.get().getPlotAreaManager().getPlotArea(player.getLocation().getWorld(), args[1]); + final PlotArea existingArea = PlotSquared.get().getPlotAreaManager().getPlotArea(player.getLocation().getWorldName(), args[1]); if (existingArea != null && existingArea.getId().equalsIgnoreCase(args[1])) { MainUtil.sendMessage(player, Captions.SINGLE_AREA_NAME_TAKEN); return false; @@ -139,7 +139,7 @@ public class Area extends SubCommand { BlockVector3.at(playerSelectionMax.getX(), 255, playerSelectionMax.getZ())); // There's only one plot in the area... final PlotId plotId = new PlotId(1, 1); - final HybridPlotWorld hybridPlotWorld = new HybridPlotWorld(player.getLocation().getWorld(), args[1], + final HybridPlotWorld hybridPlotWorld = new HybridPlotWorld(player.getLocation().getWorldName(), args[1], Objects.requireNonNull(PlotSquared.platform()).getDefaultGenerator(), plotId, plotId); // Plot size is the same as the region width hybridPlotWorld.PLOT_WIDTH = hybridPlotWorld.SIZE = (short) selectedRegion.getWidth(); @@ -462,7 +462,7 @@ public class Area extends SubCommand { return false; } if (WorldUtil.IMP.isWorld(pa.getWorldName())) { - if (!player.getLocation().getWorld().equals(pa.getWorldName())) { + if (!player.getLocation().getWorldName().equals(pa.getWorldName())) { player.teleport(WorldUtil.IMP.getSpawn(pa.getWorldName()), TeleportCause.COMMAND); } @@ -648,15 +648,13 @@ public class Area extends SubCommand { player.teleport(center, TeleportCause.COMMAND); } else { CuboidRegion region = area.getRegion(); - center = new Location(area.getWorldName(), region.getMinimumPoint().getX() + center = Location.at(area.getWorldName(), region.getMinimumPoint().getX() + (region.getMaximumPoint().getX() - region.getMinimumPoint().getX()) / 2, 0, region.getMinimumPoint().getZ() + (region.getMaximumPoint().getZ() - region.getMinimumPoint().getZ()) / 2); WorldUtil.IMP - .getHighestBlock(area.getWorldName(), center.getX(), center.getZ(), y -> { - center.setY(1 + y); - player.teleport(center, TeleportCause.COMMAND); - }); + .getHighestBlock(area.getWorldName(), center.getX(), center.getZ(), y -> + player.teleport(center.withY(1 + y), TeleportCause.COMMAND)); } return true; case "delete": diff --git a/Core/src/main/java/com/plotsquared/core/command/Claim.java b/Core/src/main/java/com/plotsquared/core/command/Claim.java index 481a25bf5..bf222d1b3 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Claim.java +++ b/Core/src/main/java/com/plotsquared/core/command/Claim.java @@ -74,7 +74,7 @@ public class Claim extends SubCommand { boolean force = event.getEventResult() == Result.FORCE; int currentPlots = Settings.Limit.GLOBAL ? player.getPlotCount() : - player.getPlotCount(location.getWorld()); + player.getPlotCount(location.getWorldName()); int grants = 0; if (currentPlots >= player.getAllowedPlots() && !force) { if (player.hasPersistentMeta("grantedPlots")) { diff --git a/Core/src/main/java/com/plotsquared/core/command/Cluster.java b/Core/src/main/java/com/plotsquared/core/command/Cluster.java index a22bfd733..0902170bf 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Cluster.java +++ b/Core/src/main/java/com/plotsquared/core/command/Cluster.java @@ -117,7 +117,7 @@ public class Cluster extends SubCommand { } int currentClusters = Settings.Limit.GLOBAL ? player.getClusterCount() : - player.getPlotCount(player.getLocation().getWorld()); + player.getPlotCount(player.getLocation().getWorldName()); if (currentClusters >= player.getAllowedPlots()) { return sendMessage(player, Captions.CANT_CLAIM_MORE_CLUSTERS); } @@ -173,7 +173,7 @@ public class Cluster extends SubCommand { if (Settings.Limit.GLOBAL) { current = player.getPlayerClusterCount(); } else { - current = player.getPlayerClusterCount(player.getLocation().getWorld()); + current = player.getPlayerClusterCount(player.getLocation().getWorldName()); } int allowed = Permissions .hasPermissionRange(player, Captions.PERMISSION_CLUSTER_SIZE, @@ -324,7 +324,7 @@ public class Cluster extends SubCommand { if (Settings.Limit.GLOBAL) { current = player.getPlayerClusterCount(); } else { - current = player.getPlayerClusterCount(player.getLocation().getWorld()); + current = player.getPlayerClusterCount(player.getLocation().getWorldName()); } current -= cluster.getArea() + (1 + pos2.x - pos1.x) * (1 + pos2.y - pos1.y); int allowed = Permissions.hasPermissionRange(player, Captions.PERMISSION_CLUSTER, @@ -454,7 +454,7 @@ public class Cluster extends SubCommand { cluster.getName()); } for (final Plot plot : PlotQuery.newQuery().inWorld(player2.getLocation() - .getWorld()).ownedBy(uuid).asCollection()) { + .getWorldName()).ownedBy(uuid).asCollection()) { PlotCluster current = plot.getCluster(); if (current != null && current.equals(cluster)) { plot.unclaim(); @@ -512,7 +512,7 @@ public class Cluster extends SubCommand { cluster.invited.remove(uuid); DBFunc.removeInvited(cluster, uuid); MainUtil.sendMessage(player, Captions.CLUSTER_REMOVED, cluster.getName()); - for (final Plot plot : PlotQuery.newQuery().inWorld(player.getLocation().getWorld()) + for (final Plot plot : PlotQuery.newQuery().inWorld(player.getLocation().getWorldName()) .ownedBy(uuid).asCollection()) { PlotCluster current = plot.getCluster(); if (current != null && current.equals(cluster)) { diff --git a/Core/src/main/java/com/plotsquared/core/command/Comment.java b/Core/src/main/java/com/plotsquared/core/command/Comment.java index c9e3031ac..455ec268c 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Comment.java +++ b/Core/src/main/java/com/plotsquared/core/command/Comment.java @@ -86,7 +86,7 @@ public class Comment extends SubCommand { String message = StringMan.join(Arrays.copyOfRange(args, index, args.length), " "); PlotComment comment = - new PlotComment(player.getLocation().getWorld(), plot.getId(), message, + new PlotComment(player.getLocation().getWorldName(), plot.getId(), message, player.getName(), inbox.toString(), System.currentTimeMillis()); boolean result = inbox.addComment(plot, comment); if (!result) { diff --git a/Core/src/main/java/com/plotsquared/core/command/Debug.java b/Core/src/main/java/com/plotsquared/core/command/Debug.java index d2bae83b2..c35ae415d 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Debug.java +++ b/Core/src/main/java/com/plotsquared/core/command/Debug.java @@ -63,7 +63,7 @@ public class Debug extends SubCommand { MainUtil.sendMessage(player, "Fetching loaded chunks..."); TaskManager.runTaskAsync(() -> MainUtil.sendMessage(player, "Loaded chunks: " + RegionManager.manager - .getChunkChunks(player.getLocation().getWorld()).size() + "(" + ( + .getChunkChunks(player.getLocation().getWorldName()).size() + "(" + ( System.currentTimeMillis() - start) + "ms) using thread: " + Thread .currentThread().getName())); return true; diff --git a/Core/src/main/java/com/plotsquared/core/command/Delete.java b/Core/src/main/java/com/plotsquared/core/command/Delete.java index 5f8178e06..d2b578757 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Delete.java +++ b/Core/src/main/java/com/plotsquared/core/command/Delete.java @@ -77,7 +77,7 @@ public class Delete extends SubCommand { final java.util.Set plots = plot.getConnectedPlots(); final int currentPlots = Settings.Limit.GLOBAL ? player.getPlotCount() : - player.getPlotCount(location.getWorld()); + player.getPlotCount(location.getWorldName()); Runnable run = () -> { if (plot.getRunning() > 0) { MainUtil.sendMessage(player, Captions.WAIT_FOR_TIMER); diff --git a/Core/src/main/java/com/plotsquared/core/command/Deny.java b/Core/src/main/java/com/plotsquared/core/command/Deny.java index edbdab068..25a0c7b4b 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Deny.java +++ b/Core/src/main/java/com/plotsquared/core/command/Deny.java @@ -133,7 +133,7 @@ public class Deny extends SubCommand { player.stopSpectating(); } Location location = player.getLocation(); - Location spawn = WorldUtil.IMP.getSpawn(location.getWorld()); + Location spawn = WorldUtil.IMP.getSpawn(location.getWorldName()); MainUtil.sendMessage(player, Captions.YOU_GOT_DENIED); if (plot.equals(spawn.getPlot())) { Location newSpawn = diff --git a/Core/src/main/java/com/plotsquared/core/command/Download.java b/Core/src/main/java/com/plotsquared/core/command/Download.java index 26ce40575..57e3d07c0 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Download.java +++ b/Core/src/main/java/com/plotsquared/core/command/Download.java @@ -51,7 +51,7 @@ import java.net.URL; public class Download extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { - String world = player.getLocation().getWorld(); + String world = player.getLocation().getWorldName(); if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) { return !sendMessage(player, Captions.NOT_IN_PLOT_WORLD); } diff --git a/Core/src/main/java/com/plotsquared/core/command/Kick.java b/Core/src/main/java/com/plotsquared/core/command/Kick.java index 978aeec29..2c7c9a9e3 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Kick.java +++ b/Core/src/main/java/com/plotsquared/core/command/Kick.java @@ -105,7 +105,7 @@ public class Kick extends SubCommand { Captions.CANNOT_KICK_PLAYER.send(player, player2.getName()); return; } - Location spawn = WorldUtil.IMP.getSpawn(location.getWorld()); + Location spawn = WorldUtil.IMP.getSpawn(location.getWorldName()); Captions.YOU_GOT_KICKED.send(player2); if (plot.equals(spawn.getPlot())) { Location newSpawn = WorldUtil.IMP diff --git a/Core/src/main/java/com/plotsquared/core/command/ListCmd.java b/Core/src/main/java/com/plotsquared/core/command/ListCmd.java index 518e780a4..0687d2160 100644 --- a/Core/src/main/java/com/plotsquared/core/command/ListCmd.java +++ b/Core/src/main/java/com/plotsquared/core/command/ListCmd.java @@ -138,7 +138,7 @@ public class ListCmd extends SubCommand { page = 0; } - String world = player.getLocation().getWorld(); + String world = player.getLocation().getWorldName(); PlotArea area = player.getApplicablePlotArea(); String arg = args[0].toLowerCase(); final boolean[] sort = new boolean[] {true}; diff --git a/Core/src/main/java/com/plotsquared/core/command/Load.java b/Core/src/main/java/com/plotsquared/core/command/Load.java index 30a503c76..59388d657 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Load.java +++ b/Core/src/main/java/com/plotsquared/core/command/Load.java @@ -53,7 +53,7 @@ import java.util.List; public class Load extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { - String world = player.getLocation().getWorld(); + String world = player.getLocation().getWorldName(); if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) { return !sendMessage(player, Captions.NOT_IN_PLOT_WORLD); } diff --git a/Core/src/main/java/com/plotsquared/core/command/Save.java b/Core/src/main/java/com/plotsquared/core/command/Save.java index a9f55e31e..86cc68487 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Save.java +++ b/Core/src/main/java/com/plotsquared/core/command/Save.java @@ -50,7 +50,7 @@ import java.util.UUID; public class Save extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { - String world = player.getLocation().getWorld(); + String world = player.getLocation().getWorldName(); if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) { return !sendMessage(player, Captions.NOT_IN_PLOT_WORLD); } @@ -77,8 +77,8 @@ public class Save extends SubCommand { TaskManager.runTaskAsync(() -> { String time = (System.currentTimeMillis() / 1000) + ""; Location[] corners = plot.getCorners(); - corners[0].setY(0); - corners[1].setY(255); + corners[0] = corners[0].withY(0); + corners[1] = corners[1].withY(255); int size = (corners[1].getX() - corners[0].getX()) + 1; PlotId id = plot.getId(); String world1 = plot.getArea().toString().replaceAll(";", "-") diff --git a/Core/src/main/java/com/plotsquared/core/command/Target.java b/Core/src/main/java/com/plotsquared/core/command/Target.java index 5d1ebcd10..410aca635 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Target.java +++ b/Core/src/main/java/com/plotsquared/core/command/Target.java @@ -54,7 +54,7 @@ public class Target extends SubCommand { Plot target = null; if (StringMan.isEqualIgnoreCaseToAny(args[0], "near", "nearest")) { int distance = Integer.MAX_VALUE; - for (Plot plot : PlotQuery.newQuery().inWorld(location.getWorld()).asCollection()) { + for (Plot plot : PlotQuery.newQuery().inWorld(location.getWorldName()).asCollection()) { double current = plot.getCenterSynchronous().getEuclideanDistanceSquared(location); if (current < distance) { distance = (int) current; diff --git a/Core/src/main/java/com/plotsquared/core/generator/AugmentedUtils.java b/Core/src/main/java/com/plotsquared/core/generator/AugmentedUtils.java index 589a8ff52..6c2f2fbd2 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/AugmentedUtils.java +++ b/Core/src/main/java/com/plotsquared/core/generator/AugmentedUtils.java @@ -153,8 +153,8 @@ public class AugmentedUtils { secondaryMask.setForceSync(true); ScopedLocalBlockQueue scoped = - new ScopedLocalBlockQueue(secondaryMask, new Location(world, blockX, 0, blockZ), - new Location(world, blockX + 15, 255, blockZ + 15)); + new ScopedLocalBlockQueue(secondaryMask, Location.at(world, blockX, 0, blockZ), + Location.at(world, blockX + 15, 255, blockZ + 15)); generator.generateChunk(scoped, area); generator.populateChunk(scoped, area); } diff --git a/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java b/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java index 46333a84c..48950c8dd 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java +++ b/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java @@ -192,10 +192,10 @@ public class ClassicPlotManager extends SquarePlotManager { if (plot.isBasePlot()) { for (CuboidRegion region : plot.getRegions()) { Location pos1 = - new Location(classicPlotWorld.getWorldName(), region.getMinimumPoint().getX(), + Location.at(classicPlotWorld.getWorldName(), region.getMinimumPoint().getX(), maxY, region.getMinimumPoint().getZ()); Location pos2 = - new Location(classicPlotWorld.getWorldName(), region.getMaximumPoint().getX(), + Location.at(classicPlotWorld.getWorldName(), region.getMaximumPoint().getX(), maxY, region.getMaximumPoint().getZ()); queue.setCuboid(pos1, pos2, blocks); } @@ -314,31 +314,31 @@ public class ClassicPlotManager extends SquarePlotManager { int ez = pos2.getZ() + 2; LocalBlockQueue queue = classicPlotWorld.getQueue(false); int maxY = getWorldHeight(); - queue.setCuboid(new Location(classicPlotWorld.getWorldName(), sx, + queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx, Math.min(classicPlotWorld.WALL_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz + 1), - new Location(classicPlotWorld.getWorldName(), ex, maxY, ez - 1), + Location.at(classicPlotWorld.getWorldName(), ex, maxY, ez - 1), BlockTypes.AIR.getDefaultState()); - queue.setCuboid(new Location(classicPlotWorld.getWorldName(), sx, 0, sz + 1), - new Location(classicPlotWorld.getWorldName(), ex, 0, ez - 1), + queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx, 0, sz + 1), + Location.at(classicPlotWorld.getWorldName(), ex, 0, ez - 1), BlockUtil.get((short) 7, (byte) 0)); - queue.setCuboid(new Location(classicPlotWorld.getWorldName(), sx, 1, sz + 1), - new Location(classicPlotWorld.getWorldName(), sx, classicPlotWorld.WALL_HEIGHT, ez - 1), + queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx, 1, sz + 1), + Location.at(classicPlotWorld.getWorldName(), sx, classicPlotWorld.WALL_HEIGHT, ez - 1), classicPlotWorld.WALL_FILLING.toPattern()); queue.setCuboid( - new Location(classicPlotWorld.getWorldName(), sx, classicPlotWorld.WALL_HEIGHT + 1, + Location.at(classicPlotWorld.getWorldName(), sx, classicPlotWorld.WALL_HEIGHT + 1, sz + 1), - new Location(classicPlotWorld.getWorldName(), sx, classicPlotWorld.WALL_HEIGHT + 1, + Location.at(classicPlotWorld.getWorldName(), sx, classicPlotWorld.WALL_HEIGHT + 1, ez - 1), classicPlotWorld.WALL_BLOCK.toPattern()); - queue.setCuboid(new Location(classicPlotWorld.getWorldName(), ex, 1, sz + 1), - new Location(classicPlotWorld.getWorldName(), ex, classicPlotWorld.WALL_HEIGHT, ez - 1), + queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), ex, 1, sz + 1), + Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.WALL_HEIGHT, ez - 1), classicPlotWorld.WALL_FILLING.toPattern()); queue.setCuboid( - new Location(classicPlotWorld.getWorldName(), ex, classicPlotWorld.WALL_HEIGHT + 1, + Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.WALL_HEIGHT + 1, sz + 1), - new Location(classicPlotWorld.getWorldName(), ex, classicPlotWorld.WALL_HEIGHT + 1, + Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.WALL_HEIGHT + 1, ez - 1), classicPlotWorld.WALL_BLOCK.toPattern()); - queue.setCuboid(new Location(classicPlotWorld.getWorldName(), sx + 1, 1, sz + 1), - new Location(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.ROAD_HEIGHT, + queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx + 1, 1, sz + 1), + Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.ROAD_HEIGHT, ez - 1), classicPlotWorld.ROAD_BLOCK.toPattern()); return queue.enqueue(); } @@ -351,32 +351,32 @@ public class ClassicPlotManager extends SquarePlotManager { int sx = pos1.getX() - 2; int ex = pos2.getX() + 2; LocalBlockQueue queue = classicPlotWorld.getQueue(false); - queue.setCuboid(new Location(classicPlotWorld.getWorldName(), sx + 1, + queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx + 1, Math.min(classicPlotWorld.WALL_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz), - new Location(classicPlotWorld.getWorldName(), ex - 1, + Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.getPlotManager().getWorldHeight(), ez), BlockTypes.AIR.getDefaultState()); - queue.setCuboid(new Location(classicPlotWorld.getWorldName(), sx + 1, 0, sz), - new Location(classicPlotWorld.getWorldName(), ex - 1, 0, ez), + queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx + 1, 0, sz), + Location.at(classicPlotWorld.getWorldName(), ex - 1, 0, ez), BlockUtil.get((short) 7, (byte) 0)); - queue.setCuboid(new Location(classicPlotWorld.getWorldName(), sx + 1, 1, sz), - new Location(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.WALL_HEIGHT, sz), + queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx + 1, 1, sz), + Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.WALL_HEIGHT, sz), classicPlotWorld.WALL_FILLING.toPattern()); queue.setCuboid( - new Location(classicPlotWorld.getWorldName(), sx + 1, classicPlotWorld.WALL_HEIGHT + 1, + Location.at(classicPlotWorld.getWorldName(), sx + 1, classicPlotWorld.WALL_HEIGHT + 1, sz), - new Location(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.WALL_HEIGHT + 1, + Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.WALL_HEIGHT + 1, sz), classicPlotWorld.WALL_BLOCK.toPattern()); - queue.setCuboid(new Location(classicPlotWorld.getWorldName(), sx + 1, 1, ez), - new Location(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.WALL_HEIGHT, ez), + queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx + 1, 1, ez), + Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.WALL_HEIGHT, ez), classicPlotWorld.WALL_FILLING.toPattern()); queue.setCuboid( - new Location(classicPlotWorld.getWorldName(), sx + 1, classicPlotWorld.WALL_HEIGHT + 1, + Location.at(classicPlotWorld.getWorldName(), sx + 1, classicPlotWorld.WALL_HEIGHT + 1, ez), - new Location(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.WALL_HEIGHT + 1, + Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.WALL_HEIGHT + 1, ez), classicPlotWorld.WALL_BLOCK.toPattern()); - queue.setCuboid(new Location(classicPlotWorld.getWorldName(), sx + 1, 1, sz + 1), - new Location(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.ROAD_HEIGHT, + queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx + 1, 1, sz + 1), + Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.ROAD_HEIGHT, ez - 1), classicPlotWorld.ROAD_BLOCK.toPattern()); return queue.enqueue(); } @@ -389,15 +389,15 @@ public class ClassicPlotManager extends SquarePlotManager { int ez = sz + classicPlotWorld.ROAD_WIDTH - 1; LocalBlockQueue queue = classicPlotWorld.getQueue(false); queue.setCuboid( - new Location(classicPlotWorld.getWorldName(), sx + 1, classicPlotWorld.ROAD_HEIGHT + 1, - sz + 1), new Location(classicPlotWorld.getWorldName(), ex - 1, + Location.at(classicPlotWorld.getWorldName(), sx + 1, classicPlotWorld.ROAD_HEIGHT + 1, + sz + 1), Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.getPlotManager().getWorldHeight(), ez - 1), BlockTypes.AIR.getDefaultState()); - queue.setCuboid(new Location(classicPlotWorld.getWorldName(), sx + 1, 0, sz + 1), - new Location(classicPlotWorld.getWorldName(), ex - 1, 0, ez - 1), + queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx + 1, 0, sz + 1), + Location.at(classicPlotWorld.getWorldName(), ex - 1, 0, ez - 1), BlockUtil.get((short) 7, (byte) 0)); - queue.setCuboid(new Location(classicPlotWorld.getWorldName(), sx + 1, 1, sz + 1), - new Location(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.ROAD_HEIGHT, + queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx + 1, 1, sz + 1), + Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.ROAD_HEIGHT, ez - 1), classicPlotWorld.ROAD_BLOCK.toPattern()); return queue.enqueue(); } @@ -410,17 +410,17 @@ public class ClassicPlotManager extends SquarePlotManager { int sz = pos1.getZ() - 1; int ez = pos2.getZ() + 1; LocalBlockQueue queue = classicPlotWorld.getQueue(false); - queue.setCuboid(new Location(classicPlotWorld.getWorldName(), sx, + queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx, Math.min(classicPlotWorld.PLOT_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz), - new Location(classicPlotWorld.getWorldName(), ex, + Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.getPlotManager().getWorldHeight(), ez), BlockTypes.AIR.getDefaultState()); - queue.setCuboid(new Location(classicPlotWorld.getWorldName(), sx, 1, sz + 1), - new Location(classicPlotWorld.getWorldName(), ex, classicPlotWorld.PLOT_HEIGHT - 1, + queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx, 1, sz + 1), + Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.PLOT_HEIGHT - 1, ez - 1), classicPlotWorld.MAIN_BLOCK.toPattern()); queue.setCuboid( - new Location(classicPlotWorld.getWorldName(), sx, classicPlotWorld.PLOT_HEIGHT, sz + 1), - new Location(classicPlotWorld.getWorldName(), ex, classicPlotWorld.PLOT_HEIGHT, ez - 1), + Location.at(classicPlotWorld.getWorldName(), sx, classicPlotWorld.PLOT_HEIGHT, sz + 1), + Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.PLOT_HEIGHT, ez - 1), classicPlotWorld.TOP_BLOCK.toPattern()); return queue.enqueue(); } @@ -433,17 +433,17 @@ public class ClassicPlotManager extends SquarePlotManager { int sx = pos1.getX() - 1; int ex = pos2.getX() + 1; LocalBlockQueue queue = classicPlotWorld.getQueue(false); - queue.setCuboid(new Location(classicPlotWorld.getWorldName(), sx, + queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx, Math.min(classicPlotWorld.PLOT_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz), - new Location(classicPlotWorld.getWorldName(), ex, + Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.getPlotManager().getWorldHeight(), ez), BlockTypes.AIR.getDefaultState()); - queue.setCuboid(new Location(classicPlotWorld.getWorldName(), sx + 1, 1, sz), - new Location(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.PLOT_HEIGHT - 1, + queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx + 1, 1, sz), + Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.PLOT_HEIGHT - 1, ez), classicPlotWorld.MAIN_BLOCK.toPattern()); queue.setCuboid( - new Location(classicPlotWorld.getWorldName(), sx + 1, classicPlotWorld.PLOT_HEIGHT, sz), - new Location(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.PLOT_HEIGHT, ez), + Location.at(classicPlotWorld.getWorldName(), sx + 1, classicPlotWorld.PLOT_HEIGHT, sz), + Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.PLOT_HEIGHT, ez), classicPlotWorld.TOP_BLOCK.toPattern()); return queue.enqueue(); } @@ -455,17 +455,17 @@ public class ClassicPlotManager extends SquarePlotManager { int sz = location.getZ() + 1; int ez = sz + classicPlotWorld.ROAD_WIDTH - 1; LocalBlockQueue queue = classicPlotWorld.getQueue(false); - queue.setCuboid(new Location(classicPlotWorld.getWorldName(), sx, + queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx, Math.min(classicPlotWorld.PLOT_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz), - new Location(classicPlotWorld.getWorldName(), ex, + Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.getPlotManager().getWorldHeight(), ez), BlockTypes.AIR.getDefaultState()); - queue.setCuboid(new Location(classicPlotWorld.getWorldName(), sx, 1, sz), - new Location(classicPlotWorld.getWorldName(), ex, classicPlotWorld.PLOT_HEIGHT - 1, ez), + queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx, 1, sz), + Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.PLOT_HEIGHT - 1, ez), classicPlotWorld.MAIN_BLOCK.toPattern()); queue.setCuboid( - new Location(classicPlotWorld.getWorldName(), sx, classicPlotWorld.PLOT_HEIGHT, sz), - new Location(classicPlotWorld.getWorldName(), ex, classicPlotWorld.PLOT_HEIGHT, ez), + Location.at(classicPlotWorld.getWorldName(), sx, classicPlotWorld.PLOT_HEIGHT, sz), + Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.PLOT_HEIGHT, ez), classicPlotWorld.TOP_BLOCK.toPattern()); return queue.enqueue(); } @@ -529,8 +529,8 @@ public class ClassicPlotManager extends SquarePlotManager { */ @Override public Location getSignLoc(Plot plot) { plot = plot.getBasePlot(false); - Location bot = plot.getBottomAbs(); - return new Location(classicPlotWorld.getWorldName(), bot.getX() - 1, + final Location bot = plot.getBottomAbs(); + return Location.at(classicPlotWorld.getWorldName(), bot.getX() - 1, classicPlotWorld.ROAD_HEIGHT + 1, bot.getZ() - 2); } diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java index 04c6ad9bd..48494e13a 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java @@ -103,9 +103,8 @@ public class HybridPlotManager extends ClassicPlotManager { PlotId id2 = new PlotId(id.x + 1, id.y); Location bot = getPlotBottomLocAbs(id2); Location top = getPlotTopLocAbs(id); - Location pos1 = - new Location(hybridPlotWorld.getWorldName(), top.getX() + 1, 0, bot.getZ() - 1); - Location pos2 = new Location(hybridPlotWorld.getWorldName(), bot.getX(), + Location pos1 = Location.at(hybridPlotWorld.getWorldName(), top.getX() + 1, 0, bot.getZ() - 1); + Location pos2 = Location.at(hybridPlotWorld.getWorldName(), bot.getX(), Math.min(getWorldHeight(), 255), top.getZ() + 1); MainUtil.resetBiome(hybridPlotWorld, pos1, pos2); if (!hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) { @@ -163,9 +162,8 @@ public class HybridPlotManager extends ClassicPlotManager { PlotId id2 = new PlotId(id.x, id.y + 1); Location bot = getPlotBottomLocAbs(id2); Location top = getPlotTopLocAbs(id); - Location pos1 = - new Location(hybridPlotWorld.getWorldName(), bot.getX() - 1, 0, top.getZ() + 1); - Location pos2 = new Location(hybridPlotWorld.getWorldName(), top.getX() + 1, + Location pos1 = Location.at(hybridPlotWorld.getWorldName(), bot.getX() - 1, 0, top.getZ() + 1); + Location pos2 = Location.at(hybridPlotWorld.getWorldName(), top.getX() + 1, Math.min(getWorldHeight(), 255), bot.getZ()); MainUtil.resetBiome(hybridPlotWorld, pos1, pos2); if (!hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) { @@ -181,10 +179,8 @@ public class HybridPlotManager extends ClassicPlotManager { super.createRoadSouthEast(plot); PlotId id = plot.getId(); PlotId id2 = new PlotId(id.x + 1, id.y + 1); - Location pos1 = getPlotTopLocAbs(id).add(1, 0, 1); - Location pos2 = getPlotBottomLocAbs(id2); - pos1.setY(0); - pos2.setY(Math.min(getWorldHeight(), 255)); + Location pos1 = getPlotTopLocAbs(id).add(1, 0, 1).withY(0); + Location pos2 = getPlotBottomLocAbs(id2).withY(Math.min(getWorldHeight(), 255)); LocalBlockQueue queue = hybridPlotWorld.getQueue(false); createSchemAbs(queue, pos1, pos2); if (hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) { @@ -239,18 +235,18 @@ public class HybridPlotManager extends ClassicPlotManager { // Set the biome MainUtil.setBiome(world, value[2], value[3], value[4], value[5], biome); // These two locations are for each component (e.g. bedrock, main block, floor, air) - Location bot = new Location(world, value[2], 0, value[3]); - Location top = new Location(world, value[4], 1, value[5]); + Location bot = Location.at(world, value[2], 0, value[3]); + Location top = Location.at(world, value[4], 1, value[5]); queue.setCuboid(bot, top, bedrock); // Each component has a different layer - bot.setY(1); - top.setY(hybridPlotWorld.PLOT_HEIGHT); + bot = bot.withY(1); + top = top.withY(hybridPlotWorld.PLOT_HEIGHT); queue.setCuboid(bot, top, filling); - bot.setY(hybridPlotWorld.PLOT_HEIGHT); - top.setY(hybridPlotWorld.PLOT_HEIGHT + 1); + bot = bot.withY(hybridPlotWorld.PLOT_HEIGHT); + top = top.withY(hybridPlotWorld.PLOT_HEIGHT + 1); queue.setCuboid(bot, top, plotfloor); - bot.setY(hybridPlotWorld.PLOT_HEIGHT + 1); - top.setY(getWorldHeight()); + bot = bot.withY(hybridPlotWorld.PLOT_HEIGHT + 1); + top = top.withY(getWorldHeight()); queue.setCuboid(bot, top, air); // And finally set the schematic, the y value is unimportant for this function pastePlotSchematic(queue, bot, top); diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java index e746e90ea..778cc645a 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java @@ -128,15 +128,13 @@ public class HybridPlotWorld extends ClassicPlotWorld { return new HybridPlotManager(this); } - public Location getSignLocation(Plot plot) { + public Location getSignLocation(@NotNull Plot plot) { plot = plot.getBasePlot(false); - Location bot = plot.getBottomAbs(); + final Location bot = plot.getBottomAbs(); if (SIGN_LOCATION == null) { - bot.setY(ROAD_HEIGHT + 1); - return bot.add(-1, 0, -2); + return bot.withY(ROAD_HEIGHT + 1).add(-1, 0, -2); } else { - bot.setY(0); - return bot.add(SIGN_LOCATION.getX(), SIGN_LOCATION.getY(), SIGN_LOCATION.getZ()); + return bot.withY(0).add(SIGN_LOCATION.getX(), SIGN_LOCATION.getY(), SIGN_LOCATION.getZ()); } } diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java b/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java index 8ccd9dcc2..31408d750 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java @@ -222,8 +222,8 @@ public abstract class HybridUtils { }); System.gc(); MainUtil.initCache(); - Location botLoc = new Location(world, bot.getX(), bot.getY(), bot.getZ()); - Location topLoc = new Location(world, top.getX(), top.getY(), top.getZ()); + Location botLoc = Location.at(world, bot.getX(), bot.getY(), bot.getZ()); + Location topLoc = Location.at(world, top.getX(), top.getY(), top.getZ()); ChunkManager.chunkTask(botLoc, topLoc, new RunnableVal() { @Override public void run(int[] value) { int X = value[0]; diff --git a/Core/src/main/java/com/plotsquared/core/generator/SingleWorldGenerator.java b/Core/src/main/java/com/plotsquared/core/generator/SingleWorldGenerator.java index eb2037def..8555c98e4 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/SingleWorldGenerator.java +++ b/Core/src/main/java/com/plotsquared/core/generator/SingleWorldGenerator.java @@ -36,12 +36,13 @@ import com.sk89q.worldedit.world.biome.BiomeTypes; import com.sk89q.worldedit.world.block.BlockTypes; public class SingleWorldGenerator extends IndependentPlotGenerator { - private Location bedrock1 = new Location(null, 0, 0, 0); - private Location bedrock2 = new Location(null, 15, 0, 15); - private Location dirt1 = new Location(null, 0, 1, 0); - private Location dirt2 = new Location(null, 15, 2, 15); - private Location grass1 = new Location(null, 0, 3, 0); - private Location grass2 = new Location(null, 15, 3, 15); + + private static final Location bedrock1 = Location.at("", 0, 0, 0); + private static final Location bedrock2 = Location.at("", 15, 0, 15); + private static final Location dirt1 = Location.at("", 0, 1, 0); + private static final Location dirt2 = Location.at("", 15, 2, 15); + private static final Location grass1 = Location.at("", 0, 3, 0); + private static final Location grass2 = Location.at("", 15, 3, 15); @Override public String getName() { return "PlotSquared:single"; diff --git a/Core/src/main/java/com/plotsquared/core/generator/SquarePlotManager.java b/Core/src/main/java/com/plotsquared/core/generator/SquarePlotManager.java index 9dbd2c611..ad030f56c 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/SquarePlotManager.java +++ b/Core/src/main/java/com/plotsquared/core/generator/SquarePlotManager.java @@ -62,10 +62,8 @@ public abstract class SquarePlotManager extends GridPlotManager { Iterator iterator = regions.iterator(); CuboidRegion region = iterator.next(); iterator.remove(); - Location pos1 = new Location(plot.getWorldName(), region.getMinimumPoint().getX(), - region.getMinimumPoint().getY(), region.getMinimumPoint().getZ()); - Location pos2 = new Location(plot.getWorldName(), region.getMaximumPoint().getX(), - region.getMaximumPoint().getY(), region.getMaximumPoint().getZ()); + final Location pos1 = Location.at(plot.getWorldName(), region.getMinimumPoint()); + final Location pos2 = Location.at(plot.getWorldName(), region.getMaximumPoint()); RegionManager.manager.regenerateRegion(pos1, pos2, false, this); } }; @@ -80,7 +78,7 @@ public abstract class SquarePlotManager extends GridPlotManager { + squarePlotWorld.PLOT_WIDTH))) - (int) Math.floor(squarePlotWorld.ROAD_WIDTH / 2) - 1; int z = (squarePlotWorld.ROAD_OFFSET_Z + (pz * (squarePlotWorld.ROAD_WIDTH + squarePlotWorld.PLOT_WIDTH))) - (int) Math.floor(squarePlotWorld.ROAD_WIDTH / 2) - 1; - return new Location(squarePlotWorld.getWorldName(), x, Math.min(getWorldHeight(), 255), z); + return Location.at(squarePlotWorld.getWorldName(), x, Math.min(getWorldHeight(), 255), z); } @Override public PlotId getPlotIdAbs(int x, int y, int z) { @@ -247,7 +245,6 @@ public abstract class SquarePlotManager extends GridPlotManager { int z = (squarePlotWorld.ROAD_OFFSET_Z + (pz * (squarePlotWorld.ROAD_WIDTH + squarePlotWorld.PLOT_WIDTH))) - squarePlotWorld.PLOT_WIDTH - (int) Math .floor(squarePlotWorld.ROAD_WIDTH / 2); - return new Location(squarePlotWorld.getWorldName(), x, squarePlotWorld.getMinBuildHeight(), - z); + return Location.at(squarePlotWorld.getWorldName(), x, squarePlotWorld.getMinBuildHeight(), z); } } diff --git a/Core/src/main/java/com/plotsquared/core/location/Location.java b/Core/src/main/java/com/plotsquared/core/location/Location.java index c27ac6d5a..7c3e7ae04 100644 --- a/Core/src/main/java/com/plotsquared/core/location/Location.java +++ b/Core/src/main/java/com/plotsquared/core/location/Location.java @@ -41,15 +41,15 @@ import org.khelekore.prtree.SimpleMBR; /** * An unmodifiable 6-tuple (world,x,y,z,yaw,pitch) */ -@EqualsAndHashCode +@EqualsAndHashCode @SuppressWarnings("unused") public final class Location implements Comparable { @Getter private final float yaw; @Getter private final float pitch; - @Getter private final String world; @Getter private final BlockVector3 blockVector3; + private final World world; - private Location(@NotNull final String world, @NotNull final BlockVector3 blockVector3, + private Location(@NotNull final World world, @NotNull final BlockVector3 blockVector3, final float yaw, final float pitch) { this.world = Preconditions.checkNotNull(world, "World may not be null"); this.blockVector3 = Preconditions.checkNotNull(blockVector3, "Vector may not be null"); @@ -57,6 +57,19 @@ public final class Location implements Comparable { this.pitch = pitch; } + private Location(@NotNull final String worldName, @NotNull final BlockVector3 blockVector3, + final float yaw, final float pitch) { + Preconditions.checkNotNull(worldName, "World name may not be null"); + if (worldName.isEmpty()) { + this.world = World.nullWorld(); + } else { + this.world = PlotSquared.platform().getPlatformWorld(worldName); + } + this.blockVector3 = Preconditions.checkNotNull(blockVector3, "Vector may not be null"); + this.yaw = yaw; + this.pitch = pitch; + } + /** * Construct a new location * @@ -113,6 +126,80 @@ public final class Location implements Comparable { return at(world, BlockVector3.at(x, y, z)); } + /** + * Construct a new location + * + * @param world World + * @param blockVector3 (x,y,z) vector + * @param yaw yaw + * @param pitch pitch + * @return New location + */ + @NotNull public static Location at(@NotNull final World world, + @NotNull final BlockVector3 blockVector3, final float yaw, final float pitch) { + return new Location(world, blockVector3, yaw, pitch); + } + + /** + * Construct a new location with yaw and pitch equal to 0 + * + * @param world World + * @param blockVector3 (x,y,z) vector + * @return New location + */ + @NotNull public static Location at(@NotNull final World world, + @NotNull final BlockVector3 blockVector3) { + return at(world, blockVector3, 0f, 0f); + } + + /** + * Construct a new location + * + * @param world World + * @param x X coordinate + * @param y Y coordinate + * @param z Z coordinate + * @param yaw Yaw + * @param pitch Pitch + * @return New location + */ + @NotNull public static Location at(@NotNull final World world, final int x, final int y, + final int z, final float yaw, final float pitch) { + return at(world, BlockVector3.at(x, y, z), yaw, pitch); + } + + /** + * Construct a new location with yaw and pitch equal to 0 + * + * @param world World + * @param x X coordinate + * @param y Y coordinate + * @param z Z coordinate + * @return New location + */ + @NotNull public static Location at(@NotNull final World world, final int x, final int y, + final int z) { + return at(world, BlockVector3.at(x, y, z)); + } + + /** + * Get the world object + * + * @return World object + */ + @NotNull public World getWorld() { + return this.world; + } + + /** + * Get the name of the world this location is in + * + * @return World name + */ + @NotNull public String getWorldName() { + return this.world.getName(); + } + /** * Get the X coordinate * diff --git a/Core/src/main/java/com/plotsquared/core/location/World.java b/Core/src/main/java/com/plotsquared/core/location/World.java new file mode 100644 index 000000000..588447dd9 --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/location/World.java @@ -0,0 +1,84 @@ +/* + * _____ _ _ _____ _ + * | __ \| | | | / ____| | | + * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| | + * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` | + * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| | + * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_| + * | | + * |_| + * PlotSquared plot management system for Minecraft + * Copyright (C) 2020 IntellectualSites + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.plotsquared.core.location; + +import org.jetbrains.annotations.NotNull; + +/** + * PlotSquared representation of a platform world + * + * @param Platform world type + */ +public interface World { + + /** + * Get the platform world represented by this world + * + * @return Platform world + */ + @NotNull T getPlatformWorld(); + + /** + * Get the name of the world + * + * @return World name + */ + @NotNull String getName(); + + /** + * Get a {@link NullWorld} implementation + * + * @return NullWorld instance + */ + static NullWorld nullWorld() { + return new NullWorld<>(); + } + + class NullWorld implements World { + + private NullWorld() { + } + + @NotNull @Override public T getPlatformWorld() { + throw new UnsupportedOperationException("Cannot get platform world from NullWorld"); + } + + @Override public @NotNull String getName() { + return ""; + } + + @Override public boolean equals(final Object obj) { + return obj instanceof NullWorld; + } + + @Override public int hashCode() { + return "null".hashCode(); + } + + } + +} diff --git a/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java b/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java index a818562e3..1752b5e14 100644 --- a/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java @@ -56,11 +56,11 @@ public class ConsolePlayer extends PlotPlayer { Location location; if (area != null) { CuboidRegion region = area.getRegion(); - location = new Location(area.getWorldName(), + location = Location.at(area.getWorldName(), region.getMinimumPoint().getX() + region.getMaximumPoint().getX() / 2, 0, region.getMinimumPoint().getZ() + region.getMaximumPoint().getZ() / 2); } else { - location = new Location("world", 0, 0, 0); + location = Location.at("world", 0, 0, 0); } setMeta("location", location); } diff --git a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java index 800e2d875..642ebbee0 100644 --- a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java @@ -266,7 +266,7 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer */ public int getPlotCount() { if (!Settings.Limit.GLOBAL) { - return getPlotCount(getLocation().getWorld()); + return getPlotCount(getLocation().getWorldName()); } final AtomicInteger count = new AtomicInteger(0); final UUID uuid = getUUID(); @@ -286,7 +286,7 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer public int getClusterCount() { if (!Settings.Limit.GLOBAL) { - return getClusterCount(getLocation().getWorld()); + return getClusterCount(getLocation().getWorldName()); } final AtomicInteger count = new AtomicInteger(0); PlotSquared.get().getPlotAreaManager().forEachPlotArea(value -> { diff --git a/Core/src/main/java/com/plotsquared/core/plot/Plot.java b/Core/src/main/java/com/plotsquared/core/plot/Plot.java index dc6449d80..4da56f47f 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -1442,7 +1442,7 @@ public class Plot { return this.getDefaultHomeSynchronous(true); } else { Location bottom = this.getBottomAbs(); - Location location = Location.at(bottom.getWorld(), bottom.getX() + home.getX(), + Location location = Location.at(bottom.getWorldName(), bottom.getX() + home.getX(), bottom.getY() + home.getY(), bottom.getZ() + home.getZ(), home.getYaw(), home.getPitch()); if (!isLoaded()) { @@ -1466,7 +1466,7 @@ public class Plot { this.getDefaultHome(result); } else { Location bottom = this.getBottomAbs(); - Location location = Location.at(bottom.getWorld(), bottom.getX() + home.getX(), + Location location = Location.at(bottom.getWorldName(), bottom.getX() + home.getX(), bottom.getY() + home.getY(), bottom.getZ() + home.getZ(), home.getYaw(), home.getPitch()); if (!isLoaded()) { @@ -1850,7 +1850,7 @@ public class Plot { */ public void getBiome(Consumer result) { this.getCenter(location -> WorldUtil.IMP - .getBiome(location.getWorld(), location.getX(), location.getZ(), result)); + .getBiome(location.getWorldName(), location.getX(), location.getZ(), result)); } /** @@ -1859,7 +1859,7 @@ public class Plot { @Deprecated public BiomeType getBiomeSynchronous() { final Location location = this.getCenterSynchronous(); return WorldUtil.IMP - .getBiomeSynchronous(location.getWorld(), location.getX(), location.getZ()); + .getBiomeSynchronous(location.getWorldName(), location.getX(), location.getZ()); } //TODO Better documentation needed. diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java index 08ac2f962..e56446108 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java @@ -585,7 +585,7 @@ public abstract class PlotArea { } public boolean contains(@NotNull final Location location) { - return StringMan.isEqual(location.getWorld(), this.getWorldName()) && ( + return StringMan.isEqual(location.getWorldName(), this.getWorldName()) && ( getRegionAbs() == null || this.region.contains(location.getBlockVector3())); } diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotCluster.java b/Core/src/main/java/com/plotsquared/core/plot/PlotCluster.java index c9de0e90c..917259ef6 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotCluster.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotCluster.java @@ -31,6 +31,7 @@ import com.plotsquared.core.location.Location; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.RegionUtil; import com.sk89q.worldedit.regions.CuboidRegion; +import org.jetbrains.annotations.NotNull; import java.util.HashSet; import java.util.UUID; @@ -151,17 +152,17 @@ public class PlotCluster { + this.pos2.y; } - public void getHome(Consumer result) { - BlockLoc home = this.settings.getPosition(); - Consumer locationConsumer = toReturn -> { + public void getHome(@NotNull final Consumer result) { + final BlockLoc home = this.settings.getPosition(); + Consumer locationConsumer = toReturn -> MainUtil.getHighestBlock(this.area.getWorldName(), toReturn.getX(), toReturn.getZ(), max -> { if (max > toReturn.getY()) { - toReturn.setY(1 + max); + result.accept(toReturn.withY(1 + max)); + } else { + result.accept(toReturn); } - result.accept(toReturn); - }); - }; + }); if (home.getY() == 0) { // default pos Plot center = getCenterPlot(); @@ -170,7 +171,7 @@ public class PlotCluster { if (toReturn.getY() == 0) { PlotManager manager = this.area.getPlotManager(); Location locationSign = manager.getSignLoc(center); - toReturn.setY(locationSign.getY()); + toReturn = toReturn.withY(locationSign.getY()); } locationConsumer.accept(toReturn); }); diff --git a/Core/src/main/java/com/plotsquared/core/plot/world/DefaultPlotAreaManager.java b/Core/src/main/java/com/plotsquared/core/plot/world/DefaultPlotAreaManager.java index f734ff8a7..6c3035451 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/world/DefaultPlotAreaManager.java +++ b/Core/src/main/java/com/plotsquared/core/plot/world/DefaultPlotAreaManager.java @@ -58,7 +58,7 @@ public class DefaultPlotAreaManager implements PlotAreaManager { if (location == null) { return null; } - final PlotWorld world = this.plotWorlds.get(location.getWorld()); + final PlotWorld world = this.plotWorlds.get(location.getWorldName()); if (world == null) { return null; } diff --git a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotArea.java b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotArea.java index 09c1f3859..5cd467e13 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotArea.java +++ b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotArea.java @@ -156,23 +156,23 @@ public class SinglePlotArea extends GridPlotWorld { } @Nullable @Override public Plot getOwnedPlot(@NotNull final Location location) { - PlotId pid = PlotId.fromStringOrNull(location.getWorld()); + PlotId pid = PlotId.fromStringOrNull(location.getWorldName()); Plot plot = pid == null ? null : this.plots.get(pid); return plot == null ? null : plot.getBasePlot(false); } @Nullable @Override public Plot getOwnedPlotAbs(@NotNull Location location) { - PlotId pid = PlotId.fromStringOrNull(location.getWorld()); + PlotId pid = PlotId.fromStringOrNull(location.getWorldName()); return pid == null ? null : plots.get(pid); } @Nullable @Override public Plot getPlot(@NotNull final Location location) { - PlotId pid = PlotId.fromStringOrNull(location.getWorld()); + PlotId pid = PlotId.fromStringOrNull(location.getWorldName()); return pid == null ? null : getPlot(pid); } @Nullable @Override public Plot getPlotAbs(@NotNull final Location location) { - final PlotId pid = PlotId.fromStringOrNull(location.getWorld()); + final PlotId pid = PlotId.fromStringOrNull(location.getWorldName()); return pid == null ? null : getPlotAbs(pid); } diff --git a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotAreaManager.java b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotAreaManager.java index 72c4ce0eb..9ea6af1dc 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotAreaManager.java +++ b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotAreaManager.java @@ -99,7 +99,7 @@ public class SinglePlotAreaManager extends DefaultPlotAreaManager { if (location == null) { return null; } - String world = location.getWorld(); + String world = location.getWorldName(); return isWorld(world) || world.equals("*") || super.getAllPlotAreas().length == 0 ? area : super.getApplicablePlotArea(location); @@ -118,7 +118,7 @@ public class SinglePlotAreaManager extends DefaultPlotAreaManager { if (found != null) { return found; } - return isWorld(location.getWorld()) || location.getWorld().equals("*") ? area : null; + return isWorld(location.getWorldName()) || location.getWorldName().equals("*") ? area : null; } @Override @NotNull public PlotArea[] getPlotAreas(@NotNull final String world, @NotNull final CuboidRegion region) { diff --git a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotManager.java b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotManager.java index 6083434a8..ecfb756af 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotManager.java +++ b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotManager.java @@ -35,6 +35,7 @@ import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.SetupUtils; import com.plotsquared.core.util.task.TaskManager; import com.sk89q.worldedit.function.pattern.Pattern; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.util.List; @@ -52,12 +53,12 @@ public class SinglePlotManager extends PlotManager { return new PlotId(0, 0); } - @Override public Location getPlotBottomLocAbs(PlotId plotId) { - return new Location(plotId.toCommaSeparatedString(), -30000000, 0, -30000000); + @Override public Location getPlotBottomLocAbs(@NotNull final PlotId plotId) { + return Location.at(plotId.toCommaSeparatedString(), -30000000, 0, -30000000); } - @Override public Location getPlotTopLocAbs(PlotId plotId) { - return new Location(plotId.toCommaSeparatedString(), 30000000, 0, 30000000); + @Override public Location getPlotTopLocAbs(@NotNull final PlotId plotId) { + return Location.at(plotId.toCommaSeparatedString(), 30000000, 0, 30000000); } @Override public boolean clearPlot(Plot plot, final Runnable whenDone) { diff --git a/Core/src/main/java/com/plotsquared/core/queue/ChunkBlockQueue.java b/Core/src/main/java/com/plotsquared/core/queue/ChunkBlockQueue.java index a8e0d1c1a..84b40b64b 100644 --- a/Core/src/main/java/com/plotsquared/core/queue/ChunkBlockQueue.java +++ b/Core/src/main/java/com/plotsquared/core/queue/ChunkBlockQueue.java @@ -31,6 +31,7 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Arrays; @@ -46,7 +47,7 @@ public class ChunkBlockQueue extends ScopedLocalBlockQueue { private final BlockVector3 top; public ChunkBlockQueue(BlockVector3 bot, BlockVector3 top, boolean biomes) { - super(null, new Location(null, 0, 0, 0), new Location(null, 15, 255, 15)); + super(null, Location.at("", 0, 0, 0), Location.at("", 15, 255, 15)); this.width = top.getX() - bot.getX() + 1; this.length = top.getZ() - bot.getZ() + 1; this.area = width * length; @@ -113,15 +114,15 @@ public class ChunkBlockQueue extends ScopedLocalBlockQueue { return null; } - @Override @Nullable public String getWorld() { - return null; + @Override @NotNull public String getWorld() { + return ""; } @Override public Location getMax() { - return new Location(getWorld(), top.getX(), top.getY(), top.getZ()); + return Location.at(getWorld(), top.getX(), top.getY(), top.getZ()); } @Override public Location getMin() { - return new Location(getWorld(), bot.getX(), bot.getY(), bot.getZ()); + return Location.at(getWorld(), bot.getX(), bot.getY(), bot.getZ()); } } diff --git a/Core/src/main/java/com/plotsquared/core/queue/LocalBlockQueue.java b/Core/src/main/java/com/plotsquared/core/queue/LocalBlockQueue.java index fc55f8942..b0eb807bf 100644 --- a/Core/src/main/java/com/plotsquared/core/queue/LocalBlockQueue.java +++ b/Core/src/main/java/com/plotsquared/core/queue/LocalBlockQueue.java @@ -125,7 +125,7 @@ public abstract class LocalBlockQueue { for (final PlotPlayer pp : PlotSquared.platform().getPlayerManager().getPlayers()) { Location pLoc = pp.getLocation(); - if (!StringMan.isEqual(getWorld(), pLoc.getWorld()) || !pLoc.getChunkLocation() + if (!StringMan.isEqual(getWorld(), pLoc.getWorldName()) || !pLoc.getChunkLocation() .equals(loc)) { continue; } diff --git a/Core/src/main/java/com/plotsquared/core/queue/ScopedLocalBlockQueue.java b/Core/src/main/java/com/plotsquared/core/queue/ScopedLocalBlockQueue.java index 637fc80bb..b141a5e61 100644 --- a/Core/src/main/java/com/plotsquared/core/queue/ScopedLocalBlockQueue.java +++ b/Core/src/main/java/com/plotsquared/core/queue/ScopedLocalBlockQueue.java @@ -35,6 +35,7 @@ import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; +import org.jetbrains.annotations.NotNull; public class ScopedLocalBlockQueue extends DelegateLocalBlockQueue { private final int minX; @@ -92,11 +93,11 @@ public class ScopedLocalBlockQueue extends DelegateLocalBlockQueue { } public Location getMin() { - return new Location(getWorld(), minX, minY, minZ); + return Location.at(this.getWorld(), this.minX, this.minY, this.minZ); } public Location getMax() { - return new Location(getWorld(), maxX, maxY, maxZ); + return Location.at(this.getWorld(), this.maxX, this.maxY, this.maxZ); } /** @@ -107,26 +108,22 @@ public class ScopedLocalBlockQueue extends DelegateLocalBlockQueue { * * @param task */ - public void mapByType2D(RunnableVal3 task) { - int bx = minX; - int bz = minZ; - PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotArea(getWorld(), null); - Location location = new Location(getWorld(), bx, 0, bz); + public void mapByType2D(@NotNull final RunnableVal3 task) { + final int bx = minX; + final int bz = minZ; + final PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotArea(getWorld(), null); + final Location location = Location.at(getWorld(), bx, 0, bz); if (area != null) { PlotManager manager = area.getPlotManager(); for (int x = 0; x < 16; x++) { - location.setX(bx + x); for (int z = 0; z < 16; z++) { - location.setZ(bz + z); - task.run(area.getPlotAbs(location), x, z); + task.run(area.getPlotAbs(location.withX(bx + x).withZ(bz + z)), x, z); } } } else { for (int x = 0; x < 16; x++) { - location.setX(bx + x); for (int z = 0; z < 16; z++) { - location.setZ(bz + z); - task.run(location.getPlotAbs(), x, z); + task.run(location.withX(bx + x).withZ(bz + z).getPlotAbs(), x, z); } } } diff --git a/Core/src/main/java/com/plotsquared/core/util/ChunkManager.java b/Core/src/main/java/com/plotsquared/core/util/ChunkManager.java index f1e27f5f8..6e6f1750b 100644 --- a/Core/src/main/java/com/plotsquared/core/util/ChunkManager.java +++ b/Core/src/main/java/com/plotsquared/core/util/ChunkManager.java @@ -56,8 +56,8 @@ public abstract class ChunkManager { int blockX = loc.getX() << 4; int blockZ = loc.getZ() << 4; ScopedLocalBlockQueue scoped = - new ScopedLocalBlockQueue(queue, new Location(world, blockX, 0, blockZ), - new Location(world, blockX + 15, 255, blockZ + 15)); + new ScopedLocalBlockQueue(queue, Location.at(world, blockX, 0, blockZ), + Location.at(world, blockX + 15, 255, blockZ + 15)); if (force != null) { force.run(scoped); } else { @@ -108,9 +108,9 @@ public abstract class ChunkManager { return; } CuboidRegion value = regions.remove(0); - Location pos1 = new Location(plot.getWorldName(), value.getMinimumPoint().getX(), 0, + Location pos1 = Location.at(plot.getWorldName(), value.getMinimumPoint().getX(), 0, value.getMinimumPoint().getZ()); - Location pos2 = new Location(plot.getWorldName(), value.getMaximumPoint().getX(), 0, + Location pos2 = Location.at(plot.getWorldName(), value.getMaximumPoint().getX(), 0, value.getMaximumPoint().getZ()); chunkTask(pos1, pos2, task, this, allocate); } @@ -191,12 +191,12 @@ public abstract class ChunkManager { int z1 = chunk.getZ() << 4; int x2 = x1 + 15; int z2 = z1 + 15; - Location bot = new Location(world, x1, 0, z1); + Location bot = Location.at(world, x1, 0, z1); Plot plot = bot.getOwnedPlotAbs(); if (plot != null) { return plot; } - Location top = new Location(world, x2, 0, z2); + Location top = Location.at(world, x2, 0, z2); plot = top.getOwnedPlotAbs(); return plot; } diff --git a/Core/src/main/java/com/plotsquared/core/util/MainUtil.java b/Core/src/main/java/com/plotsquared/core/util/MainUtil.java index 4286da033..8895b9385 100644 --- a/Core/src/main/java/com/plotsquared/core/util/MainUtil.java +++ b/Core/src/main/java/com/plotsquared/core/util/MainUtil.java @@ -397,12 +397,10 @@ public class MainUtil { return plot.getFlag(ServerPlotFlag.class); } - @NotNull public static Location[] getCorners(String world, CuboidRegion region) { - BlockVector3 min = region.getMinimumPoint(); - BlockVector3 max = region.getMaximumPoint(); - Location pos1 = new Location(world, min.getX(), min.getY(), min.getZ()); - Location pos2 = new Location(world, max.getX(), max.getY(), max.getZ()); - return new Location[] {pos1, pos2}; + @NotNull public static Location[] getCorners(@NotNull final String world, @NotNull final CuboidRegion region) { + final BlockVector3 min = region.getMinimumPoint(); + final BlockVector3 max = region.getMaximumPoint(); + return new Location[] {Location.at(world, min), Location.at(world, max)}; } /** @@ -426,16 +424,16 @@ public class MainUtil { Location pos1 = corners[0]; Location pos2 = corners[1]; if (pos2.getX() > max.getX()) { - max.setX(pos2.getX()); + max = max.withX(pos2.getX()); } if (pos1.getX() < min.getX()) { - min.setX(pos1.getX()); + min = min.withX(pos1.getX()); } if (pos2.getZ() > max.getZ()) { - max.setZ(pos2.getZ()); + max = max.withZ(pos2.getZ()); } if (pos1.getZ() < min.getZ()) { - min.setZ(pos1.getZ()); + min = min.withZ(pos1.getZ()); } } return new Location[] {min, max}; diff --git a/Core/src/main/java/com/plotsquared/core/util/OperationUtil.java b/Core/src/main/java/com/plotsquared/core/util/OperationUtil.java index 37dc11d80..1bf55bfac 100644 --- a/Core/src/main/java/com/plotsquared/core/util/OperationUtil.java +++ b/Core/src/main/java/com/plotsquared/core/util/OperationUtil.java @@ -75,7 +75,7 @@ public class OperationUtil { weWorld = ((Player) actor).getWorld(); } else { @NotNull Location loc = plotPlayer.getLocation(); - String world = loc.getWorld(); + String world = loc.getWorldName(); weWorld = getWorld(world); } return weWorld; diff --git a/Core/src/main/java/com/plotsquared/core/util/RegionManager.java b/Core/src/main/java/com/plotsquared/core/util/RegionManager.java index 8e8316862..a2bb9b2e8 100644 --- a/Core/src/main/java/com/plotsquared/core/util/RegionManager.java +++ b/Core/src/main/java/com/plotsquared/core/util/RegionManager.java @@ -155,9 +155,9 @@ public abstract class RegionManager { final Pattern blocks, int minY, int maxY) { LocalBlockQueue queue = area.getQueue(false); for (CuboidRegion region : regions) { - Location pos1 = new Location(area.getWorldName(), region.getMinimumPoint().getX(), minY, + Location pos1 = Location.at(area.getWorldName(), region.getMinimumPoint().getX(), minY, region.getMinimumPoint().getZ()); - Location pos2 = new Location(area.getWorldName(), region.getMaximumPoint().getX(), maxY, + Location pos2 = Location.at(area.getWorldName(), region.getMaximumPoint().getX(), maxY, region.getMaximumPoint().getZ()); queue.setCuboid(pos1, pos2, blocks); } diff --git a/Core/src/main/java/com/plotsquared/core/util/WEManager.java b/Core/src/main/java/com/plotsquared/core/util/WEManager.java index 979d56ee3..ea5d98ab8 100644 --- a/Core/src/main/java/com/plotsquared/core/util/WEManager.java +++ b/Core/src/main/java/com/plotsquared/core/util/WEManager.java @@ -87,7 +87,7 @@ public class WEManager { HashSet regions = new HashSet<>(); UUID uuid = player.getUUID(); Location location = player.getLocation(); - String world = location.getWorld(); + String world = location.getWorldName(); if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) { regions.add(RegionUtil .createRegion(Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, diff --git a/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java b/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java index 29cb707fd..fe72385f4 100644 --- a/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java +++ b/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java @@ -151,7 +151,7 @@ public abstract class WorldUtil { int trx = top.getX() >> 9; int trz = top.getZ() >> 9; Set files = - RegionManager.manager.getChunkChunks(bot.getWorld()); + RegionManager.manager.getChunkChunks(bot.getWorldName()); for (BlockVector2 mca : files) { if (mca.getX() >= brx && mca.getX() <= trx && mca.getZ() >= brz && mca.getZ() <= trz) {