Fix plot move/swap block rotation issue (switch to BaseBlock). Also fix container inventory pasting.

Some cleanup.
Fixes #2209
This commit is contained in:
dordsor21 2018-12-31 17:15:47 +00:00
parent 8c52e20736
commit 7bcc4c4ce3
4 changed files with 127 additions and 135 deletions

View File

@ -1,12 +1,14 @@
package com.github.intellectualsites.plotsquared.bukkit.object.schematic; package com.github.intellectualsites.plotsquared.bukkit.object.schematic;
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil; import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.C; import com.github.intellectualsites.plotsquared.plot.config.C;
import com.sk89q.jnbt.*; import com.sk89q.jnbt.*;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.block.Container;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
@ -152,6 +154,13 @@ public class StateWrapper {
BlockState state = block.getState(); BlockState state = block.getState();
switch (tileid) { switch (tileid) {
case "chest": case "chest":
case "beacon":
case "brewingstand":
case "dispenser":
case "dropper":
case "furnace":
case "hopper":
case "shulkerbox":
List<Tag> itemsTag = this.tag.getListTag("Items").getValue(); List<Tag> itemsTag = this.tag.getListTag("Items").getValue();
int length = itemsTag.size(); int length = itemsTag.size();
String[] ids = new String[length]; String[] ids = new String[length];
@ -160,20 +169,27 @@ public class StateWrapper {
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
Tag itemTag = itemsTag.get(i); Tag itemTag = itemsTag.get(i);
CompoundTag itemComp = (CompoundTag) itemTag; CompoundTag itemComp = (CompoundTag) itemTag;
String id = itemComp.getString("Id"); String id = itemComp.getString("id");
if (id.startsWith("minecraft:")) {
id = id.replace("minecraft:", "");
}
ids[i] = id; ids[i] = id;
amounts[i] = itemComp.getByte("Count"); amounts[i] = itemComp.getByte("Count");
slots[i] = itemComp.getByte("Slot"); slots[i] = itemComp.getByte("Slot");
} }
if (state instanceof InventoryHolder) { if (state instanceof Container) {
InventoryHolder holder = (InventoryHolder) state; Container container = (Container) state;
Inventory inv = holder.getInventory(); Inventory inv = container.getSnapshotInventory();
for (int i = 0; i < ids.length; i++) { for (int i = 0; i < ids.length; i++) {
ItemStack item = Material mat = Material.getMaterial(ids[i].toUpperCase());
new ItemStack(Material.getMaterial(ids[i]), (int) amounts[i]); if (mat != null) {
inv.addItem(item); ItemStack item = new ItemStack(mat, (int) amounts[i]);
inv.setItem(slots[i], item);
PlotSquared.log(mat.name() + " " + slots[i]);
} }
state.update(true); }
PlotSquared.log(inv.getStorageContents());
container.update(true, true);
return true; return true;
} }
return false; return false;

View File

@ -10,12 +10,14 @@ import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; 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.block.LocalBlockQueue;
import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.block.*; import org.bukkit.block.Block;
import org.bukkit.block.banner.Pattern; import org.bukkit.block.banner.Pattern;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.entity.*; import org.bukkit.entity.*;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.*; import java.util.*;
@ -51,43 +53,43 @@ public class BukkitChunkManager extends ChunkManager {
String worldName1 = world1.getName(); String worldName1 = world1.getName();
String worldName2 = world2.getName(); String worldName2 = world2.getName();
BukkitWorld bukkitWorld1 = new BukkitWorld(world1);
BukkitWorld bukkitWorld2 = new BukkitWorld(world2);
LocalBlockQueue queue1 = GlobalBlockQueue.IMP.getNewQueue(worldName1, false); LocalBlockQueue queue1 = GlobalBlockQueue.IMP.getNewQueue(worldName1, false);
LocalBlockQueue queue2 = GlobalBlockQueue.IMP.getNewQueue(worldName2, false); LocalBlockQueue queue2 = GlobalBlockQueue.IMP.getNewQueue(worldName2, false);
for (int x = Math.max(r1.minX, sx); x <= Math.min(r1.maxX, sx + 15); x++) { for (int x = Math.max(r1.minX, sx); x <= Math.min(r1.maxX, sx + 15); x++) {
for (int z = Math.max(r1.minZ, sz); z <= Math.min(r1.maxZ, sz + 15); z++) { for (int z = Math.max(r1.minZ, sz); z <= Math.min(r1.maxZ, sz + 15); z++) {
map.saveBlocks(world1, 256, sx, sz, relX, relZ, false); map.saveBlocks(bukkitWorld1, 256, sx, sz, relX, relZ);
for (int y = 0; y < 256; y++) { for (int y = 0; y < 256; y++) {
Block block1 = world1.getBlockAt(x, y, z); Block block1 = world1.getBlockAt(x, y, z);
// int id1 = block1.getTypeId(); BaseBlock baseBlock1 = bukkitWorld2.getFullBlock(BlockVector3.at(x, y, z));
Material id1 = block1.getType();
BlockData data1 = block1.getBlockData(); BlockData data1 = block1.getBlockData();
// byte data1 = block1.getData();
int xx = x + relX; int xx = x + relX;
int zz = z + relZ; int zz = z + relZ;
Block block2 = world2.getBlockAt(xx, y, zz); Block block2 = world2.getBlockAt(xx, y, zz);
// int id2 = block2.getTypeId(); BaseBlock baseBlock2 = bukkitWorld2.getFullBlock(BlockVector3.at(xx, y, zz));
Material id2 = block2.getType();
BlockData data2 = block2.getBlockData(); BlockData data2 = block2.getBlockData();
// byte data2 = block2.getData();
if (id1 == Material.AIR) { if (block1.isEmpty()) {
if (id2 != Material.AIR) { if (block2.isEmpty()) {
queue1.setBlock(x, y, z, PlotBlock.get(id2)); queue1.setBlock(x, y, z, baseBlock2);
queue2.setBlock(xx, y, zz, PlotBlock.get("air")); queue2.setBlock(xx, y, zz, PlotBlock.get("air"));
} }
} else if (id2 == Material.AIR) { } else if (block2.isEmpty()) {
queue1.setBlock(x, y, z, PlotBlock.get("air")); queue1.setBlock(x, y, z, PlotBlock.get("air"));
queue2.setBlock(xx, y, zz, PlotBlock.get(id1)); queue2.setBlock(xx, y, zz, baseBlock1);
} else if (id1 == id2) { } else if (block1.equals(block2)) {
if (data1 != data2) { if (data1 != data2) {
block1.setBlockData(data2); block1.setBlockData(data2);
block2.setBlockData(data1); block2.setBlockData(data1);
} }
} else { } else {
queue1.setBlock(x, y, z, PlotBlock.get(id2)); queue1.setBlock(x, y, z, baseBlock2);
queue2.setBlock(xx, y, zz, PlotBlock.get(id1)); queue2.setBlock(xx, y, zz, baseBlock1);
// queue1.setBlock(x, y, z, (short) id2, data2);
// queue2.setBlock(xx, y, zz, (short) id1, data1);
} }
} }
} }
@ -115,13 +117,11 @@ public class BukkitChunkManager extends ChunkManager {
final Runnable whenDone) { final Runnable whenDone) {
final int relX = newPos.getX() - pos1.getX(); final int relX = newPos.getX() - pos1.getX();
final int relZ = newPos.getZ() - pos1.getZ(); final int relZ = newPos.getZ() - pos1.getZ();
com.github.intellectualsites.plotsquared.plot.object.Location pos4 =
new com.github.intellectualsites.plotsquared.plot.object.Location(newPos.getWorld(),
newPos.getX() + relX, 256, newPos.getZ() + relZ);
final RegionWrapper region = final RegionWrapper region =
new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ()); new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
final World oldWorld = Bukkit.getWorld(pos1.getWorld()); final World oldWorld = Bukkit.getWorld(pos1.getWorld());
final BukkitWorld oldBukkitWorld = new BukkitWorld(oldWorld);
final World newWorld = Bukkit.getWorld(newPos.getWorld()); final World newWorld = Bukkit.getWorld(newPos.getWorld());
final String newWorldName = newWorld.getName(); final String newWorldName = newWorld.getName();
final ContentMap map = new ContentMap(); final ContentMap map = new ContentMap();
@ -139,24 +139,24 @@ public class BukkitChunkManager extends ChunkManager {
map.saveEntitiesIn(chunk, region); map.saveEntitiesIn(chunk, region);
for (int x = bx & 15; x <= (tx & 15); x++) { for (int x = bx & 15; x <= (tx & 15); x++) {
for (int z = bz & 15; z <= (tz & 15); z++) { for (int z = bz & 15; z <= (tz & 15); z++) {
map.saveBlocks(oldWorld, 256, cxx + x, czz + z, relX, relZ, true); map.saveBlocks(oldBukkitWorld, 256, cxx + x, czz + z, relX, relZ);
} }
} }
} }
}, () -> { }, () -> {
for (Entry<PlotLoc, PlotBlock[]> entry : map.allBlocks.entrySet()) { for (Entry<PlotLoc, BaseBlock[]> entry : map.allBlocks.entrySet()) {
PlotLoc loc = entry.getKey(); PlotLoc loc = entry.getKey();
PlotBlock[] blocks = entry.getValue(); BaseBlock[] blocks = entry.getValue();
for (int y = 0; y < blocks.length; y++) { for (int y = 0; y < blocks.length; y++) {
if (blocks[y] != null) { if (blocks[y] != null) {
PlotBlock block = blocks[y]; BaseBlock block = blocks[y];
queue.setBlock(loc.x, y, loc.z, block); queue.setBlock(loc.x, y, loc.z, block);
} }
} }
} }
queue.enqueue(); queue.enqueue();
GlobalBlockQueue.IMP.addTask(() -> { GlobalBlockQueue.IMP.addTask(() -> {
map.restoreBlocks(newWorld, 0, 0); //map.restoreBlocks(newWorld, 0, 0);
map.restoreEntities(newWorld, relX, relZ); map.restoreEntities(newWorld, relX, relZ);
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
}); });
@ -187,6 +187,7 @@ public class BukkitChunkManager extends ChunkManager {
} }
} }
final World worldObj = Bukkit.getWorld(world); final World worldObj = Bukkit.getWorld(world);
final BukkitWorld bukkitWorldObj = new BukkitWorld(worldObj);
TaskManager.runTask(new Runnable() { TaskManager.runTask(new Runnable() {
@Override public void run() { @Override public void run() {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
@ -246,28 +247,28 @@ public class BukkitChunkManager extends ChunkManager {
} }
final ContentMap map = new ContentMap(); final ContentMap map = new ContentMap();
if (checkX1) { if (checkX1) {
map.saveRegion(worldObj, xxb, xxb2, zzb2, zzt2); // map.saveRegion(bukkitWorldObj, xxb, xxb2, zzb2, zzt2); //
} }
if (checkX2) { if (checkX2) {
map.saveRegion(worldObj, xxt2, xxt, zzb2, zzt2); // map.saveRegion(bukkitWorldObj, xxt2, xxt, zzb2, zzt2); //
} }
if (checkZ1) { if (checkZ1) {
map.saveRegion(worldObj, xxb2, xxt2, zzb, zzb2); // map.saveRegion(bukkitWorldObj, xxb2, xxt2, zzb, zzb2); //
} }
if (checkZ2) { if (checkZ2) {
map.saveRegion(worldObj, xxb2, xxt2, zzt2, zzt); // map.saveRegion(bukkitWorldObj, xxb2, xxt2, zzt2, zzt); //
} }
if (checkX1 && checkZ1) { if (checkX1 && checkZ1) {
map.saveRegion(worldObj, xxb, xxb2, zzb, zzb2); // map.saveRegion(bukkitWorldObj, xxb, xxb2, zzb, zzb2); //
} }
if (checkX2 && checkZ1) { if (checkX2 && checkZ1) {
map.saveRegion(worldObj, xxt2, xxt, zzb, zzb2); // ? map.saveRegion(bukkitWorldObj, xxt2, xxt, zzb, zzb2); // ?
} }
if (checkX1 && checkZ2) { if (checkX1 && checkZ2) {
map.saveRegion(worldObj, xxb, xxb2, zzt2, zzt); // ? map.saveRegion(bukkitWorldObj, xxb, xxb2, zzt2, zzt); // ?
} }
if (checkX2 && checkZ2) { if (checkX2 && checkZ2) {
map.saveRegion(worldObj, xxt2, xxt, zzt2, zzt); // map.saveRegion(bukkitWorldObj, xxt2, xxt, zzt2, zzt); //
} }
map.saveEntitiesOut(chunkObj, currentPlotClear); map.saveEntitiesOut(chunkObj, currentPlotClear);
AugmentedUtils.bypass(ignoreAugment, AugmentedUtils.bypass(ignoreAugment,
@ -280,10 +281,10 @@ public class BukkitChunkManager extends ChunkManager {
for (int x1 = 0; x1 < 16; x1++) { for (int x1 = 0; x1 < 16; x1++) {
for (int z1 = 0; z1 < 16; z1++) { for (int z1 = 0; z1 < 16; z1++) {
PlotLoc loc = new PlotLoc(bx + x1, bz + z1); PlotLoc loc = new PlotLoc(bx + x1, bz + z1);
PlotBlock[] ids = map.allBlocks.get(loc); BaseBlock[] ids = map.allBlocks.get(loc);
if (ids != null) { if (ids != null) {
for (int y = 0; y < Math.min(128, ids.length); y++) { for (int y = 0; y < Math.min(128, ids.length); y++) {
PlotBlock id = ids[y]; BaseBlock id = ids[y];
if (id != null) { if (id != null) {
value.setBlock(x1, y, z1, id); value.setBlock(x1, y, z1, id);
} else { } else {
@ -292,7 +293,7 @@ public class BukkitChunkManager extends ChunkManager {
} }
for (int y = Math.min(128, ids.length); for (int y = Math.min(128, ids.length);
y < ids.length; y++) { y < ids.length; y++) {
PlotBlock id = ids[y]; BaseBlock id = ids[y];
if (id != null) { if (id != null) {
value.setBlock(x1, y, z1, id); value.setBlock(x1, y, z1, id);
} }
@ -302,7 +303,7 @@ public class BukkitChunkManager extends ChunkManager {
} }
} }
}, world, chunk)); }, world, chunk));
map.restoreBlocks(worldObj, 0, 0); //map.restoreBlocks(worldObj, 0, 0);
map.restoreEntities(worldObj, 0, 0); map.restoreEntities(worldObj, 0, 0);
} }
if (!chunks.isEmpty()) { if (!chunks.isEmpty()) {
@ -379,7 +380,7 @@ public class BukkitChunkManager extends ChunkManager {
} }
GlobalBlockQueue.IMP.addTask(() -> { GlobalBlockQueue.IMP.addTask(() -> {
for (ContentMap map : maps) { for (ContentMap map : maps) {
map.restoreBlocks(world1, 0, 0); //map.restoreBlocks(world1, 0, 0);
map.restoreEntities(world1, 0, 0); map.restoreEntities(world1, 0, 0);
TaskManager.runTaskLater(whenDone, 1); TaskManager.runTaskLater(whenDone, 1);
} }
@ -606,7 +607,7 @@ public class BukkitChunkManager extends ChunkManager {
final Map<BlockLoc, List<Pattern>> bannerPatterns; final Map<BlockLoc, List<Pattern>> bannerPatterns;
final Map<BlockLoc, DyeColor> bannerBase; final Map<BlockLoc, DyeColor> bannerBase;
final Set<EntityWrapper> entities; final Set<EntityWrapper> entities;
final Map<PlotLoc, PlotBlock[]> allBlocks; final Map<PlotLoc, BaseBlock[]> allBlocks;
ContentMap() { ContentMap() {
this.chestContents = new HashMap<>(); this.chestContents = new HashMap<>();
@ -630,7 +631,7 @@ public class BukkitChunkManager extends ChunkManager {
this.allBlocks = new HashMap<>(); this.allBlocks = new HashMap<>();
} }
public void saveRegion(World world, int x1, int x2, int z1, int z2) { public void saveRegion(BukkitWorld world, int x1, int x2, int z1, int z2) {
if (z1 > z2) { if (z1 > z2) {
int tmp = z1; int tmp = z1;
z1 = z2; z1 = z2;
@ -643,7 +644,7 @@ public class BukkitChunkManager extends ChunkManager {
} }
for (int x = x1; x <= x2; x++) { for (int x = x1; x <= x2; x++) {
for (int z = z1; z <= z2; z++) { for (int z = z1; z <= z2; z++) {
saveBlocks(world, 256, x, z, 0, 0, true); saveBlocks(world, 256, x, z, 0, 0);
} }
} }
} }
@ -708,7 +709,7 @@ public class BukkitChunkManager extends ChunkManager {
this.entities.clear(); this.entities.clear();
} }
public void restoreBlocks(World world, int xOffset, int zOffset) { /* public void restoreBlocks(World world, int xOffset, int zOffset) {
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.chestContents.entrySet()) { for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.chestContents.entrySet()) {
try { try {
Block block = world Block block = world
@ -1065,25 +1066,23 @@ public class BukkitChunkManager extends ChunkManager {
+ ',' + (blockLocByteEntry.getKey().z + zOffset)); + ',' + (blockLocByteEntry.getKey().z + zOffset));
} }
} }
} }*/
public void saveBlocks(World world, int maxY, int x, int z, int offsetX, int offsetZ, public void saveBlocks(BukkitWorld world, int maxY, int x, int z, int offsetX,
boolean storeNormal) { int offsetZ) {
maxY = Math.min(255, maxY); maxY = Math.min(255, maxY);
PlotBlock[] ids; BaseBlock[] ids;
if (storeNormal) { ids = new BaseBlock[maxY + 1];
ids = new PlotBlock[maxY + 1];
} else {
ids = null;
}
for (short y = 0; y <= maxY; y++) { for (short y = 0; y <= maxY; y++) {
Block block = world.getBlockAt(x, y, z); BaseBlock block = world.getFullBlock(BlockVector3.at(x, y, z));
Material blockType = block.getType(); ids[y] = block;
if (storeNormal) { /* if (storeNormal) {
if (blockType.name().contains("AIR")) { if (block.isEmpty()) {
ids[y] = StringPlotBlock.EVERYTHING; BukkitAdapter.
ids[y] =
BukkitAdapter.adapt(Material.AIR.createBlockData()).toBaseBlock();
} else { } else {
ids[y] = PlotBlock.get(blockType.name()); ids[y] = BukkitAdapter.adapt(block.getBlockData()).toBaseBlock();
} }
} }
if (!blockType.name().contains("AIR")) { if (!blockType.name().contains("AIR")) {
@ -1169,7 +1168,7 @@ public class BukkitChunkManager extends ChunkManager {
e.printStackTrace(); e.printStackTrace();
PlotSquared.debug("------------ but we caught it ^ --------"); PlotSquared.debug("------------ but we caught it ^ --------");
} }
} }*/
} }
PlotLoc loc = new PlotLoc(x + offsetX, z + offsetZ); PlotLoc loc = new PlotLoc(x + offsetX, z + offsetZ);
this.allBlocks.put(loc, ids); this.allBlocks.put(loc, ids);

View File

@ -54,11 +54,7 @@ import com.github.intellectualsites.plotsquared.plot.util.Permissions;
C.PLOTWORLD_INCOMPATIBLE.send(player); C.PLOTWORLD_INCOMPATIBLE.send(player);
return false; return false;
} }
if (plot1.move(plot2, new Runnable() { if (plot1.move(plot2, () -> MainUtil.sendMessage(player, C.MOVE_SUCCESS), false)) {
@Override public void run() {
MainUtil.sendMessage(player, C.MOVE_SUCCESS);
}
}, false)) {
return true; return true;
} else { } else {
MainUtil.sendMessage(player, C.REQUIRES_UNOWNED); MainUtil.sendMessage(player, C.REQUIRES_UNOWNED);

View File

@ -806,14 +806,12 @@ public class Plot {
Runnable run = new Runnable() { Runnable run = new Runnable() {
@Override public void run() { @Override public void run() {
if (queue.isEmpty()) { if (queue.isEmpty()) {
Runnable run = new Runnable() { Runnable run = () -> {
@Override public void run() {
for (RegionWrapper region : regions) { for (RegionWrapper region : regions) {
Location[] corners = region.getCorners(getWorldName()); Location[] corners = region.getCorners(getWorldName());
ChunkManager.manager.clearAllEntities(corners[0], corners[1]); ChunkManager.manager.clearAllEntities(corners[0], corners[1]);
} }
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
}
}; };
for (Plot current : plots) { for (Plot current : plots) {
if (isDelete || current.owner == null) { if (isDelete || current.owner == null) {
@ -928,12 +926,10 @@ public class Plot {
current.setMerged(merged); current.setMerged(merged);
} }
if (createSign) { if (createSign) {
GlobalBlockQueue.IMP.addTask(new Runnable() { GlobalBlockQueue.IMP.addTask(() -> {
@Override public void run() {
for (Plot current : plots) { for (Plot current : plots) {
current.setSign(MainUtil.getName(current.owner)); current.setSign(MainUtil.getName(current.owner));
} }
}
}); });
} }
if (createRoad) { if (createRoad) {
@ -951,11 +947,7 @@ public class Plot {
if (!isLoaded()) if (!isLoaded())
return; return;
if (!PlotSquared.get().isMainThread(Thread.currentThread())) { if (!PlotSquared.get().isMainThread(Thread.currentThread())) {
TaskManager.runTask(new Runnable() { TaskManager.runTask(() -> Plot.this.setSign(name));
@Override public void run() {
Plot.this.setSign(name);
}
});
return; return;
} }
PlotManager manager = this.area.getPlotManager(); PlotManager manager = this.area.getPlotManager();
@ -1045,13 +1037,11 @@ public class Plot {
return false; return false;
} }
final Set<Plot> plots = this.getConnectedPlots(); final Set<Plot> plots = this.getConnectedPlots();
this.clear(false, true, new Runnable() { this.clear(false, true, () -> {
@Override public void run() {
for (Plot current : plots) { for (Plot current : plots) {
current.unclaim(); current.unclaim();
} }
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
}
}); });
return true; return true;
} }
@ -1259,7 +1249,9 @@ public class Plot {
x = bot.getX() + loc.x; x = bot.getX() + loc.x;
z = bot.getZ() + loc.z; z = bot.getZ() + loc.z;
} }
int y = loc.y < 1 ? (isLoaded() ? WorldUtil.IMP.getHighestBlock(plot.getWorldName(), x, z) + 1 : 63) : loc.y; int y = loc.y < 1 ?
(isLoaded() ? WorldUtil.IMP.getHighestBlock(plot.getWorldName(), x, z) + 1 : 63) :
loc.y;
PlotSquared.log("Getting home with Y " + y); PlotSquared.log("Getting home with Y " + y);
return new Location(plot.getWorldName(), x, y, z); return new Location(plot.getWorldName(), x, y, z);
} }
@ -1485,13 +1477,11 @@ public class Plot {
this.getDenied().clear(); this.getDenied().clear();
this.settings = new PlotSettings(); this.settings = new PlotSettings();
if (this.area.addPlot(this)) { if (this.area.addPlot(this)) {
DBFunc.createPlotAndSettings(this, new Runnable() { DBFunc.createPlotAndSettings(this, () -> {
@Override public void run() {
PlotArea plotworld = Plot.this.area; PlotArea plotworld = Plot.this.area;
if (notify && plotworld.AUTO_MERGE) { if (notify && plotworld.AUTO_MERGE) {
Plot.this.autoMerge(-1, Integer.MAX_VALUE, uuid, true); Plot.this.autoMerge(-1, Integer.MAX_VALUE, uuid, true);
} }
}
}); });
return true; return true;
} }
@ -1839,8 +1829,7 @@ public class Plot {
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
} }
} else { } else {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(() -> {
@Override public void run() {
String name = Plot.this.id + "," + Plot.this.area + ',' + MainUtil String name = Plot.this.id + "," + Plot.this.area + ',' + MainUtil
.getName(Plot.this.owner); .getName(Plot.this.owner);
boolean result = SchematicHandler.manager.save(value, boolean result = SchematicHandler.manager.save(value,
@ -1849,7 +1838,6 @@ public class Plot {
whenDone.value = result; whenDone.value = result;
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
} }
}
}); });
} }
} }
@ -2627,13 +2615,11 @@ public class Plot {
* - Usually called when the plot state changes (unclaimed/claimed/flag change etc) * - Usually called when the plot state changes (unclaimed/claimed/flag change etc)
*/ */
public void reEnter() { public void reEnter() {
TaskManager.runTaskLater(new Runnable() { TaskManager.runTaskLater(() -> {
@Override public void run() {
for (PlotPlayer pp : Plot.this.getPlayersInPlot()) { for (PlotPlayer pp : Plot.this.getPlayersInPlot()) {
PlotListener.plotExit(pp, Plot.this); PlotListener.plotExit(pp, Plot.this);
PlotListener.plotEntry(pp, Plot.this); PlotListener.plotEntry(pp, Plot.this);
} }
}
}, 1); }, 1);
} }
@ -2688,8 +2674,7 @@ public class Plot {
MainUtil.sendMessage(player, C.TELEPORT_IN_SECONDS, Settings.Teleport.DELAY + ""); MainUtil.sendMessage(player, C.TELEPORT_IN_SECONDS, Settings.Teleport.DELAY + "");
final String name = player.getName(); final String name = player.getName();
TaskManager.TELEPORT_QUEUE.add(name); TaskManager.TELEPORT_QUEUE.add(name);
TaskManager.runTaskLater(new Runnable() { TaskManager.runTaskLater(() -> {
@Override public void run() {
if (!TaskManager.TELEPORT_QUEUE.contains(name)) { if (!TaskManager.TELEPORT_QUEUE.contains(name)) {
MainUtil.sendMessage(player, C.TELEPORT_FAILED); MainUtil.sendMessage(player, C.TELEPORT_FAILED);
return; return;
@ -2699,7 +2684,6 @@ public class Plot {
MainUtil.sendMessage(player, C.TELEPORTED_TO_PLOT); MainUtil.sendMessage(player, C.TELEPORTED_TO_PLOT);
player.teleport(location); player.teleport(location);
} }
}
}, Settings.Teleport.DELAY * 20); }, Settings.Teleport.DELAY * 20);
return true; return true;
} }
@ -2885,11 +2869,8 @@ public class Plot {
final Location pos2 = corners[1]; final Location pos2 = corners[1];
Location newPos = pos1.clone().add(offsetX, 0, offsetZ); Location newPos = pos1.clone().add(offsetX, 0, offsetZ);
newPos.setWorld(destination.getWorldName()); newPos.setWorld(destination.getWorldName());
ChunkManager.manager.copyRegion(pos1, pos2, newPos, new Runnable() { ChunkManager.manager.copyRegion(pos1, pos2, newPos,
@Override public void run() { () -> ChunkManager.manager.regenerateRegion(pos1, pos2, false, task));
ChunkManager.manager.regenerateRegion(pos1, pos2, false, task);
}
});
} }
}; };
Runnable swap = new Runnable() { Runnable swap = new Runnable() {