Move all files! Hahah

This commit is contained in:
Sauilitired
2015-07-16 16:16:13 +02:00
parent 8a4e19ab40
commit cff47cbac0
318 changed files with 58 additions and 2 deletions

View File

@ -0,0 +1,73 @@
package com.intellectualcrafters.plot.object;
public class BlockLoc {
public int x;
public int y;
public int z;
public float yaw, pitch;
public BlockLoc(final int x, final int y, final int z, final float yaw, final float pitch) {
this.x = x;
this.y = y;
this.z = z;
this.yaw = yaw;
this.pitch = pitch;
}
public BlockLoc(final int x, final int y, final int z) {
this(x, y, z, 0f, 0f);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = (prime * result) + this.x;
result = (prime * result) + this.y;
result = (prime * result) + this.z;
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final BlockLoc other = (BlockLoc) obj;
return ((this.x == other.x) && (this.y == other.y) && (this.z == other.z));
}
@Override
public String toString() {
return
x + "," + y + "," + z + "," + yaw + "," + pitch;
}
public static BlockLoc fromString(final String string) {
String[] parts = string.split(",");
float yaw, pitch;
if (parts.length == 3) {
yaw = 0f;
pitch = 0f;
} if (parts.length == 5) {
yaw = Float.parseFloat(parts[3]);
pitch = Float.parseFloat(parts[4]);
} else {
return new BlockLoc(0, 0, 0);
}
int x = Integer.parseInt(parts[0]);
int y = Integer.parseInt(parts[1]);
int z = Integer.parseInt(parts[2]);
return new BlockLoc(x, y, z, yaw, pitch);
}
}

View File

@ -0,0 +1,100 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// 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;
}
}

View File

@ -0,0 +1,138 @@
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;
}
}

View File

@ -0,0 +1,38 @@
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();
}
}

View File

@ -0,0 +1,192 @@
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(), loc.getY(), loc.getZ()));
}
@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();
}
}

View File

@ -0,0 +1,35 @@
package com.intellectualcrafters.plot.object;
public class ChunkLoc {
public int x;
public int z;
public ChunkLoc(final int x, final int z) {
this.x = x;
this.z = z;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = (prime * result) + this.x;
result = (prime * result) + this.z;
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final ChunkLoc other = (ChunkLoc) obj;
return ((this.x == other.x) && (this.z == other.z));
}
}

View File

@ -0,0 +1,12 @@
package com.intellectualcrafters.plot.object;
public class CmdInstance {
public final Runnable command;
public final long timestamp;
public CmdInstance(Runnable command) {
this.command = command;
this.timestamp = System.currentTimeMillis();
}
}

View File

@ -0,0 +1,11 @@
package com.intellectualcrafters.plot.object;
public class FileBytes {
public String path;
public byte[] data;
public FileBytes(String path, byte[] data) {
this.path = path;
this.data = data;
}
}

View File

@ -0,0 +1,86 @@
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.settings.getAlias(), "&cBiome: &6" + this.plot.settings.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.trusted.size(), "&8Click to view a list of the trusted users");
final ItemStack members = getItem(Material.EMERALD, "&cMembers", "&cAmount: &6" + this.plot.members.size(), "&8Click to view a list of plot members");
final ItemStack denied = getItem(Material.EMERALD, "&cDenied", "&cAmount: &6" + this.plot.denied.size(), "&8Click to view a list of denied players");
final ItemStack flags = getItem(Material.EMERALD, "&cFlags", "&cAmount: &6" + this.plot.settings.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;
}
}

View File

@ -0,0 +1,9 @@
package com.intellectualcrafters.plot.object;
public abstract class LazyBlock {
public abstract PlotBlock getPlotBlock();
public int getId() {
return getPlotBlock().id;
}
}

View File

@ -0,0 +1,217 @@
package com.intellectualcrafters.plot.object;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* Created 2015-02-11 for PlotSquared
*
* @author Citymonstret
*/
public class Location implements Cloneable, Comparable<Location> {
private int x, y, z;
private float yaw, pitch;
private String world;
private boolean built;
private Object o;
@Override
public Location clone() {
return new Location(this.world, this.x, this.y, this.z, this.yaw, this.pitch);
}
public Location(final String world, final int x, final int y, final int z, final float yaw, final float pitch) {
this.world = world;
this.x = x;
this.y = y;
this.z = z;
this.yaw = yaw;
this.pitch = pitch;
this.built = false;
this.o = null;
}
public Location() {
this("", 0, 0, 0, 0, 0);
}
public Location(final String world, final int x, final int y, final int z) {
this(world, x, y, z, 0f, 0f);
}
public int getX() {
return this.x;
}
public void setX(final int x) {
this.x = x;
this.built = false;
}
public int getY() {
return this.y;
}
public void setY(final int y) {
this.y = y;
this.built = false;
}
public int getZ() {
return this.z;
}
public void setZ(final int z) {
this.z = z;
this.built = false;
}
public String getWorld() {
return this.world;
}
public void setWorld(final String world) {
this.world = world;
this.built = false;
}
public float getYaw() {
return this.yaw;
}
public void setYaw(final float yaw) {
this.yaw = yaw;
this.built = false;
}
public float getPitch() {
return this.pitch;
}
public void setPitch(final float pitch) {
this.pitch = pitch;
this.built = false;
}
public Location add(final int x, final int y, final int z) {
this.x += x;
this.y += y;
this.z += z;
this.built = false;
return this;
}
public double getEuclideanDistanceSquared(final Location l2) {
final double x = getX() - l2.getX();
final double y = getY() - l2.getY();
final double z = getZ() - l2.getZ();
return (x * x) + (y * y) + (z * z);
}
public double getEuclideanDistance(final Location l2) {
return Math.sqrt(getEuclideanDistanceSquared(l2));
}
public boolean isInSphere(final Location origin, final int radius) {
return getEuclideanDistanceSquared(origin) < (radius * radius);
}
@Override
public int hashCode() {
int hash = 127;
hash = (hash * 31) + this.x;
hash = (hash * 31) + this.y;
hash = (hash * 31) + this.z;
hash = (int) ((hash * 31) + getYaw());
hash = (int) ((hash * 31) + getPitch());
return (hash * 31) + (this.world == null ? 127 : this.world.hashCode());
}
public boolean isInAABB(final Location min, final Location max) {
return (this.x >= min.getX()) && (this.x <= max.getX()) && (this.y >= min.getY()) && (this.y <= max.getY()) && (this.z >= min.getX()) && (this.z < max.getZ());
}
public void lookTowards(final int x, final int y) {
final double l = this.x - x;
final double w = this.z - this.z;
final double c = Math.sqrt((l * l) + (w * w));
if (((Math.asin(w / c) / Math.PI) * 180) > 90) {
setYaw((float) (180 - ((-Math.asin(l / c) / Math.PI) * 180)));
} else {
setYaw((float) ((-Math.asin(l / c) / Math.PI) * 180));
}
this.built = false;
}
public Location subtract(final int x, final int y, final int z) {
this.x -= x;
this.y -= y;
this.z -= z;
this.built = false;
return this;
}
@Override
public boolean equals(final Object o) {
if (o == null) {
return false;
}
if (!(o instanceof Location)) {
return false;
}
final Location l = (Location) o;
return (this.x == l.getX()) && (this.y == l.getY()) && (this.z == l.getZ()) && this.world.equals(l.getWorld()) && (this.yaw == l.getY()) && (this.pitch == l.getPitch());
}
@Override
public int compareTo(final Location o) {
if (o == null) {
throw new NullPointerException("Specified object was null");
}
if (((this.x == o.getX()) && (this.y == o.getY())) || (this.z == o.getZ())) {
return 0;
}
if ((this.x < o.getX()) && (this.y < o.getY()) && (this.z < o.getZ())) {
return -1;
}
return 1;
}
@Override
public String toString() {
return "\"plotsquaredlocation\":{" + "\"x\":" + this.x + ",\"y\":" + this.y + ",\"z\":" + this.z + ",\"yaw\":" + this.yaw + ",\"pitch\":" + this.pitch + ",\"world\":\"" + this.world + "\"}";
}
private Object getBukkitWorld() {
try {
final Class clazz = Class.forName("org.bukkit.Bukkit");
return clazz.getMethod("getWorld", String.class).invoke(null, this.world);
} catch (final Exception e) {
return null;
}
}
public Object toBukkitLocation() {
if (this.built) {
return this.o;
}
try {
final Constructor constructor = Class.forName("org.bukkit.Location").getConstructor(Class.forName("org.bukkit.World"), double.class, double.class, double.class, float.class, float.class);
this.built = true;
return (this.o = constructor.newInstance(Class.forName("org.bukkit.World").cast(getBukkitWorld()), this.x, this.y, this.z, this.yaw, this.pitch));
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | ClassNotFoundException | NoSuchMethodException e) {
return null;
}
}
/**
* Please use utility class as this is not efficient
*/
public void teleport(final Object o) throws Exception {
if (o.getClass().getName().contains("org.bukkit.entity")) {
final Method m = o.getClass().getMethod("teleport", Class.forName("org.bukkit.Location"));
m.invoke(o, toBukkitLocation());
}
}
}

View File

@ -0,0 +1,18 @@
package com.intellectualcrafters.plot.object;
import java.util.UUID;
/**
* Created 2015-02-20 for PlotSquared
*
* @author Citymonstret
*/
public interface OfflinePlotPlayer {
public UUID getUUID();
public long getLastPlayed();
public boolean isOnline();
public String getName();
}

View File

@ -0,0 +1,546 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// 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.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.UUID;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
/**
* The plot class
*
* @author Citymonstret
* @author Empire92
*/
@SuppressWarnings("javadoc")
public class Plot implements Cloneable {
/**
* plot ID
*/
public final PlotId id;
/**
* plot world
*/
public final String world;
/**
* plot owner
*/
public UUID owner;
/**
* List of trusted (with plot permissions)
*/
public ArrayList<UUID> trusted;
/**
* List of members users (with plot permissions)
*/
public ArrayList<UUID> members;
/**
* List of denied players
*/
public ArrayList<UUID> denied;
/**
* External settings class<br>
* - Please favor the methods over direct access to this class<br>
* - The methods are more likely to be left unchanged from version changes<br>
*/
public PlotSettings settings;
/**
* Has the plot changed since the last save cycle?
*/
public boolean hasChanged = false;
public boolean countsTowardsMax = true;
/**
* If this plot is temporary i.e. not stored in the DB
*/
public final boolean temp;
/**
* Constructor for a new plot
*
* @param world
* @param id
* @param owner
*/
public Plot(String world, PlotId id, UUID owner) {
this.world = world;
this.id = id;
this.owner = owner;
this.settings = new PlotSettings(this);
this.trusted = new ArrayList<>();
this.members = new ArrayList<>();
this.denied = new ArrayList<>();
this.temp = false;
}
/**
* Constructor for a temporary plot
*
* @param world
* @param id
* @param owner
* @param temp
*/
public Plot(String world, PlotId id, UUID owner, boolean temp) {
this.world = world;
this.id = id;
this.owner = owner;
this.settings = new PlotSettings(this);
this.trusted = new ArrayList<>();
this.members = new ArrayList<>();
this.denied = new ArrayList<>();
this.temp = temp;
}
/**
* Constructor for a saved plots
*
* @param id
* @param owner
* @param trusted
* @param denied
* @param merged
*/
public Plot(final PlotId id, final UUID owner, final ArrayList<UUID> trusted, final ArrayList<UUID> members, final ArrayList<UUID> denied, final String alias, final BlockLoc position, final Collection<Flag> flags, final String world, final boolean[] merged) {
this.id = id;
this.settings = new PlotSettings(this);
this.owner = owner;
this.members = members;
this.trusted = trusted;
this.denied = denied;
this.settings.setAlias(alias);
this.settings.setPosition(position);
this.settings.setMerged(merged);
if (flags != null) {
for (Flag flag : flags) {
this.settings.flags.put(flag.getKey(), flag);
}
}
this.world = world;
this.temp = false;
}
/**
* Check if the plot has a set owner
*
* @return false if there is no owner
*/
public boolean hasOwner() {
return this.owner != null;
}
public boolean isOwner(UUID uuid) {
return PlotHandler.isOwner(this, uuid);
}
/**
* Get a list of owner UUIDs for a plot (supports multi-owner mega-plots)
* @return
*/
public HashSet<UUID> getOwners() {
return PlotHandler.getOwners(this);
}
/**
* Check if the player is either the owner or on the trusted list
*
* @param uuid
*
* @return true if the player is added as a helper or is the owner
*/
public boolean isAdded(final UUID uuid) {
return PlotHandler.isAdded(this, uuid);
}
/**
* Should the player be allowed to enter?
*
* @param uuid
*
* @return boolean false if the player is allowed to enter
*/
public boolean isDenied(final UUID uuid) {
return (this.denied != null) && ((this.denied.contains(DBFunc.everyone) && !this.isAdded(uuid)) || (!this.isAdded(uuid) && this.denied.contains(uuid)));
}
/**
* Get the plot ID
*/
public PlotId getId() {
return this.id;
}
/**
* Get a clone of the plot
*
* @return Plot
*/
@Override
public Object clone() throws CloneNotSupportedException {
final Plot p = (Plot) super.clone();
if (!p.equals(this) || (p != this)) {
return new Plot(this.id, this.owner, this.trusted, this.members, this.denied, this.settings.getAlias(), this.settings.getPosition(), this.settings.flags.values(), this.world, this.settings.getMerged());
}
return p;
}
/**
* Deny someone (use DBFunc.addDenied() as well)
*
* @param uuid
*/
public void addDenied(final UUID uuid) {
if (this.denied.add(uuid)) DBFunc.setDenied(this, uuid);
}
/**
* Add someone as a helper (use DBFunc as well)
*
* @param uuid
*/
public void addTrusted(final UUID uuid) {
if (this.trusted.add(uuid)) DBFunc.setTrusted(this, uuid);
}
/**
* Add someone as a trusted user (use DBFunc as well)
*
* @param uuid
*/
public void addMember(final UUID uuid) {
if (this.members.add(uuid)) DBFunc.setMember(this, uuid);
}
/**
* Set the plot owner
* @param owner
*/
public void setOwner(final UUID owner) {
if (!this.owner.equals(owner)) {
this.owner = owner;
DBFunc.setOwner(this, owner);
}
}
/**
* Clear a plot
* @see MainUtil#clear(Plot, boolean, Runnable)
* @see MainUtil#clearAsPlayer(Plot, boolean, Runnable)
* @see #delete() to clear and delete a plot
* @param whenDone A runnable to execute when clearing finishes, or null
*/
public void clear(Runnable whenDone) {
MainUtil.clear(this, false, whenDone);
}
/**
* Delete a plot
* @see PS#removePlot(String, PlotId, boolean)
* @see #clear(Runnable) to simply clear a plot
*/
public void delete() {
MainUtil.removeSign(this);
MainUtil.clear(this, true, new Runnable() {
@Override
public void run() {
if (PS.get().removePlot(world, id, true)) {
DBFunc.delete(Plot.this);
}
}
});
}
public void unclaim() {
if (PS.get().removePlot(world, id, true)) {
DBFunc.delete(Plot.this);
}
}
/**
* Unlink a plot and remove the roads
* @see MainUtil#unlinkPlot(Plot)
* @return true if plot was linked
*/
public boolean unlink() {
return MainUtil.unlinkPlot(this);
}
/**
* Return the home location for the plot
* @see MainUtil#getPlotHome(Plot)
* @return Home location
*/
public Location getHome() {
return MainUtil.getPlotHome(this);
}
/**
* Get the ratings associated with a plot<br>
* - The rating object may contain multiple categories
* @return Map of user who rated to the rating
*/
public HashMap<UUID, Rating> getRatings() {
HashMap<UUID, Rating> map = new HashMap<UUID, Rating>();
for (Entry<UUID, Integer> entry : settings.ratings.entrySet()) {
map.put(entry.getKey(), new Rating(entry.getValue()));
}
return map;
}
/**
* Set the home location
* @param loc
*/
public void setHome(BlockLoc loc) {
BlockLoc pos = this.settings.getPosition();
if ((pos == null && loc == null) || (pos != null && pos.equals(loc))) {
return;
}
this.settings.setPosition(loc);
if (this.settings.getPosition() == null) {
DBFunc.setPosition(this, "");
}
else {
DBFunc.setPosition(this, this.settings.getPosition().toString());
}
}
/**
* Set the plot alias
* @param alias
*/
public void setAlias(String alias) {
String name = this.settings.getAlias();
if (alias == null) {
alias = "";
}
if (name.equals(alias)) {
return;
}
this.settings.setAlias(alias);
DBFunc.setAlias(this, alias);
}
/**
* Resend all chunks inside the plot to nearby players<br>
* This should not need to be called
* @see MainUtil#update(Plot)
*/
public void refreshChunks() {
MainUtil.update(this);
}
/**
* Remove the plot sign if it is set
*/
public void removeSign() {
MainUtil.removeSign(this);
}
/**
* Set the plot sign if plot signs are enabled
*/
public void setSign() {
MainUtil.setSign(this);
}
/**
* Register a plot and create it in the database<br>
* - The plot will not be created if the owner is null<br>
* - This will not save any trusted etc in the DB, those should be set after plot creation
* @return true if plot was created successfully
*/
public boolean create() {
return MainUtil.createPlot(owner, this);
}
/**
* Auto merge the plot with any adjacent plots of the same owner
* @see MainUtil#autoMerge(Plot, UUID) to specify the owner
*/
public void autoMerge() {
MainUtil.autoMerge(this, owner);
}
/**
* Set the plot biome
*/
public void setBiome(String biome) {
MainUtil.setBiome(this, biome);
}
/**
* Return the top location for the plot
* @return
*/
public Location getTop() {
return MainUtil.getPlotTopLoc(world, id);
}
/**
* Return the bottom location for the plot
* @return
*/
public Location getBottom() {
return MainUtil.getPlotBottomLoc(world, id);
}
/**
* Get the top plot, or this plot if it is not part of a mega plot
* @return The bottom plot
*/
public Plot getTopPlot() {
return MainUtil.getTopPlot(this);
}
/**
* Get the bottom plot, or this plot if it is not part of a mega plot
* @return The bottom plot
*/
public Plot getBottomPlot() {
return MainUtil.getBottomPlot(this);
}
/**
* Swap the plot contents and settings with another location<br>
* - The destination must correspond to a valid plot of equal dimensions
* @see ChunkManager#swap(String, bot1, top1, bot2, top2) to swap terrain
* @see MainUtil#getPlotSelectionIds(PlotId, PlotId) to get the plots inside a selection
* @see MainUtil#swapData(String, PlotId, PlotId, Runnable) to swap plot settings
* @param other The other plot id to swap with
* @param whenDone A task to run when finished, or null
* @see MainUtil#swapData(String, PlotId, PlotId, Runnable)
* @return boolean if swap was successful
*/
public boolean swap(PlotId destination, Runnable whenDone) {
return MainUtil.swap(world, id, destination, whenDone);
}
/**
* Move the plot to an empty location<br>
* - The location must be empty
* @param destination Where to move the plot
* @param whenDone A task to run when done, or null
* @return if the move was successful
*/
public boolean move(Plot destination, Runnable whenDone) {
return MainUtil.move(this, destination, whenDone);
}
/**
* Copy the plot contents and settings to another location<br>
* - The destination must correspond to an empty location
* @param destination The location to copy to
* @param whenDone The task to run when done
* @return If the copy was successful
*/
public boolean copy(PlotId destination, Runnable whenDone) {
return MainUtil.copy(world, id, destination, whenDone);
}
/**
* Get plot display name
*
* @return alias if set, else id
*/
@Override
public String toString() {
if (this.settings.getAlias().length() > 1) {
return this.settings.getAlias();
}
return this.world + ";" + this.getId().x + ";" + this.getId().y;
}
/**
* Remove a denied player (use DBFunc as well)
*
* @param uuid
*/
public boolean removeDenied(final UUID uuid) {
if (this.denied.remove(uuid)) {
DBFunc.removeDenied(this, uuid);
return true;
}
return false;
}
/**
* Remove a helper (use DBFunc as well)
*
* @param uuid
*/
public boolean removeTrusted(final UUID uuid) {
if (this.trusted.remove(uuid)) {
DBFunc.removeTrusted(this, uuid);
return true;
}
return false;
}
/**
* Remove a trusted user (use DBFunc as well)
*
* @param uuid
*/
public boolean removeMember(final UUID uuid) {
if (this.members.remove(uuid)) {
DBFunc.removeMember(this, uuid);
return true;
}
return false;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Plot other = (Plot) obj;
return ((this.id.x.equals(other.id.x)) && (this.id.y.equals(other.id.y)) && (this.world.equals(other.world)));
}
/**
* Get the plot hashcode
*
* @return integer. You can easily make this a character array <br> xI = c[0] x = c[1 -&gt; xI...] yI = c[xI ... + 1] y
* = c[xI ... + 2 -&gt; yI ...]
*/
@Override
public int hashCode() {
return this.id.hashCode();
}
}

View File

@ -0,0 +1,10 @@
package com.intellectualcrafters.plot.object;
public class PlotAnalysis {
public double changes;
public double faces;
public double data;
public double air;
public double variety;
public double complexity;
}

View File

@ -0,0 +1,65 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// 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;
/**
* @author Empire92
*/
public class PlotBlock {
public static PlotBlock EVERYTHING = new PlotBlock((short) 0, (byte) 0);
public final short id;
public final byte data;
public PlotBlock(final short id, final byte data) {
this.id = id;
this.data = data;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final PlotBlock other = (PlotBlock) obj;
return ((this.id == other.id) && ((this.data == other.data) || (this.data == -1) || (other.data == -1)));
}
@Override
public int hashCode() {
return this.id;
}
@Override
public String toString() {
if (this.data == -1) {
return this.id + "";
}
return this.id + ":" + this.data;
}
}

View File

@ -0,0 +1,77 @@
package com.intellectualcrafters.plot.object;
import java.util.HashSet;
import java.util.UUID;
import com.intellectualcrafters.plot.database.DBFunc;
public class PlotCluster {
public final String world;
public PlotSettings settings;
public UUID owner;
public HashSet<UUID> helpers = new HashSet<UUID>();
public HashSet<UUID> invited = new HashSet<UUID>();
private PlotId pos1;
private PlotId pos2;
public PlotId getP1() {
return this.pos1;
}
public PlotId getP2() {
return this.pos2;
}
public void setP1(final PlotId id) {
this.pos1 = id;
}
public void setP2(final PlotId id) {
this.pos2 = id;
}
public PlotCluster(final String world, final PlotId pos1, final PlotId pos2, final UUID owner) {
this.world = world;
this.pos1 = pos1;
this.pos2 = pos2;
this.owner = owner;
this.settings = new PlotSettings(null);
}
public boolean isAdded(final UUID uuid) {
return (this.owner.equals(uuid) || this.invited.contains(uuid) || this.invited.contains(DBFunc.everyone) || this.helpers.contains(uuid) || this.helpers.contains(DBFunc.everyone));
}
public boolean hasHelperRights(final UUID uuid) {
return (this.owner.equals(uuid) || this.helpers.contains(uuid) || this.helpers.contains(DBFunc.everyone));
}
public String getName() {
return this.settings.getAlias();
}
@Override
public int hashCode() {
return this.pos1.hashCode();
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final PlotCluster other = (PlotCluster) obj;
return (this.world.equals(other.world) && this.pos1.equals(other.pos1) && this.pos2.equals(other.pos2));
}
@Override
public String toString() {
return this.world + ";" + this.pos1.x + ";" + this.pos1.y + ";" + this.pos2.x + ";" + this.pos2.y;
}
}

View File

@ -0,0 +1,11 @@
package com.intellectualcrafters.plot.object;
public class PlotClusterId {
public final PlotId pos1;
public final PlotId pos2;
public PlotClusterId(final PlotId pos1, final PlotId pos2) {
this.pos1 = pos1;
this.pos2 = pos2;
}
}

View File

@ -0,0 +1,248 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// 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>();
}
@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) {
}
}

View File

@ -0,0 +1,98 @@
package com.intellectualcrafters.plot.object;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.UUID;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
public class PlotHandler {
public static HashSet<UUID> getOwners(Plot plot) {
if (plot.owner == null) {
return new HashSet<UUID>();
}
if (plot.settings.isMerged()) {
HashSet<UUID> owners = new HashSet<UUID>();
Plot top = MainUtil.getTopPlot(plot);
ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(plot.id, top.id);
for (PlotId id : ids) {
UUID owner = MainUtil.getPlot(plot.world, id).owner;
if (owner != null) {
owners.add(owner);
}
}
return owners;
}
return new HashSet<>(Arrays.asList(plot.owner));
}
public static boolean isOwner(Plot plot, UUID uuid) {
if (plot.owner == null) {
return false;
}
if (plot.settings.isMerged()) {
Plot top = MainUtil.getTopPlot(plot);
ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(plot.id, top.id);
for (PlotId id : ids) {
UUID owner = MainUtil.getPlot(plot.world, id).owner;
if (owner != null && owner.equals(uuid)) {
return true;
}
}
}
return plot.owner.equals(uuid);
}
public static boolean isOnline(Plot plot) {
if (plot.owner == null) {
return false;
}
if (plot.settings.isMerged()) {
Plot top = MainUtil.getTopPlot(plot);
ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(plot.id, top.id);
for (PlotId id : ids) {
UUID owner = MainUtil.getPlot(plot.world, id).owner;
if (owner != null) {
if (UUIDHandler.getPlayer(owner) != null) {
return true;
}
}
}
return false;
}
return UUIDHandler.getPlayer(plot.owner) != null;
}
public static boolean sameOwners(Plot plot1, Plot plot2) {
if (plot1.owner == null || plot2.owner == null) {
return false;
}
HashSet<UUID> owners = getOwners(plot1);
owners.retainAll(getOwners(plot2));
return owners.size() > 0;
}
public static boolean isAdded(Plot plot, final UUID uuid) {
if (plot.owner == null) {
return false;
}
if (isOwner(plot, uuid)) {
return true;
}
if (plot.denied.contains(uuid)) {
return false;
}
if (plot.trusted.contains(uuid) || plot.trusted.contains(DBFunc.everyone)) {
return true;
}
if (plot.members.contains(uuid) || plot.members.contains(DBFunc.everyone)) {
if (PlotHandler.isOnline(plot)) {
return true;
}
}
return PlotHandler.isOwner(plot, uuid);
}
}

View File

@ -0,0 +1,156 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// 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;
public class PlotId {
/**
* x value
*/
public Integer x;
/**
* y value
*/
public Integer y;
/**
* PlotId class (PlotId x,y values do not correspond to Block locations)
*
* @param x The plot x coordinate
* @param y The plot y coordinate
*/
public PlotId(final int x, final int y) {
this.x = x;
this.y = y;
}
/**
* Get a Plot Id based on a string
*
* @param string to create id from
*
* @return null if the string is invalid
*/
public static PlotId fromString(final String string) {
int x, y;
final String[] parts = string.split(";");
if (parts.length < 2) {
return null;
}
try {
x = Integer.parseInt(parts[0]);
y = Integer.parseInt(parts[1]);
} catch (final Exception e) {
return null;
}
return new PlotId(x, y);
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final PlotId other = (PlotId) obj;
return ((this.x.equals(other.x)) && (this.y.equals(other.y)));
}
@Override
public String toString() {
return this.x + ";" + this.y;
}
public static PlotId unpair(int hash) {
if (hash >= 0) {
if (hash % 2 == 0) {
// + +
hash /= 2;
int i = (int) (Math.abs(-1 + Math.sqrt(1 + 8 * hash)) / 2);
int idx = hash - ((i * (1 + i)) / 2);
int idy = ((i * (3 + i)) / 2) - hash;
return new PlotId(idx, idy);
}
else {
// + -
hash -= 1;
hash /= 2;
int i = (int) (Math.abs(-1 + Math.sqrt(1 + 8 * hash)) / 2);
int idx = hash - ((i * (1 + i)) / 2);
int idy = ((i * (3 + i)) / 2) - hash;
return new PlotId(idx, -idy);
}
}
else {
if (hash % 2 == 0) {
// - +
hash /= -2;
int i = (int) (Math.abs(-1 + Math.sqrt(1 + 8 * hash)) / 2);
int idx = hash - ((i * (1 + i)) / 2);
int idy = ((i * (3 + i)) / 2) - hash;
return new PlotId(-idx, idy);
}
else {
// - -
hash += 1;
hash /= -2;
int i = (int) (Math.abs(-1 + Math.sqrt(1 + 8 * hash)) / 2);
int idx = hash - ((i * (1 + i)) / 2);
int idy = ((i * (3 + i)) / 2) - hash;
return new PlotId(-idx, -idy);
}
}
}
private int hash;
public void recalculateHash() {
this.hash = 0;
hashCode();
}
@Override
public int hashCode() {
if (hash == 0) {
if (x >= 0) {
if (y >= 0) {
hash = (x * x) + (3 * x) + (2 * x * y) + y + (y * y);
} else {
final int y1 = -y;
hash = (x * x) + (3 * x) + (2 * x * y1) + y1 + (y1 * y1) + 1;
}
} else {
final int x1 = -x;
if (y >= 0) {
hash = -((x1 * x1) + (3 * x1) + (2 * x1 * y) + y + (y * y));
} else {
final int y1 = -y;
hash = -((x1 * x1) + (3 * x1) + (2 * x1 * y1) + y1 + (y1 * y1) + 1);
}
}
}
return hash;
}
}

View File

@ -0,0 +1,81 @@
package com.intellectualcrafters.plot.object;
import com.intellectualcrafters.plot.util.InventoryUtil;
public class PlotInventory {
public final PlotPlayer player;
public final int size;
private String title;
private final PlotItemStack[] items;
private boolean open = false;
public PlotInventory(PlotPlayer player) {
this.size = 4;
this.title = null;
this.player = player;
items = InventoryUtil.manager.getItems(player);
}
public PlotInventory(PlotPlayer player, int size, String name) {
this.size = size;
this.title = name == null ? "" : name;
this.player = player;
items = new PlotItemStack[size * 9];
}
public boolean onClick(int index) {
return true;
}
public void openInventory() {
if (title == null) {
return;
}
open = true;
InventoryUtil.manager.open(this);
}
public void close() {
if (title == null) {
return;
}
InventoryUtil.manager.close(this);
open = false;
}
public void setItem(int index, PlotItemStack item) {
items[index] = item;
InventoryUtil.manager.setItem(this, index, item);
}
public PlotItemStack getItem(int index) {
return items[index];
}
public void setTitle(String title) {
if (title == null) {
return;
}
boolean tmp = open;
close();
this.title = title;
if (tmp) {
openInventory();
}
}
public PlotItemStack[] getItems() {
return items;
}
public String getTitle() {
return this.title;
}
public boolean isOpen() {
return open;
}
}

View File

@ -0,0 +1,17 @@
package com.intellectualcrafters.plot.object;
public class PlotItemStack {
public final int id;
public final short data;
public final int amount;
public final String name;
public final String[] lore;
public PlotItemStack(int id, short data, int amount, String name, String[] lore) {
this.id = id;
this.data = data;
this.amount = amount;
this.name = name;
this.lore = lore;
}
}

View File

@ -0,0 +1,35 @@
package com.intellectualcrafters.plot.object;
public class PlotLoc {
public int x;
public int z;
public PlotLoc(final int x, final int z) {
this.x = x;
this.z = z;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = (prime * result) + this.x;
result = (prime * result) + this.z;
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final PlotLoc other = (PlotLoc) obj;
return ((this.x == other.x) && (this.z == other.z));
}
}

View File

@ -0,0 +1,95 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// 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.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import com.intellectualcrafters.plot.commands.Template;
public abstract class PlotManager {
/*
* Plot locations (methods with Abs in them will not need to consider mega
* plots)
*/
public abstract PlotId getPlotIdAbs(final PlotWorld plotworld, final int x, final int y, final int z);
public abstract PlotId getPlotId(final PlotWorld plotworld, final int x, final int y, final int z);
// If you have a circular plot, just return the corner if it were a square
public abstract Location getPlotBottomLocAbs(final PlotWorld plotworld, final PlotId plotid);
// the same applies here
public abstract Location getPlotTopLocAbs(final PlotWorld plotworld, final PlotId plotid);
/*
* Plot clearing (return false if you do not support some method)
*/
public abstract boolean clearPlot(final PlotWorld plotworld, final Plot plot, boolean isDelete, Runnable whenDone);
public abstract boolean claimPlot(final PlotWorld plotworld, final Plot plot);
public abstract boolean unclaimPlot(final PlotWorld plotworld, final Plot plot);
public abstract Location getSignLoc(final PlotWorld plotworld, final Plot plot);
/*
* Plot set functions (return false if you do not support the specific set
* method)
*/
public abstract String[] getPlotComponents(final PlotWorld plotworld, final PlotId plotid);
public abstract boolean setComponent(final PlotWorld plotworld, final PlotId plotid, final String component, final PlotBlock[] blocks);
public abstract boolean setBiome(final Plot plot, final int biome);
/*
* PLOT MERGING (return false if your generator does not support plot
* merging)
*/
public abstract boolean createRoadEast(final PlotWorld plotworld, final Plot plot);
public abstract boolean createRoadSouth(final PlotWorld plotworld, final Plot plot);
public abstract boolean createRoadSouthEast(final PlotWorld plotworld, final Plot plot);
public abstract boolean removeRoadEast(final PlotWorld plotworld, final Plot plot);
public abstract boolean removeRoadSouth(final PlotWorld plotworld, final Plot plot);
public abstract boolean removeRoadSouthEast(final PlotWorld plotworld, final Plot plot);
public abstract boolean startPlotMerge(final PlotWorld plotworld, final ArrayList<PlotId> plotIds);
public abstract boolean startPlotUnlink(final PlotWorld plotworld, final ArrayList<PlotId> plotIds);
public abstract boolean finishPlotMerge(final PlotWorld plotworld, final ArrayList<PlotId> plotIds);
public abstract boolean finishPlotUnlink(final PlotWorld plotworld, final ArrayList<PlotId> plotIds);
public void exportTemplate(PlotWorld plotworld) throws IOException {
HashSet<FileBytes> files = new HashSet<>(Arrays.asList(new FileBytes("templates/" + "tmp-data.yml", Template.getBytes(plotworld))));
Template.zipAll(plotworld.worldname, files);
}
}

View File

@ -0,0 +1,61 @@
package com.intellectualcrafters.plot.object;
import java.util.UUID;
/**
* Created 2015-02-20 for PlotSquared
*
* @author Citymonstret
*/
public interface PlotPlayer {
public long getPreviousLogin();
public Location getLocation();
public Location getLocationFull();
public UUID getUUID();
public boolean hasPermission(final String perm);
public void sendMessage(final String message);
public void teleport(final Location loc);
public boolean isOp();
public boolean isOnline();
public String getName();
public void setCompassTarget(Location loc);
public void loadData();
public void saveData();
/**
* Set player data that will persist restarts
* - Please note that this is not intended to store large values
* - For session only data use meta
* @param key
*/
public void setAttribute(String key);
/**
* The attribute will be either true or false
* @param key
*/
public boolean getAttribute(String key);
/**
* Remove an attribute from a player
* @param key
*/
public void removeAttribute(String key);
public void setMeta(String key, Object value);
public Object getMeta(String key);
public void deleteMeta(String key);
}

View File

@ -0,0 +1,108 @@
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));
}
}

View File

@ -0,0 +1,202 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// 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.UUID;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.comment.PlotComment;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil;
/**
* plot settings
*
* @author Citymonstret
* @author Empire92
*/
@SuppressWarnings("unused")
public class PlotSettings {
/**
* Plot
*/
private final Plot plot;
/**
* merged plots
*/
private boolean[] merged = new boolean[] { false, false, false, false };
/**
* plot alias
*/
private String alias;
/**
* Comments
*/
private List<PlotComment> comments = null;
/**
* The ratings for a plot
*/
public HashMap<UUID, Integer> ratings;
/**
* Flags
*/
public HashMap<String, Flag> flags;
/**
* Home Position
*/
private BlockLoc position;
/**
* Constructor
*
* @param plot object
*/
public PlotSettings(final Plot plot) {
this.alias = "";
this.plot = plot;
this.flags = new HashMap<>();
}
/**
* <b>Check if the plot is merged in a direction</b><br> 0 = North<br> 1 = East<br> 2 = South<br> 3 = West<br>
*
* @param direction Direction to check
*
* @return boolean merged
*/
public boolean getMerged(final int direction) {
return this.merged[direction];
}
/**
* Returns true if the plot is merged (i.e. if it's a mega plot)
*/
public boolean isMerged() {
return (this.merged[0] || this.merged[1] || this.merged[2] || this.merged[3]);
}
public boolean[] getMerged() {
return this.merged;
}
public void setMerged(final boolean[] merged) {
this.merged = merged;
}
public void setMerged(final int direction, final boolean merged) {
this.merged[direction] = merged;
}
/**
* @return biome at plot loc
*/
public String getBiome() {
final Location loc = MainUtil.getPlotBottomLoc(this.plot.world, this.plot.getId()).add(1, 0, 1);
return BlockManager.manager.getBiome(loc);
}
public BlockLoc getPosition() {
if (this.position == null) {
return new BlockLoc(0, 0, 0);
}
return this.position;
}
public void setPosition(final BlockLoc position) {
this.position = position;
}
public String getAlias() {
return this.alias;
}
/**
* Set the plot alias
*
* @param alias alias to be used
*/
public void setAlias(final String alias) {
this.alias = alias;
}
public String getJoinMessage() {
final Flag greeting = FlagManager.getPlotFlag(this.plot, "greeting");
if (greeting != null) {
return greeting.getValueString();
}
return "";
}
/**
* Get the "farewell" flag value
*
* @return Farewell flag
*/
public String getLeaveMessage() {
final Flag farewell = FlagManager.getPlotFlag(this.plot, "farewell");
if (farewell != null) {
return farewell.getValueString();
}
return "";
}
public ArrayList<PlotComment> getComments(final String inbox) {
final ArrayList<PlotComment> c = new ArrayList<>();
if (this.comments == null) {
return null;
}
for (final PlotComment comment : this.comments) {
if (comment.inbox.equals(inbox)) {
c.add(comment);
}
}
return c;
}
public void setComments(final List<PlotComment> comments) {
this.comments = comments;
}
public void removeComment(final PlotComment comment) {
if (this.comments.contains(comment)) {
this.comments.remove(comment);
}
}
public void removeComments(final List<PlotComment> comments) {
for (final PlotComment comment : comments) {
removeComment(comment);
}
}
public void addComment(final PlotComment comment) {
if (this.comments == null) {
this.comments = new ArrayList<>();
}
this.comments.add(comment);
}
}

View File

@ -0,0 +1,257 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// 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.Set;
import org.apache.commons.lang.StringUtils;
import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.Configuration;
import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.util.EconHandler;
/**
* @author Jesse Boyd
*/
public abstract class PlotWorld {
public final static boolean AUTO_MERGE_DEFAULT = false;
public final static boolean ALLOW_SIGNS_DEFAULT = true;
public final static boolean MOB_SPAWNING_DEFAULT = false;
public final static String PLOT_BIOME_DEFAULT = "FOREST";
public final static boolean PLOT_CHAT_DEFAULT = false;
public final static boolean SCHEMATIC_CLAIM_SPECIFY_DEFAULT = false;
public final static boolean SCHEMATIC_ON_CLAIM_DEFAULT = false;
public final static String SCHEMATIC_FILE_DEFAULT = "null";
public final static List<String> SCHEMATICS_DEFAULT = null;
public final static boolean USE_ECONOMY_DEFAULT = false;
public final static double PLOT_PRICE_DEFAULT = 100;
public final static double MERGE_PRICE_DEFAULT = 100;
public final static double SELL_PRICE_DEFAULT = 75;
public final static boolean PVP_DEFAULT = false;
public final static boolean PVE_DEFAULT = false;
public final static boolean SPAWN_EGGS_DEFAULT = false;
public final static boolean SPAWN_CUSTOM_DEFAULT = true;
public final static boolean SPAWN_BREEDING_DEFAULT = false;
public final static boolean WORLD_BORDER_DEFAULT = false;
public final static int MAX_PLOT_MEMBERS_DEFAULT = 128;
// are plot clusters enabled
// require claim in cluster
// TODO make this configurable
// make non static and static_default_valu + add config option
public static int[] BLOCKS;
static {
BLOCKS = new int[] { 1, 2, 3, 4, 5, 7, 14, 15, 16, 17, 19, 21, 22, 23, 24, 25, 35, 41, 42, 43, 45, 47, 48, 49, 52, 56, 57, 58, 61, 62, 73, 74, 80, 82, 84, 86, 87, 88, 91, 97, 98, 99, 100, 103, 110, 112, 120, 121, 123, 124, 125, 129, 133, 153, 155, 159, 162, 165, 166, 168, 170, 172, 173, 174, 179, 181 };
}
public final String worldname;
public int MAX_PLOT_MEMBERS;
public boolean AUTO_MERGE;
public boolean ALLOW_SIGNS;
public boolean MOB_SPAWNING;
public String PLOT_BIOME;
public boolean PLOT_CHAT;
public boolean SCHEMATIC_CLAIM_SPECIFY = false;
public boolean SCHEMATIC_ON_CLAIM;
public String SCHEMATIC_FILE;
public List<String> SCHEMATICS;
public HashMap<String, Flag> DEFAULT_FLAGS;
public boolean USE_ECONOMY;
public double PLOT_PRICE;
public double MERGE_PRICE;
public double SELL_PRICE;
public boolean PVP;
public boolean PVE;
public boolean SPAWN_EGGS;
public boolean SPAWN_CUSTOM;
public boolean SPAWN_BREEDING;
public boolean WORLD_BORDER;
public int TYPE = 0;
public int TERRAIN = 0;
public boolean HOME_ALLOW_NONMEMBER;
public PlotLoc DEFAULT_HOME;
public PlotWorld(final String worldname) {
this.worldname = worldname;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
PlotWorld plotworld = (PlotWorld) obj;
ConfigurationSection section = PS.get().config.getConfigurationSection("worlds");
for (ConfigurationNode setting : plotworld.getSettingNodes()) {
Object constant = section.get(plotworld.worldname + "." + setting.getConstant());
if (constant == null) {
return false;
}
if (!constant.equals(section.get(this.worldname + "." + setting.getConstant()))) {
return false;
}
}
return true;
}
/**
* When a world is created, the following method will be called for each
*
* @param config Configuration Section
*/
public void loadDefaultConfiguration(final ConfigurationSection config) {
if (config.contains("generator.terrain")) {
this.TERRAIN = config.getInt("generator.terrain");
this.TYPE = config.getInt("generator.type");
}
this.MOB_SPAWNING = config.getBoolean("natural_mob_spawning");
this.AUTO_MERGE = config.getBoolean("plot.auto_merge");
this.MAX_PLOT_MEMBERS = config.getInt("limits.max-members");
this.ALLOW_SIGNS = config.getBoolean("plot.create_signs");
this.PLOT_BIOME = (String) Configuration.BIOME.parseString(config.getString("plot.biome"));
this.SCHEMATIC_ON_CLAIM = config.getBoolean("schematic.on_claim");
this.SCHEMATIC_FILE = config.getString("schematic.file");
this.SCHEMATIC_CLAIM_SPECIFY = config.getBoolean("schematic.specify_on_claim");
this.SCHEMATICS = config.getStringList("schematic.schematics");
this.USE_ECONOMY = config.getBoolean("economy.use") && (EconHandler.manager != null);
this.PLOT_PRICE = config.getDouble("economy.prices.claim");
this.MERGE_PRICE = config.getDouble("economy.prices.merge");
this.SELL_PRICE = config.getDouble("economy.prices.sell");
this.PLOT_CHAT = config.getBoolean("chat.enabled");
this.WORLD_BORDER = config.getBoolean("world.border");
this.HOME_ALLOW_NONMEMBER = config.getBoolean("home.allow-nonmembers");
String homeDefault = config.getString("home.default");
if (homeDefault.equalsIgnoreCase("side")) {
DEFAULT_HOME = null;
}
else if (homeDefault.equalsIgnoreCase("center")) {
DEFAULT_HOME = new PlotLoc(Integer.MAX_VALUE, Integer.MAX_VALUE);
}
else {
try {
String[] split = homeDefault.split(",");
DEFAULT_HOME = new PlotLoc(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
}
catch (Exception e) {
DEFAULT_HOME = null;
}
}
List<String> flags = config.getStringList("flags.default");
if (flags == null || flags.size() == 0) {
flags = config.getStringList("flags");
if (flags == null || flags.size() == 0) {
flags = new ArrayList<String>();
ConfigurationSection section = config.getConfigurationSection("flags");
Set<String> keys = section.getKeys(false);
for (String key : keys) {
if (!key.equals("default")) {
flags.add(key + ";" + section.get(key));
}
}
}
}
try {
this.DEFAULT_FLAGS = FlagManager.parseFlags(flags);
} catch (final Exception e) {
e.printStackTrace();
PS.log("&cInvalid default flags for " + this.worldname + ": " + StringUtils.join(flags, ","));
this.DEFAULT_FLAGS = new HashMap<>();
}
this.PVP = config.getBoolean("event.pvp");
this.PVE = config.getBoolean("event.pve");
this.SPAWN_EGGS = config.getBoolean("event.spawn.egg");
this.SPAWN_CUSTOM = config.getBoolean("event.spawn.custom");
this.SPAWN_BREEDING = config.getBoolean("event.spawn.breeding");
loadConfiguration(config);
}
public abstract void loadConfiguration(final ConfigurationSection config);
/**
* Saving core plotworld settings
*
* @param config Configuration Section
*/
public void saveConfiguration(final ConfigurationSection config) {
final HashMap<String, Object> options = new HashMap<>();
options.put("natural_mob_spawning", PlotWorld.MOB_SPAWNING_DEFAULT);
options.put("plot.auto_merge", PlotWorld.AUTO_MERGE_DEFAULT);
options.put("plot.create_signs", PlotWorld.ALLOW_SIGNS_DEFAULT);
options.put("plot.biome", PlotWorld.PLOT_BIOME_DEFAULT.toString());
options.put("schematic.on_claim", PlotWorld.SCHEMATIC_ON_CLAIM_DEFAULT);
options.put("schematic.file", PlotWorld.SCHEMATIC_FILE_DEFAULT);
options.put("schematic.specify_on_claim", PlotWorld.SCHEMATIC_CLAIM_SPECIFY_DEFAULT);
options.put("schematic.schematics", PlotWorld.SCHEMATICS_DEFAULT);
options.put("economy.use", PlotWorld.USE_ECONOMY_DEFAULT);
options.put("economy.prices.claim", PlotWorld.PLOT_PRICE_DEFAULT);
options.put("economy.prices.merge", PlotWorld.MERGE_PRICE_DEFAULT);
options.put("economy.prices.sell", PlotWorld.SELL_PRICE_DEFAULT);
options.put("chat.enabled", PlotWorld.PLOT_CHAT_DEFAULT);
options.put("flags.default", null);
options.put("event.pvp", PlotWorld.PVP_DEFAULT);
options.put("event.pve", PlotWorld.PVE_DEFAULT);
options.put("event.spawn.egg", PlotWorld.SPAWN_EGGS_DEFAULT);
options.put("event.spawn.custom", PlotWorld.SPAWN_CUSTOM_DEFAULT);
options.put("event.spawn.breeding", PlotWorld.SPAWN_BREEDING_DEFAULT);
options.put("world.border", PlotWorld.WORLD_BORDER_DEFAULT);
options.put("limits.max-members", PlotWorld.MAX_PLOT_MEMBERS_DEFAULT);
options.put("home.default", "side");
options.put("home.allow-nonmembers", false);
if (Settings.ENABLE_CLUSTERS && (this.TYPE != 0)) {
options.put("generator.terrain", this.TERRAIN);
options.put("generator.type", this.TYPE);
}
final ConfigurationNode[] settings = getSettingNodes();
/*
* Saving generator specific settings
*/
for (final ConfigurationNode setting : settings) {
options.put(setting.getConstant(), setting.getValue());
}
for (final String option : options.keySet()) {
if (!config.contains(option)) {
config.set(option, options.get(option));
}
}
}
/**
* Used for the <b>/plot setup</b> command Return null if you do not want to support this feature
*
* @return ConfigurationNode[]
*/
public abstract ConfigurationNode[] getSettingNodes();
}

View File

@ -0,0 +1,26 @@
package com.intellectualcrafters.plot.object;
public class PseudoRandom {
public long state = 1;
public long nextLong() {
final long a = state;
state = xorShift64(a);
return a;
}
public long xorShift64(long a) {
a ^= (a << 21);
a ^= (a >>> 35);
a ^= (a << 4);
return a;
}
public int random(final int n) {
if (n == 1) {
return 0;
}
final long r = ((nextLong() >>> 32) * n) >> 32;
return (int) r;
}
}

View File

@ -0,0 +1,49 @@
package com.intellectualcrafters.plot.object;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import com.intellectualcrafters.plot.config.Settings;
public class Rating {
/**
* This is a map of the rating category to the rating value
*/
private HashMap<String, Integer> ratingMap;
public Rating(int value) {
if (Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() > 1) {
for (int i = 0 ; i < Settings.RATING_CATEGORIES.size(); i++) {
ratingMap.put(Settings.RATING_CATEGORIES.get(i), (value % 10) - 1);
value /= 10;
}
}
else {
ratingMap.put(null, value);
}
}
public List<String> getCategories() {
if (ratingMap.size() == 1) {
return new ArrayList<>();
}
return new ArrayList<>(ratingMap.keySet());
}
public double getAverageRating() {
double total = 0;
for (Entry<String, Integer> entry : ratingMap.entrySet()) {
total += entry.getValue();
}
return total / (double) ratingMap.size();
}
public Integer getRating(String category) {
return ratingMap.get(category);
}
}

View File

@ -0,0 +1,15 @@
package com.intellectualcrafters.plot.object;
public class RegionWrapper {
public final int minX;
public final int maxX;
public final int minZ;
public final int maxZ;
public RegionWrapper(final int minX, final int maxX, final int minZ, final int maxZ) {
this.maxX = maxX;
this.minX = minX;
this.maxZ = maxZ;
this.minZ = minZ;
}
}

View File

@ -0,0 +1,6 @@
package com.intellectualcrafters.plot.object;
public abstract class RunnableVal<T> implements Runnable {
public T value;
public abstract void run();
}

View File

@ -0,0 +1,52 @@
package com.intellectualcrafters.plot.object;
import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.util.SetupUtils;
public class SetupObject {
/**
* Specify a SetupUtils object here to override the existing
*/
public SetupUtils setupManager;
/**
* The current state
*/
public int current = 0;
/**
* The index in generator specific settings
*/
public int setup_index = 0;
/**
* The name of the world
*/
public String world = null;
/**
* The name of the plot manager
*/
public String plotManager = null;
/**
* The name of the generator to use for world creation
*/
public String setupGenerator = null;
/**
* The management type
*/
public int type;
/**
* The terrain type
*/
public int terrain;
/**
* Generator specific configuration steps
*/
public ConfigurationNode[] step = null;
}

View File

@ -0,0 +1,85 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// 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;
/**
* @author Empire92
*/
public class StringWrapper {
public final String value;
/**
* Constructor
*
* @param value to wrap
*/
public StringWrapper(final String value) {
this.value = value;
}
/**
* Check if a wrapped string equals another one
*
* @param obj to compare
*
* @return true if obj equals the stored value
*/
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final StringWrapper other = (StringWrapper) obj;
if ((other.value == null) || (this.value == null)) {
return false;
}
return other.value.toLowerCase().equals(this.value.toLowerCase());
}
/**
* Get the string value
*
* @return string value
*/
@Override
public String toString() {
return this.value;
}
/**
* Get the hash value
*
* @return has value
*/
@Override
public int hashCode() {
if (this.value == null) {
return 0;
}
return this.value.toLowerCase().hashCode();
}
}

View File

@ -0,0 +1,35 @@
package com.intellectualcrafters.plot.object.comment;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
public abstract class CommentInbox {
@Override
public abstract String toString();
public abstract boolean canRead(Plot plot, PlotPlayer player);
public abstract boolean canWrite(Plot plot, PlotPlayer player);
public abstract boolean canModify(Plot plot, PlotPlayer player);
/**
* The plot may be null if the user is not standing in a plot. Return false if this is not a plot-less inbox.
* <br>
* The `whenDone` parameter should be executed when it's done fetching the comments.
* The value should be set to List of comments
*
* @param plot
* @param whenDone
* @return
*/
public abstract boolean getComments(Plot plot, RunnableVal whenDone);
public abstract boolean addComment(Plot plot, PlotComment comment);
public abstract boolean removeComment(Plot plot, PlotComment comment);
public abstract boolean clearInbox(Plot plot);
}

View File

@ -0,0 +1,79 @@
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());
}
}

View File

@ -0,0 +1,97 @@
package com.intellectualcrafters.plot.object.comment;
import java.util.ArrayList;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotHandler;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager;
public class InboxOwner extends CommentInbox {
@Override
public boolean canRead(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.read." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.read." + toString() + ".other")));
}
@Override
public boolean canWrite(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.write." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.write." + toString() + ".other")));
}
@Override
public boolean canModify(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.modify." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + toString() + ".other")));
}
@Override
public boolean getComments(final Plot plot, final RunnableVal whenDone) {
if (plot == null || plot.owner == null) {
return false;
}
ArrayList<PlotComment> comments = plot.settings.getComments(toString());
if (comments != null) {
whenDone.value = comments;
TaskManager.runTask(whenDone);
return true;
}
DBFunc.getComments(plot, toString(), new RunnableVal() {
@Override
public void run() {
whenDone.value = value;
if (value != null) {
for (PlotComment comment : (ArrayList<PlotComment>) value) {
plot.settings.addComment(comment);
}
}
TaskManager.runTask(whenDone);
}
});
return true;
}
@Override
public boolean addComment(Plot plot, PlotComment comment) {
if (plot == null || plot.owner == null) {
return false;
}
plot.settings.addComment(comment);
DBFunc.setComment(plot, comment);
return true;
}
@Override
public String toString() {
return "owner";
}
@Override
public boolean removeComment(Plot plot, PlotComment comment) {
if (plot == null || plot.owner == null) {
return false;
}
DBFunc.removeComment(plot, comment);
return false;
}
@Override
public boolean clearInbox(Plot plot) {
if (plot == null || plot.owner == null) {
return false;
}
DBFunc.clearInbox(plot, toString());
return false;
}
}

View File

@ -0,0 +1,97 @@
package com.intellectualcrafters.plot.object.comment;
import java.util.ArrayList;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotHandler;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager;
public class InboxPublic extends CommentInbox {
@Override
public boolean canRead(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.read." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.read." + toString() + ".other")));
}
@Override
public boolean canWrite(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.write." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.write." + toString() + ".other")));
}
@Override
public boolean canModify(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.modify." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + toString() + ".other")));
}
@Override
public boolean getComments(final Plot plot, final RunnableVal whenDone) {
if (plot == null || plot.owner == null) {
return false;
}
ArrayList<PlotComment> comments = plot.settings.getComments(toString());
if (comments != null) {
whenDone.value = comments;
TaskManager.runTask(whenDone);
return true;
}
DBFunc.getComments(plot, toString(), new RunnableVal() {
@Override
public void run() {
whenDone.value = value;
if (value != null) {
for (PlotComment comment : (ArrayList<PlotComment>) value) {
plot.settings.addComment(comment);
}
}
TaskManager.runTask(whenDone);
}
});
return true;
}
@Override
public boolean addComment(Plot plot, PlotComment comment) {
if (plot == null || plot.owner == null) {
return false;
}
plot.settings.addComment(comment);
DBFunc.setComment(plot, comment);
return true;
}
@Override
public String toString() {
return "public";
}
@Override
public boolean removeComment(Plot plot, PlotComment comment) {
if (plot == null || plot.owner == null) {
return false;
}
DBFunc.removeComment(plot, comment);
return false;
}
@Override
public boolean clearInbox(Plot plot) {
if (plot == null || plot.owner == null) {
return false;
}
DBFunc.clearInbox(plot, toString());
return false;
}
}

View File

@ -0,0 +1,80 @@
package com.intellectualcrafters.plot.object.comment;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotHandler;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager;
public class InboxReport extends CommentInbox {
@Override
public boolean canRead(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.read." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.read." + toString() + ".other")));
}
@Override
public boolean canWrite(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.write." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.write." + toString() + ".other")));
}
@Override
public boolean canModify(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.modify." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + toString() + ".other")));
}
@Override
public boolean getComments(final Plot plot, final RunnableVal whenDone) {
DBFunc.getComments(null, toString(), new RunnableVal() {
@Override
public void run() {
whenDone.value = value;
TaskManager.runTask(whenDone);
}
});
return true;
}
@Override
public boolean addComment(Plot plot, PlotComment comment) {
if (plot == null || plot.owner == null) {
return false;
}
DBFunc.setComment(plot, comment);
return true;
}
@Override
public String toString() {
return "report";
}
@Override
public boolean removeComment(Plot plot, PlotComment comment) {
if (plot == null || plot.owner == null) {
return false;
}
DBFunc.removeComment(plot, comment);
return false;
}
@Override
public boolean clearInbox(Plot plot) {
if (plot == null || plot.owner == null) {
return false;
}
DBFunc.clearInbox(plot, toString());
return false;
}
}

View File

@ -0,0 +1,44 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// 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.comment;
import com.intellectualcrafters.plot.object.PlotId;
/**
* @author Empire92
*/
public class PlotComment {
public final String comment;
public final String inbox;
public final String senderName;
public final PlotId id;
public final String world;
public final long timestamp;
public PlotComment(final String world, final PlotId id, final String comment, final String senderName, final String inbox, final long timestamp) {
this.world = world;
this.id = id;
this.comment = comment;
this.senderName = senderName;
this.inbox = inbox;
this.timestamp = timestamp;
}
}

View File

@ -0,0 +1,7 @@
package com.intellectualcrafters.plot.object.entity;
public class AgeableStats {
public int age;
public boolean locked;
public boolean adult;
}

View File

@ -0,0 +1,15 @@
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 boolean arms;
public boolean noplate;
public boolean nogravity;
public boolean invisible;
public boolean small;
}

View File

@ -0,0 +1,11 @@
package com.intellectualcrafters.plot.object.entity;
public class EntityBaseStats {
public EntityWrapper passenger;
public float fall;
public short fire;
public int age;
public double v_z;
public double v_y;
public double v_x;
}

View File

@ -0,0 +1,661 @@
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;
}
}

View File

@ -0,0 +1,9 @@
package com.intellectualcrafters.plot.object.entity;
public class HorseStats {
public double jump;
public boolean chest;
public int variant;
public int color;
public int style;
}

View File

@ -0,0 +1,26 @@
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;
}

View File

@ -0,0 +1,8 @@
package com.intellectualcrafters.plot.object.entity;
import org.bukkit.entity.AnimalTamer;
public class TameableStats {
public AnimalTamer owner;
public boolean tamed;
}

View File

@ -0,0 +1,643 @@
package com.intellectualcrafters.plot.object.schematic;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
public enum ItemType {
AIR("air", 0),
STONE("stone", 1),
GRANITE("stone", 1, 1),
POLISHED_GRANITE("stone", 1, 2),
DIORITE("stone", 1, 3),
POLISHED_DIORITE("stone", 1, 4),
ANDESITE("stone", 1, 5),
POLISHED_ANDESITE("stone", 1, 6),
GRASS("grass", 2),
DIRT("dirt", 3),
COARSE_DIRT("dirt", 3, 1),
PODZOL("dirt", 3, 2),
COBBLESTONE("cobblestone", 4),
OAK_WOOD_PLANK("planks", 5),
SPRUCE_WOOD_PLANK("planks", 5, 1),
BIRCH_WOOD_PLANK("planks", 5, 2),
JUNGLE_WOOD_PLANK("planks", 5, 3),
ACACIA_WOOD_PLANK("planks", 5, 4),
DARK_OAK_WOOD_PLANK("planks", 5, 5),
OAK_SAPLING("sapling", 6),
SPRUCE_SAPLING("sapling", 6, 1),
BIRCH_SAPLING("sapling", 6, 2),
JUNGLE_SAPLING("sapling", 6, 3),
ACACIA_SAPLING("sapling", 6, 4),
DARK_OAK_SAPLING("sapling", 6, 5),
BEDROCK("bedrock", 7),
FLOWING_WATER("flowing_water", 8),
STILL_WATER("water", 9),
FLOWING_LAVA("flowing_lava", 10),
STILL_LAVA("lava", 11),
SAND("sand", 12),
RED_SAND("sand", 12, 1),
GRAVEL("gravel", 13),
GOLD_ORE("gold_ore", 14),
IRON_ORE("iron_ore", 15),
COAL_ORE("coal_ore", 16),
OAK_WOOD("log", 17),
SPRUCE_WOOD("log", 17, 1),
BIRCH_WOOD("log", 17, 2),
JUNGLE_WOOD("log", 17, 3),
OAK_LEAVES("leaves", 18),
SPRUCE_LEAVES("leaves", 18, 1),
BIRCH_LEAVES("leaves", 18, 2),
JUNGLE_LEAVES("leaves", 18, 3),
SPONGE("sponge", 19),
WET_SPONGE("sponge", 19, 1),
GLASS("glass", 20),
LAPIS_LAZULI_ORE("lapis_ore", 21),
LAPIS_LAZULI_BLOCK("lapis_block", 22),
DISPENSER("dispenser", 23),
SANDSTONE("sandstone", 24),
CHISELED_SANDSTONE("sandstone", 24, 1),
SMOOTH_SANDSTONE("sandstone", 24, 2),
NOTE_BLOCK("noteblock", 25),
BED("bed", 26),
POWERED_RAIL("golden_rail", 27),
DETECTOR_RAIL("detector_rail", 28),
STICKY_PISTON("sticky_piston", 29),
COBWEB("web", 30),
DEAD_SHRUB("tallgrass", 31),
TALLGRASS("tallgrass", 31, 1),
FERN("tallgrass", 31, 2),
DEAD_SHRUB1("deadbush", 32),
PISTON("piston", 33),
PISTON_HEAD("piston_head", 34),
WHITE_WOOL("wool", 35),
ORANGE_WOOL("wool", 35, 1),
MAGENTA_WOOL("wool", 35, 2),
LIGHT_BLUE_WOOL("wool", 35, 3),
YELLOW_WOOL("wool", 35, 4),
LIME_WOOL("wool", 35, 5),
PINK_WOOL("wool", 35, 6),
GRAY_WOOL("wool", 35, 7),
LIGHT_GRAY_WOOL("wool", 35, 8),
CYAN_WOOL("wool", 35, 9),
PURPLE_WOOL("wool", 35, 10),
BLUE_WOOL("wool", 35, 11),
BROWN_WOOL("wool", 35, 12),
GREEN_WOOL("wool", 35, 13),
RED_WOOL("wool", 35, 14),
BLACK_WOOL("wool", 35, 15),
DANDELION("yellow_flower", 37),
POPPY("red_flower", 38),
BLUE_ORCHID("red_flower", 38, 1),
ALLIUM("red_flower", 38, 2),
AZURE_BLUET("red_flower", 38, 3),
RED_TULIP("red_flower", 38, 4),
ORANGE_TULIP("red_flower", 38, 5),
WHITE_TULIP("red_flower", 38, 6),
PINK_TULIP("red_flower", 38, 7),
OXEYE_DAISY("red_flower", 38, 8),
BROWN_MUSHROOM("brown_mushroom", 39),
RED_MUSHROOM("red_mushroom", 40),
GOLD_BLOCK("gold_block", 41),
IRON_BLOCK("iron_block", 42),
DOUBLE_STONE_SLAB("double_stone_slab", 43),
DOUBLE_SANDSTONE_SLAB("double_stone_slab", 43, 1),
DOUBLE_WOODEN_SLAB("double_stone_slab", 43, 2),
DOUBLE_COBBLESTONE_SLAB("double_stone_slab", 43, 3),
DOUBLE_BRICK_SLAB("double_stone_slab", 43, 4),
DOUBLE_STONE_BRICK_SLAB("double_stone_slab", 43, 5),
DOUBLE_NETHER_BRICK_SLAB("double_stone_slab", 43, 6),
DOUBLE_QUARTZ_SLAB("double_stone_slab", 43, 7),
STONE_SLAB("stone_slab", 44),
SANDSTONE_SLAB("stone_slab", 44, 1),
WOODEN_SLAB("stone_slab", 44, 2),
COBBLESTONE_SLAB("stone_slab", 44, 3),
BRICK_SLAB("stone_slab", 44, 4),
STONE_BRICK_SLAB("stone_slab", 44, 5),
NETHER_BRICK_SLAB("stone_slab", 44, 6),
QUARTZ_SLAB("stone_slab", 44, 7),
BRICKS("brick_block", 45),
TNT("tnt", 46),
BOOKSHELF("bookshelf", 47),
MOSS_STONE("mossy_cobblestone", 48),
OBSIDIAN("obsidian", 49),
TORCH("torch", 50),
FIRE("fire", 51),
MONSTER_SPAWNER("mob_spawner", 52),
OAK_WOOD_STAIRS("oak_stairs", 53),
CHEST("chest", 54),
REDSTONE_WIRE("redstone_wire", 55),
DIAMOND_ORE("diamond_ore", 56),
DIAMOND_BLOCK("diamond_block", 57),
CRAFTING_TABLE("crafting_table", 58),
WHEAT_CROPS("wheat", 59),
FARMLAND("farmland", 60),
FURNACE("furnace", 61),
BURNING_FURNACE("lit_furnace", 62),
STANDING_SIGN_BLOCK("standing_sign", 63),
OAK_DOOR_BLOCK("wooden_door", 64),
LADDER("ladder", 65),
RAIL("rail", 66),
COBBLESTONE_STAIRS("stone_stairs", 67),
WALL_MOUNTED_SIGN_BLOCK("wall_sign", 68),
LEVER("lever", 69),
STONE_PRESSURE_PLATE("stone_pressure_plate", 70),
IRON_DOOR_BLOCK("iron_door", 71),
WOODEN_PRESSURE_PLATE("wooden_pressure_plate", 72),
REDSTONE_ORE("redstone_ore", 73),
GLOWING_REDSTONE_ORE("lit_redstone_ore", 74),
REDSTONE_TORCH_OFF("unlit_redstone_torch", 75),
REDSTONE_TORCH_ON("redstone_torch", 76),
STONE_BUTTON("stone_button", 77),
SNOW("snow_layer", 78),
ICE("ice", 79),
SNOW_BLOCK("snow", 80),
CACTUS("cactus", 81),
CLAY("clay", 82),
SUGAR_CANES("reeds", 83),
JUKEBOX("jukebox", 84),
OAK_FENCE("fence", 85),
PUMPKIN("pumpkin", 86),
NETHERRACK("netherrack", 87),
SOUL_SAND("soul_sand", 88),
GLOWSTONE("glowstone", 89),
NETHER_PORTAL("portal", 90),
JACK_OLANTERN("lit_pumpkin", 91),
CAKE_BLOCK("cake", 92),
REDSTONE_REPEATER_BLOCK_OFF("unpowered_repeater", 93),
REDSTONE_REPEATER_BLOCK_ON("powered_repeater", 94),
WHITE_STAINED_GLASS("stained_glass", 95),
ORANGE_STAINED_GLASS("stained_glass", 95, 1),
MAGENTA_STAINED_GLASS("stained_glass", 95, 2),
LIGHT_BLUE_STAINED_GLASS("stained_glass", 95, 3),
YELLOW_STAINED_GLASS("stained_glass", 95, 4),
LIME_STAINED_GLASS("stained_glass", 95, 5),
PINK_STAINED_GLASS("stained_glass", 95, 6),
GRAY_STAINED_GLASS("stained_glass", 95, 7),
LIGHT_GRAY_STAINED_GLASS("stained_glass", 95, 8),
CYAN_STAINED_GLASS("stained_glass", 95, 9),
PURPLE_STAINED_GLASS("stained_glass", 95, 10),
BLUE_STAINED_GLASS("stained_glass", 95, 11),
BROWN_STAINED_GLASS("stained_glass", 95, 12),
GREEN_STAINED_GLASS("stained_glass", 95, 13),
RED_STAINED_GLASS("stained_glass", 95, 14),
BLACK_STAINED_GLASS("stained_glass", 95, 15),
WOODEN_TRAPDOOR("trapdoor", 96),
STONE_MONSTER_EGG("monster_egg", 97),
COBBLESTONE_MONSTER_EGG("monster_egg", 97, 1),
STONE_BRICK_MONSTER_EGG("monster_egg", 97, 2),
MOSSY_STONE_BRICK_MONSTER_EGG("monster_egg", 97, 3),
CRACKED_STONE_BRICK_MONSTER_EGG("monster_egg", 97, 4),
CHISELED_STONE_BRICK_MONSTER_EGG("monster_egg", 97, 5),
STONE_BRICKS("stonebrick", 98),
MOSSY_STONE_BRICKS("stonebrick", 98, 1),
CRACKED_STONE_BRICKS("stonebrick", 98, 2),
CHISELED_STONE_BRICKS("stonebrick", 98, 3),
RED_MUSHROOM_CAP("stonebrick", 99),
BROWN_MUSHROOM_CAP("stonebrick", 100),
IRON_BARS("iron_bars", 101),
GLASS_PANE("glass_pane", 102),
MELON_BLOCK("melon_block", 103),
PUMPKIN_STEM("pumpkin_stem", 104),
MELON_STEM("melon_stem", 105),
VINES("vine", 106),
OAK_FENCE_GATE("fence_gate", 107),
BRICK_STAIRS("brick_stairs", 108),
STONE_BRICK_STAIRS("stone_brick_stairs", 109),
MYCELIUM("mycelium", 110),
LILY_PAD("waterlily", 111),
NETHER_BRICK("nether_brick", 112),
NETHER_BRICK_FENCE("nether_brick_fence", 113),
NETHER_BRICK_STAIRS("nether_brick_stairs", 114),
NETHER_WART("nether_wart", 115),
ENCHANTMENT_TABLE("enchanting_table", 116),
BREWING_STAND("brewing_stand", 117),
CAULDRON("cauldron", 118),
END_PORTAL("end_portal", 119),
END_PORTAL_FRAME("end_portal_frame", 120),
END_STONE("end_stone", 121),
DRAGON_EGG("dragon_egg", 122),
REDSTONE_LAMP_INACTIVE("redstone_lamp", 123),
REDSTONE_LAMP_ACTIVE("lit_redstone_lamp", 124),
DOUBLE_OAK_WOOD_SLAB("double_wooden_slab", 125),
DOUBLE_SPRUCE_WOOD_SLAB("double_wooden_slab", 125, 1),
DOUBLE_BIRCH_WOOD_SLAB("double_wooden_slab", 125, 2),
DOUBLE_JUNGLE_WOOD_SLAB("double_wooden_slab", 125, 3),
DOUBLE_ACACIA_WOOD_SLAB("double_wooden_slab", 125, 4),
DOUBLE_DARK_OAK_WOOD_SLAB("double_wooden_slab", 125, 5),
OAK_WOOD_SLAB("wooden_slab", 126),
SPRUCE_WOOD_SLAB("wooden_slab", 126, 1),
BIRCH_WOOD_SLAB("wooden_slab", 126, 2),
JUNGLE_WOOD_SLAB("wooden_slab", 126, 3),
ACACIA_WOOD_SLAB("wooden_slab", 126, 4),
DARK_OAK_WOOD_SLAB("wooden_slab", 126, 5),
COCOA("cocoa", 127),
SANDSTONE_STAIRS("sandstone_stairs", 128),
EMERALD_ORE("emerald_ore", 129),
ENDER_CHEST("ender_chest", 130),
TRIPWIRE_HOOK("tripwire_hook", 131),
TRIPWIRE("tripwire_hook", 132),
EMERALD_BLOCK("emerald_block", 133),
SPRUCE_WOOD_STAIRS("spruce_stairs", 134),
BIRCH_WOOD_STAIRS("birch_stairs", 135),
JUNGLE_WOOD_STAIRS("jungle_stairs", 136),
COMMAND_BLOCK("command_block", 137),
BEACON("beacon", 138),
COBBLESTONE_WALL("cobblestone_wall", 139),
MOSSY_COBBLESTONE_WALL("cobblestone_wall", 139, 1),
FLOWER_POT("flower_pot", 140),
CARROTS("carrots", 141),
POTATOES("potatoes", 142),
WOODEN_BUTTON("wooden_button", 143),
MOB_HEAD("skull", 144),
ANVIL("anvil", 145),
TRAPPED_CHEST("trapped_chest", 146),
WEIGHTED_PRESSURE_PLATE_LIGHT("light_weighted_pressure_plate", 147),
WEIGHTED_PRESSURE_PLATE_HEAVY("heavy_weighted_pressure_plate", 148),
REDSTONE_COMPARATOR_INACTIVE("unpowered_comparator", 149),
REDSTONE_COMPARATOR_ACTIVE("powered_comparator", 150),
DAYLIGHT_SENSOR("daylight_detector", 151),
REDSTONE_BLOCK("redstone_block", 152),
NETHER_QUARTZ_ORE("quartz_ore", 153),
HOPPER("hopper", 154),
QUARTZ_BLOCK("quartz_block", 155),
CHISELED_QUARTZ_BLOCK("quartz_block", 155, 1),
PILLAR_QUARTZ_BLOCK("quartz_block", 155, 2),
QUARTZ_STAIRS("quartz_stairs", 156),
ACTIVATOR_RAIL("activator_rail", 157),
DROPPER("dropper", 158),
WHITE_STAINED_CLAY("stained_hardened_clay", 159),
ORANGE_STAINED_CLAY("stained_hardened_clay", 159, 1),
MAGENTA_STAINED_CLAY("stained_hardened_clay", 159, 2),
LIGHT_BLUE_STAINED_CLAY("stained_hardened_clay", 159, 3),
YELLOW_STAINED_CLAY("stained_hardened_clay", 159, 4),
LIME_STAINED_CLAY("stained_hardened_clay", 159, 5),
PINK_STAINED_CLAY("stained_hardened_clay", 159, 6),
GRAY_STAINED_CLAY("stained_hardened_clay", 159, 7),
LIGHT_GRAY_STAINED_CLAY("stained_hardened_clay", 159, 8),
CYAN_STAINED_CLAY("stained_hardened_clay", 159, 9),
PURPLE_STAINED_CLAY("stained_hardened_clay", 159, 10),
BLUE_STAINED_CLAY("stained_hardened_clay", 159, 11),
BROWN_STAINED_CLAY("stained_hardened_clay", 159, 12),
GREEN_STAINED_CLAY("stained_hardened_clay", 159, 13),
RED_STAINED_CLAY("stained_hardened_clay", 159, 14),
BLACK_STAINED_CLAY("stained_hardened_clay", 159, 15),
WHITE_STAINED_GLASS_PANE("stained_glass_pane", 160),
ORANGE_STAINED_GLASS_PANE("stained_glass_pane", 160, 1),
MAGENTA_STAINED_GLASS_PANE("stained_glass_pane", 160, 2),
LIGHT_BLUE_STAINED_GLASS_PANE("stained_glass_pane", 160, 3),
YELLOW_STAINED_GLASS_PANE("stained_glass_pane", 160, 4),
LIME_STAINED_GLASS_PANE("stained_glass_pane", 160, 5),
PINK_STAINED_GLASS_PANE("stained_glass_pane", 160, 6),
GRAY_STAINED_GLASS_PANE("stained_glass_pane", 160, 7),
LIGHT_GRAY_STAINED_GLASS_PANE("stained_glass_pane", 160, 8),
CYAN_STAINED_GLASS_PANE("stained_glass_pane", 160, 9),
PURPLE_STAINED_GLASS_PANE("stained_glass_pane", 160, 10),
BLUE_STAINED_GLASS_PANE("stained_glass_pane", 160, 11),
BROWN_STAINED_GLASS_PANE("stained_glass_pane", 160, 12),
GREEN_STAINED_GLASS_PANE("stained_glass_pane", 160, 13),
RED_STAINED_GLASS_PANE("stained_glass_pane", 160, 14),
BLACK_STAINED_GLASS_PANE("stained_glass_pane", 160, 15),
ACACIA_LEAVES("leaves2", 161),
DARK_OAK_LEAVES("leaves2", 161, 1),
ACACIA_WOOD("log2", 162),
DARK_OAK_WOOD("log2", 162, 1),
ACACIA_WOOD_STAIRS("acacia_stairs", 163),
DARK_OAK_WOOD_STAIRS("dark_oak_stairs", 164),
SLIME_BLOCK("slime", 165),
BARRIER("barrier", 166),
IRON_TRAPDOOR("iron_trapdoor", 167),
PRISMARINE("prismarine", 168),
PRISMARINE_BRICKS("prismarine", 168, 1),
DARK_PRISMARINE("prismarine", 168, 2),
SEA_LANTERN("sea_lantern", 169),
HAY_BALE("hay_block", 170),
WHITE_CARPET("carpet", 171),
ORANGE_CARPET("carpet", 171, 1),
MAGENTA_CARPET("carpet", 171, 2),
LIGHT_BLUE_CARPET("carpet", 171, 3),
YELLOW_CARPET("carpet", 171, 4),
LIME_CARPET("carpet", 171, 5),
PINK_CARPET("carpet", 171, 6),
GRAY_CARPET("carpet", 171, 7),
LIGHT_GRAY_CARPET("carpet", 171, 8),
CYAN_CARPET("carpet", 171, 9),
PURPLE_CARPET("carpet", 171, 10),
BLUE_CARPET("carpet", 171, 11),
BROWN_CARPET("carpet", 171, 12),
GREEN_CARPET("carpet", 171, 13),
RED_CARPET("carpet", 171, 14),
BLACK_CARPET("carpet", 171, 15),
HARDENED_CLAY("hardened_clay", 172),
BLOCK_OF_COAL("coal_block", 173),
PACKED_ICE("packed_ice", 174),
SUNFLOWER("double_plant", 175),
LILAC("double_plant", 175, 1),
DOUBLE_TALLGRASS("double_plant", 175, 2),
LARGE_FERN("double_plant", 175, 3),
ROSE_BUSH("double_plant", 175, 4),
PEONY("double_plant", 175, 5),
FREE_STANDING_BANNER("standing_banner", 176),
WALL_MOUNTED_BANNER("wall_banner", 177),
INVERTED_DAYLIGHT_SENSOR("daylight_detector_inverted", 178),
RED_SANDSTONE("red_sandstone", 179),
SMOOTH_RED_SANDSTONE("red_sandstone", 179, 1),
CHISELED_RED_SANDSTONE("red_sandstone", 179, 2),
RED_SANDSTONE_STAIRS("red_sandstone_stairs", 180),
DOUBLE_RED_SANDSTONE_SLAB("stone_slab2", 181),
RED_SANDSTONE_SLAB("double_stone_slab2", 182),
SPRUCE_FENCE_GATE("spruce_fence_gate", 183),
BIRCH_FENCE_GATE("birch_fence_gate", 184),
JUNGLE_FENCE_GATE("jungle_fence_gate", 185),
DARK_OAK_FENCE_GATE("dark_oak_fence_gate", 186),
ACACIA_FENCE_GATE("acacia_fence_gate", 187),
SPRUCE_FENCE("spruce_fence", 188),
BIRCH_FENCE("birch_fence", 189),
JUNGLE_FENCE("jungle_fence", 190),
DARK_OAK_FENCE("dark_oak_fence", 191),
ACACIA_FENCE("acacia_fence", 192),
SPRUCE_DOOR_BLOCK("spruce_door", 193),
BIRCH_DOOR_BLOCK("birch_door", 194),
JUNGLE_DOOR_BLOCK("jungle_door", 195),
ACACIA_DOOR_BLOCK("acacia_door", 196),
DARK_OAK_DOOR_BLOCK("dark_oak_door", 197),
IRON_SHOVEL("iron_shovel", 256),
IRON_PICKAXE("iron_pickaxe", 257),
IRON_AXE("iron_axe", 258),
FLINT_AND_STEEL("flint_and_steel", 259),
APPLE("apple", 260),
BOW("bow", 261),
ARROW("arrow", 262),
COAL("coal", 263),
CHARCOAL("coal", 263, 1),
DIAMOND("diamond", 264),
IRON_INGOT("iron_ingot", 265),
GOLD_INGOT("gold_ingot", 266),
IRON_SWORD("iron_sword", 267),
WOODEN_SWORD("wooden_sword", 268),
WOODEN_SHOVEL("wooden_shovel", 269),
WOODEN_PICKAXE("wooden_pickaxe", 270),
WOODEN_AXE("wooden_axe", 271),
STONE_SWORD("stone_sword", 272),
STONE_SHOVEL("stone_shovel", 273),
STONE_PICKAXE("stone_pickaxe", 274),
STONE_AXE("stone_axe", 275),
DIAMOND_SWORD("diamond_sword", 276),
DIAMOND_SHOVEL("diamond_shovel", 277),
DIAMOND_PICKAXE("diamond_pickaxe", 278),
DIAMOND_AXE("diamond_axe", 279),
STICK("stick", 280),
BOWL("bowl", 281),
MUSHROOM_STEW("mushroom_stew", 282),
GOLDEN_SWORD("golden_sword", 283),
GOLDEN_SHOVEL("golden_shovel", 284),
GOLDEN_PICKAXE("golden_pickaxe", 285),
GOLDEN_AXE("golden_axe", 286),
STRING("string", 287),
FEATHER("feather", 288),
GUNPOWDER("gunpowder", 289),
WOODEN_HOE("wooden_hoe", 290),
STONE_HOE("stone_hoe", 291),
IRON_HOE("iron_hoe", 292),
DIAMOND_HOE("diamond_hoe", 293),
GOLDEN_HOE("golden_hoe", 294),
WHEAT_SEEDS("wheat_seeds", 295),
WHEAT("wheat", 296),
BREAD("bread", 297),
LEATHER_HELMET("leather_helmet", 298),
LEATHER_TUNIC("leather_chestplate", 299),
LEATHER_PANTS("leather_leggings", 300),
LEATHER_BOOTS("leather_boots", 301),
CHAINMAIL_HELMET("chainmail_helmet", 302),
CHAINMAIL_CHESTPLATE("chainmail_chestplate", 303),
CHAINMAIL_LEGGINGS("chainmail_leggings", 304),
CHAINMAIL_BOOTS("chainmail_boots", 305),
IRON_HELMET("iron_helmet", 306),
IRON_CHESTPLATE("iron_chestplate", 307),
IRON_LEGGINGS("iron_leggings", 308),
IRON_BOOTS("iron_boots", 309),
DIAMOND_HELMET("diamond_helmet", 310),
DIAMOND_CHESTPLATE("diamond_chestplate", 311),
DIAMOND_LEGGINGS("diamond_leggings", 312),
DIAMOND_BOOTS("diamond_boots", 313),
GOLDEN_HELMET("golden_helmet", 314),
GOLDEN_CHESTPLATE("golden_chestplate", 315),
GOLDEN_LEGGINGS("golden_leggings", 316),
GOLDEN_BOOTS("golden_boots", 317),
FLINT("flint_and_steel", 318),
RAW_PORKCHOP("porkchop", 319),
COOKED_PORKCHOP("cooked_porkchop", 320),
PAINTING("painting", 321),
GOLDEN_APPLE("golden_apple", 322),
ENCHANTED_GOLDEN_APPLE("golden_apple", 322, 1),
SIGN("sign", 323),
OAK_DOOR("wooden_door", 324),
BUCKET("bucket", 325),
WATER_BUCKET("water_bucket", 326),
LAVA_BUCKET("lava_bucket", 327),
MINECART("minecart", 328),
SADDLE("saddle", 329),
IRON_DOOR("iron_door", 330),
REDSTONE("redstone", 331),
SNOWBALL("snowball", 332),
BOAT("boat", 333),
LEATHER("leather", 334),
MILK_BUCKET("milk_bucket", 335),
BRICK("brick", 336),
CLAY1("clay_ball", 337),
SUGAR_CANES1("reeds", 338),
PAPER("paper", 339),
BOOK("book", 340),
SLIMEBALL("slime_ball", 341),
MINECART_WITH_CHEST("chest_minecart", 342),
MINECART_WITH_FURNACE("furnace_minecart", 343),
EGG("egg", 344),
COMPASS("compass", 345),
FISHING_ROD("fishing_rod", 346),
CLOCK("clock", 347),
GLOWSTONE_DUST("glowstone_dust", 348),
RAW_FISH("fish", 349),
RAW_SALMON("fish", 349, 1),
CLOWNFISH("fish", 349, 2),
PUFFERFISH("fish", 349, 3),
COOKED_FISH("cooked_fish", 350),
COOKED_SALMON("cooked_fish", 350, 1),
INK_SACK("dye", 351),
ROSE_RED("dye", 351, 1),
CACTUS_GREEN("dye", 351, 2),
COCO_BEANS("dye", 351, 3),
LAPIS_LAZULI("dye", 351, 4),
PURPLE_DYE("dye", 351, 5),
CYAN_DYE("dye", 351, 6),
LIGHT_GRAY_DYE("dye", 351, 7),
GRAY_DYE("dye", 351, 8),
PINK_DYE("dye", 351, 9),
LIME_DYE("dye", 351, 10),
DANDELION_YELLOW("dye", 351, 11),
LIGHT_BLUE_DYE("dye", 351, 12),
MAGENTA_DYE("dye", 351, 13),
ORANGE_DYE("dye", 351, 14),
BONE_MEAL("dye", 351, 15),
BONE("bone", 352),
SUGAR("sugar", 353),
CAKE("cake", 354),
BED1("bed", 355),
REDSTONE_REPEATER("repeater", 356),
COOKIE("cookie", 357),
MAP("filled_map", 358),
SHEARS("shears", 359),
MELON("melon", 360),
PUMPKIN_SEEDS("pumpkin_seeds", 361),
MELON_SEEDS("melon_seeds", 362),
RAW_BEEF("beef", 363),
STEAK("cooked_beef", 364),
RAW_CHICKEN("chicken", 365),
COOKED_CHICKEN("cooked_chicken", 366),
ROTTEN_FLESH("rotten_flesh", 367),
ENDER_PEARL("ender_pearl", 368),
BLAZE_ROD("blaze_rod", 369),
GHAST_TEAR("ghast_tear", 370),
GOLD_NUGGET("gold_nugget", 371),
NETHER_WART1("nether_wart", 372),
POTION("potion", 373),
GLASS_BOTTLE("glass_bottle", 374),
SPIDER_EYE("spider_eye", 375),
FERMENTED_SPIDER_EYE("fermented_spider_eye", 376),
BLAZE_POWDER("blaze_powder", 377),
MAGMA_CREAM("magma_cream", 378),
BREWING_STAND1("brewing_stand", 379),
CAULDRON1("cauldron", 380),
EYE_OF_ENDER("ender_eye", 381),
GLISTERING_MELON("speckled_melon", 382),
SPAWN_CREEPER("spawn_egg", 383, 50),
SPAWN_SKELETON("spawn_egg", 383, 51),
SPAWN_SPIDER("spawn_egg", 383, 52),
SPAWN_ZOMBIE("spawn_egg", 383, 54),
SPAWN_SLIME("spawn_egg", 383, 55),
SPAWN_GHAST("spawn_egg", 383, 56),
SPAWN_PIGMAN("spawn_egg", 383, 57),
SPAWN_ENDERMAN("spawn_egg", 383, 58),
SPAWN_CAVE_SPIDER("spawn_egg", 383, 59),
SPAWN_SILVERFISH("spawn_egg", 383, 60),
SPAWN_BLAZE("spawn_egg", 383, 61),
SPAWN_MAGMA_CUBE("spawn_egg", 383, 62),
SPAWN_BAT("spawn_egg", 383, 65),
SPAWN_WITCH("spawn_egg", 383, 66),
SPAWN_ENDERMITE("spawn_egg", 383, 67),
SPAWN_GUARDIAN("spawn_egg", 383, 68),
SPAWN_PIG("spawn_egg", 383, 90),
SPAWN_SHEEP("spawn_egg", 383, 91),
SPAWN_COW("spawn_egg", 383, 92),
SPAWN_CHICKEN("spawn_egg", 383, 93),
SPAWN_SQUID("spawn_egg", 383, 94),
SPAWN_WOLF("spawn_egg", 383, 95),
SPAWN_MOOSHROOM("spawn_egg", 383, 96),
SPAWN_OCELOT("spawn_egg", 383, 98),
SPAWN_HORSE("spawn_egg", 383, 100),
SPAWN_RABBIT("spawn_egg", 383, 101),
SPAWN_VILLAGER("spawn_egg", 383, 120),
BOTTLE_O_ENCHANTING("experience_bottle", 384),
FIRE_CHARGE("fire_charge", 385),
BOOK_AND_QUILL("writable_book", 386),
WRITTEN_BOOK("written_book", 387),
EMERALD("emerald", 388),
ITEM_FRAME("item_frame", 389),
FLOWER_POT1("flower_pot", 390),
CARROT("carrot", 391),
POTATO("potato", 392),
BAKED_POTATO("baked_potato", 393),
POISONOUS_POTATO("poisonous_potato", 394),
EMPTY_MAP("map", 395),
GOLDEN_CARROT("golden_carrot", 396),
MOB_HEAD_SKELETON("skull", 397),
MOB_HEAD_WITHER_SKELETON("skull", 397, 1),
MOB_HEAD_ZOMBIE("skull", 397, 2),
MOB_HEAD_HUMAN("skull", 397, 3),
MOB_HEAD_CREEPER("skull", 397, 4),
CARROT_ON_A_STICK("carrot_on_a_stick", 398),
NETHER_STAR("nether_star", 399),
PUMPKIN_PIE("pumpkin_pie", 400),
FIREWORK_ROCKET("fireworks", 401),
FIREWORK_STAR("firework_charge", 402),
ENCHANTED_BOOK("enchanted_book", 403),
REDSTONE_COMPARATOR("comparator", 404),
NETHER_BRICK1("netherbrick", 405),
NETHER_QUARTZ("quartz", 406),
MINECART_WITH_TNT("tnt_minecart", 407),
MINECART_WITH_HOPPER("hopper_minecart", 408),
PRISMARINE_SHARD("prismarine_shard", 409),
PRISMARINE_CRYSTALS("prismarine_crystals", 410),
RAW_RABBIT("rabbit", 411),
COOKED_RABBIT("cooked_rabbit", 412),
RABBIT_STEW("rabbit_stew", 413),
RABBITS_FOOT("rabbit_foot", 414),
RABBIT_HIDE("rabbit_hide", 415),
ARMOR_STAND("armor_stand", 416),
IRON_HORSE_ARMOR("iron_horse_armor", 417),
GOLDEN_HORSE_ARMOR("golden_horse_armor", 418),
DIAMOND_HORSE_ARMOR("diamond_horse_armor", 419),
LEAD("lead", 420),
NAME_TAG("name_tag", 421),
MINECART_WITH_COMMAND_BLOCK("command_block_minecart", 422),
RAW_MUTTON("mutton", 423),
COOKED_MUTTON("cooked_mutton", 424),
BANNER("banner", 425),
SPRUCE_DOOR("spruce_door", 427),
BIRCH_DOOR("birch_door", 428),
JUNGLE_DOOR("jungle_door", 429),
ACACIA_DOOR("acacia_door", 430),
DARK_OAK_DOOR("dark_oak_door", 431),
DISC_13("record_13", 2256),
CAT_DISC("record_cat", 2257),
BLOCKS_DISC("record_blocks", 2258),
CHIRP_DISC("record_chirp", 2259),
FAR_DISC("record_far", 2260),
MALL_DISC("record_mall", 2261),
MELLOHI_DISC("record_mellohi", 2262),
STAL_DISC("record_stal", 2263),
STRAD_DISC("record_strad", 2264),
WARD_DISC("record_ward", 2265),
DISC_11("record_11", 2266),
WAIT_DISC("record_wait", 2267);
private static final Map<String, Integer> ids = new HashMap<String, Integer>();
private static final Map<String, Byte> datas = new HashMap<String, Byte>();
private final int id;
private final byte data;
private final String name;
static {
for (ItemType type : EnumSet.allOf(ItemType.class)) {
ids.put(type.name, type.id);
datas.put(type.name, type.data);
}
}
ItemType(String name, int id) {
this.id = id;
this.data = 0;
this.name = name;
}
ItemType(String name, int id, int data) {
this.id = id;
this.data = (byte) data;
this.name = name;
}
public static int getId(String name) {
Integer value = ids.get(name);
if (value == null) {
return 0;
}
return value;
}
public static byte getData(String name) {
Byte value = datas.get(name);
if (value == null) {
return 0;
}
return value;
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1,112 @@
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;
}
}