A tribute to Jesse
This commit is contained in:
MattBDev
2019-09-20 21:52:35 -04:00
parent 68c8fca672
commit 8b96cdc9a5
121 changed files with 1196 additions and 1130 deletions

View File

@ -40,9 +40,7 @@ dependencies {
"implementation"("io.papermc:paperlib:1.0.2")
"compileOnly"("com.sk89q:dummypermscompat:1.10")
"implementation"("org.apache.logging.log4j:log4j-slf4j-impl:2.8.1")
"testCompile"("org.mockito:mockito-core:1.9.0-rc1") {
exclude("junit", "junit")
}
"testCompile"("org.mockito:mockito-core:1.9.0-rc1")
"compileOnly"("com.sk89q.worldguard:worldguard-bukkit:7.0.0") {
exclude("com.sk89q.worldedit", "worldedit-bukkit")
exclude("com.sk89q.worldedit", "worldedit-core")
@ -61,6 +59,9 @@ dependencies {
"implementation"("com.thevoxelbox.voxelsniper:voxelsniper:5.171.0") { isTransitive = false }
"implementation"("com.comphenix.protocol:ProtocolLib-API:4.4.0-SNAPSHOT") { isTransitive = false }
"implementation"("com.wasteofplastic:askyblock:3.0.8.2") { isTransitive = false }
"compileOnly"("com.github.intellectualsites.plotsquared:PlotSquared-API:latest") {
isTransitive = false
}
}
tasks.named<Copy>("processResources") {

View File

@ -20,6 +20,7 @@ import com.boydti.fawe.bukkit.regions.ResidenceFeature;
import com.boydti.fawe.bukkit.regions.TownyFeature;
import com.boydti.fawe.bukkit.regions.Worldguard;
import com.boydti.fawe.bukkit.regions.WorldguardFlag;
import com.boydti.fawe.bukkit.regions.plotquared.PlotSquaredFeature;
import com.boydti.fawe.bukkit.util.BukkitTaskMan;
import com.boydti.fawe.bukkit.util.ItemUtil;
import com.boydti.fawe.bukkit.util.VaultUtil;
@ -29,6 +30,7 @@ import com.boydti.fawe.object.FaweCommand;
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.world.World;
@ -84,6 +86,7 @@ public class FaweBukkit implements IFawe, Listener {
if (PaperLib.isPaper() && Settings.IMP.EXPERIMENTAL.DYNAMIC_CHUNK_RENDERING > 1) {
new RenderListener(plugin);
}
WEManager.IMP.managers.add(new PlotSquaredFeature());
} catch (final Throwable e) {
e.printStackTrace();
Bukkit.getServer().shutdown();
@ -205,6 +208,15 @@ public class FaweBukkit implements IFawe, Listener {
Player player = Bukkit.getPlayer(name);
return player != null ? BukkitAdapter.adapt(player) : null;
}
if (obj.getClass() == UUID.class) {
UUID uuid = (UUID) obj;
com.sk89q.worldedit.entity.Player existing = Fawe.get().getCachedPlayer(uuid);
if (existing != null) {
return existing;
}
Player player = Bukkit.getPlayer(uuid);
return player != null ? BukkitAdapter.adapt(player) : null;
}
return null;
}

View File

@ -1,3 +1,22 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.boydti.fawe.bukkit.adapter.mc1_14;
import com.google.common.collect.Lists;
@ -2708,4 +2727,4 @@ public class DataConverters_1_14_R4 extends DataFixerBuilder implements com.sk89
return cmp;
}
}
}
}

View File

@ -21,7 +21,7 @@ import com.sk89q.worldedit.event.platform.BlockInteractEvent;
import com.sk89q.worldedit.event.platform.Interaction;
import com.sk89q.worldedit.extension.platform.PlatformManager;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockState;
import java.lang.reflect.InvocationTargetException;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@ -239,14 +239,14 @@ public class CFIPacketListener implements Listener {
platform.handleBlockInteract(toCall);
if (toCall.isCancelled() || action == Interaction.OPEN) {
BlockVector3 realPos = pt.add(gen.getOrigin().toBlockPoint());
BlockStateHolder block = gen.getBlock(pt);
BlockState block = gen.getBlock(pt);
sendBlockChange(plr, realPos, block);
return true;
}
return false;
}
private void sendBlockChange(Player plr, BlockVector3 pt, BlockStateHolder block) {
private void sendBlockChange(Player plr, BlockVector3 pt, BlockState block) {
plr.sendBlockChange(new Location(plr.getWorld(), pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()), BukkitAdapter.adapt(block));
}

View File

@ -0,0 +1,50 @@
package com.boydti.fawe.bukkit.regions.plotquared;
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,103 @@
package com.boydti.fawe.bukkit.regions.plotquared;
import com.boydti.fawe.util.EditSessionBuilder;
import com.boydti.fawe.util.TaskManager;
import com.github.intellectualsites.plotsquared.plot.object.ChunkLoc;
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.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.World;
import java.util.concurrent.CompletableFuture;
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, ChunkLoc loc, boolean force) {
return parent.loadChunk(world, loc, force);
}
@Override
public void unloadChunk(String world, ChunkLoc 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) {
EditSession sessionA = new EditSessionBuilder(pos1.getWorld()).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
EditSession sessionB = new EditSessionBuilder(pos3.getWorld()).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) {
EditSession from = new EditSessionBuilder(pos1.getWorld()).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
EditSession to = new EditSessionBuilder(pos3.getWorld()).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) {
EditSession editSession = new EditSessionBuilder(pos1.getWorld()).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
World world = editSession.getWorld();
CuboidRegion region = new CuboidRegion(BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()), BlockVector3.at(pos2.getX(), pos2.getY(), pos2.getZ()));
world.regenerate(region, editSession);
editSession.flushQueue();
TaskManager.IMP.task(whenDone);
}
});
return true;
}
}

View File

@ -0,0 +1,142 @@
package com.boydti.fawe.bukkit.regions.plotquared;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.beta.IQueueExtent;
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.world.World;
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.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.registry.BiomeRegistry;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import java.util.Collection;
// TODO FIXME
public class FaweLocalBlockQueue extends LocalBlockQueue {
public final IQueueExtent IMP;
private final LegacyMapper legacyMapper;
private final World world;
public FaweLocalBlockQueue(String worldName) {
super(worldName);
this.world = FaweAPI.getWorld(worldName);
IMP = Fawe.get().getQueueHandler().getQueue(world);
legacyMapper = LegacyMapper.getInstance();
}
@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 PlotBlock id) {
return setBlock(x, y, z, legacyMapper.getBaseBlockFromPlotBlock(id));
}
@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 PlotBlock getBlock(int x, int y, int z) {
BlockState block = IMP.getBlock(x, y, z);
return PlotBlock.get(block.toBaseBlock());
}
private BiomeType biome;
private String lastBiome;
private BiomeRegistry reg;
@Override
public boolean setBiome(int x, int z, String biome) {
if (!StringMan.isEqual(biome, lastBiome)) {
if (reg == null) {
reg = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.USER_COMMANDS).getRegistries().getBiomeRegistry();
}
Collection<BiomeType> biomes = BiomeTypes.values();
lastBiome = biome;
this.biome = Biomes.findBiomeByName(biomes, biome, reg);
}
return IMP.setBiome(x, 0, z, this.biome);
}
@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.sendChunk(x, z, 0);
}
@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,131 @@
package com.boydti.fawe.bukkit.regions.plotquared;
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.RegionWrapper;
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.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.SpongeSchematicWriter;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
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<RegionWrapper> regions, final RunnableVal<CompoundTag> whenDone) {
TaskManager.IMP.async(() -> {
Location[] corners = MainUtil.getCorners(world, regions);
Location pos1 = corners[0];
Location pos2 = corners[1];
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(world).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
final int mx = pos1.getX();
final int my = pos1.getY();
final int mz = pos1.getZ();
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 SpongeSchematicWriter(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;
}
MainUtil.upload(uuid, file, "schematic", new RunnableVal<OutputStream>() {
@Override
public void run(OutputStream output) {
try {
try (PGZIPOutputStream gzip = new PGZIPOutputStream(output)) {
CompoundTag weTag = (CompoundTag) FaweCache.IMP.asTag(tag);
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.plotquared;
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.plotquared;
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.plotquared;
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,96 @@
package com.boydti.fawe.bukkit.regions.plotquared;
import com.boydti.fawe.Fawe;
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.RegionWrapper;
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.github.intellectualsites.plotsquared.plot.util.WorldUtil;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.math.BlockVector3;
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.HashSet;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadLocalRandom;
import org.bukkit.Bukkit;
@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 HashSet<RegionWrapper> 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(WorldUtil.IMP.getBiomeList(), Captions.BLOCK_LIST_SEPARATOR.toString());
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(BukkitAdapter.adapt(Bukkit.getWorld(plot.getArea().worldname)))
.autoQueue(false)
.checkMemory(false)
.allowedRegionsEverywhere()
.player(Fawe.imp().wrap(player.getUUID()))
.limitUnlimited()
.build();
long seed = ThreadLocalRandom.current().nextLong();
for (RegionWrapper region : regions) {
CuboidRegion cuboid = new CuboidRegion(BlockVector3.at(region.minX, 0, region.minZ), BlockVector3.at(region.maxX, 256, region.maxZ));
session.regenerate(cuboid, biome, seed);
}
session.flushQueue();
plot.removeRunning();
});
}, null);
return CompletableFuture.completedFuture(true);
}
}

View File

@ -0,0 +1,196 @@
package com.boydti.fawe.bukkit.regions.plotquared;
import com.boydti.fawe.Fawe;
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.object.RegionWrapper;
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.bukkit.BukkitAdapter;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.AbstractRegion;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionOperationException;
import java.util.HashSet;
import java.util.UUID;
import org.bukkit.Bukkit;
public class PlotSquaredFeature extends FaweMaskManager {
public PlotSquaredFeature() {
super("PlotSquared");
Fawe.debug("Optimizing PlotSquared");
setupBlockQueue();
setupSchematicHandler();
setupChunkManager();
if (Settings.PLATFORM.equalsIgnoreCase("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) {
Fawe.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() {
try {
// 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;
Fawe.debug(" - QueueProvider: " + FaweLocalBlockQueue.class);
Fawe.debug(" - HybridPlotManager.REGENERATIVE_CLEAR: " + HybridPlotManager.REGENERATIVE_CLEAR);
} catch (Throwable e) {
Fawe.debug("Please update PlotSquared: http://ci.athion.net/job/PlotSquared/");
}
}
private void setupChunkManager() {
try {
ChunkManager.manager = new FaweChunkManager(ChunkManager.manager);
Fawe.debug(" - ChunkManager: " + ChunkManager.manager);
} catch (Throwable e) {
Fawe.debug("Please update PlotSquared: http://ci.athion.net/job/PlotSquared/");
}
}
private void setupSchematicHandler() {
try {
SchematicHandler.manager = new FaweSchematicHandler();
Fawe.debug(" - SchematicHandler: " + SchematicHandler.manager);
} catch (Throwable e) {
Fawe.debug("Please update PlotSquared: http://ci.athion.net/job/PlotSquared/");
}
}
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 fp, MaskType type) {
final PlotPlayer pp = PlotPlayer.wrap(fp);
final HashSet<RegionWrapper> regions;
Plot plot = pp.getCurrentPlot();
if (isAllowed(fp, plot, type)) {
regions = plot.getRegions();
} else {
plot = null;
regions = WEManager.getMask(pp);
if (regions.size() == 1) {
RegionWrapper region = regions.iterator().next();
if (region.minX == Integer.MIN_VALUE && region.maxX == 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<com.boydti.fawe.object.RegionWrapper> faweRegions = new HashSet<>();
for (RegionWrapper current : regions) {
faweRegions.add(new com.boydti.fawe.object.RegionWrapper(current.minX, current.maxX, min, max, current.minZ, current.maxZ));
}
final RegionWrapper region = regions.iterator().next();
final BlockVector3 pos1 = BlockVector3.at(region.minX, min, region.minZ);
final BlockVector3 pos2 = BlockVector3.at(region.maxX, max, region.maxZ);
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 {
maskedRegion = new AbstractRegion(BukkitAdapter.adapt(Bukkit.getWorld(area.worldname))) {
@Override
public BlockVector3 getMinimumPoint() {
return pos1;
}
@Override
public BlockVector3 getMaximumPoint() {
return pos2;
}
@Override
public void expand(BlockVector3... changes) throws RegionOperationException {
throw new UnsupportedOperationException("Region is immutable");
}
@Override
public void contract(BlockVector3... changes) throws RegionOperationException {
throw new UnsupportedOperationException("Region is immutable");
}
@Override
public boolean contains(int x, int y, int z) {
return WEManager.maskContains(regions, x, y, z);
}
@Override
public boolean contains(int x, int z) {
return WEManager.maskContains(regions, x, z);
}
@Override
public boolean contains(BlockVector3 position) {
return contains(position.getBlockX(), position.getBlockY(), position.getBlockZ());
}
};
}
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;
}
}
}
*/

View File

@ -34,12 +34,22 @@ import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.biome.BiomeTypes;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.entity.EntityType;
import com.sk89q.worldedit.world.entity.EntityTypes;
import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.gamemode.GameModes;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.block.data.BlockData;
@ -82,7 +92,7 @@ public enum BukkitAdapter {
* @return If they are equal
*/
public static boolean equals(BlockType blockType, Material type) {
return getAdapter().equals(blockType, type);
return Objects.equals(blockType.getId(), type.getKey().toString());
}
/**
@ -95,7 +105,15 @@ public enum BukkitAdapter {
* @return a wrapped Bukkit world
*/
public static BukkitWorld asBukkitWorld(World world) {
return getAdapter().asBukkitWorld(world);
if (world instanceof BukkitWorld) {
return (BukkitWorld) world;
} else {
BukkitWorld bukkitWorld = WorldEditPlugin.getInstance().getInternalPlatform().matchWorld(world);
if (bukkitWorld == null) {
throw new RuntimeException("World '" + world.getName() + "' has no matching version in Bukkit");
}
return bukkitWorld;
}
}
/**
@ -105,11 +123,8 @@ public enum BukkitAdapter {
* @return a WorldEdit world
*/
public static World adapt(org.bukkit.World world) {
return getAdapter().adapt(world);
}
public static org.bukkit.World adapt(World world) {
return getAdapter().adapt(world);
checkNotNull(world);
return new BukkitWorld(world);
}
/**
@ -119,7 +134,7 @@ public enum BukkitAdapter {
* @return The WorldEdit player
*/
public static BukkitPlayer adapt(Player player) {
return getAdapter().adapt(player);
return WorldEditPlugin.getInstance().wrapPlayer(player);
}
/**
@ -129,7 +144,27 @@ public enum BukkitAdapter {
* @return The Bukkit player
*/
public static Player adapt(com.sk89q.worldedit.entity.Player player) {
return getAdapter().adapt(player);
return ((BukkitPlayer) player).getPlayer();
}
/**
* Create a Bukkit world from a WorldEdit world.
*
* @param world the WorldEdit world
* @return a Bukkit world
*/
public static org.bukkit.World adapt(World world) {
checkNotNull(world);
if (world instanceof BukkitWorld) {
return ((BukkitWorld) world).getWorld();
} else {
org.bukkit.World match = Bukkit.getServer().getWorld(world.getName());
if (match != null) {
return match;
} else {
throw new IllegalArgumentException("Can't find a Bukkit world for " + world.getName());
}
}
}
/**
@ -140,7 +175,12 @@ public enum BukkitAdapter {
*/
public static Location adapt(org.bukkit.Location location) {
checkNotNull(location);
return getAdapter().adapt(location);
Vector3 position = asVector(location);
return new com.sk89q.worldedit.util.Location(
adapt(location.getWorld()),
position,
location.getYaw(),
location.getPitch());
}
/**
@ -151,7 +191,12 @@ public enum BukkitAdapter {
*/
public static org.bukkit.Location adapt(Location location) {
checkNotNull(location);
return getAdapter().adapt(location);
Vector3 position = location;
return new org.bukkit.Location(
adapt((World) location.getExtent()),
position.getX(), position.getY(), position.getZ(),
location.getYaw(),
location.getPitch());
}
/**
@ -162,7 +207,11 @@ public enum BukkitAdapter {
* @return a Bukkit location
*/
public static org.bukkit.Location adapt(org.bukkit.World world, Vector3 position) {
return getAdapter().adapt(world, position);
checkNotNull(world);
checkNotNull(position);
return new org.bukkit.Location(
world,
position.getX(), position.getY(), position.getZ());
}
/**
@ -175,7 +224,9 @@ public enum BukkitAdapter {
public static org.bukkit.Location adapt(org.bukkit.World world, BlockVector3 position) {
checkNotNull(world);
checkNotNull(position);
return getAdapter().adapt(world, position);
return new org.bukkit.Location(
world,
position.getX(), position.getY(), position.getZ());
}
/**
@ -188,7 +239,11 @@ public enum BukkitAdapter {
public static org.bukkit.Location adapt(org.bukkit.World world, Location location) {
checkNotNull(world);
checkNotNull(location);
return getAdapter().adapt(world, location);
return new org.bukkit.Location(
world,
location.getX(), location.getY(), location.getZ(),
location.getYaw(),
location.getPitch());
}
/**
@ -221,7 +276,7 @@ public enum BukkitAdapter {
*/
public static Entity adapt(org.bukkit.entity.Entity entity) {
checkNotNull(entity);
return getAdapter().adapt(entity);
return new BukkitEntity(entity);
}
/**
@ -232,7 +287,10 @@ public enum BukkitAdapter {
*/
public static Material adapt(ItemType itemType) {
checkNotNull(itemType);
return getAdapter().adapt(itemType);
if (!itemType.getId().startsWith("minecraft:")) {
throw new IllegalArgumentException("Bukkit only supports Minecraft items");
}
return Material.getMaterial(itemType.getId().substring(10).toUpperCase(Locale.ROOT));
}
/**
@ -241,8 +299,12 @@ public enum BukkitAdapter {
* @param blockType The WorldEdit BlockType
* @return The Bukkit Material
*/
public static Material adapt(@NotNull BlockType blockType) {
return getAdapter().adapt(blockType);
public static Material adapt(BlockType blockType) {
checkNotNull(blockType);
if (!blockType.getId().startsWith("minecraft:")) {
throw new IllegalArgumentException("Bukkit only supports Minecraft blocks");
}
return Material.getMaterial(blockType.getId().substring(10).toUpperCase(Locale.ROOT));
}
/**
@ -253,7 +315,7 @@ public enum BukkitAdapter {
*/
public static GameMode adapt(org.bukkit.GameMode gameMode) {
checkNotNull(gameMode);
return getAdapter().adapt(gameMode);
return GameModes.get(gameMode.name().toLowerCase(Locale.ROOT));
}
/**
@ -263,11 +325,18 @@ public enum BukkitAdapter {
* @return WorldEdit BiomeType
*/
public static BiomeType adapt(Biome biome) {
return getAdapter().adapt(biome);
return BiomeTypes.get(biome.name().toLowerCase(Locale.ROOT));
}
public static Biome adapt(BiomeType biomeType) {
return getAdapter().adapt(biomeType);
if (!biomeType.getId().startsWith("minecraft:")) {
throw new IllegalArgumentException("Bukkit only supports vanilla biomes");
}
try {
return Biome.valueOf(biomeType.getId().substring(10).toUpperCase(Locale.ROOT));
} catch (IllegalArgumentException e) {
return null;
}
}
/**
@ -277,11 +346,18 @@ public enum BukkitAdapter {
* @return WorldEdit EntityType
*/
public static EntityType adapt(org.bukkit.entity.EntityType entityType) {
return getAdapter().adapt(entityType);
final String name = entityType.getName();
if (name == null) {
return null;
}
return EntityTypes.get(name.toLowerCase(Locale.ROOT));
}
public static org.bukkit.entity.EntityType adapt(EntityType entityType) {
return getAdapter().adapt(entityType);
if (!entityType.getId().startsWith("minecraft:")) {
throw new IllegalArgumentException("Bukkit only supports vanilla entities");
}
return org.bukkit.entity.EntityType.fromName(entityType.getId().substring(10));
}
/**
@ -290,8 +366,12 @@ public enum BukkitAdapter {
* @param material The material
* @return The blocktype
*/
public static BlockType asBlockType(@NotNull Material material) {
return getAdapter().asBlockType(material);
public static BlockType asBlockType(Material material) {
checkNotNull(material);
if (!material.isBlock()) {
throw new IllegalArgumentException(material.getKey().toString() + " is not a block!");
}
return BlockTypes.get(material.getKey().toString());
}
/**
@ -302,9 +382,13 @@ public enum BukkitAdapter {
*/
public static ItemType asItemType(Material material) {
checkNotNull(material);
return getAdapter().asItemType(material);
if (!material.isItem()) {
throw new IllegalArgumentException(material.getKey().toString() + " is not an item!");
}
return ItemTypes.get(material.getKey().toString());
}
private static Map<String, BlockState> blockStateCache = new HashMap<>();
/**
* Create a WorldEdit BlockState from a Bukkit BlockData
@ -320,6 +404,8 @@ public enum BukkitAdapter {
return getAdapter().adapt(material);
}
private static Map<String, BlockData> blockDataCache = new HashMap<>();
/**
* Create a Bukkit BlockData from a WorldEdit BlockStateHolder
*
@ -339,7 +425,7 @@ public enum BukkitAdapter {
public static BlockState asBlockState(ItemStack itemStack) throws WorldEditException {
checkNotNull(itemStack);
if (itemStack.getType().isBlock()) {
return getAdapter().asBlockState(itemStack);
return adapt(itemStack.getType().createBlockData());
} else {
throw new NotABlockException();
}
@ -353,7 +439,10 @@ public enum BukkitAdapter {
*/
public static BaseItemStack adapt(ItemStack itemStack) {
checkNotNull(itemStack);
return getAdapter().adapt(itemStack);
if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) {
return WorldEditPlugin.getInstance().getBukkitImplAdapter().adapt(itemStack);
}
return new BaseItemStack(ItemTypes.get(itemStack.getType().getKey().toString()), itemStack.getAmount());
}
/**
@ -364,6 +453,9 @@ public enum BukkitAdapter {
*/
public static ItemStack adapt(BaseItemStack item) {
checkNotNull(item);
return getAdapter().adapt(item);
if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) {
return WorldEditPlugin.getInstance().getBukkitImplAdapter().adapt(item);
}
return new ItemStack(adapt(item.getType()), item.getAmount());
}
}

View File

@ -164,7 +164,7 @@ public class BukkitBlockCommandSender extends AbstractNonPlayerActor implements
@Override
public boolean isPersistent() {
return true;
return false;
}
@Override

View File

@ -35,8 +35,9 @@ import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import java.util.Map;
import java.util.OptionalInt;
import javax.annotation.Nullable;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
@ -45,11 +46,6 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.Map;
import java.util.OptionalInt;
import javax.annotation.Nullable;
/**
* An interface for adapters of various Bukkit implementations.
*/
@ -202,7 +198,6 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
* @param state The block state
* @return the internal ID of the state
*/
default OptionalInt getInternalBlockStateId(BlockState state) {
return OptionalInt.empty();
}

View File

@ -2,7 +2,6 @@ package com.sk89q.worldedit.bukkit.adapter;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.NotABlockException;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.bukkit.BukkitEntity;
import com.sk89q.worldedit.bukkit.BukkitItemStack;
@ -21,9 +20,6 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.entity.EntityType;
import com.sk89q.worldedit.world.entity.EntityTypes;
import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.gamemode.GameModes;
import com.sk89q.worldedit.world.item.ItemType;
import java.util.Locale;
import org.bukkit.Bukkit;
@ -35,17 +31,6 @@ import org.bukkit.inventory.ItemStack;
public interface IBukkitAdapter {
/**
* Checks equality between a WorldEdit BlockType and a Bukkit Material
*
* @param blockType The WorldEdit BlockType
* @param type The Bukkit Material
* @return If they are equal
*/
default boolean equals(BlockType blockType, Material type) {
return blockType == asItemType(type).getBlockType();
}
/**
* Convert any WorldEdit world into an equivalent wrapped Bukkit world.
*
@ -67,17 +52,6 @@ public interface IBukkitAdapter {
}
}
/**
* Create a WorldEdit world from a Bukkit world.
*
* @param world the Bukkit world
* @return a WorldEdit world
*/
default World adapt(org.bukkit.World world) {
checkNotNull(world);
return new BukkitWorld(world);
}
/**
* Create a Bukkit world from a WorldEdit world.
*
@ -98,38 +72,6 @@ public interface IBukkitAdapter {
}
}
/**
* Create a WorldEdit location from a Bukkit location.
*
* @param location the Bukkit location
* @return a WorldEdit location
*/
default Location adapt(org.bukkit.Location location) {
checkNotNull(location);
Vector3 position = asVector(location);
return new Location(
adapt(location.getWorld()),
position,
location.getYaw(),
location.getPitch());
}
/**
* Create a Bukkit location from a WorldEdit location.
*
* @param location the WorldEdit location
* @return a Bukkit location
*/
default org.bukkit.Location adapt(Location location) {
checkNotNull(location);
Vector3 position = location;
return new org.bukkit.Location(
adapt((World) location.getExtent()),
position.getX(), position.getY(), position.getZ(),
location.getYaw(),
location.getPitch());
}
/**
* Create a Bukkit location from a WorldEdit position with a Bukkit world.
*
@ -228,27 +170,6 @@ public interface IBukkitAdapter {
return Material.getMaterial(id);
}
/**
* Create a WorldEdit GameMode from a Bukkit one.
*
* @param gameMode Bukkit GameMode
* @return WorldEdit GameMode
*/
default GameMode adapt(org.bukkit.GameMode gameMode) {
checkNotNull(gameMode);
return GameModes.get(gameMode.name().toLowerCase(Locale.ROOT));
}
/**
* Create a WorldEdit EntityType from a Bukkit one.
*
* @param entityType Bukkit EntityType
* @return WorldEdit EntityType
*/
default EntityType adapt(org.bukkit.entity.EntityType entityType) {
return EntityTypes.get(entityType.getName().toLowerCase(Locale.ROOT));
}
default org.bukkit.entity.EntityType adapt(EntityType entityType) {
if (!entityType.getId().startsWith("minecraft:")) {
throw new IllegalArgumentException("Bukkit only supports vanilla entities");
@ -303,21 +224,6 @@ public interface IBukkitAdapter {
*/
BlockData adapt(BlockStateHolder block);
/**
* Create a WorldEdit BlockStateHolder from a Bukkit ItemStack
*
* @param itemStack The Bukkit ItemStack
* @return The WorldEdit BlockState
*/
default BlockState asBlockState(ItemStack itemStack) {
checkNotNull(itemStack);
if (itemStack.getType().isBlock()) {
return adapt(itemStack.getType().createBlockData());
} else {
throw new NotABlockException();
}
}
/**
* Create a WorldEdit BaseItemStack from a Bukkit ItemStack
*