From 8ab2a0d27853e12cc370e4ee9eb5c4c832ed501a Mon Sep 17 00:00:00 2001 From: boy0001 Date: Thu, 26 Feb 2015 15:16:52 +1100 Subject: [PATCH] Finished schematic importing and chest contents --- .../intellectualcrafters/plot/BukkitMain.java | 1 - .../plot/commands/Claim.java | 2 +- .../plot/commands/SchematicCmd.java | 11 +- .../plot/generator/HybridGen.java | 8 +- .../plot/generator/HybridPlotWorld.java | 28 ++++- .../plot/generator/HybridPop.java | 41 ++++++- .../plot/object/schematic/PlotItem.java | 19 +++ .../plot/object/schematic/StateWrapper.java | 43 ++++++- .../plot/util/BlockManager.java | 5 + .../plot/util/SchematicHandler.java | 108 +++++++++++++++--- .../plot/util/bukkit/BukkitUtil.java | 26 +++++ 11 files changed, 261 insertions(+), 31 deletions(-) create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/object/schematic/PlotItem.java diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java index 90a85b94b..49ea227c0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java @@ -99,7 +99,6 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { } else { log("&dUsing metrics will allow us to improve the plugin, please consider it :)"); } - System.out.print("REGISTERING EVENTS"); getServer().getPluginManager().registerEvents(this, this); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java index 646ea5bce..afa6813fd 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java @@ -71,7 +71,7 @@ public class Claim extends SubCommand { sch = SchematicHandler.manager.getSchematic(plotworld.SCHEMATIC_FILE); } } - SchematicHandler.manager.paste(player.getLocation(), sch, plot2, 0, 0); + SchematicHandler.manager.paste(sch, plot2, 0, 0); } PlotSquared.getPlotManager(world).claimPlot(plotworld, plot); MainUtil.update(loc); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java index 46692f8fd..dc5b00017 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java @@ -39,6 +39,7 @@ import com.intellectualcrafters.plot.util.SchematicHandler.DataCollection; import com.intellectualcrafters.plot.util.SchematicHandler.Dimension; import com.intellectualcrafters.plot.util.SchematicHandler.Schematic; import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; public class SchematicCmd extends SubCommand { @@ -118,9 +119,16 @@ public class SchematicCmd extends SubCommand { } final DataCollection[] b = schematic.getBlockCollection(); final int sy = BlockManager.manager.getHeighestBlock(bot); - final Location l1 = bot.add(0, sy - 1, 0); final int WIDTH = schematic.getSchematicDimension().getX(); final int LENGTH = schematic.getSchematicDimension().getZ(); + final Location l1; + if (!(schematic.getSchematicDimension().getY() == BukkitUtil.getMaxHeight(loc.getWorld()))) { + l1 = bot.add(0, sy - 1, 0); + } + else { + l1 = bot; + } + final int blen = b.length - 1; SchematicCmd.this.task = TaskManager.runTaskRepeat(new Runnable() { @Override @@ -129,6 +137,7 @@ public class SchematicCmd extends SubCommand { while (!result) { final int start = SchematicCmd.this.counter * 5000; if (start > blen) { + SchematicHandler.manager.pasteStates(schematic, plot, 0, 0); sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS); MainUtil.update(plr.getLocation()); SchematicCmd.this.running = false; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java index 3d60a00c0..26f7b67b0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java @@ -31,7 +31,7 @@ import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.generator.BlockPopulator; -import com.intellectualcrafters.plot.object.ChunkLoc; +import com.intellectualcrafters.plot.object.PlotLoc; import com.intellectualcrafters.plot.object.PlotGenerator; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotWorld; @@ -266,7 +266,7 @@ public class HybridGen extends PlotGenerator { } setBlock(this.result, x, this.plotheight, z, this.plotfloors); } else { - final ChunkLoc loc = new ChunkLoc(X + x, Z + z); + final PlotLoc loc = new PlotLoc((short) (X + x), (short) (Z + z)); final HashMap blocks = ChunkManager.GENERATE_BLOCKS.get(loc); if (blocks != null) { for (final short y : blocks.keySet()) { @@ -304,7 +304,7 @@ public class HybridGen extends PlotGenerator { } setBlock(this.result, x, this.plotheight, z, this.plotfloors); if (this.plotworld.PLOT_SCHEMATIC) { - final ChunkLoc loc = new ChunkLoc(absX, absZ); + final PlotLoc loc = new PlotLoc((short) absX, (short) absZ); final HashMap blocks = this.plotworld.G_SCH.get(loc); if (blocks != null) { for (final short y : blocks.keySet()) { @@ -329,7 +329,7 @@ public class HybridGen extends PlotGenerator { } } if (this.plotworld.ROAD_SCHEMATIC_ENABLED) { - final ChunkLoc loc = new ChunkLoc(absX, absZ); + final PlotLoc loc = new PlotLoc((short) absX, (short) absZ); final HashMap blocks = this.plotworld.G_SCH.get(loc); if (blocks != null) { for (final short y : blocks.keySet()) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java index c3fb50315..f1f73e616 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java @@ -21,6 +21,7 @@ package com.intellectualcrafters.plot.generator; import java.util.HashMap; +import java.util.HashSet; import org.apache.commons.lang.StringUtils; import org.bukkit.configuration.ConfigurationSection; @@ -28,8 +29,9 @@ import org.bukkit.configuration.ConfigurationSection; import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Configuration; -import com.intellectualcrafters.plot.object.ChunkLoc; +import com.intellectualcrafters.plot.object.PlotLoc; import com.intellectualcrafters.plot.object.PlotBlock; +import com.intellectualcrafters.plot.object.schematic.PlotItem; import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.SchematicHandler.DataCollection; import com.intellectualcrafters.plot.util.SchematicHandler.Dimension; @@ -50,8 +52,9 @@ public class HybridPlotWorld extends ClassicPlotWorld { super(worldname); } - public HashMap> G_SCH; - public HashMap> G_SCH_DATA; + public HashMap> G_SCH; + public HashMap> G_SCH_DATA; + public HashMap> G_SCH_STATE; /** * This method is called when a world loads. Make sure you set all your constants here. You are provided with the @@ -130,6 +133,23 @@ public class HybridPlotWorld extends ClassicPlotWorld { } } } + HashSet items = schem3.getItems(); + if (items != null) { + G_SCH_STATE = new HashMap<>(); + for (PlotItem item : items) { + item.x += shift + oddshift + center_shift_x; + item.z += shift + oddshift + center_shift_z; + item.y += this.PLOT_HEIGHT; + int x = item.x; + int y = item.y; + int z = item.z; + PlotLoc loc = new PlotLoc((short) x, (short) z); + if (!G_SCH_STATE.containsKey(loc)) { + G_SCH_STATE.put(loc, new HashSet()); + } + G_SCH_STATE.get(loc).add(item); + } + } } if ((schem1 == null) || (schem2 == null) || (this.ROAD_WIDTH == 0)) { PlotSquared.log(C.PREFIX.s() + "&3 - schematic: &7false"); @@ -300,7 +320,7 @@ public class HybridPlotWorld extends ClassicPlotWorld { if (x < 0) { x += this.SIZE; } - final ChunkLoc loc = new ChunkLoc(x, z); + final PlotLoc loc = new PlotLoc(x, z); if (!this.G_SCH.containsKey(loc)) { this.G_SCH.put(loc, new HashMap()); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPop.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPop.java index 33ff0691c..641d9c8af 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPop.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPop.java @@ -1,6 +1,7 @@ package com.intellectualcrafters.plot.generator; import java.util.HashMap; +import java.util.HashSet; import java.util.Random; import org.bukkit.Chunk; @@ -9,9 +10,11 @@ import org.bukkit.block.Biome; import org.bukkit.generator.BlockPopulator; import com.intellectualcrafters.plot.PlotSquared; -import com.intellectualcrafters.plot.object.ChunkLoc; +import com.intellectualcrafters.plot.object.PlotLoc; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.RegionWrapper; +import com.intellectualcrafters.plot.object.schematic.PlotItem; +import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.ChunkManager; /** @@ -138,8 +141,23 @@ public class HybridPop extends BlockPopulator { if (this.doFloor) { setBlock(w, x, (short) this.plotheight, z, this.plotfloors); } + if (this.plotworld.PLOT_SCHEMATIC) { + final PlotLoc loc = new PlotLoc((short) (this.X + x), (short) (this.Z + z)); + final HashMap blocks = this.plotworld.G_SCH_DATA.get(loc); + if (blocks != null) { + for (final short y : blocks.keySet()) { + setBlock(w, x, (short) (this.plotheight + y), z, blocks.get(y)); + } + } + HashSet states = this.plotworld.G_SCH_STATE.get(loc); + if (states != null) { + for (PlotItem items : states) { + BlockManager.manager.addItems(this.plotworld.worldname, items); + } + } + } } else { - final ChunkLoc loc = new ChunkLoc(this.X + x, this.Z + z); + final PlotLoc loc = new PlotLoc((short) (this.X + x), (short) (this.Z + z)); final HashMap data = ChunkManager.GENERATE_DATA.get(loc); if (data != null) { for (final short y : data.keySet()) { @@ -178,6 +196,23 @@ public class HybridPop extends BlockPopulator { if (this.doFloor) { setBlock(w, x, (short) this.plotheight, z, this.plotfloors); } + if (this.plotworld.PLOT_SCHEMATIC) { + final PlotLoc loc = new PlotLoc(absX, absZ); + final HashMap blocks = this.plotworld.G_SCH_DATA.get(loc); + if (blocks != null) { + for (final short y : blocks.keySet()) { + setBlock(w, x, (short) (this.plotheight + y), z, blocks.get(y)); + } + } + HashSet states = this.plotworld.G_SCH_STATE.get(loc); + if (states != null) { + for (PlotItem items : states) { + items.x = this.X + x; + items.z = this.Z + z; + BlockManager.manager.addItems(this.plotworld.worldname, items); + } + } + } } else { // wall if (((absX >= this.pathWidthLower) && (absX <= this.pathWidthUpper) && (absZ >= this.pathWidthLower) && (absZ <= this.pathWidthUpper))) { @@ -199,7 +234,7 @@ public class HybridPop extends BlockPopulator { } } if (this.plotworld.ROAD_SCHEMATIC_ENABLED) { - final ChunkLoc loc = new ChunkLoc(absX, absZ); + final PlotLoc loc = new PlotLoc(absX, absZ); final HashMap blocks = this.plotworld.G_SCH_DATA.get(loc); if (blocks != null) { for (final short y : blocks.keySet()) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/schematic/PlotItem.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/schematic/PlotItem.java new file mode 100644 index 000000000..3fb4c8b88 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/schematic/PlotItem.java @@ -0,0 +1,19 @@ +package com.intellectualcrafters.plot.object.schematic; + +public class PlotItem { + public int x; + public int y; + public int z; + public short[] id; + public byte[] data; + public byte[] amount; + + public PlotItem(short x, short y, short z, short[] id, byte[] data, byte[] amount) { + this.x = x; + this.y = y; + this.z = z; + this.id = id; + this.data = data; + this.amount = amount; + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/schematic/StateWrapper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/schematic/StateWrapper.java index f98c3e075..1961ad496 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/schematic/StateWrapper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/schematic/StateWrapper.java @@ -6,6 +6,8 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import org.apache.commons.lang.StringUtils; +import org.bukkit.Material; import org.bukkit.block.BlockState; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.InventoryHolder; @@ -16,16 +18,55 @@ import com.intellectualcrafters.jnbt.CompoundTag; import com.intellectualcrafters.jnbt.ListTag; import com.intellectualcrafters.jnbt.ShortTag; import com.intellectualcrafters.jnbt.Tag; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.util.BlockManager; +import com.intellectualcrafters.plot.util.SchematicHandler.Schematic; public class StateWrapper { - public BlockState state; + public BlockState state = null; + public CompoundTag tag = null; public StateWrapper(BlockState state) { this.state = state; } + public StateWrapper(CompoundTag tag) { + this.tag = tag; + } + + public boolean restoreTag(short x, short y, short z, Schematic schematic) { + if (this.tag == null) { + return false; + } + List itemsTag = this.tag.getListTag("Items").getValue(); + int length = itemsTag.size(); + short[] ids = new short[length]; + byte[] datas = new byte[length]; + byte[] amounts = new byte[length]; + for (int i = 0; i < length; i++) { + Tag itemTag = itemsTag.get(i); + CompoundTag itemComp = (CompoundTag) itemTag; + short id = itemComp.getShort("id"); + String idStr = itemComp.getString("id"); + if (!StringUtils.isNumeric(idStr) && idStr != null) { + idStr = idStr.split(":")[1]; + id = (short) Material.valueOf(idStr.toUpperCase()).getId(); + } + ids[i] = id; + datas[i] = (byte) itemComp.getShort("Damage"); + amounts[i] = itemComp.getByte("Count"); + } + if (length != 0) { + schematic.addItem(new PlotItem(x, y, z, ids, datas, amounts)); + } + return true; + } + public CompoundTag getTag() { + if (this.tag != null) { + return this.tag; + } if (state instanceof InventoryHolder) { InventoryHolder inv = (InventoryHolder) state; ItemStack[] contents = inv.getInventory().getContents(); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockManager.java index 9b372b980..b50a5bcce 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockManager.java @@ -1,13 +1,18 @@ package com.intellectualcrafters.plot.util; +import org.bukkit.inventory.ItemStack; + import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PseudoRandom; +import com.intellectualcrafters.plot.object.schematic.PlotItem; public abstract class BlockManager { public static BlockManager manager; public abstract String[] getBiomeList(); + + public abstract boolean addItems(String world, PlotItem items); public abstract int getBiomeFromString(String biome); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java index 10d37e81d..539cad27b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java @@ -6,20 +6,29 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; +import org.bukkit.block.BlockState; + import com.intellectualcrafters.jnbt.ByteArrayTag; import com.intellectualcrafters.jnbt.CompoundTag; +import com.intellectualcrafters.jnbt.IntTag; +import com.intellectualcrafters.jnbt.ListTag; import com.intellectualcrafters.jnbt.NBTInputStream; import com.intellectualcrafters.jnbt.NBTOutputStream; import com.intellectualcrafters.jnbt.ShortTag; import com.intellectualcrafters.jnbt.Tag; import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.commands.Set; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.schematic.PlotItem; +import com.intellectualcrafters.plot.object.schematic.StateWrapper; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; public abstract class SchematicHandler { @@ -34,7 +43,7 @@ public abstract class SchematicHandler { * * @return true if succeeded */ - public boolean paste(final Location location, final Schematic schematic, final Plot plot, final int x_offset, final int z_offset) { + public boolean paste(final Schematic schematic, final Plot plot, final int x_offset, final int z_offset) { if (schematic == null) { PlotSquared.log("Schematic == null :|"); return false; @@ -46,12 +55,16 @@ public abstract class SchematicHandler { final int HEIGHT = demensions.getY(); final DataCollection[] blocks = schematic.getBlockCollection(); Location l1 = MainUtil.getPlotBottomLoc(plot.world, plot.getId()); - final int sy = BukkitUtil.getHeighestBlock(location.getWorld(), l1.getX() + 1, l1.getZ() + 1); - l1 = l1.add(1, sy - 1, 1); - if (HEIGHT == BukkitUtil.getMaxHeight(location.getWorld())) { - } else { - l1.getY(); + final int sy = BukkitUtil.getHeighestBlock(plot.world, l1.getX() + 1, l1.getZ() + 1); + if (!(HEIGHT == BukkitUtil.getMaxHeight(plot.world))) { + l1 = l1.add(1, sy - 1, 1); } + else { + l1 = l1.add(1, 0, 1); + } + int X = l1.getX(); + int Y = l1.getY(); + int Z = l1.getZ(); final int[] xl = new int[blocks.length]; final int[] yl = new int[blocks.length]; final int[] zl = new int[blocks.length]; @@ -62,20 +75,51 @@ public abstract class SchematicHandler { for (int y = 0; y < HEIGHT; y++) { final int index = (y * WIDTH * LENGTH) + (z * WIDTH) + x; final DataCollection block = blocks[index]; - xl[index] = x; - yl[index] = y; - zl[index] = z; + xl[index] = x + X; + yl[index] = y + Y; + zl[index] = z + Z; ids[index] = block.block; data[index] = block.data; } } } BlockManager.setBlocks(plot.world, xl, yl, zl, ids, data); + pasteStates(schematic, plot, x_offset, z_offset); } catch (final Exception e) { return false; } return true; } + + public boolean pasteStates(final Schematic schematic, final Plot plot, final int x_offset, final int z_offset) { + if (schematic == null) { + PlotSquared.log("Schematic == null :|"); + return false; + } + HashSet items = schematic.getItems(); + if (items == null) { + return false; + } + Location l1 = MainUtil.getPlotBottomLoc(plot.world, plot.getId()); + final int sy = BukkitUtil.getHeighestBlock(plot.world, l1.getX() + 1, l1.getZ() + 1); + final Dimension demensions = schematic.getSchematicDimension(); + final int HEIGHT = demensions.getY(); + if (!(HEIGHT == BukkitUtil.getMaxHeight(plot.world))) { + l1 = l1.add(1, sy - 1, 1); + } else { + l1 = l1.add(1, 0, 1); + } + int X = l1.getX() + x_offset; + int Y = l1.getY(); + int Z = l1.getZ() + z_offset; + for (PlotItem item : items) { + item.x += X; + item.y += Y; + item.z += Z; + BlockManager.manager.addItems(plot.world, item); + } + return true; + } public Schematic getSchematic(final CompoundTag tag, final File file) { final Map tagMap = tag.getValue(); @@ -106,7 +150,22 @@ public abstract class SchematicHandler { for (int x = 0; x < b.length; x++) { collection[x] = new DataCollection(blocks[x], d[x]); } - return new Schematic(collection, dimension, file); + Schematic schem = new Schematic(collection, dimension, file); + try { + List blockStates = ListTag.class.cast(tagMap.get("TileEntities")).getValue(); + for (Tag stateTag : blockStates) { + CompoundTag ct = ((CompoundTag) stateTag); + Map state = ct.getValue(); + short x = IntTag.class.cast(state.get("x")).getValue().shortValue(); + short y = IntTag.class.cast(state.get("y")).getValue().shortValue(); + short z = IntTag.class.cast(state.get("z")).getValue().shortValue(); + new StateWrapper(ct).restoreTag(x, y, z, schem); + } + } + catch (Exception e) { + e.printStackTrace(); + } + return schem; } /** @@ -196,7 +255,12 @@ public abstract class SchematicHandler { length++; } } - length = i2 - length; + length = i2 - i1 - length + 1; + + int X = l1.getX(); + int Y = l1.getY(); + int Z = l1.getZ(); + final int[] xl = new int[length]; final int[] yl = new int[length]; final int[] zl = new int[length]; @@ -206,19 +270,19 @@ public abstract class SchematicHandler { for (int i = i1; i <= i2; i++) { final short id = blocks[i].block; if (id == 0) { - continue; + continue; // } - count++; final int area = WIDTH * LENGTH; final int r = i % (area); final int x = r % WIDTH; final int y = i / area; final int z = r / WIDTH; - xl[count] = x; - yl[count] = y; - zl[count] = z; + xl[count] = x + X; + yl[count] = y + Y; + zl[count] = z + Z; ids[count] = id; data[count] = blocks[i].data; + count++; if (y > 256) { break; } @@ -236,7 +300,19 @@ public abstract class SchematicHandler { private final DataCollection[] blockCollection; private final Dimension schematicDimension; private final File file; + private HashSet items; + public void addItem(PlotItem item) { + if (this.items == null) { + this.items = new HashSet<>(); + } + items.add(item); + } + + public HashSet getItems() { + return this.items; + } + public Schematic(final DataCollection[] blockCollection, final Dimension schematicDimension, final File file) { this.blockCollection = blockCollection; this.schematicDimension = schematicDimension; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitUtil.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitUtil.java index 1fd49fee2..d127b70b8 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitUtil.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitUtil.java @@ -15,11 +15,15 @@ import org.bukkit.block.BlockState; import org.bukkit.block.Sign; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; import com.intellectualcrafters.plot.object.BukkitPlayer; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.schematic.PlotItem; import com.intellectualcrafters.plot.util.BlockManager; public class BukkitUtil extends BlockManager { @@ -257,4 +261,26 @@ public class BukkitUtil extends BlockManager { } return material.getId(); } + + @Override + public boolean addItems(String worldname, PlotItem items) { + World world = getWorld(worldname); + Block block = world.getBlockAt(items.x, items.y, items.z); + if (block == null) { + return false; + } + BlockState state = block.getState(); + if (state != null && state instanceof InventoryHolder) { + InventoryHolder holder = ((InventoryHolder) state); + Inventory inv = holder.getInventory(); + for (int i = 0; i < items.id.length; i++) { + ItemStack item = new ItemStack(items.id[i], items.amount[i], items.data[i]); + inv.addItem(item); + } + state.update(true); + return true; + } + return false; + + } }