Various changes

the most notable change is that PlotSquared is being moved to the Bukkit module again to allow for future compatibility with version 5 of the plugin.
This commit is contained in:
MattBDev
2020-02-12 16:18:36 -05:00
parent 0047f20d5d
commit 6dd85e48ba
19 changed files with 178 additions and 86 deletions

View File

@ -5,6 +5,7 @@ import com.boydti.fawe.IFawe;
import com.boydti.fawe.beta.implementation.cache.preloader.AsyncPreloader;
import com.boydti.fawe.beta.implementation.cache.preloader.Preloader;
import com.boydti.fawe.beta.implementation.queue.QueueHandler;
import com.boydti.fawe.bukkit.regions.plotsquared.PlotSquaredFeature;
import com.boydti.fawe.bukkit.adapter.BukkitQueueHandler;
import com.boydti.fawe.bukkit.listener.BrushListener;
import com.boydti.fawe.bukkit.listener.BukkitImageListener;
@ -26,6 +27,7 @@ import com.boydti.fawe.config.Settings;
import com.boydti.fawe.regions.FaweMaskManager;
import com.boydti.fawe.util.Jars;
import com.boydti.fawe.util.TaskManager;
import com.boydti.fawe.util.WEManager;
import com.boydti.fawe.util.image.ImageViewer;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.BukkitPlayer;
@ -37,7 +39,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.UUID;
import java.util.function.Supplier;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
@ -228,11 +229,6 @@ public class FaweBukkit implements IFawe, Listener {
return plugin;
}
@Override
public String getWorldName(World world) {
return world.getName();
}
/**
* A mask manager handles region restrictions e.g., PlotSquared plots / WorldGuard regions
*/
@ -347,4 +343,10 @@ public class FaweBukkit implements IFawe, Listener {
}
return null;
}
@Override
public void setupPlotSquared() {
WEManager.IMP.managers.add(new com.boydti.fawe.bukkit.regions.plotsquared.PlotSquaredFeature());
log.debug("Plugin 'PlotSquared' found. Using it now.");
}
}

View File

@ -0,0 +1,50 @@
package com.boydti.fawe.bukkit.regions.plotsquared;
import com.github.intellectualsites.plotsquared.commands.Command;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.commands.CommandCategory;
import com.github.intellectualsites.plotsquared.plot.commands.MainCommand;
import com.github.intellectualsites.plotsquared.plot.commands.RequiredType;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal2;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3;
import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotArea;
import com.sk89q.worldedit.WorldEdit;
import java.util.concurrent.CompletableFuture;
@CommandDeclaration(
command = "cfi",
permission = "plots.createfromimage",
aliases = {"createfromheightmap", "createfromimage", "cfhm"},
category = CommandCategory.APPEARANCE,
requiredType = RequiredType.NONE,
description = "Generate a world from an image heightmap: [More info](https://goo.gl/friFbV)",
usage = "/plots cfi [url or dimensions]"
)
public class CFIRedirect extends Command {
private final WorldEdit we;
public CFIRedirect() {
super(MainCommand.getInstance(), true);
this.we = WorldEdit.getInstance();
}
@Override
public CompletableFuture<Boolean> execute(final PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
checkTrue(args.length >= 1, Captions.COMMAND_SYNTAX, getUsage());
final Plot plot = check(player.getCurrentPlot(), Captions.NOT_IN_PLOT);
checkTrue(plot.isOwner(player.getUUID()), Captions.NOW_OWNER);
checkTrue(plot.getRunning() == 0, Captions.WAIT_FOR_TIMER);
final PlotArea area = plot.getArea();
if (area instanceof SinglePlotArea) {
player.sendMessage("The command has been changed to: //cfi");
} else {
player.sendMessage("Must have the `worlds` component enabled in the PlotSquared config.yml");
return CompletableFuture.completedFuture(false);
}
return CompletableFuture.completedFuture(true);
}
}

View File

@ -0,0 +1,119 @@
package com.boydti.fawe.bukkit.regions.plotsquared;
import static org.bukkit.Bukkit.getWorld;
import com.boydti.fawe.util.EditSessionBuilder;
import com.boydti.fawe.util.TaskManager;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.util.ChunkManager;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.World;
import java.util.concurrent.CompletableFuture;
import org.bukkit.Bukkit;
public class FaweChunkManager extends ChunkManager {
private ChunkManager parent;
public FaweChunkManager(ChunkManager parent) {
this.parent = parent;
}
@Override
public int[] countEntities(Plot plot) {
return parent.countEntities(plot);
}
@Override
public CompletableFuture loadChunk(String world, BlockVector2 loc, boolean force) {
return parent.loadChunk(world, loc, force);
}
@Override
public void unloadChunk(String world, BlockVector2 loc, boolean save) {
parent.unloadChunk(world, loc, save);
}
@Override
public void clearAllEntities(Location pos1, Location pos2) {
parent.clearAllEntities(pos1, pos2);
}
@Override
public void swap(final Location pos1, final Location pos2, final Location pos3, final Location pos4, final Runnable whenDone) {
TaskManager.IMP.async(() -> {
synchronized (FaweChunkManager.class) {
//todo because of the following code this should proably be in the Bukkit module
World pos1World = BukkitAdapter.adapt(getWorld(pos1.getWorld()));
World pos3World = BukkitAdapter.adapt(getWorld(pos3.getWorld()));
WorldEdit.getInstance().getEditSessionFactory().getEditSession(
pos1World,-1);
EditSession sessionA = new EditSessionBuilder(pos1World).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
EditSession sessionB = new EditSessionBuilder(pos3World).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
CuboidRegion regionA = new CuboidRegion(BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()), BlockVector3.at(pos2.getX(), pos2.getY(), pos2.getZ()));
CuboidRegion regionB = new CuboidRegion(BlockVector3.at(pos3.getX(), pos3.getY(), pos3.getZ()), BlockVector3.at(pos4.getX(), pos4.getY(), pos4.getZ()));
ForwardExtentCopy copyA = new ForwardExtentCopy(sessionA, regionA, sessionB, regionB.getMinimumPoint());
ForwardExtentCopy copyB = new ForwardExtentCopy(sessionB, regionB, sessionA, regionA.getMinimumPoint());
try {
Operations.completeLegacy(copyA);
Operations.completeLegacy(copyB);
sessionA.flushQueue();
sessionB.flushQueue();
} catch (MaxChangedBlocksException e) {
e.printStackTrace();
}
TaskManager.IMP.task(whenDone);
}
});
}
@Override
public boolean copyRegion(final Location pos1, final Location pos2, final Location pos3, final Runnable whenDone) {
TaskManager.IMP.async(() -> {
synchronized (FaweChunkManager.class) {
World pos1World = BukkitAdapter.adapt(getWorld(pos1.getWorld()));
World pos3World = BukkitAdapter.adapt(getWorld(pos3.getWorld()));
EditSession from = new EditSessionBuilder(pos1World).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
EditSession to = new EditSessionBuilder(pos3World).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
CuboidRegion region = new CuboidRegion(BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()), BlockVector3.at(pos2.getX(), pos2.getY(), pos2.getZ()));
ForwardExtentCopy copy = new ForwardExtentCopy(from, region, to, BlockVector3.at(pos3.getX(), pos3.getY(), pos3.getZ()));
try {
Operations.completeLegacy(copy);
to.flushQueue();
} catch (MaxChangedBlocksException e) {
e.printStackTrace();
}
}
TaskManager.IMP.task(whenDone);
});
return true;
}
@Override
public boolean regenerateRegion(final Location pos1, final Location pos2, boolean ignore, final Runnable whenDone) {
TaskManager.IMP.async(() -> {
synchronized (FaweChunkManager.class) {
World pos1World = BukkitAdapter.adapt(getWorld(pos1.getWorld()));
try (EditSession editSession = new EditSessionBuilder(pos1World).checkMemory(false)
.fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build()) {
CuboidRegion region = new CuboidRegion(
BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()),
BlockVector3.at(pos2.getX(), pos2.getY(), pos2.getZ()));
editSession.regenerate(region);
editSession.flushQueue();
}
TaskManager.IMP.task(whenDone);
}
});
return true;
}
}

View File

@ -0,0 +1,130 @@
package com.boydti.fawe.bukkit.regions.plotsquared;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.beta.IQueueChunk;
import com.boydti.fawe.beta.IQueueExtent;
import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
// TODO FIXME
public class FaweLocalBlockQueue extends LocalBlockQueue {
public final IQueueExtent<IQueueChunk> IMP;
private final World world;
private BlockVector3 mutable = new MutableBlockVector3();
public FaweLocalBlockQueue(String worldName) {
super(worldName);
this.world = FaweAPI.getWorld(worldName);
IMP = Fawe.get().getQueueHandler().getQueue(world);
Fawe.get().getQueueHandler().unCache();
}
@Override
public boolean next() {
if (!IMP.isEmpty()) {
IMP.flush();
}
return false;
}
@Override
public void startSet(boolean parallel) {
Fawe.get().getQueueHandler().startSet(parallel);
}
@Override
public void endSet(boolean parallel) {
Fawe.get().getQueueHandler().endSet(parallel);
}
@Override
public int size() {
return IMP.isEmpty() ? 0 : 1;
}
@Override
public void optimize() {
}
@Override
public void setModified(long l) {
}
@Override
public long getModified() {
return IMP.size();
}
@Override
public boolean setBlock(final int x, final int y, final int z, final BlockState id) {
return IMP.setBlock(x, y, z, id);
}
@Override
public boolean setBlock(int x, int y, int z, Pattern pattern) {
mutable.setComponents(x, y, z);
return pattern.apply(IMP, mutable, mutable);
}
@Override
public boolean setBlock(final int x, final int y, final int z, final BaseBlock id) {
return IMP.setBlock(x, y, z, id);
}
@Override
public BlockState getBlock(int x, int y, int z) {
return IMP.getBlock(x, y, z);
}
@Override
public boolean setBiome(int x, int z, BiomeType biomeType) {
return IMP.setBiome(x, 0, z, biomeType);
}
@Override
public String getWorld() {
return world.getId();
}
@Override
public void flush() {
IMP.flush();
}
@Override
public boolean enqueue() {
boolean val = super.enqueue();
IMP.enableQueue();
return val;
}
@Override
public void refreshChunk(int x, int z) {
world.refreshChunk(x, z);
}
@Override
public void fixChunkLighting(int x, int z) {
}
@Override
public void regenChunk(int x, int z) {
IMP.regenerateChunk(x, z, null, null);
}
@Override
public boolean setTile(int x, int y, int z, CompoundTag tag) {
IMP.setTile(x, y, z, (com.sk89q.jnbt.CompoundTag) FaweCache.IMP.asTag(tag));
return true;
}
}

View File

@ -0,0 +1,139 @@
package com.boydti.fawe.bukkit.regions.plotsquared;
import static org.bukkit.Bukkit.getWorld;
import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.object.clipboard.ReadOnlyClipboard;
import com.boydti.fawe.object.io.PGZIPOutputStream;
import com.boydti.fawe.util.EditSessionBuilder;
import com.boydti.fawe.util.IOUtil;
import com.boydti.fawe.util.TaskManager;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler;
import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.CompressedCompoundTag;
import com.sk89q.jnbt.CompressedSchematicTag;
import com.sk89q.jnbt.NBTOutputStream;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.FastSchematicWriter;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.World;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import net.jpountz.lz4.LZ4BlockInputStream;
public class FaweSchematicHandler extends SchematicHandler {
@Override
public boolean restoreTile(LocalBlockQueue queue, CompoundTag compoundTag, int x, int y, int z) {
if (queue instanceof FaweLocalBlockQueue) {
queue.setTile(x, y, z, compoundTag);
return true;
}
return false;
}
@Override
public void getCompoundTag(final String world, final Set<CuboidRegion> regions, final RunnableVal<CompoundTag> whenDone) {
TaskManager.IMP.async(() -> {
Location[] corners = MainUtil.getCorners(world, regions);
Location pos1 = corners[0];
Location pos2 = corners[1];
World adaptedWorld = BukkitAdapter.adapt(getWorld(world));
final CuboidRegion region = new CuboidRegion(BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()), BlockVector3.at(pos2.getX(), pos2.getY(), pos2.getZ()));
final EditSession editSession = new EditSessionBuilder(adaptedWorld).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
ReadOnlyClipboard clipboard = ReadOnlyClipboard.of(editSession, region);
Clipboard holder = new BlockArrayClipboard(region, clipboard);
CompressedSchematicTag tag = new CompressedSchematicTag(holder);
whenDone.run(tag);
});
}
@Override
public boolean save(CompoundTag tag, String path) {
if (tag == null) {
PlotSquared.debug("&cCannot save empty tag");
return false;
}
try {
File tmp = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), path);
tmp.getParentFile().mkdirs();
if (tag instanceof CompressedCompoundTag) {
CompressedCompoundTag cTag = (CompressedCompoundTag) tag;
if (cTag instanceof CompressedSchematicTag) {
Clipboard clipboard = (Clipboard) cTag.getSource();
try (OutputStream stream = new FileOutputStream(tmp); NBTOutputStream output = new NBTOutputStream(new BufferedOutputStream(new PGZIPOutputStream(stream)))) {
new FastSchematicWriter(output).write(clipboard);
}
} else {
try (OutputStream stream = new FileOutputStream(tmp); BufferedOutputStream output = new BufferedOutputStream(new PGZIPOutputStream(stream))) {
LZ4BlockInputStream is = cTag.adapt(cTag.getSource());
IOUtil.copy(is, stream);
}
}
} else {
try (OutputStream stream = new FileOutputStream(tmp); NBTOutputStream output = new NBTOutputStream(new PGZIPOutputStream(stream))) {
Map<String, Tag> map = tag.getValue();
output.writeNamedTag("Schematic", map.getOrDefault("Schematic", tag));
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
@Override
public void upload(final CompoundTag tag, final UUID uuid, final String file, final RunnableVal<URL> whenDone) {
if (tag == null) {
PlotSquared.debug("&cCannot save empty tag");
com.github.intellectualsites.plotsquared.plot.util.TaskManager.runTask(whenDone);
return;
}
CompoundTag weTag = (CompoundTag) FaweCache.IMP.asTag(tag);
if (weTag instanceof CompressedSchematicTag) {
Clipboard clipboard = ((CompressedSchematicTag) weTag).getSource();
URL url = FaweAPI.upload(clipboard, BuiltInClipboardFormat.SPONGE_SCHEMATIC);
whenDone.run(url);
return;
}
MainUtil.upload(uuid, file, "schematic", new RunnableVal<OutputStream>() {
@Override
public void run(OutputStream output) {
try {
try (PGZIPOutputStream gzip = new PGZIPOutputStream(output)) {
try (NBTOutputStream nos = new NBTOutputStream(gzip)) {
Map<String, Tag> map = weTag.getValue();
nos.writeNamedTag("Schematic", map.getOrDefault("Schematic", weTag));
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}, whenDone);
}
}

View File

@ -0,0 +1,56 @@
package com.boydti.fawe.bukkit.regions.plotsquared;
import com.boydti.fawe.util.TaskManager;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.commands.CommandCategory;
import com.github.intellectualsites.plotsquared.plot.commands.RequiredType;
import com.github.intellectualsites.plotsquared.plot.commands.SubCommand;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
@CommandDeclaration(
command = "trimchunks",
permission = "plots.admin",
description = "Delete unmodified portions of your plotworld",
requiredType = RequiredType.PLAYER,
category = CommandCategory.ADMINISTRATION)
public class FaweTrim extends SubCommand {
private boolean ran = false;
@Override
public boolean onCommand(final PlotPlayer plotPlayer, final String[] strings) {
if (ran) {
plotPlayer.sendMessage("Already running!");
return false;
}
if (strings.length != 2) {
plotPlayer.sendMessage("First make a backup of your world called <world-copy> then stand in the middle of an empty plot");
plotPlayer.sendMessage("use /plot trimall <world> <boolean-delete-unowned>");
return false;
}
if (!WorldUtil.IMP.isWorld(strings[0])) {
Captions.NOT_VALID_PLOT_WORLD.send(plotPlayer, strings[0]);
return false;
}
ran = true;
TaskManager.IMP.async(new Runnable() {
@Override
public void run() {
try {
// TODO NOT IMPLEMENTED
// PlotTrim trim = new PlotTrim(plotPlayer, plotPlayer.getPlotAreaAbs(), strings[0], Boolean.parseBoolean(strings[1]));
// Location loc = plotPlayer.getLocation();
// trim.setChunk(loc.getX() >> 4, loc.getZ() >> 4);
// trim.run();
// plotPlayer.sendMessage("Done!");
} catch (Throwable e) {
e.printStackTrace();
}
ran = false;
}
});
return true;
}
}

View File

@ -0,0 +1,341 @@
package com.boydti.fawe.bukkit.regions.plotsquared;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.commands.CommandCategory;
import com.github.intellectualsites.plotsquared.plot.commands.RequiredType;
@CommandDeclaration(
command = "moveto512",
permission = "plots.moveto512",
category = CommandCategory.DEBUG,
requiredType = RequiredType.CONSOLE,
description = "Move plots to a 512 sized region",
usage = "/plots moveto512 [world]"
)
// TODO FIXME
public class MoveTo512 /*extends Command*/ {
// public MoveTo512() {
// super(MainCommand.getInstance(), true);
// }
//
// private MCAChunk emptyPlot(MCAChunk chunk, HybridPlotWorld hpw) {
// int maxLayer = (hpw.PLOT_HEIGHT) >> 4;
// for (int i = maxLayer + 1; i < chunk.ids.length; i++) {
// chunk.ids[i] = null;
// chunk.data[i] = null;
// }
// for (int layer = 0; layer <= maxLayer; layer++) {
// byte[] ids = chunk.ids[layer];
// if (ids == null) {
// ids = chunk.ids[layer] = new byte[4096];
// chunk.data[layer] = new byte[2048];
// chunk.skyLight[layer] = new byte[2048];
// chunk.blockLight[layer] = new byte[2048];
// } else {
// Arrays.fill(ids, (byte) 0);
// Arrays.fill(chunk.data[layer], (byte) 0);
// Arrays.fill(chunk.skyLight[layer], (byte) 0);
// Arrays.fill(chunk.blockLight[layer], (byte) 0);
// }
// if (layer == maxLayer) {
// int yMax = hpw.PLOT_HEIGHT & 15;
// for (int y = yMax + 1; y < 15; y++) {
// Arrays.fill(chunk.skyLight[layer], y << 7, (y << 7) + 128, (byte) 255);
// }
// if (layer == 0) {
// Arrays.fill(ids, 0, 256, (byte) 7);
// for (int y = 1; y < yMax; y++) {
// int y8 = y << 8;
// Arrays.fill(ids, y8, y8 + 256, (byte) 3);
// }
// } else {
// for (int y = 0; y < yMax; y++) {
// int y8 = y << 8;
// Arrays.fill(ids, y8, y8 + 256, (byte) 3);
// }
// }
// int yMax15 = yMax & 15;
// int yMax158 = yMax15 << 8;
// Arrays.fill(ids, yMax158, yMax158 + 256, (byte) 2);
// if (yMax != 15) {
// Arrays.fill(ids, yMax158 + 256, 4096, (byte) 0);
// }
// } else if (layer == 0){
// Arrays.fill(ids, 256, 4096, (byte) 3);
// Arrays.fill(ids, 0, 256, (byte) 7);
// } else {
// Arrays.fill(ids, (byte) 3);
// }
// }
// return chunk;
// }
//
// private MCAChunk emptyRoad(MCAChunk chunk, HybridPlotWorld hpw) {
// int maxLayer = (hpw.ROAD_HEIGHT) >> 4;
// for (int i = maxLayer + 1; i < chunk.ids.length; i++) {
// chunk.ids[i] = null;
// chunk.data[i] = null;
// }
// for (int layer = 0; layer <= maxLayer; layer++) {
// byte[] ids = chunk.ids[layer];
// if (ids == null) {
// ids = chunk.ids[layer] = new byte[4096];
// chunk.data[layer] = new byte[2048];
// chunk.skyLight[layer] = new byte[2048];
// chunk.blockLight[layer] = new byte[2048];
// } else {
// Arrays.fill(ids, (byte) 0);
// Arrays.fill(chunk.data[layer], (byte) 0);
// Arrays.fill(chunk.skyLight[layer], (byte) 0);
// Arrays.fill(chunk.blockLight[layer], (byte) 0);
// }
// if (layer == maxLayer) {
// int yMax = hpw.ROAD_HEIGHT & 15;
// for (int y = yMax + 1; y < 15; y++) {
// Arrays.fill(chunk.skyLight[layer], y << 7, (y << 7) + 128, (byte) 255);
// }
// if (layer == 0) {
// Arrays.fill(ids, 0, 256, (byte) 7);
// for (int y = 1; y <= yMax; y++) {
// int y8 = y << 8;
// Arrays.fill(ids, y8, y8 + 256, (byte) hpw.ROAD_BLOCK.id);
// }
// } else {
// for (int y = 0; y <= yMax; y++) {
// int y8 = y << 8;
// Arrays.fill(ids, y8, y8 + 256, (byte) hpw.ROAD_BLOCK.id);
// }
// }
// if (yMax != 15) {
// int yMax15 = yMax & 15;
// int yMax158 = yMax15 << 8;
// Arrays.fill(ids, yMax158 + 256, 4096, (byte) 0);
// }
// } else if (layer == 0){
// Arrays.fill(ids, 256, 4096, (byte) hpw.ROAD_BLOCK.id);
// Arrays.fill(ids, 0, 256, (byte) 7);
// } else {
// Arrays.fill(ids, (byte) hpw.ROAD_BLOCK.id);
// }
// }
// return chunk;
// }
// @Override
// public void execute(PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
// checkTrue(args.length == 1, Captions.COMMAND_SYNTAX, getUsage());
// PlotArea area = player.getPlotAreaAbs();
// check(area, Captions.COMMAND_SYNTAX, getUsage());
// checkTrue(area instanceof HybridPlotWorld, Captions.NOT_VALID_HYBRID_PLOT_WORLD);
//
// WorldUtil.IMP.saveWorld(area.worldname);
//
// IQueueExtent defaultQueue = SetQueue.IMP.getNewQueue(area.worldname, true, false);
// MCAQueue queueFrom = new MCAQueue(area.worldname, defaultQueue.getSaveFolder(), defaultQueue.hasSky());
//
// String world = args[0];
// File folder = new File(PS.imp().getWorldContainer(), world + File.separator + "region");
// checkTrue(!folder.exists(), Captions.SETUP_WORLD_TAKEN, world);
//
// HybridPlotWorld hpw = (HybridPlotWorld) area;
// int minRoad = 7;
// int pLen = Math.min(hpw.PLOT_WIDTH, 512 - minRoad);
// int roadWidth = 512 - pLen;
// int roadPosLower;
// if ((roadWidth & 1) == 0) {
// roadPosLower = (short) (Math.floor(roadWidth / 2) - 1);
// } else {
// roadPosLower = (short) Math.floor(roadWidth / 2);
// }
// int roadPosUpper = 512 - roadWidth + roadPosLower + 1;
//
// final ThreadLocal<boolean[]> roadCache = new ThreadLocal<boolean[]>() {
// @Override
// protected boolean[] initialValue() {
// return new boolean[64];
// }
// };
//
// MCAChunk reference = new MCAChunk(null, 0, 0);
// {
// reference.fillCuboid(0, 15, 0, 0, 0, 15, 7, (byte) 0);
// reference.fillCuboid(0, 15, 1, hpw.PLOT_HEIGHT - 1, 0, 15, 3, (byte) 0);
// reference.fillCuboid(0, 15, hpw.PLOT_HEIGHT, hpw.PLOT_HEIGHT, 0, 15, 2, (byte) 0);
// }
//
// Map<PlotId, Plot> rawPlots = area.getPlotsRaw();
// ArrayList<Plot> plots = new ArrayList(rawPlots.values());
// int size = plots.size();
//
// PlotId nextId = new PlotId(0, 0);
//
// long start = System.currentTimeMillis();
//
// int percent = 0;
// for (Plot plot : plots) {
// Fawe.debug(((percent += 100) / size) + "% complete!");
//
// Location bot = plot.getBottomAbs();
// Location top = plot.getTopAbs();
//
// int oX = roadPosLower - bot.getX() + 1;
// int oZ = roadPosLower - bot.getZ() + 1;
//
// { // Move
// PlotId id = plot.getId();
// Fawe.debug("Moving " + plot.getId() + " to " + nextId);
// id.x = nextId.x;
// id.y = nextId.y;
// id.recalculateHash();
// }
//
// MCAWriter writer = new MCAWriter(512, 512, folder) {
//
// @Override
// public boolean shouldWrite(int chunkX, int chunkZ) {
// int bx = chunkX << 4;
// int bz = chunkZ << 4;
// int tx = bx + 15;
// int tz = bz + 15;
// return !(tx < roadPosLower || tz < roadPosLower || bx > roadPosUpper || bz > roadPosUpper);
// }
//
// @Override
// public MCAChunk write(MCAChunk newChunk, int bx, int tx, int bz, int tz) {
// Arrays.fill(newChunk.biomes, (byte) 4);
// if (!newChunk.tiles.isEmpty()) newChunk.tiles.clear();
// if (tx < roadPosLower || tz < roadPosLower || bx > roadPosUpper || bz > roadPosUpper) {
// return emptyRoad(newChunk, hpw);
// } else {
// boolean partRoad = (bx <= roadPosLower || bz <= roadPosLower || tx >= roadPosUpper || tz >= roadPosUpper);
//
// boolean changed = false;
// emptyPlot(newChunk, hpw);
//
// int obx = bx - oX;
// int obz = bz - oZ;
// int otx = tx - oX;
// int otz = tz - oZ;
// int otherBCX = (obx) >> 4;
// int otherBCZ = (obz) >> 4;
// int otherTCX = (otx) >> 4;
// int otherTCZ = (otz) >> 4;
// int cx = newChunk.getX();
// int cz = newChunk.getZ();
// int cbx = (cx << 4) - oX;
// int cbz = (cz << 4) - oZ;
//
// for (int otherCZ = otherBCZ; otherCZ <= otherTCZ; otherCZ++) {
// for (int otherCX = otherBCX; otherCX <= otherTCX; otherCX++) {
// FaweChunk chunk;
// synchronized (queueFrom) {
// chunk = queueFrom.getFaweChunk(otherCX, otherCZ);
// }
// if (!(chunk instanceof NullFaweChunk)) {
// changed = true;
// MCAChunk other = (MCAChunk) chunk;
// int ocbx = otherCX << 4;
// int ocbz = otherCZ << 4;
// int octx = ocbx + 15;
// int octz = ocbz + 15;
// int offsetY = 0;
// int minX = obx > ocbx ? (obx - ocbx) & 15 : 0;
// int maxX = otx < octx ? (otx - ocbx) : 15;
// int minZ = obz > ocbz ? (obz - ocbz) & 15 : 0;
// int maxZ = otz < octz ? (otz - ocbz) : 15;
// int offsetX = ocbx - cbx;
// int offsetZ = ocbz - cbz;
// newChunk.copyFrom(other, minX, maxX, 0, 255, minZ, maxZ, offsetX, offsetY, offsetZ);
// }
// }
// }
// if (!changed || reference.idsEqual(newChunk, false)) {
// return null;
// }
// if (partRoad) {
// boolean[] rwp = roadCache.get();
// for (short i = 0; i < 16; i++) {
// int vx = bx + i;
// int vz = bz + i;
// rwp[i] = vx < roadPosLower || vx > roadPosUpper;
// rwp[i + 32] = vx == roadPosLower || vx == roadPosUpper;
// rwp[i + 16] = vz < roadPosLower || vz > roadPosUpper;
// rwp[i + 48] = vz == roadPosLower || vz == roadPosUpper;
// }
// for (int z = 0; z < 16; z++) {
// final boolean rwpz16 = rwp[z + 16];
// final boolean rwpz48 = rwp[z + 48];
// for (int x = 0; x < 16; x++) {
// if (rwpz16 || rwp[x]) {
// for (int y = 1; y <= hpw.ROAD_HEIGHT; y++) {
// newChunk.setBlock(x, y, z, hpw.ROAD_BLOCK.id, hpw.ROAD_BLOCK.data);
// }
// for (int y = hpw.ROAD_HEIGHT + 1; y < 256; y++) {
// newChunk.setBlock(x, y, z, 0, 0);
// }
// } else if (rwpz48 || rwp[x + 32]) {
// for (int y = 1; y <= hpw.WALL_HEIGHT; y++) {
// newChunk.setBlock(x, y, z, hpw.WALL_FILLING.id, hpw.WALL_FILLING.data);
// }
// for (int y = hpw.WALL_HEIGHT + 2; y < 256; y++) {
// newChunk.setBlock(x, y, z, 0, 0);
// }
// newChunk.setBlock(x, hpw.WALL_HEIGHT + 1, z, hpw.CLAIMED_WALL_BLOCK.id, hpw.CLAIMED_WALL_BLOCK.data);
// }
// }
// }
// }
// }
// return newChunk;
// }
// };
// writer.setMCAOffset(nextId.x - 1, nextId.y - 1);
// try {
// writer.generate();
// System.gc();
// } catch (IOException e) {
// e.printStackTrace();
// return;
// }
// queueFrom.clear();
// nextId = nextId.getNextId(1);
// }
// Fawe.debug("Anvil copy completed in " + ((System.currentTimeMillis() - start) / 1000d) + "s");
// Fawe.debug("Updating database, please wait...");
// rawPlots.clear();
// for (Plot plot : plots) {
// rawPlots.put(plot.getId(), plot);
// DBFunc.movePlot(plot, plot);
// }
// SQLManager db = (SQLManager) DBFunc.dbManager;
// db.addNotifyTask(new Runnable() {
// @Override
// public void run() {
// Fawe.debug("Instructions");
// Fawe.debug(" - Stop the server");
// Fawe.debug(" - Rename the folder for the new world to the current world");
// Fawe.debug(" - Change the plot size to " + pLen);
// Fawe.debug(" - Change the road size to " + roadWidth);
// Fawe.debug(" - Start the server");
// }
// });
//
// ConfigurationSection section = PS.get().worlds.getConfigurationSection("worlds." + world);
// if (section == null) section = PS.get().worlds.createSection("worlds." + world);
// area.saveConfiguration(section);
// section.set("plot.size", pLen);
// section.set("road.width", roadWidth);
// try {
// PS.get().worlds.save(PS.get().worldsFile);
// } catch (IOException e) {
// e.printStackTrace();
// }
//
// final SetupObject object = new SetupObject();
// object.world = world;
// object.plotManager = PS.imp().getPluginName();
// object.setupGenerator = PS.imp().getPluginName();
// String created = SetupUtils.manager.setupWorld(object);
// }
}

View File

@ -0,0 +1,28 @@
package com.boydti.fawe.bukkit.regions.plotsquared;
import static com.google.common.base.Preconditions.checkNotNull;
import com.boydti.fawe.regions.general.CuboidRegionFilter;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import com.sk89q.worldedit.math.BlockVector2;
import java.util.ArrayList;
public class PlotRegionFilter extends CuboidRegionFilter {
private final PlotArea area;
public PlotRegionFilter(PlotArea area) {
checkNotNull(area);
this.area = area;
}
@Override
public void calculateRegions() {
ArrayList<Plot> plots = new ArrayList<>(area.getPlots());
for (Plot plot : plots) {
Location bottom = plot.getCorners()[0];
Location top = plot.getCorners()[1];
add(BlockVector2.at(bottom.getX(), bottom.getZ()), BlockVector2.at(top.getX(), top.getZ()));
}
}
}

View File

@ -0,0 +1,92 @@
package com.boydti.fawe.bukkit.regions.plotsquared;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.util.EditSessionBuilder;
import com.boydti.fawe.util.TaskManager;
import com.github.intellectualsites.plotsquared.commands.Command;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.commands.CommandCategory;
import com.github.intellectualsites.plotsquared.plot.commands.MainCommand;
import com.github.intellectualsites.plotsquared.plot.commands.RequiredType;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal2;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.Permissions;
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.biome.BiomeTypes;
import com.sk89q.worldedit.world.biome.Biomes;
import com.sk89q.worldedit.world.registry.BiomeRegistry;
import java.util.Collection;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadLocalRandom;
@CommandDeclaration(
command = "generatebiome",
permission = "plots.generatebiome",
category = CommandCategory.APPEARANCE,
requiredType = RequiredType.NONE,
description = "Generate a biome in your plot",
aliases = {"bg", "gb"},
usage = "/plots generatebiome <biome>"
)
public class PlotSetBiome extends Command {
public PlotSetBiome() {
super(MainCommand.getInstance(), true);
}
@Override
public CompletableFuture<Boolean> execute(final PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
final Plot plot = check(player.getCurrentPlot(), Captions.NOT_IN_PLOT);
checkTrue(plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.admin.command.generatebiome"), Captions.NO_PLOT_PERMS);
if (plot.getRunning() != 0) {
Captions.WAIT_FOR_TIMER.send(player);
return null;
}
checkTrue(args.length == 1, Captions.COMMAND_SYNTAX, getUsage());
final Set<CuboidRegion> regions = plot.getRegions();
BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry();
Collection<BiomeType> knownBiomes = BiomeTypes.values();
final BiomeType biome = Biomes.findBiomeByName(knownBiomes, args[0], biomeRegistry);
if (biome == null) {
String biomes = StringMan
.join(BiomeType.REGISTRY.values(), Captions.BLOCK_LIST_SEPARATOR.getTranslated());
Captions.NEED_BIOME.send(player);
MainUtil.sendMessage(player, Captions.SUBCOMMAND_SET_OPTIONS_HEADER.toString() + biomes);
return CompletableFuture.completedFuture(false);
}
confirm.run(this, () -> {
if (plot.getRunning() != 0) {
Captions.WAIT_FOR_TIMER.send(player);
return;
}
plot.addRunning();
TaskManager.IMP.async(() -> {
EditSession session = new EditSessionBuilder(FaweAPI.getWorld(plot.getArea().worldname))
.autoQueue(false)
.checkMemory(false)
.allowedRegionsEverywhere()
.player(Fawe.imp().wrap(player.getUUID()))
.limitUnlimited()
.build();
long seed = ThreadLocalRandom.current().nextLong();
for (CuboidRegion region : regions) {
session.regenerate(region, biome, seed);
}
session.flushQueue();
plot.removeRunning();
});
}, null);
return CompletableFuture.completedFuture(true);
}
}

View File

@ -0,0 +1,171 @@
package com.boydti.fawe.bukkit.regions.plotsquared;
import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.object.RegionWrapper;
import com.boydti.fawe.regions.FaweMask;
import com.boydti.fawe.regions.FaweMaskManager;
import com.boydti.fawe.regions.general.RegionFilter;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.commands.MainCommand;
import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.generator.HybridPlotManager;
import com.github.intellectualsites.plotsquared.plot.listener.WEManager;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.ChunkManager;
import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler;
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue;
import com.github.intellectualsites.plotsquared.plot.util.block.QueueProvider;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionIntersection;
import com.sk89q.worldedit.world.World;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class PlotSquaredFeature extends FaweMaskManager {
private static final Logger log = LoggerFactory.getLogger(PlotSquaredFeature.class);
public PlotSquaredFeature() {
super("PlotSquared");
log.debug("Optimizing PlotSquared");
if (com.boydti.fawe.config.Settings.IMP.PLOTSQUARED_HOOK) {
Settings.Enabled_Components.WORLDEDIT_RESTRICTIONS = false;
try {
setupBlockQueue();
setupSchematicHandler();
setupChunkManager();
} catch (Throwable ignored) {
log.debug("Please update PlotSquared: http://ci.athion.net/job/PlotSquared/");
}
if (Settings.PLATFORM.toLowerCase().startsWith("bukkit")) {
new FaweTrim();
}
if (MainCommand.getInstance().getCommand("generatebiome") == null) {
new PlotSetBiome();
}
}
// TODO: revisit this later on
/*
try {
if (Settings.Enabled_Components.WORLDS) {
new ReplaceAll();
}
} catch (Throwable e) {
log.debug("You need to update PlotSquared to access the CFI and REPLACEALL commands");
}
*/
}
public static String getName(UUID uuid) {
return UUIDHandler.getName(uuid);
}
private void setupBlockQueue() throws RuntimeException {
// If it's going to fail, throw an error now rather than later
QueueProvider provider = QueueProvider.of(FaweLocalBlockQueue.class, null);
GlobalBlockQueue.IMP.setProvider(provider);
HybridPlotManager.REGENERATIVE_CLEAR = false;
log.debug(" - QueueProvider: " + FaweLocalBlockQueue.class);
log.debug(" - HybridPlotManager.REGENERATIVE_CLEAR: " + HybridPlotManager.REGENERATIVE_CLEAR);
}
private void setupChunkManager() throws RuntimeException {
ChunkManager.manager = new FaweChunkManager(ChunkManager.manager);
log.debug(" - ChunkManager: " + ChunkManager.manager);
}
private void setupSchematicHandler() throws RuntimeException {
SchematicHandler.manager = new FaweSchematicHandler();
log.debug(" - SchematicHandler: " + SchematicHandler.manager);
}
public boolean isAllowed(Player player, Plot plot, MaskType type) {
if (plot == null) {
return false;
}
UUID uid = player.getUniqueId();
return !Flags.NO_WORLDEDIT.isTrue(plot) && (plot.isOwner(uid)
|| type == MaskType.MEMBER && (plot.getTrusted().contains(uid) || plot.getTrusted()
.contains(DBFunc.EVERYONE)
|| (plot.getMembers().contains(uid) || plot.getMembers().contains(DBFunc.EVERYONE))
&& player.hasPermission("fawe.plotsquared.member")) || player
.hasPermission("fawe.plotsquared.admin"));
}
@Override
public FaweMask getMask(Player player, MaskType type) {
final PlotPlayer pp = PlotPlayer.wrap(player.getUniqueId());
final Set<CuboidRegion> regions;
Plot plot = pp.getCurrentPlot();
if (isAllowed(player, plot, type)) {
regions = plot.getRegions();
} else {
plot = null;
regions = WEManager.getMask(pp);
if (regions.size() == 1) {
CuboidRegion region = regions.iterator().next();
if (region.getMinimumPoint().getX() == Integer.MIN_VALUE && region.getMaximumPoint().getX() == Integer.MAX_VALUE) {
regions.clear();
}
}
}
if (regions.isEmpty()) {
return null;
}
PlotArea area = pp.getApplicablePlotArea();
int min = area != null ? area.MIN_BUILD_HEIGHT : 0;
int max = area != null ? Math.min(255, area.MAX_BUILD_HEIGHT) : 255;
final HashSet<RegionWrapper> faweRegions = new HashSet<>();
for (CuboidRegion current : regions) {
faweRegions.add(new RegionWrapper(current.getMinimumX(), current.getMaximumX(), min, max, current.getMinimumZ(), current.getMaximumZ()));
}
final CuboidRegion region = regions.iterator().next();
final BlockVector3 pos1 = BlockVector3.at(region.getMinimumX(), min, region.getMinimumZ());
final BlockVector3 pos2 = BlockVector3.at(region.getMaximumX(), max, region.getMaximumZ());
final Plot finalPlot = plot;
if (Settings.Done.RESTRICT_BUILDING && Flags.DONE.isSet(finalPlot) || regions.isEmpty()) {
return null;
}
Region maskedRegion;
if (regions.size() == 1) {
maskedRegion = new CuboidRegion(pos1, pos2);
} else {
World world = FaweAPI.getWorld(area.worldname);
List<Region> weRegions = regions.stream()
.map(r -> new CuboidRegion(world, BlockVector3.at(r.getMinimumX(), r.getMinimumY(), r.getMinimumZ()), BlockVector3.at(r.getMaximumX(), r.getMaximumY(), r.getMaximumZ())))
.collect(Collectors.toList());
maskedRegion = new RegionIntersection(world, weRegions);
}
return new FaweMask(maskedRegion) {
@Override
public boolean isValid(Player player, MaskType type) {
if (Settings.Done.RESTRICT_BUILDING && Flags.DONE.isSet(finalPlot)) {
return false;
}
return isAllowed(player, finalPlot, type);
}
};
}
@Override
public RegionFilter getFilter(String world) {
PlotArea area = PlotSquared.get().getPlotArea(world, null);
if (area != null) return new PlotRegionFilter(area);
return null;
}
}

View File

@ -0,0 +1,75 @@
/*
package com.boydti.fawe.regions.general.plot;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.RunnableVal;
import com.boydti.fawe.util.StringMan;
import com.boydti.fawe.util.TaskManager;
import com.boydti.fawe.wrappers.FakePlayer;
import com.github.intellectualsites.plotsquared.commands.Command;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.commands.CommandCategory;
import com.github.intellectualsites.plotsquared.plot.commands.MainCommand;
import com.github.intellectualsites.plotsquared.plot.commands.RequiredType;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal2;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3;
import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotArea;
import com.github.intellectualsites.plotsquared.plot.util.SetupUtils;
import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
@CommandDeclaration(
command = "replaceall",
permission = "plots.replaceall",
category = CommandCategory.APPEARANCE,
requiredType = RequiredType.NONE,
description = "Replace all block in the plot",
usage = "/plots replaceall <from> <to>"
)
public class ReplaceAll extends Command {
public ReplaceAll() {
super(MainCommand.getInstance(), true);
}
@Override
public void execute(final PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
checkTrue(args.length >= 1, Captions.COMMAND_SYNTAX, getUsage());
final Plot plot = check(player.getCurrentPlot(), Captions.NOT_IN_PLOT);
checkTrue(plot.isOwner(player.getUUID()), Captions.NOW_OWNER);
checkTrue(plot.getRunning() == 0, Captions.WAIT_FOR_TIMER);
final PlotArea area = plot.getArea();
if (area instanceof SinglePlotArea) {
plot.addRunning();
FawePlayer<Object> fp = FawePlayer.wrap(player.getName());
Captions.TASK_START.send(player);
TaskManager.IMP.async(() -> fp.runAction(() -> {
String worldName = plot.getWorldName();
TaskManager.IMP.sync(new RunnableVal<Object>() {
@Override
public void run(Object value) {
SetupUtils.manager.unload(worldName, true);
}
});
FakePlayer actor = FakePlayer.getConsole();
String cmd = "/replaceallpattern " + worldName + " " + StringMan.join(args, " ");
CommandEvent event = new CommandEvent(actor, cmd);
PlatformCommandManager.getInstance().handleCommandOnCurrentThread(event);
TaskManager.IMP.sync(new RunnableVal<Object>() {
@Override
public void run(Object value) {
plot.teleportPlayer(player);
}
});
plot.removeRunning();
}, true, false));
} else {
player.sendMessage("Must have the `worlds` component enabled in the PlotSquared config.yml");
return;
}
}
}
*/