use of com.plotsquared.core.util.task.RunnableVal in project PlotSquared by IntellectualSites.
the class Trim method onCommand.
@Override
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
if (args.length == 0) {
sendUsage(player);
return false;
}
final String world = args[0];
if (!this.worldUtil.isWorld(world) || !this.plotAreaManager.hasPlotArea(world)) {
player.sendMessage(TranslatableCaption.of("errors.not_valid_world"));
return false;
}
if (Trim.TASK) {
player.sendMessage(TranslatableCaption.of("trim.trim_in_progress"));
return false;
}
Trim.TASK = true;
final boolean regen = args.length == 2 && Boolean.parseBoolean(args[1]);
getTrimRegions(world, new RunnableVal2<>() {
@Override
public void run(Set<BlockVector2> viable, final Set<BlockVector2> nonViable) {
Runnable regenTask;
if (regen) {
LOGGER.info("Starting regen task");
LOGGER.info(" - This is a VERY slow command");
LOGGER.info(" - It will say 'Trim done!' when complete");
regenTask = new Runnable() {
@Override
public void run() {
if (nonViable.isEmpty()) {
Trim.TASK = false;
player.sendMessage(TranslatableCaption.of("trim.trim_done"));
LOGGER.info("Trim done!");
return;
}
Iterator<BlockVector2> iterator = nonViable.iterator();
BlockVector2 mcr = iterator.next();
iterator.remove();
int cbx = mcr.getX() << 5;
int cbz = mcr.getZ() << 5;
// get all 1024 chunks
HashSet<BlockVector2> chunks = new HashSet<>();
for (int x = cbx; x < cbx + 32; x++) {
for (int z = cbz; z < cbz + 32; z++) {
BlockVector2 loc = BlockVector2.at(x, z);
chunks.add(loc);
}
}
int bx = cbx << 4;
int bz = cbz << 4;
CuboidRegion region = RegionUtil.createRegion(bx, bx + 511, 0, 0, bz, bz + 511);
for (Plot plot : PlotQuery.newQuery().inWorld(world)) {
Location bot = plot.getBottomAbs();
Location top = plot.getExtendedTopAbs();
CuboidRegion plotReg = RegionUtil.createRegion(bot.getX(), top.getX(), 0, 0, bot.getZ(), top.getZ());
if (!RegionUtil.intersects(region, plotReg)) {
continue;
}
for (int x = plotReg.getMinimumPoint().getX() >> 4; x <= plotReg.getMaximumPoint().getX() >> 4; x++) {
for (int z = plotReg.getMinimumPoint().getZ() >> 4; z <= plotReg.getMaximumPoint().getZ() >> 4; z++) {
BlockVector2 loc = BlockVector2.at(x, z);
chunks.remove(loc);
}
}
}
final QueueCoordinator queue = blockQueue.getNewQueue(worldUtil.getWeWorld(world));
TaskManager.getPlatformImplementation().objectTask(chunks, new RunnableVal<>() {
@Override
public void run(BlockVector2 value) {
queue.regenChunk(value.getX(), value.getZ());
}
}).thenAccept(ignore -> TaskManager.getPlatformImplementation().taskLater(this, TaskTime.ticks(1L)));
}
};
} else {
regenTask = () -> {
Trim.TASK = false;
player.sendMessage(TranslatableCaption.of("trim.trim_done"));
LOGGER.info("Trim done!");
};
}
regionManager.deleteRegionFiles(world, viable, regenTask);
}
});
return true;
}
use of com.plotsquared.core.util.task.RunnableVal in project PlotSquared by IntellectualSites.
the class BukkitRegionManager method regenerateRegion.
@Override
public boolean regenerateRegion(@NonNull final Location pos1, @NonNull final Location pos2, final boolean ignoreAugment, @Nullable final Runnable whenDone) {
final BukkitWorld world = (BukkitWorld) worldUtil.getWeWorld(pos1.getWorldName());
final int p1x = pos1.getX();
final int p1z = pos1.getZ();
final int p2x = pos2.getX();
final int p2z = pos2.getZ();
final int bcx = p1x >> 4;
final int bcz = p1z >> 4;
final int tcx = p2x >> 4;
final int tcz = p2z >> 4;
final QueueCoordinator queue = blockQueue.getNewQueue(world);
final QueueCoordinator regenQueue = blockQueue.getNewQueue(world);
queue.addReadChunks(new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3()).getChunks());
queue.setChunkConsumer(chunk -> {
int x = chunk.getX();
int z = chunk.getZ();
int xxb = x << 4;
int zzb = z << 4;
int xxt = xxb + 15;
int zzt = zzb + 15;
if (xxb >= p1x && xxt <= p2x && zzb >= p1z && zzt <= p2z) {
AugmentedUtils.bypass(ignoreAugment, () -> regenQueue.regenChunk(chunk.getX(), chunk.getZ()));
return;
}
boolean checkX1 = false;
int xxb2;
if (x == bcx) {
xxb2 = p1x - 1;
checkX1 = true;
} else {
xxb2 = xxb;
}
boolean checkX2 = false;
int xxt2;
if (x == tcx) {
xxt2 = p2x + 1;
checkX2 = true;
} else {
xxt2 = xxt;
}
boolean checkZ1 = false;
int zzb2;
if (z == bcz) {
zzb2 = p1z - 1;
checkZ1 = true;
} else {
zzb2 = zzb;
}
boolean checkZ2 = false;
int zzt2;
if (z == tcz) {
zzt2 = p2z + 1;
checkZ2 = true;
} else {
zzt2 = zzt;
}
final ContentMap map = new ContentMap();
if (checkX1) {
//
map.saveRegion(world, xxb, xxb2, zzb2, zzt2);
}
if (checkX2) {
//
map.saveRegion(world, xxt2, xxt, zzb2, zzt2);
}
if (checkZ1) {
//
map.saveRegion(world, xxb2, xxt2, zzb, zzb2);
}
if (checkZ2) {
//
map.saveRegion(world, xxb2, xxt2, zzt2, zzt);
}
if (checkX1 && checkZ1) {
//
map.saveRegion(world, xxb, xxb2, zzb, zzb2);
}
if (checkX2 && checkZ1) {
// ?
map.saveRegion(world, xxt2, xxt, zzb, zzb2);
}
if (checkX1 && checkZ2) {
// ?
map.saveRegion(world, xxb, xxb2, zzt2, zzt);
}
if (checkX2 && checkZ2) {
//
map.saveRegion(world, xxt2, xxt, zzt2, zzt);
}
CuboidRegion currentPlotClear = new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3());
map.saveEntitiesOut(Bukkit.getWorld(world.getName()).getChunkAt(x, z), currentPlotClear);
AugmentedUtils.bypass(ignoreAugment, () -> ChunkManager.setChunkInPlotArea(null, new RunnableVal<ScopedQueueCoordinator>() {
@Override
public void run(ScopedQueueCoordinator value) {
Location min = value.getMin();
int bx = min.getX();
int bz = min.getZ();
for (int x1 = 0; x1 < 16; x1++) {
for (int z1 = 0; z1 < 16; z1++) {
PlotLoc plotLoc = new PlotLoc(bx + x1, bz + z1);
BaseBlock[] ids = map.allBlocks.get(plotLoc);
if (ids != null) {
int minY = value.getMin().getY();
for (int yIndex = 0; yIndex < ids.length; yIndex++) {
int y = yIndex + minY;
BaseBlock id = ids[yIndex];
if (id != null) {
value.setBlock(x1, y, z1, id);
} else {
value.setBlock(x1, y, z1, BlockTypes.AIR.getDefaultState());
}
}
}
}
}
}
}, world.getName(), chunk));
// map.restoreBlocks(worldObj, 0, 0);
map.restoreEntities(Bukkit.getWorld(world.getName()));
});
regenQueue.setCompleteTask(whenDone);
queue.setCompleteTask(regenQueue::enqueue);
queue.enqueue();
return true;
}
use of com.plotsquared.core.util.task.RunnableVal in project PlotSquared by IntellectualSites.
the class Trim method getTrimRegions.
/**
* Runs the result task with the parameters (viable, nonViable).
*
* @param world The world
* @param result (viable = .mcr to trim, nonViable = .mcr keep)
* @return success or not
*/
public static boolean getTrimRegions(String world, final RunnableVal2<Set<BlockVector2>, Set<BlockVector2>> result) {
if (result == null) {
return false;
}
TranslatableCaption.of("trim.trim_starting");
final List<Plot> plots = PlotQuery.newQuery().inWorld(world).asList();
if (ExpireManager.IMP != null) {
plots.removeAll(ExpireManager.IMP.getPendingExpired());
}
result.value1 = new HashSet<>(PlotSquared.platform().worldUtil().getChunkChunks(world));
result.value2 = new HashSet<>();
StaticCaption.of(" - MCA #: " + result.value1.size());
StaticCaption.of(" - CHUNKS: " + (result.value1.size() * 1024) + " (max)");
StaticCaption.of(" - TIME ESTIMATE: 12 Parsecs");
TaskManager.getPlatformImplementation().objectTask(plots, new RunnableVal<>() {
@Override
public void run(Plot plot) {
Location pos1 = plot.getCorners()[0];
Location pos2 = plot.getCorners()[1];
int ccx1 = pos1.getX() >> 9;
int ccz1 = pos1.getZ() >> 9;
int ccx2 = pos2.getX() >> 9;
int ccz2 = pos2.getZ() >> 9;
for (int x = ccx1; x <= ccx2; x++) {
for (int z = ccz1; z <= ccz2; z++) {
BlockVector2 loc = BlockVector2.at(x, z);
if (result.value1.remove(loc)) {
result.value2.add(loc);
}
}
}
}
}).thenAccept(ignore -> TaskManager.getPlatformImplementation().taskLater(result, TaskTime.ticks(1L)));
return true;
}
use of com.plotsquared.core.util.task.RunnableVal in project PlotSquared by IntellectualSites.
the class Plot method claim.
/**
* Claim the plot
*
* @param player The player to set the owner to
* @param teleport If the player should be teleported
* @param schematic The schematic name to paste on the plot
* @param updateDB If the database should be updated
* @param auto If the plot is being claimed by a /plot auto
* @return success
* @since 6.1.0
*/
public boolean claim(@NonNull final PlotPlayer<?> player, boolean teleport, String schematic, boolean updateDB, boolean auto) {
this.eventDispatcher.callPlotClaimedNotify(this, auto);
if (updateDB) {
if (!this.getPlotModificationManager().create(player.getUUID(), true)) {
LOGGER.error("Player {} attempted to claim plot {}, but the database failed to update", player.getName(), this.getId().toCommaSeparatedString());
return false;
}
} else {
area.addPlot(this);
updateWorldBorder();
}
player.sendMessage(TranslatableCaption.of("working.claimed"), Template.of("plot", this.getId().toString()));
if (teleport) {
if (!auto && Settings.Teleport.ON_CLAIM) {
teleportPlayer(player, TeleportCause.COMMAND_CLAIM, result -> {
});
} else if (auto && Settings.Teleport.ON_AUTO) {
teleportPlayer(player, TeleportCause.COMMAND_AUTO, result -> {
});
}
}
PlotArea plotworld = getArea();
if (plotworld.isSchematicOnClaim()) {
Schematic sch;
try {
if (schematic == null || schematic.isEmpty()) {
sch = schematicHandler.getSchematic(plotworld.getSchematicFile());
} else {
sch = schematicHandler.getSchematic(schematic);
if (sch == null) {
sch = schematicHandler.getSchematic(plotworld.getSchematicFile());
}
}
} catch (SchematicHandler.UnsupportedFormatException e) {
e.printStackTrace();
return true;
}
schematicHandler.paste(sch, this, 0, getArea().getMinBuildHeight(), 0, Settings.Schematics.PASTE_ON_TOP, player, new RunnableVal<>() {
@Override
public void run(Boolean value) {
if (value) {
player.sendMessage(TranslatableCaption.of("schematics.schematic_paste_success"));
} else {
player.sendMessage(TranslatableCaption.of("schematics.schematic_paste_failed"));
}
}
});
}
plotworld.getPlotManager().claimPlot(this, null);
this.getPlotModificationManager().setSign(player.getName());
return true;
}
Aggregations