This commit is contained in:
boy0001
2015-09-11 20:09:22 +10:00
parent 37a8861fa0
commit c386f33df8
380 changed files with 43490 additions and 33913 deletions

View File

@ -1,46 +1,56 @@
package com.intellectualcrafters.plot.object;
public class BO3 {
public class BO3
{
private final ChunkLoc chunk;
private final StringBuilder blocks;
private final StringBuilder children;
private final String name;
public BO3(String name, ChunkLoc loc) {
public BO3(final String name, final ChunkLoc loc)
{
this.name = name;
this.chunk = loc;
this.blocks = new StringBuilder();
this.children = new StringBuilder();
chunk = loc;
blocks = new StringBuilder();
children = new StringBuilder();
}
public void addChild(BO3 child) {
ChunkLoc childloc = child.getLoc();
public void addChild(final BO3 child)
{
final ChunkLoc childloc = child.getLoc();
children.append("Branch(" + (childloc.x - chunk.x) + ",0," + (childloc.z - chunk.z) + "," + name + "_" + childloc.x + "_" + childloc.z + ")\n");
}
public ChunkLoc getLoc() {
return this.chunk;
public ChunkLoc getLoc()
{
return chunk;
}
public String getName() {
public String getName()
{
return name;
}
public void addBlock(int x, int y, int z, PlotBlock block) {
if (block.data == 0) {
public void addBlock(final int x, final int y, final int z, final PlotBlock block)
{
if (block.data == 0)
{
// Block(-3,1,-2,AIR)
blocks.append("Block(" + x + "," + y + "," + z + "," + block.id + ")\n");
}
else {
else
{
blocks.append("Block(" + x + "," + y + "," + z + "," + block.id + ":" + block.data + ")\n");
}
}
public String getBlocks() {
public String getBlocks()
{
return blocks.toString();
}
public String getChildren() {
public String getChildren()
{
return children.toString();
}
}

View File

@ -1,13 +1,15 @@
package com.intellectualcrafters.plot.object;
public class BlockLoc {
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) {
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;
@ -16,57 +18,60 @@ public class BlockLoc {
this.pitch = pitch;
}
public BlockLoc(final int x, final int y, final int z) {
public BlockLoc(final int x, final int y, final int z)
{
this(x, y, z, 0f, 0f);
}
@Override
public int hashCode() {
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;
result = (prime * result) + x;
result = (prime * result) + y;
result = (prime * result) + 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;
}
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));
return ((x == other.x) && (y == other.y) && (z == other.z));
}
@Override
public String toString() {
return
x + "," + y + "," + z + "," + yaw + "," + pitch;
public String toString()
{
return x + "," + y + "," + z + "," + yaw + "," + pitch;
}
public static BlockLoc fromString(final String string) {
String[] parts = string.split(",");
public static BlockLoc fromString(final String string)
{
final String[] parts = string.split(",");
float yaw, pitch;
if (parts.length == 3) {
if (parts.length == 3)
{
yaw = 0f;
pitch = 0f;
} if (parts.length == 5) {
}
if (parts.length == 5)
{
yaw = Float.parseFloat(parts[3]);
pitch = Float.parseFloat(parts[4]);
} else {
}
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]);
final int x = Integer.parseInt(parts[0]);
final int y = Integer.parseInt(parts[1]);
final int z = Integer.parseInt(parts[2]);
return new BlockLoc(x, y, z, yaw, pitch);
}

View File

@ -1,70 +1,69 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// 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;
/**
* 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;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// 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;
/**
* Wrapper class for blocks, using pure data rather than the object.
*
* Useful for NMS
*
*/
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;

View File

@ -1,35 +1,33 @@
package com.intellectualcrafters.plot.object;
public class ChunkLoc {
public class ChunkLoc
{
public int x;
public int z;
public ChunkLoc(final int x, final int z) {
public ChunkLoc(final int x, final int z)
{
this.x = x;
this.z = z;
}
@Override
public int hashCode() {
public int hashCode()
{
final int prime = 31;
int result = 1;
result = (prime * result) + this.x;
result = (prime * result) + this.z;
result = (prime * result) + x;
result = (prime * result) + 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;
}
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));
return ((x == other.x) && (z == other.z));
}
}

View File

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

View File

@ -12,150 +12,184 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.PlotGamemode;
import com.intellectualcrafters.plot.util.PlotWeather;
public class ConsolePlayer extends PlotPlayer {
public class ConsolePlayer extends PlotPlayer
{
private static ConsolePlayer instance;
private Location loc;
private final HashMap<String, Object> meta;
public static ConsolePlayer getConsole() {
if (instance == null) {
public static ConsolePlayer getConsole()
{
if (instance == null)
{
instance = new ConsolePlayer();
instance.teleport(instance.getLocation());
}
return instance;
}
private ConsolePlayer() {
private ConsolePlayer()
{
String world;
Set<String> plotworlds = PS.get().getPlotWorlds();
if (plotworlds.size() > 0) {
final Set<String> plotworlds = PS.get().getPlotWorlds();
if (plotworlds.size() > 0)
{
world = plotworlds.iterator().next();
}
else {
else
{
world = "world";
}
this.loc = new Location(world, 0, 0, 0);
this.meta = new HashMap<>();
loc = new Location(world, 0, 0, 0);
meta = new HashMap<>();
}
public static boolean isConsole(PlotPlayer plr) {
return instance == plr;
public static boolean isConsole(final PlotPlayer plr)
{
return instance == plr;
}
@Override
public long getPreviousLogin() {
public long getPreviousLogin()
{
return 0;
}
@Override
public Location getLocation() {
public Location getLocation()
{
return loc;
}
@Override
public Location getLocationFull() {
public Location getLocationFull()
{
return loc;
}
@Override
public UUID getUUID() {
public UUID getUUID()
{
return DBFunc.everyone;
}
@Override
public boolean hasPermission(String perm) {
public boolean hasPermission(final String perm)
{
return true;
}
@Override
public void sendMessage(String message) {
public void sendMessage(final String message)
{
PS.log(message);
}
@Override
public void sendMessage(C c, String... args) {
public void sendMessage(final C c, final String... args)
{
MainUtil.sendMessage(this, c, args);
}
@Override
public void teleport(Location loc) {
Plot plot = MainUtil.getPlot(loc);
public void teleport(final Location loc)
{
final Plot plot = MainUtil.getPlot(loc);
setMeta("lastplot", plot);
this.loc = loc;
}
@Override
public boolean isOnline() {
public boolean isOnline()
{
return true;
}
@Override
public String getName() {
public String getName()
{
return "*";
}
@Override
public void setCompassTarget(Location loc) {}
public void setCompassTarget(final Location loc)
{}
@Override
public void loadData() {}
public void loadData()
{}
@Override
public void saveData() {}
public void saveData()
{}
@Override
public void setAttribute(String key) {}
public void setAttribute(final String key)
{}
@Override
public boolean getAttribute(String key) {
public boolean getAttribute(final String key)
{
return false;
}
@Override
public void removeAttribute(String key) {}
public void removeAttribute(final String key)
{}
@Override
public void setMeta(String key, Object value) {
this.meta.put(key, value);
public void setMeta(final String key, final Object value)
{
meta.put(key, value);
}
@Override
public Object getMeta(String key) {
return this.meta.get(key);
public Object getMeta(final String key)
{
return meta.get(key);
}
@Override
public void deleteMeta(String key) {
this.meta.remove(key);
public void deleteMeta(final String key)
{
meta.remove(key);
}
@Override
public RequiredType getSuperCaller() {
public RequiredType getSuperCaller()
{
return RequiredType.CONSOLE;
}
@Override
public void setWeather(PlotWeather weather) {}
public void setWeather(final PlotWeather weather)
{}
@Override
public PlotGamemode getGamemode() {
public PlotGamemode getGamemode()
{
return PlotGamemode.CREATIVE;
}
@Override
public void setGamemode(PlotGamemode gamemode) {}
public void setGamemode(final PlotGamemode gamemode)
{}
@Override
public void setTime(long time) {}
public void setTime(final long time)
{}
@Override
public void setFlight(boolean fly) {}
public void setFlight(final boolean fly)
{}
@Override
public void playMusic(Location loc, int id) {}
public void playMusic(final Location loc, final int id)
{}
@Override
public void kick(String message) {}
public void kick(final String message)
{}
}

View File

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

View File

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

View File

@ -1,217 +1,245 @@
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());
}
}
}
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
*
*/
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(world, x, y, z, yaw, 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;
built = false;
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 x;
}
public void setX(final int x)
{
this.x = x;
built = false;
}
public int getY()
{
return y;
}
public void setY(final int y)
{
this.y = y;
built = false;
}
public int getZ()
{
return z;
}
public void setZ(final int z)
{
this.z = z;
built = false;
}
public String getWorld()
{
return world;
}
public void setWorld(final String world)
{
this.world = world;
built = false;
}
public float getYaw()
{
return yaw;
}
public void setYaw(final float yaw)
{
this.yaw = yaw;
built = false;
}
public float getPitch()
{
return pitch;
}
public void setPitch(final float pitch)
{
this.pitch = pitch;
built = false;
}
public Location add(final int x, final int y, final int z)
{
this.x += x;
this.y += y;
this.z += z;
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) + x;
hash = (hash * 31) + y;
hash = (hash * 31) + z;
hash = (int) ((hash * 31) + getYaw());
hash = (int) ((hash * 31) + getPitch());
return (hash * 31) + (world == null ? 127 : world.hashCode());
}
public boolean isInAABB(final Location min, final Location max)
{
return (x >= min.getX()) && (x <= max.getX()) && (y >= min.getY()) && (y <= max.getY()) && (z >= min.getX()) && (z < max.getZ());
}
public void lookTowards(final int x, final int y)
{
final double l = this.x - x;
final double w = z - 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));
}
built = false;
}
public Location subtract(final int x, final int y, final int z)
{
this.x -= x;
this.y -= y;
this.z -= z;
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 (x == l.getX()) && (y == l.getY()) && (z == l.getZ()) && world.equals(l.getWorld()) && (yaw == l.getY()) && (pitch == l.getPitch());
}
@Override
public int compareTo(final Location o)
{
if (o == null) { throw new NullPointerException("Specified object was null"); }
if (((x == o.getX()) && (y == o.getY())) || (z == o.getZ())) { return 0; }
if ((x < o.getX()) && (y < o.getY()) && (z < o.getZ())) { return -1; }
return 1;
}
@Override
public String toString()
{
return "\"plotsquaredlocation\":{" + "\"x\":" + x + ",\"y\":" + y + ",\"z\":" + z + ",\"yaw\":" + yaw + ",\"pitch\":" + pitch + ",\"world\":\"" + world + "\"}";
}
private Object getBukkitWorld()
{
try
{
final Class clazz = Class.forName("org.bukkit.Bukkit");
return clazz.getMethod("getWorld", String.class).invoke(null, world);
}
catch (final Exception e)
{
return null;
}
}
public Object toBukkitLocation()
{
if (built) { return 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);
built = true;
return (o = constructor.newInstance(Class.forName("org.bukkit.World").cast(getBukkitWorld()), x, y, z, yaw, 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

@ -1,18 +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();
}
package com.intellectualcrafters.plot.object;
import java.util.UUID;
/**
* Created 2015-02-20 for PlotSquared
*
*/
public interface OfflinePlotPlayer
{
public UUID getUUID();
public long getLastPlayed();
public boolean isOnline();
public String getName();

File diff suppressed because it is too large Load Diff

View File

@ -13,170 +13,198 @@ import com.intellectualcrafters.configuration.file.YamlConfiguration;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.bukkit.util.BukkitHybridUtils;
public class PlotAnalysis {
public class PlotAnalysis
{
public int changes;
public int faces;
public int data;
public int air;
public int variety;
public int changes_sd;
public int faces_sd;
public int data_sd;
public int air_sd;
public int variety_sd;
private int complexity;
public static PlotAnalysis MODIFIERS = new PlotAnalysis();
public static PlotAnalysis getAnalysis(Plot plot) {
Flag flag = FlagManager.getPlotFlag(plot, "analysis");
if (flag != null) {
PlotAnalysis analysis = new PlotAnalysis();
List<Integer> values = (List<Integer>) flag.getValue();
public static PlotAnalysis getAnalysis(final Plot plot)
{
final Flag flag = FlagManager.getPlotFlag(plot, "analysis");
if (flag != null)
{
final PlotAnalysis analysis = new PlotAnalysis();
final List<Integer> values = (List<Integer>) flag.getValue();
analysis.changes = values.get(0); // 2126
analysis.faces = values.get(1); // 90
analysis.data = values.get(2); // 0
analysis.air = values.get(3); // 19100
analysis.variety = values.get(4); // 266
analysis.changes_sd = values.get(5); // 2104
analysis.faces_sd = values.get(6); // 89
analysis.data_sd = values.get(7); // 0
analysis.air_sd = values.get(8); // 18909
analysis.variety_sd = values.get(9); // 263
analysis.complexity = analysis.getComplexity();
return analysis;
}
return null;
}
public List<Integer> asList() {
public List<Integer> asList()
{
return Arrays.asList(changes, faces, data, air, variety, changes_sd, faces_sd, data_sd, air_sd, variety_sd);
}
public int getComplexity() {
if (complexity != 0) {
return complexity;
}
complexity = (this.changes) * MODIFIERS.changes
+ (this.faces) * MODIFIERS.faces
+ (this.data) * MODIFIERS.data
+ (this.air) * MODIFIERS.air
+ (this.variety) * MODIFIERS.variety
+ (this.changes_sd) * MODIFIERS.changes_sd
+ (this.faces_sd) * MODIFIERS.faces_sd
+ (this.data_sd) * MODIFIERS.data_sd
+ (this.air_sd) * MODIFIERS.air_sd
+ (this.variety_sd) * MODIFIERS.variety_sd;
public int getComplexity()
{
if (complexity != 0) { return complexity; }
complexity = ((changes) * MODIFIERS.changes)
+ ((faces) * MODIFIERS.faces)
+ ((data) * MODIFIERS.data)
+ ((air) * MODIFIERS.air)
+ ((variety) * MODIFIERS.variety)
+ ((changes_sd) * MODIFIERS.changes_sd)
+ ((faces_sd) * MODIFIERS.faces_sd)
+ ((data_sd) * MODIFIERS.data_sd)
+ ((air_sd) * MODIFIERS.air_sd)
+ ((variety_sd) * MODIFIERS.variety_sd);
return complexity;
}
public static void analyzePlot(Plot plot, RunnableVal<PlotAnalysis> whenDone) {
BukkitHybridUtils.manager.analyzePlot(plot, whenDone);
public static void analyzePlot(final Plot plot, final RunnableVal<PlotAnalysis> whenDone)
{
HybridUtils.manager.analyzePlot(plot, whenDone);
}
public static boolean running = false;
/**
* This will set the optimal modifiers for the plot analysis based on the current plot ratings<br>
* - Will be used to calibrate the threshold for plot clearing
* @param whenDone
*/
public static void calcOptimalModifiers(final Runnable whenDone, final double threshold) {
if (running) {
public static void calcOptimalModifiers(final Runnable whenDone, final double threshold)
{
if (running)
{
PS.debug("Calibration task already in progress!");
return;
}
if (threshold <= 0 || threshold >= 1) {
if ((threshold <= 0) || (threshold >= 1))
{
PS.debug("Invalid threshold provided! (Cannot be 0 or 100 as then there's no point calibrating)");
return;
}
running = true;
PS.debug(" - Fetching all plots");
final ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots());
TaskManager.runTaskAsync(new Runnable() {
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
Iterator<Plot> iter = plots.iterator();
public void run()
{
final Iterator<Plot> iter = plots.iterator();
PS.debug(" - $1Reducing " + plots.size() + " plots to those with sufficient data");
while (iter.hasNext()) {
Plot plot = iter.next();
if (plot.getSettings().ratings == null || plot.getSettings().ratings.size() == 0) {
while (iter.hasNext())
{
final Plot plot = iter.next();
if ((plot.getSettings().ratings == null) || (plot.getSettings().ratings.size() == 0))
{
iter.remove();
}
else {
else
{
MainUtil.runners.put(plot, 1);
}
}
PS.debug(" - | Reduced to " + plots.size() + " plots");
if (plots.size() < 3) {
if (plots.size() < 3)
{
PS.debug("Calibration cancelled due to insufficient comparison data, please try again later");
running = false;
for (Plot plot : plots) {
for (final Plot plot : plots)
{
MainUtil.runners.remove(plot);
}
return;
}
PS.debug(" - $1Analyzing plot contents (this may take a while)");
final int[] changes = new int[plots.size()];
final int[] faces = new int[plots.size()];
final int[] data = new int[plots.size()];
final int[] air = new int[plots.size()];
final int[] variety = new int[plots.size()];
final int[] changes_sd = new int[plots.size()];
final int[] faces_sd = new int[plots.size()];
final int[] data_sd = new int[plots.size()];
final int[] air_sd = new int[plots.size()];
final int[] variety_sd = new int[plots.size()];
final int[] ratings = new int[plots.size()];
final AtomicInteger mi = new AtomicInteger(0);
Thread ratingAnalysis = new Thread(new Runnable() {
final Thread ratingAnalysis = new Thread(new Runnable()
{
@Override
public void run() {
for (;mi.intValue() < plots.size(); mi.incrementAndGet()) {
int i = mi.intValue();
Plot plot = plots.get(i);
public void run()
{
for (; mi.intValue() < plots.size(); mi.incrementAndGet())
{
final int i = mi.intValue();
final Plot plot = plots.get(i);
ratings[i] = (int) ((plot.getAverageRating() + plot.getSettings().ratings.size()) * 100);
PS.debug(" | " + plot + " (rating) " + (ratings[i]));
}
}
});
ratingAnalysis.start();
final ArrayDeque<Plot> plotsQueue = new ArrayDeque<>(plots);
while (true) {
while (true)
{
final Plot queuePlot = plotsQueue.poll();
if (queuePlot == null) {
if (queuePlot == null)
{
break;
}
PS.debug(" | " + queuePlot);
final Object lock = new Object();
TaskManager.runTask(new Runnable() {
TaskManager.runTask(new Runnable()
{
@Override
public void run() {
analyzePlot(queuePlot, new RunnableVal<PlotAnalysis>() {
public void run() {
try {
public void run()
{
analyzePlot(queuePlot, new RunnableVal<PlotAnalysis>()
{
@Override
public void run()
{
try
{
wait(10000);
} catch (InterruptedException e) {
}
catch (final InterruptedException e)
{
e.printStackTrace();
}
synchronized (lock) {
synchronized (lock)
{
MainUtil.runners.remove(queuePlot);
lock.notify();
}
@ -184,153 +212,167 @@ public class PlotAnalysis {
});
}
});
try {
synchronized (lock) {
try
{
synchronized (lock)
{
lock.wait();
}
} catch (InterruptedException e) {
}
catch (final InterruptedException e)
{
e.printStackTrace();
}
}
PS.debug(" - $1Waiting on plot rating thread: " + ((mi.intValue() * 100) / plots.size()) + "%");
try {
try
{
ratingAnalysis.join();
} catch (InterruptedException e) {
}
catch (final InterruptedException e)
{
e.printStackTrace();
}
PS.debug(" - $1Processing and grouping single plot analysis for bulk processing");
for (int i = 0; i < plots.size(); i++) {
Plot plot = plots.get(i);
for (int i = 0; i < plots.size(); i++)
{
final Plot plot = plots.get(i);
PS.debug(" | " + plot);
PlotAnalysis analysis = plot.getComplexity();
final PlotAnalysis analysis = plot.getComplexity();
changes[i] = analysis.changes;
faces[i] = analysis.faces;
data[i] = analysis.data;
air[i] = analysis.air;
variety[i] = analysis.variety;
changes_sd[i] = analysis.changes_sd;
faces_sd[i] = analysis.faces_sd;
data_sd[i] = analysis.data_sd;
air_sd[i] = analysis.air_sd;
variety_sd[i] = analysis.variety_sd;
}
PS.debug(" - $1Calculating rankings");
int[] rank_ratings = rank(ratings);
int n = rank_ratings.length;
int optimal_index = (int) Math.round((1 - threshold) * (n - 1));
final int[] rank_ratings = rank(ratings);
final int n = rank_ratings.length;
final int optimal_index = (int) Math.round((1 - threshold) * (n - 1));
PS.debug(" - $1Calculating rank correlation: ");
PS.debug(" - The analyzed plots which were processed and put into bulk data will be compared and correlated to the plot ranking");
PS.debug(" - The calculated correlation constant will then be used to calibrate the threshold for auto plot clearing");
int[] rank_changes = rank(changes);
int[] sd_changes = getSD(rank_changes, rank_ratings);
int[] variance_changes = square(sd_changes);
int sum_changes = sum(variance_changes);
double factor_changes = getCC(n, sum_changes);
PlotAnalysis.MODIFIERS.changes = factor_changes == 1 ? 0 : (int) (factor_changes * 1000 / MathMan.getMean(changes));
final int[] rank_changes = rank(changes);
final int[] sd_changes = getSD(rank_changes, rank_ratings);
final int[] variance_changes = square(sd_changes);
final int sum_changes = sum(variance_changes);
final double factor_changes = getCC(n, sum_changes);
PlotAnalysis.MODIFIERS.changes = factor_changes == 1 ? 0 : (int) ((factor_changes * 1000) / MathMan.getMean(changes));
PS.debug(" - | changes " + factor_changes);
int[] rank_faces = rank(faces);
int[] sd_faces = getSD(rank_faces, rank_ratings);
int[] variance_faces = square(sd_faces);
int sum_faces = sum(variance_faces);
double factor_faces = getCC(n, sum_faces);
PlotAnalysis.MODIFIERS.faces = factor_faces == 1 ? 0 : (int) (factor_faces * 1000 / MathMan.getMean(faces));
final int[] rank_faces = rank(faces);
final int[] sd_faces = getSD(rank_faces, rank_ratings);
final int[] variance_faces = square(sd_faces);
final int sum_faces = sum(variance_faces);
final double factor_faces = getCC(n, sum_faces);
PlotAnalysis.MODIFIERS.faces = factor_faces == 1 ? 0 : (int) ((factor_faces * 1000) / MathMan.getMean(faces));
PS.debug(" - | faces " + factor_faces);
int[] rank_data = rank(data);
int[] sd_data = getSD(rank_data, rank_ratings);
int[] variance_data = square(sd_data);
int sum_data = sum(variance_data);
double factor_data = getCC(n, sum_data);
PlotAnalysis.MODIFIERS.data = factor_data == 1 ? 0 : (int) (factor_data * 1000 / MathMan.getMean(data));
final int[] rank_data = rank(data);
final int[] sd_data = getSD(rank_data, rank_ratings);
final int[] variance_data = square(sd_data);
final int sum_data = sum(variance_data);
final double factor_data = getCC(n, sum_data);
PlotAnalysis.MODIFIERS.data = factor_data == 1 ? 0 : (int) ((factor_data * 1000) / MathMan.getMean(data));
PS.debug(" - | data " + factor_data);
int[] rank_air = rank(air);
int[] sd_air = getSD(rank_air, rank_ratings);
int[] variance_air = square(sd_air);
int sum_air = sum(variance_air);
double factor_air = getCC(n, sum_air);
PlotAnalysis.MODIFIERS.air = factor_air == 1 ? 0 : (int) (factor_air * 1000 / MathMan.getMean(air));
final int[] rank_air = rank(air);
final int[] sd_air = getSD(rank_air, rank_ratings);
final int[] variance_air = square(sd_air);
final int sum_air = sum(variance_air);
final double factor_air = getCC(n, sum_air);
PlotAnalysis.MODIFIERS.air = factor_air == 1 ? 0 : (int) ((factor_air * 1000) / MathMan.getMean(air));
PS.debug(" - | air " + factor_air);
int[] rank_variety = rank(variety);
int[] sd_variety = getSD(rank_variety, rank_ratings);
int[] variance_variety = square(sd_variety);
int sum_variety = sum(variance_variety);
double factor_variety = getCC(n, sum_variety);
PlotAnalysis.MODIFIERS.variety = factor_variety == 1 ? 0 : (int) (factor_variety * 1000 / MathMan.getMean(variety));
final int[] rank_variety = rank(variety);
final int[] sd_variety = getSD(rank_variety, rank_ratings);
final int[] variance_variety = square(sd_variety);
final int sum_variety = sum(variance_variety);
final double factor_variety = getCC(n, sum_variety);
PlotAnalysis.MODIFIERS.variety = factor_variety == 1 ? 0 : (int) ((factor_variety * 1000) / MathMan.getMean(variety));
PS.debug(" - | variety " + factor_variety);
int[] rank_changes_sd = rank(changes_sd);
int[] sd_changes_sd = getSD(rank_changes_sd, rank_ratings);
int[] variance_changes_sd = square(sd_changes_sd);
int sum_changes_sd = sum(variance_changes_sd);
double factor_changes_sd = getCC(n, sum_changes_sd);
PlotAnalysis.MODIFIERS.changes_sd = factor_changes_sd == 1 ? 0 : (int) (factor_changes_sd * 1000 / MathMan.getMean(changes_sd));
final int[] rank_changes_sd = rank(changes_sd);
final int[] sd_changes_sd = getSD(rank_changes_sd, rank_ratings);
final int[] variance_changes_sd = square(sd_changes_sd);
final int sum_changes_sd = sum(variance_changes_sd);
final double factor_changes_sd = getCC(n, sum_changes_sd);
PlotAnalysis.MODIFIERS.changes_sd = factor_changes_sd == 1 ? 0 : (int) ((factor_changes_sd * 1000) / MathMan.getMean(changes_sd));
PS.debug(" - | changes_sd " + factor_changes_sd);
int[] rank_faces_sd = rank(faces_sd);
int[] sd_faces_sd = getSD(rank_faces_sd, rank_ratings);
int[] variance_faces_sd = square(sd_faces_sd);
int sum_faces_sd = sum(variance_faces_sd);
double factor_faces_sd = getCC(n, sum_faces_sd);
PlotAnalysis.MODIFIERS.faces_sd = factor_faces_sd == 1 ? 0 : (int) (factor_faces_sd * 1000 / MathMan.getMean(faces_sd));
final int[] rank_faces_sd = rank(faces_sd);
final int[] sd_faces_sd = getSD(rank_faces_sd, rank_ratings);
final int[] variance_faces_sd = square(sd_faces_sd);
final int sum_faces_sd = sum(variance_faces_sd);
final double factor_faces_sd = getCC(n, sum_faces_sd);
PlotAnalysis.MODIFIERS.faces_sd = factor_faces_sd == 1 ? 0 : (int) ((factor_faces_sd * 1000) / MathMan.getMean(faces_sd));
PS.debug(" - | faces_sd " + factor_faces_sd);
int[] rank_data_sd = rank(data_sd);
int[] sd_data_sd = getSD(rank_data_sd, rank_ratings);
int[] variance_data_sd = square(sd_data_sd);
int sum_data_sd = sum(variance_data_sd);
double factor_data_sd = getCC(n, sum_data_sd);
PlotAnalysis.MODIFIERS.data_sd = factor_data_sd == 1 ? 0 : (int) (factor_data_sd * 1000 / MathMan.getMean(data_sd));
final int[] rank_data_sd = rank(data_sd);
final int[] sd_data_sd = getSD(rank_data_sd, rank_ratings);
final int[] variance_data_sd = square(sd_data_sd);
final int sum_data_sd = sum(variance_data_sd);
final double factor_data_sd = getCC(n, sum_data_sd);
PlotAnalysis.MODIFIERS.data_sd = factor_data_sd == 1 ? 0 : (int) ((factor_data_sd * 1000) / MathMan.getMean(data_sd));
PS.debug(" - | data_sd " + factor_data_sd);
int[] rank_air_sd = rank(air_sd);
int[] sd_air_sd = getSD(rank_air_sd, rank_ratings);
int[] variance_air_sd = square(sd_air_sd);
int sum_air_sd = sum(variance_air_sd);
double factor_air_sd = getCC(n, sum_air_sd);
PlotAnalysis.MODIFIERS.air_sd = factor_air_sd == 1 ? 0 : (int) (factor_air_sd * 1000 / MathMan.getMean(air_sd));
final int[] rank_air_sd = rank(air_sd);
final int[] sd_air_sd = getSD(rank_air_sd, rank_ratings);
final int[] variance_air_sd = square(sd_air_sd);
final int sum_air_sd = sum(variance_air_sd);
final double factor_air_sd = getCC(n, sum_air_sd);
PlotAnalysis.MODIFIERS.air_sd = factor_air_sd == 1 ? 0 : (int) ((factor_air_sd * 1000) / MathMan.getMean(air_sd));
PS.debug(" - | air_sd " + factor_air_sd);
int[] rank_variety_sd = rank(variety_sd);
int[] sd_variety_sd = getSD(rank_variety_sd, rank_ratings);
int[] variance_variety_sd = square(sd_variety_sd);
int sum_variety_sd = sum(variance_variety_sd);
double factor_variety_sd = getCC(n, sum_variety_sd);
PlotAnalysis.MODIFIERS.variety_sd = factor_variety_sd == 1 ? 0 : (int) (factor_variety_sd * 1000 / MathMan.getMean(variety_sd));
final int[] rank_variety_sd = rank(variety_sd);
final int[] sd_variety_sd = getSD(rank_variety_sd, rank_ratings);
final int[] variance_variety_sd = square(sd_variety_sd);
final int sum_variety_sd = sum(variance_variety_sd);
final double factor_variety_sd = getCC(n, sum_variety_sd);
PlotAnalysis.MODIFIERS.variety_sd = factor_variety_sd == 1 ? 0 : (int) ((factor_variety_sd * 1000) / MathMan.getMean(variety_sd));
PS.debug(" - | variety_sd " + factor_variety_sd);
int[] complexity = new int[n];
final int[] complexity = new int[n];
PS.debug(" $1Calculating threshold");
int max = 0;
int min = 0;
for (int i = 0; i < n; i++) {
Plot plot = plots.get(i);
PlotAnalysis analysis = plot.getComplexity();
for (int i = 0; i < n; i++)
{
final Plot plot = plots.get(i);
final PlotAnalysis analysis = plot.getComplexity();
complexity[i] = analysis.complexity;
if (analysis.complexity < min) {
if (analysis.complexity < min)
{
min = analysis.complexity;
}
else if (analysis.complexity > max) {
else if (analysis.complexity > max)
{
max = analysis.complexity;
}
}
int optimal_complexity = Integer.MAX_VALUE;
if (min > 0 && max < 102400) { // If low size, use my fast ranking algorithm
int[] rank_complexity = rank(complexity, max + 1);
for (int i = 0; i < n; i++) {
if (rank_complexity[i] == optimal_index) {
int optimal_complexity = Integer.MAX_VALUE;
if ((min > 0) && (max < 102400))
{ // If low size, use my fast ranking algorithm
final int[] rank_complexity = rank(complexity, max + 1);
for (int i = 0; i < n; i++)
{
if (rank_complexity[i] == optimal_index)
{
optimal_complexity = complexity[i];
break;
}
@ -341,17 +383,20 @@ public class PlotAnalysis {
logln(rank_ratings);
logln("Correlation: ");
logln(getCC(n, sum(square(getSD(rank_complexity, rank_ratings)))));
if (optimal_complexity == Integer.MAX_VALUE) {
if (optimal_complexity == Integer.MAX_VALUE)
{
PS.debug("Insufficient data to determine correlation! " + optimal_index + " | " + n);
running = false;
for (Plot plot : plots) {
for (final Plot plot : plots)
{
MainUtil.runners.remove(plot);
}
return;
}
}
else { // Use the fast radix sort algorithm
int[] sorted = complexity.clone();
else
{ // Use the fast radix sort algorithm
final int[] sorted = complexity.clone();
sort(sorted);
optimal_complexity = sorted[optimal_index];
logln("Complexity: ");
@ -359,10 +404,10 @@ public class PlotAnalysis {
logln("Ratings: ");
logln(rank_ratings);
}
// Save calibration
PS.debug(" $1Saving calibration");
YamlConfiguration config = PS.get().config;
final YamlConfiguration config = PS.get().config;
config.set("clear.auto.threshold", optimal_complexity);
config.set("clear.auto.calibration.changes", PlotAnalysis.MODIFIERS.changes);
config.set("clear.auto.calibration.faces", PlotAnalysis.MODIFIERS.faces);
@ -374,113 +419,131 @@ public class PlotAnalysis {
config.set("clear.auto.calibration.data_sd", PlotAnalysis.MODIFIERS.data_sd);
config.set("clear.auto.calibration.air_sd", PlotAnalysis.MODIFIERS.air_sd);
config.set("clear.auto.calibration.variety_sd", PlotAnalysis.MODIFIERS.variety_sd);
try {
try
{
PS.get().config.save(PS.get().configFile);
} catch (IOException e) {
}
catch (final IOException e)
{
e.printStackTrace();
}
PS.debug("$1Done!");
running = false;
for (Plot plot : plots) {
for (final Plot plot : plots)
{
MainUtil.runners.remove(plot);
}
whenDone.run();
}
});
}
public static void logln(Object obj) {
public static void logln(final Object obj)
{
PS.debug(log(obj));
}
public static String log(Object obj) {
public static String log(final Object obj)
{
String result = "";
if (obj.getClass().isArray()) {
if (obj.getClass().isArray())
{
String prefix = "";
for(int i=0; i<Array.getLength(obj); i++){
for (int i = 0; i < Array.getLength(obj); i++)
{
result += prefix + log(Array.get(obj, i));
prefix = ",";
}
return "( " + result + " )";
}
else if (obj instanceof List<?>) {
else if (obj instanceof List<?>)
{
String prefix = "";
for (Object element : (List<?>) obj) {
for (final Object element : (List<?>) obj)
{
result += prefix + log(element);
prefix = ",";
}
return "[ " + result + " ]";
}
else {
else
{
return obj.toString();
}
}
/**
* Get correllation coefficient
* @return
*/
public static double getCC(int n, int sum) {
return 1 - (6 * (double) sum) / (n * (n*n - 1));
public static double getCC(final int n, final int sum)
{
return 1 - ((6 * (double) sum) / (n * ((n * n) - 1)));
}
/**
* Sum of an array
* @param array
* @return
*/
public static int sum(int[] array) {
public static int sum(final int[] array)
{
int sum = 0;
for (int value : array ) {
for (final int value : array)
{
sum += value;
}
return sum;
}
/**
* A simple array squaring algorithm<br>
* - Used for calculating the variance
* @param array
* @return
*/
public static int[] square(int[] array) {
public static int[] square(int[] array)
{
array = array.clone();
for (int i = 0; i < array.length; i++) {
for (int i = 0; i < array.length; i++)
{
array[i] *= array[i];
}
return array;
}
/**
* An optimized lossy standard deviation algorithm
* @param ranks
* @return
*/
public static int[] getSD(int[]...ranks) {
if (ranks.length == 0) {
return null;
}
int size = ranks[0].length;
int arrays = ranks.length;
int[] result = new int[size];
for (int j = 0; j < size; j++) {
public static int[] getSD(final int[]... ranks)
{
if (ranks.length == 0) { return null; }
final int size = ranks[0].length;
final int arrays = ranks.length;
final int[] result = new int[size];
for (int j = 0; j < size; j++)
{
int sum = 0;
for (int i = 0; i < ranks.length; i++) {
sum += ranks[i][j];
for (final int[] rank : ranks)
{
sum += rank[j];
}
int mean = sum / arrays;
final int mean = sum / arrays;
int sd = 0;
for (int i = 0; i < ranks.length; i++) {
int value = ranks[i][j];
for (final int[] rank : ranks)
{
final int value = rank[j];
sd += value < mean ? mean - value : value - mean;
}
result[j] = sd;
}
return result;
}
/**
* An optimized algorithm for ranking a very specific set of inputs<br>
* - Input is an array of int with a max size of 102400<br>
@ -488,72 +551,90 @@ public class PlotAnalysis {
* @param input
* @return
*/
public static int[] rank(final int[] input) {
public static int[] rank(final int[] input)
{
return rank(input, 102400);
}
/**
* An optimized algorithm for ranking a very specific set of inputs
* @param input
* @return
*/
public static int[] rank(final int[] input, int size) {
int[] cache = new int[size];
public static int[] rank(final int[] input, final int size)
{
final int[] cache = new int[size];
int max = 0;
if (input.length < size) {
for (int value : input) {
if (value > max) {
if (input.length < size)
{
for (final int value : input)
{
if (value > max)
{
max = value;
}
cache[value]++;
}
}
else {
max = cache.length - 1;
for (int value : input) {
cache[value]++;
}
else
{
max = cache.length - 1;
for (final int value : input)
{
cache[value]++;
}
}
int last = 0;
for (int i = max; i >= 0; i--) {
if (cache[i] != 0) {
for (int i = max; i >= 0; i--)
{
if (cache[i] != 0)
{
cache[i] += last;
last = cache[i];
if (last == input.length) {
if (last == input.length)
{
break;
}
}
}
int[] ranks = new int[input.length];
for (int i = 0; i < input.length; i++) {
int index = input[i];
final int[] ranks = new int[input.length];
for (int i = 0; i < input.length; i++)
{
final int index = input[i];
ranks[i] = cache[index];
cache[index]--;
}
return ranks;
}
public static void sort(int[] input) {
public static void sort(final int[] input)
{
final int SIZE = 10;
List<Integer>[] bucket = new ArrayList[SIZE];
for (int i = 0; i < bucket.length; i++) {
final List<Integer>[] bucket = new ArrayList[SIZE];
for (int i = 0; i < bucket.length; i++)
{
bucket[i] = new ArrayList<Integer>();
}
boolean maxLength = false;
int tmp = -1, placement = 1;
while (!maxLength) {
while (!maxLength)
{
maxLength = true;
for (Integer i : input) {
for (final Integer i : input)
{
tmp = i / placement;
bucket[tmp % SIZE].add(i);
if (maxLength && tmp > 0) {
if (maxLength && (tmp > 0))
{
maxLength = false;
}
}
int a = 0;
for (int b = 0; b < SIZE; b++) {
for (Integer i : bucket[b]) {
for (int b = 0; b < SIZE; b++)
{
for (final Integer i : bucket[b])
{
input[a++] = i;
}
bucket[b].clear();

View File

@ -1,65 +1,61 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// 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;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// 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 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 ((id == other.id) && ((data == other.data) || (data == -1) || (other.data == -1)));
}
@Override
public int hashCode()
{
return id;
}
@Override
public String toString()
{
if (data == -1) { return id + ""; }
return id + ":" + data;
}

View File

@ -5,7 +5,8 @@ import java.util.UUID;
import com.intellectualcrafters.plot.database.DBFunc;
public class PlotCluster {
public class PlotCluster
{
public final String world;
public PlotSettings settings;
public UUID owner;
@ -14,72 +15,78 @@ public class PlotCluster {
private PlotId pos1;
private PlotId pos2;
public PlotId getP1() {
return this.pos1;
public PlotId getP1()
{
return pos1;
}
public PlotId getP2() {
return this.pos2;
public PlotId getP2()
{
return pos2;
}
public void setP1(final PlotId id) {
this.pos1 = id;
public void setP1(final PlotId id)
{
pos1 = id;
}
public void setP2(final PlotId id) {
this.pos2 = id;
public void setP2(final PlotId id)
{
pos2 = id;
}
public PlotCluster(final String world, final PlotId pos1, final PlotId pos2, final UUID owner) {
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);
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 isAdded(final UUID uuid)
{
return (owner.equals(uuid) || invited.contains(uuid) || invited.contains(DBFunc.everyone) || helpers.contains(uuid) || 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 boolean hasHelperRights(final UUID uuid)
{
return (owner.equals(uuid) || helpers.contains(uuid) || helpers.contains(DBFunc.everyone));
}
public String getName() {
return this.settings.getAlias();
public String getName()
{
return settings.getAlias();
}
/**
* Get the area (in plots)
* @return
*/
public int getArea() {
return (1 + pos2.x - pos1.x) * (1 + pos2.y - pos1.y);
public int getArea()
{
return ((1 + pos2.x) - pos1.x) * ((1 + pos2.y) - pos1.y);
}
@Override
public int hashCode() {
return this.pos1.hashCode();
public int hashCode()
{
return 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;
}
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));
return (world.equals(other.world) && pos1.equals(other.pos1) && pos2.equals(other.pos2));
}
@Override
public String toString() {
return this.world + ";" + this.pos1.x + ";" + this.pos1.y + ";" + this.pos2.x + ";" + this.pos2.y;
public String toString()
{
return world + ";" + pos1.x + ";" + pos1.y + ";" + pos2.x + ";" + pos2.y;
}
}

View File

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

View File

@ -1,10 +1,14 @@
package com.intellectualcrafters.plot.object;
public abstract class PlotFilter {
public boolean allowsWorld(String world) {
public abstract class PlotFilter
{
public boolean allowsWorld(final String world)
{
return true;
}
public boolean allowsPlot(Plot plot) {
public boolean allowsPlot(final Plot plot)
{
return true;
}
}

View File

@ -9,18 +9,21 @@ import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.UUIDHandler;
public class PlotHandler {
public static HashSet<UUID> getOwners(Plot plot) {
if (plot.owner == null) {
return new HashSet<UUID>();
}
if (plot.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) {
public class PlotHandler
{
public static HashSet<UUID> getOwners(final Plot plot)
{
if (plot.owner == null) { return new HashSet<UUID>(); }
if (plot.isMerged())
{
final HashSet<UUID> owners = new HashSet<UUID>();
final Plot top = MainUtil.getTopPlot(plot);
final ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(plot.id, top.id);
for (final PlotId id : ids)
{
final UUID owner = MainUtil.getPlot(plot.world, id).owner;
if (owner != null)
{
owners.add(owner);
}
}
@ -28,79 +31,69 @@ public class PlotHandler {
}
return new HashSet<>(Arrays.asList(plot.owner));
}
public static boolean isOwner(Plot plot, UUID uuid) {
if (plot.owner == null) {
return false;
}
if (plot.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;
}
public static boolean isOwner(final Plot plot, final UUID uuid)
{
if (plot.owner == null) { return false; }
if (plot.isMerged())
{
final Plot top = MainUtil.getTopPlot(plot);
final ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(plot.id, top.id);
for (final PlotId id : ids)
{
final 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.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;
}
public static boolean isOnline(final Plot plot)
{
if (plot.owner == null) { return false; }
if (plot.isMerged())
{
final Plot top = MainUtil.getTopPlot(plot);
final ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(plot.id, top.id);
for (final PlotId id : ids)
{
final 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);
public static boolean sameOwners(final Plot plot1, final Plot plot2)
{
if ((plot1.owner == null) || (plot2.owner == null)) { return false; }
final 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;
public static boolean isAdded(final Plot plot, final UUID uuid)
{
if (plot.owner == null) { return false; }
if (isOwner(plot, uuid)) { return true; }
if (plot.getDenied().contains(uuid)) { return false; }
if (plot.getTrusted().contains(uuid) || plot.getTrusted().contains(DBFunc.everyone)) { return true; }
if (plot.getMembers().contains(uuid) || plot.getMembers().contains(DBFunc.everyone))
{
if (PlotHandler.isOnline(plot)) { return true; }
}
if (isOwner(plot, uuid)) {
return true;
}
if (plot.getDenied().contains(uuid)) {
return false;
}
if (plot.getTrusted().contains(uuid) || plot.getTrusted().contains(DBFunc.everyone)) {
return true;
}
if (plot.getMembers().contains(uuid) || plot.getMembers().contains(DBFunc.everyone)) {
if (PlotHandler.isOnline(plot)) {
return true;
}
}
if (plot.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;
}
if (plot.isMerged())
{
final Plot top = MainUtil.getTopPlot(plot);
final ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(plot.id, top.id);
for (final PlotId id : ids)
{
final UUID owner = MainUtil.getPlot(plot.world, id).owner;
if ((owner != null) && owner.equals(uuid)) { return true; }
}
}
return false;

View File

@ -20,7 +20,8 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.object;
public class PlotId {
public class PlotId
{
/**
* x value
*/
@ -36,7 +37,8 @@ public class PlotId {
* @param x The plot x coordinate
* @param y The plot y coordinate
*/
public PlotId(final int x, final int y) {
public PlotId(final int x, final int y)
{
this.x = x;
this.y = y;
}
@ -48,104 +50,121 @@ public class PlotId {
*
* @return null if the string is invalid
*/
public static PlotId fromString(final String string) {
public static PlotId fromString(final String string)
{
int x, y;
final String[] parts = string.split(";");
if (parts.length < 2) {
return null;
}
try {
if (parts.length < 2) { return null; }
try
{
x = Integer.parseInt(parts[0]);
y = Integer.parseInt(parts[1]);
} catch (final Exception e) {
}
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;
}
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)));
return ((x.equals(other.x)) && (y.equals(other.y)));
}
@Override
public String toString() {
return this.x + ";" + this.y;
public String toString()
{
return x + ";" + y;
}
public static PlotId unpair(int hash) {
if (hash >= 0) {
if (hash % 2 == 0) {
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;
final int i = (int) (Math.abs(-1 + Math.sqrt(1 + (8 * hash))) / 2);
final int idx = hash - ((i * (1 + i)) / 2);
final int idy = ((i * (3 + i)) / 2) - hash;
return new PlotId(idx, idy);
}
else {
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;
final int i = (int) (Math.abs(-1 + Math.sqrt(1 + (8 * hash))) / 2);
final int idx = hash - ((i * (1 + i)) / 2);
final int idy = ((i * (3 + i)) / 2) - hash;
return new PlotId(idx, -idy);
}
}
else {
if (hash % 2 == 0) {
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;
final int i = (int) (Math.abs(-1 + Math.sqrt(1 + (8 * hash))) / 2);
final int idx = hash - ((i * (1 + i)) / 2);
final int idy = ((i * (3 + i)) / 2) - hash;
return new PlotId(-idx, idy);
}
else {
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;
final int i = (int) (Math.abs(-1 + Math.sqrt(1 + (8 * hash))) / 2);
final int idx = hash - ((i * (1 + i)) / 2);
final int idy = ((i * (3 + i)) / 2) - hash;
return new PlotId(-idx, -idy);
}
}
}
private int hash;
public void recalculateHash() {
this.hash = 0;
public void recalculateHash()
{
hash = 0;
hashCode();
}
@Override
public int hashCode() {
if (hash == 0) {
if (x >= 0) {
if (y >= 0) {
public int hashCode()
{
if (hash == 0)
{
if (x >= 0)
{
if (y >= 0)
{
hash = (x * x) + (3 * x) + (2 * x * y) + y + (y * y);
} else {
}
else
{
final int y1 = -y;
hash = (x * x) + (3 * x) + (2 * x * y1) + y1 + (y1 * y1) + 1;
}
} else {
}
else
{
final int x1 = -x;
if (y >= 0) {
if (y >= 0)
{
hash = -((x1 * x1) + (3 * x1) + (2 * x1 * y) + y + (y * y));
} else {
}
else
{
final int y1 = -y;
hash = -((x1 * x1) + (3 * x1) + (2 * x1 * y1) + y1 + (y1 * y1) + 1);
}

View File

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

View File

@ -2,26 +2,29 @@ package com.intellectualcrafters.plot.object;
import com.intellectualcrafters.plot.util.BlockManager;
public class PlotItemStack {
public class PlotItemStack
{
public final int id;
public final short data;
public final int amount;
public final String name;
public final String[] lore;
@Deprecated
public PlotItemStack(int id, short data, int amount, String name, String... lore) {
public PlotItemStack(final int id, final short data, final int amount, final String name, final String... lore)
{
this.id = id;
this.data = data;
this.amount = amount;
this.name = name;
this.lore = lore;
}
public PlotItemStack(String id, int amount, String name, String... lore) {
PlotBlock block = BlockManager.manager.getPlotBlockFromString(id);
public PlotItemStack(final String id, final int amount, final String name, final String... lore)
{
final PlotBlock block = BlockManager.manager.getPlotBlockFromString(id);
this.id = block.id;
this.data = block.data;
data = block.data;
this.amount = amount;
this.name = name;
this.lore = lore;

View File

@ -1,35 +1,33 @@
package com.intellectualcrafters.plot.object;
public class PlotLoc {
public class PlotLoc
{
public int x;
public int z;
public PlotLoc(final int x, final int z) {
public PlotLoc(final int x, final int z)
{
this.x = x;
this.z = z;
}
@Override
public int hashCode() {
public int hashCode()
{
final int prime = 31;
int result = 1;
result = (prime * result) + this.x;
result = (prime * result) + this.z;
result = (prime * result) + x;
result = (prime * result) + 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;
}
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));
return ((x == other.x) && (z == other.z));
}
}

View File

@ -27,7 +27,8 @@ import java.util.HashSet;
import com.intellectualcrafters.plot.commands.Template;
public abstract class PlotManager {
public abstract class PlotManager
{
/*
* Plot locations (methods with Abs in them will not need to consider mega
* plots)
@ -45,11 +46,11 @@ public abstract class PlotManager {
/*
* Plot clearing (return false if you do not support some method)
*/
public abstract boolean clearPlot(final PlotWorld plotworld, final Plot plot, Runnable whenDone);
public abstract boolean clearPlot(final PlotWorld plotworld, final Plot plot, final Runnable whenDone);
public abstract boolean claimPlot(final PlotWorld plotworld, final Plot plot);
public abstract boolean unclaimPlot(final PlotWorld plotworld, final Plot plot, Runnable whenDone);
public abstract boolean unclaimPlot(final PlotWorld plotworld, final Plot plot, final Runnable whenDone);
public abstract Location getSignLoc(final PlotWorld plotworld, final Plot plot);
@ -84,10 +85,11 @@ public abstract class PlotManager {
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))));
public void exportTemplate(final PlotWorld plotworld) throws IOException
{
final HashSet<FileBytes> files = new HashSet<>(Arrays.asList(new FileBytes("templates/" + "tmp-data.yml", Template.getBytes(plotworld))));
Template.zipAll(plotworld.worldname, files);
}
}

View File

@ -3,53 +3,64 @@ package com.intellectualcrafters.plot.object;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.util.ChatManager;
public class PlotMessage {
private Object builder;
public class PlotMessage
{
public PlotMessage() {
this.builder = ChatManager.manager.builder();
private final Object builder;
public PlotMessage()
{
builder = ChatManager.manager.builder();
}
public <T> T $(ChatManager<T> manager) {
public <T> T $(final ChatManager<T> manager)
{
return (T) builder;
}
public PlotMessage(String text) {
public PlotMessage(final String text)
{
this();
text(text);
}
public PlotMessage text(String text) {
public PlotMessage text(final String text)
{
ChatManager.manager.text(this, text);
return this;
}
public PlotMessage tooltip(PlotMessage... tooltip) {
public PlotMessage tooltip(final PlotMessage... tooltip)
{
ChatManager.manager.tooltip(this, tooltip);
return this;
}
public PlotMessage tooltip(String tooltip) {
public PlotMessage tooltip(final String tooltip)
{
return tooltip(new PlotMessage(tooltip));
}
public PlotMessage command(String command) {
public PlotMessage command(final String command)
{
ChatManager.manager.command(this, command);
return this;
}
public PlotMessage suggest(String command) {
public PlotMessage suggest(final String command)
{
ChatManager.manager.suggest(this, command);
return this;
}
public PlotMessage color(String color) {
public PlotMessage color(final String color)
{
ChatManager.manager.color(this, C.color(color));
return this;
}
public void send(PlotPlayer player) {
public void send(final PlotPlayer player)
{
ChatManager.manager.send(this, player);
}
}

View File

@ -1,295 +1,322 @@
package com.intellectualcrafters.plot.object;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.commands.RequiredType;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.PlotGamemode;
import com.intellectualcrafters.plot.util.PlotWeather;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandCaller;
/**
* Created 2015-02-20 for PlotSquared
*
* @author Citymonstret
*/
public abstract class PlotPlayer implements CommandCaller {
/**
* The metadata map
*/
private ConcurrentHashMap<String, Object> meta;
/**
* Wrap a Player object to get a PlotPlayer<br>
* - This will usually be cached, so no new object creation
* @param obj
* @return
*/
public static PlotPlayer wrap(Object obj) {
return PS.get().IMP.wrapPlayer(obj);
}
/**
* Get the cached PlotPlayer from a username<br>
* - This will return null if the player has just logged in or is not online
* @param name
* @return
*/
public static PlotPlayer get(String name) {
return UUIDHandler.getPlayer(name);
}
/**
* Set some session only metadata for the player
* @param key
* @param value
*/
public void setMeta(String key, Object value) {
if (this.meta == null) {
this.meta = new ConcurrentHashMap<String, Object>();
}
this.meta.put(key, value);
}
/**
* Get the metadata for a key
* @param key
* @return
*/
public Object getMeta(String key) {
if (this.meta != null) {
return this.meta.get(key);
}
return null;
}
/**
* Delete the metadata for a key<br>
* - metadata is session only
* - deleting other plugin's metadata may cause issues
* @param key
*/
public void deleteMeta(String key) {
if (this.meta != null) {
this.meta.remove(key);
}
}
/**
* Returns the player's name
* @see #getName()
*/
public String toString() {
return getName();
}
/**
* Get the player's current plot<br>
* - This is cached
* @return
*/
public Plot getCurrentPlot() {
return (Plot) getMeta("lastplot");
}
/**
* Get the total number of allowed plots
* @return
*/
public int getAllowedPlots() {
return MainUtil.getAllowedPlots(this);
}
/**
* Get the number of plots the player owns
* @return
*/
public int getPlotCount() {
return MainUtil.getPlayerPlotCount(this);
}
/**
* Get the number of plots the player owns in the world
* @param world
* @return
*/
public int getPlotCount(String world) {
return MainUtil.getPlayerPlotCount(world, this);
}
/**
* Get the plots the player owns
* @see #PS.java for more searching functions
* @return Set of plots
*/
public Set<Plot> getPlots() {
return PS.get().getPlots(this);
}
/**
* Return the PlotWorld the player is currently in, or null
* @return
*/
public PlotWorld getPlotWorld() {
return PS.get().getPlotWorld(getLocation().getWorld());
}
@Override
public RequiredType getSuperCaller() {
return RequiredType.PLAYER;
}
/////////////// PLAYER META ///////////////
////////////// PARTIALLY IMPLEMENTED ///////////
/**
* Get the player's last recorded location
* @return
*/
public Location getLocation() {
Location loc = (Location) getMeta("location");
if (loc != null) {
return loc;
}
return null;
}
////////////////////////////////////////////////
/**
* Get the previous time the player logged in
* @return
*/
public abstract long getPreviousLogin();
/**
* Get the player's full location (including yaw/pitch)
* @return
*/
public abstract Location getLocationFull();
/**
* Get the player's UUID<br>
* === !IMPORTANT ===<br>
* The UUID is dependent on the mode chosen in the settings.yml and may not be the same as Bukkit has
* (especially if using an old version of Bukkit that does not support UUIDs)
*
* @return UUID
*/
public abstract UUID getUUID();
/**
* Check the player's permissions<br>
* - Will be cached if permission caching is enabled
*/
public abstract boolean hasPermission(final String perm);
/**
* Send the player a message
*/
public abstract void sendMessage(final String message);
/**
* Teleport the player to a location
* @param loc
*/
public abstract void teleport(final Location loc);
/**
* Is the player online
* @return
*/
public abstract boolean isOnline();
/**
* Get the player's name
* @return
*/
public abstract String getName();
/**
* Set the compass target
* @param loc
*/
public abstract void setCompassTarget(Location loc);
/**
* Load the player data from disk (if applicable)
*/
public abstract void loadData();
/**
* Save the player data from disk (if applicable)
*/
public abstract 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 abstract void setAttribute(String key);
/**
* The attribute will be either true or false
* @param key
*/
public abstract boolean getAttribute(String key);
/**
* Remove an attribute from a player
* @param key
*/
public abstract void removeAttribute(String key);
/**
* Set the player's local weather
* @param weather
*/
public abstract void setWeather(PlotWeather weather);
/**
* Get the player's gamemode
* @return
*/
public abstract PlotGamemode getGamemode();
/**
* Set the player's gamemode
* @param gamemode
*/
public abstract void setGamemode(PlotGamemode gamemode);
/**
* Set the player's local time
* @param time
*/
public abstract void setTime(long time);
/**
* Set the player's fly mode
* @param fly
*/
public abstract void setFlight(boolean fly);
/**
* Play music at a location for the player
* @param loc
* @param id
*/
public abstract void playMusic(Location loc, int id);
/**
* Kick the player from the game
* @param message
*/
public abstract void kick(String message);
}
package com.intellectualcrafters.plot.object;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.commands.RequiredType;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.PlotGamemode;
import com.intellectualcrafters.plot.util.PlotWeather;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandCaller;
/**
* Created 2015-02-20 for PlotSquared
*
*/
public abstract class PlotPlayer implements CommandCaller
{
/**
* The metadata map
*/
private ConcurrentHashMap<String, Object> meta;
/**
* Efficiently wrap a Player object to get a PlotPlayer (or fetch if it's already cached)<br>
* - Accepts sponge/bukkit Player (online)
* - Accepts player name (online)
* - Accepts UUID
* - Accepts bukkit OfflinePlayer (offline)
* @param obj
* @return
*/
public static PlotPlayer wrap(final Object obj)
{
return PS.get().IMP.wrapPlayer(obj);
}
/**
* Get the cached PlotPlayer from a username<br>
* - This will return null if the player has just logged in or is not online
* @param name
* @return
*/
public static PlotPlayer get(final String name)
{
return UUIDHandler.getPlayer(name);
}
/**
* Set some session only metadata for the player
* @param key
* @param value
*/
public void setMeta(final String key, final Object value)
{
if (meta == null)
{
meta = new ConcurrentHashMap<String, Object>();
}
meta.put(key, value);
}
/**
* Get the metadata for a key
* @param key
* @return
*/
public Object getMeta(final String key)
{
if (meta != null) { return meta.get(key); }
return null;
}
/**
* Delete the metadata for a key<br>
* - metadata is session only
* - deleting other plugin's metadata may cause issues
* @param key
*/
public void deleteMeta(final String key)
{
if (meta != null)
{
meta.remove(key);
}
}
/**
* Returns the player's name
* @see #getName()
*/
@Override
public String toString()
{
return getName();
}
/**
* Get the player's current plot<br>
* - This will return null if the player is standing in the road, or not in a plot world/area
* - An unowned plot is still a plot, it just doesn't have any settings
* @return
*/
public Plot getCurrentPlot()
{
return (Plot) getMeta("lastplot");
}
/**
* Get the total number of allowed plots
* Possibly relevant: (To increment the player's allowed plots, see the example script on the wiki)
* @return number of allowed plots within the scope (globally, or in the player's current world as defined in the settings.yml)
*/
public int getAllowedPlots()
{
return MainUtil.getAllowedPlots(this);
}
/**
* Get the number of plots the player owns
*
* @see #getPlotCount(String);
* @see #getPlots()
*
* @return number of plots within the scope (globally, or in the player's current world as defined in the settings.yml)
*/
public int getPlotCount()
{
return MainUtil.getPlayerPlotCount(this);
}
/**
* Get the number of plots the player owns in the world
* @param world
* @return
*/
public int getPlotCount(final String world)
{
return MainUtil.getPlayerPlotCount(world, this);
}
/**
* Get the plots the player owns
* @see #PS.java for more searching functions
* @see #getPlotCount() for the number of plots
* @return Set of plots
*/
public Set<Plot> getPlots()
{
return PS.get().getPlots(this);
}
/**
* Return the PlotWorld the player is currently in, or null
* @return
*/
public PlotWorld getPlotWorld()
{
return PS.get().getPlotWorld(getLocation().getWorld());
}
@Override
public RequiredType getSuperCaller()
{
return RequiredType.PLAYER;
}
/////////////// PLAYER META ///////////////
////////////// PARTIALLY IMPLEMENTED ///////////
/**
* Get the player's last recorded location or null if they don't any plot relevant location
* @return
*/
public Location getLocation()
{
final Location loc = (Location) getMeta("location");
if (loc != null) { return loc; }
return null;
}
////////////////////////////////////////////////
/**
* Get the previous time the player logged in
* @return
*/
public abstract long getPreviousLogin();
/**
* Get the player's full location (including yaw/pitch)
* @return
*/
public abstract Location getLocationFull();
/**
* Get the player's UUID<br>
* === !IMPORTANT ===<br>
* The UUID is dependent on the mode chosen in the settings.yml and may not be the same as Bukkit has
* (especially if using an old version of Bukkit that does not support UUIDs)
*
* @return UUID
*/
public abstract UUID getUUID();
/**
* Check the player's permissions<br>
* - Will be cached if permission caching is enabled
*/
@Override
public abstract boolean hasPermission(final String perm);
/**
* Send the player a message
*/
@Override
public abstract void sendMessage(final String message);
/**
* Teleport the player to a location
* @param loc
*/
public abstract void teleport(final Location loc);
/**
* Is the player online
* @return
*/
public abstract boolean isOnline();
/**
* Get the player's name
* @return
*/
public abstract String getName();
/**
* Set the compass target
* @param loc
*/
public abstract void setCompassTarget(final Location loc);
/**
* Load the player data from disk (if applicable)
* @deprecated hacky
*/
@Deprecated
public abstract void loadData();
/**
* Save the player data from disk (if applicable)
* @deprecated hacky
*/
@Deprecated
public abstract 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 abstract void setAttribute(final String key);
/**
* The attribute will be either true or false
* @param key
*/
public abstract boolean getAttribute(final String key);
/**
* Remove an attribute from a player
* @param key
*/
public abstract void removeAttribute(final String key);
/**
* Set the player's local weather
* @param weather
*/
public abstract void setWeather(final PlotWeather weather);
/**
* Get the player's gamemode
* @return
*/
public abstract PlotGamemode getGamemode();
/**
* Set the player's gamemode
* @param gamemode
*/
public abstract void setGamemode(final PlotGamemode gamemode);
/**
* Set the player's local time (ticks)
* @param time
*/
public abstract void setTime(final long time);
/**
* Set the player's fly mode
* @param fly
*/
public abstract void setFlight(final boolean fly);
/**
* Play music at a location for the player
* @param loc
* @param id
*/
public abstract void playMusic(final Location loc, final int id);
/**
* Kick the player from the game
* @param message
*/
public abstract void kick(final String message);

View File

@ -1,192 +1,205 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// 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;
/**
* 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;
}
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);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// 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;
/**
* plot settings
*
*/
@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)
{
alias = "";
this.plot = plot;
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 merged[direction];
}
/**
* Returns true if the plot is merged (i.e. if it's a mega plot)
*/
public boolean isMerged()
{
return (merged[0] || merged[1] || merged[2] || merged[3]);
}
public boolean[] getMerged()
{
return merged;
}
public void setMerged(final boolean[] merged)
{
this.merged = merged;
}
public void setMerged(final int direction, final boolean merged)
{
this.merged[direction] = merged;
}
public BlockLoc getPosition()
{
if (position == null) { return new BlockLoc(0, 0, 0); }
return position;
}
public void setPosition(final BlockLoc position)
{
this.position = position;
}
public String getAlias()
{
return 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(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(plot, "farewell");
if (farewell != null) { return farewell.getValueString(); }
return "";
}
public ArrayList<PlotComment> getComments(final String inbox)
{
final ArrayList<PlotComment> c = new ArrayList<>();
if (comments == null) { return null; }
for (final PlotComment comment : 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 (comments.contains(comment))
{
comments.remove(comment);
}
}
public void removeComments(final List<PlotComment> comments)
{
for (final PlotComment comment : comments)
{
removeComment(comment);
}
}
public void addComment(final PlotComment comment)
{
if (comments == null)
{
comments = new ArrayList<>();
}
comments.add(comment);

View File

@ -39,7 +39,8 @@ import com.intellectualcrafters.plot.util.StringMan;
/**
* @author Jesse Boyd
*/
public abstract class PlotWorld {
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;
@ -68,8 +69,75 @@ public abstract class PlotWorld {
// 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 };
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;
@ -101,31 +169,24 @@ public abstract class PlotWorld {
public int MIN_BUILD_HEIGHT;
public PlotGamemode GAMEMODE = PlotGamemode.CREATIVE;
public PlotWorld(final String worldname) {
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;
}
public boolean equals(final Object obj)
{
if (this == obj) { return true; }
if (obj == null) { return false; }
if (getClass() != obj.getClass()) { return false; }
final PlotWorld plotworld = (PlotWorld) obj;
final ConfigurationSection section = PS.get().config.getConfigurationSection("worlds");
for (final ConfigurationNode setting : plotworld.getSettingNodes())
{
final Object constant = section.get(plotworld.worldname + "." + setting.getConstant());
if (constant == null) { return false; }
if (!constant.equals(section.get(worldname + "." + setting.getConstant()))) { return false; }
}
return true;
}
@ -135,98 +196,113 @@ public abstract class PlotWorld {
*
* @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");
public void loadDefaultConfiguration(final ConfigurationSection config)
{
if (config.contains("generator.terrain"))
{
TERRAIN = config.getInt("generator.terrain");
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.MAX_BUILD_HEIGHT = config.getInt("world.max_height");
this.MIN_BUILD_HEIGHT = config.getInt("min.max_height");
switch (config.getString("world.gamemode").toLowerCase()) {
MOB_SPAWNING = config.getBoolean("natural_mob_spawning");
AUTO_MERGE = config.getBoolean("plot.auto_merge");
MAX_PLOT_MEMBERS = config.getInt("limits.max-members");
ALLOW_SIGNS = config.getBoolean("plot.create_signs");
PLOT_BIOME = Configuration.BIOME.parseString(config.getString("plot.biome"));
SCHEMATIC_ON_CLAIM = config.getBoolean("schematic.on_claim");
SCHEMATIC_FILE = config.getString("schematic.file");
SCHEMATIC_CLAIM_SPECIFY = config.getBoolean("schematic.specify_on_claim");
SCHEMATICS = config.getStringList("schematic.schematics");
USE_ECONOMY = config.getBoolean("economy.use") && (EconHandler.manager != null);
PLOT_PRICE = config.getDouble("economy.prices.claim");
MERGE_PRICE = config.getDouble("economy.prices.merge");
SELL_PRICE = config.getDouble("economy.prices.sell");
PLOT_CHAT = config.getBoolean("chat.enabled");
WORLD_BORDER = config.getBoolean("world.border");
MAX_BUILD_HEIGHT = config.getInt("world.max_height");
MIN_BUILD_HEIGHT = config.getInt("min.max_height");
switch (config.getString("world.gamemode").toLowerCase())
{
case "survival":
case "s":
case "0":
this.GAMEMODE = PlotGamemode.SURVIVAL;
GAMEMODE = PlotGamemode.SURVIVAL;
break;
case "creative":
case "c":
case "1":
this.GAMEMODE = PlotGamemode.CREATIVE;
GAMEMODE = PlotGamemode.CREATIVE;
break;
case "adventure":
case "a":
case "2":
this.GAMEMODE = PlotGamemode.ADVENTURE;
GAMEMODE = PlotGamemode.ADVENTURE;
break;
case "spectator":
case "3":
this.GAMEMODE = PlotGamemode.SPECTATOR;
GAMEMODE = PlotGamemode.SPECTATOR;
break;
default:
PS.debug("&cInvalid gamemode set for: " + worldname);
break;
}
this.HOME_ALLOW_NONMEMBER = config.getBoolean("home.allow-nonmembers");
String homeDefault = config.getString("home.default");
if (homeDefault.equalsIgnoreCase("side")) {
HOME_ALLOW_NONMEMBER = config.getBoolean("home.allow-nonmembers");
final String homeDefault = config.getString("home.default");
if (homeDefault.equalsIgnoreCase("side"))
{
DEFAULT_HOME = null;
}
else if (homeDefault.equalsIgnoreCase("center")) {
else if (homeDefault.equalsIgnoreCase("center"))
{
DEFAULT_HOME = new PlotLoc(Integer.MAX_VALUE, Integer.MAX_VALUE);
}
else {
try {
String[] split = homeDefault.split(",");
else
{
try
{
final String[] split = homeDefault.split(",");
DEFAULT_HOME = new PlotLoc(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
}
catch (Exception e) {
catch (final Exception e)
{
DEFAULT_HOME = null;
}
}
List<String> flags = config.getStringList("flags.default");
if (flags == null || flags.size() == 0) {
if ((flags == null) || (flags.size() == 0))
{
flags = config.getStringList("flags");
if (flags == null || flags.size() == 0) {
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")) {
final ConfigurationSection section = config.getConfigurationSection("flags");
final Set<String> keys = section.getKeys(false);
for (final 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.debug("&cInvalid default flags for " + this.worldname + ": " + StringMan.join(flags, ","));
this.DEFAULT_FLAGS = new HashMap<>();
try
{
DEFAULT_FLAGS = FlagManager.parseFlags(flags);
}
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");
catch (final Exception e)
{
e.printStackTrace();
PS.debug("&cInvalid default flags for " + worldname + ": " + StringMan.join(flags, ","));
DEFAULT_FLAGS = new HashMap<>();
}
PVP = config.getBoolean("event.pvp");
PVE = config.getBoolean("event.pve");
SPAWN_EGGS = config.getBoolean("event.spawn.egg");
SPAWN_CUSTOM = config.getBoolean("event.spawn.custom");
SPAWN_BREEDING = config.getBoolean("event.spawn.breeding");
loadConfiguration(config);
}
@ -237,7 +313,8 @@ public abstract class PlotWorld {
*
* @param config Configuration Section
*/
public void saveConfiguration(final ConfigurationSection config) {
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);
@ -266,19 +343,23 @@ public abstract class PlotWorld {
options.put("world.min_height", PlotWorld.MIN_BUILD_HEIGHT_DEFAULT);
options.put("world.gamemode", PlotWorld.GAMEMODE_DEFAULT.name().toLowerCase());
if (Settings.ENABLE_CLUSTERS && (this.TYPE != 0)) {
options.put("generator.terrain", this.TERRAIN);
options.put("generator.type", this.TYPE);
if (Settings.ENABLE_CLUSTERS && (TYPE != 0))
{
options.put("generator.terrain", TERRAIN);
options.put("generator.type", TYPE);
}
final ConfigurationNode[] settings = getSettingNodes();
/*
* Saving generator specific settings
*/
for (final ConfigurationNode setting : settings) {
for (final ConfigurationNode setting : settings)
{
options.put(setting.getConstant(), setting.getValue());
}
for (final String option : options.keySet()) {
if (!config.contains(option)) {
for (final String option : options.keySet())
{
if (!config.contains(option))
{
config.set(option, options.get(option));
}
}

View File

@ -1,25 +1,27 @@
package com.intellectualcrafters.plot.object;
public class PseudoRandom {
public class PseudoRandom
{
public long state = System.nanoTime();
public long nextLong() {
public long nextLong()
{
final long a = state;
state = xorShift64(a);
return a;
}
public long xorShift64(long 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;
}
public int random(final int n)
{
if (n == 1) { return 0; }
final long r = ((nextLong() >>> 32) * n) >> 32;
return (int) r;
}

View File

@ -7,80 +7,89 @@ import java.util.Map.Entry;
import com.intellectualcrafters.plot.config.Settings;
public class Rating {
public class Rating
{
/**
* This is a map of the rating category to the rating value
*/
private HashMap<String, Integer> ratingMap;
private boolean changed;
private int initial;
public Rating(int value) {
this.initial = value;
public Rating(int value)
{
initial = value;
ratingMap = new HashMap<>();
if (Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() > 1) {
if (value < 10) {
for (int i = 0 ; i < Settings.RATING_CATEGORIES.size(); i++) {
if ((Settings.RATING_CATEGORIES != null) && (Settings.RATING_CATEGORIES.size() > 1))
{
if (value < 10)
{
for (int i = 0; i < Settings.RATING_CATEGORIES.size(); i++)
{
ratingMap.put(Settings.RATING_CATEGORIES.get(i), value);
}
changed = true;
return;
}
for (int i = 0 ; i < Settings.RATING_CATEGORIES.size(); i++) {
for (int i = 0; i < Settings.RATING_CATEGORIES.size(); i++)
{
ratingMap.put(Settings.RATING_CATEGORIES.get(i), (value % 10) - 1);
value /= 10;
}
}
else {
else
{
ratingMap.put(null, value);
}
}
public List<String> getCategories() {
if (ratingMap.size() == 1) {
return new ArrayList<>();
}
public List<String> getCategories()
{
if (ratingMap.size() == 1) { return new ArrayList<>(); }
return new ArrayList<>(ratingMap.keySet());
}
public double getAverageRating() {
public double getAverageRating()
{
double total = 0;
for (Entry<String, Integer> entry : ratingMap.entrySet()) {
for (final Entry<String, Integer> entry : ratingMap.entrySet())
{
total += entry.getValue();
}
return total / (double) ratingMap.size();
return total / ratingMap.size();
}
public Integer getRating(String category) {
public Integer getRating(final String category)
{
return ratingMap.get(category);
}
public boolean setRating(String category, int value) {
public boolean setRating(final String category, final int value)
{
changed = true;
if (!this.ratingMap.containsKey(category)) {
return false;
}
return this.ratingMap.put(category, value) != null;
if (!ratingMap.containsKey(category)) { return false; }
return ratingMap.put(category, value) != null;
}
public int getAggregate() {
if (!changed) {
return initial;
}
if (Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() > 1) {
public int getAggregate()
{
if (!changed) { return initial; }
if ((Settings.RATING_CATEGORIES != null) && (Settings.RATING_CATEGORIES.size() > 1))
{
int val = 0;
for (int i = 0; i < Settings.RATING_CATEGORIES.size(); i++) {
for (int i = 0; i < Settings.RATING_CATEGORIES.size(); i++)
{
val += (i + 1) * Math.pow(10, ratingMap.get(Settings.RATING_CATEGORIES.get(i)));
}
return val;
}
else {
else
{
return ratingMap.get(null);
}
}
}

View File

@ -1,6 +1,7 @@
package com.intellectualcrafters.plot.object;
public class RegionWrapper {
public class RegionWrapper
{
public final int minX;
public final int maxX;
public final int minY;
@ -8,16 +9,18 @@ public class RegionWrapper {
public final int minZ;
public final int maxZ;
public RegionWrapper(final int minX, final int maxX, final int minZ, 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;
this.minY = 0;
this.maxY = 256;
minY = 0;
maxY = 256;
}
public RegionWrapper(final int minX, final int maxX, final int minY, final int maxY, final int minZ, final int maxZ) {
public RegionWrapper(final int minX, final int maxX, final int minY, final int maxY, final int minZ, final int maxZ)
{
this.maxX = maxX;
this.minX = minX;
this.maxZ = maxZ;
@ -25,12 +28,14 @@ public class RegionWrapper {
this.minY = minY;
this.maxY = maxY;
}
public boolean isIn(final int x, final int y, final int z) {
return ((x >= this.minX) && (x <= this.maxX) && (z >= this.minZ) && (z <= this.maxZ) && (y >= this.minY) && (y <= this.maxY));
public boolean isIn(final int x, final int y, final int z)
{
return ((x >= minX) && (x <= maxX) && (z >= minZ) && (z <= maxZ) && (y >= minY) && (y <= maxY));
}
public boolean isIn(final int x, final int z) {
return ((x >= this.minX) && (x <= this.maxX) && (z >= this.minZ) && (z <= this.maxZ));
public boolean isIn(final int x, final int z)
{
return ((x >= minX) && (x <= maxX) && (z >= minZ) && (z <= maxZ));
}
}

View File

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

View File

@ -3,48 +3,49 @@ package com.intellectualcrafters.plot.object;
import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.util.SetupUtils;
public class SetupObject {
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
*/

View File

@ -1,93 +1,86 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// 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;
}
if (obj.hashCode() != hashCode()) {
return false;
}
final StringWrapper other = (StringWrapper) obj;
if ((other.value == null) || (this.value == null)) {
return false;
}
return other.value.equalsIgnoreCase(this.value.toLowerCase());
}
/**
* Get the string value
*
* @return string value
*/
@Override
public String toString() {
return this.value;
}
private int hash;
/**
* Get the hash value
*
* @return has value
*/
@Override
public int hashCode() {
if (this.value == null) {
return 0;
}
if (this.hash == 0) {
this.hash = this.value.toLowerCase().hashCode();
}
return hash;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// 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 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; }
if (obj.hashCode() != hashCode()) { return false; }
final StringWrapper other = (StringWrapper) obj;
if ((other.value == null) || (value == null)) { return false; }
return other.value.equalsIgnoreCase(value.toLowerCase());
}
/**
* Get the string value
*
* @return string value
*/
@Override
public String toString()
{
return value;
}
private int hash;
/**
* Get the hash value
*
* @return has value
*/
@Override
public int hashCode()
{
if (value == null) { return 0; }
if (hash == 0)
{
hash = value.toLowerCase().hashCode();
}
return hash;
}

View File

@ -4,32 +4,33 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
public abstract class CommentInbox {
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);
public abstract boolean canRead(final Plot plot, final PlotPlayer player);
public abstract boolean canWrite(final Plot plot, final PlotPlayer player);
public abstract boolean canModify(final Plot plot, final 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);
public abstract boolean getComments(final Plot plot, final RunnableVal whenDone);
public abstract boolean addComment(final Plot plot, final PlotComment comment);
public abstract boolean removeComment(final Plot plot, final PlotComment comment);
public abstract boolean clearInbox(final Plot plot);
}

View File

@ -10,53 +10,62 @@ import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager;
public class InboxOwner extends CommentInbox {
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")));
public boolean canRead(final Plot plot, final 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")));
public boolean canWrite(final Plot plot, final 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")));
public boolean canModify(final Plot plot, final 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.getSettings().getComments(toString());
if (comments != null) {
public boolean getComments(final Plot plot, final RunnableVal whenDone)
{
if ((plot == null) || (plot.owner == null)) { return false; }
final ArrayList<PlotComment> comments = plot.getSettings().getComments(toString());
if (comments != null)
{
whenDone.value = comments;
TaskManager.runTask(whenDone);
return true;
}
DBFunc.getComments(plot, toString(), new RunnableVal() {
DBFunc.getComments(plot, toString(), new RunnableVal()
{
@Override
public void run() {
public void run()
{
whenDone.value = value;
if (value != null) {
for (PlotComment comment : (ArrayList<PlotComment>) value) {
if (value != null)
{
for (final PlotComment comment : (ArrayList<PlotComment>) value)
{
plot.getSettings().addComment(comment);
}
}
else {
else
{
plot.getSettings().setComments(new ArrayList<PlotComment>());
}
TaskManager.runTask(whenDone);
@ -66,34 +75,32 @@ public class InboxOwner extends CommentInbox {
}
@Override
public boolean addComment(Plot plot, PlotComment comment) {
if (plot == null || plot.owner == null) {
return false;
}
public boolean addComment(final Plot plot, final PlotComment comment)
{
if ((plot == null) || (plot.owner == null)) { return false; }
plot.getSettings().addComment(comment);
DBFunc.setComment(plot, comment);
return true;
}
@Override
public String toString() {
public String toString()
{
return "owner";
}
@Override
public boolean removeComment(Plot plot, PlotComment comment) {
if (plot == null || plot.owner == null) {
return false;
}
public boolean removeComment(final Plot plot, final 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;
}
public boolean clearInbox(final Plot plot)
{
if ((plot == null) || (plot.owner == null)) { return false; }
DBFunc.clearInbox(plot, toString());
return false;
}

View File

@ -10,49 +10,57 @@ import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager;
public class InboxPublic extends CommentInbox {
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")));
public boolean canRead(final Plot plot, final 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")));
public boolean canWrite(final Plot plot, final 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")));
public boolean canModify(final Plot plot, final 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.getSettings().getComments(toString());
if (comments != null) {
public boolean getComments(final Plot plot, final RunnableVal whenDone)
{
if ((plot == null) || (plot.owner == null)) { return false; }
final ArrayList<PlotComment> comments = plot.getSettings().getComments(toString());
if (comments != null)
{
whenDone.value = comments;
TaskManager.runTask(whenDone);
return true;
}
DBFunc.getComments(plot, toString(), new RunnableVal() {
DBFunc.getComments(plot, toString(), new RunnableVal()
{
@Override
public void run() {
public void run()
{
whenDone.value = value;
if (value != null) {
for (PlotComment comment : (ArrayList<PlotComment>) value) {
if (value != null)
{
for (final PlotComment comment : (ArrayList<PlotComment>) value)
{
plot.getSettings().addComment(comment);
}
}
@ -63,34 +71,32 @@ public class InboxPublic extends CommentInbox {
}
@Override
public boolean addComment(Plot plot, PlotComment comment) {
if (plot == null || plot.owner == null) {
return false;
}
public boolean addComment(final Plot plot, final PlotComment comment)
{
if ((plot == null) || (plot.owner == null)) { return false; }
plot.getSettings().addComment(comment);
DBFunc.setComment(plot, comment);
return true;
}
@Override
public String toString() {
public String toString()
{
return "public";
}
@Override
public boolean removeComment(Plot plot, PlotComment comment) {
if (plot == null || plot.owner == null) {
return false;
}
public boolean removeComment(final Plot plot, final 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;
}
public boolean clearInbox(final Plot plot)
{
if ((plot == null) || (plot.owner == null)) { return false; }
DBFunc.clearInbox(plot, toString());
return false;
}

View File

@ -8,37 +8,44 @@ import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager;
public class InboxReport extends CommentInbox {
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")));
public boolean canRead(final Plot plot, final 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")));
public boolean canWrite(final Plot plot, final 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")));
public boolean canModify(final Plot plot, final 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() {
public boolean getComments(final Plot plot, final RunnableVal whenDone)
{
DBFunc.getComments(null, toString(), new RunnableVal()
{
@Override
public void run() {
public void run()
{
whenDone.value = value;
TaskManager.runTask(whenDone);
}
@ -47,33 +54,31 @@ public class InboxReport extends CommentInbox {
}
@Override
public boolean addComment(Plot plot, PlotComment comment) {
if (plot == null || plot.owner == null) {
return false;
}
public boolean addComment(final Plot plot, final PlotComment comment)
{
if ((plot == null) || (plot.owner == null)) { return false; }
DBFunc.setComment(plot, comment);
return true;
}
@Override
public String toString() {
public String toString()
{
return "report";
}
@Override
public boolean removeComment(Plot plot, PlotComment comment) {
if (plot == null || plot.owner == null) {
return false;
}
public boolean removeComment(final Plot plot, final 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;
}
public boolean clearInbox(final Plot plot)
{
if ((plot == null) || (plot.owner == null)) { return false; }
DBFunc.clearInbox(plot, toString());
return false;
}

View File

@ -1,44 +1,45 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// 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;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// 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;
/**
*/
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

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

View File

@ -1,6 +1,7 @@
package com.intellectualcrafters.plot.object.entity;
public class ArmorStandStats {
public class ArmorStandStats
{
public float[] head = new float[3];
public float[] body = new float[3];
public float[] leftLeg = new float[3];

View File

@ -2,7 +2,8 @@ package com.intellectualcrafters.plot.object.entity;
import com.plotsquared.bukkit.object.entity.EntityWrapper;
public class EntityBaseStats {
public class EntityBaseStats
{
public EntityWrapper passenger;
public float fall;
public short fire;

View File

@ -1,6 +1,7 @@
package com.intellectualcrafters.plot.object.entity;
public class HorseStats {
public class HorseStats
{
public double jump;
public boolean chest;
public int variant;

View File

@ -4,7 +4,8 @@ import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
public enum ItemType {
public enum ItemType
{
AIR("air", 0),
STONE("stone", 1),
GRANITE("stone", 1, 1),
@ -599,7 +600,7 @@ public enum ItemType {
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>();
@ -607,37 +608,40 @@ public enum ItemType {
private final byte data;
private final String name;
static {
for (ItemType type : EnumSet.allOf(ItemType.class)) {
static
{
for (final ItemType type : EnumSet.allOf(ItemType.class))
{
ids.put(type.name, type.id);
datas.put(type.name, type.data);
}
}
ItemType(String name, int id) {
ItemType(final String name, final int id)
{
this.id = id;
this.data = 0;
data = 0;
this.name = name;
}
ItemType(String name, int id, int data) {
ItemType(final String name, final int id, final 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;
}
public static int getId(final String name)
{
final 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;
}
public static byte getData(final String name)
{
final Byte value = datas.get(name);
if (value == null) { return 0; }
return value;
}
}

View File

@ -1,14 +1,16 @@
package com.intellectualcrafters.plot.object.schematic;
public class PlotItem {
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) {
public PlotItem(final short x, final short y, final short z, final short[] id, final byte[] data, final byte[] amount)
{
this.x = x;
this.y = y;
this.z = z;