1.13 shizzle

This commit is contained in:
sauilitired
2018-12-17 20:57:21 +01:00
parent 820710721e
commit fb7bcef05f
40 changed files with 1487 additions and 2332 deletions

View File

@ -1,53 +0,0 @@
package com.github.intellectualsites.plotsquared.plot.commands;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.config.C;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.BO3Handler;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.Permissions;
@CommandDeclaration(command = "bo3", aliases = {
"bo2"}, description = "Mark a plot as done", permission = "plots.bo3", category = CommandCategory.SCHEMATIC, requiredType = RequiredType.NONE)
public class BO3 extends SubCommand {
public void noArgs(PlotPlayer player) {
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot bo3 export [category] [alias] [-r]");
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot bo3 import <file>");
}
@Override public boolean onCommand(PlotPlayer player, String[] args) {
Location loc = player.getLocation();
Plot plot = loc.getPlotAbs();
if (plot == null || !plot.hasOwner()) {
return !sendMessage(player, C.NOT_IN_PLOT);
}
if (!plot.isOwner(player.getUUID()) && !Permissions
.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_BO3)) {
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
return false;
}
if (args.length == 0) {
noArgs(player);
return false;
}
switch (args[0].toLowerCase()) {
case "output":
case "save":
case "export":
return BO3Handler.saveBO3(player, plot);
case "paste":
case "load":
case "import":
case "input":
// TODO NOT IMPLEMENTED YET
MainUtil.sendMessage(player, "NOT IMPLEMENTED YET!!!");
return false;
default:
noArgs(player);
return false;
}
}
}

View File

@ -65,27 +65,6 @@ public class Download extends SubCommand {
});
}
});
} else if (args.length == 1 && StringMan
.isEqualIgnoreCaseToAny(args[0], "bo3", "bo2", "b03", "b02")) {
if (!Permissions.hasPermission(player, C.PERMISSION_DOWNLOAD_BO3)) {
C.NO_PERMISSION.send(player, C.PERMISSION_DOWNLOAD_BO3);
return false;
}
if (plot.getVolume() > 128d * 128d * 256) {
C.SCHEMATIC_TOO_LARGE.send(player);
return false;
}
plot.addRunning();
BO3Handler.upload(plot, null, null, new RunnableVal<URL>() {
@Override public void run(URL url) {
plot.removeRunning();
if (url == null) {
MainUtil.sendMessage(player, C.GENERATING_LINK_FAILED);
return;
}
MainUtil.sendMessage(player, url.toString());
}
});
} else if (args.length == 1 && StringMan
.isEqualIgnoreCaseToAny(args[0], "mcr", "world", "mca")) {
if (!Permissions.hasPermission(player, C.PERMISSION_DOWNLOAD_WORLD)) {

View File

@ -88,7 +88,6 @@ import java.util.Arrays;
new Trim();
new Done();
new Continue();
new BO3();
new Middle();
new Grant();
// Set commands

View File

@ -25,11 +25,10 @@ public class Music extends SubCommand {
if (item == null) {
return true;
}
int id = item.id == 7 ? 0 : item.id;
if (id == 0) {
if (item.getPlotBlock().equalsAny(7, "bedrock")) {
plot.removeFlag(Flags.MUSIC);
} else {
plot.setFlag(Flags.MUSIC, id);
plot.setFlag(Flags.MUSIC, item.getPlotBlock().getRawId());
}
return false;
}

View File

@ -77,7 +77,7 @@ public class Set extends SubCommand {
}
}
return false;
} else if (!allowUnsafe && (block.id != 0 && !WorldUtil.IMP
} else if (!allowUnsafe && (!block.isAir() && !WorldUtil.IMP
.isBlockSolid(block))) {
MainUtil
.sendMessage(player, C.NOT_ALLOWED_BLOCK, block.toString());
@ -86,7 +86,7 @@ public class Set extends SubCommand {
}
if (!allowUnsafe) {
for (PlotBlock block : blocks) {
if (block.id != 0 && !WorldUtil.IMP.isBlockSolid(block)) {
if (!block.isAir() && !WorldUtil.IMP.isBlockSolid(block)) {
MainUtil.sendMessage(player, C.NOT_ALLOWED_BLOCK,
block.toString());
return false;

View File

@ -46,7 +46,7 @@ public class ClassicPlotManager extends SquarePlotManager {
@Override public boolean unclaimPlot(PlotArea plotArea, Plot plot, Runnable whenDone) {
ClassicPlotWorld dpw = (ClassicPlotWorld) plotArea;
setWallFilling(dpw, plot.getId(), new PlotBlock[] {dpw.WALL_FILLING});
if (dpw.WALL_BLOCK.id != 0 || !dpw.WALL_BLOCK.equals(dpw.CLAIMED_WALL_BLOCK)) {
if (!dpw.WALL_BLOCK.isAir() || !dpw.WALL_BLOCK.equals(dpw.CLAIMED_WALL_BLOCK)) {
setWall(dpw, plot.getId(), new PlotBlock[] {dpw.WALL_BLOCK});
}
GlobalBlockQueue.IMP.addTask(whenDone);
@ -431,7 +431,7 @@ public class ClassicPlotManager extends SquarePlotManager {
@Override public boolean finishPlotMerge(PlotArea plotArea, ArrayList<PlotId> plotIds) {
PlotBlock block = ((ClassicPlotWorld) plotArea).CLAIMED_WALL_BLOCK;
PlotBlock unclaim = ((ClassicPlotWorld) plotArea).WALL_BLOCK;
if (block.id != 0 || !block.equals(unclaim)) {
if (!block.isAir() || !block.equals(unclaim)) {
for (PlotId id : plotIds) {
setWall(plotArea, id, new PlotBlock[] {block});
}
@ -443,7 +443,7 @@ public class ClassicPlotManager extends SquarePlotManager {
PlotBlock block = ((ClassicPlotWorld) plotArea).CLAIMED_WALL_BLOCK;
PlotBlock unclaim = ((ClassicPlotWorld) plotArea).WALL_BLOCK;
for (PlotId id : plotIds) {
if (block.id != 0 || !block.equals(unclaim)) {
if (block.isAir() || !block.equals(unclaim)) {
setWall(plotArea, id, new PlotBlock[] {block});
}
}
@ -461,7 +461,7 @@ public class ClassicPlotManager extends SquarePlotManager {
@Override public boolean claimPlot(PlotArea plotArea, Plot plot) {
PlotBlock unclaim = ((ClassicPlotWorld) plotArea).WALL_BLOCK;
PlotBlock claim = ((ClassicPlotWorld) plotArea).CLAIMED_WALL_BLOCK;
if (claim.id != 0 || !claim.equals(unclaim)) {
if (!claim.isAir() || !claim.equals(unclaim)) {
setWall(plotArea, plot.getId(), new PlotBlock[] {claim});
}
return true;

View File

@ -12,8 +12,8 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld {
public int ROAD_HEIGHT = 64;
public int PLOT_HEIGHT = 64;
public int WALL_HEIGHT = 64;
public PlotBlock[] MAIN_BLOCK = new PlotBlock[] {PlotBlock.get((short) 1, (byte) 0)};
public PlotBlock[] TOP_BLOCK = new PlotBlock[] {PlotBlock.get((short) 2, (byte) 0)};
public PlotBlock[] MAIN_BLOCK = new PlotBlock[] {PlotBlock.get("stone")};
public PlotBlock[] TOP_BLOCK = new PlotBlock[] {PlotBlock.get("grass")};
public PlotBlock WALL_BLOCK = PlotBlock.get((short) 44, (byte) 0);
public PlotBlock CLAIMED_WALL_BLOCK = PlotBlock.get((short) 44, (byte) 1);
public PlotBlock WALL_FILLING = PlotBlock.get((short) 1, (byte) 0);
@ -45,12 +45,14 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld {
new ConfigurationNode("wall.block", this.WALL_BLOCK, "Top wall block",
Configuration.BLOCK),
new ConfigurationNode("wall.block_claimed", this.CLAIMED_WALL_BLOCK,
"Wall block (claimed)", Configuration.BLOCK),
"Wall block (claimed)",
Configuration.BLOCK),
new ConfigurationNode("road.width", this.ROAD_WIDTH, "Road width",
Configuration.INTEGER),
new ConfigurationNode("road.height", this.ROAD_HEIGHT, "Road height",
Configuration.INTEGER),
new ConfigurationNode("road.block", this.ROAD_BLOCK, "Road block", Configuration.BLOCK),
new ConfigurationNode("road.block", this.ROAD_BLOCK, "Road block",
Configuration.BLOCK),
new ConfigurationNode("wall.filling", this.WALL_FILLING, "Wall filling block",
Configuration.BLOCK),
new ConfigurationNode("wall.height", this.WALL_HEIGHT, "Wall height",

View File

@ -277,7 +277,7 @@ public class HybridPlotWorld extends ClassicPlotWorld {
}
this.ROAD_SCHEMATIC_ENABLED = true;
// Do not populate road if using schematic population
this.ROAD_BLOCK = PlotBlock.get(this.ROAD_BLOCK.id, (byte) 0);
this.ROAD_BLOCK = PlotBlock.getEmptyData(this.ROAD_BLOCK); // PlotBlock.get(this.ROAD_BLOCK.id, (byte) 0);
short[] ids1 = schematic1.getIds();
byte[] datas1 = schematic1.getDatas();

View File

@ -6,10 +6,7 @@ import com.github.intellectualsites.plotsquared.plot.config.C;
import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.object.*;
import com.github.intellectualsites.plotsquared.plot.util.ChunkManager;
import com.github.intellectualsites.plotsquared.plot.util.MathMan;
import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler;
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
import com.github.intellectualsites.plotsquared.plot.util.*;
import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue;
import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue;
import com.github.intellectualsites.plotsquared.plot.util.expiry.PlotAnalysis;
@ -100,7 +97,7 @@ public abstract class HybridUtils {
PlotBlock block = queue.getBlock(x, y, z);
boolean same = false;
for (PlotBlock p : blocks) {
if (block.id == p.id) {
if (WorldUtil.IMP.isBlockSame(block, p)) {
same = true;
break;
}
@ -333,7 +330,7 @@ public abstract class HybridUtils {
for (int y = sy; y <= pm.getWorldHeight(); y++) {
if (y > ey) {
PlotBlock block = queue.getBlock(x, y, z);
if (block.id != 0) {
if (!block.isAir()) {
ey = y;
}
}

View File

@ -1,75 +0,0 @@
package com.github.intellectualsites.plotsquared.plot.object;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import java.io.File;
public class BO3 {
private final ChunkLoc chunk;
private final String world;
private final StringBuilder blocks;
private final StringBuilder children;
private final String name;
public BO3(String name, String world, ChunkLoc loc) {
this.world = world;
this.name = name;
this.chunk = loc;
this.blocks = new StringBuilder();
this.children = new StringBuilder();
}
public void addChild(BO3 child) {
ChunkLoc childloc = child.getLoc();
this.children.append("Branch(").append(childloc.x - this.chunk.x).append(",0,")
.append(childloc.z - this.chunk.z).append(',').append(this.name).append('_')
.append(childloc.x).append('_').append(childloc.z).append(",NORTH,100)\n");
}
public ChunkLoc getLoc() {
return this.chunk;
}
public String getWorld() {
return this.world;
}
public String getName() {
return this.name;
}
public void addBlock(int x, int y, int z, PlotBlock block) {
if (block.data == 0) {
// Block(-3,1,-2,AIR)
this.blocks.append("Block(").append(x).append(',').append(y).append(',').append(z)
.append(',').append(block.id).append(")\n");
} else {
this.blocks.append("Block(").append(x).append(',').append(y).append(',').append(z)
.append(',').append(block.id).append(':').append(block.data).append(")\n");
}
}
public String getBlocks() {
return this.blocks.toString();
}
public String getChildren() {
return this.children.toString();
}
public File getFile() {
return MainUtil.getFile(PlotSquared.get().IMP.getDirectory(),
Settings.Paths.BO3 + File.separator + getWorld() + File.separator + getFilename());
}
public String getFilename() {
if (this.chunk.x == 0 && this.chunk.z == 0) {
return this.name + ".bo3";
} else {
return this.name + ("_" + this.chunk.x + '_' + this.chunk.z) + ".bo3";
}
}
}

View File

@ -2,9 +2,9 @@ package com.github.intellectualsites.plotsquared.plot.object;
public abstract class LazyBlock {
public abstract PlotBlock getPlotBlock();
public abstract StringPlotBlock getPlotBlock();
public int getId() {
return getPlotBlock().id;
public String getId() {
return getPlotBlock().getItemId();
}
}

View File

@ -0,0 +1,62 @@
package com.github.intellectualsites.plotsquared.plot.object;
import lombok.Getter;
public class LegacyPlotBlock extends PlotBlock {
public static final PlotBlock EVERYTHING = new LegacyPlotBlock((short) 0, (byte) 0);
public static final PlotBlock[] CACHE = new PlotBlock[65535];
static {
for (int i = 0; i < 65535; i++) {
short id = (short) (i >> 4);
byte data = (byte) (i & 15);
CACHE[i] = new LegacyPlotBlock(id, data);
}
}
@Getter
public final short id;
@Getter
public final byte data;
public LegacyPlotBlock(short id, byte data) {
this.id = id;
this.data = data;
}
@Override public Object getRawId() {
return this.id;
}
@Override public boolean isAir() {
return this.id == 0;
}
@Override public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
LegacyPlotBlock other = (LegacyPlotBlock) obj;
return (this.id == other.id) && ((this.data == other.data) || (this.data == -1) || (
other.data == -1));
}
@Override public int hashCode() {
return this.id;
}
@Override public String toString() {
if (this.data == -1) {
return this.id + "";
}
return this.id + ":" + this.data;
}
}

View File

@ -1203,7 +1203,7 @@ public class Plot {
bot.getZ() + home.z, home.yaw, home.pitch);
if (!isLoaded())
return loc;
if (WorldUtil.IMP.getBlock(loc).id != 0) {
if (!WorldUtil.IMP.getBlock(loc).isAir()) {
loc.setY(Math.max(
1 + WorldUtil.IMP.getHighestBlock(this.getWorldName(), loc.getX(), loc.getZ()),
bot.getY()));
@ -1848,22 +1848,6 @@ public class Plot {
});
}
/**
* Export the plot as a BO3 object<br>
* - bedrock, floor and main block are ignored in their respective sections
* - air is ignored
* - The center is considered to be on top of the plot in the center
*
* @param whenDone value will be false if exporting fails
*/
public void exportBO3(RunnableVal<Boolean> whenDone) {
boolean result = BO3Handler.saveBO3(this);
if (whenDone != null) {
whenDone.value = result;
}
TaskManager.runTask(whenDone);
}
/**
* Upload the plot as a schematic to the configured web interface.
*
@ -1889,18 +1873,6 @@ public class Plot {
WorldUtil.IMP.upload(this, null, null, whenDone);
}
/**
* Upload this plot as a BO3<br>
* - May not work on non default generator<br>
* - BO3 includes flags/ignores plot main/floor block<br>
*
* @param whenDone
* @see BO3Handler
*/
public void uploadBO3(RunnableVal<URL> whenDone) {
BO3Handler.upload(this, null, null, whenDone);
}
@Override public boolean equals(Object obj) {
if (this == obj) {
return true;

View File

@ -1,26 +1,26 @@
package com.github.intellectualsites.plotsquared.plot.object;
import com.github.intellectualsites.plotsquared.plot.config.Settings;
import lombok.NonNull;
public class PlotBlock {
import java.util.Collection;
public static final PlotBlock EVERYTHING = new PlotBlock((short) 0, (byte) 0);
private static final PlotBlock[] CACHE = new PlotBlock[65535];
public abstract class PlotBlock {
static {
for (int i = 0; i < 65535; i++) {
short id = (short) (i >> 4);
byte data = (byte) (i & 15);
CACHE[i] = new PlotBlock(id, data);
}
public static boolean isEverything(@NonNull final PlotBlock block) {
return block.equals(LegacyPlotBlock.EVERYTHING) || block.equals(StringPlotBlock.EVERYTHING);
}
public final short id;
public final byte data;
public static boolean containsEverything(@NonNull final Collection<PlotBlock> blocks) {
for (final PlotBlock block : blocks) {
if (isEverything(block)) {
return true;
}
}
return false;
}
public PlotBlock(short id, byte data) {
this.id = id;
this.data = data;
protected PlotBlock() {
}
public static PlotBlock get(char combinedId) {
@ -34,35 +34,43 @@ public class PlotBlock {
}
}
public abstract boolean isAir();
public static StringPlotBlock get(@NonNull final String itemId) {
if (Settings.Enabled_Components.BLOCK_CACHE) {
return StringPlotBlock.getOrAdd(itemId);
}
return new StringPlotBlock(itemId);
}
public static PlotBlock get(int id, int data) {
return Settings.Enabled_Components.BLOCK_CACHE && data > 0 ?
CACHE[(id << 4) + data] :
new PlotBlock((short) id, (byte) data);
LegacyPlotBlock.CACHE[(id << 4) + data] :
new LegacyPlotBlock((short) id, (byte) data);
}
@Override public boolean equals(Object obj) {
if (this == obj) {
return true;
public static PlotBlock getEmptyData(@NonNull final PlotBlock plotBlock) {
if (plotBlock instanceof StringPlotBlock) {
return plotBlock;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
PlotBlock other = (PlotBlock) obj;
return (this.id == other.id) && ((this.data == other.data) || (this.data == -1) || (
other.data == -1));
return get(((LegacyPlotBlock) plotBlock).getId(), (byte) 0);
}
@Override public int hashCode() {
return this.id;
public final boolean equalsAny(final int id, @NonNull final String stringId) {
if (this instanceof StringPlotBlock) {
final StringPlotBlock stringPlotBlock = (StringPlotBlock) this;
return stringPlotBlock.idEquals(stringId);
}
final LegacyPlotBlock legacyPlotBlock = (LegacyPlotBlock) this;
return legacyPlotBlock.id == id;
}
@Override public String toString() {
if (this.data == -1) {
return this.id + "";
}
return this.id + ":" + this.data;
}
@Override public abstract boolean equals(Object obj);
@Override public abstract int hashCode();
@Override public abstract String toString();
public abstract Object getRawId();
}

View File

@ -2,10 +2,13 @@ package com.github.intellectualsites.plotsquared.plot.object;
import com.github.intellectualsites.plotsquared.plot.util.StringComparison;
import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
import lombok.Getter;
public class PlotItemStack {
public final int id;
public final short data;
// public final int id;
// public final short data;
@Getter
private final PlotBlock plotBlock;
public final int amount;
public final String name;
public final String[] lore;
@ -13,19 +16,16 @@ public class PlotItemStack {
@Deprecated
public PlotItemStack(final int id, final short data, final int amount, final String name,
final String... lore) {
this.id = id;
this.data = data;
this.amount = amount;
this.name = name;
this.lore = lore;
this.plotBlock = PlotBlock.get(id, data);
}
public PlotItemStack(final String id, final int amount, final String name,
final String... lore) {
StringComparison<PlotBlock>.ComparisonResult match = WorldUtil.IMP.getClosestBlock(id);
final PlotBlock block = match.best;
this.id = block.id;
data = block.data;
this.plotBlock = match.best;
this.amount = amount;
this.name = name;
this.lore = lore;

View File

@ -0,0 +1,91 @@
package com.github.intellectualsites.plotsquared.plot.object;
import lombok.Getter;
import lombok.NonNull;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
public class StringPlotBlock extends PlotBlock {
public static final PlotBlock EVERYTHING = new StringPlotBlock("");
private static final Map<String, StringPlotBlock> STRING_PLOT_BLOCK_CACHE = new HashMap<>();
public static StringPlotBlock getOrAdd(@NonNull final String itemId) {
// final String id = itemId.toLowerCase(Locale.ENGLISH);
StringPlotBlock plotBlock = STRING_PLOT_BLOCK_CACHE.get(itemId);
if (plotBlock == null) {
plotBlock = new StringPlotBlock(itemId);
STRING_PLOT_BLOCK_CACHE.put(itemId, plotBlock);
}
return plotBlock;
}
@Getter
private final String nameSpace;
@Getter
private final String itemId;
private boolean isForeign = false;
public StringPlotBlock(@NonNull final String nameSpace, @NonNull final String itemId) {
this.nameSpace = nameSpace.toLowerCase(Locale.ENGLISH);
this.itemId = itemId.toLowerCase(Locale.ENGLISH);
this.determineForeign();
}
public StringPlotBlock(@NonNull final String itemId) {
if (itemId.contains(":")) {
final String[] parts = itemId.split(":");
if (parts.length < 2) {
throw new IllegalArgumentException(String.format("Cannot parse \"%s\"", itemId));
}
this.nameSpace = parts[0].toLowerCase(Locale.ENGLISH);
this.itemId = parts[1].toLowerCase(Locale.ENGLISH);
} else {
this.nameSpace = "minecraft";
this.itemId = itemId.toLowerCase(Locale.ENGLISH);
}
this.determineForeign();
}
private void determineForeign() {
this.isForeign = !this.nameSpace.equals("minecraft");
}
@Override public String toString() {
return this.isForeign ? String.format("%s:%s", nameSpace, itemId) : itemId;
}
@Override public boolean isAir() {
return this.itemId.isEmpty() || this.itemId.equalsIgnoreCase("air");
}
@Override public int hashCode() {
return this.toString().hashCode();
}
public boolean idEquals(@NonNull final String id) {
return id.equalsIgnoreCase(this.itemId);
}
@Override public Object getRawId() {
return this.getItemId();
}
@Override public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
StringPlotBlock other = (StringPlotBlock) obj;
return other.nameSpace.equals(this.nameSpace) && other.itemId.equals(this.itemId);
}
}

View File

@ -1,297 +0,0 @@
package com.github.intellectualsites.plotsquared.plot.util;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
import com.github.intellectualsites.plotsquared.plot.generator.ClassicPlotWorld;
import com.github.intellectualsites.plotsquared.plot.object.*;
import java.io.*;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.*;
import java.util.Map.Entry;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class BO3Handler {
/**
* @param plot
* @return if successfully exported
* @see #saveBO3(PlotPlayer, Plot, RunnableVal)
*/
public static boolean saveBO3(Plot plot) {
return saveBO3(null, plot);
}
public static boolean saveBO3(PlotPlayer player, final Plot plot) {
return saveBO3(player, plot, new RunnableVal<BO3>() {
@Override public void run(BO3 bo3) {
save(plot, bo3);
}
});
}
public static boolean contains(PlotBlock[] blocks, PlotBlock block) {
for (PlotBlock item : blocks) {
if (item.equals(block)) {
return true;
}
}
return false;
}
/**
* Save a plot as a BO3 file.
* - Use null for the player object if no player is applicable
*
* @param player
* @param plot
* @return
*/
public static boolean saveBO3(PlotPlayer player, Plot plot, RunnableVal<BO3> saveTask) {
if (saveTask == null) {
throw new IllegalArgumentException("Save task cannot be null!");
}
PlotArea plotworld = plot.getArea();
if (!(plotworld instanceof ClassicPlotWorld) || plotworld.TYPE != 0) {
MainUtil.sendMessage(player, "BO3 exporting only supports type 0 classic generation.");
return false;
}
String alias = plot.toString();
Location[] corners = plot.getCorners();
Location bot = corners[0];
Location top = corners[1];
ClassicPlotWorld cpw = (ClassicPlotWorld) plotworld;
int height = cpw.PLOT_HEIGHT;
int cx = MathMan.average(bot.getX(), top.getX());
int cz = MathMan.average(bot.getZ(), top.getZ());
HashMap<ChunkLoc, BO3> map = new HashMap<>();
HashSet<RegionWrapper> regions = plot.getRegions();
ArrayList<ChunkLoc> chunks = new ArrayList<>();
for (RegionWrapper region : regions) {
for (int x = region.minX >> 4; x <= region.maxX >> 4; x++) {
for (int z = region.minZ >> 4; z <= region.maxZ >> 4; z++) {
chunks.add(new ChunkLoc(x, z));
}
}
}
for (ChunkLoc loc : chunks) {
ChunkManager.manager.loadChunk(plot.getWorldName(), loc, false);
}
boolean content = false;
for (RegionWrapper region : regions) {
Location pos1 =
new Location(plotworld.worldname, region.minX, region.minY, region.minZ);
Location pos2 =
new Location(plotworld.worldname, region.maxX, region.maxY, region.maxZ);
for (int x = pos1.getX(); x <= pos2.getX(); x++) {
int X = x + 7 - cx >> 4;
int xx = (x - cx) % 16;
for (int z = pos1.getZ(); z <= pos2.getZ(); z++) {
int Z = z + 7 - cz >> 4;
int zz = (z - cz) % 16;
ChunkLoc loc = new ChunkLoc(X, Z);
BO3 bo3 = map.get(loc);
for (int y = 1; y < height; y++) {
PlotBlock block =
WorldUtil.IMP.getBlock(new Location(plot.getWorldName(), x, y, z));
if (!contains(cpw.MAIN_BLOCK, block)) {
if (bo3 == null) {
bo3 = new BO3(alias, plotworld.worldname, loc);
map.put(loc, bo3);
content = true;
}
bo3.addBlock(xx, y - height - 1, zz, block);
}
}
PlotBlock floor =
WorldUtil.IMP.getBlock(new Location(plot.getWorldName(), x, height, z));
if (!contains(cpw.TOP_BLOCK, floor)) {
if (bo3 == null) {
bo3 = new BO3(alias, plotworld.worldname, loc);
map.put(loc, bo3);
content = true;
}
bo3.addBlock(xx, -1, zz, floor);
}
for (int y = height + 1; y < 256; y++) {
PlotBlock block =
WorldUtil.IMP.getBlock(new Location(plot.getWorldName(), x, y, z));
if (block.id != 0) {
if (bo3 == null) {
bo3 = new BO3(alias, plotworld.worldname, loc);
map.put(loc, bo3);
content = true;
}
bo3.addBlock(xx, y - height - 1, zz, block);
}
}
}
}
}
if (!content) {
MainUtil.sendMessage(player, "No content found!");
return false;
}
for (Entry<ChunkLoc, BO3> entry : map.entrySet()) {
ChunkLoc chunk = entry.getKey();
BO3 bo3 = entry.getValue();
if (chunk.x == 0 && chunk.z == 0) {
continue;
}
int x = chunk.x;
int z = chunk.z;
if (Math.abs(chunk.x) > Math.abs(chunk.z)) {
x += chunk.x > 0 ? -1 : 1;
} else {
z += chunk.z > 0 ? -1 : 1;
}
ChunkLoc parentLoc = new ChunkLoc(x, z);
if (!map.containsKey(parentLoc)) {
parentLoc = null;
for (Entry<ChunkLoc, BO3> entry2 : map.entrySet()) {
ChunkLoc other = entry2.getKey();
if (other.x == chunk.x - 1 && other.z == chunk.z
|| other.z == chunk.z - 1 && other.x == chunk.x) {
parentLoc = other;
}
}
if (parentLoc == null) {
MainUtil.sendMessage(player,
"Exporting BO3 cancelled due to detached chunk: " + chunk
+ " - Make sure you only have one object per plot");
return false;
}
}
map.get(parentLoc).addChild(bo3);
}
for (Entry<ChunkLoc, BO3> entry : map.entrySet()) {
saveTask.run(entry.getValue());
}
MainUtil.sendMessage(player, "BO3 exporting was successful!");
return true;
}
public static void upload(final Plot plot, UUID uuid, String file, RunnableVal<URL> whenDone) {
if (plot == null) {
throw new IllegalArgumentException("Arguments may not be null!");
}
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (final ZipOutputStream zos = new ZipOutputStream(baos)) {
saveBO3(null, plot, new RunnableVal<BO3>() {
@Override public void run(BO3 bo3) {
try {
ZipEntry ze = new ZipEntry(bo3.getFilename());
zos.putNextEntry(ze);
write(zos, plot, bo3);
zos.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
});
} catch (IOException e) {
e.printStackTrace();
whenDone.run();
return;
}
MainUtil.upload(uuid, file, "zip", new RunnableVal<OutputStream>() {
@Override public void run(OutputStream output) {
try {
output.write(baos.toByteArray());
baos.flush();
baos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}, whenDone);
}
public static void write(OutputStream stream, Plot plot, BO3 bo3) throws IOException {
File base = getBaseFile(bo3.getWorld());
List<String> lines = Files.readAllLines(base.toPath(), StandardCharsets.UTF_8);
for (int i = 0; i < lines.size(); i++) {
String line = lines.get(i).trim();
String result = StringMan
.replaceAll(line, "%owner%", MainUtil.getName(plot.owner), "%alias%",
plot.toString(), "%blocks%", bo3.getBlocks(), "%branches%", bo3.getChildren(),
"%flags%", StringMan.join(FlagManager.getPlotFlags(plot).values(), ","));
if (!StringMan.isEqual(result, line)) {
lines.set(i, result);
}
}
stream.write(StringMan.join(lines, System.getProperty("line.separator")).getBytes());
}
public static boolean save(Plot plot, BO3 bo3) {
try {
File bo3File = bo3.getFile();
File parent = bo3File.getParentFile();
if (parent != null) {
parent.mkdirs();
}
bo3File.createNewFile();
bo3File.getParentFile().mkdirs();
try (FileOutputStream fos = new FileOutputStream(bo3File)) {
write(fos, plot, bo3);
}
} catch (IOException e) {
e.printStackTrace();
return false;
}
File base = getBaseFile(plot.getWorldName());
try {
List<String> lines = Files.readAllLines(base.toPath(), StandardCharsets.UTF_8);
for (int i = 0; i < lines.size(); i++) {
String line = lines.get(i).trim();
String result = StringMan
.replaceAll(line, "%owner%", MainUtil.getName(plot.owner), "%alias%",
plot.toString(), "%blocks%", bo3.getBlocks(), "%branches%",
bo3.getChildren(), "%flags%",
StringMan.join(FlagManager.getPlotFlags(plot).values(), ","));
if (!StringMan.isEqual(result, line)) {
lines.set(i, result);
}
}
File bo3File;
if (bo3.getLoc().x == 0 && bo3.getLoc().z == 0) {
bo3File = MainUtil.getFile(base.getParentFile(), bo3.getName() + ".bo3");
} else {
bo3File = MainUtil.getFile(base.getParentFile(),
bo3.getName() + '_' + bo3.getLoc().x + '_' + bo3.getLoc().z + ".bo3");
}
bo3File.createNewFile();
Files.write(bo3File.toPath(),
StringMan.join(lines, System.getProperty("line.separator")).getBytes(),
StandardOpenOption.WRITE);
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
public static File getBaseFile(String category) {
File base = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(),
Settings.Paths.BO3 + File.separator + category + File.separator + "base.yml");
if (!base.exists()) {
PlotSquared.get().copyFile("base.yml", Settings.Paths.BO3 + File.separator + category);
}
return base;
}
}

View File

@ -134,16 +134,14 @@ public abstract class EventUtil {
Optional<HashSet<PlotBlock>> use = plot.getFlag(Flags.USE);
if (use.isPresent()) {
HashSet<PlotBlock> value = use.get();
if (value.contains(PlotBlock.EVERYTHING) || value
.contains(block.getPlotBlock())) {
if (PlotBlock.containsEverything(value) || value.contains(block.getPlotBlock())) {
return true;
}
}
Optional<HashSet<PlotBlock>> destroy = plot.getFlag(Flags.BREAK);
if (destroy.isPresent()) {
HashSet<PlotBlock> value = destroy.get();
if (value.contains(PlotBlock.EVERYTHING) || value
.contains(block.getPlotBlock())) {
if (PlotBlock.containsEverything(value) || value.contains(block.getPlotBlock())) {
return true;
}
}
@ -220,7 +218,7 @@ public abstract class EventUtil {
} else {
value = null;
}
if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value
if (value == null || !PlotBlock.containsEverything(value) && !value
.contains(block.getPlotBlock())) {
return Permissions
.hasPermission(player, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), false) || !(
@ -245,7 +243,7 @@ public abstract class EventUtil {
} else {
value = null;
}
if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value
if (value == null || !PlotBlock.containsEverything(value) && !value
.contains(block.getPlotBlock())) {
if (Permissions
.hasPermission(player, C.PERMISSION_ADMIN_BUILD_OTHER.s(), false)) {
@ -275,7 +273,7 @@ public abstract class EventUtil {
} else {
value = null;
}
if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value
if (value == null || !PlotBlock.containsEverything(value) && !value
.contains(block.getPlotBlock())) {
if (Permissions
.hasPermission(player, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), false)) {
@ -305,7 +303,7 @@ public abstract class EventUtil {
} else {
value = null;
}
if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value
if (value == null || !PlotBlock.containsEverything(value) && !value
.contains(block.getPlotBlock())) {
if (Permissions
.hasPermission(player, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), false)) {
@ -336,7 +334,7 @@ public abstract class EventUtil {
} else {
value = null;
}
if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value
if (value == null || !PlotBlock.containsEverything(value) && !value
.contains(block.getPlotBlock())) {
if (Permissions
.hasPermission(player, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), false)) {
@ -367,7 +365,7 @@ public abstract class EventUtil {
} else {
value = null;
}
if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value
if (value == null || !PlotBlock.containsEverything(value) && !value
.contains(block.getPlotBlock())) {
if (Permissions
.hasPermission(player, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), false)) {
@ -398,7 +396,7 @@ public abstract class EventUtil {
} else {
value = null;
}
if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value
if (value == null || !PlotBlock.containsEverything(value) && !value
.contains(block.getPlotBlock())) {
if (Permissions
.hasPermission(player, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), false)) {
@ -431,7 +429,7 @@ public abstract class EventUtil {
} else {
value = null;
}
if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value
if (value == null || !PlotBlock.containsEverything(value) && !value
.contains(block.getPlotBlock())) {
if (Permissions
.hasPermission(player, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), false)) {
@ -463,7 +461,7 @@ public abstract class EventUtil {
} else {
value = null;
}
if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value
if (value == null || !PlotBlock.containsEverything(value) && !value
.contains(block.getPlotBlock())) {
if (Permissions
.hasPermission(player, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), false)) {

View File

@ -142,4 +142,6 @@ public abstract class WorldUtil {
}
return null;
}
public abstract boolean isBlockSame(PlotBlock block1, PlotBlock block2);
}

View File

@ -5,6 +5,7 @@ import com.github.intellectualsites.plotsquared.plot.object.RunnableVal;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.MathMan;
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
import lombok.NonNull;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedDeque;
@ -84,6 +85,33 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
this.modified = modified;
}
@Override public boolean setBlock(int x, int y, int z, String id) {
if ((y > 255) || (y < 0)) {
return false;
}
int cx = x >> 4;
int cz = z >> 4;
if (cx != lastX || cz != lastZ) {
lastX = cx;
lastZ = cz;
long pair = (long) (cx) << 32 | (cz) & 0xFFFFFFFFL;
lastWrappedChunk = this.blocks.get(pair);
if (lastWrappedChunk == null) {
lastWrappedChunk = this.getLocalChunk(x >> 4, z >> 4);
lastWrappedChunk.setBlock(x & 15, y, z & 15, id);
LocalChunk previous = this.blocks.put(pair, lastWrappedChunk);
if (previous == null) {
chunks.add(lastWrappedChunk);
return true;
}
this.blocks.put(pair, previous);
lastWrappedChunk = previous;
}
}
lastWrappedChunk.setBlock(x & 15, y, z & 15, id);
return true;
}
@Override public final boolean setBlock(int x, int y, int z, int id, int data) {
if ((y > 255) || (y < 0)) {
return false;
@ -211,6 +239,18 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
}
}
public void fillCuboid(int x1, int x2, int y1, int y2, int z1, int z2, String id) {
for (int x = x1; x <= x2; x++) {
for (int y = y1; y <= y2; y++) {
for (int z = z1; z <= z2; z++) {
setBlock(x, y, z, id);
}
}
}
}
public abstract void setBlock(final int x, final int y, final int z, final String id);
public abstract void setBlock(final int x, final int y, final int z, final int id,
final int data);
@ -241,20 +281,28 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
blocks = new PlotBlock[16][];
}
public void setBlock(final int x, final int y, final int z, final int id, final int data) {
PlotBlock block = PlotBlock.get(id, data);
int i = MainUtil.CACHE_I[y][x][z];
int j = MainUtil.CACHE_J[y][x][z];
@Override public void setBlock(final int x, final int y, final int z, @NonNull final String id) {
final PlotBlock block = PlotBlock.get(id);
this.setInternal(x, y, z, block);
}
private void setInternal(final int x, final int y, final int z, final PlotBlock plotBlock) {
final int i = MainUtil.CACHE_I[y][x][z];
final int j = MainUtil.CACHE_J[y][x][z];
PlotBlock[] array = blocks[i];
if (array == null) {
array = (blocks[i] = new PlotBlock[4096]);
}
array[j] = block;
array[j] = plotBlock;
}
public void setBlock(final int x, final int y, final int z, final int id, final int data) {
final PlotBlock block = PlotBlock.get(id, data);
this.setInternal(x, y, z, block);
}
}
public class CharLocalChunk extends LocalChunk<char[]> {
/* public class CharLocalChunk extends LocalChunk<char[]> {
public CharLocalChunk(BasicLocalBlockQueue parent, int x, int z) {
super(parent, x, z);
@ -271,5 +319,5 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
}
array[j] = (char) ((block.id << 4) + block.data);
}
}
} */
}

View File

@ -57,6 +57,10 @@ public class DelegateLocalBlockQueue extends LocalBlockQueue {
}
}
@Override public boolean setBlock(int x, int y, int z, String id) {
return parent.setBlock(x, y, z, id);
}
@Override public boolean setBlock(int x, int y, int z, int id, int data) {
return parent.setBlock(x, y, z, id, data);
}

View File

@ -6,6 +6,7 @@ import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler;
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
import lombok.NonNull;
import java.util.Map;
@ -43,8 +44,16 @@ public abstract class LocalBlockQueue {
return setBlock(x, y, z, id, 0);
}
public final boolean setBlock(int x, int y, int z, PlotBlock block) {
return setBlock(x, y, z, block.id, block.data);
public abstract boolean setBlock(final int x, final int y, final int z, final String id);
public final boolean setBlock(int x, int y, int z, @NonNull final PlotBlock block) {
if (block instanceof LegacyPlotBlock) {
final LegacyPlotBlock legacyPlotBlock = (LegacyPlotBlock) block;
return this.setBlock(x, y, z, legacyPlotBlock.id, legacyPlotBlock.data);
} else {
final StringPlotBlock stringPlotBlock = (StringPlotBlock) block;
return this.setBlock(x, y, z, stringPlotBlock.getItemId());
}
}
public boolean setTile(int x, int y, int z, CompoundTag tag) {

View File

@ -44,6 +44,11 @@ public class ScopedLocalBlockQueue extends DelegateLocalBlockQueue {
}
}
@Override public boolean setBlock(int x, int y, int z, String id) {
return x >= 0 && x <= dx && y >= 0 && y <= dy && z >= 0 && z <= dz &&
super.setBlock(x + minX, y + minY, z + minZ, id);
}
@Override public boolean setBlock(int x, int y, int z, int id, int data) {
return x >= 0 && x <= dx && y >= 0 && y <= dy && z >= 0 && z <= dz && super
.setBlock(x + minX, y + minY, z + minZ, id, data);