mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 07:06:44 +01:00
Fix schematic pasting to paste tile entities and blocks with BlockData (e.g. stairs) properly
This commit is contained in:
parent
9fe9c2662b
commit
af23d3d98e
@ -1,11 +1,13 @@
|
||||
package com.github.intellectualsites.plotsquared.bukkit.object.schematic;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.C;
|
||||
import com.sk89q.jnbt.*;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
@ -30,11 +32,125 @@ public class StateWrapper {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public static String jsonToColourCode(String str) {
|
||||
str = str.replace("{\"extra\":", "").replace("],\"text\":\"\"}", "]")
|
||||
.replace("[{\"color\":\"black\",\"text\":\"", "&0")
|
||||
.replace("[{\"color\":\"dark_blue\",\"text\":\"", "&1")
|
||||
.replace("[{\"color\":\"dark_green\",\"text\":\"", "&2")
|
||||
.replace("[{\"color\":\"dark_aqua\",\"text\":\"", "&3")
|
||||
.replace("[{\"color\":\"dark_red\",\"text\":\"", "&4")
|
||||
.replace("[{\"color\":\"dark_purple\",\"text\":\"", "&5")
|
||||
.replace("[{\"color\":\"gold\",\"text\":\"", "&6")
|
||||
.replace("[{\"color\":\"gray\",\"text\":\"", "&7")
|
||||
.replace("[{\"color\":\"dark_gray\",\"text\":\"", "&8")
|
||||
.replace("[{\"color\":\"blue\",\"text\":\"", "&9")
|
||||
.replace("[{\"color\":\"green\",\"text\":\"", "&a")
|
||||
.replace("[{\"color\":\"aqua\",\"text\":\"", "&b")
|
||||
.replace("[{\"color\":\"red\",\"text\":\"", "&c")
|
||||
.replace("[{\"color\":\"light_purple\",\"text\":\"", "&d")
|
||||
.replace("[{\"color\":\"yellow\",\"text\":\"", "&e")
|
||||
.replace("[{\"color\":\"white\",\"text\":\"", "&f")
|
||||
.replace("[{\"obfuscated\":true,\"text\":\"", "&k")
|
||||
.replace("[{\"bold\":true,\"text\":\"", "&l")
|
||||
.replace("[{\"strikethrough\":true,\"text\":\"", "&m")
|
||||
.replace("[{\"underlined\":true,\"text\":\"", "&n")
|
||||
.replace("[{\"italic\":true,\"text\":\"", "&o").replace("[{\"color\":\"black\",", "&0")
|
||||
.replace("[{\"color\":\"dark_blue\",", "&1")
|
||||
.replace("[{\"color\":\"dark_green\",", "&2")
|
||||
.replace("[{\"color\":\"dark_aqua\",", "&3").replace("[{\"color\":\"dark_red\",", "&4")
|
||||
.replace("[{\"color\":\"dark_purple\",", "&5").replace("[{\"color\":\"gold\",", "&6")
|
||||
.replace("[{\"color\":\"gray\",", "&7").replace("[{\"color\":\"dark_gray\",", "&8")
|
||||
.replace("[{\"color\":\"blue\",", "&9").replace("[{\"color\":\"green\",", "&a")
|
||||
.replace("[{\"color\":\"aqua\",", "&b").replace("[{\"color\":\"red\",", "&c")
|
||||
.replace("[{\"color\":\"light_purple\",", "&d").replace("[{\"color\":\"yellow\",", "&e")
|
||||
.replace("[{\"color\":\"white\",", "&f").replace("[{\"obfuscated\":true,", "&k")
|
||||
.replace("[{\"bold\":true,", "&l").replace("[{\"strikethrough\":true,", "&m")
|
||||
.replace("[{\"underlined\":true,", "&n").replace("[{\"italic\":true,", "&o")
|
||||
.replace("{\"color\":\"black\",\"text\":\"", "&0")
|
||||
.replace("{\"color\":\"dark_blue\",\"text\":\"", "&1")
|
||||
.replace("{\"color\":\"dark_green\",\"text\":\"", "&2")
|
||||
.replace("{\"color\":\"dark_aqua\",\"text\":\"", "&3")
|
||||
.replace("{\"color\":\"dark_red\",\"text\":\"", "&4")
|
||||
.replace("{\"color\":\"dark_purple\",\"text\":\"", "&5")
|
||||
.replace("{\"color\":\"gold\",\"text\":\"", "&6")
|
||||
.replace("{\"color\":\"gray\",\"text\":\"", "&7")
|
||||
.replace("{\"color\":\"dark_gray\",\"text\":\"", "&8")
|
||||
.replace("{\"color\":\"blue\",\"text\":\"", "&9")
|
||||
.replace("{\"color\":\"green\",\"text\":\"", "&a")
|
||||
.replace("{\"color\":\"aqua\",\"text\":\"", "&b")
|
||||
.replace("{\"color\":\"red\",\"text\":\"", "&c")
|
||||
.replace("{\"color\":\"light_purple\",\"text\":\"", "&d")
|
||||
.replace("{\"color\":\"yellow\",\"text\":\"", "&e")
|
||||
.replace("{\"color\":\"white\",\"text\":\"", "&f")
|
||||
.replace("{\"obfuscated\":true,\"text\":\"", "&k")
|
||||
.replace("{\"bold\":true,\"text\":\"", "&l")
|
||||
.replace("{\"strikethrough\":true,\"text\":\"", "&m")
|
||||
.replace("{\"underlined\":true,\"text\":\"", "&n")
|
||||
.replace("{\"italic\":true,\"text\":\"", "&o").replace("{\"color\":\"black\",", "&0")
|
||||
.replace("{\"color\":\"dark_blue\",", "&1").replace("{\"color\":\"dark_green\",", "&2")
|
||||
.replace("{\"color\":\"dark_aqua\",", "&3").replace("{\"color\":\"dark_red\",", "&4")
|
||||
.replace("{\"color\":\"dark_purple\",", "&5").replace("{\"color\":\"gold\",", "&6")
|
||||
.replace("{\"color\":\"gray\",", "&7").replace("{\"color\":\"dark_gray\",", "&8")
|
||||
.replace("{\"color\":\"blue\",", "&9").replace("{\"color\":\"green\",", "&a")
|
||||
.replace("{\"color\":\"aqua\",", "&b").replace("{\"color\":\"red\",", "&c")
|
||||
.replace("{\"color\":\"light_purple\",", "&d").replace("{\"color\":\"yellow\",", "&e")
|
||||
.replace("{\"color\":\"white\",", "&f").replace("{\"obfuscated\":true,", "&k")
|
||||
.replace("{\"bold\":true,", "&l").replace("{\"strikethrough\":true,", "&m")
|
||||
.replace("{\"underlined\":true,", "&n").replace("{\"italic\":true,", "&o")
|
||||
.replace("\"color\":\"black\",\"text\":\"", "&0")
|
||||
.replace("\"color\":\"dark_blue\",\"text\":\"", "&1")
|
||||
.replace("\"color\":\"dark_green\",\"text\":\"", "&2")
|
||||
.replace("\"color\":\"dark_aqua\",\"text\":\"", "&3")
|
||||
.replace("\"color\":\"dark_red\",\"text\":\"", "&4")
|
||||
.replace("\"color\":\"dark_purple\",\"text\":\"", "&5")
|
||||
.replace("\"color\":\"gold\",\"text\":\"", "&6")
|
||||
.replace("\"color\":\"gray\",\"text\":\"", "&7")
|
||||
.replace("\"color\":\"dark_gray\",\"text\":\"", "&8")
|
||||
.replace("\"color\":\"blue\",\"text\":\"", "&9")
|
||||
.replace("\"color\":\"green\",\"text\":\"", "&a")
|
||||
.replace("\"color\":\"aqua\",\"text\":\"", "&b")
|
||||
.replace("\"color\":\"red\",\"text\":\"", "&c")
|
||||
.replace("\"color\":\"light_purple\",\"text\":\"", "&d")
|
||||
.replace("\"color\":\"yellow\",\"text\":\"", "&e")
|
||||
.replace("\"color\":\"white\",\"text\":\"", "&f")
|
||||
.replace("\"obfuscated\":true,\"text\":\"", "&k")
|
||||
.replace("\"bold\":true,\"text\":\"", "&l")
|
||||
.replace("\"strikethrough\":true,\"text\":\"", "&m")
|
||||
.replace("\"underlined\":true,\"text\":\"", "&n")
|
||||
.replace("\"italic\":true,\"text\":\"", "&o").replace("\"color\":\"black\",", "&0")
|
||||
.replace("\"color\":\"dark_blue\",", "&1").replace("\"color\":\"dark_green\",", "&2")
|
||||
.replace("\"color\":\"dark_aqua\",", "&3").replace("\"color\":\"dark_red\",", "&4")
|
||||
.replace("\"color\":\"dark_purple\",", "&5").replace("\"color\":\"gold\",", "&6")
|
||||
.replace("\"color\":\"gray\",", "&7").replace("\"color\":\"dark_gray\",", "&8")
|
||||
.replace("\"color\":\"blue\",", "&9").replace("\"color\":\"green\",", "&a")
|
||||
.replace("\"color\":\"aqua\",", "&b").replace("\"color\":\"red\",", "&c")
|
||||
.replace("\"color\":\"light_purple\",", "&d").replace("\"color\":\"yellow\",", "&e")
|
||||
.replace("\"color\":\"white\",", "&f").replace("\"obfuscated\":true,", "&k")
|
||||
.replace("\"bold\":true,", "&l").replace("\"strikethrough\":true,", "&m")
|
||||
.replace("\"underlined\":true,", "&n").replace("\"italic\":true,", "&o")
|
||||
.replace("[{\"text\":\"", "&0").replace("{\"text\":\"", "&0").replace("\"},", "")
|
||||
.replace("\"}]", "").replace("\"}", "");
|
||||
for (Entry<String, String> entry : C.replacements.entrySet()) {
|
||||
str = str.replace(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public boolean restoreTag(String worldName, int x, int y, int z) {
|
||||
if (this.tag == null) {
|
||||
return false;
|
||||
}
|
||||
switch (this.tag.getString("id").toLowerCase()) {
|
||||
String tileid = this.tag.getString("id").toLowerCase();
|
||||
if (tileid.startsWith("minecraft:")) {
|
||||
tileid = tileid.replace("minecraft:", "");
|
||||
}
|
||||
World world = BukkitUtil.getWorld(worldName);
|
||||
Block block = world.getBlockAt(x, y, z);
|
||||
if (block == null) {
|
||||
return false;
|
||||
}
|
||||
BlockState state = block.getState();
|
||||
switch (tileid) {
|
||||
case "chest":
|
||||
List<Tag> itemsTag = this.tag.getListTag("Items").getValue();
|
||||
int length = itemsTag.size();
|
||||
@ -44,17 +160,11 @@ public class StateWrapper {
|
||||
for (int i = 0; i < length; i++) {
|
||||
Tag itemTag = itemsTag.get(i);
|
||||
CompoundTag itemComp = (CompoundTag) itemTag;
|
||||
String id = itemComp.getString("id");
|
||||
String id = itemComp.getString("Id");
|
||||
ids[i] = id;
|
||||
amounts[i] = itemComp.getByte("Count");
|
||||
slots[i] = itemComp.getByte("Slot");
|
||||
}
|
||||
World world = BukkitUtil.getWorld(worldName);
|
||||
Block block = world.getBlockAt(x, y, z);
|
||||
if (block == null) {
|
||||
return false;
|
||||
}
|
||||
BlockState state = block.getState();
|
||||
if (state instanceof InventoryHolder) {
|
||||
InventoryHolder holder = (InventoryHolder) state;
|
||||
Inventory inv = holder.getInventory();
|
||||
@ -66,6 +176,18 @@ public class StateWrapper {
|
||||
state.update(true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case "sign":
|
||||
if (state instanceof Sign) {
|
||||
Sign sign = (Sign) state;
|
||||
sign.setLine(0, jsonToColourCode(tag.getString("Text1")));
|
||||
sign.setLine(1, jsonToColourCode(tag.getString("Text2")));
|
||||
sign.setLine(2, jsonToColourCode(tag.getString("Text3")));
|
||||
sign.setLine(3, jsonToColourCode(tag.getString("Text4")));
|
||||
state.update(true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -119,4 +241,5 @@ public class StateWrapper {
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.intellectualsites.plotsquared.bukkit.util.block;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.bukkit.object.schematic.StateWrapper;
|
||||
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.LegacyPlotBlock;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
|
||||
@ -7,6 +8,9 @@ import com.github.intellectualsites.plotsquared.plot.object.StringPlotBlock;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.block.BasicLocalBlockQueue;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
@ -67,8 +71,11 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
|
||||
}
|
||||
|
||||
@Override public final void setComponents(LocalChunk<T> lc) {
|
||||
if (isBaseBlocks()) {
|
||||
setBaseBlocks(lc);
|
||||
} else {
|
||||
setBlocks(lc);
|
||||
setBiomes(lc);
|
||||
}
|
||||
}
|
||||
|
||||
public World getBukkitWorld() {
|
||||
@ -93,15 +100,6 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
|
||||
int y = MainUtil.y_loc[layer][j];
|
||||
int z = MainUtil.z_loc[layer][j];
|
||||
Block existing = chunk.getBlock(x, y, z);
|
||||
// int existingId = existing.getTypeId();
|
||||
// if (existingId == block.id) {
|
||||
// if (existingId == 0) {
|
||||
// continue;
|
||||
// }
|
||||
// if (existing.getData() == block.data) {
|
||||
// continue;
|
||||
// }
|
||||
//}
|
||||
if (equals(block, existing)) {
|
||||
continue;
|
||||
}
|
||||
@ -112,6 +110,41 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
|
||||
}
|
||||
}
|
||||
|
||||
public void setBaseBlocks(LocalChunk<T> lc) {
|
||||
World worldObj = Bukkit.getWorld(getWorld());
|
||||
Chunk chunk = worldObj.getChunkAt(lc.getX(), lc.getZ());
|
||||
chunk.load(true);
|
||||
for (int layer = 0; layer < lc.baseblocks.length; layer++) {
|
||||
BaseBlock[] blocksLayer = lc.baseblocks[layer];
|
||||
if (blocksLayer != null) {
|
||||
for (int j = 0; j < blocksLayer.length; j++) {
|
||||
if (blocksLayer[j] != null) {
|
||||
BaseBlock block = blocksLayer[j];
|
||||
int x = MainUtil.x_loc[layer][j];
|
||||
int y = MainUtil.y_loc[layer][j];
|
||||
int z = MainUtil.z_loc[layer][j];
|
||||
|
||||
Block existing = chunk.getBlock(x, y, z);
|
||||
if (equals(PlotBlock.get(block), existing) && existing.getBlockData()
|
||||
.matches(BukkitAdapter.adapt(block))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
existing.setType(BukkitAdapter.adapt(block.getBlockType()), false);
|
||||
existing.setBlockData(BukkitAdapter.adapt(block), false);
|
||||
if (block.hasNbtData()) {
|
||||
CompoundTag tag = block.getNbtData();
|
||||
StateWrapper sw = new StateWrapper(tag);
|
||||
|
||||
sw.restoreTag(worldObj.getName(), existing.getX(), existing.getY(),
|
||||
existing.getZ());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setMaterial(@NonNull final PlotBlock plotBlock, @NonNull final Block block) {
|
||||
final Material material;
|
||||
if (plotBlock instanceof StringPlotBlock) {
|
||||
@ -125,7 +158,8 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
|
||||
} else {
|
||||
final LegacyPlotBlock legacyPlotBlock = (LegacyPlotBlock) plotBlock;
|
||||
material = PlotSquared.get().IMP.getLegacyMappings()
|
||||
.fromLegacyToString(legacyPlotBlock.getId(), legacyPlotBlock.getData()).to(Material.class);
|
||||
.fromLegacyToString(legacyPlotBlock.getId(), legacyPlotBlock.getData())
|
||||
.to(Material.class);
|
||||
if (material == null) {
|
||||
throw new IllegalStateException(String
|
||||
.format("Could not find material that matches %s", legacyPlotBlock.toString()));
|
||||
@ -140,8 +174,9 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
|
||||
}
|
||||
final LegacyPlotBlock legacyPlotBlock = (LegacyPlotBlock) plotBlock;
|
||||
return Material.getMaterial(PlotSquared.get().IMP.getLegacyMappings()
|
||||
.fromLegacyToString(((LegacyPlotBlock) plotBlock).id, ((LegacyPlotBlock) plotBlock).data).toString()) == block.getType()
|
||||
&& (legacyPlotBlock.id == 0 || legacyPlotBlock.data == block.getData());
|
||||
.fromLegacyToString(((LegacyPlotBlock) plotBlock).id,
|
||||
((LegacyPlotBlock) plotBlock).data).toString()) == block.getType() && (
|
||||
legacyPlotBlock.id == 0 || legacyPlotBlock.data == block.getData());
|
||||
}
|
||||
|
||||
public void setBiomes(LocalChunk<T> lc) {
|
||||
|
@ -50,9 +50,9 @@ public class Load extends SubCommand {
|
||||
MainUtil.sendMessage(player, C.LOAD_NULL);
|
||||
return false;
|
||||
}
|
||||
String schematic;
|
||||
String schem;
|
||||
try {
|
||||
schematic = schematics.get(Integer.parseInt(args[0]) - 1);
|
||||
schem = schematics.get(Integer.parseInt(args[0]) - 1);
|
||||
} catch (Exception ignored) {
|
||||
// use /plot load <index>
|
||||
MainUtil
|
||||
@ -61,7 +61,7 @@ public class Load extends SubCommand {
|
||||
}
|
||||
final URL url;
|
||||
try {
|
||||
url = new URL(Settings.Web.URL + "saves/" + player.getUUID() + '/' + schematic);
|
||||
url = new URL(Settings.Web.URL + "saves/" + player.getUUID() + '/' + schem);
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
MainUtil.sendMessage(player, C.LOAD_FAILED);
|
||||
@ -69,8 +69,7 @@ public class Load extends SubCommand {
|
||||
}
|
||||
plot.addRunning();
|
||||
MainUtil.sendMessage(player, C.GENERATING_COMPONENT);
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override public void run() {
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
Schematic schematic = SchematicHandler.manager.getSchematic(url);
|
||||
if (schematic == null) {
|
||||
plot.removeRunning();
|
||||
@ -91,7 +90,6 @@ public class Load extends SubCommand {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
@ -55,8 +55,7 @@ public class SchematicCmd extends SubCommand {
|
||||
}
|
||||
final String location = args[1];
|
||||
this.running = true;
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override public void run() {
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
Schematic schematic = null;
|
||||
if (location.startsWith("url:")) {
|
||||
try {
|
||||
@ -95,7 +94,6 @@ public class SchematicCmd extends SubCommand {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
@ -153,12 +151,8 @@ public class SchematicCmd extends SubCommand {
|
||||
.sendMessage(player, "&cInvalid world. Use &7/plot sch exportall <area>");
|
||||
return false;
|
||||
}
|
||||
boolean result =
|
||||
SchematicHandler.manager.exportAll(plots, null, null, new Runnable() {
|
||||
@Override public void run() {
|
||||
MainUtil.sendMessage(player, "&aFinished mass export");
|
||||
}
|
||||
});
|
||||
boolean result = SchematicHandler.manager.exportAll(plots, null, null,
|
||||
() -> MainUtil.sendMessage(player, "&aFinished mass export"));
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(player, "&cTask is already running.");
|
||||
return false;
|
||||
@ -197,12 +191,9 @@ public class SchematicCmd extends SubCommand {
|
||||
location.getWorld();
|
||||
Collection<Plot> plots = new ArrayList<>();
|
||||
plots.add(plot);
|
||||
boolean result =
|
||||
SchematicHandler.manager.exportAll(plots, null, null, new Runnable() {
|
||||
@Override public void run() {
|
||||
boolean result = SchematicHandler.manager.exportAll(plots, null, null, () -> {
|
||||
MainUtil.sendMessage(player, "&aFinished export");
|
||||
SchematicCmd.this.running = false;
|
||||
}
|
||||
});
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(player, "&cTask is already running.");
|
||||
|
@ -180,19 +180,10 @@ public abstract class SchematicHandler {
|
||||
final int bcz = p1z >> 4;
|
||||
final int tcx = p2x >> 4;
|
||||
final int tcz = p2z >> 4;
|
||||
/* final ArrayList<ChunkLoc> chunks = new ArrayList<>();
|
||||
for (int x = bcx; x <= tcx; x++) {
|
||||
for (int z = bcz; z <= tcz; z++) {
|
||||
chunks.add(new ChunkLoc(x, z));
|
||||
}
|
||||
}*/
|
||||
|
||||
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
|
||||
@Override public void run(int[] value) {
|
||||
//int count = 0;
|
||||
//while (!chunks.isEmpty() && count < 256) {
|
||||
//count++;
|
||||
ChunkLoc chunk = new ChunkLoc(value[0], value[1]);
|
||||
PlotSquared.log(chunk.toString());
|
||||
int x = chunk.x;
|
||||
int z = chunk.z;
|
||||
int xxb = x << 4;
|
||||
@ -218,47 +209,24 @@ public abstract class SchematicHandler {
|
||||
if (yy > 255) {
|
||||
continue;
|
||||
}
|
||||
int i1 = ry * WIDTH * LENGTH;
|
||||
for (int rz = zzb - p1z; rz <= (zzt - p1z); rz++) {
|
||||
int i2 = (rz * WIDTH) + i1;
|
||||
for (int rx = xxb - p1x; rx <= (xxt - p1x); rx++) {
|
||||
int i = i2 + rx;
|
||||
int xx = p1x + rx;
|
||||
int zz = p1z + rz;
|
||||
int xx = p1x + xOffset + rx;
|
||||
int zz = p1z + zOffset + rz;
|
||||
BaseBlock id = blockArrayClipboard
|
||||
.getFullBlock(BlockVector3.at(rx, ry, rz));
|
||||
queue.setBlock(xx, yy, zz, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
queue.enqueue();
|
||||
/* }
|
||||
if (!chunks.isEmpty()) {
|
||||
this.run();
|
||||
} else {
|
||||
queue.flush();
|
||||
HashMap<BlockLoc, CompoundTag> tiles = schematic.getClipboard().getTiles();
|
||||
if (!tiles.isEmpty()) {
|
||||
TaskManager.IMP.sync(new RunnableVal<Object>() {
|
||||
@Override public void run(Object value) {
|
||||
for (Map.Entry<BlockLoc, CompoundTag> entry : schematic
|
||||
.getTiles().entrySet()) {
|
||||
BlockLoc loc = entry.getKey();
|
||||
restoreTile(queue, entry.getValue(),
|
||||
p1x + xOffset + loc.x, loc.y + y_offset_actual,
|
||||
p1z + zOffset + loc.z);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}, null, 10);
|
||||
}, () -> {
|
||||
if (whenDone != null) {
|
||||
whenDone.value = true;
|
||||
whenDone.run();
|
||||
}
|
||||
}, 10);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
TaskManager.runTask(whenDone);
|
||||
|
@ -6,7 +6,7 @@ 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 com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import lombok.NonNull;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedDeque;
|
||||
@ -14,12 +14,13 @@ import java.util.concurrent.ConcurrentLinkedDeque;
|
||||
public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
|
||||
|
||||
private final String world;
|
||||
private final ConcurrentHashMap<Long, LocalChunk> blocks = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<Long, LocalChunk> blockChunks = new ConcurrentHashMap<>();
|
||||
private final ConcurrentLinkedDeque<LocalChunk> chunks = new ConcurrentLinkedDeque<>();
|
||||
private long modified;
|
||||
private LocalChunk lastWrappedChunk;
|
||||
private int lastX = Integer.MIN_VALUE;
|
||||
private int lastZ = Integer.MIN_VALUE;
|
||||
@Getter private boolean baseBlocks = false;
|
||||
|
||||
public BasicLocalBlockQueue(String world) {
|
||||
super(world);
|
||||
@ -41,13 +42,13 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
|
||||
lastX = Integer.MIN_VALUE;
|
||||
lastZ = Integer.MIN_VALUE;
|
||||
try {
|
||||
if (this.blocks.size() == 0) {
|
||||
if (this.blockChunks.size() == 0) {
|
||||
return false;
|
||||
}
|
||||
synchronized (blocks) {
|
||||
synchronized (blockChunks) {
|
||||
LocalChunk chunk = chunks.poll();
|
||||
if (chunk != null) {
|
||||
blocks.remove(chunk.longHash());
|
||||
blockChunks.remove(chunk.longHash());
|
||||
this.execute(chunk);
|
||||
return true;
|
||||
}
|
||||
@ -90,22 +91,23 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
|
||||
if ((y > 255) || (y < 0)) {
|
||||
return false;
|
||||
}
|
||||
baseBlocks = true;
|
||||
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);
|
||||
lastWrappedChunk = this.blockChunks.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);
|
||||
LocalChunk previous = this.blockChunks.put(pair, lastWrappedChunk);
|
||||
if (previous == null) {
|
||||
chunks.add(lastWrappedChunk);
|
||||
return true;
|
||||
}
|
||||
this.blocks.put(pair, previous);
|
||||
this.blockChunks.put(pair, previous);
|
||||
lastWrappedChunk = previous;
|
||||
}
|
||||
}
|
||||
@ -123,16 +125,16 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
|
||||
lastX = cx;
|
||||
lastZ = cz;
|
||||
long pair = (long) (cx) << 32 | (cz) & 0xFFFFFFFFL;
|
||||
lastWrappedChunk = this.blocks.get(pair);
|
||||
lastWrappedChunk = this.blockChunks.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);
|
||||
LocalChunk previous = this.blockChunks.put(pair, lastWrappedChunk);
|
||||
if (previous == null) {
|
||||
chunks.add(lastWrappedChunk);
|
||||
return true;
|
||||
}
|
||||
this.blocks.put(pair, previous);
|
||||
this.blockChunks.put(pair, previous);
|
||||
lastWrappedChunk = previous;
|
||||
}
|
||||
}
|
||||
@ -142,12 +144,12 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
|
||||
|
||||
@Override public final boolean setBiome(int x, int z, String biome) {
|
||||
long pair = (long) (x >> 4) << 32 | (z >> 4) & 0xFFFFFFFFL;
|
||||
LocalChunk result = this.blocks.get(pair);
|
||||
LocalChunk result = this.blockChunks.get(pair);
|
||||
if (result == null) {
|
||||
result = this.getLocalChunk(x >> 4, z >> 4);
|
||||
LocalChunk previous = this.blocks.put(pair, result);
|
||||
LocalChunk previous = this.blockChunks.put(pair, result);
|
||||
if (previous != null) {
|
||||
this.blocks.put(pair, previous);
|
||||
this.blockChunks.put(pair, previous);
|
||||
result = previous;
|
||||
} else {
|
||||
chunks.add(result);
|
||||
@ -158,7 +160,7 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
|
||||
}
|
||||
|
||||
public final void setChunk(LocalChunk<T> chunk) {
|
||||
LocalChunk previous = this.blocks.put(chunk.longHash(), chunk);
|
||||
LocalChunk previous = this.blockChunks.put(chunk.longHash(), chunk);
|
||||
if (previous != null) {
|
||||
chunks.remove(previous);
|
||||
}
|
||||
@ -182,6 +184,7 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
|
||||
public final int x;
|
||||
|
||||
public T[] blocks;
|
||||
public BaseBlock[][] baseblocks;
|
||||
public String[][] biomes;
|
||||
|
||||
public LocalChunk(BasicLocalBlockQueue<T> parent, int x, int z) {
|
||||
@ -209,7 +212,7 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
|
||||
|
||||
public abstract void setBlock(final int x, final int y, final int z, final PlotBlock block);
|
||||
|
||||
public abstract void setBlock(final int x, final int y, final int z, final BaseBlock id);
|
||||
public abstract void setBlock(final int x, final int y, final int z, final BaseBlock block);
|
||||
|
||||
public void setBiome(int x, int z, String biome) {
|
||||
if (this.biomes == null) {
|
||||
@ -236,27 +239,13 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
|
||||
public BasicLocalChunk(BasicLocalBlockQueue parent, int x, int z) {
|
||||
super(parent, x, z);
|
||||
blocks = new PlotBlock[16][];
|
||||
baseblocks = new BaseBlock[16][];
|
||||
}
|
||||
|
||||
@Override public void setBlock(int x, int y, int z, PlotBlock block) {
|
||||
this.setInternal(x, y, z, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock(final int x, final int y, final int z, @NonNull final BaseBlock id) {
|
||||
this.setInternal(x, y, z, id);
|
||||
}
|
||||
|
||||
private void setInternal(final int x, final int y, final int z, final BaseBlock bsh) {
|
||||
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] = PlotBlock.get(bsh);
|
||||
}
|
||||
|
||||
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];
|
||||
@ -267,6 +256,20 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
|
||||
array[j] = plotBlock;
|
||||
}
|
||||
|
||||
@Override public void setBlock(int x, int y, int z, BaseBlock block) {
|
||||
this.setInternal(x, y, z, block);
|
||||
}
|
||||
|
||||
private void setInternal(final int x, final int y, final int z, final BaseBlock baseBlock) {
|
||||
final int i = MainUtil.CACHE_I[y][x][z];
|
||||
final int j = MainUtil.CACHE_J[y][x][z];
|
||||
BaseBlock[] array = baseblocks[i];
|
||||
if (array == null) {
|
||||
array = (baseblocks[i] = new BaseBlock[4096]);
|
||||
}
|
||||
array[j] = baseBlock;
|
||||
}
|
||||
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user