mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-28 11:44:42 +02:00
Move bukkit specific files
This commit is contained in:
@ -1,100 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.object;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
/**
|
||||
* Wrapper class for blocks, using pure data rather than the object.
|
||||
*
|
||||
* Useful for NMS
|
||||
*
|
||||
* @author Empire92
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class BlockWrapper {
|
||||
/**
|
||||
* X Coordinate
|
||||
*/
|
||||
public final int x;
|
||||
/**
|
||||
* Y Coordinate
|
||||
*/
|
||||
public final int y;
|
||||
/**
|
||||
* Z Coordinate
|
||||
*/
|
||||
public final int z;
|
||||
/**
|
||||
* Block ID
|
||||
*/
|
||||
public final int id;
|
||||
/**
|
||||
* Block Data Value
|
||||
*/
|
||||
public final byte data;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param x X Loc Value
|
||||
* @param y Y Loc Value
|
||||
* @param z Z Loc Value
|
||||
* @param id Material ID
|
||||
* @param data Data Value
|
||||
*/
|
||||
public BlockWrapper(final int x, final int y, final int z, final short id, final byte data) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.id = id;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alternative Constructor Uses block data, rather than typed data
|
||||
*
|
||||
* @param block Block from which we get the data
|
||||
*/
|
||||
@SuppressWarnings({ "deprecation", "unused" })
|
||||
public BlockWrapper(final Block block) {
|
||||
this.x = block.getX();
|
||||
this.y = block.getY();
|
||||
this.z = block.getZ();
|
||||
this.id = block.getTypeId();
|
||||
this.data = block.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a block based on the block wrapper
|
||||
*
|
||||
* @param world World in which the block is/will be, located
|
||||
*
|
||||
* @return block created/fetched from settings
|
||||
*/
|
||||
@SuppressWarnings({ "unused", "deprecation" })
|
||||
public Block toBlock(final World world) {
|
||||
final Block block = world.getBlockAt(this.x, this.y, this.z);
|
||||
block.setTypeIdAndData(this.id, this.data, true);
|
||||
return block;
|
||||
}
|
||||
}
|
@ -1,138 +0,0 @@
|
||||
package com.intellectualcrafters.plot.object;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
public class BukkitLazyBlock extends LazyBlock {
|
||||
|
||||
private int id = -1;
|
||||
private Block block;
|
||||
private PlotBlock pb;
|
||||
|
||||
|
||||
public BukkitLazyBlock(int id, Block block) {
|
||||
this.id = id;
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
public BukkitLazyBlock(PlotBlock pb) {
|
||||
this.id = pb.id;
|
||||
this.pb = pb;
|
||||
}
|
||||
|
||||
public BukkitLazyBlock(Block block) {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotBlock getPlotBlock() {
|
||||
if (pb != null) {
|
||||
return pb;
|
||||
}
|
||||
if (id == -1 ) {
|
||||
id = block.getTypeId();
|
||||
}
|
||||
byte data;
|
||||
switch(id) {
|
||||
case 0:
|
||||
case 2:
|
||||
case 4:
|
||||
case 13:
|
||||
case 14:
|
||||
case 15:
|
||||
case 20:
|
||||
case 21:
|
||||
case 22:
|
||||
case 24:
|
||||
case 25:
|
||||
case 30:
|
||||
case 32:
|
||||
case 37:
|
||||
case 39:
|
||||
case 40:
|
||||
case 41:
|
||||
case 42:
|
||||
case 45:
|
||||
case 46:
|
||||
case 47:
|
||||
case 48:
|
||||
case 49:
|
||||
case 50:
|
||||
case 51:
|
||||
case 52:
|
||||
case 54:
|
||||
case 55:
|
||||
case 56:
|
||||
case 57:
|
||||
case 58:
|
||||
case 60:
|
||||
case 61:
|
||||
case 62:
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
case 10:
|
||||
case 11:
|
||||
case 73:
|
||||
case 74:
|
||||
case 75:
|
||||
case 76:
|
||||
case 78:
|
||||
case 79:
|
||||
case 80:
|
||||
case 81:
|
||||
case 82:
|
||||
case 83:
|
||||
case 84:
|
||||
case 85:
|
||||
case 87:
|
||||
case 88:
|
||||
case 101:
|
||||
case 102:
|
||||
case 103:
|
||||
case 110:
|
||||
case 112:
|
||||
case 113:
|
||||
case 117:
|
||||
case 121:
|
||||
case 122:
|
||||
case 123:
|
||||
case 124:
|
||||
case 129:
|
||||
case 133:
|
||||
case 138:
|
||||
case 137:
|
||||
case 140:
|
||||
case 165:
|
||||
case 166:
|
||||
case 169:
|
||||
case 170:
|
||||
case 172:
|
||||
case 173:
|
||||
case 174:
|
||||
case 176:
|
||||
case 177:
|
||||
case 181:
|
||||
case 182:
|
||||
case 188:
|
||||
case 189:
|
||||
case 190:
|
||||
case 191:
|
||||
case 192:
|
||||
data = 0;
|
||||
default:
|
||||
data = block.getData();
|
||||
}
|
||||
pb = new PlotBlock((short) id, data);
|
||||
return pb;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
if (id == -1) {
|
||||
id = block.getTypeId();
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
package com.intellectualcrafters.plot.object;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
public class BukkitOfflinePlayer implements OfflinePlotPlayer {
|
||||
|
||||
public final OfflinePlayer player;
|
||||
|
||||
/**
|
||||
* Please do not use this method. Instead use BukkitUtil.getPlayer(Player), as it caches player objects.
|
||||
* @param player
|
||||
*/
|
||||
public BukkitOfflinePlayer(final OfflinePlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
return this.player.getUniqueId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastPlayed() {
|
||||
return this.player.getLastPlayed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return this.player.isOnline();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.player.getName();
|
||||
}
|
||||
}
|
@ -1,191 +0,0 @@
|
||||
package com.intellectualcrafters.plot.object;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class BukkitPlayer implements PlotPlayer {
|
||||
|
||||
public final Player player;
|
||||
UUID uuid;
|
||||
String name;
|
||||
private int op = 0;
|
||||
private long last = 0;
|
||||
public HashSet<String> hasPerm = new HashSet<>();
|
||||
public HashSet<String> noPerm = new HashSet<>();
|
||||
|
||||
private HashMap<String, Object> meta;
|
||||
|
||||
/**
|
||||
* Please do not use this method. Instead use BukkitUtil.getPlayer(Player), as it caches player objects.
|
||||
* @param player
|
||||
*/
|
||||
public BukkitPlayer(final Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public long getPreviousLogin() {
|
||||
if (last == 0) {
|
||||
last = player.getLastPlayed();
|
||||
}
|
||||
return last;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return BukkitUtil.getLocation(this.player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
if (this.uuid == null) {
|
||||
this.uuid = UUIDHandler.getUUID(this);
|
||||
}
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final String perm) {
|
||||
if (Settings.PERMISSION_CACHING) {
|
||||
if (this.noPerm.contains(perm)) {
|
||||
return false;
|
||||
}
|
||||
if (this.hasPerm.contains(perm)) {
|
||||
return true;
|
||||
}
|
||||
final boolean result = this.player.hasPermission(perm);
|
||||
if (!result) {
|
||||
this.noPerm.add(perm);
|
||||
return false;
|
||||
}
|
||||
this.hasPerm.add(perm);
|
||||
return true;
|
||||
}
|
||||
return this.player.hasPermission(perm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(final String message) {
|
||||
this.player.sendMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport(final Location loc) {
|
||||
this.player.teleport(new org.bukkit.Location(BukkitUtil.getWorld(loc.getWorld()), loc.getX() + 0.5, loc.getY(), loc.getZ() + 0.5, loc.getYaw(), loc.getPitch()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOp() {
|
||||
if (this.op != 0) {
|
||||
if (this.op == 1) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
final boolean result = this.player.isOp();
|
||||
if (!result) {
|
||||
this.op = 1;
|
||||
return false;
|
||||
}
|
||||
this.op = 2;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (this.name == null) {
|
||||
this.name = this.player.getName();
|
||||
}
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return this.player.isOnline();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCompassTarget(final Location loc) {
|
||||
this.player.setCompassTarget(new org.bukkit.Location(BukkitUtil.getWorld(loc.getWorld()), loc.getX(), loc.getY(), loc.getZ()));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocationFull() {
|
||||
return BukkitUtil.getLocationFull(this.player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMeta(String key, Object value) {
|
||||
if (this.meta == null) {
|
||||
this.meta = new HashMap<String, Object>();
|
||||
}
|
||||
this.meta.put(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getMeta(String key) {
|
||||
if (this.meta != null) {
|
||||
return this.meta.get(key);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteMeta(String key) {
|
||||
if (this.meta != null) {
|
||||
this.meta.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAttribute(String key) {
|
||||
key = "plotsquared_user_attributes." + key;
|
||||
EconHandler.manager.setPermission(this, key, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getAttribute(String key) {
|
||||
key = "plotsquared_user_attributes." + key;
|
||||
Permission perm = Bukkit.getServer().getPluginManager().getPermission(key);
|
||||
if (perm == null) {
|
||||
perm = new Permission(key, PermissionDefault.FALSE);
|
||||
Bukkit.getServer().getPluginManager().addPermission(perm);
|
||||
Bukkit.getServer().getPluginManager().recalculatePermissionDefaults(perm);
|
||||
}
|
||||
return player.hasPermission(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAttribute(String key) {
|
||||
key = "plotsquared_user_attributes." + key;
|
||||
EconHandler.manager.setPermission(this, key, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadData() {
|
||||
if (!player.isOnline()) {
|
||||
player.loadData();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveData() {
|
||||
player.saveData();
|
||||
}
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
package com.intellectualcrafters.plot.object;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
/**
|
||||
* Created 2014-11-18 for PlotSquared
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class InfoInventory implements InventoryHolder {
|
||||
private final Plot plot;
|
||||
private final Inventory inventory;
|
||||
private final Player player;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param plot from which we take information
|
||||
*/
|
||||
public InfoInventory(final Plot plot, final PlotPlayer plr) {
|
||||
this.plot = plot;
|
||||
this.player = ((BukkitPlayer) plr).player;
|
||||
this.inventory = Bukkit.createInventory(this, 9, "Plot: " + plot.id.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
public String getName(final UUID uuid) {
|
||||
final String name = UUIDHandler.getName(this.plot.owner);
|
||||
if (name == null) {
|
||||
return "unknown";
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public InfoInventory build() {
|
||||
final UUID uuid = UUIDHandler.getUUID(BukkitUtil.getPlayer(this.player));
|
||||
final ItemStack generalInfo = getItem(Material.EMERALD, "&cPlot Info", "&cID: &6" + this.plot.getId().toString(), "&cOwner: &6" + getName(this.plot.owner), "&cAlias: &6" + this.plot.getSettings().getAlias(), "&cBiome: &6" + this.plot.getSettings().getBiome().toString().replaceAll("_", "").toLowerCase(), "&cCan Build: &6" + this.plot.isAdded(uuid), "&cIs Denied: &6" + this.plot.isDenied(uuid));
|
||||
final ItemStack trusted = getItem(Material.EMERALD, "&cTrusted", "&cAmount: &6" + this.plot.getTrusted().size(), "&8Click to view a list of the trusted users");
|
||||
final ItemStack members = getItem(Material.EMERALD, "&cMembers", "&cAmount: &6" + this.plot.getMembers().size(), "&8Click to view a list of plot members");
|
||||
final ItemStack denied = getItem(Material.EMERALD, "&cDenied", "&cAmount: &6" + this.plot.getDenied().size(), "&8Click to view a list of denied players");
|
||||
final ItemStack flags = getItem(Material.EMERALD, "&cFlags", "&cAmount: &6" + this.plot.getSettings().flags.size(), "&8Click to view a list of plot flags");
|
||||
this.inventory.setItem(2, generalInfo);
|
||||
this.inventory.setItem(3, trusted);
|
||||
this.inventory.setItem(4, members);
|
||||
this.inventory.setItem(5, denied);
|
||||
this.inventory.setItem(6, flags);
|
||||
return this;
|
||||
}
|
||||
|
||||
public InfoInventory display() {
|
||||
this.player.closeInventory();
|
||||
this.player.openInventory(this.inventory);
|
||||
return this;
|
||||
}
|
||||
|
||||
private ItemStack getItem(final Material material, final String name, final String... lore) {
|
||||
final ItemStack stack = new ItemStack(material);
|
||||
final ItemMeta meta = stack.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
|
||||
final List<String> lList = new ArrayList<>();
|
||||
for (final String l : lore) {
|
||||
lList.add(ChatColor.translateAlternateColorCodes('&', l));
|
||||
}
|
||||
meta.setLore(lList);
|
||||
stack.setItemMeta(meta);
|
||||
return stack;
|
||||
}
|
||||
}
|
@ -1,256 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.object;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.listeners.WorldEvents;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
|
||||
public abstract class PlotGenerator extends ChunkGenerator {
|
||||
|
||||
public static short[][][] CACHE_I = null;
|
||||
public static short[][][] CACHE_J = null;
|
||||
public int X;
|
||||
public int Z;
|
||||
private boolean loaded = false;
|
||||
private short[][] result;
|
||||
private PseudoRandom random = new PseudoRandom();
|
||||
|
||||
public PlotGenerator(String world) {
|
||||
WorldEvents.lastWorld = world;
|
||||
initCache();
|
||||
}
|
||||
|
||||
public void initCache() {
|
||||
if (CACHE_I == null) {
|
||||
CACHE_I = new short[256][16][16];
|
||||
CACHE_J = new short[256][16][16];
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int y = 0; y < 256; y++) {
|
||||
short i = (short) (y >> 4);
|
||||
short j = (short) (((y & 0xF) << 8) | (z << 4) | x);
|
||||
CACHE_I[y][x][z] = i;
|
||||
CACHE_J[y][x][z] = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<BlockPopulator> getDefaultPopulators(World world) {
|
||||
try {
|
||||
if (!loaded) {
|
||||
PS.get().loadWorld(WorldEvents.getName(world), this);
|
||||
PlotWorld plotworld = PS.get().getPlotWorld(WorldEvents.getName(world));
|
||||
if (!plotworld.MOB_SPAWNING) {
|
||||
if (!plotworld.SPAWN_EGGS) {
|
||||
world.setSpawnFlags(false, false);
|
||||
}
|
||||
world.setAmbientSpawnLimit(0);
|
||||
world.setAnimalSpawnLimit(0);
|
||||
world.setMonsterSpawnLimit(0);
|
||||
world.setWaterAnimalSpawnLimit(0);
|
||||
}
|
||||
else {
|
||||
world.setSpawnFlags(true, true);
|
||||
world.setAmbientSpawnLimit(-1);
|
||||
world.setAnimalSpawnLimit(-1);
|
||||
world.setMonsterSpawnLimit(-1);
|
||||
world.setWaterAnimalSpawnLimit(-1);
|
||||
}
|
||||
loaded = true;
|
||||
return (List<BlockPopulator>)(List<?>) getPopulators(WorldEvents.getName(world));
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new ArrayList<BlockPopulator>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the result;
|
||||
* @param result
|
||||
*/
|
||||
public void setResult(short[][] result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short[][] generateExtBlockSections(World world, Random r, int cx, int cz, BiomeGrid biomes) {
|
||||
try {
|
||||
if (!loaded) {
|
||||
PS.get().loadWorld(WorldEvents.getName(world), this);
|
||||
loaded = true;
|
||||
}
|
||||
final int prime = 13;
|
||||
int h = 1;
|
||||
h = (prime * h) + cx;
|
||||
h = (prime * h) + cz;
|
||||
this.random.state = h;
|
||||
this.result = new short[16][];
|
||||
this.X = cx << 4;
|
||||
this.Z = cz << 4;
|
||||
if (ChunkManager.FORCE_PASTE) {
|
||||
PlotWorld plotworld = PS.get().getPlotWorld(world.getName());
|
||||
Biome biome = Biome.valueOf(plotworld.PLOT_BIOME);
|
||||
for (short x = 0; x < 16; x++) {
|
||||
for (short z = 0; z < 16; z++) {
|
||||
if (biomes != null) {
|
||||
biomes.setBiome(x, z, biome);
|
||||
}
|
||||
final PlotLoc loc = new PlotLoc((X + x), (Z + z));
|
||||
final HashMap<Short, Short> blocks = ChunkManager.GENERATE_BLOCKS.get(loc);
|
||||
for (final Entry<Short, Short> entry : blocks.entrySet()) {
|
||||
setBlock(x, entry.getKey(), z, entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.result;
|
||||
}
|
||||
generateChunk(world, ChunkManager.CURRENT_PLOT_CLEAR, random, cx, cz, biomes);
|
||||
if (ChunkManager.CURRENT_PLOT_CLEAR != null) {
|
||||
PlotLoc loc;
|
||||
for (Entry<PlotLoc, HashMap<Short, Short>> entry : ChunkManager.GENERATE_BLOCKS.entrySet()) {
|
||||
for (Entry<Short, Short> entry2 : entry.getValue().entrySet()) {
|
||||
loc = entry.getKey();
|
||||
int xx = loc.x - X;
|
||||
int zz = loc.z - Z;
|
||||
if (xx >= 0 && xx < 16) {
|
||||
if (zz >= 0 && zz < 16) {
|
||||
setBlock(xx, entry2.getKey(), zz, entry2.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setBlock(final int x, final int y, final int z, final short blkid) {
|
||||
if (result[CACHE_I[y][x][z]] == null) {
|
||||
result[CACHE_I[y][x][z]] = new short[4096];
|
||||
}
|
||||
result[CACHE_I[y][x][z]][CACHE_J[y][x][z]] = blkid;
|
||||
}
|
||||
|
||||
public void setBlock(final int x, final int y, final int z, final short[] blkid) {
|
||||
if (blkid.length == 1) {
|
||||
setBlock(x, y, z, blkid[0]);
|
||||
}
|
||||
short id = blkid[random.random(blkid.length)];
|
||||
if (result[CACHE_I[y][x][z]] == null) {
|
||||
result[CACHE_I[y][x][z]] = new short[4096];
|
||||
}
|
||||
result[CACHE_I[y][x][z]][CACHE_J[y][x][z]] = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if a region contains a location. (x, z) must be between [0,15], [0,15]
|
||||
* @param plot
|
||||
* @param x
|
||||
* @param z
|
||||
* @return
|
||||
*/
|
||||
public boolean contains(final RegionWrapper plot, final int x, final int z) {
|
||||
int xx = X + x;
|
||||
int zz = Z + z;
|
||||
return ((xx >= plot.minX) && (xx <= plot.maxX) && (zz >= plot.minZ) && (zz <= plot.maxZ));
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow spawning everywhere
|
||||
*/
|
||||
@Override
|
||||
public boolean canSpawn(final World world, final int x, final int z) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* <b>random</b> is an optimized random number generator.<br>
|
||||
* - Change the state to have the same chunk random each time it generates<br>
|
||||
* <b>requiredRegion</b> If a plot is being regenerated, you are only required to generate content in this area<br>
|
||||
* - use the contains(RegionWrapper, x, z) method to check if the region contains a location<br>
|
||||
* - You can ignore this if you do not want to further optimize your generator<br>
|
||||
* - will be null if no restrictions are set<br>
|
||||
* <b>result</b> is the standard 2D block data array used for generation<br>
|
||||
* <b>biomes</b> is the standard BiomeGrid used for generation
|
||||
*
|
||||
* @param world
|
||||
* @param random
|
||||
* @param cx
|
||||
* @param cz
|
||||
* @param requiredRegion
|
||||
* @param biomes
|
||||
* @param result
|
||||
* @return
|
||||
*/
|
||||
public abstract void generateChunk(final World world, RegionWrapper requiredRegion, final PseudoRandom random, final int cx, final int cz, final BiomeGrid biomes);
|
||||
|
||||
public abstract List<PlotPopulator> getPopulators(String world);
|
||||
|
||||
/**
|
||||
* This is called when the generator is initialized.
|
||||
* You don't need to do anything with it necessarily.
|
||||
* @param plotworld
|
||||
*/
|
||||
public abstract void init(PlotWorld plotworld);
|
||||
|
||||
/**
|
||||
* Return a new instance of the PlotWorld for a world
|
||||
* @param world
|
||||
* @return
|
||||
*/
|
||||
public abstract PlotWorld getNewPlotWorld(final String world);
|
||||
|
||||
/**
|
||||
* Get the PlotManager class for this generator
|
||||
* @return
|
||||
*/
|
||||
public abstract PlotManager getPlotManager();
|
||||
|
||||
/**
|
||||
* If you need to do anything fancy for /plot setup<br>
|
||||
* - Otherwise it will just use the PlotWorld configuration<br>
|
||||
* Feel free to extend BukkitSetupUtils and customize world creation
|
||||
* @param object
|
||||
*/
|
||||
public void processSetup(SetupObject object) {
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
import com.plotsquared.bukkit.util.bukkit.UUIDHandler;
|
||||
|
||||
public class PlotHandler {
|
||||
public static HashSet<UUID> getOwners(Plot plot) {
|
||||
|
@ -1,108 +0,0 @@
|
||||
package com.intellectualcrafters.plot.object;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
|
||||
|
||||
public abstract class PlotPopulator extends BlockPopulator {
|
||||
|
||||
private PseudoRandom random = new PseudoRandom();
|
||||
|
||||
public int X;
|
||||
public int Z;
|
||||
private World world;
|
||||
|
||||
@Override
|
||||
public void populate(World world, Random rand, Chunk chunk) {
|
||||
this.world = world;
|
||||
this.X = chunk.getX() << 4;
|
||||
this.Z = chunk.getZ() << 4;
|
||||
if (ChunkManager.FORCE_PASTE) {
|
||||
for (short x = 0; x < 16; x++) {
|
||||
for (short z = 0; z < 16; z++) {
|
||||
final PlotLoc loc = new PlotLoc((short) (X + x), (short) (Z + z));
|
||||
final HashMap<Short, Byte> blocks = ChunkManager.GENERATE_DATA.get(loc);
|
||||
for (final Entry<Short, Byte> entry : blocks.entrySet()) {
|
||||
setBlock(x, entry.getKey(), z, entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
populate(world, ChunkManager.CURRENT_PLOT_CLEAR, random, X, Z);
|
||||
if (ChunkManager.CURRENT_PLOT_CLEAR != null) {
|
||||
PlotLoc loc;
|
||||
for (Entry<PlotLoc, HashMap<Short, Byte>> entry : ChunkManager.GENERATE_DATA.entrySet()) {
|
||||
for (Entry<Short, Byte> entry2 : entry.getValue().entrySet()) {
|
||||
loc = entry.getKey();
|
||||
int xx = loc.x - X;
|
||||
int zz = loc.z - Z;
|
||||
if (xx >= 0 && xx < 16) {
|
||||
if (zz >= 0 && zz < 16) {
|
||||
setBlock(xx, entry2.getKey(), zz, entry2.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void populate(World world, RegionWrapper requiredRegion, PseudoRandom random, int cx, int cz);
|
||||
|
||||
/**
|
||||
* Set the id and data at a location. (x, y, z) must be between [0,15], [0,255], [0,15]
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param id
|
||||
* @param data
|
||||
*/
|
||||
public void setBlock(int x, int y, int z, short id, byte data) {
|
||||
BukkitUtil.setBlock(world, X + x, y, Z + z, id, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the data at a location. (x, y, z) must be between [0,15], [0,255], [0,15]
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param data
|
||||
*/
|
||||
public void setBlock(int x, int y, int z, byte data) {
|
||||
if (data != 0) {
|
||||
world.getBlockAt(X + x, y, Z + z).setData(data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Like setblock, but lacks the data != 0 check
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param data
|
||||
*/
|
||||
public void setBlockAbs(int x, int y, int z, byte data) {
|
||||
world.getBlockAt(X + x, y, Z + z).setData(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* check if a region contains a location. (x, z) must be between [0,15], [0,15]
|
||||
* @param plot
|
||||
* @param x
|
||||
* @param z
|
||||
* @return
|
||||
*/
|
||||
public boolean contains(final RegionWrapper plot, final int x, final int z) {
|
||||
int xx = X + x;
|
||||
int zz = Z + z;
|
||||
return ((xx >= plot.minX) && (xx <= plot.maxX) && (zz >= plot.minZ) && (zz <= plot.maxZ));
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package com.intellectualcrafters.plot.object;
|
||||
|
||||
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
||||
import com.intellectualcrafters.plot.util.SetupUtils;
|
||||
import com.plotsquared.bukkit.util.SetupUtils;
|
||||
|
||||
public class SetupObject {
|
||||
|
||||
|
@ -1,79 +0,0 @@
|
||||
package com.intellectualcrafters.plot.object.comment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.titles.AbstractTitle;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
|
||||
public class CommentManager {
|
||||
public static HashMap<String, CommentInbox> inboxes = new HashMap<>();
|
||||
|
||||
public static void sendTitle(final PlotPlayer player, final Plot plot) {
|
||||
if (!Settings.COMMENT_NOTIFICATIONS) {
|
||||
return;
|
||||
}
|
||||
if (!plot.isOwner(player.getUUID())) {
|
||||
return;
|
||||
}
|
||||
TaskManager.runTaskLaterAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Collection<CommentInbox> boxes = CommentManager.inboxes.values();
|
||||
final AtomicInteger count = new AtomicInteger(0);
|
||||
final AtomicInteger size = new AtomicInteger(boxes.size());
|
||||
for (final CommentInbox inbox : inboxes.values()) {
|
||||
inbox.getComments(plot, new RunnableVal() {
|
||||
@Override
|
||||
public void run() {
|
||||
int total;
|
||||
if (value != null) {
|
||||
int num = 0;
|
||||
for (PlotComment comment : (ArrayList<PlotComment>) value) {
|
||||
if (comment.timestamp > getTimestamp(player, inbox.toString())) {
|
||||
num++;
|
||||
}
|
||||
}
|
||||
total = count.addAndGet(num);
|
||||
}
|
||||
else {
|
||||
total = count.get();
|
||||
}
|
||||
if (size.decrementAndGet() == 0 && total > 0) {
|
||||
AbstractTitle.sendTitle(player, "", C.INBOX_NOTIFICATION.s().replaceAll("%s", "" + total), ChatColor.GOLD, ChatColor.valueOf(C.TITLE_ENTERED_PLOT_SUB_COLOR.s()));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}, 20);
|
||||
}
|
||||
|
||||
public static long getTimestamp(PlotPlayer player, String inbox) {
|
||||
Object meta = player.getMeta("inbox:"+inbox);
|
||||
if (meta == null) {
|
||||
return player.getPreviousLogin();
|
||||
}
|
||||
return (Long) meta;
|
||||
}
|
||||
|
||||
public static void addInbox(CommentInbox inbox) {
|
||||
inboxes.put(inbox.toString().toLowerCase(), inbox);
|
||||
}
|
||||
|
||||
public static void registerDefaultInboxes() {
|
||||
addInbox(new InboxReport());
|
||||
addInbox(new InboxPublic());
|
||||
addInbox(new InboxOwner());
|
||||
}
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
package com.intellectualcrafters.plot.object.entity;
|
||||
|
||||
public class ArmorStandStats {
|
||||
float[] head = new float[3];
|
||||
float[] body = new float[3];
|
||||
float[] leftLeg = new float[3];
|
||||
float[] rightLeg = new float[3];
|
||||
float[] leftArm = new float[3];
|
||||
float[] rightArm = new float[3];
|
||||
public float[] head = new float[3];
|
||||
public float[] body = new float[3];
|
||||
public float[] leftLeg = new float[3];
|
||||
public float[] rightLeg = new float[3];
|
||||
public float[] leftArm = new float[3];
|
||||
public float[] rightArm = new float[3];
|
||||
public boolean arms;
|
||||
public boolean noplate;
|
||||
public boolean nogravity;
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.intellectualcrafters.plot.object.entity;
|
||||
|
||||
import com.plotsquared.bukkit.object.entity.EntityWrapper;
|
||||
|
||||
public class EntityBaseStats {
|
||||
public EntityWrapper passenger;
|
||||
public float fall;
|
||||
|
@ -1,661 +0,0 @@
|
||||
package com.intellectualcrafters.plot.object.entity;
|
||||
|
||||
import org.bukkit.Art;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Rotation;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Guardian;
|
||||
import org.bukkit.entity.Horse;
|
||||
import org.bukkit.entity.Horse.Color;
|
||||
import org.bukkit.entity.Horse.Style;
|
||||
import org.bukkit.entity.Horse.Variant;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Painting;
|
||||
import org.bukkit.entity.Rabbit;
|
||||
import org.bukkit.entity.Rabbit.Type;
|
||||
import org.bukkit.entity.Sheep;
|
||||
import org.bukkit.entity.Skeleton;
|
||||
import org.bukkit.entity.Skeleton.SkeletonType;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.EulerAngle;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
|
||||
public class EntityWrapper {
|
||||
public short id;
|
||||
public float yaw;
|
||||
public float pitch;
|
||||
public double x;
|
||||
public double y;
|
||||
public double z;
|
||||
public short depth;
|
||||
public EntityBaseStats base = null;
|
||||
// Extended
|
||||
public ItemStack stack;
|
||||
public ItemStack[] inventory;
|
||||
public byte dataByte;
|
||||
public byte dataByte2;
|
||||
public String dataString;
|
||||
public LivingEntityStats lived;
|
||||
public AgeableStats aged;
|
||||
public TameableStats tamed;
|
||||
private HorseStats horse;
|
||||
private ArmorStandStats stand;
|
||||
|
||||
public void storeInventory(final InventoryHolder held) {
|
||||
this.inventory = held.getInventory().getContents().clone();
|
||||
}
|
||||
|
||||
private void restoreLiving(final LivingEntity entity) {
|
||||
if (this.lived.loot) {
|
||||
entity.setCanPickupItems(this.lived.loot);
|
||||
}
|
||||
if (this.lived.name != null) {
|
||||
entity.setCustomName(this.lived.name);
|
||||
entity.setCustomNameVisible(this.lived.visible);
|
||||
}
|
||||
if ((this.lived.potions != null) && (this.lived.potions.size() > 0)) {
|
||||
entity.addPotionEffects(this.lived.potions);
|
||||
}
|
||||
entity.setRemainingAir(this.lived.air);
|
||||
entity.setRemoveWhenFarAway(this.lived.persistent);
|
||||
if (this.lived.equipped) {
|
||||
final EntityEquipment equipment = entity.getEquipment();
|
||||
equipment.setItemInHand(this.lived.hands);
|
||||
equipment.setHelmet(this.lived.helmet);
|
||||
equipment.setChestplate(this.lived.chestplate);
|
||||
equipment.setLeggings(this.lived.leggings);
|
||||
equipment.setBoots(this.lived.boots);
|
||||
}
|
||||
if (this.lived.leashed) {
|
||||
// TODO leashes
|
||||
// World world = entity.getWorld();
|
||||
// Entity leash = world.spawnEntity(new Location(world, Math.floor(x) + lived.leash_x, Math.floor(y) + lived.leash_y, Math.floor(z) + lived.leash_z), EntityType.LEASH_HITCH);
|
||||
// entity.setLeashHolder(leash);
|
||||
}
|
||||
}
|
||||
|
||||
private void restoreInventory(final InventoryHolder entity) {
|
||||
entity.getInventory().setContents(this.inventory);
|
||||
}
|
||||
|
||||
public void storeLiving(final LivingEntity lived) {
|
||||
this.lived = new LivingEntityStats();
|
||||
this.lived.potions = lived.getActivePotionEffects();
|
||||
this.lived.loot = lived.getCanPickupItems();
|
||||
this.lived.name = lived.getCustomName();
|
||||
this.lived.visible = lived.isCustomNameVisible();
|
||||
this.lived.health = (float) lived.getHealth();
|
||||
this.lived.air = (short) lived.getRemainingAir();
|
||||
this.lived.persistent = lived.getRemoveWhenFarAway();
|
||||
this.lived.leashed = lived.isLeashed();
|
||||
if (this.lived.leashed) {
|
||||
final Location loc = lived.getLeashHolder().getLocation();
|
||||
this.lived.leash_x = (short) (this.x - loc.getBlockX());
|
||||
this.lived.leash_y = (short) (this.y - loc.getBlockY());
|
||||
this.lived.leash_z = (short) (this.z - loc.getBlockZ());
|
||||
}
|
||||
final EntityEquipment equipment = lived.getEquipment();
|
||||
this.lived.equipped = equipment != null;
|
||||
if (this.lived.equipped) {
|
||||
this.lived.hands = equipment.getItemInHand().clone();
|
||||
this.lived.boots = equipment.getBoots().clone();
|
||||
this.lived.leggings = equipment.getLeggings().clone();
|
||||
this.lived.chestplate = equipment.getChestplate().clone();
|
||||
this.lived.helmet = equipment.getHelmet().clone();
|
||||
}
|
||||
}
|
||||
|
||||
private void restoreTameable(final Tameable entity) {
|
||||
if (this.tamed.tamed) {
|
||||
if (this.tamed.owner != null) {
|
||||
entity.setTamed(true);
|
||||
entity.setOwner(this.tamed.owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void restoreAgeable(final Ageable entity) {
|
||||
if (!this.aged.adult) {
|
||||
entity.setBaby();
|
||||
}
|
||||
if (this.aged.locked) {
|
||||
entity.setAgeLock(this.aged.locked);
|
||||
}
|
||||
entity.setAge(this.aged.age);
|
||||
}
|
||||
|
||||
public void storeAgeable(final Ageable aged) {
|
||||
this.aged = new AgeableStats();
|
||||
this.aged.age = aged.getAge();
|
||||
this.aged.locked = aged.getAgeLock();
|
||||
this.aged.adult = aged.isAdult();
|
||||
}
|
||||
|
||||
public void storeTameable(final Tameable tamed) {
|
||||
this.tamed = new TameableStats();
|
||||
this.tamed.owner = tamed.getOwner();
|
||||
this.tamed.tamed = tamed.isTamed();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public EntityWrapper(final org.bukkit.entity.Entity entity, final short depth) {
|
||||
this.depth = depth;
|
||||
final Location loc = entity.getLocation();
|
||||
this.yaw = loc.getYaw();
|
||||
this.pitch = loc.getPitch();
|
||||
this.x = loc.getX();
|
||||
this.y = loc.getY();
|
||||
this.z = loc.getZ();
|
||||
this.id = entity.getType().getTypeId();
|
||||
if (depth == 0) {
|
||||
return;
|
||||
}
|
||||
this.base = new EntityBaseStats();
|
||||
final Entity p = entity.getPassenger();
|
||||
if (p != null) {
|
||||
this.base.passenger = new EntityWrapper(p, depth);
|
||||
}
|
||||
this.base.fall = entity.getFallDistance();
|
||||
this.base.fire = (short) entity.getFireTicks();
|
||||
this.base.age = entity.getTicksLived();
|
||||
final Vector velocity = entity.getVelocity();
|
||||
this.base.v_x = velocity.getX();
|
||||
this.base.v_y = velocity.getY();
|
||||
this.base.v_z = velocity.getZ();
|
||||
if (depth == 1) {
|
||||
return;
|
||||
}
|
||||
switch (entity.getType()) {
|
||||
case ARROW:
|
||||
case BOAT:
|
||||
case COMPLEX_PART:
|
||||
case EGG:
|
||||
case ENDER_CRYSTAL:
|
||||
case ENDER_PEARL:
|
||||
case ENDER_SIGNAL:
|
||||
case EXPERIENCE_ORB:
|
||||
case FALLING_BLOCK:
|
||||
case FIREBALL:
|
||||
case FIREWORK:
|
||||
case FISHING_HOOK:
|
||||
case LEASH_HITCH:
|
||||
case LIGHTNING:
|
||||
case MINECART:
|
||||
case MINECART_COMMAND:
|
||||
case MINECART_MOB_SPAWNER:
|
||||
case MINECART_TNT:
|
||||
case PLAYER:
|
||||
case PRIMED_TNT:
|
||||
case SLIME:
|
||||
case SMALL_FIREBALL:
|
||||
case SNOWBALL:
|
||||
case MINECART_FURNACE:
|
||||
case SPLASH_POTION:
|
||||
case THROWN_EXP_BOTTLE:
|
||||
case WEATHER:
|
||||
case WITHER_SKULL:
|
||||
case UNKNOWN: {
|
||||
// Do this stuff later
|
||||
return;
|
||||
}
|
||||
default: {
|
||||
PS.log("&cCOULD NOT IDENTIFY ENTITY: " + entity.getType());
|
||||
return;
|
||||
}
|
||||
// MISC //
|
||||
case DROPPED_ITEM: {
|
||||
final Item item = (Item) entity;
|
||||
this.stack = item.getItemStack();
|
||||
return;
|
||||
}
|
||||
case ITEM_FRAME: {
|
||||
final ItemFrame itemframe = (ItemFrame) entity;
|
||||
this.x = Math.floor(this.x);
|
||||
this.y = Math.floor(this.y);
|
||||
this.z = Math.floor(this.z);
|
||||
this.dataByte = getOrdinal(Rotation.values(), itemframe.getRotation());
|
||||
this.stack = itemframe.getItem().clone();
|
||||
return;
|
||||
}
|
||||
case PAINTING: {
|
||||
final Painting painting = (Painting) entity;
|
||||
this.x = Math.floor(this.x);
|
||||
this.y = Math.floor(this.y);
|
||||
this.z = Math.floor(this.z);
|
||||
final Art a = painting.getArt();
|
||||
this.dataByte = getOrdinal(BlockFace.values(), painting.getFacing());
|
||||
final int h = a.getBlockHeight();
|
||||
if ((h % 2) == 0) {
|
||||
this.y -= 1;
|
||||
}
|
||||
this.dataString = a.name();
|
||||
return;
|
||||
}
|
||||
// END MISC //
|
||||
// INVENTORY HOLDER //
|
||||
case MINECART_CHEST: {
|
||||
storeInventory((InventoryHolder) entity);
|
||||
return;
|
||||
}
|
||||
case MINECART_HOPPER: {
|
||||
storeInventory((InventoryHolder) entity);
|
||||
return;
|
||||
}
|
||||
// START LIVING ENTITY //
|
||||
// START AGEABLE //
|
||||
// START TAMEABLE //
|
||||
case HORSE: {
|
||||
final Horse horse = (Horse) entity;
|
||||
this.horse = new HorseStats();
|
||||
this.horse.jump = horse.getJumpStrength();
|
||||
this.horse.chest = horse.isCarryingChest();
|
||||
this.horse.variant = getOrdinal(Variant.values(), horse.getVariant());
|
||||
this.horse.style = getOrdinal(Style.values(), horse.getStyle());
|
||||
this.horse.color = getOrdinal(Color.values(), horse.getColor());
|
||||
storeTameable((Tameable) entity);
|
||||
storeAgeable((Ageable) entity);
|
||||
storeLiving((LivingEntity) entity);
|
||||
storeInventory((InventoryHolder) entity);
|
||||
return;
|
||||
}
|
||||
// END INVENTORY HOLDER //
|
||||
case WOLF:
|
||||
case OCELOT: {
|
||||
storeTameable((Tameable) entity);
|
||||
storeAgeable((Ageable) entity);
|
||||
storeLiving((LivingEntity) entity);
|
||||
return;
|
||||
}
|
||||
// END AMEABLE //
|
||||
case SHEEP: {
|
||||
final Sheep sheep = (Sheep) entity;
|
||||
this.dataByte = (byte) ((sheep).isSheared() ? 1 : 0);
|
||||
this.dataByte2 = sheep.getColor().getDyeData();
|
||||
storeAgeable((Ageable) entity);
|
||||
storeLiving((LivingEntity) entity);
|
||||
return;
|
||||
}
|
||||
case VILLAGER:
|
||||
case CHICKEN:
|
||||
case COW:
|
||||
case MUSHROOM_COW:
|
||||
case PIG: {
|
||||
storeAgeable((Ageable) entity);
|
||||
storeLiving((LivingEntity) entity);
|
||||
return;
|
||||
}
|
||||
// END AGEABLE //
|
||||
case RABBIT: { // NEW
|
||||
this.dataByte = getOrdinal(Type.values(), ((Rabbit) entity).getRabbitType());
|
||||
storeAgeable((Ageable) entity);
|
||||
storeLiving((LivingEntity) entity);
|
||||
return;
|
||||
}
|
||||
case GUARDIAN: { // NEW
|
||||
this.dataByte = (byte) (((Guardian) entity).isElder() ? 1 : 0);
|
||||
storeLiving((LivingEntity) entity);
|
||||
return;
|
||||
}
|
||||
case SKELETON: { // NEW
|
||||
this.dataByte = (byte) ((Skeleton) entity).getSkeletonType().getId();
|
||||
storeLiving((LivingEntity) entity);
|
||||
return;
|
||||
}
|
||||
case ARMOR_STAND: { // NEW
|
||||
// CHECK positions
|
||||
final ArmorStand stand = (ArmorStand) entity;
|
||||
this.inventory = new ItemStack[] { stand.getItemInHand().clone(), stand.getHelmet().clone(), stand.getChestplate().clone(), stand.getLeggings().clone(), stand.getBoots().clone() };
|
||||
storeLiving((LivingEntity) entity);
|
||||
this.stand = new ArmorStandStats();
|
||||
|
||||
EulerAngle head = stand.getHeadPose();
|
||||
this.stand.head[0] = (float) head.getX();
|
||||
this.stand.head[1] = (float) head.getY();
|
||||
this.stand.head[2] = (float) head.getZ();
|
||||
|
||||
EulerAngle body = stand.getBodyPose();
|
||||
this.stand.body[0] = (float) body.getX();
|
||||
this.stand.body[1] = (float) body.getY();
|
||||
this.stand.body[2] = (float) body.getZ();
|
||||
|
||||
EulerAngle leftLeg = stand.getLeftLegPose();
|
||||
this.stand.leftLeg[0] = (float) leftLeg.getX();
|
||||
this.stand.leftLeg[1] = (float) leftLeg.getY();
|
||||
this.stand.leftLeg[2] = (float) leftLeg.getZ();
|
||||
|
||||
EulerAngle rightLeg = stand.getRightLegPose();
|
||||
this.stand.rightLeg[0] = (float) rightLeg.getX();
|
||||
this.stand.rightLeg[1] = (float) rightLeg.getY();
|
||||
this.stand.rightLeg[2] = (float) rightLeg.getZ();
|
||||
|
||||
EulerAngle leftArm = stand.getLeftArmPose();
|
||||
this.stand.leftArm[0] = (float) leftArm.getX();
|
||||
this.stand.leftArm[1] = (float) leftArm.getY();
|
||||
this.stand.leftArm[2] = (float) leftArm.getZ();
|
||||
|
||||
EulerAngle rightArm = stand.getRightArmPose();
|
||||
this.stand.rightArm[0] = (float) rightArm.getX();
|
||||
this.stand.rightArm[1] = (float) rightArm.getY();
|
||||
this.stand.rightArm[2] = (float) rightArm.getZ();
|
||||
|
||||
if (stand.hasArms()) {
|
||||
this.stand.arms = true;
|
||||
}
|
||||
if (!stand.hasBasePlate()) {
|
||||
this.stand.noplate = true;
|
||||
}
|
||||
if (!stand.hasGravity()) {
|
||||
this.stand.nogravity = true;
|
||||
}
|
||||
if (!stand.isVisible()) {
|
||||
this.stand.invisible = true;
|
||||
}
|
||||
if (stand.isSmall()) {
|
||||
this.stand.small = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
case ENDERMITE: // NEW
|
||||
case BAT:
|
||||
case ENDER_DRAGON:
|
||||
case GHAST:
|
||||
case MAGMA_CUBE:
|
||||
case SQUID:
|
||||
case PIG_ZOMBIE:
|
||||
case ZOMBIE:
|
||||
case WITHER:
|
||||
case WITCH:
|
||||
case SPIDER:
|
||||
case CAVE_SPIDER:
|
||||
case SILVERFISH:
|
||||
case GIANT:
|
||||
case ENDERMAN:
|
||||
case CREEPER:
|
||||
case BLAZE:
|
||||
case SNOWMAN:
|
||||
case IRON_GOLEM: {
|
||||
storeLiving((LivingEntity) entity);
|
||||
return;
|
||||
}
|
||||
// END LIVING //
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public Entity spawn(final World world, final int x_offset, final int z_offset) {
|
||||
final Location loc = new Location(world, this.x + x_offset, this.y, this.z + z_offset);
|
||||
loc.setYaw(this.yaw);
|
||||
loc.setPitch(this.pitch);
|
||||
if (this.id == -1) {
|
||||
return null;
|
||||
}
|
||||
final EntityType type = EntityType.fromId(this.id);
|
||||
Entity entity;
|
||||
switch (type) {
|
||||
case DROPPED_ITEM: {
|
||||
return world.dropItem(loc, this.stack);
|
||||
}
|
||||
case PLAYER:
|
||||
case LEASH_HITCH: {
|
||||
return null;
|
||||
}
|
||||
default:
|
||||
entity = world.spawnEntity(loc, type);
|
||||
break;
|
||||
}
|
||||
if (this.depth == 0) {
|
||||
return entity;
|
||||
}
|
||||
if (this.base.passenger != null) {
|
||||
try {
|
||||
entity.setPassenger(this.base.passenger.spawn(world, x_offset, z_offset));
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
}
|
||||
entity.setFallDistance(this.base.fall);
|
||||
entity.setFireTicks(this.base.fire);
|
||||
entity.setTicksLived(this.base.age);
|
||||
entity.setVelocity(new Vector(this.base.v_x, this.base.v_y, this.base.v_z));
|
||||
if (this.depth == 1) {
|
||||
return entity;
|
||||
}
|
||||
switch (entity.getType()) {
|
||||
case ARROW:
|
||||
case BOAT:
|
||||
case COMPLEX_PART:
|
||||
case EGG:
|
||||
case ENDER_CRYSTAL:
|
||||
case ENDER_PEARL:
|
||||
case ENDER_SIGNAL:
|
||||
case EXPERIENCE_ORB:
|
||||
case FALLING_BLOCK:
|
||||
case FIREBALL:
|
||||
case FIREWORK:
|
||||
case FISHING_HOOK:
|
||||
case LEASH_HITCH:
|
||||
case LIGHTNING:
|
||||
case MINECART:
|
||||
case MINECART_COMMAND:
|
||||
case MINECART_MOB_SPAWNER:
|
||||
case MINECART_TNT:
|
||||
case PLAYER:
|
||||
case PRIMED_TNT:
|
||||
case SLIME:
|
||||
case SMALL_FIREBALL:
|
||||
case SNOWBALL:
|
||||
case SPLASH_POTION:
|
||||
case THROWN_EXP_BOTTLE:
|
||||
case WEATHER:
|
||||
case WITHER_SKULL:
|
||||
case MINECART_FURNACE:
|
||||
case UNKNOWN: {
|
||||
// Do this stuff later
|
||||
return entity;
|
||||
}
|
||||
default: {
|
||||
PS.log("&cCOULD NOT IDENTIFY ENTITY: " + entity.getType());
|
||||
return entity;
|
||||
}
|
||||
// MISC //
|
||||
case ITEM_FRAME: {
|
||||
final ItemFrame itemframe = (ItemFrame) entity;
|
||||
itemframe.setRotation(Rotation.values()[this.dataByte]);
|
||||
itemframe.setItem(this.stack);
|
||||
return entity;
|
||||
}
|
||||
case PAINTING: {
|
||||
final Painting painting = (Painting) entity;
|
||||
painting.setFacingDirection(BlockFace.values()[this.dataByte], true);
|
||||
painting.setArt(Art.getByName(this.dataString), true);
|
||||
return entity;
|
||||
}
|
||||
// END MISC //
|
||||
// INVENTORY HOLDER //
|
||||
case MINECART_CHEST: {
|
||||
restoreInventory((InventoryHolder) entity);
|
||||
return entity;
|
||||
}
|
||||
case MINECART_HOPPER: {
|
||||
restoreInventory((InventoryHolder) entity);
|
||||
return entity;
|
||||
}
|
||||
// START LIVING ENTITY //
|
||||
// START AGEABLE //
|
||||
// START TAMEABLE //
|
||||
case HORSE: {
|
||||
final Horse horse = (Horse) entity;
|
||||
horse.setJumpStrength(this.horse.jump);
|
||||
horse.setCarryingChest(this.horse.chest);
|
||||
horse.setVariant(Variant.values()[this.horse.variant]);
|
||||
horse.setStyle(Style.values()[this.horse.style]);
|
||||
horse.setColor(Color.values()[this.horse.color]);
|
||||
restoreTameable((Tameable) entity);
|
||||
restoreAgeable((Ageable) entity);
|
||||
restoreLiving((LivingEntity) entity);
|
||||
restoreInventory((InventoryHolder) entity);
|
||||
return entity;
|
||||
}
|
||||
// END INVENTORY HOLDER //
|
||||
case WOLF:
|
||||
case OCELOT: {
|
||||
restoreTameable((Tameable) entity);
|
||||
restoreAgeable((Ageable) entity);
|
||||
restoreLiving((LivingEntity) entity);
|
||||
return entity;
|
||||
}
|
||||
// END AMEABLE //
|
||||
case SHEEP: {
|
||||
final Sheep sheep = (Sheep) entity;
|
||||
if (this.dataByte == 1) {
|
||||
sheep.setSheared(true);
|
||||
}
|
||||
if (this.dataByte2 != 0) {
|
||||
sheep.setColor(DyeColor.getByDyeData(this.dataByte2));
|
||||
}
|
||||
restoreAgeable((Ageable) entity);
|
||||
restoreLiving((LivingEntity) entity);
|
||||
return entity;
|
||||
}
|
||||
case VILLAGER:
|
||||
case CHICKEN:
|
||||
case COW:
|
||||
case MUSHROOM_COW:
|
||||
case PIG: {
|
||||
restoreAgeable((Ageable) entity);
|
||||
restoreLiving((LivingEntity) entity);
|
||||
return entity;
|
||||
}
|
||||
// END AGEABLE //
|
||||
case RABBIT: { // NEW
|
||||
if (this.dataByte != 0) {
|
||||
((Rabbit) entity).setRabbitType(Type.values()[this.dataByte]);
|
||||
}
|
||||
restoreAgeable((Ageable) entity);
|
||||
restoreLiving((LivingEntity) entity);
|
||||
return entity;
|
||||
}
|
||||
case GUARDIAN: { // NEW
|
||||
if (this.dataByte != 0) {
|
||||
((Guardian) entity).setElder(true);
|
||||
}
|
||||
restoreLiving((LivingEntity) entity);
|
||||
return entity;
|
||||
}
|
||||
case SKELETON: { // NEW
|
||||
if (this.dataByte != 0) {
|
||||
((Skeleton) entity).setSkeletonType(SkeletonType.values()[this.dataByte]);
|
||||
}
|
||||
storeLiving((LivingEntity) entity);
|
||||
return entity;
|
||||
}
|
||||
case ARMOR_STAND: { // NEW
|
||||
// CHECK positions
|
||||
final ArmorStand stand = (ArmorStand) entity;
|
||||
if (this.inventory[0] != null) {
|
||||
stand.setItemInHand(this.inventory[0]);
|
||||
}
|
||||
if (this.inventory[1] != null) {
|
||||
stand.setHelmet(this.inventory[1]);
|
||||
}
|
||||
if (this.inventory[2] != null) {
|
||||
stand.setChestplate(this.inventory[2]);
|
||||
}
|
||||
if (this.inventory[3] != null) {
|
||||
stand.setLeggings(this.inventory[3]);
|
||||
}
|
||||
if (this.inventory[4] != null) {
|
||||
stand.setBoots(this.inventory[4]);
|
||||
}
|
||||
if (this.stand.head[0] != 0 || this.stand.head[1] != 0 || this.stand.head[2] != 0) {
|
||||
EulerAngle pose = new EulerAngle(this.stand.head[0], this.stand.head[1], this.stand.head[2]);
|
||||
stand.setHeadPose(pose);
|
||||
}
|
||||
if (this.stand.body[0] != 0 || this.stand.body[1] != 0 || this.stand.body[2] != 0) {
|
||||
EulerAngle pose = new EulerAngle(this.stand.body[0], this.stand.body[1], this.stand.body[2]);
|
||||
stand.setBodyPose(pose);
|
||||
}
|
||||
if (this.stand.leftLeg[0] != 0 || this.stand.leftLeg[1] != 0 || this.stand.leftLeg[2] != 0) {
|
||||
EulerAngle pose = new EulerAngle(this.stand.leftLeg[0], this.stand.leftLeg[1], this.stand.leftLeg[2]);
|
||||
stand.setLeftLegPose(pose);
|
||||
}
|
||||
if (this.stand.rightLeg[0] != 0 || this.stand.rightLeg[1] != 0 || this.stand.rightLeg[2] != 0) {
|
||||
EulerAngle pose = new EulerAngle(this.stand.rightLeg[0], this.stand.rightLeg[1], this.stand.rightLeg[2]);
|
||||
stand.setRightLegPose(pose);
|
||||
}
|
||||
if (this.stand.leftArm[0] != 0 || this.stand.leftArm[1] != 0 || this.stand.leftArm[2] != 0) {
|
||||
EulerAngle pose = new EulerAngle(this.stand.leftArm[0], this.stand.leftArm[1], this.stand.leftArm[2]);
|
||||
stand.setLeftArmPose(pose);
|
||||
}
|
||||
if (this.stand.rightArm[0] != 0 || this.stand.rightArm[1] != 0 || this.stand.rightArm[2] != 0) {
|
||||
EulerAngle pose = new EulerAngle(this.stand.rightArm[0], this.stand.rightArm[1], this.stand.rightArm[2]);
|
||||
stand.setRightArmPose(pose);
|
||||
}
|
||||
if (this.stand.invisible) {
|
||||
stand.setVisible(false);
|
||||
}
|
||||
if (this.stand.arms) {
|
||||
stand.setArms(true);
|
||||
}
|
||||
if (this.stand.nogravity) {
|
||||
stand.setGravity(false);
|
||||
}
|
||||
if (this.stand.noplate) {
|
||||
stand.setBasePlate(false);
|
||||
}
|
||||
if (this.stand.small) {
|
||||
stand.setSmall(true);
|
||||
}
|
||||
restoreLiving((LivingEntity) entity);
|
||||
return entity;
|
||||
}
|
||||
case ENDERMITE: // NEW
|
||||
case BAT:
|
||||
case ENDER_DRAGON:
|
||||
case GHAST:
|
||||
case MAGMA_CUBE:
|
||||
case SQUID:
|
||||
case PIG_ZOMBIE:
|
||||
case ZOMBIE:
|
||||
case WITHER:
|
||||
case WITCH:
|
||||
case SPIDER:
|
||||
case CAVE_SPIDER:
|
||||
case SILVERFISH:
|
||||
case GIANT:
|
||||
case ENDERMAN:
|
||||
case CREEPER:
|
||||
case BLAZE:
|
||||
case SNOWMAN:
|
||||
case IRON_GOLEM: {
|
||||
restoreLiving((LivingEntity) entity);
|
||||
return entity;
|
||||
}
|
||||
// END LIVING //
|
||||
}
|
||||
}
|
||||
|
||||
private byte getOrdinal(final Object[] list, final Object value) {
|
||||
for (byte i = 0; i < list.length; i++) {
|
||||
if (list[i].equals(value)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.intellectualcrafters.plot.object.entity;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
public class LivingEntityStats {
|
||||
public boolean loot;
|
||||
public String name;
|
||||
public boolean visible;
|
||||
public float health;
|
||||
public short air;
|
||||
public boolean persistent;
|
||||
public boolean leashed;
|
||||
public short leash_x;
|
||||
public short leash_y;
|
||||
public short leash_z;
|
||||
public boolean equipped;
|
||||
public ItemStack hands;
|
||||
public ItemStack helmet;
|
||||
public ItemStack boots;
|
||||
public ItemStack leggings;
|
||||
public ItemStack chestplate;
|
||||
public Collection<PotionEffect> potions;
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package com.intellectualcrafters.plot.object.entity;
|
||||
|
||||
import org.bukkit.entity.AnimalTamer;
|
||||
|
||||
public class TameableStats {
|
||||
public AnimalTamer owner;
|
||||
public boolean tamed;
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
package com.intellectualcrafters.plot.object.schematic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.intellectualcrafters.jnbt.ByteTag;
|
||||
import com.intellectualcrafters.jnbt.CompoundTag;
|
||||
import com.intellectualcrafters.jnbt.ListTag;
|
||||
import com.intellectualcrafters.jnbt.ShortTag;
|
||||
import com.intellectualcrafters.jnbt.Tag;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler.Schematic;
|
||||
|
||||
public class StateWrapper {
|
||||
|
||||
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].toLowerCase();
|
||||
id = (short) ItemType.getId(idStr);
|
||||
}
|
||||
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();
|
||||
Map<String, Tag> values = new HashMap<String, Tag>();
|
||||
values.put("Items", new ListTag("Items", CompoundTag.class, serializeInventory(contents)));
|
||||
return new CompoundTag(values);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return "Chest";
|
||||
}
|
||||
|
||||
public List<CompoundTag> serializeInventory(ItemStack[] items) {
|
||||
List<CompoundTag> tags = new ArrayList<CompoundTag>();
|
||||
for (int i = 0; i < items.length; ++i) {
|
||||
if (items[i] != null) {
|
||||
Map<String, Tag> tagData = serializeItem(items[i]);
|
||||
tagData.put("Slot", new ByteTag("Slot", (byte) i));
|
||||
tags.add(new CompoundTag(tagData));
|
||||
}
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
|
||||
public Map<String, Tag> serializeItem(ItemStack item) {
|
||||
Map<String, Tag> data = new HashMap<String, Tag>();
|
||||
data.put("id", new ShortTag("id", (short) item.getTypeId()));
|
||||
data.put("Damage", new ShortTag("Damage", item.getDurability()));
|
||||
data.put("Count", new ByteTag("Count", (byte) item.getAmount()));
|
||||
if (!item.getEnchantments().isEmpty()) {
|
||||
List<CompoundTag> enchantmentList = new ArrayList<CompoundTag>();
|
||||
for(Entry<Enchantment, Integer> entry : item.getEnchantments().entrySet()) {
|
||||
Map<String, Tag> enchantment = new HashMap<String, Tag>();
|
||||
enchantment.put("id", new ShortTag("id", (short) entry.getKey().getId()));
|
||||
enchantment.put("lvl", new ShortTag("lvl", entry.getValue().shortValue()));
|
||||
enchantmentList.add(new CompoundTag(enchantment));
|
||||
}
|
||||
Map<String, Tag> auxData = new HashMap<String, Tag>();
|
||||
auxData.put("ench", new ListTag("ench", CompoundTag.class, enchantmentList));
|
||||
data.put("tag", new CompoundTag("tag", auxData));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user