PlotSquared/Core/src/main/java/com/plotsquared/core/plot/PlotCluster.java

225 lines
7.1 KiB
Java
Raw Normal View History

/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* Copyright (C) IntellectualSites team and contributors
*
* 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 <https://www.gnu.org/licenses/>.
*/
2020-04-15 21:26:54 +02:00
package com.plotsquared.core.plot;
2015-01-26 05:16:10 +01:00
import com.plotsquared.core.PlotSquared;
2020-04-30 12:01:52 +02:00
import com.plotsquared.core.database.DBFunc;
2020-04-15 21:26:54 +02:00
import com.plotsquared.core.location.BlockLoc;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.util.RegionUtil;
import com.sk89q.worldedit.regions.CuboidRegion;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
2016-03-14 07:18:04 +01:00
import java.util.HashSet;
import java.util.UUID;
import java.util.function.Consumer;
2016-03-14 07:18:04 +01:00
2015-09-13 06:04:31 +02:00
public class PlotCluster {
2016-02-10 19:59:51 +01:00
public PlotArea area;
2019-02-04 16:18:50 +01:00
public PlotSettings settings;
2015-02-20 07:34:19 +01:00
public UUID owner;
2016-03-14 07:18:04 +01:00
public HashSet<UUID> helpers = new HashSet<>();
public HashSet<UUID> invited = new HashSet<>();
public int temp;
2019-02-04 16:18:50 +01:00
private PlotId pos1;
private PlotId pos2;
private CuboidRegion region;
2019-02-04 16:18:50 +01:00
public PlotCluster(PlotArea area, PlotId pos1, PlotId pos2, UUID owner) {
2016-02-10 19:59:51 +01:00
this.area = area;
2015-02-20 07:34:19 +01:00
this.pos1 = pos1;
this.pos2 = pos2;
this.owner = owner;
2016-03-29 06:56:44 +02:00
this.settings = new PlotSettings();
this.temp = -1;
2016-02-10 19:59:51 +01:00
setRegion();
}
2016-03-29 06:56:44 +02:00
2019-02-04 16:18:50 +01:00
public PlotCluster(PlotArea area, PlotId pos1, PlotId pos2, UUID owner, int temp) {
2016-02-10 19:59:51 +01:00
this.area = area;
this.pos1 = pos1;
this.pos2 = pos2;
this.owner = owner;
2016-03-29 06:56:44 +02:00
this.settings = new PlotSettings();
this.temp = temp;
2016-02-10 19:59:51 +01:00
setRegion();
}
2016-03-14 07:18:04 +01:00
public PlotId getP1() {
2016-03-29 06:56:44 +02:00
return this.pos1;
2016-03-14 07:18:04 +01:00
}
2016-03-29 06:56:44 +02:00
public void setP1(PlotId id) {
this.pos1 = id;
2016-03-14 07:18:04 +01:00
setRegion();
}
public PlotId getP2() {
2016-03-29 06:56:44 +02:00
return this.pos2;
2016-03-14 07:18:04 +01:00
}
2016-03-29 06:56:44 +02:00
public void setP2(PlotId id) {
this.pos2 = id;
2016-03-14 07:18:04 +01:00
setRegion();
}
2018-08-10 17:01:10 +02:00
2016-02-10 19:59:51 +01:00
private void setRegion() {
Implement extended world heights from Y-64 to Y319 #3473 (#3473) * Begin to implement extended world heights: - Implemented in Bukkit module (and where required in Core module) * Implement extended world heights into core module * Add min gen height to setup, * Default gen/build heights based on minecraft version * Few fixes * Fix up queues * Address comments * Make road schematic stuff slightly more efficient by sharing queues * Minor fixes, don't overlay error many times for the same y * Fix incorrect schematic paste height, undo changes to HybridUtils * Overhall regenallroads method to make it work, make sure BukkitChunkCoordinator can/will finish * Process chunks in order when regenerating all roads * Address comments * Address comments * Ground level//bedrock is at min gen height - Add comment on == rather than <= being used - It's because it's only checking for the bedrock layer being broken if that's disabled * Fix offset for min build height in SchematicHandler * Better javadoc Co-authored-by: Hannes Greule <SirYwell@users.noreply.github.com> * Address inclusivity issues for max world height * Javadocs/comments/deprecation * Use world min/max heights if present in QueueCoordinator * Address some deprecations for regions and biome setting * Add a count for chunks we're currently trying to load to not skip chunks at the end of a queue's edit * Use minGenHeight + 1 rather than build height in AugmentedUtils * Create utility method for layer index in GenChunk * Correct height in HybridUtils, also use minGenHeight + 1 * Don't magically split to 128 height in regeneration * Add utility methods for world height in QueueCoordinator * Clean up ClassicPlotManager road creation/removal * Start generation at min gen height if bedrock is disabled * min gen height is set in PlotArea * Add note on schem y normalisation * Improve plot getVolume method readability * Don't overly extend height when regenerating road region * y index utility method in ChunknQueueCoordinator * Layer index utility method in LocalChunk * Use version min/max heights if world not present in QueueCoordinator * Fix min -> max * Don't allow players to modify outside build height when using plot set / schematics. - Also fixes schematic height issues * Remove debug * Address comments * Switch loadingChunks to AtomicInteger to be safe (in case of multi-threaded) * Fix "security" issue that was already present * Ensure sign isn't physicsed Co-authored-by: Hannes Greule <SirYwell@users.noreply.github.com>
2022-03-05 19:03:39 +01:00
this.region = RegionUtil.createRegion(this.pos1.getX(), this.pos2.getX(), 0, 0,
this.pos1.getY(), this.pos2.getY()
);
2016-02-10 19:59:51 +01:00
}
2018-08-10 17:01:10 +02:00
Implement extended world heights from Y-64 to Y319 #3473 (#3473) * Begin to implement extended world heights: - Implemented in Bukkit module (and where required in Core module) * Implement extended world heights into core module * Add min gen height to setup, * Default gen/build heights based on minecraft version * Few fixes * Fix up queues * Address comments * Make road schematic stuff slightly more efficient by sharing queues * Minor fixes, don't overlay error many times for the same y * Fix incorrect schematic paste height, undo changes to HybridUtils * Overhall regenallroads method to make it work, make sure BukkitChunkCoordinator can/will finish * Process chunks in order when regenerating all roads * Address comments * Address comments * Ground level//bedrock is at min gen height - Add comment on == rather than <= being used - It's because it's only checking for the bedrock layer being broken if that's disabled * Fix offset for min build height in SchematicHandler * Better javadoc Co-authored-by: Hannes Greule <SirYwell@users.noreply.github.com> * Address inclusivity issues for max world height * Javadocs/comments/deprecation * Use world min/max heights if present in QueueCoordinator * Address some deprecations for regions and biome setting * Add a count for chunks we're currently trying to load to not skip chunks at the end of a queue's edit * Use minGenHeight + 1 rather than build height in AugmentedUtils * Create utility method for layer index in GenChunk * Correct height in HybridUtils, also use minGenHeight + 1 * Don't magically split to 128 height in regeneration * Add utility methods for world height in QueueCoordinator * Clean up ClassicPlotManager road creation/removal * Start generation at min gen height if bedrock is disabled * min gen height is set in PlotArea * Add note on schem y normalisation * Improve plot getVolume method readability * Don't overly extend height when regenerating road region * y index utility method in ChunknQueueCoordinator * Layer index utility method in LocalChunk * Use version min/max heights if world not present in QueueCoordinator * Fix min -> max * Don't allow players to modify outside build height when using plot set / schematics. - Also fixes schematic height issues * Remove debug * Address comments * Switch loadingChunks to AtomicInteger to be safe (in case of multi-threaded) * Fix "security" issue that was already present * Ensure sign isn't physicsed Co-authored-by: Hannes Greule <SirYwell@users.noreply.github.com>
2022-03-05 19:03:39 +01:00
/**
* Returns a region of PlotIDs
*
* @deprecated - returns region of IDs, not of actual blocks.
*/
@Deprecated
public CuboidRegion getRegion() {
2016-03-29 06:56:44 +02:00
return this.region;
}
2016-09-25 10:42:05 +02:00
public boolean isOwner(UUID uuid) {
return uuid.equals(owner);
}
2016-03-29 06:56:44 +02:00
public boolean isAdded(UUID uuid) {
2018-08-10 17:01:10 +02:00
return this.owner.equals(uuid) || this.invited.contains(uuid) || this.invited
.contains(DBFunc.EVERYONE) || this.helpers.contains(uuid) || this.helpers
.contains(DBFunc.EVERYONE);
}
2016-03-29 06:56:44 +02:00
public boolean hasHelperRights(UUID uuid) {
2018-08-10 17:01:10 +02:00
return this.owner.equals(uuid) || this.helpers.contains(uuid) || this.helpers
.contains(DBFunc.EVERYONE);
2015-02-20 07:34:19 +01:00
}
2018-08-10 17:01:10 +02:00
2015-09-13 06:04:31 +02:00
public String getName() {
2016-03-29 06:56:44 +02:00
return this.settings.getAlias();
2015-02-20 07:34:19 +01:00
}
2018-08-10 17:01:10 +02:00
2015-08-28 08:28:55 +02:00
/**
2016-03-29 06:56:44 +02:00
* Get the area (in plots).
*
* @return area of plots
2015-08-28 08:28:55 +02:00
*/
2015-09-13 06:04:31 +02:00
public int getArea() {
2020-07-18 11:05:16 +02:00
return (1 + this.pos2.getX() - this.pos1.getX()) * (1 + this.pos2.getY() - this.pos1.getY());
2015-08-28 08:28:55 +02:00
}
2016-03-14 07:18:04 +01:00
2016-06-02 17:38:47 +02:00
public void setArea(PlotArea plotArea) {
2016-03-14 07:18:04 +01:00
if (this.area != null) {
this.area.removeCluster(this);
}
2016-06-02 17:38:47 +02:00
this.area = plotArea;
plotArea.addCluster(this);
2016-03-14 07:18:04 +01:00
}
2018-08-10 17:01:10 +02:00
@Override
public int hashCode() {
2016-03-29 06:56:44 +02:00
return this.pos1.hashCode();
2015-02-20 07:34:19 +01:00
}
2018-08-10 17:01:10 +02:00
@Override
public boolean equals(Object obj) {
2015-09-13 06:04:31 +02:00
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
2016-03-29 06:56:44 +02:00
PlotCluster other = (PlotCluster) obj;
2018-08-10 17:01:10 +02:00
return this.pos1.equals(other.pos1) && this.pos2.equals(other.pos2) && this.area
.equals(other.area);
2015-02-20 07:34:19 +01:00
}
2018-08-10 17:01:10 +02:00
@Override
public String toString() {
2020-07-18 11:05:16 +02:00
return this.area + ";" + this.pos1.toString() + ";" + this.pos2.toString();
2016-02-10 19:59:51 +01:00
}
2018-08-10 17:01:10 +02:00
public void getHome(final @NonNull Consumer<Location> result) {
final BlockLoc home = this.settings.getPosition();
Consumer<Location> locationConsumer = toReturn ->
PlotSquared.platform().worldUtil().getHighestBlock(this.area.getWorldName(), toReturn.getX(), toReturn.getZ(),
highest -> {
Implement extended world heights from Y-64 to Y319 #3473 (#3473) * Begin to implement extended world heights: - Implemented in Bukkit module (and where required in Core module) * Implement extended world heights into core module * Add min gen height to setup, * Default gen/build heights based on minecraft version * Few fixes * Fix up queues * Address comments * Make road schematic stuff slightly more efficient by sharing queues * Minor fixes, don't overlay error many times for the same y * Fix incorrect schematic paste height, undo changes to HybridUtils * Overhall regenallroads method to make it work, make sure BukkitChunkCoordinator can/will finish * Process chunks in order when regenerating all roads * Address comments * Address comments * Ground level//bedrock is at min gen height - Add comment on == rather than <= being used - It's because it's only checking for the bedrock layer being broken if that's disabled * Fix offset for min build height in SchematicHandler * Better javadoc Co-authored-by: Hannes Greule <SirYwell@users.noreply.github.com> * Address inclusivity issues for max world height * Javadocs/comments/deprecation * Use world min/max heights if present in QueueCoordinator * Address some deprecations for regions and biome setting * Add a count for chunks we're currently trying to load to not skip chunks at the end of a queue's edit * Use minGenHeight + 1 rather than build height in AugmentedUtils * Create utility method for layer index in GenChunk * Correct height in HybridUtils, also use minGenHeight + 1 * Don't magically split to 128 height in regeneration * Add utility methods for world height in QueueCoordinator * Clean up ClassicPlotManager road creation/removal * Start generation at min gen height if bedrock is disabled * min gen height is set in PlotArea * Add note on schem y normalisation * Improve plot getVolume method readability * Don't overly extend height when regenerating road region * y index utility method in ChunknQueueCoordinator * Layer index utility method in LocalChunk * Use version min/max heights if world not present in QueueCoordinator * Fix min -> max * Don't allow players to modify outside build height when using plot set / schematics. - Also fixes schematic height issues * Remove debug * Address comments * Switch loadingChunks to AtomicInteger to be safe (in case of multi-threaded) * Fix "security" issue that was already present * Ensure sign isn't physicsed Co-authored-by: Hannes Greule <SirYwell@users.noreply.github.com>
2022-03-05 19:03:39 +01:00
if (highest <= area.getMinBuildHeight()) {
highest = 63;
}
if (highest > toReturn.getY()) {
result.accept(toReturn.withY(1 + highest));
} else {
result.accept(toReturn);
}
}
);
Implement extended world heights from Y-64 to Y319 #3473 (#3473) * Begin to implement extended world heights: - Implemented in Bukkit module (and where required in Core module) * Implement extended world heights into core module * Add min gen height to setup, * Default gen/build heights based on minecraft version * Few fixes * Fix up queues * Address comments * Make road schematic stuff slightly more efficient by sharing queues * Minor fixes, don't overlay error many times for the same y * Fix incorrect schematic paste height, undo changes to HybridUtils * Overhall regenallroads method to make it work, make sure BukkitChunkCoordinator can/will finish * Process chunks in order when regenerating all roads * Address comments * Address comments * Ground level//bedrock is at min gen height - Add comment on == rather than <= being used - It's because it's only checking for the bedrock layer being broken if that's disabled * Fix offset for min build height in SchematicHandler * Better javadoc Co-authored-by: Hannes Greule <SirYwell@users.noreply.github.com> * Address inclusivity issues for max world height * Javadocs/comments/deprecation * Use world min/max heights if present in QueueCoordinator * Address some deprecations for regions and biome setting * Add a count for chunks we're currently trying to load to not skip chunks at the end of a queue's edit * Use minGenHeight + 1 rather than build height in AugmentedUtils * Create utility method for layer index in GenChunk * Correct height in HybridUtils, also use minGenHeight + 1 * Don't magically split to 128 height in regeneration * Add utility methods for world height in QueueCoordinator * Clean up ClassicPlotManager road creation/removal * Start generation at min gen height if bedrock is disabled * min gen height is set in PlotArea * Add note on schem y normalisation * Improve plot getVolume method readability * Don't overly extend height when regenerating road region * y index utility method in ChunknQueueCoordinator * Layer index utility method in LocalChunk * Use version min/max heights if world not present in QueueCoordinator * Fix min -> max * Don't allow players to modify outside build height when using plot set / schematics. - Also fixes schematic height issues * Remove debug * Address comments * Switch loadingChunks to AtomicInteger to be safe (in case of multi-threaded) * Fix "security" issue that was already present * Ensure sign isn't physicsed Co-authored-by: Hannes Greule <SirYwell@users.noreply.github.com>
2022-03-05 19:03:39 +01:00
if (home.getY() == Integer.MIN_VALUE) {
2016-02-10 19:59:51 +01:00
// default pos
2016-03-29 06:56:44 +02:00
Plot center = getCenterPlot();
center.getHome(location -> {
Location toReturn = location;
Implement extended world heights from Y-64 to Y319 #3473 (#3473) * Begin to implement extended world heights: - Implemented in Bukkit module (and where required in Core module) * Implement extended world heights into core module * Add min gen height to setup, * Default gen/build heights based on minecraft version * Few fixes * Fix up queues * Address comments * Make road schematic stuff slightly more efficient by sharing queues * Minor fixes, don't overlay error many times for the same y * Fix incorrect schematic paste height, undo changes to HybridUtils * Overhall regenallroads method to make it work, make sure BukkitChunkCoordinator can/will finish * Process chunks in order when regenerating all roads * Address comments * Address comments * Ground level//bedrock is at min gen height - Add comment on == rather than <= being used - It's because it's only checking for the bedrock layer being broken if that's disabled * Fix offset for min build height in SchematicHandler * Better javadoc Co-authored-by: Hannes Greule <SirYwell@users.noreply.github.com> * Address inclusivity issues for max world height * Javadocs/comments/deprecation * Use world min/max heights if present in QueueCoordinator * Address some deprecations for regions and biome setting * Add a count for chunks we're currently trying to load to not skip chunks at the end of a queue's edit * Use minGenHeight + 1 rather than build height in AugmentedUtils * Create utility method for layer index in GenChunk * Correct height in HybridUtils, also use minGenHeight + 1 * Don't magically split to 128 height in regeneration * Add utility methods for world height in QueueCoordinator * Clean up ClassicPlotManager road creation/removal * Start generation at min gen height if bedrock is disabled * min gen height is set in PlotArea * Add note on schem y normalisation * Improve plot getVolume method readability * Don't overly extend height when regenerating road region * y index utility method in ChunknQueueCoordinator * Layer index utility method in LocalChunk * Use version min/max heights if world not present in QueueCoordinator * Fix min -> max * Don't allow players to modify outside build height when using plot set / schematics. - Also fixes schematic height issues * Remove debug * Address comments * Switch loadingChunks to AtomicInteger to be safe (in case of multi-threaded) * Fix "security" issue that was already present * Ensure sign isn't physicsed Co-authored-by: Hannes Greule <SirYwell@users.noreply.github.com>
2022-03-05 19:03:39 +01:00
if (toReturn.getY() <= area.getMinBuildHeight()) {
PlotManager manager = this.area.getPlotManager();
Location locationSign = manager.getSignLoc(center);
toReturn = toReturn.withY(locationSign.getY());
}
locationConsumer.accept(toReturn);
});
2016-02-10 19:59:51 +01:00
} else {
locationConsumer.accept(getClusterBottom().add(home.getX(), home.getY(), home.getZ()));
2016-02-10 19:59:51 +01:00
}
}
2018-08-10 17:01:10 +02:00
public @NonNull PlotId getCenterPlotId() {
2020-07-18 11:05:16 +02:00
final PlotId bot = getP1();
final PlotId top = getP2();
return PlotId.of((bot.getX() + top.getX()) / 2, (bot.getY() + top.getY()) / 2);
2016-02-10 19:59:51 +01:00
}
2016-03-14 07:18:04 +01:00
public @Nullable Plot getCenterPlot() {
2016-03-29 06:56:44 +02:00
return this.area.getPlotAbs(getCenterPlotId());
2016-02-10 19:59:51 +01:00
}
public Location getClusterBottom() {
2016-03-29 06:56:44 +02:00
PlotManager manager = this.area.getPlotManager();
return manager.getPlotBottomLocAbs(getP1());
2016-02-10 19:59:51 +01:00
}
2018-08-10 17:01:10 +02:00
2016-02-10 19:59:51 +01:00
public Location getClusterTop() {
2016-03-29 06:56:44 +02:00
PlotManager manager = this.area.getPlotManager();
return manager.getPlotTopLocAbs(getP2());
2016-02-10 19:59:51 +01:00
}
2018-08-10 17:01:10 +02:00
2016-02-10 19:59:51 +01:00
public boolean intersects(PlotId pos1, PlotId pos2) {
2020-07-18 11:05:16 +02:00
return pos1.getX() <= this.pos2.getX() && pos2.getX() >= this.pos1.getX() &&
pos1.getY() <= this.pos2.getY() && pos2.getY() >= this.pos1.getY();
2016-02-10 19:59:51 +01:00
}
2016-03-29 06:56:44 +02:00
public boolean contains(PlotId id) {
2020-07-18 11:05:16 +02:00
return this.pos1.getX() <= id.getX() && this.pos1.getY() <= id.getY() &&
this.pos2.getX() >= id.getX() && this.pos2.getY() >= id.getY();
2015-02-20 07:34:19 +01:00
}
2015-01-26 05:16:10 +01:00
}