2020-04-16 04:52:39 +02:00
|
|
|
/*
|
2022-06-15 20:17:17 +02:00
|
|
|
* PlotSquared, a land and world management plugin for Minecraft.
|
|
|
|
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
|
|
|
* Copyright (C) IntellectualSites team and contributors
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* 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.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* 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.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* 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-16 04:52:39 +02:00
|
|
|
*/
|
2020-04-15 21:26:54 +02:00
|
|
|
package com.plotsquared.core.plot;
|
2014-10-08 12:42:13 +02:00
|
|
|
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.command.Template;
|
2020-04-16 06:14:33 +02:00
|
|
|
import com.plotsquared.core.configuration.Settings;
|
2020-04-30 12:01:52 +02:00
|
|
|
import com.plotsquared.core.location.Location;
|
2020-09-11 13:59:40 +02:00
|
|
|
import com.plotsquared.core.player.PlotPlayer;
|
2020-07-18 14:55:54 +02:00
|
|
|
import com.plotsquared.core.queue.QueueCoordinator;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.util.FileBytes;
|
2019-11-10 18:47:37 +01:00
|
|
|
import com.sk89q.worldedit.function.pattern.Pattern;
|
2021-01-09 22:28:41 +01:00
|
|
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
|
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
2016-06-10 19:00:34 +02:00
|
|
|
|
2015-02-27 08:50:16 +01:00
|
|
|
import java.io.IOException;
|
2016-01-10 21:00:56 +01:00
|
|
|
import java.util.Collections;
|
2015-02-25 09:25:22 +01:00
|
|
|
import java.util.HashSet;
|
2018-12-28 07:39:39 +01:00
|
|
|
import java.util.List;
|
2015-01-13 17:38:15 +01:00
|
|
|
|
2015-09-13 06:04:31 +02:00
|
|
|
public abstract class PlotManager {
|
2016-03-23 18:13:09 +01:00
|
|
|
|
2019-05-31 13:16:05 +02:00
|
|
|
private final PlotArea plotArea;
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
public PlotManager(@NonNull PlotArea plotArea) {
|
2019-05-31 13:16:05 +02:00
|
|
|
this.plotArea = plotArea;
|
|
|
|
}
|
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
/*
|
|
|
|
* Plot locations (methods with Abs in them will not need to consider mega
|
2016-03-23 18:13:09 +01:00
|
|
|
* plots).
|
2014-11-05 04:42:08 +01:00
|
|
|
*/
|
2019-05-31 15:05:37 +02:00
|
|
|
public abstract PlotId getPlotIdAbs(int x, int y, int z);
|
2016-03-23 18:13:09 +01:00
|
|
|
|
2019-05-31 15:05:37 +02:00
|
|
|
public abstract PlotId getPlotId(int x, int y, int z);
|
2016-03-23 18:13:09 +01:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
// If you have a circular plot, just return the corner if it were a square
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract Location getPlotBottomLocAbs(@NonNull PlotId plotId);
|
2016-03-23 18:13:09 +01:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
// the same applies here
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract Location getPlotTopLocAbs(@NonNull PlotId plotId);
|
2016-03-23 18:13:09 +01:00
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract boolean clearPlot(
|
|
|
|
@NonNull Plot plot,
|
|
|
|
@Nullable Runnable whenDone,
|
|
|
|
@Nullable PlotPlayer<?> actor,
|
|
|
|
@Nullable QueueCoordinator queue
|
|
|
|
);
|
2016-03-23 18:13:09 +01:00
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract boolean claimPlot(@NonNull Plot plot, @Nullable QueueCoordinator queue);
|
2016-03-23 18:13:09 +01:00
|
|
|
|
2020-07-28 11:17:15 +02:00
|
|
|
/**
|
|
|
|
* Completes block changes associated with plot unclaim.
|
|
|
|
*
|
2020-08-16 14:22:49 +02:00
|
|
|
* @param plot plot to unclaim
|
|
|
|
* @param whenDone task to run when plot is unclaimed
|
|
|
|
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
|
|
|
* otherwise writes to the queue but does not enqueue.
|
|
|
|
* @return success or not
|
2020-07-28 11:17:15 +02:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract boolean unClaimPlot(@NonNull Plot plot, @Nullable Runnable whenDone, @Nullable QueueCoordinator queue);
|
2016-03-23 18:13:09 +01:00
|
|
|
|
2019-09-08 20:02:45 +02:00
|
|
|
/**
|
|
|
|
* Retrieves the location of where a sign should be for a plot.
|
|
|
|
*
|
|
|
|
* @param plot The plot
|
|
|
|
* @return The location where a sign should be
|
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract Location getSignLoc(@NonNull Plot plot);
|
2016-03-23 18:13:09 +01:00
|
|
|
|
2020-08-16 14:22:49 +02:00
|
|
|
/**
|
|
|
|
* Get an array of the plot's component values as string
|
|
|
|
*
|
|
|
|
* @param plotId plotId to get components of
|
|
|
|
* @return array of plot's component values
|
2014-11-05 04:42:08 +01:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract String[] getPlotComponents(@NonNull PlotId plotId);
|
2016-03-23 18:13:09 +01:00
|
|
|
|
2020-07-28 11:17:15 +02:00
|
|
|
/**
|
|
|
|
* Set the specified components to the specified Pattern on the specified plot.
|
|
|
|
*
|
2020-08-16 14:22:49 +02:00
|
|
|
* @param plotId id of plot to set component to
|
2020-07-28 11:17:15 +02:00
|
|
|
* @param component FLOOR, WALL, AIR, MAIN, MIDDLE, OUTLINE, BORDER, ALL (floor, air and main).
|
2020-08-16 14:22:49 +02:00
|
|
|
* @param blocks Pattern to set component to
|
2020-09-11 13:59:40 +02:00
|
|
|
* @param actor The player executing the task
|
2020-07-28 11:17:15 +02:00
|
|
|
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
|
|
|
* otherwise writes to the queue but does not enqueue.
|
2020-08-16 14:22:49 +02:00
|
|
|
* @return success or not
|
2020-07-28 11:17:15 +02:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract boolean setComponent(
|
|
|
|
@NonNull PlotId plotId,
|
|
|
|
@NonNull String component,
|
|
|
|
@NonNull Pattern blocks,
|
|
|
|
@Nullable PlotPlayer<?> actor,
|
|
|
|
@Nullable QueueCoordinator queue
|
|
|
|
);
|
2016-03-23 18:13:09 +01:00
|
|
|
|
2020-07-28 11:17:15 +02:00
|
|
|
/**
|
|
|
|
* Create the road east of the plot (not schematic-based)
|
|
|
|
*
|
2020-08-16 14:22:49 +02:00
|
|
|
* @param plot plot to create the road for
|
2020-07-28 11:17:15 +02:00
|
|
|
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
|
|
|
* otherwise writes to the queue but does not enqueue.
|
2020-08-16 14:22:49 +02:00
|
|
|
* @return success or not
|
2014-11-05 04:42:08 +01:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract boolean createRoadEast(@NonNull Plot plot, @Nullable QueueCoordinator queue);
|
2016-03-23 18:13:09 +01:00
|
|
|
|
2020-07-28 11:17:15 +02:00
|
|
|
/**
|
|
|
|
* Create the road south of the plot (not schematic-based)
|
|
|
|
*
|
2020-08-16 14:22:49 +02:00
|
|
|
* @param plot plot to create the road for
|
2020-07-28 11:17:15 +02:00
|
|
|
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
|
|
|
* otherwise writes to the queue but does not enqueue.
|
2020-08-16 14:22:49 +02:00
|
|
|
* @return success or not
|
2020-07-28 11:17:15 +02:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract boolean createRoadSouth(@NonNull Plot plot, @Nullable QueueCoordinator queue);
|
2016-03-23 18:13:09 +01:00
|
|
|
|
2020-07-28 11:17:15 +02:00
|
|
|
/**
|
|
|
|
* Create the south-east corner of the road (intersection, not schematic-based)
|
|
|
|
*
|
2020-08-16 14:22:49 +02:00
|
|
|
* @param plot plot to create the road for
|
2020-07-28 11:17:15 +02:00
|
|
|
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
|
|
|
* otherwise writes to the queue but does not enqueue.
|
2020-08-16 14:22:49 +02:00
|
|
|
* @return success or not
|
2020-07-28 11:17:15 +02:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract boolean createRoadSouthEast(@NonNull Plot plot, @Nullable QueueCoordinator queue);
|
2016-03-23 18:13:09 +01:00
|
|
|
|
2020-07-28 11:17:15 +02:00
|
|
|
/**
|
|
|
|
* Replace the road to the east of the plot with standard plot blocks (for when merging plots)
|
|
|
|
*
|
2020-08-16 14:22:49 +02:00
|
|
|
* @param plot plot to remove east road from
|
2020-07-28 11:17:15 +02:00
|
|
|
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
|
|
|
* otherwise writes to the queue but does not enqueue.
|
2020-08-16 14:22:49 +02:00
|
|
|
* @return success or not
|
2020-07-28 11:17:15 +02:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract boolean removeRoadEast(@NonNull Plot plot, @Nullable QueueCoordinator queue);
|
2016-03-23 18:13:09 +01:00
|
|
|
|
2020-07-28 11:17:15 +02:00
|
|
|
/**
|
|
|
|
* Replace the road to the south of the plot with standard plot blocks (for when merging plots)
|
|
|
|
*
|
2020-08-16 14:22:49 +02:00
|
|
|
* @param plot plot to remove south road from
|
2020-07-28 11:17:15 +02:00
|
|
|
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
|
|
|
* otherwise writes to the queue but does not enqueue.
|
2020-08-16 14:22:49 +02:00
|
|
|
* @return success or not
|
2020-07-28 11:17:15 +02:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract boolean removeRoadSouth(@NonNull Plot plot, @Nullable QueueCoordinator queue);
|
2016-03-23 18:13:09 +01:00
|
|
|
|
2020-07-28 11:17:15 +02:00
|
|
|
/**
|
|
|
|
* Replace the road to the south east of the plot (intersection) with standard plot blocks (for when merging plots)
|
|
|
|
*
|
2020-08-16 14:22:49 +02:00
|
|
|
* @param plot plot to remove south east road intersection from
|
2020-07-28 11:17:15 +02:00
|
|
|
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
|
|
|
* otherwise writes to the queue but does not enqueue.
|
2020-08-16 14:22:49 +02:00
|
|
|
* @return success or not
|
2020-07-28 11:17:15 +02:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract boolean removeRoadSouthEast(@NonNull Plot plot, @Nullable QueueCoordinator queue);
|
2016-03-23 18:13:09 +01:00
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract boolean startPlotMerge(@NonNull List<PlotId> plotIds, @Nullable QueueCoordinator queue);
|
2016-03-23 18:13:09 +01:00
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract boolean startPlotUnlink(@NonNull List<PlotId> plotIds, @Nullable QueueCoordinator queue);
|
2016-03-23 18:13:09 +01:00
|
|
|
|
2020-07-28 11:17:15 +02:00
|
|
|
/**
|
|
|
|
* Finishing off plot merging by adding in the walls surrounding the plot (OPTIONAL)(UNFINISHED).
|
|
|
|
*
|
2020-08-16 14:22:49 +02:00
|
|
|
* @param plotIds list of PlotIds to finish the merge for
|
|
|
|
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
|
|
|
* otherwise writes to the queue but does not enqueue.
|
2022-01-24 21:41:54 +01:00
|
|
|
* @return {@code false} if part if the merge failed, otherwise {@code true} if successful.
|
2020-07-28 11:17:15 +02:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract boolean finishPlotMerge(@NonNull List<PlotId> plotIds, @Nullable QueueCoordinator queue);
|
2016-03-23 18:13:09 +01:00
|
|
|
|
2020-07-28 11:17:15 +02:00
|
|
|
/**
|
|
|
|
* Finished off an unlink by resetting the top wall block for unlinked plots
|
|
|
|
*
|
2020-08-16 14:22:49 +02:00
|
|
|
* @param plotIds list of PlotIds to reset the top wall block of
|
|
|
|
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
|
|
|
* otherwise writes to the queue but does not enqueue.
|
|
|
|
* @return success or not
|
2020-07-28 11:17:15 +02:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public abstract boolean finishPlotUnlink(@NonNull List<PlotId> plotIds, @Nullable QueueCoordinator queue);
|
2016-03-23 18:13:09 +01:00
|
|
|
|
2019-05-31 15:05:37 +02:00
|
|
|
public void exportTemplate() throws IOException {
|
2020-07-24 17:24:53 +02:00
|
|
|
HashSet<FileBytes> files =
|
2021-01-09 22:28:41 +01:00
|
|
|
new HashSet<>(Collections.singletonList(new FileBytes(
|
|
|
|
Settings.Paths.TEMPLATES + "/tmp-data.yml",
|
|
|
|
Template.getBytes(plotArea)
|
|
|
|
)));
|
2020-04-02 14:34:38 +02:00
|
|
|
Template.zipAll(plotArea.getWorldName(), files);
|
2015-02-25 08:50:17 +01:00
|
|
|
}
|
2016-03-23 18:13:09 +01:00
|
|
|
|
2021-05-01 18:33:02 +02:00
|
|
|
/**
|
|
|
|
* @return the world height
|
|
|
|
* @deprecated In favor of custom world heights within 1.17 and therefore scheduled for removal without replacement
|
|
|
|
*/
|
2022-01-24 21:46:01 +01:00
|
|
|
@Deprecated(forRemoval = true, since = "6.0.0")
|
2016-09-17 08:02:05 +02:00
|
|
|
public int getWorldHeight() {
|
|
|
|
return 255;
|
|
|
|
}
|
|
|
|
|
2019-11-08 06:17:51 +01:00
|
|
|
/**
|
|
|
|
* Sets all the blocks along all the plot walls to their correct state (claimed or unclaimed).
|
|
|
|
*
|
2020-07-28 11:17:15 +02:00
|
|
|
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
|
|
|
* otherwise writes to the queue but does not enqueue.
|
2022-01-24 21:41:54 +01:00
|
|
|
* @return {@code true} if the wall blocks were successfully set
|
2019-11-08 06:17:51 +01:00
|
|
|
*/
|
2020-07-18 14:55:54 +02:00
|
|
|
public boolean regenerateAllPlotWalls(@Nullable QueueCoordinator queue) {
|
2019-11-08 06:17:51 +01:00
|
|
|
boolean success = true;
|
|
|
|
for (Plot plot : plotArea.getPlots()) {
|
|
|
|
if (plot.hasOwner()) {
|
2020-07-18 14:55:54 +02:00
|
|
|
success &= claimPlot(plot, queue);
|
2019-11-08 06:17:51 +01:00
|
|
|
} else {
|
2020-07-18 14:55:54 +02:00
|
|
|
success &= unClaimPlot(plot, null, queue);
|
2019-11-08 06:17:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return success;
|
|
|
|
}
|
2019-06-01 14:43:29 +02:00
|
|
|
|
2014-10-05 04:58:35 +02:00
|
|
|
}
|