Code cleanup and Optimizations

This commit is contained in:
MattBDev
2016-03-29 00:56:44 -04:00
parent 49d18b9229
commit 32ba55baf5
34 changed files with 456 additions and 540 deletions

View File

@ -539,10 +539,6 @@ public class MemorySection implements ConfigurationSection {
public List<String> getStringList(String path) {
List<?> list = getList(path);
if (list == null) {
return new ArrayList<>(0);
}
List<String> result = new ArrayList<>();
for (Object object : list) {
@ -558,10 +554,6 @@ public class MemorySection implements ConfigurationSection {
public List<Integer> getIntegerList(String path) {
List<?> list = getList(path);
if (list == null) {
return new ArrayList<>(0);
}
List<Integer> result = new ArrayList<>();
for (Object object : list) {
@ -586,10 +578,6 @@ public class MemorySection implements ConfigurationSection {
public List<Boolean> getBooleanList(String path) {
List<?> list = getList(path);
if (list == null) {
return new ArrayList<>(0);
}
List<Boolean> result = new ArrayList<>();
for (Object object : list) {
@ -611,10 +599,6 @@ public class MemorySection implements ConfigurationSection {
public List<Double> getDoubleList(String path) {
List<?> list = getList(path);
if (list == null) {
return new ArrayList<>(0);
}
List<Double> result = new ArrayList<>();
for (Object object : list) {
@ -639,10 +623,6 @@ public class MemorySection implements ConfigurationSection {
public List<Float> getFloatList(String path) {
List<?> list = getList(path);
if (list == null) {
return new ArrayList<>(0);
}
List<Float> result = new ArrayList<>();
for (Object object : list) {
@ -667,10 +647,6 @@ public class MemorySection implements ConfigurationSection {
public List<Long> getLongList(String path) {
List<?> list = getList(path);
if (list == null) {
return new ArrayList<>(0);
}
List<Long> result = new ArrayList<>();
for (Object object : list) {
@ -695,10 +671,6 @@ public class MemorySection implements ConfigurationSection {
public List<Byte> getByteList(String path) {
List<?> list = getList(path);
if (list == null) {
return new ArrayList<>(0);
}
List<Byte> result = new ArrayList<>();
for (Object object : list) {
@ -723,10 +695,6 @@ public class MemorySection implements ConfigurationSection {
public List<Character> getCharacterList(String path) {
List<?> list = getList(path);
if (list == null) {
return new ArrayList<>(0);
}
List<Character> result = new ArrayList<>();
for (Object object : list) {
@ -750,10 +718,6 @@ public class MemorySection implements ConfigurationSection {
public List<Short> getShortList(String path) {
List<?> list = getList(path);
if (list == null) {
return new ArrayList<>(0);
}
List<Short> result = new ArrayList<>();
for (Object object : list) {
@ -779,10 +743,6 @@ public class MemorySection implements ConfigurationSection {
List<?> list = getList(path);
List<Map<?, ?>> result = new ArrayList<>();
if (list == null) {
return result;
}
for (Object object : list) {
if (object instanceof Map) {
result.add((Map<?, ?>) object);

View File

@ -48,7 +48,7 @@ public final class NBTOutputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
public NBTOutputStream(final OutputStream os) {
public NBTOutputStream(OutputStream os) {
this.os = new DataOutputStream(os);
}
@ -59,13 +59,13 @@ public final class NBTOutputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
public void writeTag(final Tag tag) throws IOException {
final int type = NBTUtils.getTypeCode(tag.getClass());
final String name = tag.getName();
final byte[] nameBytes = name.getBytes(NBTConstants.CHARSET);
os.writeByte(type);
os.writeShort(nameBytes.length);
os.write(nameBytes);
public void writeTag(Tag tag) throws IOException {
int type = NBTUtils.getTypeCode(tag.getClass());
String name = tag.getName();
byte[] nameBytes = name.getBytes(NBTConstants.CHARSET);
this.os.writeByte(type);
this.os.writeShort(nameBytes.length);
this.os.write(nameBytes);
if (type == NBTConstants.TYPE_END) {
throw new IOException("Named TAG_End not permitted.");
}
@ -79,8 +79,8 @@ public final class NBTOutputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
private void writeTagPayload(final Tag tag) throws IOException {
final int type = NBTUtils.getTypeCode(tag.getClass());
private void writeTagPayload(Tag tag) throws IOException {
int type = NBTUtils.getTypeCode(tag.getClass());
switch (type) {
case NBTConstants.TYPE_END:
writeEndTagPayload((EndTag) tag);
@ -130,8 +130,8 @@ public final class NBTOutputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
private void writeByteTagPayload(final ByteTag tag) throws IOException {
os.writeByte(tag.getValue());
private void writeByteTagPayload(ByteTag tag) throws IOException {
this.os.writeByte(tag.getValue());
}
/**
@ -141,10 +141,10 @@ public final class NBTOutputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
private void writeByteArrayTagPayload(final ByteArrayTag tag) throws IOException {
final byte[] bytes = tag.getValue();
os.writeInt(bytes.length);
os.write(bytes);
private void writeByteArrayTagPayload(ByteArrayTag tag) throws IOException {
byte[] bytes = tag.getValue();
this.os.writeInt(bytes.length);
this.os.write(bytes);
}
/**
@ -154,11 +154,11 @@ public final class NBTOutputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
private void writeCompoundTagPayload(final CompoundTag tag) throws IOException {
for (final Tag childTag : tag.getValue().values()) {
private void writeCompoundTagPayload(CompoundTag tag) throws IOException {
for (Tag childTag : tag.getValue().values()) {
writeTag(childTag);
}
os.writeByte((byte) 0); // end tag - better way?
this.os.writeByte((byte) 0); // end tag - better way?
}
/**
@ -168,13 +168,13 @@ public final class NBTOutputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
private void writeListTagPayload(final ListTag tag) throws IOException {
final Class<? extends Tag> clazz = tag.getType();
final List<Tag> tags = tag.getValue();
final int size = tags.size();
os.writeByte(NBTUtils.getTypeCode(clazz));
os.writeInt(size);
for (final Tag tag1 : tags) {
private void writeListTagPayload(ListTag tag) throws IOException {
Class<? extends Tag> clazz = tag.getType();
List<Tag> tags = tag.getValue();
int size = tags.size();
this.os.writeByte(NBTUtils.getTypeCode(clazz));
this.os.writeInt(size);
for (Tag tag1 : tags) {
writeTagPayload(tag1);
}
}
@ -186,10 +186,10 @@ public final class NBTOutputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
private void writeStringTagPayload(final StringTag tag) throws IOException {
final byte[] bytes = tag.getValue().getBytes(NBTConstants.CHARSET);
os.writeShort(bytes.length);
os.write(bytes);
private void writeStringTagPayload(StringTag tag) throws IOException {
byte[] bytes = tag.getValue().getBytes(NBTConstants.CHARSET);
this.os.writeShort(bytes.length);
this.os.write(bytes);
}
/**
@ -199,8 +199,8 @@ public final class NBTOutputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
private void writeDoubleTagPayload(final DoubleTag tag) throws IOException {
os.writeDouble(tag.getValue());
private void writeDoubleTagPayload(DoubleTag tag) throws IOException {
this.os.writeDouble(tag.getValue());
}
/**
@ -210,8 +210,8 @@ public final class NBTOutputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
private void writeFloatTagPayload(final FloatTag tag) throws IOException {
os.writeFloat(tag.getValue());
private void writeFloatTagPayload(FloatTag tag) throws IOException {
this.os.writeFloat(tag.getValue());
}
/**
@ -221,8 +221,8 @@ public final class NBTOutputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
private void writeLongTagPayload(final LongTag tag) throws IOException {
os.writeLong(tag.getValue());
private void writeLongTagPayload(LongTag tag) throws IOException {
this.os.writeLong(tag.getValue());
}
/**
@ -232,8 +232,8 @@ public final class NBTOutputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
private void writeIntTagPayload(final IntTag tag) throws IOException {
os.writeInt(tag.getValue());
private void writeIntTagPayload(IntTag tag) throws IOException {
this.os.writeInt(tag.getValue());
}
/**
@ -243,32 +243,30 @@ public final class NBTOutputStream implements Closeable {
*
* @throws IOException if an I/O error occurs.
*/
private void writeShortTagPayload(final ShortTag tag) throws IOException {
os.writeShort(tag.getValue());
private void writeShortTagPayload(ShortTag tag) throws IOException {
this.os.writeShort(tag.getValue());
}
/**
* Writes a <code>TAG_Empty</code> tag.
*
* @param tag The tag.
*
* @throws IOException if an I/O error occurs.
*/
private void writeEndTagPayload(final EndTag tag) {
private void writeEndTagPayload(EndTag tag) {
/* empty */
}
private void writeIntArrayTagPayload(final IntArrayTag tag) throws IOException {
final int[] data = tag.getValue();
os.writeInt(data.length);
for (final int element : data) {
os.writeInt(element);
private void writeIntArrayTagPayload(IntArrayTag tag) throws IOException {
int[] data = tag.getValue();
this.os.writeInt(data.length);
for (int element : data) {
this.os.writeInt(element);
}
}
@Override
public void close() throws IOException {
os.close();
this.os.close();
}
/**
@ -276,6 +274,6 @@ public final class NBTOutputStream implements Closeable {
* @throws IOException
*/
public void flush() throws IOException {
os.flush();
this.os.flush();
}
}

View File

@ -21,7 +21,7 @@ public class JSONML {
*
* @throws JSONException
*/
private static Object parse(final XMLTokener x, final boolean arrayForm, final JSONArray ja) throws JSONException {
private static Object parse(XMLTokener x, boolean arrayForm, JSONArray ja) throws JSONException {
String attribute;
char c;
String closeTag = null;
@ -114,9 +114,6 @@ public class JSONML {
if (token == null) {
token = x.nextToken();
}
if (token == null) {
throw x.syntaxError("Misshaped tag");
}
if (!(token instanceof String)) {
break;
}
@ -195,7 +192,7 @@ public class JSONML {
*
* @throws JSONException
*/
public static JSONArray toJSONArray(final String string) throws JSONException {
public static JSONArray toJSONArray(String string) throws JSONException {
return toJSONArray(new XMLTokener(string));
}
@ -212,7 +209,7 @@ public class JSONML {
*
* @throws JSONException
*/
public static JSONArray toJSONArray(final XMLTokener x) throws JSONException {
public static JSONArray toJSONArray(XMLTokener x) throws JSONException {
return (JSONArray) parse(x, true, null);
}
@ -230,7 +227,7 @@ public class JSONML {
*
* @throws JSONException
*/
public static JSONObject toJSONObject(final XMLTokener x) throws JSONException {
public static JSONObject toJSONObject(XMLTokener x) throws JSONException {
return (JSONObject) parse(x, false, null);
}
@ -248,7 +245,7 @@ public class JSONML {
*
* @throws JSONException
*/
public static JSONObject toJSONObject(final String string) throws JSONException {
public static JSONObject toJSONObject(String string) throws JSONException {
return toJSONObject(new XMLTokener(string));
}
@ -261,14 +258,14 @@ public class JSONML {
*
* @throws JSONException
*/
public static String toString(final JSONArray ja) throws JSONException {
public static String toString(JSONArray ja) throws JSONException {
int i;
JSONObject jo;
String key;
Iterator<String> keys;
int length;
Object object;
final StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder();
String tagName;
String value;
// Emit <tagName
@ -338,8 +335,8 @@ public class JSONML {
*
* @throws JSONException
*/
public static String toString(final JSONObject jo) throws JSONException {
final StringBuilder sb = new StringBuilder();
public static String toString(JSONObject jo) throws JSONException {
StringBuilder sb = new StringBuilder();
int i;
JSONArray ja;
String key;

View File

@ -2324,7 +2324,7 @@ public class PS {
*/
private void setupStyle() {
this.style.set("version", StringMan.join(this.version, "."));
Map<String, Object> o = new HashMap<>();
Map<String, Object> o = new HashMap<>(4);
o.put("color.1", "6");
o.put("color.2", "7");
o.put("color.3", "8");

View File

@ -137,7 +137,7 @@ public class Area extends SubCommand {
}, null);
}
} else {
MainUtil.sendMessage(plr, "An error occured while creating the world: " + area.worldname);
MainUtil.sendMessage(plr, "An error occurred while creating the world: " + area.worldname);
}
}
};
@ -257,7 +257,7 @@ public class Area extends SubCommand {
C.SETUP_FINISHED.send(plr);
plr.teleport(WorldUtil.IMP.getSpawn(world));
} else {
MainUtil.sendMessage(plr, "An error occured while creating the world: " + pa.worldname);
MainUtil.sendMessage(plr, "An error occurred while creating the world: " + pa.worldname);
}
try {
PS.get().config.save(PS.get().configFile);

View File

@ -42,7 +42,7 @@ import java.util.UUID;
aliases = {"owner", "so", "seto"},
category = CommandCategory.CLAIMING,
requiredType = RequiredType.NONE,
confirmation=true)
confirmation = true)
public class Owner extends SetCommand {
@Override

View File

@ -189,8 +189,8 @@ public class SchematicCmd extends SubCommand {
MainUtil.sendMessage(plr, "&cTask is already running.");
return false;
} else {
MainUtil.sendMessage(plr, "&3PlotSquared&8->&3Schemaitc&8: &7Mass export has started. This may take a while.");
MainUtil.sendMessage(plr, "&3PlotSquared&8->&3Schemaitc&8: &7Found &c" + plots.size() + "&7 plots...");
MainUtil.sendMessage(plr, "&3PlotSquared&8->&3Schematic&8: &7Mass export has started. This may take a while.");
MainUtil.sendMessage(plr, "&3PlotSquared&8->&3Schematic&8: &7Found &c" + plots.size() + "&7 plots...");
}
break;
}
@ -204,7 +204,6 @@ public class SchematicCmd extends SubCommand {
MainUtil.sendMessage(plr, "&cTask is already running.");
return false;
}
Plot p2;
Location loc = plr.getLocation();
Plot plot = loc.getPlotAbs();
if (plot == null) {
@ -218,7 +217,7 @@ public class SchematicCmd extends SubCommand {
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
p2 = plot;
Plot p2 = plot;
loc.getWorld();
Collection<Plot> plots = new ArrayList<Plot>();
plots.add(p2);

View File

@ -954,7 +954,7 @@ public class SQLManager implements AbstractDB {
}
/**
* Create a plot
* Create a plot.
*
* @param plot
*/
@ -1038,7 +1038,7 @@ public class SQLManager implements AbstractDB {
}
/**
* Create tables
* Create tables.
*
* @throws SQLException
*/

View File

@ -31,15 +31,16 @@ public class Flag<T> implements Cloneable {
private String name;
/**
* Flag object used to store basic information for a Plot. Flags are a key/value pair. For a flag to be usable by a
* player, you need to register it with PlotSquared.
* Flag object used to store basic information for a Plot. Flags are a
* key/value pair. For a flag to be usable by a player, you need to
* register it with PlotSquared.
*
* @param key AbstractFlag
* @param value Value must be alphanumerical (can have spaces) and be &lt;= 48 characters
*
* @throws IllegalArgumentException if you provide inadequate inputs
*/
public Flag(final AbstractFlag key, final String value) {
public Flag(AbstractFlag key, String value) {
if (!StringMan.isAsciiPrintable(value)) {
throw new IllegalArgumentException("Flag must be ascii");
}
@ -55,8 +56,10 @@ public class Flag<T> implements Cloneable {
/**
* Warning: Unchecked
* @param key
* @param value
*/
public Flag(final AbstractFlag key, final Object value) {
public Flag(AbstractFlag key, Object value) {
this.key = key;
this.value = value;
}
@ -66,53 +69,53 @@ public class Flag<T> implements Cloneable {
}
/**
* Get the AbstractFlag used in creating the flag
* Get the AbstractFlag used in creating the flag.
*
* @return AbstractFlag
*/
public AbstractFlag getAbstractFlag() {
return key;
return this.key;
}
/**
* Get the key for the AbstractFlag
* Get the key for the AbstractFlag.
*
* @return String
*/
public String getKey() {
return key.getKey();
return this.key.getKey();
}
public void setKey(final AbstractFlag key) {
public void setKey(AbstractFlag key) {
this.key = key;
if (value instanceof String) {
value = key.parseValueRaw((String) value);
if (this.value instanceof String) {
this.value = key.parseValueRaw((String) this.value);
}
}
/**
* Get the value
* Get the value.
*
* @return String
*/
public Object getValue() {
return value;
return this.value;
}
public String getValueString() {
return key.toString(value);
return this.key.toString(this.value);
}
@Override
public String toString() {
if ("".equals(value)) {
return key.getKey();
if ("".equals(this.value)) {
return this.key.getKey();
}
return key + ":" + getValueString();
return this.key + ":" + getValueString();
}
@Override
public boolean equals(final Object obj) {
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
@ -122,29 +125,29 @@ public class Flag<T> implements Cloneable {
if (getClass() != obj.getClass()) {
return false;
}
final Flag other = (Flag) obj;
return key.getKey().equals(other.key.getKey()) && value.equals(other.value);
Flag other = (Flag) obj;
return this.key.getKey().equals(other.key.getKey()) && this.value.equals(other.value);
}
@Override
public int hashCode() {
return key.getKey().hashCode();
return this.key.getKey().hashCode();
}
@Override
protected Object clone() {
try {
if (value == null) {
if (this.value == null) {
return super.clone();
}
if (value instanceof Cloneable) {
Method method = value.getClass().getDeclaredMethod("clone");
if (this.value instanceof Cloneable) {
Method method = this.value.getClass().getDeclaredMethod("clone");
if (!method.isAccessible()) {
method.setAccessible(true);
}
return new Flag(key, method.invoke(value));
return new Flag(this.key, method.invoke(this.value));
}
return new Flag(key, key.parseValueRaw(value.toString()));
return new Flag(this.key, this.key.parseValueRaw(this.value.toString()));
} catch (CloneNotSupportedException | IllegalAccessException | IllegalArgumentException | NoSuchMethodException | SecurityException | InvocationTargetException e) {
e.printStackTrace();
}
@ -152,6 +155,6 @@ public class Flag<T> implements Cloneable {
}
public String getName() {
return name;
return this.name;
}
}

View File

@ -367,7 +367,7 @@ public class Plot {
}
/**
* Get a list of owner UUIDs for a plot (supports multi-owner mega-plots)
* Get a list of owner UUIDs for a plot (supports multi-owner mega-plots).
* @return
*/
public HashSet<UUID> getOwners() {
@ -474,7 +474,7 @@ public class Plot {
}
/**
* Get or create plot settings
* Get or create plot settings.
* @return PlotSettings
* @deprecated use equivalent plot method;
*/
@ -487,7 +487,8 @@ public class Plot {
}
/**
* Returns true if the plot is not merged, or it is the base plot of multiple merged plots
* Returns true if the plot is not merged, or it is the base
* plot of multiple merged plots.
* @return
*/
public boolean isBasePlot() {
@ -528,7 +529,7 @@ public class Plot {
}
/**
* Check if the plot is merged in any direction
* Check if the plot is merged in any direction.
* @return
*/
public boolean isMerged() {
@ -603,7 +604,7 @@ public class Plot {
}
/**
* Get the denied users
* Get the denied users.
* @return
*/
public HashSet<UUID> getDenied() {
@ -614,7 +615,7 @@ public class Plot {
}
/**
* Set the denied users for this plot
* Set the denied users for this plot.
* @param uuids
*/
public void setDenied(Set<UUID> uuids) {
@ -633,7 +634,7 @@ public class Plot {
}
/**
* Get the trusted users
* Get the trusted users.
* @return
*/
public HashSet<UUID> getTrusted() {
@ -644,7 +645,7 @@ public class Plot {
}
/**
* Set the trusted users for this plot
* Set the trusted users for this plot.
* @param uuids
*/
public void setTrusted(Set<UUID> uuids) {

View File

@ -294,9 +294,9 @@ public abstract class PlotArea {
}
List<String> flags = config.getStringList("flags.default");
if (flags == null || flags.isEmpty()) {
if (flags.isEmpty()) {
flags = config.getStringList("flags");
if (flags == null || flags.isEmpty()) {
if (flags.isEmpty()) {
flags = new ArrayList<>();
ConfigurationSection section = config.getConfigurationSection("flags");
Set<String> keys = section.getKeys(false);

View File

@ -17,71 +17,72 @@ public class PlotCluster {
private PlotId pos2;
private RegionWrapper region;
public PlotCluster(final PlotArea area, final PlotId pos1, final PlotId pos2, final UUID owner) {
public PlotCluster(PlotArea area, PlotId pos1, PlotId pos2, UUID owner) {
this.area = area;
this.pos1 = pos1;
this.pos2 = pos2;
this.owner = owner;
settings = new PlotSettings();
this.settings = new PlotSettings();
this.temp = -1;
setRegion();
}
public PlotCluster(final PlotArea area, final PlotId pos1, final PlotId pos2, final UUID owner, int temp) {
public PlotCluster(PlotArea area, PlotId pos1, PlotId pos2, UUID owner, int temp) {
this.area = area;
this.pos1 = pos1;
this.pos2 = pos2;
this.owner = owner;
settings = new PlotSettings();
this.settings = new PlotSettings();
this.temp = temp;
setRegion();
}
public PlotId getP1() {
return pos1;
return this.pos1;
}
public void setP1(final PlotId id) {
pos1 = id;
public void setP1(PlotId id) {
this.pos1 = id;
setRegion();
}
public PlotId getP2() {
return pos2;
return this.pos2;
}
public void setP2(final PlotId id) {
pos2 = id;
public void setP2(PlotId id) {
this.pos2 = id;
setRegion();
}
private void setRegion() {
region = new RegionWrapper(pos1.x, pos2.x, pos1.y, pos2.y);
this.region = new RegionWrapper(this.pos1.x, this.pos2.x, this.pos1.y, this.pos2.y);
}
public RegionWrapper getRegion() {
return region;
return this.region;
}
public boolean isAdded(final UUID uuid) {
return owner.equals(uuid) || invited.contains(uuid) || invited.contains(DBFunc.everyone) || helpers.contains(uuid) || helpers
public boolean isAdded(UUID uuid) {
return this.owner.equals(uuid) || this.invited.contains(uuid) || this.invited.contains(DBFunc.everyone) || this.helpers.contains(uuid)
|| this.helpers
.contains(DBFunc.everyone);
}
public boolean hasHelperRights(final UUID uuid) {
return owner.equals(uuid) || helpers.contains(uuid) || helpers.contains(DBFunc.everyone);
public boolean hasHelperRights(UUID uuid) {
return this.owner.equals(uuid) || this.helpers.contains(uuid) || this.helpers.contains(DBFunc.everyone);
}
public String getName() {
return settings.getAlias();
return this.settings.getAlias();
}
/**
* Get the area (in plots)
* Get the area (in plots).
* @return
*/
public int getArea() {
return (1 + pos2.x - pos1.x) * (1 + pos2.y - pos1.y);
return (1 + this.pos2.x - this.pos1.x) * (1 + this.pos2.y - this.pos1.y);
}
public void setArea(PlotArea plotarea) {
@ -94,11 +95,11 @@ public class PlotCluster {
@Override
public int hashCode() {
return pos1.hashCode();
return this.pos1.hashCode();
}
@Override
public boolean equals(final Object obj) {
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
@ -108,31 +109,31 @@ public class PlotCluster {
if (getClass() != obj.getClass()) {
return false;
}
final PlotCluster other = (PlotCluster) obj;
return pos1.equals(other.pos1) && pos2.equals(other.pos2) && area.equals(other.area);
PlotCluster other = (PlotCluster) obj;
return this.pos1.equals(other.pos1) && this.pos2.equals(other.pos2) && this.area.equals(other.area);
}
@Override
public String toString() {
return area + ";" + pos1.x + ";" + pos1.y + ";" + pos2.x + ";" + pos2.y;
return this.area + ";" + this.pos1.x + ";" + this.pos1.y + ";" + this.pos2.x + ";" + this.pos2.y;
}
public Location getHome() {
final BlockLoc home = settings.getPosition();
BlockLoc home = this.settings.getPosition();
Location toReturn;
if (home.y == 0) {
// default pos
final Plot center = getCenterPlot();
Plot center = getCenterPlot();
toReturn = center.getHome();
if (toReturn.getY() == 0) {
final PlotManager manager = area.getPlotManager();
final Location loc = manager.getSignLoc(area, center);
PlotManager manager = this.area.getPlotManager();
Location loc = manager.getSignLoc(this.area, center);
toReturn.setY(loc.getY());
}
} else {
toReturn = getClusterBottom().add(home.x, home.y, home.z);
}
final int max = MainUtil.getHeighestBlock(area.worldname, toReturn.getX(), toReturn.getZ());
int max = MainUtil.getHeighestBlock(this.area.worldname, toReturn.getX(), toReturn.getZ());
if (max > toReturn.getY()) {
toReturn.setY(max);
}
@ -140,30 +141,30 @@ public class PlotCluster {
}
public PlotId getCenterPlotId() {
final PlotId bot = getP1();
final PlotId top = getP2();
PlotId bot = getP1();
PlotId top = getP2();
return new PlotId((bot.x + top.x) / 2, (bot.y + top.y) / 2);
}
public Plot getCenterPlot() {
return area.getPlotAbs(getCenterPlotId());
return this.area.getPlotAbs(getCenterPlotId());
}
public Location getClusterBottom() {
final PlotManager manager = area.getPlotManager();
return manager.getPlotBottomLocAbs(area, getP1());
PlotManager manager = this.area.getPlotManager();
return manager.getPlotBottomLocAbs(this.area, getP1());
}
public Location getClusterTop() {
final PlotManager manager = area.getPlotManager();
return manager.getPlotTopLocAbs(area, getP2());
PlotManager manager = this.area.getPlotManager();
return manager.getPlotTopLocAbs(this.area, getP2());
}
public boolean intersects(PlotId pos1, PlotId pos2) {
return pos1.x <= this.pos2.x && pos2.x >= this.pos1.x && pos1.y <= this.pos2.y && pos2.y >= this.pos1.y;
}
public boolean contains(final PlotId id) {
return pos1.x <= id.x && pos1.y <= id.y && pos2.x >= id.x && pos2.y >= id.y;
public boolean contains(PlotId id) {
return this.pos1.x <= id.x && this.pos1.y <= id.y && this.pos2.x >= id.x && this.pos2.y >= id.y;
}
}

View File

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

View File

@ -599,43 +599,43 @@ 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;
private static final Map<String, Integer> ids = new HashMap<>();
private static final Map<String, Byte> datas = new HashMap<>();
static {
for (final ItemType type : EnumSet.allOf(ItemType.class)) {
for (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) {
private final int id;
private final byte data;
private final String name;
ItemType(String name, int id) {
this.id = id;
data = 0;
this.data = 0;
this.name = name;
}
ItemType(final String name, final int id, final int data) {
ItemType(String name, int id, int data) {
this.id = id;
this.data = (byte) data;
this.name = name;
}
public static int getId(final String name) {
final Integer value = ids.get(name);
public static int getId(String name) {
Integer value = ids.get(name);
if (value == null) {
return 0;
}
return value;
}
public static byte getData(final String name) {
final Byte value = datas.get(name);
public static byte getData(String name) {
Byte value = datas.get(name);
if (value == null) {
return 0;
}

View File

@ -229,17 +229,13 @@ public class MainUtil {
if (MathMan.isInteger(string)) {
return Long.parseLong(string);
}
if (string == null) {
return 0;
}
string = string.toLowerCase().trim().toLowerCase();
if (string.equalsIgnoreCase("false")) {
return 0;
}
String[] split = string.split(" ");
long time = 0;
for (int i = 0; i < split.length; i++) {
String value = split[i];
for (String value : split) {
int nums = Integer.parseInt(value.replaceAll("[^\\d]", ""));
String letters = value.replaceAll("[^a-z]", "");
switch (letters) {

View File

@ -1,58 +1,58 @@
package com.intellectualcrafters.plot.util.helpmenu;
import java.util.List;
import com.intellectualcrafters.plot.commands.CommandCategory;
import com.intellectualcrafters.plot.commands.MainCommand;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.plotsquared.general.commands.Command;
import java.util.List;
public class HelpMenu {
public static final int PER_PAGE = 5;
private final PlotPlayer _player;
private HelpPage _page = new HelpPage(CommandCategory.INFO, 0, 0);
private int _maxPage;
private CommandCategory _commandCategory;
private List<Command> _commands;
public HelpMenu(final PlotPlayer player) {
_player = player;
private final PlotPlayer player;
private HelpPage page = new HelpPage(CommandCategory.INFO, 0, 0);
private int maxPage;
private CommandCategory commandCategory;
private List<Command> commands;
public HelpMenu(PlotPlayer player) {
this.player = player;
}
public HelpMenu setCategory(final CommandCategory commandCategory) {
_commandCategory = commandCategory;
public HelpMenu setCategory(CommandCategory commandCategory) {
this.commandCategory = commandCategory;
return this;
}
public HelpMenu getCommands() {
_commands = MainCommand.getInstance().getCommands(_commandCategory, _player);
this.commands = MainCommand.getInstance().getCommands(this.commandCategory, this.player);
return this;
}
public HelpMenu generateMaxPages() {
_maxPage = Math.max((_commands.size() - 1) / PER_PAGE, 0);
this.maxPage = Math.max((this.commands.size() - 1) / PER_PAGE, 0);
return this;
}
public HelpMenu generatePage(int currentPage, final String label) {
if (currentPage > _maxPage) {
currentPage = _maxPage;
public HelpMenu generatePage(int currentPage, String label) {
if (currentPage > this.maxPage) {
currentPage = this.maxPage;
}
if (currentPage < 0) {
currentPage = 0;
}
_page = new HelpPage(_commandCategory, currentPage, _maxPage);
final int max = Math.min((currentPage * PER_PAGE) + (PER_PAGE - 1), _commands.size());
this.page = new HelpPage(this.commandCategory, currentPage, this.maxPage);
int max = Math.min((currentPage * PER_PAGE) + (PER_PAGE - 1), this.commands.size());
for (int i = currentPage * PER_PAGE; i < max; i++) {
_page.addHelpItem(new HelpObject(_commands.get(i), label));
this.page.addHelpItem(new HelpObject(this.commands.get(i), label));
}
return this;
}
public void render() {
_page.render(_player);
this.page.render(this.player);
}
}

View File

@ -5,29 +5,31 @@ import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.StringMan;
import java.util.ArrayList;
import java.util.List;
public class HelpPage {
private final List<HelpObject> helpObjects;
private final String _header;
private final String header;
public HelpPage(final CommandCategory category, final int currentPage, final int maxPages) {
helpObjects = new ArrayList<>();
_header = C.HELP_PAGE_HEADER.s().replace("%category%", category == null ? "ALL" : category.toString()).replace("%current%", (currentPage + 1) + "").replace("%max%", (maxPages + 1) + "");
public HelpPage(CommandCategory category, int currentPage, int maxPages) {
this.helpObjects = new ArrayList<>();
this.header = C.HELP_PAGE_HEADER.s().replace("%category%", category == null ? "ALL" : category.toString())
.replace("%current%", (currentPage + 1) + "").replace("%max%", (maxPages + 1) + "");
}
public void render(final PlotPlayer player) {
if (helpObjects.size() < 1) {
public void render(PlotPlayer player) {
if (this.helpObjects.size() < 1) {
MainUtil.sendMessage(player, C.NOT_VALID_NUMBER, "(0)");
} else {
String message = C.HELP_HEADER.s() + "\n" + _header + "\n" + StringMan.join(helpObjects, "\n") + "\n" + C.HELP_FOOTER.s();
String message = C.HELP_HEADER.s() + "\n" + this.header + "\n" + StringMan.join(this.helpObjects, "\n") + "\n" + C.HELP_FOOTER.s();
MainUtil.sendMessage(player, message, false);
}
}
public void addHelpItem(final HelpObject object) {
helpObjects.add(object);
public void addHelpItem(HelpObject object) {
this.helpObjects.add(object);
}
}