mirror of
				https://github.com/IntellectualSites/PlotSquared.git
				synced 2025-11-04 11:13:45 +01:00 
			
		
		
		
	Fix schematic pasting to paste tile entities and blocks with BlockData (e.g. stairs) properly
This commit is contained in:
		@@ -1,11 +1,13 @@
 | 
				
			|||||||
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.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.Sign;
 | 
				
			||||||
import org.bukkit.enchantments.Enchantment;
 | 
					import org.bukkit.enchantments.Enchantment;
 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					import org.bukkit.inventory.Inventory;
 | 
				
			||||||
import org.bukkit.inventory.InventoryHolder;
 | 
					import org.bukkit.inventory.InventoryHolder;
 | 
				
			||||||
@@ -30,11 +32,125 @@ public class StateWrapper {
 | 
				
			|||||||
        this.tag = tag;
 | 
					        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) {
 | 
					    public boolean restoreTag(String worldName, int x, int y, int z) {
 | 
				
			||||||
        if (this.tag == null) {
 | 
					        if (this.tag == null) {
 | 
				
			||||||
            return false;
 | 
					            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":
 | 
					            case "chest":
 | 
				
			||||||
                List<Tag> itemsTag = this.tag.getListTag("Items").getValue();
 | 
					                List<Tag> itemsTag = this.tag.getListTag("Items").getValue();
 | 
				
			||||||
                int length = itemsTag.size();
 | 
					                int length = itemsTag.size();
 | 
				
			||||||
@@ -44,17 +160,11 @@ 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");
 | 
				
			||||||
                    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");
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                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) {
 | 
					                if (state instanceof InventoryHolder) {
 | 
				
			||||||
                    InventoryHolder holder = (InventoryHolder) state;
 | 
					                    InventoryHolder holder = (InventoryHolder) state;
 | 
				
			||||||
                    Inventory inv = holder.getInventory();
 | 
					                    Inventory inv = holder.getInventory();
 | 
				
			||||||
@@ -66,6 +176,18 @@ public class StateWrapper {
 | 
				
			|||||||
                    state.update(true);
 | 
					                    state.update(true);
 | 
				
			||||||
                    return 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;
 | 
					        return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -119,4 +241,5 @@ public class StateWrapper {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        return data;
 | 
					        return data;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,6 @@
 | 
				
			|||||||
package com.github.intellectualsites.plotsquared.bukkit.util.block;
 | 
					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.PlotSquared;
 | 
				
			||||||
import com.github.intellectualsites.plotsquared.plot.object.LegacyPlotBlock;
 | 
					import com.github.intellectualsites.plotsquared.plot.object.LegacyPlotBlock;
 | 
				
			||||||
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
 | 
					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.MainUtil;
 | 
				
			||||||
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
 | 
					import com.github.intellectualsites.plotsquared.plot.util.StringMan;
 | 
				
			||||||
import com.github.intellectualsites.plotsquared.plot.util.block.BasicLocalBlockQueue;
 | 
					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 lombok.NonNull;
 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
import org.bukkit.Chunk;
 | 
					import org.bukkit.Chunk;
 | 
				
			||||||
@@ -67,8 +71,11 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override public final void setComponents(LocalChunk<T> lc) {
 | 
					    @Override public final void setComponents(LocalChunk<T> lc) {
 | 
				
			||||||
        setBlocks(lc);
 | 
					        if (isBaseBlocks()) {
 | 
				
			||||||
        setBiomes(lc);
 | 
					            setBaseBlocks(lc);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            setBlocks(lc);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public World getBukkitWorld() {
 | 
					    public World getBukkitWorld() {
 | 
				
			||||||
@@ -93,15 +100,6 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
 | 
				
			|||||||
                        int y = MainUtil.y_loc[layer][j];
 | 
					                        int y = MainUtil.y_loc[layer][j];
 | 
				
			||||||
                        int z = MainUtil.z_loc[layer][j];
 | 
					                        int z = MainUtil.z_loc[layer][j];
 | 
				
			||||||
                        Block existing = chunk.getBlock(x, y, z);
 | 
					                        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)) {
 | 
					                        if (equals(block, existing)) {
 | 
				
			||||||
                            continue;
 | 
					                            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) {
 | 
					    private void setMaterial(@NonNull final PlotBlock plotBlock, @NonNull final Block block) {
 | 
				
			||||||
        final Material material;
 | 
					        final Material material;
 | 
				
			||||||
        if (plotBlock instanceof StringPlotBlock) {
 | 
					        if (plotBlock instanceof StringPlotBlock) {
 | 
				
			||||||
@@ -125,7 +158,8 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
 | 
				
			|||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            final LegacyPlotBlock legacyPlotBlock = (LegacyPlotBlock) plotBlock;
 | 
					            final LegacyPlotBlock legacyPlotBlock = (LegacyPlotBlock) plotBlock;
 | 
				
			||||||
            material = PlotSquared.get().IMP.getLegacyMappings()
 | 
					            material = PlotSquared.get().IMP.getLegacyMappings()
 | 
				
			||||||
                .fromLegacyToString(legacyPlotBlock.getId(), legacyPlotBlock.getData()).to(Material.class);
 | 
					                .fromLegacyToString(legacyPlotBlock.getId(), legacyPlotBlock.getData())
 | 
				
			||||||
 | 
					                .to(Material.class);
 | 
				
			||||||
            if (material == null) {
 | 
					            if (material == null) {
 | 
				
			||||||
                throw new IllegalStateException(String
 | 
					                throw new IllegalStateException(String
 | 
				
			||||||
                    .format("Could not find material that matches %s", legacyPlotBlock.toString()));
 | 
					                    .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;
 | 
					        final LegacyPlotBlock legacyPlotBlock = (LegacyPlotBlock) plotBlock;
 | 
				
			||||||
        return Material.getMaterial(PlotSquared.get().IMP.getLegacyMappings()
 | 
					        return Material.getMaterial(PlotSquared.get().IMP.getLegacyMappings()
 | 
				
			||||||
            .fromLegacyToString(((LegacyPlotBlock) plotBlock).id, ((LegacyPlotBlock) plotBlock).data).toString()) == block.getType()
 | 
					            .fromLegacyToString(((LegacyPlotBlock) plotBlock).id,
 | 
				
			||||||
            && (legacyPlotBlock.id == 0 || legacyPlotBlock.data == block.getData());
 | 
					                ((LegacyPlotBlock) plotBlock).data).toString()) == block.getType() && (
 | 
				
			||||||
 | 
					            legacyPlotBlock.id == 0 || legacyPlotBlock.data == block.getData());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void setBiomes(LocalChunk<T> lc) {
 | 
					    public void setBiomes(LocalChunk<T> lc) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -50,9 +50,9 @@ public class Load extends SubCommand {
 | 
				
			|||||||
                    MainUtil.sendMessage(player, C.LOAD_NULL);
 | 
					                    MainUtil.sendMessage(player, C.LOAD_NULL);
 | 
				
			||||||
                    return false;
 | 
					                    return false;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                String schematic;
 | 
					                String schem;
 | 
				
			||||||
                try {
 | 
					                try {
 | 
				
			||||||
                    schematic = schematics.get(Integer.parseInt(args[0]) - 1);
 | 
					                    schem = schematics.get(Integer.parseInt(args[0]) - 1);
 | 
				
			||||||
                } catch (Exception ignored) {
 | 
					                } catch (Exception ignored) {
 | 
				
			||||||
                    // use /plot load <index>
 | 
					                    // use /plot load <index>
 | 
				
			||||||
                    MainUtil
 | 
					                    MainUtil
 | 
				
			||||||
@@ -61,7 +61,7 @@ public class Load extends SubCommand {
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
                final URL url;
 | 
					                final URL url;
 | 
				
			||||||
                try {
 | 
					                try {
 | 
				
			||||||
                    url = new URL(Settings.Web.URL + "saves/" + player.getUUID() + '/' + schematic);
 | 
					                    url = new URL(Settings.Web.URL + "saves/" + player.getUUID() + '/' + schem);
 | 
				
			||||||
                } catch (MalformedURLException e) {
 | 
					                } catch (MalformedURLException e) {
 | 
				
			||||||
                    e.printStackTrace();
 | 
					                    e.printStackTrace();
 | 
				
			||||||
                    MainUtil.sendMessage(player, C.LOAD_FAILED);
 | 
					                    MainUtil.sendMessage(player, C.LOAD_FAILED);
 | 
				
			||||||
@@ -69,29 +69,27 @@ public class Load extends SubCommand {
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
                plot.addRunning();
 | 
					                plot.addRunning();
 | 
				
			||||||
                MainUtil.sendMessage(player, C.GENERATING_COMPONENT);
 | 
					                MainUtil.sendMessage(player, C.GENERATING_COMPONENT);
 | 
				
			||||||
                TaskManager.runTaskAsync(new Runnable() {
 | 
					                TaskManager.runTaskAsync(() -> {
 | 
				
			||||||
                    @Override public void run() {
 | 
					                    Schematic schematic = SchematicHandler.manager.getSchematic(url);
 | 
				
			||||||
                        Schematic schematic = SchematicHandler.manager.getSchematic(url);
 | 
					                    if (schematic == null) {
 | 
				
			||||||
                        if (schematic == null) {
 | 
					                        plot.removeRunning();
 | 
				
			||||||
                            plot.removeRunning();
 | 
					                        sendMessage(player, C.SCHEMATIC_INVALID,
 | 
				
			||||||
                            sendMessage(player, C.SCHEMATIC_INVALID,
 | 
					                            "non-existent or not in gzip format");
 | 
				
			||||||
                                "non-existent or not in gzip format");
 | 
					                        return;
 | 
				
			||||||
                            return;
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                        PlotArea area = plot.getArea();
 | 
					 | 
				
			||||||
                        SchematicHandler.manager
 | 
					 | 
				
			||||||
                            .paste(schematic, plot, 0, area.MIN_BUILD_HEIGHT, 0, false,
 | 
					 | 
				
			||||||
                                new RunnableVal<Boolean>() {
 | 
					 | 
				
			||||||
                                    @Override public void run(Boolean value) {
 | 
					 | 
				
			||||||
                                        plot.removeRunning();
 | 
					 | 
				
			||||||
                                        if (value) {
 | 
					 | 
				
			||||||
                                            sendMessage(player, C.SCHEMATIC_PASTE_SUCCESS);
 | 
					 | 
				
			||||||
                                        } else {
 | 
					 | 
				
			||||||
                                            sendMessage(player, C.SCHEMATIC_PASTE_FAILED);
 | 
					 | 
				
			||||||
                                        }
 | 
					 | 
				
			||||||
                                    }
 | 
					 | 
				
			||||||
                                });
 | 
					 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					                    PlotArea area = plot.getArea();
 | 
				
			||||||
 | 
					                    SchematicHandler.manager
 | 
				
			||||||
 | 
					                        .paste(schematic, plot, 0, area.MIN_BUILD_HEIGHT, 0, false,
 | 
				
			||||||
 | 
					                            new RunnableVal<Boolean>() {
 | 
				
			||||||
 | 
					                                @Override public void run(Boolean value) {
 | 
				
			||||||
 | 
					                                    plot.removeRunning();
 | 
				
			||||||
 | 
					                                    if (value) {
 | 
				
			||||||
 | 
					                                        sendMessage(player, C.SCHEMATIC_PASTE_SUCCESS);
 | 
				
			||||||
 | 
					                                    } else {
 | 
				
			||||||
 | 
					                                        sendMessage(player, C.SCHEMATIC_PASTE_FAILED);
 | 
				
			||||||
 | 
					                                    }
 | 
				
			||||||
 | 
					                                }
 | 
				
			||||||
 | 
					                            });
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
                return true;
 | 
					                return true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -55,47 +55,45 @@ public class SchematicCmd extends SubCommand {
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
                final String location = args[1];
 | 
					                final String location = args[1];
 | 
				
			||||||
                this.running = true;
 | 
					                this.running = true;
 | 
				
			||||||
                TaskManager.runTaskAsync(new Runnable() {
 | 
					                TaskManager.runTaskAsync(() -> {
 | 
				
			||||||
                    @Override public void run() {
 | 
					                    Schematic schematic = null;
 | 
				
			||||||
                        Schematic schematic = null;
 | 
					                    if (location.startsWith("url:")) {
 | 
				
			||||||
                        if (location.startsWith("url:")) {
 | 
					                        try {
 | 
				
			||||||
                            try {
 | 
					                            UUID uuid = UUID.fromString(location.substring(4));
 | 
				
			||||||
                                UUID uuid = UUID.fromString(location.substring(4));
 | 
					                            URL base = new URL(Settings.Web.URL);
 | 
				
			||||||
                                URL base = new URL(Settings.Web.URL);
 | 
					                            URL url = new URL(base, "uploads/" + uuid + ".schematic");
 | 
				
			||||||
                                URL url = new URL(base, "uploads/" + uuid + ".schematic");
 | 
					                            schematic = SchematicHandler.manager.getSchematic(url);
 | 
				
			||||||
                                schematic = SchematicHandler.manager.getSchematic(url);
 | 
					                        } catch (Exception e) {
 | 
				
			||||||
                            } catch (Exception e) {
 | 
					                            e.printStackTrace();
 | 
				
			||||||
                                e.printStackTrace();
 | 
					 | 
				
			||||||
                                sendMessage(player, C.SCHEMATIC_INVALID,
 | 
					 | 
				
			||||||
                                    "non-existent url: " + location);
 | 
					 | 
				
			||||||
                                SchematicCmd.this.running = false;
 | 
					 | 
				
			||||||
                                return;
 | 
					 | 
				
			||||||
                            }
 | 
					 | 
				
			||||||
                        } else {
 | 
					 | 
				
			||||||
                            try {
 | 
					 | 
				
			||||||
                                schematic = SchematicHandler.manager.getSchematic(location);
 | 
					 | 
				
			||||||
                            } catch (SchematicHandler.UnsupportedFormatException e) {
 | 
					 | 
				
			||||||
                                e.printStackTrace();
 | 
					 | 
				
			||||||
                            }
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                        if (schematic == null) {
 | 
					 | 
				
			||||||
                            SchematicCmd.this.running = false;
 | 
					 | 
				
			||||||
                            sendMessage(player, C.SCHEMATIC_INVALID,
 | 
					                            sendMessage(player, C.SCHEMATIC_INVALID,
 | 
				
			||||||
                                "non-existent or not in gzip format");
 | 
					                                "non-existent url: " + location);
 | 
				
			||||||
 | 
					                            SchematicCmd.this.running = false;
 | 
				
			||||||
                            return;
 | 
					                            return;
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                        SchematicHandler.manager
 | 
					                    } else {
 | 
				
			||||||
                            .paste(schematic, plot, 0, 1, 0, false, new RunnableVal<Boolean>() {
 | 
					                        try {
 | 
				
			||||||
                                @Override public void run(Boolean value) {
 | 
					                            schematic = SchematicHandler.manager.getSchematic(location);
 | 
				
			||||||
                                    SchematicCmd.this.running = false;
 | 
					                        } catch (SchematicHandler.UnsupportedFormatException e) {
 | 
				
			||||||
                                    if (value) {
 | 
					                            e.printStackTrace();
 | 
				
			||||||
                                        sendMessage(player, C.SCHEMATIC_PASTE_SUCCESS);
 | 
					                        }
 | 
				
			||||||
                                    } else {
 | 
					 | 
				
			||||||
                                        sendMessage(player, C.SCHEMATIC_PASTE_FAILED);
 | 
					 | 
				
			||||||
                                    }
 | 
					 | 
				
			||||||
                                }
 | 
					 | 
				
			||||||
                            });
 | 
					 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					                    if (schematic == null) {
 | 
				
			||||||
 | 
					                        SchematicCmd.this.running = false;
 | 
				
			||||||
 | 
					                        sendMessage(player, C.SCHEMATIC_INVALID,
 | 
				
			||||||
 | 
					                            "non-existent or not in gzip format");
 | 
				
			||||||
 | 
					                        return;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    SchematicHandler.manager
 | 
				
			||||||
 | 
					                        .paste(schematic, plot, 0, 1, 0, false, new RunnableVal<Boolean>() {
 | 
				
			||||||
 | 
					                            @Override public void run(Boolean value) {
 | 
				
			||||||
 | 
					                                SchematicCmd.this.running = false;
 | 
				
			||||||
 | 
					                                if (value) {
 | 
				
			||||||
 | 
					                                    sendMessage(player, C.SCHEMATIC_PASTE_SUCCESS);
 | 
				
			||||||
 | 
					                                } else {
 | 
				
			||||||
 | 
					                                    sendMessage(player, C.SCHEMATIC_PASTE_FAILED);
 | 
				
			||||||
 | 
					                                }
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                        });
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -153,12 +151,8 @@ public class SchematicCmd extends SubCommand {
 | 
				
			|||||||
                        .sendMessage(player, "&cInvalid world. Use &7/plot sch exportall <area>");
 | 
					                        .sendMessage(player, "&cInvalid world. Use &7/plot sch exportall <area>");
 | 
				
			||||||
                    return false;
 | 
					                    return false;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                boolean result =
 | 
					                boolean result = SchematicHandler.manager.exportAll(plots, null, null,
 | 
				
			||||||
                    SchematicHandler.manager.exportAll(plots, null, null, new Runnable() {
 | 
					                    () -> MainUtil.sendMessage(player, "&aFinished mass export"));
 | 
				
			||||||
                        @Override public void run() {
 | 
					 | 
				
			||||||
                            MainUtil.sendMessage(player, "&aFinished mass export");
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                    });
 | 
					 | 
				
			||||||
                if (!result) {
 | 
					                if (!result) {
 | 
				
			||||||
                    MainUtil.sendMessage(player, "&cTask is already running.");
 | 
					                    MainUtil.sendMessage(player, "&cTask is already running.");
 | 
				
			||||||
                    return false;
 | 
					                    return false;
 | 
				
			||||||
@@ -197,13 +191,10 @@ public class SchematicCmd extends SubCommand {
 | 
				
			|||||||
                location.getWorld();
 | 
					                location.getWorld();
 | 
				
			||||||
                Collection<Plot> plots = new ArrayList<>();
 | 
					                Collection<Plot> plots = new ArrayList<>();
 | 
				
			||||||
                plots.add(plot);
 | 
					                plots.add(plot);
 | 
				
			||||||
                boolean result =
 | 
					                boolean result = SchematicHandler.manager.exportAll(plots, null, null, () -> {
 | 
				
			||||||
                    SchematicHandler.manager.exportAll(plots, null, null, new Runnable() {
 | 
					                    MainUtil.sendMessage(player, "&aFinished export");
 | 
				
			||||||
                        @Override public void run() {
 | 
					                    SchematicCmd.this.running = false;
 | 
				
			||||||
                            MainUtil.sendMessage(player, "&aFinished export");
 | 
					                });
 | 
				
			||||||
                            SchematicCmd.this.running = false;
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                    });
 | 
					 | 
				
			||||||
                if (!result) {
 | 
					                if (!result) {
 | 
				
			||||||
                    MainUtil.sendMessage(player, "&cTask is already running.");
 | 
					                    MainUtil.sendMessage(player, "&cTask is already running.");
 | 
				
			||||||
                    return false;
 | 
					                    return false;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -180,19 +180,10 @@ public abstract class SchematicHandler {
 | 
				
			|||||||
                final int bcz = p1z >> 4;
 | 
					                final int bcz = p1z >> 4;
 | 
				
			||||||
                final int tcx = p2x >> 4;
 | 
					                final int tcx = p2x >> 4;
 | 
				
			||||||
                final int tcz = p2z >> 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[]>() {
 | 
					                ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
 | 
				
			||||||
                    @Override public void run(int[] value) {
 | 
					                    @Override public void run(int[] value) {
 | 
				
			||||||
                        //int count = 0;
 | 
					 | 
				
			||||||
                        //while (!chunks.isEmpty() && count < 256) {
 | 
					 | 
				
			||||||
                        //count++;
 | 
					 | 
				
			||||||
                        ChunkLoc chunk = new ChunkLoc(value[0], value[1]);
 | 
					                        ChunkLoc chunk = new ChunkLoc(value[0], value[1]);
 | 
				
			||||||
                        PlotSquared.log(chunk.toString());
 | 
					 | 
				
			||||||
                        int x = chunk.x;
 | 
					                        int x = chunk.x;
 | 
				
			||||||
                        int z = chunk.z;
 | 
					                        int z = chunk.z;
 | 
				
			||||||
                        int xxb = x << 4;
 | 
					                        int xxb = x << 4;
 | 
				
			||||||
@@ -218,47 +209,24 @@ public abstract class SchematicHandler {
 | 
				
			|||||||
                            if (yy > 255) {
 | 
					                            if (yy > 255) {
 | 
				
			||||||
                                continue;
 | 
					                                continue;
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                            int i1 = ry * WIDTH * LENGTH;
 | 
					 | 
				
			||||||
                            for (int rz = zzb - p1z; rz <= (zzt - p1z); rz++) {
 | 
					                            for (int rz = zzb - p1z; rz <= (zzt - p1z); rz++) {
 | 
				
			||||||
                                int i2 = (rz * WIDTH) + i1;
 | 
					 | 
				
			||||||
                                for (int rx = xxb - p1x; rx <= (xxt - p1x); rx++) {
 | 
					                                for (int rx = xxb - p1x; rx <= (xxt - p1x); rx++) {
 | 
				
			||||||
                                    int i = i2 + rx;
 | 
					                                    int xx = p1x + xOffset + rx;
 | 
				
			||||||
                                    int xx = p1x + rx;
 | 
					                                    int zz = p1z + zOffset + rz;
 | 
				
			||||||
                                    int zz = p1z + rz;
 | 
					 | 
				
			||||||
                                    BaseBlock id = blockArrayClipboard
 | 
					                                    BaseBlock id = blockArrayClipboard
 | 
				
			||||||
                                        .getFullBlock(BlockVector3.at(rx, ry, rz));
 | 
					                                        .getFullBlock(BlockVector3.at(rx, ry, rz));
 | 
				
			||||||
                                    queue.setBlock(xx, yy, zz, id);
 | 
					                                    queue.setBlock(xx, yy, zz, id);
 | 
				
			||||||
                                }
 | 
					                                }
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 | 
					 | 
				
			||||||
                        queue.enqueue();
 | 
					                        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) {
 | 
					                    if (whenDone != null) {
 | 
				
			||||||
                    whenDone.value = true;
 | 
					                        whenDone.value = true;
 | 
				
			||||||
                    whenDone.run();
 | 
					                        whenDone.run();
 | 
				
			||||||
                }
 | 
					                    }
 | 
				
			||||||
 | 
					                }, 10);
 | 
				
			||||||
            } catch (Exception e) {
 | 
					            } catch (Exception e) {
 | 
				
			||||||
                e.printStackTrace();
 | 
					                e.printStackTrace();
 | 
				
			||||||
                TaskManager.runTask(whenDone);
 | 
					                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.MathMan;
 | 
				
			||||||
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
 | 
					import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
 | 
				
			||||||
import com.sk89q.worldedit.world.block.BaseBlock;
 | 
					import com.sk89q.worldedit.world.block.BaseBlock;
 | 
				
			||||||
import lombok.NonNull;
 | 
					import lombok.Getter;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.concurrent.ConcurrentHashMap;
 | 
					import java.util.concurrent.ConcurrentHashMap;
 | 
				
			||||||
import java.util.concurrent.ConcurrentLinkedDeque;
 | 
					import java.util.concurrent.ConcurrentLinkedDeque;
 | 
				
			||||||
@@ -14,12 +14,13 @@ import java.util.concurrent.ConcurrentLinkedDeque;
 | 
				
			|||||||
public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
 | 
					public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private final String world;
 | 
					    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 final ConcurrentLinkedDeque<LocalChunk> chunks = new ConcurrentLinkedDeque<>();
 | 
				
			||||||
    private long modified;
 | 
					    private long modified;
 | 
				
			||||||
    private LocalChunk lastWrappedChunk;
 | 
					    private LocalChunk lastWrappedChunk;
 | 
				
			||||||
    private int lastX = Integer.MIN_VALUE;
 | 
					    private int lastX = Integer.MIN_VALUE;
 | 
				
			||||||
    private int lastZ = Integer.MIN_VALUE;
 | 
					    private int lastZ = Integer.MIN_VALUE;
 | 
				
			||||||
 | 
					    @Getter private boolean baseBlocks = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public BasicLocalBlockQueue(String world) {
 | 
					    public BasicLocalBlockQueue(String world) {
 | 
				
			||||||
        super(world);
 | 
					        super(world);
 | 
				
			||||||
@@ -41,13 +42,13 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
 | 
				
			|||||||
        lastX = Integer.MIN_VALUE;
 | 
					        lastX = Integer.MIN_VALUE;
 | 
				
			||||||
        lastZ = Integer.MIN_VALUE;
 | 
					        lastZ = Integer.MIN_VALUE;
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            if (this.blocks.size() == 0) {
 | 
					            if (this.blockChunks.size() == 0) {
 | 
				
			||||||
                return false;
 | 
					                return false;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            synchronized (blocks) {
 | 
					            synchronized (blockChunks) {
 | 
				
			||||||
                LocalChunk chunk = chunks.poll();
 | 
					                LocalChunk chunk = chunks.poll();
 | 
				
			||||||
                if (chunk != null) {
 | 
					                if (chunk != null) {
 | 
				
			||||||
                    blocks.remove(chunk.longHash());
 | 
					                    blockChunks.remove(chunk.longHash());
 | 
				
			||||||
                    this.execute(chunk);
 | 
					                    this.execute(chunk);
 | 
				
			||||||
                    return true;
 | 
					                    return true;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
@@ -90,22 +91,23 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
 | 
				
			|||||||
        if ((y > 255) || (y < 0)) {
 | 
					        if ((y > 255) || (y < 0)) {
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        baseBlocks = true;
 | 
				
			||||||
        int cx = x >> 4;
 | 
					        int cx = x >> 4;
 | 
				
			||||||
        int cz = z >> 4;
 | 
					        int cz = z >> 4;
 | 
				
			||||||
        if (cx != lastX || cz != lastZ) {
 | 
					        if (cx != lastX || cz != lastZ) {
 | 
				
			||||||
            lastX = cx;
 | 
					            lastX = cx;
 | 
				
			||||||
            lastZ = cz;
 | 
					            lastZ = cz;
 | 
				
			||||||
            long pair = (long) (cx) << 32 | (cz) & 0xFFFFFFFFL;
 | 
					            long pair = (long) (cx) << 32 | (cz) & 0xFFFFFFFFL;
 | 
				
			||||||
            lastWrappedChunk = this.blocks.get(pair);
 | 
					            lastWrappedChunk = this.blockChunks.get(pair);
 | 
				
			||||||
            if (lastWrappedChunk == null) {
 | 
					            if (lastWrappedChunk == null) {
 | 
				
			||||||
                lastWrappedChunk = this.getLocalChunk(x >> 4, z >> 4);
 | 
					                lastWrappedChunk = this.getLocalChunk(x >> 4, z >> 4);
 | 
				
			||||||
                lastWrappedChunk.setBlock(x & 15, y, z & 15, id);
 | 
					                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) {
 | 
					                if (previous == null) {
 | 
				
			||||||
                    chunks.add(lastWrappedChunk);
 | 
					                    chunks.add(lastWrappedChunk);
 | 
				
			||||||
                    return true;
 | 
					                    return true;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                this.blocks.put(pair, previous);
 | 
					                this.blockChunks.put(pair, previous);
 | 
				
			||||||
                lastWrappedChunk = previous;
 | 
					                lastWrappedChunk = previous;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -123,16 +125,16 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
 | 
				
			|||||||
            lastX = cx;
 | 
					            lastX = cx;
 | 
				
			||||||
            lastZ = cz;
 | 
					            lastZ = cz;
 | 
				
			||||||
            long pair = (long) (cx) << 32 | (cz) & 0xFFFFFFFFL;
 | 
					            long pair = (long) (cx) << 32 | (cz) & 0xFFFFFFFFL;
 | 
				
			||||||
            lastWrappedChunk = this.blocks.get(pair);
 | 
					            lastWrappedChunk = this.blockChunks.get(pair);
 | 
				
			||||||
            if (lastWrappedChunk == null) {
 | 
					            if (lastWrappedChunk == null) {
 | 
				
			||||||
                lastWrappedChunk = this.getLocalChunk(x >> 4, z >> 4);
 | 
					                lastWrappedChunk = this.getLocalChunk(x >> 4, z >> 4);
 | 
				
			||||||
                lastWrappedChunk.setBlock(x & 15, y, z & 15, id);
 | 
					                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) {
 | 
					                if (previous == null) {
 | 
				
			||||||
                    chunks.add(lastWrappedChunk);
 | 
					                    chunks.add(lastWrappedChunk);
 | 
				
			||||||
                    return true;
 | 
					                    return true;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                this.blocks.put(pair, previous);
 | 
					                this.blockChunks.put(pair, previous);
 | 
				
			||||||
                lastWrappedChunk = 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) {
 | 
					    @Override public final boolean setBiome(int x, int z, String biome) {
 | 
				
			||||||
        long pair = (long) (x >> 4) << 32 | (z >> 4) & 0xFFFFFFFFL;
 | 
					        long pair = (long) (x >> 4) << 32 | (z >> 4) & 0xFFFFFFFFL;
 | 
				
			||||||
        LocalChunk result = this.blocks.get(pair);
 | 
					        LocalChunk result = this.blockChunks.get(pair);
 | 
				
			||||||
        if (result == null) {
 | 
					        if (result == null) {
 | 
				
			||||||
            result = this.getLocalChunk(x >> 4, z >> 4);
 | 
					            result = this.getLocalChunk(x >> 4, z >> 4);
 | 
				
			||||||
            LocalChunk previous = this.blocks.put(pair, result);
 | 
					            LocalChunk previous = this.blockChunks.put(pair, result);
 | 
				
			||||||
            if (previous != null) {
 | 
					            if (previous != null) {
 | 
				
			||||||
                this.blocks.put(pair, previous);
 | 
					                this.blockChunks.put(pair, previous);
 | 
				
			||||||
                result = previous;
 | 
					                result = previous;
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                chunks.add(result);
 | 
					                chunks.add(result);
 | 
				
			||||||
@@ -158,7 +160,7 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public final void setChunk(LocalChunk<T> chunk) {
 | 
					    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) {
 | 
					        if (previous != null) {
 | 
				
			||||||
            chunks.remove(previous);
 | 
					            chunks.remove(previous);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -182,6 +184,7 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
 | 
				
			|||||||
        public final int x;
 | 
					        public final int x;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public T[] blocks;
 | 
					        public T[] blocks;
 | 
				
			||||||
 | 
					        public BaseBlock[][] baseblocks;
 | 
				
			||||||
        public String[][] biomes;
 | 
					        public String[][] biomes;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public LocalChunk(BasicLocalBlockQueue<T> parent, int x, int z) {
 | 
					        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 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) {
 | 
					        public void setBiome(int x, int z, String biome) {
 | 
				
			||||||
            if (this.biomes == null) {
 | 
					            if (this.biomes == null) {
 | 
				
			||||||
@@ -236,27 +239,13 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
 | 
				
			|||||||
        public BasicLocalChunk(BasicLocalBlockQueue parent, int x, int z) {
 | 
					        public BasicLocalChunk(BasicLocalBlockQueue parent, int x, int z) {
 | 
				
			||||||
            super(parent, x, z);
 | 
					            super(parent, x, z);
 | 
				
			||||||
            blocks = new PlotBlock[16][];
 | 
					            blocks = new PlotBlock[16][];
 | 
				
			||||||
 | 
					            baseblocks = new BaseBlock[16][];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        @Override public void setBlock(int x, int y, int z, PlotBlock block) {
 | 
					        @Override public void setBlock(int x, int y, int z, PlotBlock block) {
 | 
				
			||||||
            this.setInternal(x, y, z, 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) {
 | 
					        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 i = MainUtil.CACHE_I[y][x][z];
 | 
				
			||||||
            final int j = MainUtil.CACHE_J[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;
 | 
					            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) {
 | 
					        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);
 | 
					            final PlotBlock block = PlotBlock.get(id, data);
 | 
				
			||||||
            this.setInternal(x, y, z, block);
 | 
					            this.setInternal(x, y, z, block);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user