mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 21:26:45 +01:00
Finished schematic importing and chest contents
This commit is contained in:
parent
d89d3cc8ae
commit
8ab2a0d278
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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<Short, Short> 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<Short, Short> 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<Short, Short> blocks = this.plotworld.G_SCH.get(loc);
|
||||
if (blocks != null) {
|
||||
for (final short y : blocks.keySet()) {
|
||||
|
@ -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<ChunkLoc, HashMap<Short, Short>> G_SCH;
|
||||
public HashMap<ChunkLoc, HashMap<Short, Byte>> G_SCH_DATA;
|
||||
public HashMap<PlotLoc, HashMap<Short, Short>> G_SCH;
|
||||
public HashMap<PlotLoc, HashMap<Short, Byte>> G_SCH_DATA;
|
||||
public HashMap<PlotLoc, HashSet<PlotItem>> 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<PlotItem> 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<PlotItem>());
|
||||
}
|
||||
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<Short, Short>());
|
||||
}
|
||||
|
@ -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<Short, Byte> 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<PlotItem> 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<Short, Byte> 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<Short, Byte> 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<PlotItem> 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<Short, Byte> blocks = this.plotworld.G_SCH_DATA.get(loc);
|
||||
if (blocks != null) {
|
||||
for (final short y : blocks.keySet()) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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<Tag> 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();
|
||||
|
@ -1,14 +1,19 @@
|
||||
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);
|
||||
|
||||
public abstract int getBlockIdFromString(String block);
|
||||
|
@ -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);
|
||||
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);
|
||||
if (HEIGHT == BukkitUtil.getMaxHeight(location.getWorld())) {
|
||||
} else {
|
||||
l1.getY();
|
||||
}
|
||||
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,21 +75,52 @@ 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<PlotItem> 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<String, Tag> tagMap = tag.getValue();
|
||||
byte[] addId = new byte[0];
|
||||
@ -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<Tag> blockStates = ListTag.class.cast(tagMap.get("TileEntities")).getValue();
|
||||
for (Tag stateTag : blockStates) {
|
||||
CompoundTag ct = ((CompoundTag) stateTag);
|
||||
Map<String, Tag> 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,6 +300,18 @@ public abstract class SchematicHandler {
|
||||
private final DataCollection[] blockCollection;
|
||||
private final Dimension schematicDimension;
|
||||
private final File file;
|
||||
private HashSet<PlotItem> items;
|
||||
|
||||
public void addItem(PlotItem item) {
|
||||
if (this.items == null) {
|
||||
this.items = new HashSet<>();
|
||||
}
|
||||
items.add(item);
|
||||
}
|
||||
|
||||
public HashSet<PlotItem> getItems() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
public Schematic(final DataCollection[] blockCollection, final Dimension schematicDimension, final File file) {
|
||||
this.blockCollection = blockCollection;
|
||||
|
@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user