Clean up PlotAreaManager and move a bunch of plot area related logic out of PlotSquared

This commit is contained in:
Alexander Söderberg 2020-07-07 13:37:03 +02:00
parent d76c9dad52
commit 196df855ac
No known key found for this signature in database
GPG Key ID: C0207FF7EA146678
40 changed files with 288 additions and 241 deletions

View File

@ -1010,7 +1010,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
}
map.put(plotAreaType.name().toLowerCase(), terrainTypes);
}
for (final PlotArea plotArea : PlotSquared.get().getPlotAreas()) {
for (final PlotArea plotArea : PlotSquared.get().getPlotAreaManager().getAllPlotAreas()) {
final Map<String, Integer> terrainTypeMap =
map.get(plotArea.getType().name().toLowerCase());
terrainTypeMap.put(plotArea.getTerrain().name().toLowerCase(),
@ -1071,7 +1071,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
world = Bukkit.getWorld(worldName);
} else {
try {
if (!PlotSquared.get().hasPlotArea(worldName)) {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(worldName)) {
SetGenCB.setGenerator(BukkitUtil.getWorld(worldName));
}
} catch (Exception e) {

View File

@ -54,7 +54,10 @@ final class BlockStatePopulator extends BlockPopulator {
if (this.queue == null) {
this.queue = GlobalBlockQueue.IMP.getNewQueue(world.getName(), false);
}
final PlotArea area = PlotSquared.get().getPlotArea(world.getName(), null);
final PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotArea(world.getName(), null);
if (area == null) {
return;
}
final ChunkWrapper wrap =
new ChunkWrapper(area.getWorldName(), source.getX(), source.getZ());
final ScopedLocalBlockQueue chunk = this.queue.getForChunk(wrap.x, wrap.z);

View File

@ -108,7 +108,7 @@ public class BukkitPlotGenerator extends ChunkGenerator
if (!this.loaded) {
String name = world.getName();
PlotSquared.get().loadWorld(name, this);
Set<PlotArea> areas = PlotSquared.get().getPlotAreas(name);
final Set<PlotArea> areas = PlotSquared.get().getPlotAreaManager().getPlotAreasSet(name);
if (!areas.isEmpty()) {
PlotArea area = areas.iterator().next();
if (!area.isMobSpawning()) {
@ -198,8 +198,8 @@ public class BukkitPlotGenerator extends ChunkGenerator
if (ChunkManager.preProcessChunk(loc, result)) {
return;
}
PlotArea area = PlotSquared.get().getPlotArea(world.getName(), null);
if (area == null && (area = PlotSquared.get().getPlotArea(this.levelName, null)) == null) {
PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotArea(world.getName(), null);
if (area == null && (area = PlotSquared.get().getPlotAreaManager().getPlotArea(this.levelName, null)) == null) {
throw new IllegalStateException(
"Cannot regenerate chunk that does not belong to a plot area." + " Location: " + loc
+ ", world: " + world);

View File

@ -90,7 +90,7 @@ public class ChunkListener implements Listener {
HashSet<Chunk> toUnload = new HashSet<>();
for (World world : Bukkit.getWorlds()) {
String worldName = world.getName();
if (!PlotSquared.get().hasPlotArea(worldName)) {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(worldName)) {
continue;
}
Object w = world.getClass().getDeclaredMethod("getHandle").invoke(world);
@ -177,7 +177,7 @@ public class ChunkListener implements Listener {
Chunk chunk = event.getChunk();
if (Settings.Chunk_Processor.AUTO_TRIM) {
String world = chunk.getWorld().getName();
if (PlotSquared.get().hasPlotArea(world)) {
if (PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) {
if (unloadChunk(world, chunk, true)) {
return;
}
@ -200,7 +200,7 @@ public class ChunkListener implements Listener {
event.setCancelled(true);
return;
}
if (!PlotSquared.get().hasPlotArea(chunk.getWorld().getName())) {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(chunk.getWorld().getName())) {
return;
}
Entity[] entities = chunk.getEntities();
@ -230,7 +230,7 @@ public class ChunkListener implements Listener {
event.setCancelled(true);
return;
}
if (!PlotSquared.get().hasPlotArea(chunk.getWorld().getName())) {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(chunk.getWorld().getName())) {
return;
}
Entity[] entities = chunk.getEntities();
@ -281,7 +281,7 @@ public class ChunkListener implements Listener {
}
public boolean processChunk(Chunk chunk, boolean unload) {
if (!PlotSquared.get().hasPlotArea(chunk.getWorld().getName())) {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(chunk.getWorld().getName())) {
return false;
}
Entity[] entities = chunk.getEntities();

View File

@ -78,7 +78,7 @@ public class EntitySpawnListener implements Listener {
if (areaName == world.getName()) {
} else {
areaName = world.getName();
hasPlotArea = PlotSquared.get().hasPlotArea(areaName);
hasPlotArea = PlotSquared.get().getPlotAreaManager().hasPlotArea(areaName);
}
if (!hasPlotArea) {
return;
@ -90,7 +90,7 @@ public class EntitySpawnListener implements Listener {
@NotNull World world = entity.getWorld();
List<MetadataValue> meta = entity.getMetadata(KEY);
if (meta.isEmpty()) {
if (PlotSquared.get().hasPlotArea(world.getName())) {
if (PlotSquared.get().getPlotAreaManager().hasPlotArea(world.getName())) {
entity.setMetadata(KEY,
new FixedMetadataValue((Plugin) PlotSquared.platform(), entity.getLocation()));
}

View File

@ -305,7 +305,7 @@ public class PaperListener implements Listener {
return;
}
Location location = BukkitUtil.getLocation(entity);
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorld())) {
return;
}
PlotPlayer<?> pp = BukkitUtil.getPlayer((Player) shooter);

View File

@ -483,7 +483,7 @@ public class PlayerEvents extends PlotListener implements Listener {
return;
}
Location location = BukkitUtil.getLocation(entity);
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorld())) {
return;
}
PlotPlayer<Player> pp = BukkitUtil.getPlayer((Player) shooter);
@ -497,7 +497,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().hasPlotArea(location.getWorld())) {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorld())) {
return true;
}
PlotArea area = location.getPlotArea();
@ -1069,7 +1069,7 @@ public class PlayerEvents extends PlotListener implements Listener {
PlotArea area = location.getPlotArea();
boolean plotArea = location.isPlotArea();
if (!plotArea) {
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorld())) {
return;
}
return;
@ -1165,7 +1165,7 @@ public class PlayerEvents extends PlotListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityBlockForm(EntityBlockFormEvent event) {
String world = event.getBlock().getWorld().getName();
if (!PlotSquared.get().hasPlotArea(world)) {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) {
return;
}
Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
@ -1495,7 +1495,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().hasPlotArea(location.getWorld())) {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorld())) {
return;
}
for (Block block1 : event.getBlocks()) {
@ -1532,7 +1532,7 @@ public class PlayerEvents extends PlotListener implements Listener {
Location location = BukkitUtil.getLocation(block.getLocation());
PlotArea area = location.getPlotArea();
if (area == null) {
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorld())) {
return;
}
if (this.pistonBlocks) {
@ -1625,7 +1625,7 @@ public class PlayerEvents extends PlotListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onStructureGrow(StructureGrowEvent event) {
if (!PlotSquared.get().hasPlotArea(event.getWorld().getName())) {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(event.getWorld().getName())) {
return;
}
List<org.bukkit.block.BlockState> blocks = event.getBlocks();
@ -1688,7 +1688,7 @@ public class PlayerEvents extends PlotListener implements Listener {
return;
}*/
HumanEntity entity = event.getWhoClicked();
if (!(entity instanceof Player) || !PlotSquared.get()
if (!(entity instanceof Player) || !PlotSquared.get().getPlotAreaManager()
.hasPlotArea(entity.getWorld().getName())) {
return;
}
@ -1819,7 +1819,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().hasPlotArea(location.getWorld())) {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorld())) {
return;
}
if (!this.onProjectileHit(event)) {
@ -1884,7 +1884,7 @@ public class PlayerEvents extends PlotListener implements Listener {
Block block = event.getBlock();
Location location = BukkitUtil.getLocation(block.getLocation());
String world = location.getWorld();
if (!PlotSquared.get().hasPlotArea(world)) {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) {
return;
}
PlotArea area = location.getPlotArea();
@ -2158,7 +2158,7 @@ public class PlayerEvents extends PlotListener implements Listener {
Block block = event.getBlock();
World world = block.getWorld();
String worldName = world.getName();
if (!PlotSquared.get().hasPlotArea(worldName)) {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(worldName)) {
return;
}
Location location = BukkitUtil.getLocation(block.getLocation());
@ -2669,7 +2669,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().hasPlotArea(location.getWorld())) {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorld())) {
return;
}
int count = 0;
@ -2699,7 +2699,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().hasPlotArea(location.getWorld())) {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorld())) {
return;
}
Entity victim = event.getEntity();

View File

@ -87,7 +87,6 @@ import com.plotsquared.core.util.task.TaskManager;
import com.plotsquared.core.uuid.UUIDPipeline;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.regions.CuboidRegion;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
@ -387,11 +386,17 @@ public class PlotSquared<P> {
return PlotSquared.instance;
}
/**
* Get the platform specific implementation of PlotSquared
*
* @return Platform implementation
*/
@NotNull public static PlotPlatform<?> platform() {
if (instance != null && instance.platform != null) {
return instance.platform;
}
throw new IllegalStateException("Plot main implementation is missing");
throw new IllegalStateException("Plot platform implementation is missing");
}
/**
@ -480,9 +485,12 @@ public class PlotSquared<P> {
return plot.getArea().getPlotManager();
}
public PlotManager getPlotManager(Location location) {
PlotArea pa = getPlotAreaAbs(location);
return pa != null ? pa.getPlotManager() : null;
@Nullable public PlotManager getPlotManager(@NotNull final Location location) {
final PlotArea plotArea = this.getPlotAreaManager().getPlotArea(location);
if (plotArea == null) {
return null;
}
return plotArea.getPlotManager();
}
/**
@ -586,8 +594,8 @@ public class PlotSquared<P> {
setPlotsTmp(area);
}
public void removePlotAreas(String world) {
for (PlotArea area : getPlotAreas(world)) {
public void removePlotAreas(@NotNull final String world) {
for (final PlotArea area : this.getPlotAreaManager().getPlotAreasSet(world)) {
if (area.getWorldName().equals(world)) {
removePlotArea(area);
}
@ -609,9 +617,9 @@ public class PlotSquared<P> {
this.clusters_tmp.put(area.toString(), area.getClusters());
}
public Set<PlotCluster> getClusters(String world) {
Set<PlotCluster> set = new HashSet<>();
for (PlotArea area : getPlotAreas(world)) {
public Set<PlotCluster> getClusters(@NotNull final String world) {
final Set<PlotCluster> set = new HashSet<>();
for (final PlotArea area : this.getPlotAreaManager().getPlotAreasSet(world)) {
set.addAll(area.getClusters());
}
return Collections.unmodifiableSet(set);
@ -882,7 +890,7 @@ public class PlotSquared<P> {
*/
@Deprecated public Set<Plot> getPlots(final PlotFilter... filters) {
final List<PlotArea> areas = new LinkedList<>();
for (final PlotArea plotArea : this.getPlotAreas()) {
for (final PlotArea plotArea : this.getPlotAreaManager().getAllPlotAreas()) {
for (final PlotFilter filter : filters) {
if (filter.allowsArea(plotArea)) {
areas.add(plotArea);
@ -911,21 +919,20 @@ public class PlotSquared<P> {
return result;
}
public void setPlots(HashMap<String, HashMap<PlotId, Plot>> plots) {
public void setPlots(@NotNull final Map<String, HashMap<PlotId, Plot>> plots) {
if (this.plots_tmp == null) {
this.plots_tmp = new HashMap<>();
}
for (Entry<String, HashMap<PlotId, Plot>> entry : plots.entrySet()) {
String world = entry.getKey();
PlotArea area = getPlotArea(world, null);
if (area == null) {
HashMap<PlotId, Plot> map =
this.plots_tmp.computeIfAbsent(world, k -> new HashMap<>());
for (final Entry<String, HashMap<PlotId, Plot>> entry : plots.entrySet()) {
final String world = entry.getKey();
final PlotArea plotArea = this.getPlotAreaManager().getPlotArea(world, null);
if (plotArea == null) {
Map<PlotId, Plot> map = this.plots_tmp.computeIfAbsent(world, k -> new HashMap<>());
map.putAll(entry.getValue());
} else {
for (Plot plot : entry.getValue().values()) {
plot.setArea(area);
area.addPlot(plot);
plot.setArea(plotArea);
plotArea.addPlot(plot);
}
}
}
@ -962,7 +969,7 @@ public class PlotSquared<P> {
* @param player the plot owner
* @return Set of plot
*/
public Set<Plot> getPlots(String world, PlotPlayer player) {
public Set<Plot> getPlots(String world, PlotPlayer<?> player) {
return PlotQuery.newQuery().inWorld(world).ownedBy(player).asSet();
}
@ -973,7 +980,7 @@ public class PlotSquared<P> {
* @param player the plot owner
* @return Set of plot
*/
public Set<Plot> getPlots(PlotArea area, PlotPlayer player) {
public Set<Plot> getPlots(PlotArea area, PlotPlayer<?> player) {
return PlotQuery.newQuery().inArea(area).ownedBy(player).asSet();
}
@ -999,17 +1006,6 @@ public class PlotSquared<P> {
return PlotQuery.newQuery().inArea(area).ownedBy(uuid).asSet();
}
/**
* Check if a plot world.
*
* @param world the world
* @return if a plot world is registered
* @see #getPlotAreaByString(String) to get the PlotArea object
*/
public boolean hasPlotArea(String world) {
return plotAreaManager.getPlotAreas(world, null).length != 0;
}
public Collection<Plot> getPlots(String world) {
return PlotQuery.newQuery().inWorld(world).asCollection();
}
@ -1020,7 +1016,7 @@ public class PlotSquared<P> {
* @param player the player to retrieve the plots for
* @return Set of Plot
*/
public Set<Plot> getPlots(PlotPlayer player) {
public Set<Plot> getPlots(PlotPlayer<?> player) {
return PlotQuery.newQuery().ownedBy(player).asSet();
}
@ -1032,7 +1028,7 @@ public class PlotSquared<P> {
return area == null ? null : id == null ? null : area.getPlot(id);
}
public Set<Plot> getBasePlots(PlotPlayer player) {
public Set<Plot> getBasePlots(PlotPlayer<?> player) {
return getBasePlots(player.getUUID());
}
@ -1276,7 +1272,7 @@ public class PlotSquared<P> {
throw new IllegalArgumentException("Invalid Area identifier: " + areaId
+ ". Expected form `<name>-<x1;z1>-<x2;z2>`");
}
PlotArea existing = getPlotArea(world, name);
final PlotArea existing = this.getPlotAreaManager().getPlotArea(world, name);
if (existing != null && name.equals(existing.getId())) {
continue;
}
@ -1937,11 +1933,6 @@ public class PlotSquared<P> {
}
}
public PlotArea getFirstPlotArea() {
PlotArea[] areas = plotAreaManager.getAllPlotAreas();
return areas.length > 0 ? areas[0] : null;
}
public int getPlotAreaCount() {
return this.plotAreaManager.getAllPlotAreas().length;
}
@ -1951,12 +1942,6 @@ public class PlotSquared<P> {
.mapToInt(PlotArea::getPlotCount).sum();
}
public Set<PlotArea> getPlotAreas() {
final Set<PlotArea> set = new HashSet<>();
Collections.addAll(set, plotAreaManager.getAllPlotAreas());
return Collections.unmodifiableSet(set);
}
/**
* Check if the chunk uses vanilla/non-PlotSquared generation
*
@ -1979,81 +1964,6 @@ public class PlotSquared<P> {
return areas != null && (areas.length > 1 || areas[0].getType() != PlotAreaType.NORMAL);
}
/**
* Gets a list of PlotArea objects.
*
* @param world the world
* @return Collection of PlotArea objects
*/
public Set<PlotArea> getPlotAreas(@NonNull final String world) {
final Set<PlotArea> set = new HashSet<>();
Collections.addAll(set, plotAreaManager.getPlotAreas(world, null));
return set;
}
/**
* Gets the relevant plot area for a specified location.
* <ul>
* <li>If there is only one plot area globally that will be returned.
* <li>If there is only one plot area in the world, it will return that.
* <li>If the plot area for a location cannot be unambiguously
* resolved, null will be returned.
* </ul>
* Note: An applicable plot area may not include the location i.e. clusters
*
* @param location the location
* @return
*/
public PlotArea getApplicablePlotArea(@NonNull final Location location) {
return plotAreaManager.getApplicablePlotArea(location);
}
public PlotArea getPlotArea(@NonNull final String world, final String id) {
return plotAreaManager.getPlotArea(world, id);
}
/**
* Gets the {@code PlotArea} which contains a location.
* <ul>
* <li>If the plot area does not contain a location, null
* will be returned.
* </ul>
*
* @param location the location
* @return the {@link PlotArea} in the location, null if non existent
*/
public PlotArea getPlotAreaAbs(@NonNull final Location location) {
return plotAreaManager.getPlotArea(location);
}
public PlotArea getPlotAreaByString(@NonNull final String search) {
String[] split = search.split("[;,]");
PlotArea[] areas = plotAreaManager.getPlotAreas(split[0], null);
if (areas == null) {
for (PlotArea area : plotAreaManager.getAllPlotAreas()) {
if (area.getWorldName().equalsIgnoreCase(split[0])) {
if (area.getId() == null || split.length == 2 && area.getId()
.equalsIgnoreCase(split[1])) {
return area;
}
}
}
return null;
}
if (areas.length == 1) {
return areas[0];
} else if (split.length == 1) {
return null;
} else {
for (PlotArea area : areas) {
if (StringMan.isEqual(split[1], area.getId())) {
return area;
}
}
return null;
}
}
/**
* Gets Plots based on alias
*
@ -2066,13 +1976,6 @@ public class PlotSquared<P> {
return PlotQuery.newQuery().inWorld(worldname).withAlias(alias).asSet();
}
public Set<PlotArea> getPlotAreas(final String world, final CuboidRegion region) {
final PlotArea[] areas = plotAreaManager.getPlotAreas(world, region);
final Set<PlotArea> set = new HashSet<>();
Collections.addAll(set, areas);
return Collections.unmodifiableSet(set);
}
public YamlConfiguration getConfig() {
return config;
}

View File

@ -157,7 +157,7 @@ import java.util.UUID;
if (world == null) {
return Collections.emptySet();
}
return PlotSquared.get().getPlotAreas(world);
return PlotSquared.get().getPlotAreaManager().getPlotAreasSet(world);
}
/**

View File

@ -70,6 +70,8 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Set;
@ -102,7 +104,7 @@ public class Area extends SubCommand {
MainUtil.sendMessage(player, Captions.SINGLE_AREA_NEEDS_NAME);
return false;
}
final PlotArea existingArea = PlotSquared.get().getPlotArea(player.getLocation().getWorld(), args[1]);
final PlotArea existingArea = PlotSquared.get().getPlotAreaManager().getPlotArea(player.getLocation().getWorld(), args[1]);
if (existingArea != null && existingArea.getId().equalsIgnoreCase(args[1])) {
MainUtil.sendMessage(player, Captions.SINGLE_AREA_NAME_TAKEN);
return false;
@ -274,8 +276,8 @@ public class Area extends SubCommand {
final int offsetX = bx - (area.ROAD_WIDTH == 0 ? 0 : lower);
final int offsetZ = bz - (area.ROAD_WIDTH == 0 ? 0 : lower);
final CuboidRegion region = RegionUtil.createRegion(bx, tx, bz, tz);
Set<PlotArea> areas =
PlotSquared.get().getPlotAreas(area.getWorldName(), region);
final Set<PlotArea> areas = PlotSquared.get().getPlotAreaManager()
.getPlotAreasSet(area.getWorldName(), region);
if (!areas.isEmpty()) {
Captions.CLUSTER_INTERSECTION
.send(player, areas.iterator().next().toString());
@ -340,12 +342,12 @@ public class Area extends SubCommand {
builder.worldName(split[0]);
final HybridPlotWorld pa = new HybridPlotWorld(builder.worldName(), id,
PlotSquared.platform().getDefaultGenerator(), null, null);
PlotArea other = PlotSquared.get().getPlotArea(pa.getWorldName(), id);
PlotArea other = PlotSquared.get().getPlotAreaManager().getPlotArea(pa.getWorldName(), id);
if (other != null && Objects.equals(pa.getId(), other.getId())) {
Captions.SETUP_WORLD_TAKEN.send(player, pa.toString());
return false;
}
Set<PlotArea> areas = PlotSquared.get().getPlotAreas(pa.getWorldName());
Set<PlotArea> areas = PlotSquared.get().getPlotAreaManager().getPlotAreasSet(pa.getWorldName());
if (!areas.isEmpty()) {
PlotArea area = areas.iterator().next();
pa.setType(area.getType());
@ -490,7 +492,7 @@ public class Area extends SubCommand {
area = player.getApplicablePlotArea();
break;
case 2:
area = PlotSquared.get().getPlotAreaByString(args[1]);
area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[1]);
break;
default:
Captions.COMMAND_SYNTAX.send(player, getCommandString() + " info [area]");
@ -552,7 +554,7 @@ public class Area extends SubCommand {
Captions.COMMAND_SYNTAX.send(player, getCommandString() + " list [#]");
return false;
}
ArrayList<PlotArea> areas = new ArrayList<>(PlotSquared.get().getPlotAreas());
final List<PlotArea> areas = new ArrayList<>(Arrays.asList(PlotSquared.get().getPlotAreaManager().getAllPlotAreas()));
paginate(player, areas, 8, page,
new RunnableVal3<Integer, PlotArea, PlotMessage>() {
@Override public void run(Integer i, PlotArea area, PlotMessage message) {
@ -635,7 +637,7 @@ public class Area extends SubCommand {
Captions.COMMAND_SYNTAX.send(player, "/plot visit [area]");
return false;
}
PlotArea area = PlotSquared.get().getPlotAreaByString(args[1]);
PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[1]);
if (area == null) {
Captions.NOT_VALID_PLOT_WORLD.send(player, args[1]);
return false;

View File

@ -59,7 +59,7 @@ public class Condense extends SubCommand {
MainUtil.sendMessage(player, getUsage());
return false;
}
PlotArea area = PlotSquared.get().getPlotAreaByString(args[0]);
PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[0]);
if (area == null || !WorldUtil.IMP.isWorld(area.getWorldName())) {
MainUtil.sendMessage(player, "INVALID AREA");
return false;

View File

@ -80,7 +80,7 @@ public class DatabaseCommand extends SubCommand {
return false;
}
List<Plot> plots;
PlotArea area = PlotSquared.get().getPlotAreaByString(args[0]);
PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[0]);
if (area != null) {
plots = PlotSquared.get().sortPlotsByTemp(area.getPlots());
args = Arrays.copyOfRange(args, 1, args.length);
@ -116,7 +116,7 @@ public class DatabaseCommand extends SubCommand {
plots = new ArrayList<>();
for (Entry<String, HashMap<PlotId, Plot>> entry : map.entrySet()) {
String areaName = entry.getKey();
PlotArea pa = PlotSquared.get().getPlotAreaByString(areaName);
PlotArea pa = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(areaName);
if (pa != null) {
for (Entry<PlotId, Plot> entry2 : entry.getValue().entrySet()) {
Plot plot = entry2.getValue();

View File

@ -118,7 +118,7 @@ public class Debug extends SubCommand {
information.append(header);
information.append(getSection(section, "PlotArea"));
information.append(
getLine(line, "Plot Worlds", StringMan.join(PlotSquared.get().getPlotAreas(), ", ")));
getLine(line, "Plot Worlds", StringMan.join(PlotSquared.get().getPlotAreaManager().getAllPlotAreas(), ", ")));
information.append(getLine(line, "Owned Plots", PlotSquared.get().getPlots().size()));
information.append(getSection(section, "Messages"));
information.append(getLine(line, "Total Messages", Captions.values().length));

View File

@ -259,7 +259,7 @@ public class DebugExec extends SubCommand {
"&cInvalid syntax: /plot debugexec start-rgar <world>");
return false;
}
PlotArea area = PlotSquared.get().getPlotAreaByString(args[1]);
PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[1]);
if (area == null) {
MainUtil.sendMessage(player, Captions.NOT_VALID_PLOT_WORLD, args[1]);
return false;

View File

@ -52,7 +52,7 @@ public class Download extends SubCommand {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
String world = player.getLocation().getWorld();
if (!PlotSquared.get().hasPlotArea(world)) {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) {
return !sendMessage(player, Captions.NOT_IN_PLOT_WORLD);
}
final Plot plot = player.getCurrentPlot();

View File

@ -297,7 +297,7 @@ public class ListCmd extends SubCommand {
plotConsumer.accept(PlotQuery.newQuery().plotsBySearch(term));
break;
default:
if (PlotSquared.get().hasPlotArea(args[0])) {
if (PlotSquared.get().getPlotAreaManager().hasPlotArea(args[0])) {
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_WORLD)) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION,
Captions.PERMISSION_LIST_WORLD);

View File

@ -54,7 +54,7 @@ public class Load extends SubCommand {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
String world = player.getLocation().getWorld();
if (!PlotSquared.get().hasPlotArea(world)) {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) {
return !sendMessage(player, Captions.NOT_IN_PLOT_WORLD);
}
final Plot plot = player.getCurrentPlot();

View File

@ -70,7 +70,7 @@ public class Move extends SubCommand {
Captions.COMMAND_SYNTAX.send(player, getUsage());
return CompletableFuture.completedFuture(false);
}
PlotArea area = PlotSquared.get().getPlotAreaByString(args[0]);
PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[0]);
Plot plot2;
if (area == null) {
plot2 = MainUtil.getPlotFromString(player, args[0], true);

View File

@ -78,7 +78,7 @@ public class Purge extends SubCommand {
break;
case "area":
case "a":
area = PlotSquared.get().getPlotAreaByString(split[1]);
area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(split[1]);
if (area == null) {
Captions.NOT_VALID_PLOT_WORLD.send(player, split[1]);
return false;

View File

@ -59,7 +59,7 @@ public class RegenAllRoads extends SubCommand {
"/plot regenallroads <world> [height]");
return false;
}
PlotArea area = PlotSquared.get().getPlotAreaByString(args[0]);
PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[0]);
if (area == null) {
Captions.NOT_VALID_PLOT_WORLD.send(player, args[0]);
return false;

View File

@ -51,7 +51,7 @@ public class Save extends SubCommand {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
String world = player.getLocation().getWorld();
if (!PlotSquared.get().hasPlotArea(world)) {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) {
return !sendMessage(player, Captions.NOT_IN_PLOT_WORLD);
}
final Plot plot = player.getCurrentPlot();

View File

@ -150,7 +150,7 @@ public class SchematicCmd extends SubCommand {
MainUtil.sendMessage(player, Captions.SCHEMATIC_EXPORTALL_WORLD_ARGS);
return false;
}
PlotArea area = PlotSquared.get().getPlotAreaByString(args[1]);
PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[1]);
if (area == null) {
Captions.NOT_VALID_PLOT_WORLD.send(player, args[1]);
return false;

View File

@ -159,7 +159,7 @@ public class Template extends SubCommand {
"/plot template import <world> <template>");
return false;
}
if (PlotSquared.get().hasPlotArea(world)) {
if (PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) {
MainUtil.sendMessage(player, Captions.SETUP_WORLD_TAKEN, world);
return false;
}
@ -203,7 +203,7 @@ public class Template extends SubCommand {
"/plot template export <world>");
return false;
}
final PlotArea area = PlotSquared.get().getPlotAreaByString(world);
final PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(world);
if (area == null) {
MainUtil.sendMessage(player, Captions.NOT_VALID_PLOT_WORLD);
return false;

View File

@ -165,7 +165,7 @@ public class Trim extends SubCommand {
return false;
}
final String world = args[0];
if (!WorldUtil.IMP.isWorld(world) || !PlotSquared.get().hasPlotArea(world)) {
if (!WorldUtil.IMP.isWorld(world) || !PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) {
MainUtil.sendMessage(player, Captions.NOT_VALID_WORLD);
return false;
}

View File

@ -165,7 +165,7 @@ public class Visit extends Command {
// /p v <name> [page]
case 2:
if (page != Integer.MIN_VALUE || !MathMan.isInteger(args[1])) {
sortByArea = PlotSquared.get().getPlotAreaByString(args[1]);
sortByArea = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[1]);
if (sortByArea == null) {
Captions.NOT_VALID_NUMBER.send(player, "(1, ∞)");
Captions.COMMAND_SYNTAX.send(player, getUsage());
@ -305,7 +305,7 @@ public class Visit extends Command {
}
private void completeAreas(final List<Command> commands, final String arg) {
for (final PlotArea area : PlotSquared.get().getPlotAreas()) {
for (final PlotArea area : PlotSquared.get().getPlotAreaManager().getAllPlotAreas()) {
final String areaName = area.getWorldName() + ";" + area.getId();
if (!areaName.toLowerCase().startsWith(arg.toLowerCase())) {
continue;

View File

@ -68,7 +68,7 @@ public class AugmentedUtils {
// entire chunk
CuboidRegion region = RegionUtil.createRegion(blockX, blockX + 15, blockZ, blockZ + 15);
// Query for plot areas in the chunk
Set<PlotArea> areas = PlotSquared.get().getPlotAreas(world, region);
final Set<PlotArea> areas = PlotSquared.get().getPlotAreaManager().getPlotAreasSet(world, region);
if (areas.isEmpty()) {
return false;
}

View File

@ -115,7 +115,7 @@ public abstract class HybridUtils {
final int width = tx - bx + 1;
final int length = tz - bz + 1;
PlotArea area = PlotSquared.get().getPlotArea(world, null);
PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotArea(world, null);
if (!(area instanceof HybridPlotWorld)) {
return;

View File

@ -83,19 +83,19 @@ public class WESubscriber {
if (Permissions.hasPermission(plotPlayer, "plots.worldedit.bypass")) {
MainUtil.sendMessage(plotPlayer, Captions.WORLDEDIT_BYPASS);
}
if (PlotSquared.get().hasPlotArea(world)) {
if (PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) {
event.setExtent(new NullExtent());
}
return;
}
}
if (Settings.Enabled_Components.CHUNK_PROCESSOR) {
if (PlotSquared.get().hasPlotArea(world)) {
if (PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) {
event.setExtent(
new ProcessedWEExtent(world, mask, event.getMaxBlocks(), event.getExtent(),
event.getExtent()));
}
} else if (PlotSquared.get().hasPlotArea(world)) {
} else if (PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) {
event.setExtent(new WEExtent(mask, event.getExtent()));
}
}

View File

@ -34,6 +34,7 @@ import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.Nullable;
import org.khelekore.prtree.MBR;
import org.khelekore.prtree.SimpleMBR;
@ -103,8 +104,8 @@ public class Location implements Cloneable, Comparable<Location> {
}
}
public PlotArea getPlotArea() {
return PlotSquared.get().getPlotAreaAbs(this);
@Nullable public PlotArea getPlotArea() {
return PlotSquared.get().getPlotAreaManager().getPlotArea(this);
}
public Plot getOwnedPlot() {

View File

@ -46,7 +46,13 @@ public class ConsolePlayer extends PlotPlayer<Actor> {
private static ConsolePlayer instance;
private ConsolePlayer() {
PlotArea area = PlotSquared.get().getFirstPlotArea();
final PlotArea[] areas = PlotSquared.get().getPlotAreaManager().getAllPlotAreas();
final PlotArea area;
if (areas.length > 0) {
area = areas[0];
} else {
area = null;
}
Location location;
if (area != null) {
CuboidRegion region = area.getRegion();

View File

@ -54,6 +54,7 @@ import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.item.ItemType;
import lombok.NonNull;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.nio.ByteBuffer;
import java.util.Collection;
@ -307,7 +308,7 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
public int getPlotCount(String world) {
UUID uuid = getUUID();
int count = 0;
for (PlotArea area : PlotSquared.get().getPlotAreas(world)) {
for (PlotArea area : PlotSquared.get().getPlotAreaManager().getPlotAreasSet(world)) {
if (!Settings.Done.COUNTS_TOWARDS_LIMIT) {
count +=
area.getPlotsAbs(uuid).stream().filter(plot -> !DoneFlag.isDone(plot)).count();
@ -321,7 +322,7 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
public int getClusterCount(String world) {
UUID uuid = getUUID();
int count = 0;
for (PlotArea area : PlotSquared.get().getPlotAreas(world)) {
for (PlotArea area : PlotSquared.get().getPlotAreaManager().getPlotAreasSet(world)) {
for (PlotCluster cluster : area.getClusters()) {
if (cluster.isOwner(getUUID())) {
count++;
@ -345,14 +346,14 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
/**
* Return the PlotArea this player is currently in, or null.
*
* @return
* @return Plot area the player is currently in, or {@code null}
*/
public PlotArea getPlotAreaAbs() {
return PlotSquared.get().getPlotAreaAbs(getLocation());
@Nullable public PlotArea getPlotAreaAbs() {
return PlotSquared.get().getPlotAreaManager().getPlotArea(getLocation());
}
public PlotArea getApplicablePlotArea() {
return PlotSquared.get().getApplicablePlotArea(getLocation());
return PlotSquared.get().getPlotAreaManager().getApplicablePlotArea(getLocation());
}
@Override public RequiredType getSuperCaller() {

View File

@ -278,13 +278,13 @@ public class Plot {
return defaultArea.getPlotAbs(id);
}
} else if (split.length == 3) {
PlotArea pa = PlotSquared.get().getPlotArea(split[0], null);
PlotArea pa = PlotSquared.get().getPlotAreaManager().getPlotArea(split[0], null);
if (pa != null) {
PlotId id = PlotId.fromString(split[1] + ';' + split[2]);
return pa.getPlotAbs(id);
}
} else if (split.length == 4) {
PlotArea pa = PlotSquared.get().getPlotArea(split[0], split[1]);
PlotArea pa = PlotSquared.get().getPlotAreaManager().getPlotArea(split[0], split[1]);
if (pa != null) {
PlotId id = PlotId.fromString(split[1] + ';' + split[2]);
return pa.getPlotAbs(id);

View File

@ -46,7 +46,7 @@ public class DefaultPlotAreaManager implements PlotAreaManager {
final PlotArea[] noPlotAreas = new PlotArea[0];
private final Map<String, PlotWorld> plotWorlds = new HashMap<>();
@Override public PlotArea[] getAllPlotAreas() {
@Override @NotNull public PlotArea[] getAllPlotAreas() {
final Set<PlotArea> area = new HashSet<>();
for (final PlotWorld world : plotWorlds.values()) {
area.addAll(world.getAreas());
@ -54,7 +54,7 @@ public class DefaultPlotAreaManager implements PlotAreaManager {
return area.toArray(new PlotArea[0]);
}
@Override @Nullable public PlotArea getApplicablePlotArea(final Location location) {
@Override @Nullable public PlotArea getApplicablePlotArea(@Nullable final Location location) {
if (location == null) {
return null;
}
@ -65,7 +65,7 @@ public class DefaultPlotAreaManager implements PlotAreaManager {
return world.getArea(location);
}
@Override public void addPlotArea(final PlotArea plotArea) {
@Override public void addPlotArea(@NotNull final PlotArea plotArea) {
PlotWorld world = this.plotWorlds.get(plotArea.getWorldName());
if (world != null) {
if (world instanceof StandardPlotWorld && world.getAreas().isEmpty()) {
@ -84,7 +84,7 @@ public class DefaultPlotAreaManager implements PlotAreaManager {
this.plotWorlds.put(plotArea.getWorldName(), world);
}
@Override public void removePlotArea(final PlotArea area) {
@Override public void removePlotArea(@NotNull final PlotArea area) {
final PlotWorld world = this.plotWorlds.get(area.getWorldName());
if (world == null) {
return;
@ -99,7 +99,7 @@ public class DefaultPlotAreaManager implements PlotAreaManager {
}
}
@Override public PlotArea getPlotArea(final String world, final String id) {
@Override public PlotArea getPlotArea(@NotNull final String world, @Nullable final String id) {
final PlotWorld plotWorld = this.plotWorlds.get(world);
if (plotWorld == null) {
return null;
@ -119,11 +119,11 @@ public class DefaultPlotAreaManager implements PlotAreaManager {
return null;
}
@Override public PlotArea getPlotArea(@NotNull final Location location) {
@Override @Nullable public PlotArea getPlotArea(@NotNull final Location location) {
return this.getApplicablePlotArea(location);
}
@Override public PlotArea[] getPlotAreas(final String world, final CuboidRegion region) {
@Override @NotNull public PlotArea[] getPlotAreas(@NotNull final String world, @Nullable final CuboidRegion region) {
final PlotWorld plotWorld = this.plotWorlds.get(world);
if (plotWorld == null) {
return noPlotAreas;
@ -134,7 +134,7 @@ public class DefaultPlotAreaManager implements PlotAreaManager {
return plotWorld.getAreasInRegion(region).toArray(new PlotArea[0]);
}
@Override public void addWorld(final String worldName) {
@Override public void addWorld(@NotNull final String worldName) {
PlotWorld world = this.plotWorlds.get(worldName);
if (world != null) {
return;
@ -145,11 +145,11 @@ public class DefaultPlotAreaManager implements PlotAreaManager {
this.plotWorlds.put(worldName, world);
}
@Override public void removeWorld(final String worldName) {
@Override public void removeWorld(@NotNull final String worldName) {
this.plotWorlds.remove(worldName);
}
@Override public String[] getAllWorlds() {
@Override @NotNull public String[] getAllWorlds() {
return this.plotWorlds.keySet().toArray(new String[0]);
}
}

View File

@ -27,10 +27,15 @@ package com.plotsquared.core.plot.world;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.util.StringMan;
import com.sk89q.worldedit.regions.CuboidRegion;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public interface PlotAreaManager {
/**
@ -45,7 +50,7 @@ public interface PlotAreaManager {
* @param location The location
* @return An applicable area, or null
*/
@Nullable PlotArea getApplicablePlotArea(Location location);
@Nullable PlotArea getApplicablePlotArea(@Nullable Location location);
/**
* Get the plot area, if there is any, for the given
@ -53,24 +58,146 @@ public interface PlotAreaManager {
* does not belong to a plot area.
*
* @param location The location
* @return The area, if found
* @return The area if found, else {@code null}
*/
PlotArea getPlotArea(@NotNull Location location);
@Nullable PlotArea getPlotArea(@NotNull Location location);
PlotArea getPlotArea(String world, String id);
/**
* Get the plot area in a world with an (optional ID).
* If the world has more than one plot area, and ID must be
* supplied. If the world only has one plot area, the ID will
* be ignored
*
* @param world World name
* @param id Area ID
* @return Plot area matching the criteria
*/
@Nullable PlotArea getPlotArea(@NotNull String world, @Nullable String id);
PlotArea[] getPlotAreas(String world, CuboidRegion region);
/**
* Get all plot areas in a world, with an optional region constraint
*
* @param world World name
* @param region Optional region
* @return All plots in the region
*/
@NotNull PlotArea[] getPlotAreas(@NotNull String world, @Nullable CuboidRegion region);
PlotArea[] getAllPlotAreas();
/**
* Get all plot areas recognized by PlotSquared
*
* @return All plot areas
*/
@NotNull PlotArea[] getAllPlotAreas();
String[] getAllWorlds();
/**
* Get all worlds recognized by PlotSquared
*
* @return All world names
*/
@NotNull String[] getAllWorlds();
void addPlotArea(PlotArea area);
/**
* Add a plot area
*
* @param area Area
*/
void addPlotArea(@NotNull PlotArea area);
void removePlotArea(PlotArea area);
/**
* Remove a plot area
*
* @param area Area
*/
void removePlotArea(@NotNull PlotArea area);
void addWorld(String worldName);
/**
* Add a world
*
* @param worldName Name of the world to add
*/
void addWorld(@NotNull String worldName);
void removeWorld(String worldName);
/**
* Remove a world
*
* @param worldName Name of the world to remove
*/
void removeWorld(@NotNull String worldName);
/**
* Method that delegates to {@link #getPlotAreas(String, CuboidRegion)} but returns an
* immutable set, instead of an array
*
* @param world World name
* @param region Optional region
* @return All areas in the world (and region)
*/
@NotNull default Set<PlotArea> getPlotAreasSet(@NotNull final String world,
@Nullable final CuboidRegion region) {
final PlotArea[] areas = this.getPlotAreas(world, region);
final Set<PlotArea> set = new HashSet<>();
Collections.addAll(set, areas);
return Collections.unmodifiableSet(set);
}
/**
* Method identical to {@link #getPlotAreasSet(String, CuboidRegion)} but that
* does not take in a region, and returns a modifiable set
*
* @param world World name
* @return Modifiable set containing all plot areas in the specified world
*/
@NotNull default Set<PlotArea> getPlotAreasSet(@NotNull final String world) {
final Set<PlotArea> set = new HashSet<>();
Collections.addAll(set, this.getPlotAreas(world, null));
return set;
}
/**
* Get a plot area from a search string in the format "world;id" or "world,id"
* where the ID portion is optional
*
* @param search Search string
* @return An area that matches the search string, or {@code null}
*/
@Nullable default PlotArea getPlotAreaByString(@NotNull final String search) {
String[] split = search.split("[;,]");
PlotArea[] areas = this.getPlotAreas(split[0], null);
if (areas == null) {
for (PlotArea area : this.getAllPlotAreas()) {
if (area.getWorldName().equalsIgnoreCase(split[0])) {
if (area.getId() == null || split.length == 2 && area.getId()
.equalsIgnoreCase(split[1])) {
return area;
}
}
}
return null;
}
if (areas.length == 1) {
return areas[0];
} else if (split.length == 1) {
return null;
} else {
for (PlotArea area : areas) {
if (StringMan.isEqual(split[1], area.getId())) {
return area;
}
}
return null;
}
}
/**
* Check if a plot world.
*
* @param world the world
* @return if a plot world is registered
* @see #getPlotAreaByString(String) to get the PlotArea object
*/
default boolean hasPlotArea(@NotNull final String world) {
return this.getPlotAreas(world, null).length != 0;
}
}

View File

@ -32,8 +32,10 @@ import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.util.SetupUtils;
import com.sk89q.worldedit.regions.CuboidRegion;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class SinglePlotAreaManager extends DefaultPlotAreaManager {
private final SinglePlotArea[] array;
private SinglePlotArea area;
private PlotArea[] all;
@ -50,13 +52,13 @@ public class SinglePlotAreaManager extends DefaultPlotAreaManager {
return area;
}
public void setArea(SinglePlotArea area) {
public void setArea(@NotNull final SinglePlotArea area) {
this.area = area;
array[0] = area;
all = ArrayUtil.concatAll(super.getAllPlotAreas(), array);
}
public boolean isWorld(String id) {
public boolean isWorld(@NotNull final String id) {
char[] chars = id.toCharArray();
if (chars.length == 1 && chars[0] == '*') {
return true;
@ -88,20 +90,22 @@ public class SinglePlotAreaManager extends DefaultPlotAreaManager {
if ((c <= '/') || (c >= ':')) {
return false;
}
continue;
}
}
return mode == 3;
}
@Override public PlotArea getApplicablePlotArea(Location location) {
@Override @Nullable public PlotArea getApplicablePlotArea(@Nullable final Location location) {
if (location == null) {
return null;
}
String world = location.getWorld();
return isWorld(world) || world.equals("*") || super.getAllPlotAreas().length == 0 ?
area :
super.getApplicablePlotArea(location);
}
@Override public PlotArea getPlotArea(String world, String id) {
@Override @Nullable public PlotArea getPlotArea(@NotNull final String world, @NotNull final String id) {
PlotArea found = super.getPlotArea(world, id);
if (found != null) {
return found;
@ -109,7 +113,7 @@ public class SinglePlotAreaManager extends DefaultPlotAreaManager {
return isWorld(world) || world.equals("*") ? area : super.getPlotArea(world, id);
}
@Override public PlotArea getPlotArea(@NotNull Location location) {
@Override @Nullable public PlotArea getPlotArea(@NotNull final Location location) {
PlotArea found = super.getPlotArea(location);
if (found != null) {
return found;
@ -117,7 +121,7 @@ public class SinglePlotAreaManager extends DefaultPlotAreaManager {
return isWorld(location.getWorld()) || location.getWorld().equals("*") ? area : null;
}
@Override public PlotArea[] getPlotAreas(String world, CuboidRegion region) {
@Override @NotNull public PlotArea[] getPlotAreas(@NotNull final String world, @NotNull final CuboidRegion region) {
PlotArea[] found = super.getPlotAreas(world, region);
if (found != null && found.length != 0) {
return found;
@ -127,15 +131,15 @@ public class SinglePlotAreaManager extends DefaultPlotAreaManager {
all.length == 0 ? noPlotAreas : super.getPlotAreas(world, region);
}
@Override public PlotArea[] getAllPlotAreas() {
@Override @NotNull public PlotArea[] getAllPlotAreas() {
return all;
}
@Override public String[] getAllWorlds() {
@Override @NotNull public String[] getAllWorlds() {
return super.getAllWorlds();
}
@Override public void addPlotArea(PlotArea area) {
@Override public void addPlotArea(@NotNull final PlotArea area) {
if (area == this.area) {
return;
}
@ -143,18 +147,18 @@ public class SinglePlotAreaManager extends DefaultPlotAreaManager {
all = ArrayUtil.concatAll(super.getAllPlotAreas(), array);
}
@Override public void removePlotArea(PlotArea area) {
@Override public void removePlotArea(@NotNull final PlotArea area) {
if (area == this.area) {
throw new UnsupportedOperationException("Cannot remove base area!");
}
super.removePlotArea(area);
}
@Override public void addWorld(String worldName) {
@Override public void addWorld(@NotNull final String worldName) {
super.addWorld(worldName);
}
@Override public void removeWorld(String worldName) {
@Override public void removeWorld(@NotNull final String worldName) {
super.removeWorld(worldName);
}
}

View File

@ -110,7 +110,7 @@ public class ScopedLocalBlockQueue extends DelegateLocalBlockQueue {
public void mapByType2D(RunnableVal3<Plot, Integer, Integer> task) {
int bx = minX;
int bz = minZ;
PlotArea area = PlotSquared.get().getPlotArea(getWorld(), null);
PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotArea(getWorld(), null);
Location location = new Location(getWorld(), bx, 0, bz);
if (area != null) {
PlotManager manager = area.getPlotManager();

View File

@ -134,7 +134,7 @@ public enum CommonSetupSteps implements SetupStep {
MainUtil.sendMessage(plotPlayer, Captions.SETUP_AREA_NON_ALPHANUMERICAL);
return this;
}
for (PlotArea area : PlotSquared.get().getPlotAreas()) {
for (PlotArea area : PlotSquared.get().getPlotAreaManager().getAllPlotAreas()) {
if (area.getId() != null && area.getId().equalsIgnoreCase(argument)) {
MainUtil.sendMessage(plotPlayer, Captions.SETUP_AREA_INVALID_ID);
return this;
@ -215,7 +215,7 @@ public enum CommonSetupSteps implements SetupStep {
return this;
}
if (WorldUtil.IMP.isWorld(argument)) {
if (PlotSquared.get().hasPlotArea(argument)) {
if (PlotSquared.get().getPlotAreaManager().hasPlotArea(argument)) {
MainUtil.sendMessage(plotPlayer, Captions.SETUP_WORLD_NAME_TAKEN);
return this;
}

View File

@ -528,7 +528,7 @@ public class MainUtil {
}
PlotArea area;
if (player != null) {
area = PlotSquared.get().getPlotAreaByString(arg);
area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(arg);
if (area == null) {
area = player.getApplicablePlotArea();
}
@ -538,10 +538,10 @@ public class MainUtil {
String[] split = arg.split(";|,");
PlotId id;
if (split.length == 4) {
area = PlotSquared.get().getPlotAreaByString(split[0] + ';' + split[1]);
area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(split[0] + ';' + split[1]);
id = PlotId.fromString(split[2] + ';' + split[3]);
} else if (split.length == 3) {
area = PlotSquared.get().getPlotAreaByString(split[0]);
area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(split[0]);
id = PlotId.fromString(split[1] + ';' + split[2]);
} else if (split.length == 2) {
id = PlotId.fromString(arg);

View File

@ -88,7 +88,7 @@ public class WEManager {
UUID uuid = player.getUUID();
Location location = player.getLocation();
String world = location.getWorld();
if (!PlotSquared.get().hasPlotArea(world)) {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) {
regions.add(RegionUtil
.createRegion(Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE,
Integer.MAX_VALUE));

View File

@ -95,7 +95,7 @@ public final class PlotQuery {
*/
@NotNull public PlotQuery inWorld(@NotNull final String world) {
Preconditions.checkNotNull(world, "World may not be null");
this.plotProvider = new AreaLimitedPlotProvider(PlotSquared.get().getPlotAreas(world));
this.plotProvider = new AreaLimitedPlotProvider(PlotSquared.get().getPlotAreaManager().getPlotAreasSet(world));
return this;
}