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.util;
|
2015-02-23 06:29:45 +01:00
|
|
|
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.PlotSquared;
|
|
|
|
import com.plotsquared.core.location.Location;
|
2020-07-17 16:41:06 +02:00
|
|
|
import com.plotsquared.core.queue.QueueCoordinator;
|
2022-06-16 16:41:03 +02:00
|
|
|
import com.plotsquared.core.queue.ZeroedDelegateScopedQueueCoordinator;
|
2020-04-30 12:01:52 +02:00
|
|
|
import com.plotsquared.core.util.task.RunnableVal;
|
2019-11-04 18:44:23 +01:00
|
|
|
import com.sk89q.worldedit.math.BlockVector2;
|
2022-03-05 19:03:39 +01:00
|
|
|
import com.sk89q.worldedit.world.World;
|
2018-08-10 17:01:10 +02:00
|
|
|
|
2019-05-17 21:32:05 +02:00
|
|
|
import java.util.Map;
|
2019-09-12 01:04:29 +02:00
|
|
|
import java.util.concurrent.CompletableFuture;
|
2019-03-26 09:27:20 +01:00
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
2016-03-23 02:41:37 +01:00
|
|
|
|
2015-09-13 06:04:31 +02:00
|
|
|
public abstract class ChunkManager {
|
2018-08-10 17:01:10 +02:00
|
|
|
|
2022-06-16 16:41:03 +02:00
|
|
|
private static final Map<BlockVector2, RunnableVal<ZeroedDelegateScopedQueueCoordinator>> forceChunks = new ConcurrentHashMap<>();
|
|
|
|
private static final Map<BlockVector2, RunnableVal<ZeroedDelegateScopedQueueCoordinator>> addChunks = new ConcurrentHashMap<>();
|
2016-02-14 02:01:18 +01:00
|
|
|
|
2022-06-09 14:49:58 +02:00
|
|
|
/**
|
2023-06-15 17:24:21 +02:00
|
|
|
* @since 7.0.0
|
2022-06-09 14:49:58 +02:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public static void setChunkInPlotArea(
|
2022-06-16 16:41:03 +02:00
|
|
|
RunnableVal<ZeroedDelegateScopedQueueCoordinator> force,
|
|
|
|
RunnableVal<ZeroedDelegateScopedQueueCoordinator> add,
|
2021-01-09 22:28:41 +01:00
|
|
|
String world,
|
|
|
|
BlockVector2 loc
|
|
|
|
) {
|
2022-03-05 19:03:39 +01:00
|
|
|
World weWorld = PlotSquared.platform().worldUtil().getWeWorld(world);
|
|
|
|
QueueCoordinator queue = PlotSquared.platform().globalBlockQueue().getNewQueue(weWorld);
|
2020-07-24 17:24:53 +02:00
|
|
|
if (PlotSquared.get().getPlotAreaManager().isAugmented(world) && PlotSquared.get().isNonStandardGeneration(world, loc)) {
|
2019-11-04 18:44:23 +01:00
|
|
|
int blockX = loc.getX() << 4;
|
|
|
|
int blockZ = loc.getZ() << 4;
|
2022-06-16 16:41:03 +02:00
|
|
|
ZeroedDelegateScopedQueueCoordinator scoped =
|
|
|
|
new ZeroedDelegateScopedQueueCoordinator(
|
2021-01-09 22:28:41 +01:00
|
|
|
queue,
|
2022-03-05 19:03:39 +01:00
|
|
|
Location.at(world, blockX, weWorld.getMinY(), blockZ),
|
|
|
|
Location.at(world, blockX + 15, weWorld.getMaxY(), blockZ + 15)
|
2021-01-09 22:28:41 +01:00
|
|
|
);
|
2016-02-10 19:59:51 +01:00
|
|
|
if (force != null) {
|
2016-06-13 06:47:50 +02:00
|
|
|
force.run(scoped);
|
|
|
|
} else {
|
2019-11-04 18:44:23 +01:00
|
|
|
scoped.regenChunk(loc.getX(), loc.getZ());
|
2016-06-13 06:47:50 +02:00
|
|
|
if (add != null) {
|
|
|
|
add.run(scoped);
|
|
|
|
}
|
2016-02-10 19:59:51 +01:00
|
|
|
}
|
2020-07-17 16:41:06 +02:00
|
|
|
queue.enqueue();
|
2016-02-10 19:59:51 +01:00
|
|
|
} else {
|
2020-02-28 22:15:04 +01:00
|
|
|
if (force != null) {
|
|
|
|
forceChunks.put(loc, force);
|
|
|
|
}
|
2019-03-26 09:27:20 +01:00
|
|
|
addChunks.put(loc, add);
|
2019-11-04 18:44:23 +01:00
|
|
|
queue.regenChunk(loc.getX(), loc.getZ());
|
2019-03-26 09:27:20 +01:00
|
|
|
forceChunks.remove(loc);
|
|
|
|
addChunks.remove(loc);
|
2016-02-10 19:59:51 +01:00
|
|
|
}
|
|
|
|
}
|
2018-08-10 17:01:10 +02:00
|
|
|
|
2022-06-09 14:49:58 +02:00
|
|
|
/**
|
2023-06-15 17:24:21 +02:00
|
|
|
* @since 7.0.0
|
2022-06-09 14:49:58 +02:00
|
|
|
*/
|
2022-06-16 16:41:03 +02:00
|
|
|
public static boolean preProcessChunk(BlockVector2 loc, ZeroedDelegateScopedQueueCoordinator queue) {
|
|
|
|
final RunnableVal<ZeroedDelegateScopedQueueCoordinator> forceChunk = forceChunks.get(loc);
|
2019-03-26 09:27:20 +01:00
|
|
|
if (forceChunk != null) {
|
|
|
|
forceChunk.run(queue);
|
|
|
|
forceChunks.remove(loc);
|
2016-03-17 15:22:51 +01:00
|
|
|
return true;
|
2016-02-10 19:59:51 +01:00
|
|
|
}
|
2016-03-17 15:22:51 +01:00
|
|
|
return false;
|
2016-02-10 19:59:51 +01:00
|
|
|
}
|
2018-08-10 17:01:10 +02:00
|
|
|
|
2022-06-09 14:49:58 +02:00
|
|
|
/**
|
2023-06-15 17:24:21 +02:00
|
|
|
* @since 7.0.0
|
2022-06-09 14:49:58 +02:00
|
|
|
*/
|
2022-06-16 16:41:03 +02:00
|
|
|
public static boolean postProcessChunk(BlockVector2 loc, ZeroedDelegateScopedQueueCoordinator queue) {
|
|
|
|
final RunnableVal<ZeroedDelegateScopedQueueCoordinator> addChunk = forceChunks.get(loc);
|
2019-03-26 09:27:20 +01:00
|
|
|
if (addChunk != null) {
|
|
|
|
addChunk.run(queue);
|
|
|
|
addChunks.remove(loc);
|
2016-03-17 15:22:51 +01:00
|
|
|
return true;
|
2016-02-10 19:59:51 +01:00
|
|
|
}
|
2016-03-17 15:22:51 +01:00
|
|
|
return false;
|
2016-02-10 19:59:51 +01:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Deprecated
|
2021-05-01 18:33:02 +02:00
|
|
|
public abstract CompletableFuture<?> loadChunk(String world, BlockVector2 loc, boolean force);
|
2016-03-23 02:41:37 +01:00
|
|
|
|
2015-02-23 06:29:45 +01:00
|
|
|
}
|