Hows this?

This commit is contained in:
boy0001
2015-09-13 14:04:31 +10:00
parent 1cccdd9d4d
commit 5137b23357
379 changed files with 18471 additions and 28437 deletions

View File

@ -1,56 +1,45 @@
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(final String name, final ChunkLoc loc)
{
public BO3(final String name, final ChunkLoc loc) {
this.name = name;
chunk = loc;
blocks = new StringBuilder();
children = new StringBuilder();
}
public void addChild(final BO3 child)
{
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()
{
public ChunkLoc getLoc() {
return chunk;
}
public String getName()
{
public String getName() {
return name;
}
public void addBlock(final int x, final int y, final int z, final 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,31 +1,27 @@
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;
this.yaw = yaw;
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) + x;
@ -33,46 +29,45 @@ public class BlockLoc
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 ((x == other.x) && (y == other.y) && (z == other.z));
}
@Override
public String toString()
{
public String toString() {
return x + "," + y + "," + z + "," + yaw + "," + pitch;
}
public static BlockLoc fromString(final String string)
{
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);
}
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

@ -26,8 +26,7 @@ package com.intellectualcrafters.plot.object;
* Useful for NMS
*
*/
*/
public class BlockWrapper {
/**
@ -48,7 +47,7 @@ public class BlockWrapper
public final int id;
/**
* Block Data Value
*/
*/
public final byte data;
/**
@ -58,8 +57,7 @@ public class BlockWrapper
* @param y Y Loc Value
* @param z Z Loc Value
* @param id Material ID
* @param data Data Value
*/
* @param data Data Value
*/
public BlockWrapper(final int x, final int y, final int z, final short id, final byte data) {
this.x = x;

View File

@ -1,32 +1,34 @@
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) + 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 ((x == other.x) && (z == other.z));
}

View File

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

View File

@ -12,184 +12,149 @@ 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;
final Set<String> plotworlds = PS.get().getPlotWorlds();
if (plotworlds.size() > 0)
{
if (plotworlds.size() > 0) {
world = plotworlds.iterator().next();
}
else
{
} else {
world = "world";
}
loc = new Location(world, 0, 0, 0);
meta = new HashMap<>();
}
public static boolean isConsole(final PlotPlayer 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(final String perm)
{
public boolean hasPermission(final String perm) {
return true;
}
@Override
public void sendMessage(final String message)
{
public void sendMessage(final String message) {
PS.log(message);
}
@Override
public void sendMessage(final C c, final String... args)
{
public void sendMessage(final C c, final String... args) {
MainUtil.sendMessage(this, c, args);
}
@Override
public void teleport(final Location 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(final 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(final String key)
{}
public void setAttribute(final String key) {}
@Override
public boolean getAttribute(final String key)
{
public boolean getAttribute(final String key) {
return false;
}
@Override
public void removeAttribute(final String key)
{}
public void removeAttribute(final String key) {}
@Override
public void setMeta(final String key, final Object value)
{
public void setMeta(final String key, final Object value) {
meta.put(key, value);
}
@Override
public Object getMeta(final String key)
{
public Object getMeta(final String key) {
return meta.get(key);
}
@Override
public void deleteMeta(final String key)
{
public void deleteMeta(final String key) {
meta.remove(key);
}
@Override
public RequiredType getSuperCaller()
{
public RequiredType getSuperCaller() {
return RequiredType.CONSOLE;
}
@Override
public void setWeather(final PlotWeather weather)
{}
public void setWeather(final PlotWeather weather) {}
@Override
public PlotGamemode getGamemode()
{
public PlotGamemode getGamemode() {
return PlotGamemode.CREATIVE;
}
@Override
public void setGamemode(final PlotGamemode gamemode)
{}
public void setGamemode(final PlotGamemode gamemode) {}
@Override
public void setTime(final long time)
{}
public void setTime(final long time) {}
@Override
public void setFlight(final boolean fly)
{}
public void setFlight(final boolean fly) {}
@Override
public void playMusic(final Location loc, final int id)
{}
public void playMusic(final Location loc, final int id) {}
@Override
public void kick(final String message)
{}
public void kick(final String message) {}
}

View File

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

View File

@ -1,11 +1,9 @@
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

@ -8,22 +8,19 @@ import java.lang.reflect.Method;
* Created 2015-02-11 for PlotSquared
*
*/
public class Location implements Cloneable, Comparable<Location>
*/
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;
private Object o;
@Override
public Location clone()
@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)
}
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;
@ -33,113 +30,94 @@ public class Location implements Cloneable, Comparable<Location>
this.pitch = pitch;
built = false;
o = null;
}
public Location()
}
public Location() {
this("", 0, 0, 0, 0, 0);
}
public Location(final String world, final int x, final int y, final int z)
}
public Location(final String world, final int x, final int y, final int z) {
this(world, x, y, z, 0f, 0f);
}
public int getX()
}
public int getX() {
return x;
}
public void setX(final int x)
}
public void setX(final int x) {
this.x = x;
built = false;
}
public int getY()
}
public int getY() {
return y;
}
public void setY(final int y)
}
public void setY(final int y) {
this.y = y;
built = false;
}
public int getZ()
}
public int getZ() {
return z;
}
public void setZ(final int z)
}
public void setZ(final int z) {
this.z = z;
built = false;
}
public String getWorld()
}
public String getWorld() {
return world;
}
public void setWorld(final String world)
}
public void setWorld(final String world) {
this.world = world;
built = false;
}
public float getYaw()
}
public float getYaw() {
return yaw;
}
public void setYaw(final float yaw)
}
public void setYaw(final float yaw) {
this.yaw = yaw;
built = false;
}
public float getPitch()
}
public float getPitch() {
return pitch;
}
public void setPitch(final float pitch)
}
public void setPitch(final float pitch) {
this.pitch = pitch;
built = false;
}
public Location add(final int x, final int y, final int z)
}
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)
}
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)
}
public double getEuclideanDistance(final Location l2) {
return Math.sqrt(getEuclideanDistanceSquared(l2));
}
public boolean isInSphere(final Location origin, final int radius)
}
public boolean isInSphere(final Location origin, final int radius) {
return getEuclideanDistanceSquared(origin) < (radius * radius);
}
}
@Override
public int hashCode()
@Override
public int hashCode() {
int hash = 127;
hash = (hash * 31) + x;
@ -148,96 +126,89 @@ public class Location implements Cloneable, Comparable<Location>
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)
}
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)
}
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)
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) (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)
}
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; }
@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; }
@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()
@Override
public String toString() {
return "\"plotsquaredlocation\":{" + "\"x\":" + x + ",\"y\":" + y + ",\"z\":" + z + ",\"yaw\":" + yaw + ",\"pitch\":" + pitch + ",\"world\":\"" + world + "\"}";
}
private Object getBukkitWorld()
{
try
}
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 clazz.getMethod("getWorld", String.class).invoke(null, world);
} catch (final Exception e) {
return null;
}
}
public Object toBukkitLocation()
{
if (built) { return o; }
try
}
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 (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"))
*/
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

@ -6,13 +6,12 @@ import java.util.UUID;
* Created 2015-02-20 for PlotSquared
*
*/
public interface OfflinePlotPlayer
*/
public interface OfflinePlotPlayer {
public UUID getUUID();
public UUID getUUID();
public long getLastPlayed();
public long getLastPlayed();
public boolean isOnline();
public boolean isOnline();
public String getName();

File diff suppressed because it is too large Load Diff

View File

@ -18,29 +18,26 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.TaskManager;
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(final Plot plot)
{
public static PlotAnalysis getAnalysis(final Plot plot) {
final Flag flag = FlagManager.getPlotFlag(plot, "analysis");
if (flag != null)
{
if (flag != null) {
final PlotAnalysis analysis = new PlotAnalysis();
final List<Integer> values = (List<Integer>) flag.getValue();
analysis.changes = values.get(0); // 2126
@ -48,27 +45,27 @@ public class PlotAnalysis
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; }
public int getComplexity() {
if (complexity != 0) {
return complexity;
}
complexity = ((changes) * MODIFIERS.changes)
+ ((faces) * MODIFIERS.faces)
+ ((data) * MODIFIERS.data)
@ -81,91 +78,76 @@ public class PlotAnalysis
+ ((variety_sd) * MODIFIERS.variety_sd);
return complexity;
}
public static void analyzePlot(final Plot plot, final RunnableVal<PlotAnalysis> 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()
{
public void run() {
final Iterator<Plot> iter = plots.iterator();
PS.debug(" - $1Reducing " + plots.size() + " plots to those with sufficient data");
while (iter.hasNext())
{
while (iter.hasNext()) {
final Plot plot = iter.next();
if ((plot.getSettings().ratings == null) || (plot.getSettings().ratings.size() == 0))
{
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 (final 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);
final Thread ratingAnalysis = new Thread(new Runnable()
{
final Thread ratingAnalysis = new Thread(new Runnable() {
@Override
public void run()
{
for (; mi.intValue() < plots.size(); mi.incrementAndGet())
{
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);
@ -174,37 +156,27 @@ public class PlotAnalysis
}
});
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() {
analyzePlot(queuePlot, new RunnableVal<PlotAnalysis>() {
@Override
public void run()
{
try
{
public void run() {
try {
wait(10000);
}
catch (final InterruptedException e)
{
} catch (final InterruptedException e) {
e.printStackTrace();
}
synchronized (lock)
{
synchronized (lock) {
MainUtil.runners.remove(queuePlot);
lock.notify();
}
@ -212,60 +184,52 @@ public class PlotAnalysis
});
}
});
try
{
synchronized (lock)
{
try {
synchronized (lock) {
lock.wait();
}
}
catch (final 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 (final 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++)
{
for (int i = 0; i < plots.size(); i++) {
final Plot plot = plots.get(i);
PS.debug(" | " + plot);
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");
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");
final int[] rank_changes = rank(changes);
final int[] sd_changes = getSD(rank_changes, rank_ratings);
final int[] variance_changes = square(sd_changes);
@ -273,7 +237,7 @@ public class PlotAnalysis
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);
final int[] rank_faces = rank(faces);
final int[] sd_faces = getSD(rank_faces, rank_ratings);
final int[] variance_faces = square(sd_faces);
@ -281,7 +245,7 @@ public class PlotAnalysis
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);
final int[] rank_data = rank(data);
final int[] sd_data = getSD(rank_data, rank_ratings);
final int[] variance_data = square(sd_data);
@ -289,7 +253,7 @@ public class PlotAnalysis
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);
final int[] rank_air = rank(air);
final int[] sd_air = getSD(rank_air, rank_ratings);
final int[] variance_air = square(sd_air);
@ -297,7 +261,7 @@ public class PlotAnalysis
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);
final int[] rank_variety = rank(variety);
final int[] sd_variety = getSD(rank_variety, rank_ratings);
final int[] variance_variety = square(sd_variety);
@ -305,7 +269,7 @@ public class PlotAnalysis
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);
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);
@ -313,7 +277,7 @@ public class PlotAnalysis
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);
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);
@ -321,7 +285,7 @@ public class PlotAnalysis
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);
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);
@ -329,7 +293,7 @@ public class PlotAnalysis
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);
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);
@ -337,7 +301,7 @@ public class PlotAnalysis
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);
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);
@ -345,34 +309,27 @@ public class PlotAnalysis
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);
final int[] complexity = new int[n];
PS.debug(" $1Calculating threshold");
int max = 0;
int min = 0;
for (int i = 0; i < n; i++)
{
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
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)
{
for (int i = 0; i < n; i++) {
if (rank_complexity[i] == optimal_index) {
optimal_complexity = complexity[i];
break;
}
@ -383,19 +340,15 @@ 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 (final Plot plot : plots)
{
for (final Plot plot : plots) {
MainUtil.runners.remove(plot);
}
return;
}
}
else
{ // Use the fast radix sort algorithm
} else { // Use the fast radix sort algorithm
final int[] sorted = complexity.clone();
sort(sorted);
optimal_complexity = sorted[optimal_index];
@ -404,7 +357,7 @@ public class PlotAnalysis
logln("Ratings: ");
logln(rank_ratings);
}
// Save calibration
PS.debug(" $1Saving calibration");
final YamlConfiguration config = PS.get().config;
@ -419,123 +372,103 @@ 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 (final IOException e)
{
} catch (final IOException e) {
e.printStackTrace();
}
PS.debug("$1Done!");
running = false;
for (final Plot plot : plots)
{
for (final Plot plot : plots) {
MainUtil.runners.remove(plot);
}
whenDone.run();
}
});
}
public static void logln(final Object obj)
{
public static void logln(final Object obj) {
PS.debug(log(obj));
}
public static String log(final 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 (final 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(final int n, final int sum)
{
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(final int[] array)
{
public static int sum(final int[] array) {
int sum = 0;
for (final 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(final int[]... ranks)
{
if (ranks.length == 0) { return null; }
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++)
{
for (int j = 0; j < size; j++) {
int sum = 0;
for (final int[] rank : ranks)
{
for (final int[] rank : ranks) {
sum += rank[j];
}
final int mean = sum / arrays;
int sd = 0;
for (final int[] rank : ranks)
{
for (final int[] rank : ranks) {
final int value = rank[j];
sd += value < mean ? mean - value : value - mean;
}
@ -543,7 +476,7 @@ public class PlotAnalysis
}
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>
@ -551,90 +484,71 @@ 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, final 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 (final int value : input)
{
if (value > max)
{
if (input.length < size) {
for (final int value : input) {
if (value > max) {
max = value;
}
cache[value]++;
}
}
else
{
} else {
max = cache.length - 1;
for (final int value : input)
{
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;
}
}
}
final int[] ranks = new int[input.length];
for (int i = 0; i < input.length; i++)
{
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(final int[] input)
{
public static void sort(final int[] input) {
final int SIZE = 10;
final List<Integer>[] bucket = new ArrayList[SIZE];
for (int i = 0; i < bucket.length; i++)
{
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 (final 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 (final 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

@ -22,40 +22,43 @@ package com.intellectualcrafters.plot.object;
/**
*/
public class PlotBlock
{
*/
public class PlotBlock {
public static PlotBlock EVERYTHING = new PlotBlock((short) 0, (byte) 0);
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)
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; }
@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()
@Override
public int hashCode() {
return id;
}
}
@Override
public String toString()
{
@Override
public String toString() {
if (data == -1) {
return id + "";
}
return id + ":" + data;
}

View File

@ -5,8 +5,7 @@ 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,79 +13,73 @@ public class PlotCluster
public HashSet<UUID> invited = new HashSet<UUID>();
private PlotId pos1;
private PlotId pos2;
public PlotId getP1()
{
public PlotId getP1() {
return pos1;
}
public PlotId getP2()
{
public PlotId getP2() {
return pos2;
}
public void setP1(final PlotId id)
{
public void setP1(final PlotId id) {
pos1 = id;
}
public void setP2(final PlotId 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;
settings = new PlotSettings(null);
}
public boolean isAdded(final UUID uuid)
{
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)
{
public boolean hasHelperRights(final UUID uuid) {
return (owner.equals(uuid) || helpers.contains(uuid) || helpers.contains(DBFunc.everyone));
}
public String getName()
{
public String getName() {
return settings.getAlias();
}
/**
* Get the area (in plots)
* @return
*/
public int getArea()
{
public int getArea() {
return ((1 + pos2.x) - pos1.x) * ((1 + pos2.y) - pos1.y);
}
@Override
public int 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 (world.equals(other.world) && pos1.equals(other.pos1) && pos2.equals(other.pos2));
}
@Override
public String toString()
{
public String toString() {
return world + ";" + pos1.x + ";" + pos1.y + ";" + pos2.x + ";" + pos2.y;
}
}

View File

@ -1,12 +1,10 @@
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,14 +1,11 @@
package com.intellectualcrafters.plot.object;
public abstract class PlotFilter
{
public boolean allowsWorld(final String world)
{
public abstract class PlotFilter {
public boolean allowsWorld(final String world) {
return true;
}
public boolean allowsPlot(final Plot plot)
{
public boolean allowsPlot(final Plot plot) {
return true;
}
}

View File

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

View File

@ -20,8 +20,7 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.object;
public class PlotId
{
public class PlotId {
/**
* x value
*/
@ -30,19 +29,18 @@ public class PlotId
* y value
*/
public Integer y;
/**
* PlotId class (PlotId x,y values do not correspond to Block locations)
*
* @param x The plot x coordinate
* @param y The plot y coordinate
*/
public PlotId(final int x, final int y)
{
public PlotId(final int x, final int y) {
this.x = x;
this.y = y;
}
/**
* Get a Plot Id based on a string
*
@ -50,54 +48,51 @@ 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 ((x.equals(other.x)) && (y.equals(other.y)));
}
@Override
public String toString()
{
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;
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;
@ -106,20 +101,15 @@ public class PlotId
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;
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;
@ -130,41 +120,29 @@ public class PlotId
}
}
}
private int hash;
public void recalculateHash()
{
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,88 +2,83 @@ 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(final PlotPlayer player)
{
public PlotInventory(final PlotPlayer player) {
size = 4;
title = null;
this.player = player;
items = InventoryUtil.manager.getItems(player);
}
public PlotInventory(final PlotPlayer player, final int size, final String name)
{
public PlotInventory(final PlotPlayer player, final int size, final String name) {
this.size = size;
title = name == null ? "" : name;
this.player = player;
items = new PlotItemStack[size * 9];
}
public boolean onClick(final 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(final int index, final PlotItemStack item)
{
public void setItem(final int index, final PlotItemStack item) {
items[index] = item;
InventoryUtil.manager.setItem(this, index, item);
}
public PlotItemStack getItem(final 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(final String title)
{
if (title == null) { return; }
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()
{
public String getTitle() {
return title;
}
public boolean isOpen()
{
public boolean isOpen() {
return open;
}
}

View File

@ -2,26 +2,23 @@ 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(final int id, final short data, final int amount, final String name, final 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(final String id, final int amount, final String name, final String... lore)
{
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;
data = block.data;

View File

@ -1,32 +1,34 @@
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) + 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 ((x == other.x) && (z == other.z));
}

View File

@ -27,69 +27,67 @@ 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)
*/
public abstract PlotId getPlotIdAbs(final PlotWorld plotworld, final int x, final int y, final int z);
public abstract PlotId getPlotId(final PlotWorld plotworld, final int x, final int y, final int z);
// If you have a circular plot, just return the corner if it were a square
public abstract Location getPlotBottomLocAbs(final PlotWorld plotworld, final PlotId plotid);
// the same applies here
public abstract Location getPlotTopLocAbs(final PlotWorld plotworld, final PlotId plotid);
/*
* Plot clearing (return false if you do not support some method)
*/
public abstract boolean clearPlot(final PlotWorld plotworld, final Plot plot, final Runnable whenDone);
public abstract boolean claimPlot(final PlotWorld plotworld, final Plot plot);
public abstract boolean unclaimPlot(final PlotWorld plotworld, final Plot plot, final Runnable whenDone);
public abstract Location getSignLoc(final PlotWorld plotworld, final Plot plot);
/*
* Plot set functions (return false if you do not support the specific set
* method)
*/
public abstract String[] getPlotComponents(final PlotWorld plotworld, final PlotId plotid);
public abstract boolean setComponent(final PlotWorld plotworld, final PlotId plotid, final String component, final PlotBlock[] blocks);
/*
* PLOT MERGING (return false if your generator does not support plot
* merging)
*/
public abstract boolean createRoadEast(final PlotWorld plotworld, final Plot plot);
public abstract boolean createRoadSouth(final PlotWorld plotworld, final Plot plot);
public abstract boolean createRoadSouthEast(final PlotWorld plotworld, final Plot plot);
public abstract boolean removeRoadEast(final PlotWorld plotworld, final Plot plot);
public abstract boolean removeRoadSouth(final PlotWorld plotworld, final Plot plot);
public abstract boolean removeRoadSouthEast(final PlotWorld plotworld, final Plot plot);
public abstract boolean startPlotMerge(final PlotWorld plotworld, final ArrayList<PlotId> plotIds);
public abstract boolean startPlotUnlink(final PlotWorld plotworld, final ArrayList<PlotId> plotIds);
public abstract boolean finishPlotMerge(final PlotWorld plotworld, final ArrayList<PlotId> plotIds);
public abstract boolean finishPlotUnlink(final PlotWorld plotworld, final ArrayList<PlotId> plotIds);
public void exportTemplate(final PlotWorld plotworld) throws IOException
{
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,64 +3,53 @@ package com.intellectualcrafters.plot.object;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.util.ChatManager;
public class PlotMessage
{
public class PlotMessage {
private final Object builder;
public PlotMessage()
{
public PlotMessage() {
builder = ChatManager.manager.builder();
}
public <T> T $(final ChatManager<T> manager)
{
public <T> T $(final ChatManager<T> manager) {
return (T) builder;
}
public PlotMessage(final String text)
{
public PlotMessage(final String text) {
this();
text(text);
}
public PlotMessage text(final String text)
{
public PlotMessage text(final String text) {
ChatManager.manager.text(this, text);
return this;
}
public PlotMessage tooltip(final PlotMessage... tooltip)
{
public PlotMessage tooltip(final PlotMessage... tooltip) {
ChatManager.manager.tooltip(this, tooltip);
return this;
}
public PlotMessage tooltip(final String tooltip)
{
public PlotMessage tooltip(final String tooltip) {
return tooltip(new PlotMessage(tooltip));
}
public PlotMessage command(final String command)
{
public PlotMessage command(final String command) {
ChatManager.manager.command(this, command);
return this;
}
public PlotMessage suggest(final String command)
{
public PlotMessage suggest(final String command) {
ChatManager.manager.suggest(this, command);
return this;
}
public PlotMessage color(final String color)
{
public PlotMessage color(final String color) {
ChatManager.manager.color(this, C.color(color));
return this;
}
public void send(final PlotPlayer player)
{
public void send(final PlotPlayer player) {
ChatManager.manager.send(this, player);
}
}

View File

@ -16,14 +16,13 @@ import com.plotsquared.general.commands.CommandCaller;
* Created 2015-02-20 for PlotSquared
*
*/
public abstract class PlotPlayer implements CommandCaller
{
*/
public abstract class PlotPlayer implements CommandCaller {
/**
* The metadata map
*/
private ConcurrentHashMap<String, Object> meta;
private ConcurrentHashMap<String, Object> meta;
/**
* Efficiently wrap a Player object to get a PlotPlayer (or fetch if it's already cached)<br>
@ -33,92 +32,84 @@ public abstract class PlotPlayer implements CommandCaller
* - Accepts bukkit OfflinePlayer (offline)
* @param obj
* @return
*/
public static PlotPlayer wrap(final Object obj)
*/
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)
*/
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)
*/
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)
{
*/
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)
*/
public void deleteMeta(final String key) {
if (meta != null) {
meta.remove(key);
}
}
}
/**
* Returns the player's name
* @see #getName()
*/
@Override
public String toString()
@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()
*/
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()
*/
public int getAllowedPlots() {
return MainUtil.getAllowedPlots(this);
}
}
/**
* Get the number of plots the player owns
@ -127,75 +118,71 @@ public abstract class PlotPlayer implements CommandCaller
* @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()
*/
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)
*/
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()
*/
public Set<Plot> getPlots() {
return PS.get().getPlots(this);
}
}
/**
* Return the PlotWorld the player is currently in, or null
* @return
*/
public PlotWorld getPlotWorld()
*/
public PlotWorld getPlotWorld() {
return PS.get().getPlotWorld(getLocation().getWorld());
}
}
@Override
public RequiredType getSuperCaller()
@Override
public RequiredType getSuperCaller() {
return RequiredType.PLAYER;
}
}
/////////////// PLAYER META ///////////////
/////////////// 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()
*/
public Location getLocation() {
final Location loc = (Location) getMeta("location");
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();
public abstract long getPreviousLogin();
/**
* Get the player's full location (including yaw/pitch)
* @return
*/
public abstract Location getLocationFull();
public abstract Location getLocationFull();
/**
* Get the player's UUID<br>
@ -205,58 +192,58 @@ public abstract class PlotPlayer implements CommandCaller
*
* @return UUID
*/
public abstract UUID getUUID();
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);
public abstract boolean hasPermission(final String perm);
/**
* Send the player a message
*/
@Override
public abstract void sendMessage(final String message);
public abstract void sendMessage(final String message);
/**
* Teleport the player to a location
* @param loc
*/
public abstract void teleport(final Location loc);
public abstract void teleport(final Location loc);
/**
* Is the player online
* @return
*/
public abstract boolean isOnline();
public abstract boolean isOnline();
/**
* Get the player's name
* @return
*/
public abstract String getName();
public abstract String getName();
/**
* Set the compass target
* @param loc
*/
public abstract void setCompassTarget(final Location loc);
public abstract void setCompassTarget(final Location loc);
/**
* Load the player data from disk (if applicable)
* @deprecated hacky
*/
@Deprecated
public abstract void loadData();
public abstract void loadData();
/**
* Save the player data from disk (if applicable)
* @deprecated hacky
*/
@Deprecated
public abstract void saveData();
public abstract void saveData();
/**
* Set player data that will persist restarts
@ -264,56 +251,56 @@ public abstract class PlotPlayer implements CommandCaller
* - For session only data use meta
* @param key
*/
public abstract void setAttribute(final String 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);
public abstract boolean getAttribute(final String key);
/**
* Remove an attribute from a player
* @param key
*/
public abstract void removeAttribute(final String key);
public abstract void removeAttribute(final String key);
/**
* Set the player's local weather
* @param weather
*/
public abstract void setWeather(final PlotWeather weather);
public abstract void setWeather(final PlotWeather weather);
/**
* Get the player's gamemode
* @return
*/
public abstract PlotGamemode getGamemode();
public abstract PlotGamemode getGamemode();
/**
* Set the player's gamemode
* @param gamemode
*/
public abstract void setGamemode(final PlotGamemode gamemode);
public abstract void setGamemode(final PlotGamemode gamemode);
/**
* Set the player's local time (ticks)
* @param time
*/
public abstract void setTime(final long time);
public abstract void setTime(final long time);
/**
* Set the player's fly mode
* @param fly
*/
public abstract void setFlight(final boolean 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);
public abstract void playMusic(final Location loc, final int id);
/**
* Kick the player from the game

View File

@ -34,8 +34,7 @@ import com.intellectualcrafters.plot.object.comment.PlotComment;
*
*/
@SuppressWarnings("unused")
*/
@SuppressWarnings("unused")
public class PlotSettings {
/**
@ -52,12 +51,12 @@ public class PlotSettings
private String alias;
/**
* Comments
*/
*/
private List<PlotComment> comments = null;
/**
* The ratings for a plot
*/
*/
public HashMap<UUID, Integer> ratings;
/**
@ -66,19 +65,18 @@ public class PlotSettings
public HashMap<String, Flag> flags;
/**
* Home Position
*/
*/
private BlockLoc position;
/**
* Constructor
*
* @param plot object
*/
* @param plot object
*/
public PlotSettings(final Plot plot) {
alias = "";
this.plot = plot;
flags = new HashMap<>();
flags = new HashMap<>();
}
/**
@ -86,118 +84,105 @@ public class PlotSettings
*
* @param direction Direction to check
*
* @return boolean merged
*/
* @return boolean merged
*/
public boolean getMerged(final int direction) {
return merged[direction];
return merged[direction];
}
/**
* Returns true if the plot is merged (i.e. if it's a mega plot)
*/
* 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]);
}
return (merged[0] || merged[1] || merged[2] || merged[3]);
}
public boolean[] getMerged() {
return merged;
}
return merged;
}
public void setMerged(final boolean[] merged) {
this.merged = merged;
}
this.merged = merged;
}
public void setMerged(final int direction, final boolean merged) {
this.merged[direction] = merged;
}
public BlockLoc getPosition()
this.merged[direction] = merged;
}
public BlockLoc getPosition() {
if (position == null) {
return new BlockLoc(0, 0, 0);
}
return position;
}
return position;
}
public void setPosition(final BlockLoc position) {
this.position = position;
}
this.position = position;
}
public String getAlias() {
return alias;
return alias;
}
/**
* Set the plot alias
*
* @param alias alias to be used
*/
* @param alias alias to be used
*/
public void setAlias(final String alias) {
this.alias = alias;
}
this.alias = alias;
}
{
public String getJoinMessage() {
final Flag greeting = FlagManager.getPlotFlag(plot, "greeting");
if (greeting != null) {
return greeting.getValueString();
}
return "";
return "";
}
/**
* Get the "farewell" flag value
*
* @return Farewell flag
*/
* @return Farewell flag
*/
{
public String getLeaveMessage() {
final Flag farewell = FlagManager.getPlotFlag(plot, "farewell");
if (farewell != null) {
return farewell.getValueString();
}
return "";
}
return "";
}
{
final ArrayList<PlotComment> c = new ArrayList<>();
if (comments == null) { return null; }
for (final PlotComment comment : comments)
{
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;
}
return c;
}
public void setComments(final List<PlotComment> comments) {
this.comments = comments;
}
public void removeComment(final PlotComment comment)
{
this.comments = comments;
}
public void removeComment(final PlotComment comment) {
if (comments.contains(comment)) {
comments.remove(comment);
}
}
public void removeComments(final List<PlotComment> comments)
{
}
}
public void removeComments(final List<PlotComment> comments) {
for (final PlotComment comment : comments) {
removeComment(comment);
}
}
public void addComment(final PlotComment comment)
{
}
}
public void addComment(final PlotComment comment) {
if (comments == null) {
comments = new ArrayList<>();

View File

@ -39,8 +39,7 @@ 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;
@ -69,8 +68,7 @@ public abstract class PlotWorld
// TODO make this configurable
// make non static and static_default_valu + add config option
public static int[] BLOCKS;
static
{
static {
BLOCKS = new int[] {
1,
2,
@ -168,38 +166,43 @@ public abstract class PlotWorld
public int MAX_BUILD_HEIGHT;
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(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 PlotWorld plotworld = (PlotWorld) obj;
final ConfigurationSection section = PS.get().config.getConfigurationSection("worlds");
for (final ConfigurationNode setting : plotworld.getSettingNodes())
{
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; }
if (constant == null) {
return false;
}
if (!constant.equals(section.get(worldname + "." + setting.getConstant()))) {
return false;
}
}
return true;
}
/**
* When a world is created, the following method will be called for each
*
* @param config Configuration Section
*/
public void loadDefaultConfiguration(final ConfigurationSection config)
{
if (config.contains("generator.terrain"))
{
public void loadDefaultConfiguration(final ConfigurationSection config) {
if (config.contains("generator.terrain")) {
TERRAIN = config.getInt("generator.terrain");
TYPE = config.getInt("generator.type");
}
@ -220,9 +223,8 @@ public abstract class PlotWorld
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())
{
switch (config.getString("world.gamemode").toLowerCase()) {
case "survival":
case "s":
case "0":
@ -246,54 +248,39 @@ public abstract class PlotWorld
PS.debug("&cInvalid gamemode set for: " + worldname);
break;
}
HOME_ALLOW_NONMEMBER = config.getBoolean("home.allow-nonmembers");
final String homeDefault = config.getString("home.default");
if (homeDefault.equalsIgnoreCase("side"))
{
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
{
} else {
try {
final String[] split = homeDefault.split(",");
DEFAULT_HOME = new PlotLoc(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
}
catch (final 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>();
final ConfigurationSection section = config.getConfigurationSection("flags");
final Set<String> keys = section.getKeys(false);
for (final String key : keys)
{
if (!key.equals("default"))
{
for (final String key : keys) {
if (!key.equals("default")) {
flags.add(key + ";" + section.get(key));
}
}
}
}
try
{
try {
DEFAULT_FLAGS = FlagManager.parseFlags(flags);
}
catch (final Exception e)
{
} catch (final Exception e) {
e.printStackTrace();
PS.debug("&cInvalid default flags for " + worldname + ": " + StringMan.join(flags, ","));
DEFAULT_FLAGS = new HashMap<>();
@ -305,16 +292,15 @@ public abstract class PlotWorld
SPAWN_BREEDING = config.getBoolean("event.spawn.breeding");
loadConfiguration(config);
}
public abstract void loadConfiguration(final ConfigurationSection config);
/**
* Saving core plotworld settings
*
* @param config Configuration Section
*/
public void saveConfiguration(final ConfigurationSection config)
{
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);
@ -342,9 +328,8 @@ public abstract class PlotWorld
options.put("world.max_height", PlotWorld.MAX_BUILD_HEIGHT_DEFAULT);
options.put("world.min_height", PlotWorld.MIN_BUILD_HEIGHT_DEFAULT);
options.put("world.gamemode", PlotWorld.GAMEMODE_DEFAULT.name().toLowerCase());
if (Settings.ENABLE_CLUSTERS && (TYPE != 0))
{
if (Settings.ENABLE_CLUSTERS && (TYPE != 0)) {
options.put("generator.terrain", TERRAIN);
options.put("generator.type", TYPE);
}
@ -352,19 +337,16 @@ public abstract class PlotWorld
/*
* 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));
}
}
}
/**
* Used for the <b>/plot setup</b> command Return null if you do not want to support this feature
*

View File

@ -1,27 +1,25 @@
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,89 +7,77 @@ 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)
{
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 (final Entry<String, Integer> entry : ratingMap.entrySet())
{
for (final Entry<String, Integer> entry : ratingMap.entrySet()) {
total += entry.getValue();
}
return total / ratingMap.size();
}
public Integer getRating(final String category)
{
public Integer getRating(final String category) {
return ratingMap.get(category);
}
public boolean setRating(final String category, final int value)
{
public boolean setRating(final String category, final int value) {
changed = true;
if (!ratingMap.containsKey(category)) { return false; }
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,16 +1,14 @@
package com.intellectualcrafters.plot.object;
public class RegionWrapper
{
public class RegionWrapper {
public final int minX;
public final int maxX;
public final int minY;
public final int maxY;
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;
@ -18,9 +16,8 @@ public class RegionWrapper
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;
@ -28,14 +25,12 @@ public class RegionWrapper
this.minY = minY;
this.maxY = maxY;
}
public boolean isIn(final int x, final int y, final int z)
{
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)
{
public boolean isIn(final int x, final int z) {
return ((x >= minX) && (x <= maxX) && (z >= minZ) && (z <= maxZ));
}
}

View File

@ -1,9 +1,8 @@
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,49 +3,48 @@ 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

@ -22,20 +22,18 @@ package com.intellectualcrafters.plot.object;
/**
*/
public class StringWrapper
*/
public class StringWrapper {
public final String value;
public final String value;
/**
* Constructor
*
* @param value to wrap
*/
public StringWrapper(final String value)
*/
public StringWrapper(final String value) {
this.value = value;
}
}
/**
* Check if a wrapped string equals another one
@ -44,41 +42,49 @@ public class StringWrapper
*
* @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; }
@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;
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()
@Override
public String toString() {
return value;
}
}
private int hash;
private int hash;
/**
* Get the hash value
*
* @return has value
*/
@Override
public int hashCode()
{
if (value == null) { return 0; }
if (hash == 0)
@Override
public int hashCode() {
if (value == null) {
return 0;
}
if (hash == 0) {
hash = value.toLowerCase().hashCode();
}

View File

@ -4,18 +4,17 @@ 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(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>
@ -27,10 +26,10 @@ public abstract class CommentInbox
* @return
*/
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,62 +10,58 @@ 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(final Plot plot, final PlotPlayer player)
{
if (plot == null) { return Permissions.hasPermission(player, "plots.inbox.read." + toString()); }
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(final Plot plot, final PlotPlayer player)
{
if (plot == null) { return Permissions.hasPermission(player, "plots.inbox.write." + toString()); }
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(final Plot plot, final PlotPlayer player)
{
if (plot == null) { return Permissions.hasPermission(player, "plots.inbox.modify." + toString()); }
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; }
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)
{
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 (final 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);
@ -73,34 +69,36 @@ public class InboxOwner extends CommentInbox
});
return true;
}
@Override
public boolean addComment(final Plot plot, final 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(final Plot plot, final 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(final 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,57 +10,55 @@ 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(final Plot plot, final PlotPlayer player)
{
if (plot == null) { return Permissions.hasPermission(player, "plots.inbox.read." + toString()); }
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(final Plot plot, final PlotPlayer player)
{
if (plot == null) { return Permissions.hasPermission(player, "plots.inbox.write." + toString()); }
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(final Plot plot, final PlotPlayer player)
{
if (plot == null) { return Permissions.hasPermission(player, "plots.inbox.modify." + toString()); }
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; }
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)
{
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 (final PlotComment comment : (ArrayList<PlotComment>) value)
{
if (value != null) {
for (final PlotComment comment : (ArrayList<PlotComment>) value) {
plot.getSettings().addComment(comment);
}
}
@ -69,34 +67,36 @@ public class InboxPublic extends CommentInbox
});
return true;
}
@Override
public boolean addComment(final Plot plot, final 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(final Plot plot, final 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(final 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,77 +8,78 @@ 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(final Plot plot, final PlotPlayer player)
{
if (plot == null) { return Permissions.hasPermission(player, "plots.inbox.read." + toString()); }
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(final Plot plot, final PlotPlayer player)
{
if (plot == null) { return Permissions.hasPermission(player, "plots.inbox.write." + toString()); }
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(final Plot plot, final PlotPlayer player)
{
if (plot == null) { return Permissions.hasPermission(player, "plots.inbox.modify." + toString()); }
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);
}
});
return true;
}
@Override
public boolean addComment(final Plot plot, final 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(final Plot plot, final 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(final 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

@ -24,17 +24,15 @@ import com.intellectualcrafters.plot.object.PlotId;
/**
*/
public class PlotComment
*/
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)
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;

View File

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

View File

@ -1,7 +1,6 @@
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,8 +2,7 @@ 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,7 +1,6 @@
package com.intellectualcrafters.plot.object.entity;
public class HorseStats
{
public class HorseStats {
public double jump;
public boolean chest;
public int variant;

View File

@ -4,8 +4,7 @@ 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),
@ -600,48 +599,46 @@ 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>();
private final int id;
private final byte data;
private final String name;
static
{
for (final 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(final String name, final int id)
{
ItemType(final String name, final int id) {
this.id = id;
data = 0;
this.name = name;
}
ItemType(final String name, final int id, final 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(final String name)
{
public static int getId(final String name) {
final Integer value = ids.get(name);
if (value == null) { return 0; }
if (value == null) {
return 0;
}
return value;
}
public static byte getData(final String name)
{
public static byte getData(final String name) {
final Byte value = datas.get(name);
if (value == null) { return 0; }
if (value == null) {
return 0;
}
return value;
}
}

View File

@ -1,16 +1,14 @@
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(final short x, final short y, final short z, final short[] id, final byte[] data, final 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;