From 59be72aefe5937fd41ec56e9c2ac88ddabb0f347 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Tue, 16 Dec 2014 16:03:20 +1100 Subject: [PATCH] Weekly code cleanup --- .../jnbt/ByteArrayTag.java | 9 +- .../intellectualcrafters/jnbt/ByteTag.java | 9 +- .../jnbt/CompoundTag.java | 161 +++-- .../jnbt/CompoundTagBuilder.java | 73 ++- .../intellectualcrafters/jnbt/DoubleTag.java | 9 +- .../intellectualcrafters/jnbt/FloatTag.java | 9 +- .../jnbt/IntArrayTag.java | 9 +- .../com/intellectualcrafters/jnbt/IntTag.java | 9 +- .../intellectualcrafters/jnbt/ListTag.java | 177 ++++-- .../jnbt/ListTagBuilder.java | 18 +- .../intellectualcrafters/jnbt/LongTag.java | 9 +- .../jnbt/NBTConstants.java | 8 +- .../jnbt/NBTInputStream.java | 36 +- .../jnbt/NBTOutputStream.java | 86 ++- .../intellectualcrafters/jnbt/NBTUtils.java | 96 ++- .../intellectualcrafters/jnbt/ShortTag.java | 9 +- .../intellectualcrafters/jnbt/StringTag.java | 9 +- .../com/intellectualcrafters/jnbt/Tag.java | 3 +- .../jnbt/WorldEditUtils.java | 18 +- .../com/intellectualcrafters/json/CDL.java | 62 +- .../com/intellectualcrafters/json/Cookie.java | 30 +- .../intellectualcrafters/json/CookieList.java | 6 +- .../com/intellectualcrafters/json/HTTP.java | 36 +- .../json/HTTPTokener.java | 7 +- .../intellectualcrafters/json/JSONArray.java | 331 ++++++---- .../json/JSONException.java | 10 +- .../com/intellectualcrafters/json/JSONML.java | 103 +-- .../intellectualcrafters/json/JSONObject.java | 529 ++++++++++------ .../json/JSONStringer.java | 2 + .../json/JSONTokener.java | 97 +-- .../intellectualcrafters/json/JSONWriter.java | 100 +-- .../com/intellectualcrafters/json/Kim.java | 107 ++-- .../intellectualcrafters/json/Property.java | 6 +- .../com/intellectualcrafters/json/XML.java | 124 ++-- .../intellectualcrafters/json/XMLTokener.java | 59 +- .../intellectualcrafters/plot/PlotMain.java | 447 +++++++------ .../plot/api/PlotAPI.java | 199 +++--- .../plot/commands/Auto.java | 63 +- .../plot/commands/Ban.java | 9 +- .../plot/commands/Claim.java | 17 +- .../plot/commands/Clear.java | 30 +- .../plot/commands/Clipboard.java | 7 +- .../plot/commands/Command.java | 30 +- .../plot/commands/CommandPermission.java | 9 +- .../plot/commands/Comment.java | 14 +- .../plot/commands/Copy.java | 3 +- .../plot/commands/DEOP.java | 9 +- .../plot/commands/Database.java | 103 ++- .../plot/commands/Debug.java | 11 +- .../plot/commands/DebugClaimTest.java | 41 +- .../plot/commands/DebugLoadTest.java | 13 +- .../plot/commands/DebugSaveTest.java | 10 +- .../plot/commands/Delete.java | 11 +- .../plot/commands/Denied.java | 27 +- .../plot/commands/Help.java | 1 - .../plot/commands/Helpers.java | 24 +- .../plot/commands/Home.java | 14 +- .../plot/commands/Inbox.java | 50 +- .../plot/commands/Info.java | 43 +- .../plot/commands/Inventory.java | 4 +- .../plot/commands/Kick.java | 7 +- .../plot/commands/MainCommand.java | 105 +--- .../plot/commands/Merge.java | 24 +- .../plot/commands/MusicSubcommand.java | 11 +- .../plot/commands/OP.java | 9 +- .../plot/commands/Paste.java | 6 +- .../plot/commands/Purge.java | 11 +- .../plot/commands/Rate.java | 13 +- .../plot/commands/Reload.java | 6 +- .../plot/commands/Schematic.java | 61 +- .../plot/commands/Set.java | 54 +- .../plot/commands/SetOwner.java | 34 +- .../plot/commands/Setup.java | 56 +- .../plot/commands/SubCommand.java | 96 +-- .../plot/commands/Swap.java | 8 +- .../plot/commands/TP.java | 19 +- .../plot/commands/Trusted.java | 24 +- .../plot/commands/Unban.java | 9 +- .../plot/commands/Unclaim.java | 9 +- .../plot/commands/Unlink.java | 27 +- .../plot/commands/Visit.java | 14 +- .../plot/commands/list.java | 35 +- .../plot/commands/plugin.java | 22 +- .../intellectualcrafters/plot/config/C.java | 91 ++- .../plot/config/Configuration.java | 76 ++- .../plot/config/ConfigurationNode.java | 16 +- .../plot/config/Settings.java | 67 +- .../plot/database/AbstractDB.java | 158 +++-- .../plot/database/DBFunc.java | 46 +- .../plot/database/Database.java | 37 +- .../plot/database/MySQL.java | 30 +- .../plot/database/PlotMeConverter.java | 89 +-- .../plot/database/SQLManager.java | 437 +++++++------ .../plot/database/SQLite.java | 21 +- .../plot/events/PlayerClaimPlotEvent.java | 17 +- .../plot/events/PlayerEnterPlotEvent.java | 11 +- .../plot/events/PlayerLeavePlotEvent.java | 11 +- .../plot/events/PlayerPlotDeniedEvent.java | 25 +- .../plot/events/PlayerPlotHelperEvent.java | 25 +- .../plot/events/PlayerPlotTrustedEvent.java | 25 +- .../events/PlayerTeleportToPlotEvent.java | 18 +- .../plot/events/PlotClearEvent.java | 15 +- .../plot/events/PlotDeleteEvent.java | 15 +- .../plot/events/PlotFlagAddEvent.java | 17 +- .../plot/events/PlotFlagRemoveEvent.java | 17 +- .../plot/events/PlotMergeEvent.java | 24 +- .../plot/events/PlotUnlinkEvent.java | 17 +- .../plot/flag/AbstractFlag.java | 8 +- .../intellectualcrafters/plot/flag/Flag.java | 15 +- .../plot/flag/FlagManager.java | 33 +- .../plot/flag/FlagValue.java | 16 +- .../plot/generator/DefaultPlotManager.java | 585 +++++++++++------- .../plot/generator/DefaultPlotWorld.java | 61 +- .../plot/generator/WorldGenerator.java | 134 ++-- .../plot/generator/XPopulator.java | 120 ++-- .../plot/listeners/EntityListener.java | 116 ++-- .../plot/listeners/ForceFieldListener.java | 21 +- .../plot/listeners/InventoryListener.java | 9 +- .../plot/listeners/PlayerEvents.java | 244 +++++--- .../plot/listeners/PlotListener.java | 42 +- .../plot/listeners/PlotPlusListener.java | 35 +- .../plot/listeners/WorldEditListener.java | 63 +- .../plot/listeners/WorldGuardListener.java | 59 +- .../plot/object/BlockWrapper.java | 40 +- .../plot/object/InfoInventory.java | 75 +-- .../plot/object/Plot.java | 82 +-- .../plot/object/PlotBlock.java | 6 +- .../plot/object/PlotComment.java | 2 +- .../plot/object/PlotGenerator.java | 3 +- .../plot/object/PlotHomePosition.java | 4 +- .../plot/object/PlotId.java | 46 +- .../plot/object/PlotManager.java | 6 +- .../plot/object/PlotSelection.java | 27 +- .../plot/object/PlotSettings.java | 51 +- .../plot/object/PlotWorld.java | 336 +++++++--- .../plot/object/StringWrapper.java | 6 +- .../plot/object/Title.java | 108 ++-- .../plot/util/LSetCube.java | 4 +- .../intellectualcrafters/plot/util/Lag.java | 12 +- .../plot/util/Logger.java | 17 +- .../plot/util/Metrics.java | 126 ++-- .../intellectualcrafters/plot/util/PWE.java | 28 +- .../plot/util/PlayerFunctions.java | 118 ++-- .../plot/util/PlotHelper.java | 182 +++--- .../plot/util/RUtils.java | 14 +- .../plot/util/ReflectionUtils.java | 175 ++++-- .../plot/util/SchematicHandler.java | 88 ++- .../plot/util/SendChunk.java | 53 +- .../plot/util/SetBlockFast.java | 59 +- .../plot/util/StringComparison.java | 20 +- .../plot/util/UUIDHandler.java | 120 ++-- .../plot/uuid/DefaultUUIDWrapper.java | 18 +- .../plot/uuid/NameFetcher.java | 13 +- .../plot/uuid/OfflineUUIDWrapper.java | 20 +- .../plot/uuid/PlotUUIDSaver.java | 17 +- .../plot/uuid/UUIDFetcher.java | 25 +- .../plot/uuid/UUIDSaver.java | 22 +- .../plot/uuid/UUIDSet.java | 8 +- .../plot/uuid/UUIDWrapper.java | 4 +- .../translation/TranslationAsset.java | 12 +- .../translation/TranslationFile.java | 6 +- .../translation/TranslationLanguage.java | 34 +- .../translation/TranslationManager.java | 125 ++-- .../translation/TranslationObject.java | 30 +- .../translation/YamlTranslationFile.java | 148 ++--- .../translation/bukkit/BukkitTranslation.java | 30 +- .../translation/bukkit/TranslationPlugin.java | 28 +- PlotSquared/src/test/java/Test1.java | 133 ++-- 168 files changed, 5733 insertions(+), 3829 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ByteArrayTag.java b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ByteArrayTag.java index 32cdf131b..1eea41719 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ByteArrayTag.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ByteArrayTag.java @@ -10,7 +10,8 @@ public final class ByteArrayTag extends Tag { /** * Creates the tag with an empty name. * - * @param value the value of the tag + * @param value + * the value of the tag */ public ByteArrayTag(final byte[] value) { super(); @@ -20,8 +21,10 @@ public final class ByteArrayTag extends Tag { /** * Creates the tag. * - * @param name the name of the tag - * @param value the value of the tag + * @param name + * the name of the tag + * @param value + * the value of the tag */ public ByteArrayTag(final String name, final byte[] value) { super(name); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ByteTag.java b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ByteTag.java index 8e2ad5638..15e355dfc 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ByteTag.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ByteTag.java @@ -10,7 +10,8 @@ public final class ByteTag extends Tag { /** * Creates the tag with an empty name. * - * @param value the value of the tag + * @param value + * the value of the tag */ public ByteTag(final byte value) { super(); @@ -20,8 +21,10 @@ public final class ByteTag extends Tag { /** * Creates the tag. * - * @param name the name of the tag - * @param value the value of the tag + * @param name + * the name of the tag + * @param value + * the value of the tag */ public ByteTag(final String name, final byte value) { super(name); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/CompoundTag.java b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/CompoundTag.java index ba608ac70..d4b65590b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/CompoundTag.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/CompoundTag.java @@ -15,7 +15,8 @@ public final class CompoundTag extends Tag { /** * Creates the tag with an empty name. * - * @param value the value of the tag + * @param value + * the value of the tag */ public CompoundTag(final Map value) { super(); @@ -25,8 +26,10 @@ public final class CompoundTag extends Tag { /** * Creates the tag. * - * @param name the name of the tag - * @param value the value of the tag + * @param name + * the name of the tag + * @param value + * the value of the tag */ public CompoundTag(final String name, final Map value) { super(name); @@ -36,7 +39,8 @@ public final class CompoundTag extends Tag { /** * Returns whether this compound tag contains the given key. * - * @param key the given key + * @param key + * the given key * @return true if the tag contains the given key */ public boolean containsKey(final String key) { @@ -51,7 +55,8 @@ public final class CompoundTag extends Tag { /** * Return a new compound tag with the given values. * - * @param value the value + * @param value + * the value * @return the new compound tag */ public CompoundTag setValue(final Map value) { @@ -75,14 +80,16 @@ public final class CompoundTag extends Tag { * empty byte array will be returned. *

* - * @param key the key + * @param key + * the key * @return a byte array */ public byte[] getByteArray(final String key) { final Tag tag = this.value.get(key); if (tag instanceof ByteArrayTag) { return ((ByteArrayTag) tag).getValue(); - } else { + } + else { return new byte[0]; } } @@ -95,14 +102,16 @@ public final class CompoundTag extends Tag { * will be returned. *

* - * @param key the key + * @param key + * the key * @return a byte */ public byte getByte(final String key) { final Tag tag = this.value.get(key); if (tag instanceof ByteTag) { return ((ByteTag) tag).getValue(); - } else { + } + else { return (byte) 0; } } @@ -115,14 +124,16 @@ public final class CompoundTag extends Tag { * {@code 0} will be returned. *

* - * @param key the key + * @param key + * the key * @return a double */ public double getDouble(final String key) { final Tag tag = this.value.get(key); if (tag instanceof DoubleTag) { return ((DoubleTag) tag).getValue(); - } else { + } + else { return 0; } } @@ -136,7 +147,8 @@ public final class CompoundTag extends Tag { * will be returned. *

* - * @param key the key + * @param key + * the key * @return a double */ public double asDouble(final String key) { @@ -144,22 +156,28 @@ public final class CompoundTag extends Tag { if (tag instanceof ByteTag) { return ((ByteTag) tag).getValue(); - } else if (tag instanceof ShortTag) { + } + else if (tag instanceof ShortTag) { return ((ShortTag) tag).getValue(); - } else if (tag instanceof IntTag) { + } + else if (tag instanceof IntTag) { return ((IntTag) tag).getValue(); - } else if (tag instanceof LongTag) { + } + else if (tag instanceof LongTag) { return ((LongTag) tag).getValue(); - } else if (tag instanceof FloatTag) { + } + else if (tag instanceof FloatTag) { return ((FloatTag) tag).getValue(); - } else if (tag instanceof DoubleTag) { + } + else if (tag instanceof DoubleTag) { return ((DoubleTag) tag).getValue(); - } else { + } + else { return 0; } } @@ -172,14 +190,16 @@ public final class CompoundTag extends Tag { * will be returned. *

* - * @param key the key + * @param key + * the key * @return a float */ public float getFloat(final String key) { final Tag tag = this.value.get(key); if (tag instanceof FloatTag) { return ((FloatTag) tag).getValue(); - } else { + } + else { return 0; } } @@ -192,14 +212,16 @@ public final class CompoundTag extends Tag { * empty array will be returned. *

* - * @param key the key + * @param key + * the key * @return an int array */ public int[] getIntArray(final String key) { final Tag tag = this.value.get(key); if (tag instanceof IntArrayTag) { return ((IntArrayTag) tag).getValue(); - } else { + } + else { return new int[0]; } } @@ -212,14 +234,16 @@ public final class CompoundTag extends Tag { * will be returned. *

* - * @param key the key + * @param key + * the key * @return an int */ public int getInt(final String key) { final Tag tag = this.value.get(key); if (tag instanceof IntTag) { return ((IntTag) tag).getValue(); - } else { + } + else { return 0; } } @@ -233,7 +257,8 @@ public final class CompoundTag extends Tag { * will be returned. *

* - * @param key the key + * @param key + * the key * @return an int */ public int asInt(final String key) { @@ -241,22 +266,28 @@ public final class CompoundTag extends Tag { if (tag instanceof ByteTag) { return ((ByteTag) tag).getValue(); - } else if (tag instanceof ShortTag) { + } + else if (tag instanceof ShortTag) { return ((ShortTag) tag).getValue(); - } else if (tag instanceof IntTag) { + } + else if (tag instanceof IntTag) { return ((IntTag) tag).getValue(); - } else if (tag instanceof LongTag) { + } + else if (tag instanceof LongTag) { return ((LongTag) tag).getValue().intValue(); - } else if (tag instanceof FloatTag) { + } + else if (tag instanceof FloatTag) { return ((FloatTag) tag).getValue().intValue(); - } else if (tag instanceof DoubleTag) { + } + else if (tag instanceof DoubleTag) { return ((DoubleTag) tag).getValue().intValue(); - } else { + } + else { return 0; } } @@ -269,14 +300,16 @@ public final class CompoundTag extends Tag { * list will be returned. *

* - * @param key the key + * @param key + * the key * @return a list of tags */ public List getList(final String key) { final Tag tag = this.value.get(key); if (tag instanceof ListTag) { return ((ListTag) tag).getValue(); - } else { + } + else { return Collections.emptyList(); } } @@ -289,15 +322,17 @@ public final class CompoundTag extends Tag { * tag list will be returned. *

* - * @param key the key + * @param key + * the key * @return a tag list instance */ public ListTag getListTag(final String key) { final Tag tag = this.value.get(key); if (tag instanceof ListTag) { return (ListTag) tag; - } else { - return new ListTag(key, StringTag.class, Collections.emptyList()); + } + else { + return new ListTag(key, StringTag.class, Collections. emptyList()); } } @@ -310,9 +345,12 @@ public final class CompoundTag extends Tag { * of a different type, then an empty list will also be returned. *

* - * @param key the key - * @param listType the class of the contained type - * @param the type of list + * @param key + * the key + * @param listType + * the class of the contained type + * @param + * the type of list * @return a list of tags */ @SuppressWarnings("unchecked") @@ -322,10 +360,12 @@ public final class CompoundTag extends Tag { final ListTag listTag = (ListTag) tag; if (listTag.getType().equals(listType)) { return (List) listTag.getValue(); - } else { + } + else { return Collections.emptyList(); } - } else { + } + else { return Collections.emptyList(); } } @@ -338,14 +378,16 @@ public final class CompoundTag extends Tag { * will be returned. *

* - * @param key the key + * @param key + * the key * @return a long */ public long getLong(final String key) { final Tag tag = this.value.get(key); if (tag instanceof LongTag) { return ((LongTag) tag).getValue(); - } else { + } + else { return 0L; } } @@ -359,7 +401,8 @@ public final class CompoundTag extends Tag { * will be returned. *

* - * @param key the key + * @param key + * the key * @return a long */ public long asLong(final String key) { @@ -367,22 +410,28 @@ public final class CompoundTag extends Tag { if (tag instanceof ByteTag) { return ((ByteTag) tag).getValue(); - } else if (tag instanceof ShortTag) { + } + else if (tag instanceof ShortTag) { return ((ShortTag) tag).getValue(); - } else if (tag instanceof IntTag) { + } + else if (tag instanceof IntTag) { return ((IntTag) tag).getValue(); - } else if (tag instanceof LongTag) { + } + else if (tag instanceof LongTag) { return ((LongTag) tag).getValue(); - } else if (tag instanceof FloatTag) { + } + else if (tag instanceof FloatTag) { return ((FloatTag) tag).getValue().longValue(); - } else if (tag instanceof DoubleTag) { + } + else if (tag instanceof DoubleTag) { return ((DoubleTag) tag).getValue().longValue(); - } else { + } + else { return 0L; } } @@ -395,14 +444,16 @@ public final class CompoundTag extends Tag { * will be returned. *

* - * @param key the key + * @param key + * the key * @return a short */ public short getShort(final String key) { final Tag tag = this.value.get(key); if (tag instanceof ShortTag) { return ((ShortTag) tag).getValue(); - } else { + } + else { return 0; } } @@ -415,14 +466,16 @@ public final class CompoundTag extends Tag { * {@code ""} will be returned. *

* - * @param key the key + * @param key + * the key * @return a string */ public String getString(final String key) { final Tag tag = this.value.get(key); if (tag instanceof StringTag) { return ((StringTag) tag).getValue(); - } else { + } + else { return ""; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/CompoundTagBuilder.java b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/CompoundTagBuilder.java index 7371fee14..184984fc0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/CompoundTagBuilder.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/CompoundTagBuilder.java @@ -1,10 +1,10 @@ package com.intellectualcrafters.jnbt; +import static com.google.common.base.Preconditions.checkNotNull; + import java.util.HashMap; import java.util.Map; -import static com.google.common.base.Preconditions.checkNotNull; - /** * Helps create compound tags. */ @@ -22,7 +22,8 @@ public class CompoundTagBuilder { /** * Create a new instance and use the given map (which will be modified). * - * @param value the value + * @param value + * the value */ CompoundTagBuilder(final Map value) { checkNotNull(value); @@ -41,8 +42,10 @@ public class CompoundTagBuilder { /** * Put the given key and tag into the compound tag. * - * @param key they key - * @param value the value + * @param key + * they key + * @param value + * the value * @return this object */ public CompoundTagBuilder put(final String key, final Tag value) { @@ -56,8 +59,10 @@ public class CompoundTagBuilder { * Put the given key and value into the compound tag as a * {@code ByteArrayTag}. * - * @param key they key - * @param value the value + * @param key + * they key + * @param value + * the value * @return this object */ public CompoundTagBuilder putByteArray(final String key, final byte[] value) { @@ -67,8 +72,10 @@ public class CompoundTagBuilder { /** * Put the given key and value into the compound tag as a {@code ByteTag}. * - * @param key they key - * @param value the value + * @param key + * they key + * @param value + * the value * @return this object */ public CompoundTagBuilder putByte(final String key, final byte value) { @@ -78,8 +85,10 @@ public class CompoundTagBuilder { /** * Put the given key and value into the compound tag as a {@code DoubleTag}. * - * @param key they key - * @param value the value + * @param key + * they key + * @param value + * the value * @return this object */ public CompoundTagBuilder putDouble(final String key, final double value) { @@ -89,8 +98,10 @@ public class CompoundTagBuilder { /** * Put the given key and value into the compound tag as a {@code FloatTag}. * - * @param key they key - * @param value the value + * @param key + * they key + * @param value + * the value * @return this object */ public CompoundTagBuilder putFloat(final String key, final float value) { @@ -101,8 +112,10 @@ public class CompoundTagBuilder { * Put the given key and value into the compound tag as a * {@code IntArrayTag}. * - * @param key they key - * @param value the value + * @param key + * they key + * @param value + * the value * @return this object */ public CompoundTagBuilder putIntArray(final String key, final int[] value) { @@ -112,8 +125,10 @@ public class CompoundTagBuilder { /** * Put the given key and value into the compound tag as an {@code IntTag}. * - * @param key they key - * @param value the value + * @param key + * they key + * @param value + * the value * @return this object */ public CompoundTagBuilder putInt(final String key, final int value) { @@ -123,8 +138,10 @@ public class CompoundTagBuilder { /** * Put the given key and value into the compound tag as a {@code LongTag}. * - * @param key they key - * @param value the value + * @param key + * they key + * @param value + * the value * @return this object */ public CompoundTagBuilder putLong(final String key, final long value) { @@ -134,8 +151,10 @@ public class CompoundTagBuilder { /** * Put the given key and value into the compound tag as a {@code ShortTag}. * - * @param key they key - * @param value the value + * @param key + * they key + * @param value + * the value * @return this object */ public CompoundTagBuilder putShort(final String key, final short value) { @@ -145,8 +164,10 @@ public class CompoundTagBuilder { /** * Put the given key and value into the compound tag as a {@code StringTag}. * - * @param key they key - * @param value the value + * @param key + * they key + * @param value + * the value * @return this object */ public CompoundTagBuilder putString(final String key, final String value) { @@ -156,7 +177,8 @@ public class CompoundTagBuilder { /** * Put all the entries from the given map into this map. * - * @param value the map of tags + * @param value + * the map of tags * @return this object */ public CompoundTagBuilder putAll(final Map value) { @@ -179,7 +201,8 @@ public class CompoundTagBuilder { /** * Build a new compound tag with this builder's entries. * - * @param name the name of the tag + * @param name + * the name of the tag * @return the created compound tag */ public CompoundTag build(final String name) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/DoubleTag.java b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/DoubleTag.java index 2a4c52448..0477e54c5 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/DoubleTag.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/DoubleTag.java @@ -10,7 +10,8 @@ public final class DoubleTag extends Tag { /** * Creates the tag with an empty name. * - * @param value the value of the tag + * @param value + * the value of the tag */ public DoubleTag(final double value) { super(); @@ -20,8 +21,10 @@ public final class DoubleTag extends Tag { /** * Creates the tag. * - * @param name the name of the tag - * @param value the value of the tag + * @param name + * the name of the tag + * @param value + * the value of the tag */ public DoubleTag(final String name, final double value) { super(name); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/FloatTag.java b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/FloatTag.java index a9701340a..32dbe86ff 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/FloatTag.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/FloatTag.java @@ -10,7 +10,8 @@ public final class FloatTag extends Tag { /** * Creates the tag with an empty name. * - * @param value the value of the tag + * @param value + * the value of the tag */ public FloatTag(final float value) { super(); @@ -20,8 +21,10 @@ public final class FloatTag extends Tag { /** * Creates the tag. * - * @param name the name of the tag - * @param value the value of the tag + * @param name + * the name of the tag + * @param value + * the value of the tag */ public FloatTag(final String name, final float value) { super(name); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/IntArrayTag.java b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/IntArrayTag.java index 9439f051b..bfca5e264 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/IntArrayTag.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/IntArrayTag.java @@ -12,7 +12,8 @@ public final class IntArrayTag extends Tag { /** * Creates the tag with an empty name. * - * @param value the value of the tag + * @param value + * the value of the tag */ public IntArrayTag(final int[] value) { super(); @@ -23,8 +24,10 @@ public final class IntArrayTag extends Tag { /** * Creates the tag. * - * @param name the name of the tag - * @param value the value of the tag + * @param name + * the name of the tag + * @param value + * the value of the tag */ public IntArrayTag(final String name, final int[] value) { super(name); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/IntTag.java b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/IntTag.java index 7e5328f37..334e347df 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/IntTag.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/IntTag.java @@ -10,7 +10,8 @@ public final class IntTag extends Tag { /** * Creates the tag with an empty name. * - * @param value the value of the tag + * @param value + * the value of the tag */ public IntTag(final int value) { super(); @@ -20,8 +21,10 @@ public final class IntTag extends Tag { /** * Creates the tag. * - * @param name the name of the tag - * @param value the value of the tag + * @param name + * the name of the tag + * @param value + * the value of the tag */ public IntTag(final String name, final int value) { super(name); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ListTag.java b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ListTag.java index 937fd4343..615615ead 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ListTag.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ListTag.java @@ -1,11 +1,12 @@ package com.intellectualcrafters.jnbt; -import javax.annotation.Nullable; +import static com.google.common.base.Preconditions.checkNotNull; + import java.util.Collections; import java.util.List; import java.util.NoSuchElementException; -import static com.google.common.base.Preconditions.checkNotNull; +import javax.annotation.Nullable; /** * The {@code TAG_List} tag. @@ -13,13 +14,15 @@ import static com.google.common.base.Preconditions.checkNotNull; public final class ListTag extends Tag { private final Class type; - private final List value; + private final List value; /** * Creates the tag with an empty name. * - * @param type the type of tag - * @param value the value of the tag + * @param type + * the type of tag + * @param value + * the value of the tag */ public ListTag(final Class type, final List value) { super(); @@ -31,9 +34,12 @@ public final class ListTag extends Tag { /** * Creates the tag. * - * @param name the name of the tag - * @param type the type of tag - * @param value the value of the tag + * @param name + * the name of the tag + * @param type + * the type of tag + * @param value + * the value of the tag */ public ListTag(final String name, final Class type, final List value) { super(name); @@ -59,7 +65,8 @@ public final class ListTag extends Tag { /** * Create a new list tag with this tag's name and type. * - * @param list the new list + * @param list + * the new list * @return a new list tag */ public ListTag setValue(final List list) { @@ -69,14 +76,16 @@ public final class ListTag extends Tag { /** * Get the tag if it exists at the given index. * - * @param index the index + * @param index + * the index * @return the tag or null */ @Nullable public Tag getIfExists(final int index) { try { return this.value.get(index); - } catch (final NoSuchElementException e) { + } + catch (final NoSuchElementException e) { return null; } } @@ -89,14 +98,16 @@ public final class ListTag extends Tag { * empty byte array will be returned. *

* - * @param index the index + * @param index + * the index * @return a byte array */ public byte[] getByteArray(final int index) { final Tag tag = getIfExists(index); if (tag instanceof ByteArrayTag) { return ((ByteArrayTag) tag).getValue(); - } else { + } + else { return new byte[0]; } } @@ -109,14 +120,16 @@ public final class ListTag extends Tag { * {@code 0} will be returned. *

* - * @param index the index + * @param index + * the index * @return a byte */ public byte getByte(final int index) { final Tag tag = getIfExists(index); if (tag instanceof ByteTag) { return ((ByteTag) tag).getValue(); - } else { + } + else { return (byte) 0; } } @@ -129,14 +142,16 @@ public final class ListTag extends Tag { * {@code 0} will be returned. *

* - * @param index the index + * @param index + * the index * @return a double */ public double getDouble(final int index) { final Tag tag = getIfExists(index); if (tag instanceof DoubleTag) { return ((DoubleTag) tag).getValue(); - } else { + } + else { return 0; } } @@ -150,7 +165,8 @@ public final class ListTag extends Tag { * will be returned. *

* - * @param index the index + * @param index + * the index * @return a double */ public double asDouble(final int index) { @@ -158,22 +174,28 @@ public final class ListTag extends Tag { if (tag instanceof ByteTag) { return ((ByteTag) tag).getValue(); - } else if (tag instanceof ShortTag) { + } + else if (tag instanceof ShortTag) { return ((ShortTag) tag).getValue(); - } else if (tag instanceof IntTag) { + } + else if (tag instanceof IntTag) { return ((IntTag) tag).getValue(); - } else if (tag instanceof LongTag) { + } + else if (tag instanceof LongTag) { return ((LongTag) tag).getValue(); - } else if (tag instanceof FloatTag) { + } + else if (tag instanceof FloatTag) { return ((FloatTag) tag).getValue(); - } else if (tag instanceof DoubleTag) { + } + else if (tag instanceof DoubleTag) { return ((DoubleTag) tag).getValue(); - } else { + } + else { return 0; } } @@ -186,14 +208,16 @@ public final class ListTag extends Tag { * {@code 0} will be returned. *

* - * @param index the index + * @param index + * the index * @return a float */ public float getFloat(final int index) { final Tag tag = getIfExists(index); if (tag instanceof FloatTag) { return ((FloatTag) tag).getValue(); - } else { + } + else { return 0; } } @@ -206,14 +230,16 @@ public final class ListTag extends Tag { * empty array will be returned. *

* - * @param index the index + * @param index + * the index * @return an int array */ public int[] getIntArray(final int index) { final Tag tag = getIfExists(index); if (tag instanceof IntArrayTag) { return ((IntArrayTag) tag).getValue(); - } else { + } + else { return new int[0]; } } @@ -226,14 +252,16 @@ public final class ListTag extends Tag { * {@code 0} will be returned. *

* - * @param index the index + * @param index + * the index * @return an int */ public int getInt(final int index) { final Tag tag = getIfExists(index); if (tag instanceof IntTag) { return ((IntTag) tag).getValue(); - } else { + } + else { return 0; } } @@ -247,7 +275,8 @@ public final class ListTag extends Tag { * will be returned. *

* - * @param index the index + * @param index + * the index * @return an int */ public int asInt(final int index) { @@ -255,22 +284,28 @@ public final class ListTag extends Tag { if (tag instanceof ByteTag) { return ((ByteTag) tag).getValue(); - } else if (tag instanceof ShortTag) { + } + else if (tag instanceof ShortTag) { return ((ShortTag) tag).getValue(); - } else if (tag instanceof IntTag) { + } + else if (tag instanceof IntTag) { return ((IntTag) tag).getValue(); - } else if (tag instanceof LongTag) { + } + else if (tag instanceof LongTag) { return ((LongTag) tag).getValue().intValue(); - } else if (tag instanceof FloatTag) { + } + else if (tag instanceof FloatTag) { return ((FloatTag) tag).getValue().intValue(); - } else if (tag instanceof DoubleTag) { + } + else if (tag instanceof DoubleTag) { return ((DoubleTag) tag).getValue().intValue(); - } else { + } + else { return 0; } } @@ -283,14 +318,16 @@ public final class ListTag extends Tag { * list will be returned. *

* - * @param index the index + * @param index + * the index * @return a list of tags */ public List getList(final int index) { final Tag tag = getIfExists(index); if (tag instanceof ListTag) { return ((ListTag) tag).getValue(); - } else { + } + else { return Collections.emptyList(); } } @@ -303,15 +340,17 @@ public final class ListTag extends Tag { * tag list will be returned. *

* - * @param index the index + * @param index + * the index * @return a tag list instance */ public ListTag getListTag(final int index) { final Tag tag = getIfExists(index); if (tag instanceof ListTag) { return (ListTag) tag; - } else { - return new ListTag(StringTag.class, Collections.emptyList()); + } + else { + return new ListTag(StringTag.class, Collections. emptyList()); } } @@ -324,9 +363,12 @@ public final class ListTag extends Tag { * of of a different type, then an empty list will also be returned. *

* - * @param index the index - * @param listType the class of the contained type - * @param the NBT type + * @param index + * the index + * @param listType + * the class of the contained type + * @param + * the NBT type * @return a list of tags */ @SuppressWarnings("unchecked") @@ -336,10 +378,12 @@ public final class ListTag extends Tag { final ListTag listTag = (ListTag) tag; if (listTag.getType().equals(listType)) { return (List) listTag.getValue(); - } else { + } + else { return Collections.emptyList(); } - } else { + } + else { return Collections.emptyList(); } } @@ -352,14 +396,16 @@ public final class ListTag extends Tag { * {@code 0} will be returned. *

* - * @param index the index + * @param index + * the index * @return a long */ public long getLong(final int index) { final Tag tag = getIfExists(index); if (tag instanceof LongTag) { return ((LongTag) tag).getValue(); - } else { + } + else { return 0L; } } @@ -373,7 +419,8 @@ public final class ListTag extends Tag { * will be returned. *

* - * @param index the index + * @param index + * the index * @return a long */ public long asLong(final int index) { @@ -381,22 +428,28 @@ public final class ListTag extends Tag { if (tag instanceof ByteTag) { return ((ByteTag) tag).getValue(); - } else if (tag instanceof ShortTag) { + } + else if (tag instanceof ShortTag) { return ((ShortTag) tag).getValue(); - } else if (tag instanceof IntTag) { + } + else if (tag instanceof IntTag) { return ((IntTag) tag).getValue(); - } else if (tag instanceof LongTag) { + } + else if (tag instanceof LongTag) { return ((LongTag) tag).getValue(); - } else if (tag instanceof FloatTag) { + } + else if (tag instanceof FloatTag) { return ((FloatTag) tag).getValue().longValue(); - } else if (tag instanceof DoubleTag) { + } + else if (tag instanceof DoubleTag) { return ((DoubleTag) tag).getValue().longValue(); - } else { + } + else { return 0; } } @@ -409,14 +462,16 @@ public final class ListTag extends Tag { * {@code 0} will be returned. *

* - * @param index the index + * @param index + * the index * @return a short */ public short getShort(final int index) { final Tag tag = getIfExists(index); if (tag instanceof ShortTag) { return ((ShortTag) tag).getValue(); - } else { + } + else { return 0; } } @@ -429,14 +484,16 @@ public final class ListTag extends Tag { * {@code ""} will be returned. *

* - * @param index the index + * @param index + * the index * @return a string */ public String getString(final int index) { final Tag tag = getIfExists(index); if (tag instanceof StringTag) { return ((StringTag) tag).getValue(); - } else { + } + else { return ""; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ListTagBuilder.java b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ListTagBuilder.java index 972ba655a..530acbe26 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ListTagBuilder.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ListTagBuilder.java @@ -1,24 +1,25 @@ package com.intellectualcrafters.jnbt; +import static com.google.common.base.Preconditions.checkNotNull; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; -import static com.google.common.base.Preconditions.checkNotNull; - /** * Helps create list tags. */ public class ListTagBuilder { private final Class type; - private final List entries; + private final List entries; /** * Create a new instance. * - * @param type of tag contained in this list + * @param type + * of tag contained in this list */ ListTagBuilder(final Class type) { checkNotNull(type); @@ -63,7 +64,8 @@ public class ListTagBuilder { /** * Add the given tag. * - * @param value the tag + * @param value + * the tag * @return this object */ public ListTagBuilder add(final Tag value) { @@ -78,7 +80,8 @@ public class ListTagBuilder { /** * Add all the tags in the given list. * - * @param value a list of tags + * @param value + * a list of tags * @return this object */ public ListTagBuilder addAll(final Collection value) { @@ -101,7 +104,8 @@ public class ListTagBuilder { /** * Build a new list tag with this builder's entries. * - * @param name the name of the tag + * @param name + * the name of the tag * @return the created list tag */ public ListTag build(final String name) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/LongTag.java b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/LongTag.java index a8d22218c..3d1b4f73b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/LongTag.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/LongTag.java @@ -10,7 +10,8 @@ public final class LongTag extends Tag { /** * Creates the tag with an empty name. * - * @param value the value of the tag + * @param value + * the value of the tag */ public LongTag(final long value) { super(); @@ -20,8 +21,10 @@ public final class LongTag extends Tag { /** * Creates the tag. * - * @param name the name of the tag - * @param value the value of the tag + * @param name + * the name of the tag + * @param value + * the value of the tag */ public LongTag(final String name, final long value) { super(name); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTConstants.java b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTConstants.java index caca83753..ab043857c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTConstants.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTConstants.java @@ -30,7 +30,7 @@ public final class NBTConstants { public static final Charset CHARSET = Charset.forName("UTF-8"); - public static final int TYPE_END = 0, TYPE_BYTE = 1, TYPE_SHORT = 2, TYPE_INT = 3, TYPE_LONG = 4, TYPE_FLOAT = 5, TYPE_DOUBLE = 6, TYPE_BYTE_ARRAY = 7, TYPE_STRING = 8, TYPE_LIST = 9, TYPE_COMPOUND = 10, TYPE_INT_ARRAY = 11; + public static final int TYPE_END = 0, TYPE_BYTE = 1, TYPE_SHORT = 2, TYPE_INT = 3, TYPE_LONG = 4, TYPE_FLOAT = 5, TYPE_DOUBLE = 6, TYPE_BYTE_ARRAY = 7, TYPE_STRING = 8, TYPE_LIST = 9, TYPE_COMPOUND = 10, TYPE_INT_ARRAY = 11; /** * Default private constructor. @@ -42,9 +42,11 @@ public final class NBTConstants { /** * Convert a type ID to its corresponding {@link Tag} class. * - * @param id type ID + * @param id + * type ID * @return tag class - * @throws IllegalArgumentException thrown if the tag ID is not valid + * @throws IllegalArgumentException + * thrown if the tag ID is not valid */ public static Class getClassFromType(final int id) { switch (id) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTInputStream.java b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTInputStream.java index 4f0f25fa2..0ad474cbe 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTInputStream.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTInputStream.java @@ -28,8 +28,10 @@ public final class NBTInputStream implements Closeable { * Creates a new {@code NBTInputStream}, which will source its data * from the specified input stream. * - * @param is the input stream - * @throws IOException if an I/O error occurs + * @param is + * the input stream + * @throws IOException + * if an I/O error occurs */ public NBTInputStream(final InputStream is) throws IOException { this.is = new DataInputStream(is); @@ -39,7 +41,8 @@ public final class NBTInputStream implements Closeable { * Reads an NBT tag from the stream. * * @return The tag that was read. - * @throws IOException if an I/O error occurs. + * @throws IOException + * if an I/O error occurs. */ public Tag readTag() throws IOException { return readTag(0); @@ -48,9 +51,11 @@ public final class NBTInputStream implements Closeable { /** * Reads an NBT from the stream. * - * @param depth the depth of this tag + * @param depth + * the depth of this tag * @return The tag that was read. - * @throws IOException if an I/O error occurs. + * @throws IOException + * if an I/O error occurs. */ private Tag readTag(final int depth) throws IOException { final int type = this.is.readByte() & 0xFF; @@ -61,7 +66,8 @@ public final class NBTInputStream implements Closeable { final byte[] nameBytes = new byte[nameLength]; this.is.readFully(nameBytes); name = new String(nameBytes, NBTConstants.CHARSET); - } else { + } + else { name = ""; } @@ -71,18 +77,23 @@ public final class NBTInputStream implements Closeable { /** * Reads the payload of a tag, given the name and type. * - * @param type the type - * @param name the name - * @param depth the depth + * @param type + * the type + * @param name + * the name + * @param depth + * the depth * @return the tag - * @throws IOException if an I/O error occurs. + * @throws IOException + * if an I/O error occurs. */ private Tag readTagPayload(final int type, final String name, final int depth) throws IOException { switch (type) { case NBTConstants.TYPE_END: if (depth == 0) { throw new IOException("TAG_End found without a TAG_Compound/TAG_List tag preceding it."); - } else { + } + else { return new EndTag(); } case NBTConstants.TYPE_BYTE: @@ -127,7 +138,8 @@ public final class NBTInputStream implements Closeable { final Tag tag = readTag(depth + 1); if (tag instanceof EndTag) { break; - } else { + } + else { tagMap.put(tag.getName(), tag); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTOutputStream.java b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTOutputStream.java index e1abcdaba..1506c2a93 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTOutputStream.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTOutputStream.java @@ -52,8 +52,10 @@ public final class NBTOutputStream implements Closeable { * Creates a new NBTOutputStream, which will write data to the * specified underlying output stream. * - * @param os The output stream. - * @throws IOException if an I/O error occurs. + * @param os + * The output stream. + * @throws IOException + * if an I/O error occurs. */ public NBTOutputStream(final OutputStream os) throws IOException { this.os = new DataOutputStream(os); @@ -62,8 +64,10 @@ public final class NBTOutputStream implements Closeable { /** * Writes a tag. * - * @param tag The tag to write. - * @throws IOException if an I/O error occurs. + * @param tag + * The tag to write. + * @throws IOException + * if an I/O error occurs. */ public void writeTag(final Tag tag) throws IOException { final int type = NBTUtils.getTypeCode(tag.getClass()); @@ -84,8 +88,10 @@ public final class NBTOutputStream implements Closeable { /** * Writes tag payload. * - * @param tag The tag. - * @throws IOException if an I/O error occurs. + * @param tag + * The tag. + * @throws IOException + * if an I/O error occurs. */ private void writeTagPayload(final Tag tag) throws IOException { final int type = NBTUtils.getTypeCode(tag.getClass()); @@ -134,8 +140,10 @@ public final class NBTOutputStream implements Closeable { /** * Writes a TAG_Byte tag. * - * @param tag The tag. - * @throws IOException if an I/O error occurs. + * @param tag + * The tag. + * @throws IOException + * if an I/O error occurs. */ private void writeByteTagPayload(final ByteTag tag) throws IOException { this.os.writeByte(tag.getValue()); @@ -144,8 +152,10 @@ public final class NBTOutputStream implements Closeable { /** * Writes a TAG_Byte_Array tag. * - * @param tag The tag. - * @throws IOException if an I/O error occurs. + * @param tag + * The tag. + * @throws IOException + * if an I/O error occurs. */ private void writeByteArrayTagPayload(final ByteArrayTag tag) throws IOException { final byte[] bytes = tag.getValue(); @@ -156,8 +166,10 @@ public final class NBTOutputStream implements Closeable { /** * Writes a TAG_Compound tag. * - * @param tag The tag. - * @throws IOException if an I/O error occurs. + * @param tag + * The tag. + * @throws IOException + * if an I/O error occurs. */ private void writeCompoundTagPayload(final CompoundTag tag) throws IOException { for (final Tag childTag : tag.getValue().values()) { @@ -169,8 +181,10 @@ public final class NBTOutputStream implements Closeable { /** * Writes a TAG_List tag. * - * @param tag The tag. - * @throws IOException if an I/O error occurs. + * @param tag + * The tag. + * @throws IOException + * if an I/O error occurs. */ private void writeListTagPayload(final ListTag tag) throws IOException { final Class clazz = tag.getType(); @@ -179,7 +193,7 @@ public final class NBTOutputStream implements Closeable { this.os.writeByte(NBTUtils.getTypeCode(clazz)); this.os.writeInt(size); - for (Tag tag1 : tags) { + for (final Tag tag1 : tags) { writeTagPayload(tag1); } } @@ -187,8 +201,10 @@ public final class NBTOutputStream implements Closeable { /** * Writes a TAG_String tag. * - * @param tag The tag. - * @throws IOException if an I/O error occurs. + * @param tag + * The tag. + * @throws IOException + * if an I/O error occurs. */ private void writeStringTagPayload(final StringTag tag) throws IOException { final byte[] bytes = tag.getValue().getBytes(NBTConstants.CHARSET); @@ -199,8 +215,10 @@ public final class NBTOutputStream implements Closeable { /** * Writes a TAG_Double tag. * - * @param tag The tag. - * @throws IOException if an I/O error occurs. + * @param tag + * The tag. + * @throws IOException + * if an I/O error occurs. */ private void writeDoubleTagPayload(final DoubleTag tag) throws IOException { this.os.writeDouble(tag.getValue()); @@ -209,8 +227,10 @@ public final class NBTOutputStream implements Closeable { /** * Writes a TAG_Float tag. * - * @param tag The tag. - * @throws IOException if an I/O error occurs. + * @param tag + * The tag. + * @throws IOException + * if an I/O error occurs. */ private void writeFloatTagPayload(final FloatTag tag) throws IOException { this.os.writeFloat(tag.getValue()); @@ -219,8 +239,10 @@ public final class NBTOutputStream implements Closeable { /** * Writes a TAG_Long tag. * - * @param tag The tag. - * @throws IOException if an I/O error occurs. + * @param tag + * The tag. + * @throws IOException + * if an I/O error occurs. */ private void writeLongTagPayload(final LongTag tag) throws IOException { this.os.writeLong(tag.getValue()); @@ -229,8 +251,10 @@ public final class NBTOutputStream implements Closeable { /** * Writes a TAG_Int tag. * - * @param tag The tag. - * @throws IOException if an I/O error occurs. + * @param tag + * The tag. + * @throws IOException + * if an I/O error occurs. */ private void writeIntTagPayload(final IntTag tag) throws IOException { this.os.writeInt(tag.getValue()); @@ -239,8 +263,10 @@ public final class NBTOutputStream implements Closeable { /** * Writes a TAG_Short tag. * - * @param tag The tag. - * @throws IOException if an I/O error occurs. + * @param tag + * The tag. + * @throws IOException + * if an I/O error occurs. */ private void writeShortTagPayload(final ShortTag tag) throws IOException { this.os.writeShort(tag.getValue()); @@ -249,8 +275,10 @@ public final class NBTOutputStream implements Closeable { /** * Writes a TAG_Empty tag. * - * @param tag The tag. - * @throws IOException if an I/O error occurs. + * @param tag + * The tag. + * @throws IOException + * if an I/O error occurs. */ private void writeEndTagPayload(final EndTag tag) { /* empty */ diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTUtils.java b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTUtils.java index d7251787f..44a014c20 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTUtils.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTUtils.java @@ -16,35 +16,48 @@ public final class NBTUtils { /** * Gets the type name of a tag. * - * @param clazz the tag class + * @param clazz + * the tag class * @return The type name. */ public static String getTypeName(final Class clazz) { if (clazz.equals(ByteArrayTag.class)) { return "TAG_Byte_Array"; - } else if (clazz.equals(ByteTag.class)) { + } + else if (clazz.equals(ByteTag.class)) { return "TAG_Byte"; - } else if (clazz.equals(CompoundTag.class)) { + } + else if (clazz.equals(CompoundTag.class)) { return "TAG_Compound"; - } else if (clazz.equals(DoubleTag.class)) { + } + else if (clazz.equals(DoubleTag.class)) { return "TAG_Double"; - } else if (clazz.equals(EndTag.class)) { + } + else if (clazz.equals(EndTag.class)) { return "TAG_End"; - } else if (clazz.equals(FloatTag.class)) { + } + else if (clazz.equals(FloatTag.class)) { return "TAG_Float"; - } else if (clazz.equals(IntTag.class)) { + } + else if (clazz.equals(IntTag.class)) { return "TAG_Int"; - } else if (clazz.equals(ListTag.class)) { + } + else if (clazz.equals(ListTag.class)) { return "TAG_List"; - } else if (clazz.equals(LongTag.class)) { + } + else if (clazz.equals(LongTag.class)) { return "TAG_Long"; - } else if (clazz.equals(ShortTag.class)) { + } + else if (clazz.equals(ShortTag.class)) { return "TAG_Short"; - } else if (clazz.equals(StringTag.class)) { + } + else if (clazz.equals(StringTag.class)) { return "TAG_String"; - } else if (clazz.equals(IntArrayTag.class)) { + } + else if (clazz.equals(IntArrayTag.class)) { return "TAG_Int_Array"; - } else { + } + else { throw new IllegalArgumentException("Invalid tag classs (" + clazz.getName() + ")."); } } @@ -52,36 +65,50 @@ public final class NBTUtils { /** * Gets the type code of a tag class. * - * @param clazz the tag class + * @param clazz + * the tag class * @return The type code. - * @throws IllegalArgumentException if the tag class is invalid. + * @throws IllegalArgumentException + * if the tag class is invalid. */ public static int getTypeCode(final Class clazz) { if (clazz.equals(ByteArrayTag.class)) { return NBTConstants.TYPE_BYTE_ARRAY; - } else if (clazz.equals(ByteTag.class)) { + } + else if (clazz.equals(ByteTag.class)) { return NBTConstants.TYPE_BYTE; - } else if (clazz.equals(CompoundTag.class)) { + } + else if (clazz.equals(CompoundTag.class)) { return NBTConstants.TYPE_COMPOUND; - } else if (clazz.equals(DoubleTag.class)) { + } + else if (clazz.equals(DoubleTag.class)) { return NBTConstants.TYPE_DOUBLE; - } else if (clazz.equals(EndTag.class)) { + } + else if (clazz.equals(EndTag.class)) { return NBTConstants.TYPE_END; - } else if (clazz.equals(FloatTag.class)) { + } + else if (clazz.equals(FloatTag.class)) { return NBTConstants.TYPE_FLOAT; - } else if (clazz.equals(IntTag.class)) { + } + else if (clazz.equals(IntTag.class)) { return NBTConstants.TYPE_INT; - } else if (clazz.equals(ListTag.class)) { + } + else if (clazz.equals(ListTag.class)) { return NBTConstants.TYPE_LIST; - } else if (clazz.equals(LongTag.class)) { + } + else if (clazz.equals(LongTag.class)) { return NBTConstants.TYPE_LONG; - } else if (clazz.equals(ShortTag.class)) { + } + else if (clazz.equals(ShortTag.class)) { return NBTConstants.TYPE_SHORT; - } else if (clazz.equals(StringTag.class)) { + } + else if (clazz.equals(StringTag.class)) { return NBTConstants.TYPE_STRING; - } else if (clazz.equals(IntArrayTag.class)) { + } + else if (clazz.equals(IntArrayTag.class)) { return NBTConstants.TYPE_INT_ARRAY; - } else { + } + else { throw new IllegalArgumentException("Invalid tag classs (" + clazz.getName() + ")."); } } @@ -89,9 +116,11 @@ public final class NBTUtils { /** * Gets the class of a type of tag. * - * @param type the type + * @param type + * the type * @return The class. - * @throws IllegalArgumentException if the tag type is invalid. + * @throws IllegalArgumentException + * if the tag type is invalid. */ public static Class getTypeClass(final int type) { switch (type) { @@ -127,9 +156,12 @@ public final class NBTUtils { /** * Get child tag of a NBT structure. * - * @param items the map to read from - * @param key the key to look for - * @param expected the expected NBT class type + * @param items + * the map to read from + * @param key + * the key to look for + * @param expected + * the expected NBT class type * @return child tag */ public static T getChildTag(final Map items, final String key, final Class expected) throws IllegalArgumentException { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ShortTag.java b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ShortTag.java index b4fb7e2a8..c2976b6ff 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ShortTag.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ShortTag.java @@ -31,7 +31,8 @@ public final class ShortTag extends Tag { /** * Creates the tag with an empty name. * - * @param value the value of the tag + * @param value + * the value of the tag */ public ShortTag(final short value) { super(); @@ -41,8 +42,10 @@ public final class ShortTag extends Tag { /** * Creates the tag. * - * @param name the name of the tag - * @param value the value of the tag + * @param name + * the name of the tag + * @param value + * the value of the tag */ public ShortTag(final String name, final short value) { super(name); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/StringTag.java b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/StringTag.java index 708331cec..05069471a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/StringTag.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/StringTag.java @@ -12,7 +12,8 @@ public final class StringTag extends Tag { /** * Creates the tag with an empty name. * - * @param value the value of the tag + * @param value + * the value of the tag */ public StringTag(final String value) { super(); @@ -23,8 +24,10 @@ public final class StringTag extends Tag { /** * Creates the tag. * - * @param name the name of the tag - * @param value the value of the tag + * @param name + * the name of the tag + * @param value + * the value of the tag */ public StringTag(final String name, final String value) { super(name); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/Tag.java b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/Tag.java index aa060c18e..af13d6249 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/Tag.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/Tag.java @@ -38,7 +38,8 @@ public abstract class Tag { /** * Creates the tag with the specified name. * - * @param name the name + * @param name + * the name */ Tag(String name) { if (name == null) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/WorldEditUtils.java b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/WorldEditUtils.java index 29d646ee4..30123a5ac 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/WorldEditUtils.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/WorldEditUtils.java @@ -5,17 +5,17 @@ import org.bukkit.World; public class WorldEditUtils { public static void setNBT(final World world, final short id, final byte data, final int x, final int y, final int z, final com.intellectualcrafters.jnbt.CompoundTag tag) { -// final LocalWorld bukkitWorld = BukkitUtil.getLocalWorld(world); + // final LocalWorld bukkitWorld = BukkitUtil.getLocalWorld(world); // I need to somehow convert our CompoundTag to WorldEdit's -// final BaseBlock block = new BaseBlock(5, 5, (CompoundTag) tag); -// final Vector vector = new Vector(x, y, z); -// try { -// bukkitWorld.setBlock(vector, block); -// } -// catch (final WorldEditException e) { -// e.printStackTrace(); -// } + // final BaseBlock block = new BaseBlock(5, 5, (CompoundTag) tag); + // final Vector vector = new Vector(x, y, z); + // try { + // bukkitWorld.setBlock(vector, block); + // } + // catch (final WorldEditException e) { + // e.printStackTrace(); + // } } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/json/CDL.java b/PlotSquared/src/main/java/com/intellectualcrafters/json/CDL.java index c0c822279..da59e4763 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/json/CDL.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/json/CDL.java @@ -26,9 +26,11 @@ public class CDL { * Get the next value. The value can be wrapped in quotes. The value can * be empty. * - * @param x A JSONTokener of the source text. + * @param x + * A JSONTokener of the source text. * @return The value string, or null if empty. - * @throws JSONException if the quoted string is badly formed. + * @throws JSONException + * if the quoted string is badly formed. */ private static String getValue(final JSONTokener x) throws JSONException { char c; @@ -45,7 +47,7 @@ public class CDL { case '\'': q = c; sb = new StringBuffer(); - for (; ; ) { + for (;;) { c = x.next(); if (c == q) { break; @@ -68,20 +70,21 @@ public class CDL { /** * Produce a JSONArray of strings from a row of comma delimited values. * - * @param x A JSONTokener of the source text. + * @param x + * A JSONTokener of the source text. * @return A JSONArray of strings. * @throws JSONException */ public static JSONArray rowToJSONArray(final JSONTokener x) throws JSONException { final JSONArray ja = new JSONArray(); - for (; ; ) { + for (;;) { final String value = getValue(x); char c = x.next(); if ((value == null) || ((ja.length() == 0) && (value.length() == 0) && (c != ','))) { return null; } ja.put(value); - for (; ; ) { + for (;;) { if (c == ',') { break; } @@ -100,11 +103,13 @@ public class CDL { * Produce a JSONObject from a row of comma delimited text, using a * parallel JSONArray of strings to provides the names of the elements. * - * @param names A JSONArray of names. This is commonly obtained from the - * first row of a comma delimited text file using the - * rowToJSONArray - * method. - * @param x A JSONTokener of the source text. + * @param names + * A JSONArray of names. This is commonly obtained from the + * first row of a comma delimited text file using the + * rowToJSONArray + * method. + * @param x + * A JSONTokener of the source text. * @return A JSONObject combining the names and values. * @throws JSONException */ @@ -118,7 +123,8 @@ public class CDL { * the comma character will be quoted. Troublesome characters may be * removed. * - * @param ja A JSONArray of strings. + * @param ja + * A JSONArray of strings. * @return A string ending in NEWLINE. */ public static String rowToString(final JSONArray ja) { @@ -140,7 +146,8 @@ public class CDL { } } sb.append('"'); - } else { + } + else { sb.append(string); } } @@ -153,7 +160,8 @@ public class CDL { * Produce a JSONArray of JSONObjects from a comma delimited text string, * using the first row as a source of names. * - * @param string The comma delimited text. + * @param string + * The comma delimited text. * @return A JSONArray of JSONObjects. * @throws JSONException */ @@ -165,7 +173,8 @@ public class CDL { * Produce a JSONArray of JSONObjects from a comma delimited text string, * using the first row as a source of names. * - * @param x The JSONTokener containing the comma delimited text. + * @param x + * The JSONTokener containing the comma delimited text. * @return A JSONArray of JSONObjects. * @throws JSONException */ @@ -177,8 +186,10 @@ public class CDL { * Produce a JSONArray of JSONObjects from a comma delimited text string * using a supplied JSONArray as the source of element names. * - * @param names A JSONArray of strings. - * @param string The comma delimited text. + * @param names + * A JSONArray of strings. + * @param string + * The comma delimited text. * @return A JSONArray of JSONObjects. * @throws JSONException */ @@ -190,8 +201,10 @@ public class CDL { * Produce a JSONArray of JSONObjects from a comma delimited text string * using a supplied JSONArray as the source of element names. * - * @param names A JSONArray of strings. - * @param x A JSONTokener of the source text. + * @param names + * A JSONArray of strings. + * @param x + * A JSONTokener of the source text. * @return A JSONArray of JSONObjects. * @throws JSONException */ @@ -200,7 +213,7 @@ public class CDL { return null; } final JSONArray ja = new JSONArray(); - for (; ; ) { + for (;;) { final JSONObject jo = rowToJSONObject(names, x); if (jo == null) { break; @@ -218,7 +231,8 @@ public class CDL { * first row will be a list of names obtained by inspecting the first * JSONObject. * - * @param ja A JSONArray of JSONObjects. + * @param ja + * A JSONArray of JSONObjects. * @return A comma delimited text. * @throws JSONException */ @@ -238,8 +252,10 @@ public class CDL { * a provided list of names. The list of names is not included in the * output. * - * @param names A JSONArray of strings. - * @param ja A JSONArray of JSONObjects. + * @param names + * A JSONArray of strings. + * @param ja + * A JSONArray of JSONObjects. * @return A comma delimited text. * @throws JSONException */ diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/json/Cookie.java b/PlotSquared/src/main/java/com/intellectualcrafters/json/Cookie.java index efadf91cd..8bfa065fe 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/json/Cookie.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/json/Cookie.java @@ -40,7 +40,8 @@ public class Cookie { * encoded values. We encode '=' and ';' because we must. We encode '%' and * '+' because they are meta characters in URL encoding. * - * @param string The source string. + * @param string + * The source string. * @return The escaped result. */ public static String escape(final String string) { @@ -54,7 +55,8 @@ public class Cookie { sb.append('%'); sb.append(Character.forDigit((char) ((c >>> 4) & 0x0f), 16)); sb.append(Character.forDigit((char) (c & 0x0f), 16)); - } else { + } + else { sb.append(c); } } @@ -72,9 +74,10 @@ public class Cookie { * validation of the parameters. It only converts the cookie string into * a JSONObject. * - * @param string The cookie specification string. + * @param string + * The cookie specification string. * @return A JSONObject containing "name", "value", and possibly other - * members. + * members. * @throws JSONException */ public static JSONObject toJSONObject(final String string) throws JSONException { @@ -91,10 +94,12 @@ public class Cookie { if (x.next() != '=') { if (name.equals("secure")) { value = Boolean.TRUE; - } else { + } + else { throw x.syntaxError("Missing '=' in cookie parameter."); } - } else { + } + else { value = unescape(x.nextTo(';')); x.next(); } @@ -110,7 +115,8 @@ public class Cookie { * members, they will be appended to the cookie specification string. * All other members are ignored. * - * @param jo A JSONObject + * @param jo + * A JSONObject * @return A cookie specification string * @throws JSONException */ @@ -142,9 +148,10 @@ public class Cookie { * Convert %hh sequences to single characters, and * convert plus to space. * - * @param string A string that may contain + - *  (plus) and %hh - * sequences. + * @param string + * A string that may contain + + *  (plus) and %hh + * sequences. * @return The unescaped string. */ public static String unescape(final String string) { @@ -154,7 +161,8 @@ public class Cookie { char c = string.charAt(i); if (c == '+') { c = ' '; - } else if ((c == '%') && ((i + 2) < length)) { + } + else if ((c == '%') && ((i + 2) < length)) { final int d = JSONTokener.dehexchar(string.charAt(i + 1)); final int e = JSONTokener.dehexchar(string.charAt(i + 2)); if ((d >= 0) && (e >= 0)) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/json/CookieList.java b/PlotSquared/src/main/java/com/intellectualcrafters/json/CookieList.java index 1d4a2f59d..9bebbf660 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/json/CookieList.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/json/CookieList.java @@ -20,7 +20,8 @@ public class CookieList { * cookielistJSONObject.put(cookieJSONObject.getString("name"), * cookieJSONObject.getString("value")); * - * @param string A cookie list string + * @param string + * A cookie list string * @return A JSONObject * @throws JSONException */ @@ -42,7 +43,8 @@ public class CookieList { * The pairs are separated by ';'. The characters '%', '+', '=', and ';' * in the names and values are replaced by "%hh". * - * @param jo A JSONObject + * @param jo + * A JSONObject * @return A cookie list string * @throws JSONException */ diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/json/HTTP.java b/PlotSquared/src/main/java/com/intellectualcrafters/json/HTTP.java index e3917c281..cbab17d8b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/json/HTTP.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/json/HTTP.java @@ -40,6 +40,7 @@ public class HTTP { * Convert an HTTP header string into a JSONObject. It can be a request * header or a response header. A request header will contain *

+ * *

      * {
      *    Method: "POST" (for example),
@@ -50,6 +51,7 @@ public class HTTP {
      * 

* A response header will contain *

+ * *

      * {
      *    "HTTP-Version": "HTTP/1.1" (for example),
@@ -61,6 +63,7 @@ public class HTTP {
      * In addition, the other parameters in the header will be captured, using
      * the HTTP field names as JSON names, so that
      * 

+ * *

      *    Date: Sun, 26 May 2002 18:06:04 GMT
      *    Cookie: Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s
@@ -69,6 +72,7 @@ public class HTTP {
      * 

* become *

+ * *

      * {...
      *    Date: "Sun, 26 May 2002 18:06:04 GMT",
@@ -77,12 +81,13 @@ public class HTTP {
      * ...}
      * 
*

- * It does no further checking or conversion. It does not parse dates. - * It does not do '%' transforms on URLs. + * It does no further checking or conversion. It does not parse dates. It + * does not do '%' transforms on URLs. * - * @param string An HTTP header string. + * @param string + * An HTTP header string. * @return A JSONObject containing the elements and attributes - * of the XML string. + * of the XML string. * @throws JSONException */ public static JSONObject toJSONObject(final String string) throws JSONException { @@ -100,7 +105,8 @@ public class HTTP { jo.put("Reason-Phrase", x.nextTo('\0')); x.next(); - } else { + } + else { // Request @@ -123,6 +129,7 @@ public class HTTP { /** * Convert a JSONObject into an HTTP header. A request header must contain *

+ * *

      * {
      *    Method: "POST" (for example),
@@ -133,6 +140,7 @@ public class HTTP {
      * 

* A response header must contain *

+ * *

      * {
      *    "HTTP-Version": "HTTP/1.1" (for example),
@@ -141,13 +149,15 @@ public class HTTP {
      * }
      * 
*

- * Any other members of the JSONObject will be output as HTTP fields. - * The result will end with two CRLF pairs. + * Any other members of the JSONObject will be output as HTTP fields. The + * result will end with two CRLF pairs. * - * @param jo A JSONObject + * @param jo + * A JSONObject * @return An HTTP header string. - * @throws JSONException if the object does not contain enough - * information. + * @throws JSONException + * if the object does not contain enough + * information. */ public static String toString(final JSONObject jo) throws JSONException { final Iterator keys = jo.keys(); @@ -159,7 +169,8 @@ public class HTTP { sb.append(jo.getString("Status-Code")); sb.append(' '); sb.append(jo.getString("Reason-Phrase")); - } else if (jo.has("Method") && jo.has("Request-URI")) { + } + else if (jo.has("Method") && jo.has("Request-URI")) { sb.append(jo.getString("Method")); sb.append(' '); sb.append('"'); @@ -167,7 +178,8 @@ public class HTTP { sb.append('"'); sb.append(' '); sb.append(jo.getString("HTTP-Version")); - } else { + } + else { throw new JSONException("Not enough material for an HTTP header."); } sb.append(CRLF); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/json/HTTPTokener.java b/PlotSquared/src/main/java/com/intellectualcrafters/json/HTTPTokener.java index 1e2d6fa79..85039fb6a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/json/HTTPTokener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/json/HTTPTokener.java @@ -12,7 +12,8 @@ public class HTTPTokener extends JSONTokener { /** * Construct an HTTPTokener from a string. * - * @param string A source string. + * @param string + * A source string. */ public HTTPTokener(final String string) { super(string); @@ -34,7 +35,7 @@ public class HTTPTokener extends JSONTokener { while (Character.isWhitespace(c)); if ((c == '"') || (c == '\'')) { q = c; - for (; ; ) { + for (;;) { c = next(); if (c < ' ') { throw syntaxError("Unterminated string."); @@ -45,7 +46,7 @@ public class HTTPTokener extends JSONTokener { sb.append(c); } } - for (; ; ) { + for (;;) { if ((c == 0) || Character.isWhitespace(c)) { return sb.toString(); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONArray.java b/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONArray.java index cad77b24c..94f91f072 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONArray.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONArray.java @@ -90,8 +90,10 @@ public class JSONArray { /** * Construct a JSONArray from a JSONTokener. * - * @param x A JSONTokener - * @throws JSONException If there is a syntax error. + * @param x + * A JSONTokener + * @throws JSONException + * If there is a syntax error. */ public JSONArray(final JSONTokener x) throws JSONException { this(); @@ -100,11 +102,12 @@ public class JSONArray { } if (x.nextClean() != ']') { x.back(); - for (; ; ) { + for (;;) { if (x.nextClean() == ',') { x.back(); this.myArrayList.add(JSONObject.NULL); - } else { + } + else { x.back(); this.myArrayList.add(x.nextValue()); } @@ -127,10 +130,12 @@ public class JSONArray { /** * Construct a JSONArray from a source JSON text. * - * @param source A string that begins with [ (left - * bracket) and ends with ] - *  (right bracket). - * @throws JSONException If there is a syntax error. + * @param source + * A string that begins with [ (left + * bracket) and ends with ] + *  (right bracket). + * @throws JSONException + * If there is a syntax error. */ public JSONArray(final String source) throws JSONException { this(new JSONTokener(source)); @@ -139,12 +144,13 @@ public class JSONArray { /** * Construct a JSONArray from a Collection. * - * @param collection A Collection. + * @param collection + * A Collection. */ public JSONArray(final Collection collection) { this.myArrayList = new ArrayList(); if (collection != null) { - for (Object aCollection : collection) { + for (final Object aCollection : collection) { this.myArrayList.add(JSONObject.wrap(aCollection)); } } @@ -153,7 +159,8 @@ public class JSONArray { /** * Construct a JSONArray from an array * - * @throws JSONException If not an array. + * @throws JSONException + * If not an array. */ public JSONArray(final Object array) throws JSONException { this(); @@ -162,7 +169,8 @@ public class JSONArray { for (int i = 0; i < length; i += 1) { this.put(JSONObject.wrap(Array.get(array, i))); } - } else { + } + else { throw new JSONException("JSONArray initial value should be a string or collection or array."); } } @@ -170,9 +178,11 @@ public class JSONArray { /** * Get the object value associated with an index. * - * @param index The index must be between 0 and length() - 1. + * @param index + * The index must be between 0 and length() - 1. * @return An object value. - * @throws JSONException If there is no value for the index. + * @throws JSONException + * If there is no value for the index. */ public Object get(final int index) throws JSONException { final Object object = this.opt(index); @@ -186,16 +196,19 @@ public class JSONArray { * Get the boolean value associated with an index. The string values "true" * and "false" are converted to boolean. * - * @param index The index must be between 0 and length() - 1. + * @param index + * The index must be between 0 and length() - 1. * @return The truth. - * @throws JSONException If there is no value for the index or if the value is not - * convertible to boolean. + * @throws JSONException + * If there is no value for the index or if the value is not + * convertible to boolean. */ public boolean getBoolean(final int index) throws JSONException { final Object object = this.get(index); if (object.equals(Boolean.FALSE) || ((object instanceof String) && ((String) object).equalsIgnoreCase("false"))) { return false; - } else if (object.equals(Boolean.TRUE) || ((object instanceof String) && ((String) object).equalsIgnoreCase("true"))) { + } + else if (object.equals(Boolean.TRUE) || ((object instanceof String) && ((String) object).equalsIgnoreCase("true"))) { return true; } throw new JSONException("JSONArray[" + index + "] is not a boolean."); @@ -204,16 +217,19 @@ public class JSONArray { /** * Get the double value associated with an index. * - * @param index The index must be between 0 and length() - 1. + * @param index + * The index must be between 0 and length() - 1. * @return The value. - * @throws JSONException If the key is not found or if the value cannot be converted - * to a number. + * @throws JSONException + * If the key is not found or if the value cannot be converted + * to a number. */ public double getDouble(final int index) throws JSONException { final Object object = this.get(index); try { return object instanceof Number ? ((Number) object).doubleValue() : Double.parseDouble((String) object); - } catch (final Exception e) { + } + catch (final Exception e) { throw new JSONException("JSONArray[" + index + "] is not a number."); } } @@ -221,15 +237,18 @@ public class JSONArray { /** * Get the int value associated with an index. * - * @param index The index must be between 0 and length() - 1. + * @param index + * The index must be between 0 and length() - 1. * @return The value. - * @throws JSONException If the key is not found or if the value is not a number. + * @throws JSONException + * If the key is not found or if the value is not a number. */ public int getInt(final int index) throws JSONException { final Object object = this.get(index); try { return object instanceof Number ? ((Number) object).intValue() : Integer.parseInt((String) object); - } catch (final Exception e) { + } + catch (final Exception e) { throw new JSONException("JSONArray[" + index + "] is not a number."); } } @@ -237,10 +256,12 @@ public class JSONArray { /** * Get the JSONArray associated with an index. * - * @param index The index must be between 0 and length() - 1. + * @param index + * The index must be between 0 and length() - 1. * @return A JSONArray value. - * @throws JSONException If there is no value for the index. or if the value is not a - * JSONArray + * @throws JSONException + * If there is no value for the index. or if the value is not a + * JSONArray */ public JSONArray getJSONArray(final int index) throws JSONException { final Object object = this.get(index); @@ -253,10 +274,12 @@ public class JSONArray { /** * Get the JSONObject associated with an index. * - * @param index subscript + * @param index + * subscript * @return A JSONObject value. - * @throws JSONException If there is no value for the index or if the value is not a - * JSONObject + * @throws JSONException + * If there is no value for the index or if the value is not a + * JSONObject */ public JSONObject getJSONObject(final int index) throws JSONException { final Object object = this.get(index); @@ -269,16 +292,19 @@ public class JSONArray { /** * Get the long value associated with an index. * - * @param index The index must be between 0 and length() - 1. + * @param index + * The index must be between 0 and length() - 1. * @return The value. - * @throws JSONException If the key is not found or if the value cannot be converted - * to a number. + * @throws JSONException + * If the key is not found or if the value cannot be converted + * to a number. */ public long getLong(final int index) throws JSONException { final Object object = this.get(index); try { return object instanceof Number ? ((Number) object).longValue() : Long.parseLong((String) object); - } catch (final Exception e) { + } + catch (final Exception e) { throw new JSONException("JSONArray[" + index + "] is not a number."); } } @@ -286,9 +312,11 @@ public class JSONArray { /** * Get the string associated with an index. * - * @param index The index must be between 0 and length() - 1. + * @param index + * The index must be between 0 and length() - 1. * @return A string value. - * @throws JSONException If there is no string value for the index. + * @throws JSONException + * If there is no string value for the index. */ public String getString(final int index) throws JSONException { final Object object = this.get(index); @@ -301,7 +329,8 @@ public class JSONArray { /** * Determine if the value is null. * - * @param index The index must be between 0 and length() - 1. + * @param index + * The index must be between 0 and length() - 1. * @return true if the value at the index is null, or if there is no value. */ public boolean isNull(final int index) { @@ -313,9 +342,11 @@ public class JSONArray { * separator string is inserted between each element. Warning: * This method assumes that the data structure is acyclical. * - * @param separator A string that will be inserted between the elements. + * @param separator + * A string that will be inserted between the elements. * @return a string. - * @throws JSONException If the array contains an invalid number. + * @throws JSONException + * If the array contains an invalid number. */ public String join(final String separator) throws JSONException { final int len = this.length(); @@ -342,7 +373,8 @@ public class JSONArray { /** * Get the optional object value associated with an index. * - * @param index The index must be between 0 and length() - 1. + * @param index + * The index must be between 0 and length() - 1. * @return An object value, or null if there is no object at that index. */ public Object opt(final int index) { @@ -354,7 +386,8 @@ public class JSONArray { * if there is no value at that index, or if the value is not Boolean.TRUE * or the String "true". * - * @param index The index must be between 0 and length() - 1. + * @param index + * The index must be between 0 and length() - 1. * @return The truth. */ public boolean optBoolean(final int index) { @@ -366,14 +399,17 @@ public class JSONArray { * defaultValue if there is no value at that index or if it is not a Boolean * or the String "true" or "false" (case insensitive). * - * @param index The index must be between 0 and length() - 1. - * @param defaultValue A boolean default. + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * A boolean default. * @return The truth. */ public boolean optBoolean(final int index, final boolean defaultValue) { try { return this.getBoolean(index); - } catch (final Exception e) { + } + catch (final Exception e) { return defaultValue; } } @@ -383,7 +419,8 @@ public class JSONArray { * if there is no value for the index, or if the value is not a number and * cannot be converted to a number. * - * @param index The index must be between 0 and length() - 1. + * @param index + * The index must be between 0 and length() - 1. * @return The value. */ public double optDouble(final int index) { @@ -395,14 +432,17 @@ public class JSONArray { * is returned if there is no value for the index, or if the value is not a * number and cannot be converted to a number. * - * @param index subscript - * @param defaultValue The default value. + * @param index + * subscript + * @param defaultValue + * The default value. * @return The value. */ public double optDouble(final int index, final double defaultValue) { try { return this.getDouble(index); - } catch (final Exception e) { + } + catch (final Exception e) { return defaultValue; } } @@ -412,7 +452,8 @@ public class JSONArray { * there is no value for the index, or if the value is not a number and * cannot be converted to a number. * - * @param index The index must be between 0 and length() - 1. + * @param index + * The index must be between 0 and length() - 1. * @return The value. */ public int optInt(final int index) { @@ -424,14 +465,17 @@ public class JSONArray { * returned if there is no value for the index, or if the value is not a * number and cannot be converted to a number. * - * @param index The index must be between 0 and length() - 1. - * @param defaultValue The default value. + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * The default value. * @return The value. */ public int optInt(final int index, final int defaultValue) { try { return this.getInt(index); - } catch (final Exception e) { + } + catch (final Exception e) { return defaultValue; } } @@ -439,9 +483,10 @@ public class JSONArray { /** * Get the optional JSONArray associated with an index. * - * @param index subscript + * @param index + * subscript * @return A JSONArray value, or null if the index has no value, or if the - * value is not a JSONArray. + * value is not a JSONArray. */ public JSONArray optJSONArray(final int index) { final Object o = this.opt(index); @@ -453,7 +498,8 @@ public class JSONArray { * the key is not found, or null if the index has no value, or if the value * is not a JSONObject. * - * @param index The index must be between 0 and length() - 1. + * @param index + * The index must be between 0 and length() - 1. * @return A JSONObject value. */ public JSONObject optJSONObject(final int index) { @@ -466,7 +512,8 @@ public class JSONArray { * there is no value for the index, or if the value is not a number and * cannot be converted to a number. * - * @param index The index must be between 0 and length() - 1. + * @param index + * The index must be between 0 and length() - 1. * @return The value. */ public long optLong(final int index) { @@ -478,14 +525,17 @@ public class JSONArray { * returned if there is no value for the index, or if the value is not a * number and cannot be converted to a number. * - * @param index The index must be between 0 and length() - 1. - * @param defaultValue The default value. + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * The default value. * @return The value. */ public long optLong(final int index, final long defaultValue) { try { return this.getLong(index); - } catch (final Exception e) { + } + catch (final Exception e) { return defaultValue; } } @@ -495,7 +545,8 @@ public class JSONArray { * empty string if there is no value at that index. If the value is not a * string and is not null, then it is coverted to a string. * - * @param index The index must be between 0 and length() - 1. + * @param index + * The index must be between 0 and length() - 1. * @return A String value. */ public String optString(final int index) { @@ -506,8 +557,10 @@ public class JSONArray { * Get the optional string associated with an index. The defaultValue is * returned if the key is not found. * - * @param index The index must be between 0 and length() - 1. - * @param defaultValue The default value. + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * The default value. * @return A String value. */ public String optString(final int index, final String defaultValue) { @@ -518,7 +571,8 @@ public class JSONArray { /** * Append a boolean value. This increases the array's length by one. * - * @param value A boolean value. + * @param value + * A boolean value. * @return this. */ public JSONArray put(final boolean value) { @@ -530,7 +584,8 @@ public class JSONArray { * Put a value in the JSONArray, where the value will be a JSONArray which * is produced from a Collection. * - * @param value A Collection value. + * @param value + * A Collection value. * @return this. */ public JSONArray put(final Collection value) { @@ -541,9 +596,11 @@ public class JSONArray { /** * Append a double value. This increases the array's length by one. * - * @param value A double value. + * @param value + * A double value. * @return this. - * @throws JSONException if the value is not finite. + * @throws JSONException + * if the value is not finite. */ public JSONArray put(final double value) throws JSONException { final Double d = value; @@ -555,7 +612,8 @@ public class JSONArray { /** * Append an int value. This increases the array's length by one. * - * @param value An int value. + * @param value + * An int value. * @return this. */ public JSONArray put(final int value) { @@ -566,7 +624,8 @@ public class JSONArray { /** * Append an long value. This increases the array's length by one. * - * @param value A long value. + * @param value + * A long value. * @return this. */ public JSONArray put(final long value) { @@ -578,7 +637,8 @@ public class JSONArray { * Put a value in the JSONArray, where the value will be a JSONObject which * is produced from a Map. * - * @param value A Map value. + * @param value + * A Map value. * @return this. */ public JSONArray put(final Map value) { @@ -589,9 +649,10 @@ public class JSONArray { /** * Append an object value. This increases the array's length by one. * - * @param value An object value. The value should be a Boolean, Double, - * Integer, JSONArray, JSONObject, Long, or String, or the - * JSONObject.NULL object. + * @param value + * An object value. The value should be a Boolean, Double, + * Integer, JSONArray, JSONObject, Long, or String, or the + * JSONObject.NULL object. * @return this. */ public JSONArray put(final Object value) { @@ -604,10 +665,13 @@ public class JSONArray { * than the length of the JSONArray, then null elements will be added as * necessary to pad it out. * - * @param index The subscript. - * @param value A boolean value. + * @param index + * The subscript. + * @param value + * A boolean value. * @return this. - * @throws JSONException If the index is negative. + * @throws JSONException + * If the index is negative. */ public JSONArray put(final int index, final boolean value) throws JSONException { this.put(index, value ? Boolean.TRUE : Boolean.FALSE); @@ -618,10 +682,13 @@ public class JSONArray { * Put a value in the JSONArray, where the value will be a JSONArray which * is produced from a Collection. * - * @param index The subscript. - * @param value A Collection value. + * @param index + * The subscript. + * @param value + * A Collection value. * @return this. - * @throws JSONException If the index is negative or if the value is not finite. + * @throws JSONException + * If the index is negative or if the value is not finite. */ public JSONArray put(final int index, final Collection value) throws JSONException { this.put(index, new JSONArray(value)); @@ -633,10 +700,13 @@ public class JSONArray { * the JSONArray, then null elements will be added as necessary to pad it * out. * - * @param index The subscript. - * @param value A double value. + * @param index + * The subscript. + * @param value + * A double value. * @return this. - * @throws JSONException If the index is negative or if the value is not finite. + * @throws JSONException + * If the index is negative or if the value is not finite. */ public JSONArray put(final int index, final double value) throws JSONException { this.put(index, new Double(value)); @@ -648,10 +718,13 @@ public class JSONArray { * the JSONArray, then null elements will be added as necessary to pad it * out. * - * @param index The subscript. - * @param value An int value. + * @param index + * The subscript. + * @param value + * An int value. * @return this. - * @throws JSONException If the index is negative. + * @throws JSONException + * If the index is negative. */ public JSONArray put(final int index, final int value) throws JSONException { this.put(index, new Integer(value)); @@ -663,10 +736,13 @@ public class JSONArray { * the JSONArray, then null elements will be added as necessary to pad it * out. * - * @param index The subscript. - * @param value A long value. + * @param index + * The subscript. + * @param value + * A long value. * @return this. - * @throws JSONException If the index is negative. + * @throws JSONException + * If the index is negative. */ public JSONArray put(final int index, final long value) throws JSONException { this.put(index, new Long(value)); @@ -677,11 +753,14 @@ public class JSONArray { * Put a value in the JSONArray, where the value will be a JSONObject that * is produced from a Map. * - * @param index The subscript. - * @param value The Map value. + * @param index + * The subscript. + * @param value + * The Map value. * @return this. - * @throws JSONException If the index is negative or if the the value is an invalid - * number. + * @throws JSONException + * If the index is negative or if the the value is an invalid + * number. */ public JSONArray put(final int index, final Map value) throws JSONException { this.put(index, new JSONObject(value)); @@ -693,13 +772,16 @@ public class JSONArray { * than the length of the JSONArray, then null elements will be added as * necessary to pad it out. * - * @param index The subscript. - * @param value The value to put into the array. The value should be a - * Boolean, Double, Integer, JSONArray, JSONObject, Long, or - * String, or the JSONObject.NULL object. + * @param index + * The subscript. + * @param value + * The value to put into the array. The value should be a + * Boolean, Double, Integer, JSONArray, JSONObject, Long, or + * String, or the JSONObject.NULL object. * @return this. - * @throws JSONException If the index is negative or if the the value is an invalid - * number. + * @throws JSONException + * If the index is negative or if the the value is an invalid + * number. */ public JSONArray put(final int index, final Object value) throws JSONException { JSONObject.testValidity(value); @@ -708,7 +790,8 @@ public class JSONArray { } if (index < this.length()) { this.myArrayList.set(index, value); - } else { + } + else { while (index != this.length()) { this.put(JSONObject.NULL); } @@ -720,9 +803,10 @@ public class JSONArray { /** * Remove an index and close the hole. * - * @param index The index of the element to be removed. + * @param index + * The index of the element to be removed. * @return The value that was associated with the index, or null if there - * was no value. + * was no value. */ public Object remove(final int index) { return (index >= 0) && (index < this.length()) ? this.myArrayList.remove(index) : null; @@ -732,7 +816,8 @@ public class JSONArray { * Determine if two JSONArrays are similar. * They must contain similar sequences. * - * @param other The other JSONArray + * @param other + * The other JSONArray * @return true if they are equal */ public boolean similar(final Object other) { @@ -750,11 +835,13 @@ public class JSONArray { if (!((JSONObject) valueThis).similar(valueOther)) { return false; } - } else if (valueThis instanceof JSONArray) { + } + else if (valueThis instanceof JSONArray) { if (!((JSONArray) valueThis).similar(valueOther)) { return false; } - } else if (!valueThis.equals(valueOther)) { + } + else if (!valueThis.equals(valueOther)) { return false; } } @@ -765,11 +852,13 @@ public class JSONArray { * Produce a JSONObject by combining a JSONArray of names with the values of * this JSONArray. * - * @param names A JSONArray containing a list of key strings. These will be - * paired with the values. + * @param names + * A JSONArray containing a list of key strings. These will be + * paired with the values. * @return A JSONObject, or null if there are no names or if this JSONArray - * has no values. - * @throws JSONException If any of the names are null. + * has no values. + * @throws JSONException + * If any of the names are null. */ public JSONObject toJSONObject(final JSONArray names) throws JSONException { if ((names == null) || (names.length() == 0) || (this.length() == 0)) { @@ -791,13 +880,14 @@ public class JSONArray { * Warning: This method assumes that the data structure is acyclical. * * @return a printable, displayable, transmittable representation of the - * array. + * array. */ @Override public String toString() { try { return this.toString(0); - } catch (final Exception e) { + } + catch (final Exception e) { return null; } } @@ -806,11 +896,12 @@ public class JSONArray { * Make a prettyprinted JSON text of this JSONArray. Warning: This method * assumes that the data structure is acyclical. * - * @param indentFactor The number of spaces to add to each level of indentation. + * @param indentFactor + * The number of spaces to add to each level of indentation. * @return a printable, displayable, transmittable representation of the - * object, beginning with [ (left - * bracket) and ending with ] - *  (right bracket). + * object, beginning with [ (left + * bracket) and ending with ] + *  (right bracket). * @throws JSONException */ public String toString(final int indentFactor) throws JSONException { @@ -839,8 +930,10 @@ public class JSONArray { *

* Warning: This method assumes that the data structure is acyclical. * - * @param indentFactor The number of spaces to add to each level of indentation. - * @param indent The indention of the top level. + * @param indentFactor + * The number of spaces to add to each level of indentation. + * @param indent + * The indention of the top level. * @return The writer. * @throws JSONException */ @@ -852,7 +945,8 @@ public class JSONArray { if (length == 1) { JSONObject.writeValue(writer, this.myArrayList.get(0), indentFactor, indent); - } else if (length != 0) { + } + else if (length != 0) { final int newindent = indent + indentFactor; for (int i = 0; i < length; i += 1) { @@ -873,7 +967,8 @@ public class JSONArray { } writer.write(']'); return writer; - } catch (final IOException e) { + } + catch (final IOException e) { throw new JSONException(e); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONException.java b/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONException.java index 606c1fc1f..17f89893f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONException.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONException.java @@ -8,12 +8,13 @@ package com.intellectualcrafters.json; */ public class JSONException extends RuntimeException { private static final long serialVersionUID = 0; - private Throwable cause; + private Throwable cause; /** * Constructs a JSONException with an explanatory message. * - * @param message Detail about the reason for the exception. + * @param message + * Detail about the reason for the exception. */ public JSONException(final String message) { super(message); @@ -22,7 +23,8 @@ public class JSONException extends RuntimeException { /** * Constructs a new JSONException with the specified cause. * - * @param cause The cause. + * @param cause + * The cause. */ public JSONException(final Throwable cause) { super(cause.getMessage()); @@ -34,7 +36,7 @@ public class JSONException extends RuntimeException { * or unknown. * * @return the cause of this exception or null if the cause is nonexistent - * or unknown. + * or unknown. */ @Override public Throwable getCause() { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONML.java b/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONML.java index b405f162d..fb6533f65 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONML.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONML.java @@ -15,10 +15,13 @@ public class JSONML { /** * Parse XML values and store them in a JSONArray. * - * @param x The XMLTokener containing the source string. - * @param arrayForm true if array form, false if object form. - * @param ja The JSONArray that is containing the current tag or null - * if we are at the outermost level. + * @param x + * The XMLTokener containing the source string. + * @param arrayForm + * true if array form, false if object form. + * @param ja + * The JSONArray that is containing the current tag or null + * if we are at the outermost level. * @return A JSONArray if the value is the outermost tag, otherwise null. * @throws JSONException */ @@ -58,7 +61,8 @@ public class JSONML { throw x.syntaxError("Misshaped close tag"); } return token; - } else if (token == XML.BANG) { + } + else if (token == XML.BANG) { // "); - } else { + } + else { x.back(); } - } else if (c == '[') { + } + else if (c == '[') { token = x.nextToken(); if (token.equals("CDATA") && (x.next() == '[')) { if (ja != null) { ja.put(x.nextCDATA()); } - } else { + } + else { throw x.syntaxError("Expected 'CDATA['"); } - } else { + } + else { i = 1; do { token = x.nextMeta(); if (token == null) { throw x.syntaxError("Missing '>' after ' 0); } - } else if (token == XML.QUEST) { + } + else if (token == XML.QUEST) { // "); - } else { + } + else { throw x.syntaxError("Misshaped tag"); } // Open tag < - } else { + } + else { if (!(token instanceof String)) { throw x.syntaxError("Bad tagName '" + token + "'."); } @@ -115,14 +128,15 @@ public class JSONML { if (ja != null) { ja.put(newja); } - } else { + } + else { newjo.put("tagName", tagName); if (ja != null) { ja.put(newjo); } } token = null; - for (; ; ) { + for (;;) { if (token == null) { token = x.nextToken(); } @@ -147,7 +161,8 @@ public class JSONML { } newjo.accumulate(attribute, XML.stringToValue((String) token)); token = null; - } else { + } + else { newjo.accumulate(attribute, ""); } } @@ -164,14 +179,16 @@ public class JSONML { if (ja == null) { if (arrayForm) { return newja; - } else { + } + else { return newjo; } } // Content, between <...> and - } else { + } + else { if (token != XML.GT) { throw x.syntaxError("Misshaped tag"); } @@ -187,14 +204,16 @@ public class JSONML { if (ja == null) { if (arrayForm) { return newja; - } else { + } + else { return newjo; } } } } } - } else { + } + else { if (ja != null) { ja.put(token instanceof String ? XML.stringToValue((String) token) : token); } @@ -211,7 +230,8 @@ public class JSONML { * JSONArrays will represent the child tags. * Comments, prologs, DTDs, and <[ [ ]]> are ignored. * - * @param string The source string. + * @param string + * The source string. * @return A JSONArray containing the structured data from the XML string. * @throws JSONException */ @@ -228,7 +248,8 @@ public class JSONML { * JSONArrays will represent the child content and tags. * Comments, prologs, DTDs, and <[ [ ]]> are ignored. * - * @param x An XMLTokener. + * @param x + * An XMLTokener. * @return A JSONArray containing the structured data from the XML string. * @throws JSONException */ @@ -246,7 +267,8 @@ public class JSONML { *

* Comments, prologs, DTDs, and <[ [ ]]> are ignored. * - * @param x An XMLTokener of the XML source text. + * @param x + * An XMLTokener of the XML source text. * @return A JSONObject containing the structured data from the XML string. * @throws JSONException */ @@ -264,7 +286,8 @@ public class JSONML { *

* Comments, prologs, DTDs, and <[ [ ]]> are ignored. * - * @param string The XML source text. + * @param string + * The XML source text. * @return A JSONObject containing the structured data from the XML string. * @throws JSONException */ @@ -275,7 +298,8 @@ public class JSONML { /** * Reverse the JSONML transformation, making an XML text from a JSONArray. * - * @param ja A JSONArray. + * @param ja + * A JSONArray. * @return An XML string. * @throws JSONException */ @@ -319,7 +343,8 @@ public class JSONML { sb.append('"'); } } - } else { + } + else { i = 1; } @@ -329,7 +354,8 @@ public class JSONML { if (i >= length) { sb.append('/'); sb.append('>'); - } else { + } + else { sb.append('>'); do { object = ja.get(i); @@ -337,9 +363,11 @@ public class JSONML { if (object != null) { if (object instanceof String) { sb.append(XML.escape(object.toString())); - } else if (object instanceof JSONObject) { + } + else if (object instanceof JSONObject) { sb.append(toString((JSONObject) object)); - } else if (object instanceof JSONArray) { + } + else if (object instanceof JSONArray) { sb.append(toString((JSONArray) object)); } } @@ -359,7 +387,8 @@ public class JSONML { * then it must have a "childNodes" property containing an array of objects. * The other properties are attributes with string values. * - * @param jo A JSONObject. + * @param jo + * A JSONObject. * @return An XML string. * @throws JSONException */ @@ -410,7 +439,8 @@ public class JSONML { if (ja == null) { sb.append('/'); sb.append('>'); - } else { + } + else { sb.append('>'); length = ja.length(); for (i = 0; i < length; i += 1) { @@ -418,11 +448,14 @@ public class JSONML { if (object != null) { if (object instanceof String) { sb.append(XML.escape(object.toString())); - } else if (object instanceof JSONObject) { + } + else if (object instanceof JSONObject) { sb.append(toString((JSONObject) object)); - } else if (object instanceof JSONArray) { + } + else if (object instanceof JSONArray) { sb.append(toString((JSONArray) object)); - } else { + } + else { sb.append(object.toString()); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONObject.java b/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONObject.java index 319aa7032..d21aeb630 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONObject.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONObject.java @@ -6,8 +6,15 @@ import java.io.Writer; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.*; +import java.util.Collection; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Locale; +import java.util.Map; import java.util.Map.Entry; +import java.util.ResourceBundle; +import java.util.Set; /** * A JSONObject is an unordered collection of name/value pairs. Its external @@ -35,6 +42,7 @@ import java.util.Map.Entry; *

* The put methods add or replace values in an object. For example, *

+ * *

  * myString = new JSONObject().put("JSON", "Hello, World!").toString();
  * 
@@ -67,7 +75,7 @@ public class JSONObject { * JSONObject.NULL.equals(null) returns true. * JSONObject.NULL.toString() returns "null". */ - public static final Object NULL = new Null(); + public static final Object NULL = new Null(); /** * The map where the JSONObject's properties are kept. */ @@ -85,18 +93,22 @@ public class JSONObject { * strings is used to identify the keys that should be copied. Missing keys * are ignored. * - * @param jo A JSONObject. - * @param names An array of strings. + * @param jo + * A JSONObject. + * @param names + * An array of strings. * @throws JSONException - * @throws JSONException If a value is a non-finite number or if a name is - * duplicated. + * @throws JSONException + * If a value is a non-finite number or if a name is + * duplicated. */ public JSONObject(final JSONObject jo, final String[] names) { this(); for (final String name : names) { try { this.putOnce(name, jo.opt(name)); - } catch (final Exception ignore) { + } + catch (final Exception ignore) { } } } @@ -104,9 +116,11 @@ public class JSONObject { /** * Construct a JSONObject from a JSONTokener. * - * @param x A JSONTokener object containing the source string. - * @throws JSONException If there is a syntax error in the source string or a - * duplicated key. + * @param x + * A JSONTokener object containing the source string. + * @throws JSONException + * If there is a syntax error in the source string or a + * duplicated key. */ public JSONObject(final JSONTokener x) throws JSONException { this(); @@ -116,7 +130,7 @@ public class JSONObject { if (x.nextClean() != '{') { throw x.syntaxError("A JSONObject text must begin with '{'"); } - for (; ; ) { + for (;;) { c = x.nextClean(); switch (c) { case 0: @@ -157,14 +171,15 @@ public class JSONObject { /** * Construct a JSONObject from a Map. * - * @param map A map object that can be used to initialize the contents of + * @param map + * A map object that can be used to initialize the contents of * the JSONObject. * @throws JSONException */ public JSONObject(final Map map) { this.map = new HashMap(); if (map != null) { - for (Entry entry : map.entrySet()) { + for (final Entry entry : map.entrySet()) { final Object value = entry.getValue(); if (value != null) { this.map.put(entry.getKey(), wrap(value)); @@ -190,8 +205,9 @@ public class JSONObject { * "Larry Fine", then the JSONObject will contain * "name": "Larry Fine". * - * @param bean An object that has getter methods that should be used to make - * a JSONObject. + * @param bean + * An object that has getter methods that should be used to make + * a JSONObject. */ public JSONObject(final Object bean) { this(); @@ -205,10 +221,12 @@ public class JSONObject { * those keys in the object. If a key is not found or not visible, then it * will not be copied into the new JSONObject. * - * @param object An object that has fields that should be used to make a - * JSONObject. - * @param names An array of strings, the names of the fields to be obtained - * from the object. + * @param object + * An object that has fields that should be used to make a + * JSONObject. + * @param names + * An array of strings, the names of the fields to be obtained + * from the object. */ public JSONObject(final Object object, final String names[]) { this(); @@ -216,7 +234,8 @@ public class JSONObject { for (final String name : names) { try { this.putOpt(name, c.getField(name).get(object)); - } catch (final Exception ignore) { + } + catch (final Exception ignore) { } } } @@ -225,11 +244,13 @@ public class JSONObject { * Construct a JSONObject from a source JSON text string. This is the most * commonly used JSONObject constructor. * - * @param source A string beginning with { (left - * brace) and ending with } - *  (right brace). - * @throws JSONException If there is a syntax error in the source string or a - * duplicated key. + * @param source + * A string beginning with { (left + * brace) and ending with } + *  (right brace). + * @throws JSONException + * If there is a syntax error in the source string or a + * duplicated key. */ public JSONObject(final String source) throws JSONException { this(new JSONTokener(source)); @@ -238,9 +259,12 @@ public class JSONObject { /** * Construct a JSONObject from a ResourceBundle. * - * @param baseName The ResourceBundle base name. - * @param locale The Locale to load the ResourceBundle for. - * @throws JSONException If any JSONExceptions are detected. + * @param baseName + * The ResourceBundle base name. + * @param locale + * The Locale to load the ResourceBundle for. + * @throws JSONException + * If any JSONExceptions are detected. */ public JSONObject(final String baseName, final Locale locale) throws JSONException { this(); @@ -280,7 +304,8 @@ public class JSONObject { * Produce a string from a double. The string "null" will be returned if the * number is not finite. * - * @param d A double. + * @param d + * A double. * @return A String. */ public static String doubleToString(final double d) { @@ -347,9 +372,11 @@ public class JSONObject { /** * Produce a string from a Number. * - * @param number A Number + * @param number + * A Number * @return A String. - * @throws JSONException If n is a non-finite number. + * @throws JSONException + * If n is a non-finite number. */ public static String numberToString(final Number number) throws JSONException { if (number == null) { @@ -377,7 +404,8 @@ public class JSONObject { * allowing JSON text to be delivered in HTML. In JSON text, a string cannot * contain a control character or an unescaped quote or backslash. * - * @param string A String + * @param string + * A String * @return A String correctly formatted for insertion in a JSON text. */ public static String quote(final String string) { @@ -385,7 +413,8 @@ public class JSONObject { synchronized (sw.getBuffer()) { try { return quote(string, sw).toString(); - } catch (final IOException ignored) { + } + catch (final IOException ignored) { // will never happen - we are writing to a string writer return ""; } @@ -441,7 +470,8 @@ public class JSONObject { hhhh = Integer.toHexString(c); w.write("0000", 0, 4 - hhhh.length()); w.write(hhhh); - } else { + } + else { w.write(c); } } @@ -454,7 +484,8 @@ public class JSONObject { * Try to convert a string into a number, boolean, or null. If the string * can't be converted, return the string. * - * @param string A String. + * @param string + * A String. * @return A simple JSON value. */ public static Object stringToValue(final String string) { @@ -485,17 +516,20 @@ public class JSONObject { if (!d.isInfinite() && !d.isNaN()) { return d; } - } else { + } + else { final Long myLong = new Long(string); if (string.equals(myLong.toString())) { if (myLong == myLong.intValue()) { return myLong.intValue(); - } else { + } + else { return myLong; } } } - } catch (final Exception ignore) { + } + catch (final Exception ignore) { } } return string; @@ -504,8 +538,10 @@ public class JSONObject { /** * Throw an exception if the object is a NaN or infinite number. * - * @param o The object to test. - * @throws JSONException If o is a non-finite number. + * @param o + * The object to test. + * @throws JSONException + * If o is a non-finite number. */ public static void testValidity(final Object o) throws JSONException { if (o != null) { @@ -513,7 +549,8 @@ public class JSONObject { if (((Double) o).isInfinite() || ((Double) o).isNaN()) { throw new JSONException("JSON does not allow non-finite numbers."); } - } else if (o instanceof Float) { + } + else if (o instanceof Float) { if (((Float) o).isInfinite() || ((Float) o).isNaN()) { throw new JSONException("JSON does not allow non-finite numbers."); } @@ -536,12 +573,14 @@ public class JSONObject { *

* Warning: This method assumes that the data structure is acyclical. * - * @param value The value to be serialized. + * @param value + * The value to be serialized. * @return a printable, displayable, transmittable representation of the - * object, beginning with { (left - * brace) and ending with } (right - * brace). - * @throws JSONException If the value is or contains an invalid number. + * object, beginning with { (left + * brace) and ending with } (right + * brace). + * @throws JSONException + * If the value is or contains an invalid number. */ public static String valueToString(final Object value) throws JSONException { if ((value == null) || value.equals(null)) { @@ -551,7 +590,8 @@ public class JSONObject { Object object; try { object = ((JSONString) value).toJSONString(); - } catch (final Exception e) { + } + catch (final Exception e) { throw new JSONException(e); } if (object instanceof String) { @@ -585,7 +625,8 @@ public class JSONObject { * one of the java packages, turn it into a string. And if it doesn't, try * to wrap it in a JSONObject. If the wrapping fails, then null is returned. * - * @param object The object to wrap + * @param object + * The object to wrap * @return The wrapped value */ public static Object wrap(final Object object) { @@ -612,7 +653,8 @@ public class JSONObject { return object.toString(); } return new JSONObject(object); - } catch (final Exception exception) { + } + catch (final Exception exception) { return null; } } @@ -620,29 +662,39 @@ public class JSONObject { static final Writer writeValue(final Writer writer, final Object value, final int indentFactor, final int indent) throws JSONException, IOException { if ((value == null) || value.equals(null)) { writer.write("null"); - } else if (value instanceof JSONObject) { + } + else if (value instanceof JSONObject) { ((JSONObject) value).write(writer, indentFactor, indent); - } else if (value instanceof JSONArray) { + } + else if (value instanceof JSONArray) { ((JSONArray) value).write(writer, indentFactor, indent); - } else if (value instanceof Map) { + } + else if (value instanceof Map) { new JSONObject((Map) value).write(writer, indentFactor, indent); - } else if (value instanceof Collection) { + } + else if (value instanceof Collection) { new JSONArray((Collection) value).write(writer, indentFactor, indent); - } else if (value.getClass().isArray()) { + } + else if (value.getClass().isArray()) { new JSONArray(value).write(writer, indentFactor, indent); - } else if (value instanceof Number) { + } + else if (value instanceof Number) { writer.write(numberToString((Number) value)); - } else if (value instanceof Boolean) { + } + else if (value instanceof Boolean) { writer.write(value.toString()); - } else if (value instanceof JSONString) { + } + else if (value instanceof JSONString) { Object o; try { o = ((JSONString) value).toJSONString(); - } catch (final Exception e) { + } + catch (final Exception e) { throw new JSONException(e); } writer.write(o != null ? o.toString() : quote(value.toString())); - } else { + } + else { quote(value.toString(), writer); } return writer; @@ -665,19 +717,24 @@ public class JSONObject { * will be the same as using put. But if multiple values are accumulated, * then the result will be like append. * - * @param key A key string. - * @param value An object to be accumulated under the key. + * @param key + * A key string. + * @param value + * An object to be accumulated under the key. * @return this. - * @throws JSONException If the value is an invalid number or if the key is null. + * @throws JSONException + * If the value is an invalid number or if the key is null. */ public JSONObject accumulate(final String key, final Object value) throws JSONException { testValidity(value); final Object object = this.opt(key); if (object == null) { this.put(key, value instanceof JSONArray ? new JSONArray().put(value) : value); - } else if (object instanceof JSONArray) { + } + else if (object instanceof JSONArray) { ((JSONArray) object).put(value); - } else { + } + else { this.put(key, new JSONArray().put(object).put(value)); } return this; @@ -689,20 +746,25 @@ public class JSONObject { * JSONArray containing the value parameter. If the key was already * associated with a JSONArray, then the value parameter is appended to it. * - * @param key A key string. - * @param value An object to be accumulated under the key. + * @param key + * A key string. + * @param value + * An object to be accumulated under the key. * @return this. - * @throws JSONException If the key is null or if the current value associated with - * the key is not a JSONArray. + * @throws JSONException + * If the key is null or if the current value associated with + * the key is not a JSONArray. */ public JSONObject append(final String key, final Object value) throws JSONException { testValidity(value); final Object object = this.opt(key); if (object == null) { this.put(key, new JSONArray().put(value)); - } else if (object instanceof JSONArray) { + } + else if (object instanceof JSONArray) { this.put(key, ((JSONArray) object).put(value)); - } else { + } + else { throw new JSONException("JSONObject[" + key + "] is not a JSONArray."); } return this; @@ -711,9 +773,11 @@ public class JSONObject { /** * Get the value object associated with a key. * - * @param key A key string. + * @param key + * A key string. * @return The object associated with the key. - * @throws JSONException if the key is not found. + * @throws JSONException + * if the key is not found. */ public Object get(final String key) throws JSONException { if (key == null) { @@ -729,16 +793,19 @@ public class JSONObject { /** * Get the boolean value associated with a key. * - * @param key A key string. + * @param key + * A key string. * @return The truth. - * @throws JSONException if the value is not a Boolean or the String "true" or - * "false". + * @throws JSONException + * if the value is not a Boolean or the String "true" or + * "false". */ public boolean getBoolean(final String key) throws JSONException { final Object object = this.get(key); if (object.equals(Boolean.FALSE) || ((object instanceof String) && ((String) object).equalsIgnoreCase("false"))) { return false; - } else if (object.equals(Boolean.TRUE) || ((object instanceof String) && ((String) object).equalsIgnoreCase("true"))) { + } + else if (object.equals(Boolean.TRUE) || ((object instanceof String) && ((String) object).equalsIgnoreCase("true"))) { return true; } throw new JSONException("JSONObject[" + quote(key) + "] is not a Boolean."); @@ -747,16 +814,19 @@ public class JSONObject { /** * Get the double value associated with a key. * - * @param key A key string. + * @param key + * A key string. * @return The numeric value. - * @throws JSONException if the key is not found or if the value is not a Number - * object and cannot be converted to a number. + * @throws JSONException + * if the key is not found or if the value is not a Number + * object and cannot be converted to a number. */ public double getDouble(final String key) throws JSONException { final Object object = this.get(key); try { return object instanceof Number ? ((Number) object).doubleValue() : Double.parseDouble((String) object); - } catch (final Exception e) { + } + catch (final Exception e) { throw new JSONException("JSONObject[" + quote(key) + "] is not a number."); } } @@ -764,16 +834,19 @@ public class JSONObject { /** * Get the int value associated with a key. * - * @param key A key string. + * @param key + * A key string. * @return The integer value. - * @throws JSONException if the key is not found or if the value cannot be converted - * to an integer. + * @throws JSONException + * if the key is not found or if the value cannot be converted + * to an integer. */ public int getInt(final String key) throws JSONException { final Object object = this.get(key); try { return object instanceof Number ? ((Number) object).intValue() : Integer.parseInt((String) object); - } catch (final Exception e) { + } + catch (final Exception e) { throw new JSONException("JSONObject[" + quote(key) + "] is not an int."); } } @@ -781,9 +854,11 @@ public class JSONObject { /** * Get the JSONArray value associated with a key. * - * @param key A key string. + * @param key + * A key string. * @return A JSONArray which is the value. - * @throws JSONException if the key is not found or if the value is not a JSONArray. + * @throws JSONException + * if the key is not found or if the value is not a JSONArray. */ public JSONArray getJSONArray(final String key) throws JSONException { final Object object = this.get(key); @@ -796,9 +871,11 @@ public class JSONObject { /** * Get the JSONObject value associated with a key. * - * @param key A key string. + * @param key + * A key string. * @return A JSONObject which is the value. - * @throws JSONException if the key is not found or if the value is not a JSONObject. + * @throws JSONException + * if the key is not found or if the value is not a JSONObject. */ public JSONObject getJSONObject(final String key) throws JSONException { final Object object = this.get(key); @@ -811,16 +888,19 @@ public class JSONObject { /** * Get the long value associated with a key. * - * @param key A key string. + * @param key + * A key string. * @return The long value. - * @throws JSONException if the key is not found or if the value cannot be converted - * to a long. + * @throws JSONException + * if the key is not found or if the value cannot be converted + * to a long. */ public long getLong(final String key) throws JSONException { final Object object = this.get(key); try { return object instanceof Number ? ((Number) object).longValue() : Long.parseLong((String) object); - } catch (final Exception e) { + } + catch (final Exception e) { throw new JSONException("JSONObject[" + quote(key) + "] is not a long."); } } @@ -828,9 +908,11 @@ public class JSONObject { /** * Get the string associated with a key. * - * @param key A key string. + * @param key + * A key string. * @return A string which is the value. - * @throws JSONException if there is no string value for the key. + * @throws JSONException + * if there is no string value for the key. */ public String getString(final String key) throws JSONException { final Object object = this.get(key); @@ -843,7 +925,8 @@ public class JSONObject { /** * Determine if the JSONObject contains a specific key. * - * @param key A key string. + * @param key + * A key string. * @return true if the key exists in the JSONObject. */ public boolean has(final String key) { @@ -855,24 +938,31 @@ public class JSONObject { * create one with a value of 1. If there is such a property, and if it is * an Integer, Long, Double, or Float, then add one to it. * - * @param key A key string. + * @param key + * A key string. * @return this. - * @throws JSONException If there is already a property with this name that is not an - * Integer, Long, Double, or Float. + * @throws JSONException + * If there is already a property with this name that is not an + * Integer, Long, Double, or Float. */ public JSONObject increment(final String key) throws JSONException { final Object value = this.opt(key); if (value == null) { this.put(key, 1); - } else if (value instanceof Integer) { + } + else if (value instanceof Integer) { this.put(key, (Integer) value + 1); - } else if (value instanceof Long) { + } + else if (value instanceof Long) { this.put(key, (Long) value + 1); - } else if (value instanceof Double) { + } + else if (value instanceof Double) { this.put(key, (Double) value + 1); - } else if (value instanceof Float) { + } + else if (value instanceof Float) { this.put(key, (Float) value + 1); - } else { + } + else { throw new JSONException("Unable to increment [" + quote(key) + "]."); } return this; @@ -882,9 +972,10 @@ public class JSONObject { * Determine if the value associated with the key is null or if there is no * value. * - * @param key A key string. + * @param key + * A key string. * @return true if there is no value associated with the key or if the value - * is the JSONObject.NULL object. + * is the JSONObject.NULL object. */ public boolean isNull(final String key) { return JSONObject.NULL.equals(this.opt(key)); @@ -922,7 +1013,7 @@ public class JSONObject { * JSONObject. * * @return A JSONArray containing the key strings, or null if the JSONObject - * is empty. + * is empty. */ public JSONArray names() { final JSONArray ja = new JSONArray(); @@ -936,7 +1027,8 @@ public class JSONObject { /** * Get an optional value associated with a key. * - * @param key A key string. + * @param key + * A key string. * @return An object which is the value, or null if there is no value. */ public Object opt(final String key) { @@ -947,7 +1039,8 @@ public class JSONObject { * Get an optional boolean associated with a key. It returns false if there * is no such key, or if the value is not Boolean.TRUE or the String "true". * - * @param key A key string. + * @param key + * A key string. * @return The truth. */ public boolean optBoolean(final String key) { @@ -959,14 +1052,17 @@ public class JSONObject { * defaultValue if there is no such key, or if it is not a Boolean or the * String "true" or "false" (case insensitive). * - * @param key A key string. - * @param defaultValue The default. + * @param key + * A key string. + * @param defaultValue + * The default. * @return The truth. */ public boolean optBoolean(final String key, final boolean defaultValue) { try { return this.getBoolean(key); - } catch (final Exception e) { + } + catch (final Exception e) { return defaultValue; } } @@ -976,7 +1072,8 @@ public class JSONObject { * key or if its value is not a number. If the value is a string, an attempt * will be made to evaluate it as a number. * - * @param key A string which is the key. + * @param key + * A string which is the key. * @return An object which is the value. */ public double optDouble(final String key) { @@ -988,14 +1085,17 @@ public class JSONObject { * there is no such key or if its value is not a number. If the value is a * string, an attempt will be made to evaluate it as a number. * - * @param key A key string. - * @param defaultValue The default. + * @param key + * A key string. + * @param defaultValue + * The default. * @return An object which is the value. */ public double optDouble(final String key, final double defaultValue) { try { return this.getDouble(key); - } catch (final Exception e) { + } + catch (final Exception e) { return defaultValue; } } @@ -1005,7 +1105,8 @@ public class JSONObject { * such key or if the value is not a number. If the value is a string, an * attempt will be made to evaluate it as a number. * - * @param key A key string. + * @param key + * A key string. * @return An object which is the value. */ public int optInt(final String key) { @@ -1017,14 +1118,17 @@ public class JSONObject { * is no such key or if the value is not a number. If the value is a string, * an attempt will be made to evaluate it as a number. * - * @param key A key string. - * @param defaultValue The default. + * @param key + * A key string. + * @param defaultValue + * The default. * @return An object which is the value. */ public int optInt(final String key, final int defaultValue) { try { return this.getInt(key); - } catch (final Exception e) { + } + catch (final Exception e) { return defaultValue; } } @@ -1033,7 +1137,8 @@ public class JSONObject { * Get an optional JSONArray associated with a key. It returns null if there * is no such key, or if its value is not a JSONArray. * - * @param key A key string. + * @param key + * A key string. * @return A JSONArray which is the value. */ public JSONArray optJSONArray(final String key) { @@ -1045,7 +1150,8 @@ public class JSONObject { * Get an optional JSONObject associated with a key. It returns null if * there is no such key, or if its value is not a JSONObject. * - * @param key A key string. + * @param key + * A key string. * @return A JSONObject which is the value. */ public JSONObject optJSONObject(final String key) { @@ -1058,7 +1164,8 @@ public class JSONObject { * such key or if the value is not a number. If the value is a string, an * attempt will be made to evaluate it as a number. * - * @param key A key string. + * @param key + * A key string. * @return An object which is the value. */ public long optLong(final String key) { @@ -1070,14 +1177,17 @@ public class JSONObject { * is no such key or if the value is not a number. If the value is a string, * an attempt will be made to evaluate it as a number. * - * @param key A key string. - * @param defaultValue The default. + * @param key + * A key string. + * @param defaultValue + * The default. * @return An object which is the value. */ public long optLong(final String key, final long defaultValue) { try { return this.getLong(key); - } catch (final Exception e) { + } + catch (final Exception e) { return defaultValue; } } @@ -1087,7 +1197,8 @@ public class JSONObject { * if there is no such key. If the value is not a string and is not null, * then it is converted to a string. * - * @param key A key string. + * @param key + * A key string. * @return A string which is the value. */ public String optString(final String key) { @@ -1098,8 +1209,10 @@ public class JSONObject { * Get an optional string associated with a key. It returns the defaultValue * if there is no such key. * - * @param key A key string. - * @param defaultValue The default. + * @param key + * A key string. + * @param defaultValue + * The default. * @return A string which is the value. */ public String optString(final String key, final String defaultValue) { @@ -1123,16 +1236,19 @@ public class JSONObject { if (name.startsWith("get")) { if ("getClass".equals(name) || "getDeclaringClass".equals(name)) { key = ""; - } else { + } + else { key = name.substring(3); } - } else if (name.startsWith("is")) { + } + else if (name.startsWith("is")) { key = name.substring(2); } if ((key.length() > 0) && Character.isUpperCase(key.charAt(0)) && (method.getParameterTypes().length == 0)) { if (key.length() == 1) { key = key.toLowerCase(); - } else if (!Character.isUpperCase(key.charAt(1))) { + } + else if (!Character.isUpperCase(key.charAt(1))) { key = key.substring(0, 1).toLowerCase() + key.substring(1); } @@ -1142,7 +1258,8 @@ public class JSONObject { } } } - } catch (final Exception ignore) { + } + catch (final Exception ignore) { } } } @@ -1150,10 +1267,13 @@ public class JSONObject { /** * Put a key/boolean pair in the JSONObject. * - * @param key A key string. - * @param value A boolean which is the value. + * @param key + * A key string. + * @param value + * A boolean which is the value. * @return this. - * @throws JSONException If the key is null. + * @throws JSONException + * If the key is null. */ public JSONObject put(final String key, final boolean value) throws JSONException { this.put(key, value ? Boolean.TRUE : Boolean.FALSE); @@ -1164,8 +1284,10 @@ public class JSONObject { * Put a key/value pair in the JSONObject, where the value will be a * JSONArray which is produced from a Collection. * - * @param key A key string. - * @param value A Collection value. + * @param key + * A key string. + * @param value + * A Collection value. * @return this. * @throws JSONException */ @@ -1177,10 +1299,13 @@ public class JSONObject { /** * Put a key/double pair in the JSONObject. * - * @param key A key string. - * @param value A double which is the value. + * @param key + * A key string. + * @param value + * A double which is the value. * @return this. - * @throws JSONException If the key is null or if the number is invalid. + * @throws JSONException + * If the key is null or if the number is invalid. */ public JSONObject put(final String key, final double value) throws JSONException { this.put(key, new Double(value)); @@ -1190,10 +1315,13 @@ public class JSONObject { /** * Put a key/int pair in the JSONObject. * - * @param key A key string. - * @param value An int which is the value. + * @param key + * A key string. + * @param value + * An int which is the value. * @return this. - * @throws JSONException If the key is null. + * @throws JSONException + * If the key is null. */ public JSONObject put(final String key, final int value) throws JSONException { this.put(key, new Integer(value)); @@ -1203,10 +1331,13 @@ public class JSONObject { /** * Put a key/long pair in the JSONObject. * - * @param key A key string. - * @param value A long which is the value. + * @param key + * A key string. + * @param value + * A long which is the value. * @return this. - * @throws JSONException If the key is null. + * @throws JSONException + * If the key is null. */ public JSONObject put(final String key, final long value) throws JSONException { this.put(key, new Long(value)); @@ -1217,8 +1348,10 @@ public class JSONObject { * Put a key/value pair in the JSONObject, where the value will be a * JSONObject which is produced from a Map. * - * @param key A key string. - * @param value A Map value. + * @param key + * A key string. + * @param value + * A Map value. * @return this. * @throws JSONException */ @@ -1231,12 +1364,15 @@ public class JSONObject { * Put a key/value pair in the JSONObject. If the value is null, then the * key will be removed from the JSONObject if it is present. * - * @param key A key string. - * @param value An object which is the value. It should be of one of these - * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, - * String, or the JSONObject.NULL object. + * @param key + * A key string. + * @param value + * An object which is the value. It should be of one of these + * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, + * String, or the JSONObject.NULL object. * @return this. - * @throws JSONException If the value is non-finite number or if the key is null. + * @throws JSONException + * If the value is non-finite number or if the key is null. */ public JSONObject put(final String key, final Object value) throws JSONException { if (key == null) { @@ -1245,7 +1381,8 @@ public class JSONObject { if (value != null) { testValidity(value); this.map.put(key, value); - } else { + } + else { this.remove(key); } return this; @@ -1256,10 +1393,13 @@ public class JSONObject { * are both non-null, and only if there is not already a member with that * name. * - * @param key string - * @param value object + * @param key + * string + * @param value + * object * @return this. - * @throws JSONException if the key is a duplicate + * @throws JSONException + * if the key is a duplicate */ public JSONObject putOnce(final String key, final Object value) throws JSONException { if ((key != null) && (value != null)) { @@ -1275,12 +1415,15 @@ public class JSONObject { * Put a key/value pair in the JSONObject, but only if the key and the value * are both non-null. * - * @param key A key string. - * @param value An object which is the value. It should be of one of these - * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, - * String, or the JSONObject.NULL object. + * @param key + * A key string. + * @param value + * An object which is the value. It should be of one of these + * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, + * String, or the JSONObject.NULL object. * @return this. - * @throws JSONException If the value is a non-finite number. + * @throws JSONException + * If the value is a non-finite number. */ public JSONObject putOpt(final String key, final Object value) throws JSONException { if ((key != null) && (value != null)) { @@ -1292,9 +1435,10 @@ public class JSONObject { /** * Remove a name and its value, if present. * - * @param key The name to be removed. + * @param key + * The name to be removed. * @return The value that was associated with the name, or null if there was - * no value. + * no value. */ public Object remove(final String key) { return this.map.remove(key); @@ -1305,7 +1449,8 @@ public class JSONObject { * They must contain the same set of names which must be associated with * similar values. * - * @param other The other JSONObject + * @param other + * The other JSONObject * @return true if they are equal */ public boolean similar(final Object other) { @@ -1317,23 +1462,26 @@ public class JSONObject { if (!set.equals(((JSONObject) other).keySet())) { return false; } - for (String name : set) { + for (final String name : set) { final Object valueThis = this.get(name); final Object valueOther = ((JSONObject) other).get(name); if (valueThis instanceof JSONObject) { if (!((JSONObject) valueThis).similar(valueOther)) { return false; } - } else if (valueThis instanceof JSONArray) { + } + else if (valueThis instanceof JSONArray) { if (!((JSONArray) valueThis).similar(valueOther)) { return false; } - } else if (!valueThis.equals(valueOther)) { + } + else if (!valueThis.equals(valueOther)) { return false; } } return true; - } catch (final Throwable exception) { + } + catch (final Throwable exception) { return false; } } @@ -1342,10 +1490,12 @@ public class JSONObject { * Produce a JSONArray containing the values of the members of this * JSONObject. * - * @param names A JSONArray containing a list of key strings. This determines - * the sequence of the values in the result. + * @param names + * A JSONArray containing a list of key strings. This determines + * the sequence of the values in the result. * @return A JSONArray of values. - * @throws JSONException If any of the values are non-finite numbers. + * @throws JSONException + * If any of the values are non-finite numbers. */ public JSONArray toJSONArray(final JSONArray names) throws JSONException { if ((names == null) || (names.length() == 0)) { @@ -1366,15 +1516,16 @@ public class JSONObject { * Warning: This method assumes that the data structure is acyclical. * * @return a printable, displayable, portable, transmittable representation - * of the object, beginning with { (left - * brace) and ending with } (right - * brace). + * of the object, beginning with { (left + * brace) and ending with } (right + * brace). */ @Override public String toString() { try { return this.toString(0); - } catch (final Exception e) { + } + catch (final Exception e) { return null; } } @@ -1384,12 +1535,14 @@ public class JSONObject { *

* Warning: This method assumes that the data structure is acyclical. * - * @param indentFactor The number of spaces to add to each level of indentation. + * @param indentFactor + * The number of spaces to add to each level of indentation. * @return a printable, displayable, portable, transmittable representation - * of the object, beginning with { (left - * brace) and ending with } (right - * brace). - * @throws JSONException If the object contains an invalid number. + * of the object, beginning with { (left + * brace) and ending with } (right + * brace). + * @throws JSONException + * If the object contains an invalid number. */ public String toString(final int indentFactor) throws JSONException { final StringWriter w = new StringWriter(); @@ -1435,7 +1588,8 @@ public class JSONObject { writer.write(' '); } writeValue(writer, this.map.get(key), indentFactor, indent); - } else if (length != 0) { + } + else if (length != 0) { final int newindent = indent + indentFactor; while (keys.hasNext()) { final Object key = keys.next(); @@ -1461,7 +1615,8 @@ public class JSONObject { } writer.write('}'); return writer; - } catch (final IOException exception) { + } + catch (final IOException exception) { throw new JSONException(exception); } } @@ -1483,7 +1638,8 @@ public class JSONObject { protected final Object clone() { try { return super.clone(); - } catch (Exception e) { + } + catch (final Exception e) { return this; } } @@ -1491,9 +1647,10 @@ public class JSONObject { /** * A Null object is equal to the null value and to itself. * - * @param object An object to test for nullness. + * @param object + * An object to test for nullness. * @return true if the object parameter is the JSONObject.NULL object or - * null. + * null. */ @Override public boolean equals(final Object object) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONStringer.java b/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONStringer.java index dd2db14ef..729bd016d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONStringer.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONStringer.java @@ -16,12 +16,14 @@ import java.io.StringWriter; * these methods return the JSONWriter instance, permitting cascade style. For * example, *

+ * *

  * myString = new JSONStringer().object().key("JSON").value("Hello, World!").endObject().toString();
  * 
*

* which produces the string *

+ * *

  * {"JSON":"Hello, World!"}
  * 
diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONTokener.java b/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONTokener.java index 2dfe33430..ef16678c0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONTokener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONTokener.java @@ -1,6 +1,11 @@ package com.intellectualcrafters.json; -import java.io.*; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringReader; /** * A JSONTokener takes a source string and extracts characters and tokens from @@ -13,17 +18,18 @@ import java.io.*; public class JSONTokener { private final Reader reader; - private long character; - private boolean eof; - private long index; - private long line; - private char previous; - private boolean usePrevious; + private long character; + private boolean eof; + private long index; + private long line; + private char previous; + private boolean usePrevious; /** * Construct a JSONTokener from a Reader. * - * @param reader A reader. + * @param reader + * A reader. */ public JSONTokener(final Reader reader) { this.reader = reader.markSupported() ? reader : new BufferedReader(reader); @@ -38,7 +44,8 @@ public class JSONTokener { /** * Construct a JSONTokener from an InputStream. * - * @param inputStream The source. + * @param inputStream + * The source. */ public JSONTokener(final InputStream inputStream) throws JSONException { this(new InputStreamReader(inputStream)); @@ -47,7 +54,8 @@ public class JSONTokener { /** * Construct a JSONTokener from a string. * - * @param s A source string. + * @param s + * A source string. */ public JSONTokener(final String s) { this(new StringReader(s)); @@ -56,8 +64,9 @@ public class JSONTokener { /** * Get the hex value of a character (base16). * - * @param c A character between '0' and '9' or between 'A' and 'F' or - * between 'a' and 'f'. + * @param c + * A character between '0' and '9' or between 'A' and 'F' or + * between 'a' and 'f'. * @return An int between 0 and 15, or -1 if c was not a hex digit. */ public static int dehexchar(final char c) { @@ -117,10 +126,12 @@ public class JSONTokener { if (this.usePrevious) { this.usePrevious = false; c = this.previous; - } else { + } + else { try { c = this.reader.read(); - } catch (final IOException exception) { + } + catch (final IOException exception) { throw new JSONException(exception); } @@ -133,10 +144,12 @@ public class JSONTokener { if (this.previous == '\r') { this.line += 1; this.character = c == '\n' ? 0 : 1; - } else if (c == '\n') { + } + else if (c == '\n') { this.line += 1; this.character = 0; - } else { + } + else { this.character += 1; } this.previous = (char) c; @@ -147,9 +160,11 @@ public class JSONTokener { * Consume the next character, and check that it matches a specified * character. * - * @param c The character to match. + * @param c + * The character to match. * @return The character. - * @throws JSONException if the character does not match. + * @throws JSONException + * if the character does not match. */ public char next(final char c) throws JSONException { final char n = this.next(); @@ -162,10 +177,12 @@ public class JSONTokener { /** * Get the next n characters. * - * @param n The number of characters to take. + * @param n + * The number of characters to take. * @return A string of n characters. - * @throws JSONException Substring bounds error if there are not - * n characters remaining in the source string. + * @throws JSONException + * Substring bounds error if there are not + * n characters remaining in the source string. */ public String next(final int n) throws JSONException { if (n == 0) { @@ -192,7 +209,7 @@ public class JSONTokener { * @throws JSONException */ public char nextClean() throws JSONException { - for (; ; ) { + for (;;) { final char c = this.next(); if ((c == 0) || (c > ' ')) { return c; @@ -206,16 +223,18 @@ public class JSONTokener { * allow strings in single quotes, but an implementation is allowed to * accept them. * - * @param quote The quoting character, either " - *  (double quote) or ' - *  (single quote). + * @param quote + * The quoting character, either " + *  (double quote) or ' + *  (single quote). * @return A String. - * @throws JSONException Unterminated string. + * @throws JSONException + * Unterminated string. */ public String nextString(final char quote) throws JSONException { char c; final StringBuilder sb = new StringBuilder(); - for (; ; ) { + for (;;) { c = this.next(); switch (c) { case 0: @@ -266,12 +285,13 @@ public class JSONTokener { * Get the text up but not including the specified character or the * end of line, whichever comes first. * - * @param delimiter A delimiter character. + * @param delimiter + * A delimiter character. * @return A string. */ public String nextTo(final char delimiter) throws JSONException { final StringBuilder sb = new StringBuilder(); - for (; ; ) { + for (;;) { final char c = this.next(); if ((c == delimiter) || (c == 0) || (c == '\n') || (c == '\r')) { if (c != 0) { @@ -287,13 +307,14 @@ public class JSONTokener { * Get the text up but not including one of the specified delimiter * characters or the end of line, whichever comes first. * - * @param delimiters A set of delimiter characters. + * @param delimiters + * A set of delimiter characters. * @return A string, trimmed. */ public String nextTo(final String delimiters) throws JSONException { char c; final StringBuilder sb = new StringBuilder(); - for (; ; ) { + for (;;) { c = this.next(); if ((delimiters.indexOf(c) >= 0) || (c == 0) || (c == '\n') || (c == '\r')) { if (c != 0) { @@ -310,7 +331,8 @@ public class JSONTokener { * JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object. * * @return An object. - * @throws JSONException If syntax error. + * @throws JSONException + * If syntax error. */ public Object nextValue() throws JSONException { char c = this.nextClean(); @@ -354,9 +376,10 @@ public class JSONTokener { * Skip characters until the next character is the requested character. * If the requested character is not found, no characters are skipped. * - * @param to A character to skip to. + * @param to + * A character to skip to. * @return The requested character, or zero if the requested character - * is not found. + * is not found. */ public char skipTo(final char to) throws JSONException { char c; @@ -376,7 +399,8 @@ public class JSONTokener { } } while (c != to); - } catch (final IOException exception) { + } + catch (final IOException exception) { throw new JSONException(exception); } this.back(); @@ -386,7 +410,8 @@ public class JSONTokener { /** * Make a JSONException to signal a syntax error. * - * @param message The error message. + * @param message + * The error message. * @return A JSONException object, suitable for throwing */ public JSONException syntaxError(final String message) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONWriter.java b/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONWriter.java index 416834279..45989c0b5 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONWriter.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONWriter.java @@ -17,12 +17,14 @@ import java.io.Writer; * these methods return the JSONWriter instance, permitting a cascade style. For * example, *

+ * *

  * new JSONWriter(myWriter).object().key("JSON").value("Hello, World!").endObject();
  * 
*

* which writes *

+ * *

  * {"JSON":"Hello, World!"}
  * 
@@ -41,7 +43,7 @@ public class JSONWriter { /** * The writer that will receive the output. */ - protected final Writer writer; + protected final Writer writer; /** * The object/array stack. */ @@ -54,16 +56,16 @@ public class JSONWriter { * 'k' (key), * 'o' (object). */ - protected char mode; + protected char mode; /** * The comma flag determines if a comma should be output before the next * value. */ - private boolean comma; + private boolean comma; /** * The stack top index. A value of 0 indicates that the stack is empty. */ - private int top; + private int top; /** * Make a fresh JSONWriter. It can be used to build one JSON text. @@ -79,9 +81,11 @@ public class JSONWriter { /** * Append a value. * - * @param string A string value. + * @param string + * A string value. * @return this - * @throws JSONException If the value is out of sequence. + * @throws JSONException + * If the value is out of sequence. */ private JSONWriter append(final String string) throws JSONException { if (string == null) { @@ -93,7 +97,8 @@ public class JSONWriter { this.writer.write(','); } this.writer.write(string); - } catch (final IOException e) { + } + catch (final IOException e) { throw new JSONException(e); } if (this.mode == 'o') { @@ -111,10 +116,11 @@ public class JSONWriter { * endArray method must be called to mark the array's end. * * @return this - * @throws JSONException If the nesting is too deep, or if the object is - * started in the wrong place (for example as a key or after the - * end of the - * outermost array or object). + * @throws JSONException + * If the nesting is too deep, or if the object is + * started in the wrong place (for example as a key or after the + * end of the + * outermost array or object). */ public JSONWriter array() throws JSONException { if ((this.mode == 'i') || (this.mode == 'o') || (this.mode == 'a')) { @@ -129,10 +135,13 @@ public class JSONWriter { /** * End something. * - * @param mode Mode - * @param c Closing character + * @param mode + * Mode + * @param c + * Closing character * @return this - * @throws JSONException If unbalanced. + * @throws JSONException + * If unbalanced. */ private JSONWriter end(final char mode, final char c) throws JSONException { if (this.mode != mode) { @@ -141,7 +150,8 @@ public class JSONWriter { this.pop(mode); try { this.writer.write(c); - } catch (final IOException e) { + } + catch (final IOException e) { throw new JSONException(e); } this.comma = true; @@ -153,7 +163,8 @@ public class JSONWriter { * array. * * @return this - * @throws JSONException If incorrectly nested. + * @throws JSONException + * If incorrectly nested. */ public JSONWriter endArray() throws JSONException { return this.end('a', ']'); @@ -164,7 +175,8 @@ public class JSONWriter { * object. * * @return this - * @throws JSONException If incorrectly nested. + * @throws JSONException + * If incorrectly nested. */ public JSONWriter endObject() throws JSONException { return this.end('k', '}'); @@ -174,10 +186,12 @@ public class JSONWriter { * Append a key. The key will be associated with the next value. In an * object, every value must be preceded by a key. * - * @param string A key string. + * @param string + * A key string. * @return this - * @throws JSONException If the key is out of place. For example, keys - * do not belong in arrays or if the key is null. + * @throws JSONException + * If the key is out of place. For example, keys + * do not belong in arrays or if the key is null. */ public JSONWriter key(final String string) throws JSONException { if (string == null) { @@ -194,7 +208,8 @@ public class JSONWriter { this.comma = false; this.mode = 'o'; return this; - } catch (final IOException e) { + } + catch (final IOException e) { throw new JSONException(e); } } @@ -207,10 +222,11 @@ public class JSONWriter { * endObject method must be called to mark the object's end. * * @return this - * @throws JSONException If the nesting is too deep, or if the object is - * started in the wrong place (for example as a key or after the - * end of the - * outermost array or object). + * @throws JSONException + * If the nesting is too deep, or if the object is + * started in the wrong place (for example as a key or after the + * end of the + * outermost array or object). */ public JSONWriter object() throws JSONException { if (this.mode == 'i') { @@ -229,8 +245,10 @@ public class JSONWriter { /** * Pop an array or object scope. * - * @param c The scope to close. - * @throws JSONException If nesting is wrong. + * @param c + * The scope to close. + * @throws JSONException + * If nesting is wrong. */ private void pop(final char c) throws JSONException { if (this.top <= 0) { @@ -247,8 +265,10 @@ public class JSONWriter { /** * Push an array or object scope. * - * @param jo The scope to open. - * @throws JSONException If nesting is too deep. + * @param jo + * The scope to open. + * @throws JSONException + * If nesting is too deep. */ private void push(final JSONObject jo) throws JSONException { if (this.top >= maxdepth) { @@ -263,7 +283,8 @@ public class JSONWriter { * Append either the value true or the value false * . * - * @param b A boolean. + * @param b + * A boolean. * @return this * @throws JSONException */ @@ -274,9 +295,11 @@ public class JSONWriter { /** * Append a double value. * - * @param d A double. + * @param d + * A double. * @return this - * @throws JSONException If the number is not finite. + * @throws JSONException + * If the number is not finite. */ public JSONWriter value(final double d) throws JSONException { return this.value(new Double(d)); @@ -285,7 +308,8 @@ public class JSONWriter { /** * Append a long value. * - * @param l A long. + * @param l + * A long. * @return this * @throws JSONException */ @@ -296,11 +320,13 @@ public class JSONWriter { /** * Append an object value. * - * @param object The object to append. It can be null, or a Boolean, Number, - * String, JSONObject, or JSONArray, or an object that implements - * JSONString. + * @param object + * The object to append. It can be null, or a Boolean, Number, + * String, JSONObject, or JSONArray, or an object that implements + * JSONString. * @return this - * @throws JSONException If the value is out of sequence. + * @throws JSONException + * If the value is out of sequence. */ public JSONWriter value(final Object object) throws JSONException { return this.append(JSONObject.valueToString(object)); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/json/Kim.java b/PlotSquared/src/main/java/com/intellectualcrafters/json/Kim.java index f7feb59a8..41e1b15d2 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/json/Kim.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/json/Kim.java @@ -8,11 +8,8 @@ package com.intellectualcrafters.json; * than 3 bytes. Every byte contributes 7 bits to the character. ASCII is * unmodified. *

- * Kim UTF-8 - * one byte U+007F U+007F - * two bytes U+3FFF U+07FF - * three bytes U+10FFF U+FFFF - * four bytes U+10FFFF + * Kim UTF-8 one byte U+007F U+007F two bytes U+3FFF U+07FF three bytes U+10FFF + * U+FFFF four bytes U+10FFFF *

* Characters in the ranges U+0800..U+3FFF and U+10000..U+10FFFF will be one * byte smaller when encoded in Kim compared to UTF-8. @@ -20,12 +17,12 @@ package com.intellectualcrafters.json; * Kim is beneficial when using scripts such as Old South Arabian, Aramaic, * Avestan, Balinese, Batak, Bopomofo, Buginese, Buhid, Carian, Cherokee, * Coptic, Cyrillic, Deseret, Egyptian Hieroglyphs, Ethiopic, Georgian, - * Glagolitic, Gothic, Hangul Jamo, Hanunoo, Hiragana, Kanbun, Kaithi, - * Kannada, Katakana, Kharoshthi, Khmer, Lao, Lepcha, Limbu, Lycian, Lydian, - * Malayalam, Mandaic, Meroitic, Miao, Mongolian, Myanmar, New Tai Lue, - * Ol Chiki, Old Turkic, Oriya, Osmanya, Pahlavi, Parthian, Phags-Pa, - * Phoenician, Samaritan, Sharada, Sinhala, Sora Sompeng, Tagalog, Tagbanwa, - * Takri, Tai Le, Tai Tham, Tamil, Telugu, Thai, Tibetan, Tifinagh, UCAS. + * Glagolitic, Gothic, Hangul Jamo, Hanunoo, Hiragana, Kanbun, Kaithi, Kannada, + * Katakana, Kharoshthi, Khmer, Lao, Lepcha, Limbu, Lycian, Lydian, Malayalam, + * Mandaic, Meroitic, Miao, Mongolian, Myanmar, New Tai Lue, Ol Chiki, Old + * Turkic, Oriya, Osmanya, Pahlavi, Parthian, Phags-Pa, Phoenician, Samaritan, + * Sharada, Sinhala, Sora Sompeng, Tagalog, Tagbanwa, Takri, Tai Le, Tai Tham, + * Tamil, Telugu, Thai, Tibetan, Tifinagh, UCAS. *

* A kim object can be constructed from an ordinary UTF-16 string, or from a * byte array. A kim object can produce a UTF-16 string. @@ -42,26 +39,29 @@ public class Kim { * The number of bytes in the kim. The number of bytes can be as much as * three times the number of characters. */ - public int length = 0; + public int length = 0; /** * The byte array containing the kim's content. */ - private byte[] bytes = null; + private byte[] bytes = null; /** * The kim's hashcode, conforming to Java's hashcode conventions. */ - private int hashcode = 0; + private int hashcode = 0; /** * The memoization of toString(). */ - private String string = null; + private String string = null; /** * Make a kim from a portion of a byte array. * - * @param bytes A byte array. - * @param from The index of the first byte. - * @param thru The index of the last byte plus one. + * @param bytes + * A byte array. + * @param from + * The index of the first byte. + * @param thru + * The index of the last byte plus one. */ public Kim(final byte[] bytes, final int from, final int thru) { @@ -88,8 +88,10 @@ public class Kim { /** * Make a kim from a byte array. * - * @param bytes The byte array. - * @param length The number of bytes. + * @param bytes + * The byte array. + * @param length + * The number of bytes. */ public Kim(final byte[] bytes, final int length) { this(bytes, 0, length); @@ -99,9 +101,12 @@ public class Kim { * Make a new kim from a substring of an existing kim. The coordinates are * in byte units, not character units. * - * @param kim The source of bytes. - * @param from The point at which to take bytes. - * @param thru The point at which to stop taking bytes. + * @param kim + * The source of bytes. + * @param from + * The point at which to take bytes. + * @param thru + * The point at which to stop taking bytes. */ public Kim(final Kim kim, final int from, final int thru) { this(kim.bytes, from, thru); @@ -110,8 +115,10 @@ public class Kim { /** * Make a kim from a string. * - * @param string The string. - * @throws JSONException if surrogate pair mismatch. + * @param string + * The string. + * @throws JSONException + * if surrogate pair mismatch. */ public Kim(final String string) throws JSONException { final int stringLength = string.length(); @@ -126,9 +133,11 @@ public class Kim { final int c = string.charAt(i); if (c <= 0x7F) { this.length += 1; - } else if (c <= 0x3FFF) { + } + else if (c <= 0x3FFF) { this.length += 2; - } else { + } + else { if ((c >= 0xD800) && (c <= 0xDFFF)) { i += 1; final int d = string.charAt(i); @@ -155,7 +164,8 @@ public class Kim { sum += character; this.hashcode += sum; at += 1; - } else if (character <= 0x3FFF) { + } + else if (character <= 0x3FFF) { b = 0x80 | (character >>> 7); this.bytes[at] = (byte) b; sum += b; @@ -166,7 +176,8 @@ public class Kim { sum += b; this.hashcode += sum; at += 1; - } else { + } + else { if ((character >= 0xD800) && (character <= 0xDBFF)) { i += 1; character = (((character & 0x3FF) << 10) | (string.charAt(i) & 0x3FF)) + 65536; @@ -196,9 +207,11 @@ public class Kim { * Returns the number of bytes needed to contain the character in Kim * format. * - * @param character a Unicode character between 0 and 0x10FFFF. + * @param character + * a Unicode character between 0 and 0x10FFFF. * @return 1, 2, or 3 - * @throws JSONException if the character is not representable in a kim. + * @throws JSONException + * if the character is not representable in a kim. */ public static int characterSize(final int character) throws JSONException { if ((character < 0) || (character > 0x10FFFF)) { @@ -212,8 +225,10 @@ public class Kim { * values and ranges from 0 to length - 1. The index of the next character * is at index + Kim.characterSize(kim.characterAt(index)). * - * @param at the index of the char value. The first character is at 0. - * @throws JSONException if at does not point to a valid character. + * @param at + * the index of the char value. The first character is at 0. + * @throws JSONException + * if at does not point to a valid character. * @returns a Unicode character between 0 and 0x10FFFF. */ public int characterAt(final int at) throws JSONException { @@ -228,7 +243,8 @@ public class Kim { if (character > 0x7F) { return character; } - } else { + } + else { final int c2 = get(at + 2); character = ((c & 0x7F) << 14) | ((c1 & 0x7F) << 7) | c2; if (((c2 & 0x80) == 0) && (character > 0x3FFF) && (character <= 0x10FFFF) && ((character < 0xD800) || (character > 0xDFFF))) { @@ -241,8 +257,10 @@ public class Kim { /** * Copy the contents of this kim to a byte array. * - * @param bytes A byte array of sufficient size. - * @param at The position within the byte array to take the byes. + * @param bytes + * A byte array of sufficient size. + * @param at + * The position within the byte array to take the byes. * @return The position immediately after the copy. */ public int copy(final byte[] bytes, final int at) { @@ -254,9 +272,10 @@ public class Kim { * Two kim objects containing exactly the same bytes in the same order are * equal to each other. * - * @param obj the other kim with which to compare. + * @param obj + * the other kim with which to compare. * @returns true if this and obj are both kim objects containing identical - * byte sequences. + * byte sequences. */ @Override public boolean equals(final Object obj) { @@ -276,9 +295,11 @@ public class Kim { /** * Get a byte from a kim. * - * @param at The position of the byte. The first byte is at 0. + * @param at + * The position of the byte. The first byte is at 0. * @return The byte. - * @throws JSONException if there is no byte at that position. + * @throws JSONException + * if there is no byte at that position. */ public int get(final int at) throws JSONException { if ((at < 0) || (at > this.length)) { @@ -301,7 +322,8 @@ public class Kim { * it could be less. * * @return The string. A kim memoizes its string representation. - * @throws JSONException if the kim is not valid. + * @throws JSONException + * if the kim is not valid. */ @Override public String toString() throws JSONException { @@ -314,7 +336,8 @@ public class Kim { if (c < 0x10000) { chars[length] = (char) c; length += 1; - } else { + } + else { chars[length] = (char) (0xD800 | ((c - 0x10000) >>> 10)); length += 1; chars[length] = (char) (0xDC00 | (c & 0x03FF)); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/json/Property.java b/PlotSquared/src/main/java/com/intellectualcrafters/json/Property.java index d97281ec7..cec8f38d0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/json/Property.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/json/Property.java @@ -36,7 +36,8 @@ public class Property { * Converts a property file object into a JSONObject. The property file * object is a table of name value pairs. * - * @param properties java.util.Properties + * @param properties + * java.util.Properties * @return JSONObject * @throws JSONException */ @@ -55,7 +56,8 @@ public class Property { /** * Converts the JSONObject into a property file object. * - * @param jo JSONObject + * @param jo + * JSONObject * @return java.util.Properties * @throws JSONException */ diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/json/XML.java b/PlotSquared/src/main/java/com/intellectualcrafters/json/XML.java index 3a0fc5cc7..1b83b2d76 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/json/XML.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/json/XML.java @@ -14,32 +14,32 @@ public class XML { /** * The Character '&'. */ - public static final Character AMP = '&'; + public static final Character AMP = '&'; /** * The Character '''. */ - public static final Character APOS = '\''; + public static final Character APOS = '\''; /** * The Character '!'. */ - public static final Character BANG = '!'; + public static final Character BANG = '!'; /** * The Character '='. */ - public static final Character EQ = '='; + public static final Character EQ = '='; /** * The Character '>'. */ - public static final Character GT = '>'; + public static final Character GT = '>'; /** * The Character '<'. */ - public static final Character LT = '<'; + public static final Character LT = '<'; /** * The Character '?'. @@ -49,7 +49,7 @@ public class XML { /** * The Character '"'. */ - public static final Character QUOT = '"'; + public static final Character QUOT = '"'; /** * The Character '/'. @@ -59,6 +59,7 @@ public class XML { /** * Replace special characters with XML escapes: *

+ * *

      * & (ampersand) is replaced by &amp;
      * < (less than) is replaced by &lt;
@@ -66,7 +67,8 @@ public class XML {
      * " (double quote) is replaced by &quot;
      * 
* - * @param string The string to be escaped. + * @param string + * The string to be escaped. * @return The escaped string. */ public static String escape(final String string) { @@ -100,7 +102,8 @@ public class XML { * Throw an exception if the string contains whitespace. * Whitespace is not allowed in tagNames and attributes. * - * @param string A string. + * @param string + * A string. * @throws JSONException */ public static void noSpace(final String string) throws JSONException { @@ -119,9 +122,12 @@ public class XML { /** * Scan the content following the named tag, attaching it to the context. * - * @param x The XMLTokener containing the source string. - * @param context The JSONObject that will include the new material. - * @param name The tag name. + * @param x + * The XMLTokener containing the source string. + * @param context + * The JSONObject that will include the new material. + * @param name + * The tag name. * @return true if the close tag is processed. * @throws JSONException */ @@ -155,7 +161,8 @@ public class XML { return false; } x.back(); - } else if (c == '[') { + } + else if (c == '[') { token = x.nextToken(); if ("CDATA".equals(token)) { if (x.next() == '[') { @@ -173,21 +180,25 @@ public class XML { token = x.nextMeta(); if (token == null) { throw x.syntaxError("Missing '>' after ' 0); return false; - } else if (token == QUEST) { + } + else if (token == QUEST) { // "); return false; - } else if (token == SLASH) { + } + else if (token == SLASH) { // Close tag - } else if (token == SLASH) { + } + else if (token == SLASH) { if (x.nextToken() != GT) { throw x.syntaxError("Misshaped tag"); } if (jsonobject.length() > 0) { context.accumulate(tagName, jsonobject); - } else { + } + else { context.accumulate(tagName, ""); } return false; // Content, between <...> and - } else if (token == GT) { - for (; ; ) { + } + else if (token == GT) { + for (;;) { token = x.nextContent(); if (token == null) { if (tagName != null) { throw x.syntaxError("Unclosed tag " + tagName); } return false; - } else if (token instanceof String) { + } + else if (token instanceof String) { string = (String) token; if (string.length() > 0) { jsonobject.accumulate("content", XML.stringToValue(string)); @@ -264,20 +282,24 @@ public class XML { // Nested element - } else if (token == LT) { + } + else if (token == LT) { if (parse(x, jsonobject, tagName)) { if (jsonobject.length() == 0) { context.accumulate(tagName, ""); - } else if ((jsonobject.length() == 1) && (jsonobject.opt("content") != null)) { + } + else if ((jsonobject.length() == 1) && (jsonobject.opt("content") != null)) { context.accumulate(tagName, jsonobject.opt("content")); - } else { + } + else { context.accumulate(tagName, jsonobject); } return false; } } } - } else { + } + else { throw x.syntaxError("Misshaped tag"); } } @@ -291,7 +313,8 @@ public class XML { * convert plus forms, octal forms, hex forms, or E forms lacking decimal * points. * - * @param string A String. + * @param string + * A String. * @return A simple JSON value. */ public static Object stringToValue(final String string) { @@ -317,13 +340,15 @@ public class XML { return value; } } - } catch (final Exception ignore) { + } + catch (final Exception ignore) { try { final Double value = new Double(string); if (value.toString().equals(string)) { return value; } - } catch (final Exception ignoreAlso) { + } + catch (final Exception ignoreAlso) { } } return string; @@ -340,7 +365,8 @@ public class XML { * text may be placed in a "content" member. Comments, prologs, DTDs, and * <[ [ ]]> are ignored. * - * @param string The source string. + * @param string + * The source string. * @return A JSONObject containing the structured data from the XML string. * @throws JSONException */ @@ -356,7 +382,8 @@ public class XML { /** * Convert a JSONObject into a well-formed, element-normal XML string. * - * @param object A JSONObject. + * @param object + * A JSONObject. * @return A string. * @throws JSONException */ @@ -367,8 +394,10 @@ public class XML { /** * Convert a JSONObject into a well-formed, element-normal XML string. * - * @param object A JSONObject. - * @param tagName The optional name of the enclosing tag. + * @param object + * A JSONObject. + * @param tagName + * The optional name of the enclosing tag. * @return A string. * @throws JSONException */ @@ -416,13 +445,15 @@ public class XML { } sb.append(escape(ja.get(i).toString())); } - } else { + } + else { sb.append(escape(value.toString())); } // Emit an array of similar keys - } else if (value instanceof JSONArray) { + } + else if (value instanceof JSONArray) { ja = (JSONArray) value; length = ja.length(); for (i = 0; i < length; i += 1) { @@ -435,18 +466,21 @@ public class XML { sb.append("'); - } else { + } + else { sb.append(toString(value, key)); } } - } else if ("".equals(value)) { + } + else if ("".equals(value)) { sb.append('<'); sb.append(key); sb.append("/>"); // Emit a new tag - } else { + } + else { sb.append(toString(value, key)); } } @@ -464,7 +498,8 @@ public class XML { // a place // where XML is lacking, synthesize an element. - } else { + } + else { if (object.getClass().isArray()) { object = new JSONArray(object); } @@ -475,7 +510,8 @@ public class XML { sb.append(toString(ja.opt(i), tagName == null ? "array" : tagName)); } return sb.toString(); - } else { + } + else { string = (object == null) ? "null" : escape(object.toString()); return (tagName == null) ? "\"" + string + "\"" : (string.length() == 0) ? "<" + tagName + "/>" : "<" + tagName + ">" + string + ""; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/json/XMLTokener.java b/PlotSquared/src/main/java/com/intellectualcrafters/json/XMLTokener.java index 4094315c2..1e4896e7e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/json/XMLTokener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/json/XMLTokener.java @@ -27,7 +27,8 @@ public class XMLTokener extends JSONTokener { /** * Construct an XMLTokener from a string. * - * @param s A source string. + * @param s + * A source string. */ public XMLTokener(final String s) { super(s); @@ -37,13 +38,14 @@ public class XMLTokener extends JSONTokener { * Get the text in the CDATA block. * * @return The string up to the ]]>. - * @throws JSONException If the ]]> is not found. + * @throws JSONException + * If the ]]> is not found. */ public String nextCDATA() throws JSONException { char c; int i; final StringBuilder sb = new StringBuilder(); - for (; ; ) { + for (;;) { c = next(); if (end()) { throw syntaxError("Unclosed CDATA"); @@ -80,14 +82,15 @@ public class XMLTokener extends JSONTokener { return XML.LT; } sb = new StringBuilder(); - for (; ; ) { + for (;;) { if ((c == '<') || (c == 0)) { back(); return sb.toString().trim(); } if (c == '&') { sb.append(nextEntity(c)); - } else { + } + else { sb.append(c); } c = next(); @@ -98,19 +101,23 @@ public class XMLTokener extends JSONTokener { * Return the next entity. These entities are translated to Characters: * & ' > < ". * - * @param ampersand An ampersand character. + * @param ampersand + * An ampersand character. * @return A Character or an entity String if the entity is not recognized. - * @throws JSONException If missing ';' in XML entity. + * @throws JSONException + * If missing ';' in XML entity. */ public Object nextEntity(final char ampersand) throws JSONException { final StringBuilder sb = new StringBuilder(); - for (; ; ) { + for (;;) { final char c = next(); if (Character.isLetterOrDigit(c) || (c == '#')) { sb.append(Character.toLowerCase(c)); - } else if (c == ';') { + } + else if (c == ';') { break; - } else { + } + else { throw syntaxError("Missing ';' in XML entity: &" + sb); } } @@ -124,11 +131,12 @@ public class XMLTokener extends JSONTokener { * and structures. * * @return Syntax characters (< > / = ! ?) are returned as - * Character, and strings and names are returned as Boolean. We - * don't care - * what the values actually are. - * @throws JSONException If a string is not properly closed or if the XML - * is badly structured. + * Character, and strings and names are returned as Boolean. We + * don't care + * what the values actually are. + * @throws JSONException + * If a string is not properly closed or if the XML + * is badly structured. */ public Object nextMeta() throws JSONException { char c; @@ -155,7 +163,7 @@ public class XMLTokener extends JSONTokener { case '"': case '\'': q = c; - for (; ; ) { + for (;;) { c = next(); if (c == 0) { throw syntaxError("Unterminated string"); @@ -165,7 +173,7 @@ public class XMLTokener extends JSONTokener { } } default: - for (; ; ) { + for (;;) { c = next(); if (Character.isWhitespace(c)) { return Boolean.TRUE; @@ -194,7 +202,8 @@ public class XMLTokener extends JSONTokener { * name. * * @return a String or a Character. - * @throws JSONException If the XML is not well formed. + * @throws JSONException + * If the XML is not well formed. */ public Object nextToken() throws JSONException { char c; @@ -220,13 +229,13 @@ public class XMLTokener extends JSONTokener { case '?': return XML.QUEST; - // Quoted string + // Quoted string case '"': case '\'': q = c; sb = new StringBuilder(); - for (; ; ) { + for (;;) { c = next(); if (c == 0) { throw syntaxError("Unterminated string"); @@ -236,7 +245,8 @@ public class XMLTokener extends JSONTokener { } if (c == '&') { sb.append(nextEntity(c)); - } else { + } + else { sb.append(c); } } @@ -245,7 +255,7 @@ public class XMLTokener extends JSONTokener { // Name sb = new StringBuilder(); - for (; ; ) { + for (;;) { sb.append(c); c = next(); if (Character.isWhitespace(c)) { @@ -277,7 +287,8 @@ public class XMLTokener extends JSONTokener { * If it is not found, we are left at the end of the source with a result of * false. * - * @param to A string to skip past. + * @param to + * A string to skip past. * @throws JSONException */ public boolean skipPast(final String to) throws JSONException { @@ -304,7 +315,7 @@ public class XMLTokener extends JSONTokener { /* We will loop, possibly for all of the remaining characters. */ - for (; ; ) { + for (;;) { j = offset; b = true; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java index 9e9da3ab9..819380ead 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java @@ -21,42 +21,6 @@ package com.intellectualcrafters.plot; -import com.intellectualcrafters.plot.commands.Auto; -import com.intellectualcrafters.plot.commands.MainCommand; -import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.config.ConfigurationNode; -import com.intellectualcrafters.plot.config.Settings; -import com.intellectualcrafters.plot.database.*; -import com.intellectualcrafters.plot.events.PlayerTeleportToPlotEvent; -import com.intellectualcrafters.plot.events.PlotDeleteEvent; -import com.intellectualcrafters.plot.flag.AbstractFlag; -import com.intellectualcrafters.plot.flag.FlagManager; -import com.intellectualcrafters.plot.generator.DefaultPlotManager; -import com.intellectualcrafters.plot.generator.DefaultPlotWorld; -import com.intellectualcrafters.plot.generator.WorldGenerator; -import com.intellectualcrafters.plot.listeners.*; -import com.intellectualcrafters.plot.object.*; -import com.intellectualcrafters.plot.util.*; -import com.intellectualcrafters.plot.util.Logger.LogLevel; -import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper; -import com.intellectualcrafters.plot.uuid.PlotUUIDSaver; -import com.intellectualcrafters.plot.uuid.UUIDSaver; -import com.sk89q.worldedit.bukkit.WorldEditPlugin; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; - -import me.confuser.barapi.BarAPI; -import net.milkbowl.vault.economy.Economy; - -import org.bukkit.*; -import org.bukkit.command.PluginCommand; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.generator.ChunkGenerator; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.RegisteredServiceProvider; -import org.bukkit.plugin.java.JavaPlugin; - import java.io.File; import java.io.FileWriter; import java.io.IOException; @@ -64,10 +28,85 @@ import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; +import java.util.Set; +import java.util.UUID; import java.util.concurrent.TimeUnit; +import me.confuser.barapi.BarAPI; +import net.milkbowl.vault.economy.Economy; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Chunk; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.OfflinePlayer; +import org.bukkit.World; +import org.bukkit.command.PluginCommand; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.generator.ChunkGenerator; +import org.bukkit.plugin.RegisteredServiceProvider; +import org.bukkit.plugin.java.JavaPlugin; + +import com.intellectualcrafters.plot.commands.Auto; +import com.intellectualcrafters.plot.commands.MainCommand; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.ConfigurationNode; +import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.database.MySQL; +import com.intellectualcrafters.plot.database.PlotMeConverter; +import com.intellectualcrafters.plot.database.SQLManager; +import com.intellectualcrafters.plot.database.SQLite; +import com.intellectualcrafters.plot.events.PlayerTeleportToPlotEvent; +import com.intellectualcrafters.plot.events.PlotDeleteEvent; +import com.intellectualcrafters.plot.flag.AbstractFlag; +import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.generator.DefaultPlotManager; +import com.intellectualcrafters.plot.generator.DefaultPlotWorld; +import com.intellectualcrafters.plot.generator.WorldGenerator; +import com.intellectualcrafters.plot.listeners.EntityListener; +import com.intellectualcrafters.plot.listeners.ForceFieldListener; +import com.intellectualcrafters.plot.listeners.InventoryListener; +import com.intellectualcrafters.plot.listeners.PlayerEvents; +import com.intellectualcrafters.plot.listeners.PlotListener; +import com.intellectualcrafters.plot.listeners.PlotPlusListener; +import com.intellectualcrafters.plot.listeners.WorldEditListener; +import com.intellectualcrafters.plot.listeners.WorldGuardListener; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotGenerator; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotManager; +import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.util.ConsoleColors; +import com.intellectualcrafters.plot.util.Lag; +import com.intellectualcrafters.plot.util.Logger; +import com.intellectualcrafters.plot.util.Logger.LogLevel; +import com.intellectualcrafters.plot.util.Metrics; +import com.intellectualcrafters.plot.util.PlayerFunctions; +import com.intellectualcrafters.plot.util.PlotHelper; +import com.intellectualcrafters.plot.util.SendChunk; +import com.intellectualcrafters.plot.util.SetBlockFast; +import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper; +import com.intellectualcrafters.plot.uuid.PlotUUIDSaver; +import com.intellectualcrafters.plot.uuid.UUIDSaver; +import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; + /** * PlotMain class. * @@ -76,22 +115,19 @@ import java.util.concurrent.TimeUnit; */ @SuppressWarnings("unused") public class PlotMain extends JavaPlugin { - private static PlotMain main = null; + private static PlotMain main = null; /** * Permission that allows for "everything" */ - public static final String ADMIN_PERMISSION = - "plots.admin"; + public static final String ADMIN_PERMISSION = "plots.admin"; /** * Storage version */ - public final static int storage_ver = - 1; + public final static int storage_ver = 1; /** * Boolean Flags (material) */ - public final static HashMap booleanFlags = - new HashMap<>(); + public final static HashMap booleanFlags = new HashMap<>(); /** * Initialize the material flags @@ -114,71 +150,63 @@ public class PlotMain extends JavaPlugin { /** * All loaded plot worlds */ - private final static HashMap worlds = - new HashMap<>(); + private final static HashMap worlds = new HashMap<>(); /** * All world managers */ - private final static HashMap managers = - new HashMap<>(); + private final static HashMap managers = new HashMap<>(); /** * settings.properties */ - public static File configFile; + public static File configFile; /** * The main configuration file */ - public static YamlConfiguration config; + public static YamlConfiguration config; /** * storage.properties */ - public static File storageFile; + public static File storageFile; /** * Contains storage options */ - public static YamlConfiguration storage; + public static YamlConfiguration storage; /** * MySQL Connection */ - public static Connection connection; + public static Connection connection; /** * WorldEdit object */ - public static WorldEditPlugin worldEdit = - null; + public static WorldEditPlugin worldEdit = null; /** * BarAPI object */ - public static BarAPI barAPI = - null; + public static BarAPI barAPI = null; /** * World Guard Object */ - public static WorldGuardPlugin worldGuard = - null; + public static WorldGuardPlugin worldGuard = null; /** * World Guard Listener */ - public static WorldGuardListener worldGuardListener = - null; + public static WorldGuardListener worldGuardListener = null; /** * Economy Object (vault) */ - public static Economy - economy; + public static Economy economy; /** * Use Economy? */ - public static boolean useEconomy = - false; + public static boolean useEconomy = false; /** * The UUID Saver */ - private static UUIDSaver uuidSaver; + private static UUIDSaver uuidSaver; /** * MySQL Object */ - private static MySQL mySQL; + private static MySQL mySQL; /** * List of all plots * DO NOT USE EXCEPT FOR DATABASE PURPOSES @@ -191,7 +219,7 @@ public class PlotMain extends JavaPlugin { public static MySQL getMySQL() { return mySQL; } - + /** * Check for expired plots */ @@ -202,7 +230,8 @@ public class PlotMain extends JavaPlugin { public void run() { try { checkExpired(plugin, true); - } catch (Exception e) { + } + catch (final Exception e) { e.printStackTrace(); } } @@ -213,9 +242,12 @@ public class PlotMain extends JavaPlugin { * Check a range of permissions e.g. 'plots.plot.<0-100>'
* Returns highest integer in range. * - * @param player to check - * @param stub to check - * @param range tp check + * @param player + * to check + * @param stub + * to check + * @param range + * tp check * @return permitted range */ public static int hasPermissionRange(final Player player, final String stub, final int range) { @@ -238,8 +270,10 @@ public class PlotMain extends JavaPlugin { * - Op has all permissions
* - checks for '*' nodes * - * @param player to check - * @param perms to check + * @param player + * to check + * @param perms + * to check * @return true of player has permissions */ public static boolean hasPermissions(final Player player, final String[] perms) { @@ -249,8 +283,9 @@ public class PlotMain extends JavaPlugin { } for (final String perm : perms) { boolean permitted = false; - if (player.hasPermission(perm)) + if (player.hasPermission(perm)) { permitted = true; + } else { final String[] nodes = perm.split("\\."); final StringBuilder n = new StringBuilder(); @@ -283,7 +318,8 @@ public class PlotMain extends JavaPlugin { /** * Set the uuid saver * - * @param saver new saver + * @param saver + * new saver * @see com.intellectualcrafters.plot.uuid.UUIDSaver */ public static void setUUIDSaver(final UUIDSaver saver) { @@ -295,8 +331,10 @@ public class PlotMain extends JavaPlugin { * - Op has all permissions
* - checks for '*' nodes * - * @param player to check - * @param perm to check + * @param player + * to check + * @param perm + * to check * @return true if player has the permission */ public static boolean hasPermission(final Player player, final String perm) { @@ -345,7 +383,8 @@ public class PlotMain extends JavaPlugin { } /** - * @param player player + * @param player + * player * @return Set Containing the players plots */ public static Set getPlots(final Player player) { @@ -364,8 +403,10 @@ public class PlotMain extends JavaPlugin { } /** - * @param world plot world - * @param player plot owner + * @param world + * plot world + * @param player + * plot owner * @return players plots */ public static Set getPlots(final World world, final Player player) { @@ -384,7 +425,8 @@ public class PlotMain extends JavaPlugin { /** * Get plots for the specified world * - * @param world A world, in which you want to search for plots + * @param world + * A world, in which you want to search for plots * @return HashMap containing Plot IDs and Plot Objects */ public static HashMap getPlots(final String world) { @@ -395,7 +437,8 @@ public class PlotMain extends JavaPlugin { } /** - * @param world plot world + * @param world + * plot world * @return plots in world */ public static HashMap getPlots(final World world) { @@ -409,7 +452,7 @@ public class PlotMain extends JavaPlugin { * get all plot worlds */ public static String[] getPlotWorlds() { - Set strings = worlds.keySet(); + final Set strings = worlds.keySet(); return (strings.toArray(new String[strings.size()])); } @@ -417,12 +460,13 @@ public class PlotMain extends JavaPlugin { * @return plots worlds */ public static String[] getPlotWorldsString() { - Set strings = plots.keySet(); + final Set strings = plots.keySet(); return strings.toArray(new String[strings.size()]); } /** - * @param world plotworld(?) + * @param world + * plotworld(?) * @return true if the world is a plotworld */ public static boolean isPlotWorld(final World world) { @@ -430,7 +474,8 @@ public class PlotMain extends JavaPlugin { } /** - * @param world plotworld(?) + * @param world + * plotworld(?) * @return true if the world is a plotworld */ public static boolean isPlotWorld(final String world) { @@ -438,7 +483,8 @@ public class PlotMain extends JavaPlugin { } /** - * @param world World to get manager for + * @param world + * World to get manager for * @return manager for world */ public static PlotManager getPlotManager(final World world) { @@ -449,7 +495,8 @@ public class PlotMain extends JavaPlugin { } /** - * @param world world + * @param world + * world * @return PlotManager */ public static PlotManager getPlotManager(final String world) { @@ -460,7 +507,8 @@ public class PlotMain extends JavaPlugin { } /** - * @param world to search + * @param world + * to search * @return PlotWorld object */ public static PlotWorld getWorldSettings(final World world) { @@ -471,7 +519,8 @@ public class PlotMain extends JavaPlugin { } /** - * @param world to search + * @param world + * to search * @return PlotWorld object */ public static PlotWorld getWorldSettings(final String world) { @@ -482,20 +531,24 @@ public class PlotMain extends JavaPlugin { } /** - * @param world world to search + * @param world + * world to search * @return set containing the plots for a world */ public static Plot[] getWorldPlots(final World world) { - Collection values = plots.get(world.getName()).values(); + final Collection values = plots.get(world.getName()).values(); return (values.toArray(new Plot[values.size()])); } /** * Remove a plot * - * @param world The Plot World - * @param id The Plot ID - * @param callEvent Whether or not to call the PlotDeleteEvent + * @param world + * The Plot World + * @param id + * The Plot ID + * @param callEvent + * Whether or not to call the PlotDeleteEvent * @return true if successful, false if not */ public static boolean removePlot(final String world, final PlotId id, final boolean callEvent) { @@ -514,7 +567,8 @@ public class PlotMain extends JavaPlugin { /** * Replace the plot object with an updated version * - * @param plot plot object + * @param plot + * plot object */ public static void updatePlot(final Plot plot) { final String world = plot.world; @@ -546,8 +600,10 @@ public class PlotMain extends JavaPlugin { * - Add new plots to the end.
* - The task then only needs to go through the first few plots * - * @param plugin Plugin - * @param async Call async? + * @param plugin + * Plugin + * @param async + * Call async? */ private static void checkExpired(final JavaPlugin plugin, final boolean async) { if (async) { @@ -573,7 +629,8 @@ public class PlotMain extends JavaPlugin { Bukkit.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { event.setCancelled(true); - } else { + } + else { toDeletePlot.add(plot); } } @@ -592,7 +649,8 @@ public class PlotMain extends JavaPlugin { } } }); - } else { + } + else { for (final String world : getPlotWorldsString()) { if (PlotMain.plots.containsKey(world)) { for (final Plot plot : PlotMain.plots.get(world).values()) { @@ -601,7 +659,8 @@ public class PlotMain extends JavaPlugin { Bukkit.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { event.setCancelled(true); - } else { + } + else { DBFunc.delete(world, plot); } } @@ -632,12 +691,14 @@ public class PlotMain extends JavaPlugin { /** * Send a message to the console. * - * @param string message + * @param string + * message */ public static void sendConsoleSenderMessage(final String string) { if (getMain().getServer().getConsoleSender() == null) { System.out.println(ChatColor.stripColor(ConsoleColors.fromString(string))); - } else { + } + else { getMain().getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', string)); } } @@ -645,9 +706,12 @@ public class PlotMain extends JavaPlugin { /** * Teleport a player to a plot * - * @param player Player to teleport - * @param from Previous Location - * @param plot Plot to teleport to + * @param player + * Player to teleport + * @param from + * Previous Location + * @param plot + * Plot to teleport to * @return true if successful */ public static boolean teleportPlayer(final Player player, final Location from, final Plot plot) { @@ -668,7 +732,8 @@ public class PlotMain extends JavaPlugin { /** * Send a message to the console * - * @param c message + * @param c + * message */ @SuppressWarnings("unused") public static void sendConsoleSenderMessage(final C c) { @@ -678,7 +743,8 @@ public class PlotMain extends JavaPlugin { /** * Broadcast publicly * - * @param c message + * @param c + * message */ public static void Broadcast(final C c) { Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', C.PREFIX.s() + c.s())); @@ -696,7 +762,8 @@ public class PlotMain extends JavaPlugin { /** * Broadcast a message to all admins * - * @param c message + * @param c + * message */ public static void BroadcastWithPerms(final C c) { for (final Player player : Bukkit.getOnlinePlayers()) { @@ -719,7 +786,8 @@ public class PlotMain extends JavaPlugin { /** * Ge the last played time * - * @param uuid UUID for the player + * @param uuid + * UUID for the player * @return last play time as a long */ public static long getLastPlayed(final UUID uuid) { @@ -751,7 +819,8 @@ public class PlotMain extends JavaPlugin { } config = YamlConfiguration.loadConfiguration(configFile); setupConfig(); - } catch (final Exception err_trans) { + } + catch (final Exception err_trans) { Logger.add(LogLevel.DANGER, "Failed to save settings.yml"); System.out.println("Failed to save settings.yml"); } @@ -764,14 +833,16 @@ public class PlotMain extends JavaPlugin { } storage = YamlConfiguration.loadConfiguration(storageFile); setupStorage(); - } catch (final Exception err_trans) { + } + catch (final Exception err_trans) { Logger.add(LogLevel.DANGER, "Failed to save storage.yml"); System.out.println("Failed to save storage.yml"); } try { config.save(configFile); storage.save(storageFile); - } catch (final IOException e) { + } + catch (final IOException e) { Logger.add(LogLevel.DANGER, "Configuration file saving failed"); e.printStackTrace(); } @@ -817,7 +888,7 @@ public class PlotMain extends JavaPlugin { public static void killAllEntities() { Bukkit.getScheduler().scheduleSyncRepeatingTask(getMain(), new Runnable() { long ticked = 0l; - long error = 0l; + long error = 0l; { sendConsoleSenderMessage(C.PREFIX.s() + "KillAllEntities started."); @@ -906,9 +977,11 @@ public class PlotMain extends JavaPlugin { // } } } - } catch (final Throwable e) { + } + catch (final Throwable e) { ++this.error; - } finally { + } + finally { ++this.ticked; } } @@ -923,7 +996,7 @@ public class PlotMain extends JavaPlugin { final int config_ver = 1; config.set("version", config_ver); final Map options = new HashMap<>(); - + options.put("auto_update", false); options.put("claim.max-auto-area", Settings.MAX_AUTO_SIZE); options.put("UUID.offline", Settings.OFFLINE_MODE); @@ -943,7 +1016,7 @@ public class PlotMain extends JavaPlugin { options.put("teleport.on_login", Settings.TELEPORT_ON_LOGIN); options.put("perm-based-mob-cap.enabled", Settings.MOB_CAP_ENABLED); options.put("perm-based-mob-cap.max", Settings.MOB_CAP); - options.put("worldedit.require-selection-in-mask",Settings.REQUIRE_SELECTION); + options.put("worldedit.require-selection-in-mask", Settings.REQUIRE_SELECTION); for (final Entry node : options.entrySet()) { if (!config.contains(node.getKey())) { @@ -967,16 +1040,17 @@ public class PlotMain extends JavaPlugin { Settings.MOB_CAP = config.getInt("perm-based-mob-cap.max"); Settings.MAX_PLOTS = config.getInt("max_plots"); Settings.SCHEMATIC_SAVE_PATH = config.getString("schematics.save_path"); - + Settings.OFFLINE_MODE = config.getBoolean("UUID.offline"); - + Settings.REQUIRE_SELECTION = config.getBoolean("worldedit.require-selection-in-mask"); } /** * Create a plotworld config section * - * @param plotworld World to create the section for + * @param plotworld + * World to create the section for */ @SuppressWarnings("unused") public static void createConfiguration(final PlotWorld plotworld) { @@ -994,7 +1068,8 @@ public class PlotMain extends JavaPlugin { try { config.save(PlotMain.configFile); - } catch (final IOException e) { + } + catch (final IOException e) { PlotMain.sendConsoleSenderMessage("&c[Warning] PlotSquared failed to save the configuration&7 (settings.yml may differ from the one in memory)\n - To force a save from console use /plots save"); } } @@ -1004,9 +1079,7 @@ public class PlotMain extends JavaPlugin { return; } - Set worlds = (config.contains("worlds") ? - config.getConfigurationSection("worlds").getKeys(false) : - new HashSet()); + final Set worlds = (config.contains("worlds") ? config.getConfigurationSection("worlds").getKeys(false) : new HashSet()); // Let's create these here instead final PlotWorld plotWorld; @@ -1015,12 +1088,9 @@ public class PlotMain extends JavaPlugin { final String path = "worlds." + world; if ((generator != null) && (generator instanceof PlotGenerator)) { - plotGenerator = - (PlotGenerator) generator; - plotWorld = - plotGenerator.getNewPlotWorld(world); - plotManager = - plotGenerator.getPlotManager(); + plotGenerator = (PlotGenerator) generator; + plotWorld = plotGenerator.getNewPlotWorld(world); + plotManager = plotGenerator.getPlotManager(); sendConsoleSenderMessage(C.PREFIX.s() + "&aDetected world load for '" + world + "'"); sendConsoleSenderMessage(C.PREFIX.s() + "&3 - generator: &7" + plotGenerator.getClass().getName()); sendConsoleSenderMessage(C.PREFIX.s() + "&3 - plotworld: &7" + plotWorld.getClass().getName()); @@ -1035,20 +1105,20 @@ public class PlotMain extends JavaPlugin { try { config.save(configFile); - } catch (final IOException e) { + } + catch (final IOException e) { e.printStackTrace(); } - //Now add it + // Now add it addPlotWorld(world, plotWorld, plotManager); - } else { + } + else { if (worlds.contains(world)) { sendConsoleSenderMessage("&cWorld '" + world + "' in settings.yml is not using PlotSquared generator!"); - plotWorld = - new DefaultPlotWorld(world); - plotManager = - new DefaultPlotManager(); + plotWorld = new DefaultPlotWorld(world); + plotManager = new DefaultPlotManager(); if (!config.contains(path)) { config.createSection(path); @@ -1059,7 +1129,8 @@ public class PlotMain extends JavaPlugin { try { config.save(configFile); - } catch (final IOException e) { + } + catch (final IOException e) { e.printStackTrace(); } @@ -1075,7 +1146,8 @@ public class PlotMain extends JavaPlugin { * use this method unless the required world is preconfigured in the * settings.yml * - * @param world to load + * @param world + * to load */ public static void loadWorld(final World world) { if (world == null) { @@ -1135,14 +1207,17 @@ public class PlotMain extends JavaPlugin { seconds = 1; try { amount = Integer.parseInt(values[0]); - } catch (final Exception e) { + } + catch (final Exception e) { return null; } - } else { + } + else { try { amount = Integer.parseInt(values[0]); seconds = Integer.parseInt(values[1]); - } catch (final Exception e) { + } + catch (final Exception e) { return null; } } @@ -1269,7 +1344,8 @@ public class PlotMain extends JavaPlugin { public String parseValue(final String value) { try { return Long.parseLong(value) + ""; - } catch (final Exception e) { + } + catch (final Exception e) { return null; } } @@ -1307,9 +1383,12 @@ public class PlotMain extends JavaPlugin { /** * Add a Plot world * - * @param world World to add - * @param plotworld PlotWorld Object - * @param manager Plot Manager for the new world + * @param world + * World to add + * @param plotworld + * PlotWorld Object + * @param manager + * Plot Manager for the new world */ public static void addPlotWorld(final String world, final PlotWorld plotworld, final PlotManager manager) { worlds.put(world, plotworld); @@ -1322,7 +1401,8 @@ public class PlotMain extends JavaPlugin { /** * Remove a plot world * - * @param world World to remove + * @param world + * World to remove */ public static void removePlotWorld(final String world) { plots.remove(world); @@ -1342,7 +1422,8 @@ public class PlotMain extends JavaPlugin { /** * Set all plots * - * @param plots New Plot LinkedHashMap + * @param plots + * New Plot LinkedHashMap */ public static void setAllPlotsRaw(final LinkedHashMap> plots) { PlotMain.plots = plots; @@ -1351,7 +1432,8 @@ public class PlotMain extends JavaPlugin { /** * Set all plots * - * @param plots New Plot HashMap + * @param plots + * New Plot HashMap */ public static void setAllPlotsRaw(final HashMap> plots) { PlotMain.plots = new LinkedHashMap<>(plots); @@ -1383,7 +1465,8 @@ public class PlotMain extends JavaPlugin { writer.write("Created at: " + new Date().toString() + "\n\n\n"); writer.close(); } - } catch (final IOException e) { + } + catch (final IOException e) { e.printStackTrace(); } @@ -1410,7 +1493,8 @@ public class PlotMain extends JavaPlugin { sendConsoleSenderMessage(C.PREFIX.s() + "&cURL: &6https://java.com/en/download/index.jsp"); Bukkit.getPluginManager().disablePlugin(this); return; - } else if (getJavaVersion() < 1.8) { + } + else if (getJavaVersion() < 1.8) { sendConsoleSenderMessage(C.PREFIX.s() + "&cIt's really recommended to run Java 1.8, as it increases performance"); } // Setup configuration @@ -1421,10 +1505,12 @@ public class PlotMain extends JavaPlugin { final Metrics metrics = new Metrics(this); metrics.start(); sendConsoleSenderMessage(C.PREFIX.s() + "&6Metrics enabled."); - } catch (final Exception e) { + } + catch (final Exception e) { sendConsoleSenderMessage(C.PREFIX.s() + "&cFailed to load up metrics."); } - } else { + } + else { // We should at least make them feel bad. sendConsoleSenderMessage("Using metrics will allow us to improve the plugin\nPlease consider it :)"); } @@ -1437,9 +1523,7 @@ public class PlotMain extends JavaPlugin { } // Add tables to this one, if we create more :D - final String[] tables = new String[]{ - "plot_trusted", "plot_ratings", "plot_comments" - }; + final String[] tables = new String[] { "plot_trusted", "plot_ratings", "plot_comments" }; // Use mysql? if (Settings.DB.USE_MYSQL) { @@ -1454,8 +1538,9 @@ public class PlotMain extends JavaPlugin { ResultSet res = meta.getTables(null, null, Settings.DB.PREFIX + "plot", null); if (!res.next()) { DBFunc.createTables("mysql", true); - } else { - for (String table : tables) { + } + else { + for (final String table : tables) { res = meta.getTables(null, null, Settings.DB.PREFIX + table, null); if (!res.next()) { DBFunc.createTables("mysql", false); @@ -1464,7 +1549,8 @@ public class PlotMain extends JavaPlugin { // We should not repeat our self :P } } - } catch (final Exception e) { + } + catch (final Exception e) { Logger.add(LogLevel.DANGER, "MySQL connection failed."); sendConsoleSenderMessage("&c[Plots] MySQL is not setup correctly. The plugin will disable itself."); if ((config == null) || config.getBoolean("debug")) { @@ -1482,7 +1568,8 @@ public class PlotMain extends JavaPlugin { else if (Settings.DB.USE_MONGO) { // DBFunc.dbManager = new MongoManager(); sendConsoleSenderMessage(C.PREFIX.s() + "MongoDB is not yet implemented"); - } else if (Settings.DB.USE_SQLITE) { + } + else if (Settings.DB.USE_SQLITE) { try { connection = new SQLite(this, Settings.DB.SQLITE_DB + ".db").openConnection(); { @@ -1491,8 +1578,9 @@ public class PlotMain extends JavaPlugin { ResultSet res = meta.getTables(null, null, Settings.DB.PREFIX + "plot", null); if (!res.next()) { DBFunc.createTables("sqlite", true); - } else { - for (String table : tables) { + } + else { + for (final String table : tables) { res = meta.getTables(null, null, Settings.DB.PREFIX + table, null); if (!res.next()) { DBFunc.createTables("sqlite", false); @@ -1500,7 +1588,8 @@ public class PlotMain extends JavaPlugin { } } } - } catch (final Exception e) { + } + catch (final Exception e) { Logger.add(LogLevel.DANGER, "SQLite connection failed"); sendConsoleSenderMessage(C.PREFIX.s() + "&cFailed to open SQLite connection. The plugin will disable itself."); sendConsoleSenderMessage("&9==== Here is an ugly stacktrace, if you are interested in those things ==="); @@ -1509,7 +1598,8 @@ public class PlotMain extends JavaPlugin { return; } plots = DBFunc.getPlots(); - } else { + } + else { Logger.add(LogLevel.DANGER, "No storage type is set."); sendConsoleSenderMessage(C.PREFIX + "&cNo storage type is set!"); getServer().getPluginManager().disablePlugin(this); @@ -1522,7 +1612,8 @@ public class PlotMain extends JavaPlugin { if (getServer().getPluginManager().getPlugin("PlotMe") != null) { try { new PlotMeConverter(this).runAsync(); - } catch (final Exception e) { + } + catch (final Exception e) { e.printStackTrace(); } } @@ -1531,9 +1622,7 @@ public class PlotMain extends JavaPlugin { final MainCommand command = new MainCommand(); final PluginCommand plotCommand = getCommand("plots"); plotCommand.setExecutor(command); - plotCommand.setAliases( - Arrays.asList("p", "ps", "plotme", "plot") - ); + plotCommand.setAliases(Arrays.asList("p", "ps", "plotme", "plot")); plotCommand.setTabCompleter(command); } if (Settings.MOB_CAP_ENABLED) { @@ -1564,7 +1653,8 @@ public class PlotMain extends JavaPlugin { PlotMain.sendConsoleSenderMessage("&cThis version of WorldEdit does not support PlotSquared."); PlotMain.sendConsoleSenderMessage("&cPlease use WorldEdit 6+"); PlotMain.sendConsoleSenderMessage("&c - http://builds.enginehub.org/job/worldedit"); - } else { + } + else { getServer().getPluginManager().registerEvents(new WorldEditListener(), this); } } @@ -1598,14 +1688,16 @@ public class PlotMain extends JavaPlugin { try { new SetBlockFast(); PlotHelper.canSetFast = true; - } catch (final Throwable e) { + } + catch (final Throwable e) { PlotHelper.canSetFast = false; } try { new SendChunk(); PlotHelper.canSendChunk = true; - } catch (final Throwable e) { + } + catch (final Throwable e) { PlotHelper.canSendChunk = false; } } @@ -1635,7 +1727,8 @@ public class PlotMain extends JavaPlugin { final public void onDisable() { try { C.saveTranslations(); - } catch (Exception e) { + } + catch (final Exception e) { sendConsoleSenderMessage("Failed to save translations"); Logger.add(LogLevel.DANGER, "Failed to save translations"); e.printStackTrace(); @@ -1643,13 +1736,15 @@ public class PlotMain extends JavaPlugin { Logger.add(LogLevel.GENERAL, "Logger disabled"); try { Logger.write(); - } catch (final IOException e1) { + } + catch (final IOException e1) { e1.printStackTrace(); } try { connection.close(); mySQL.closeConnection(); - } catch (NullPointerException | SQLException e) { + } + catch (NullPointerException | SQLException e) { if (connection != null) { Logger.add(LogLevel.DANGER, "Could not close mysql connection"); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java index b0063db7b..22114e90f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java @@ -21,6 +21,16 @@ package com.intellectualcrafters.plot.api; +import java.util.ArrayList; +import java.util.Set; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.commands.MainCommand; import com.intellectualcrafters.plot.commands.SubCommand; @@ -38,16 +48,6 @@ import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.UUIDHandler; import com.sun.istack.internal.NotNull; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -import java.util.ArrayList; -import java.util.Set; - /** * PlotSquared API * @@ -65,7 +65,7 @@ public class PlotAPI { * this permission node will allow the player * to use any part of the plugin, without limitations. */ - public static final String ADMIN_PERMISSION = "plots.admin"; + public static final String ADMIN_PERMISSION = "plots.admin"; /** * Plot Helper Class @@ -74,28 +74,31 @@ public class PlotAPI { * * @see com.intellectualcrafters.plot.util.PlotHelper */ - private static PlotHelper plotHelper; + private static PlotHelper plotHelper; /** * Player Functions * * General functions involving players, and plot worlds + * * @see com.intellectualcrafters.plot.util.PlayerFunctions */ - private static PlayerFunctions playerFunctions; + private static PlayerFunctions playerFunctions; /** * Flag Manager * * The manager which handles all flags + * * @see com.intellectualcrafters.plot.flag.FlagManager */ - private static FlagManager flagManager; + private static FlagManager flagManager; /** * Schematic Handler * * The handler which is used to create, and paste, schematics + * * @see com.intellectualcrafters.plot.util.SchematicHandler */ private static SchematicHandler schematicHandler; @@ -105,27 +108,30 @@ public class PlotAPI { * * @see com.intellectualcrafters.plot.config.C */ - private static C c; + private static C c; /** * PlotMain instance * * This is the instance that allows for most methods to be used. + * * @see com.intellectualcrafters.plot.PlotMain */ - private final PlotMain plotMain; + private final PlotMain plotMain; /** * Constructor. Insert any Plugin. * (Optimally the plugin that is accessing the method) * - * @param plugin Plugin used to access this method - * @throws com.intellectualcrafters.plot.util.PlotSquaredException if the program fails to fetch the PlotMain instance + * @param plugin + * Plugin used to access this method + * @throws com.intellectualcrafters.plot.util.PlotSquaredException + * if the program fails to fetch the PlotMain instance * @see com.intellectualcrafters.plot.PlotMain */ public PlotAPI(@NotNull final JavaPlugin plugin) { this.plotMain = PlotMain.getMain(); - if (plotMain == null) { + if (this.plotMain == null) { throw new PlotSquaredException(PlotSquaredException.PlotError.PLOTMAIN_NULL, "Failed to fetch the plotmain instance, Plot API for " + plugin.getName() + " will be disabled"); } } @@ -143,7 +149,8 @@ public class PlotAPI { /** * Return all plots for a player * - * @param player Player, whose plots to search for + * @param player + * Player, whose plots to search for * @return all plots that a player owns */ public Set getPlayerPlots(@NotNull final Player player) { @@ -153,12 +160,15 @@ public class PlotAPI { /** * Add a plot world * - * @param world World Name - * @param plotWorld Plot World Object - * @param manager World Manager + * @param world + * World Name + * @param plotWorld + * Plot World Object + * @param manager + * World Manager * @see com.intellectualcrafters.plot.PlotMain#addPlotWorld(String, - * com.intellectualcrafters.plot.object.PlotWorld, - * com.intellectualcrafters.plot.object.PlotManager) + * com.intellectualcrafters.plot.object.PlotWorld, + * com.intellectualcrafters.plot.object.PlotManager) */ public void addPlotWorld(@NotNull final String world, @NotNull final PlotWorld plotWorld, @NotNull final PlotManager manager) { PlotMain.addPlotWorld(world, plotWorld, manager); @@ -247,7 +257,8 @@ public class PlotAPI { * Get the plot manager for a world. - Most of these methods can be accessed * through the PlotHelper * - * @param world Which manager to get + * @param world + * Which manager to get * @return PlotManager * @see com.intellectualcrafters.plot.object.PlotManager * @see PlotMain#getPlotManager(org.bukkit.World) @@ -260,7 +271,8 @@ public class PlotAPI { * Get the plot manager for a world. - Contains useful low level methods for * plot merging, clearing, and tessellation * - * @param world Plot World + * @param world + * Plot World * @return PlotManager * @see PlotMain#getPlotManager(String) * @see com.intellectualcrafters.plot.object.PlotManager @@ -274,9 +286,10 @@ public class PlotAPI { * will need to downcast for the specific settings a Generator has. e.g. * DefaultPlotWorld class implements PlotWorld * - * @param world (to get settings of) + * @param world + * (to get settings of) * @return PlotWorld class for that world ! will return null if not a plot - * world world + * world world * @see PlotMain#getWorldSettings(org.bukkit.World) * @see com.intellectualcrafters.plot.object.PlotWorld */ @@ -287,9 +300,10 @@ public class PlotAPI { /** * Get the settings for a world (settings bundled in PlotWorld class) * - * @param world (to get settings of) + * @param world + * (to get settings of) * @return PlotWorld class for that world ! will return null if not a plot - * world world + * world world * @see PlotMain#getWorldSettings(String) * @see com.intellectualcrafters.plot.object.PlotWorld */ @@ -300,9 +314,12 @@ public class PlotAPI { /** * Send a message to a player. * - * @param player Player that will receive the message - * @param c (Caption) - * @see com.intellectualcrafters.plot.util.PlayerFunctions#sendMessage(org.bukkit.entity.Player, com.intellectualcrafters.plot.config.C, String...) + * @param player + * Player that will receive the message + * @param c + * (Caption) + * @see com.intellectualcrafters.plot.util.PlayerFunctions#sendMessage(org.bukkit.entity.Player, + * com.intellectualcrafters.plot.config.C, String...) */ public void sendMessage(@NotNull final Player player, @NotNull final C c) { PlayerFunctions.sendMessage(player, c); @@ -311,9 +328,12 @@ public class PlotAPI { /** * Send a message to a player. - Supports color codes * - * @param player Player that will receive the message - * @param string The message - * @see com.intellectualcrafters.plot.util.PlayerFunctions#sendMessage(org.bukkit.entity.Player, String) + * @param player + * Player that will receive the message + * @param string + * The message + * @see com.intellectualcrafters.plot.util.PlayerFunctions#sendMessage(org.bukkit.entity.Player, + * String) */ public void sendMessage(@NotNull final Player player, @NotNull final String string) { PlayerFunctions.sendMessage(player, string); @@ -322,7 +342,8 @@ public class PlotAPI { /** * Send a message to the console. - Supports color codes * - * @param msg Message that should be sent to the console + * @param msg + * Message that should be sent to the console * @see PlotMain#sendConsoleSenderMessage(String) */ public void sendConsoleMessage(@NotNull final String msg) { @@ -332,7 +353,8 @@ public class PlotAPI { /** * Send a message to the console * - * @param c (Caption) + * @param c + * (Caption) * @see #sendConsoleMessage(String) * @see com.intellectualcrafters.plot.config.C */ @@ -343,7 +365,8 @@ public class PlotAPI { /** * Register a flag for use in plots * - * @param flag Flag that should be registered + * @param flag + * Flag that should be registered * @see com.intellectualcrafters.plot.flag.FlagManager#addFlag(com.intellectualcrafters.plot.flag.AbstractFlag) * @see com.intellectualcrafters.plot.flag.AbstractFlag */ @@ -365,11 +388,15 @@ public class PlotAPI { /** * Get a plot based on the ID * - * @param world World in which the plot is located - * @param x Plot Location X Co-ord - * @param z Plot Location Z Co-ord + * @param world + * World in which the plot is located + * @param x + * Plot Location X Co-ord + * @param z + * Plot Location Z Co-ord * @return plot, null if ID is wrong - * @see PlotHelper#getPlot(org.bukkit.World, com.intellectualcrafters.plot.object.PlotId) + * @see PlotHelper#getPlot(org.bukkit.World, + * com.intellectualcrafters.plot.object.PlotId) * @see com.intellectualcrafters.plot.object.Plot */ public Plot getPlot(@NotNull final World world, final int x, final int z) { @@ -379,7 +406,8 @@ public class PlotAPI { /** * Get a plot based on the location * - * @param l The location that you want to to retrieve the plot from + * @param l + * The location that you want to to retrieve the plot from * @return plot if found, otherwise it creates a temporary plot- * @see PlotHelper#getCurrentPlot(org.bukkit.Location) * @see com.intellectualcrafters.plot.object.Plot @@ -391,7 +419,8 @@ public class PlotAPI { /** * Get a plot based on the player location * - * @param player Get the current plot for the player location + * @param player + * Get the current plot for the player location * @return plot if found, otherwise it creates a temporary plot * @see #getPlot(org.bukkit.Location) * @see com.intellectualcrafters.plot.object.Plot @@ -403,7 +432,8 @@ public class PlotAPI { /** * Check whether or not a player has a plot * - * @param player Player that you want to check for + * @param player + * Player that you want to check for * @return true if player has a plot, false if not. * @see #getPlots(org.bukkit.World, org.bukkit.entity.Player, boolean) */ @@ -414,8 +444,10 @@ public class PlotAPI { /** * Get all plots for the player * - * @param plr to search for - * @param just_owner should we just search for owner? Or with rights? + * @param plr + * to search for + * @param just_owner + * should we just search for owner? Or with rights? * @see com.intellectualcrafters.plot.object.Plot */ public Plot[] getPlots(@NotNull final World world, @NotNull final Player plr, final boolean just_owner) { @@ -425,7 +457,8 @@ public class PlotAPI { if ((plot.owner != null) && (plot.owner == UUIDHandler.getUUID(plr))) { pPlots.add(plot); } - } else { + } + else { if (plot.hasRights(plr)) { pPlots.add(plot); } @@ -437,7 +470,8 @@ public class PlotAPI { /** * Get all plots for the world * - * @param world to get plots of + * @param world + * to get plots of * @return Plot[] - array of plot objects in world * @see PlotMain#getWorldPlots(org.bukkit.World) * @see com.intellectualcrafters.plot.object.Plot @@ -459,7 +493,8 @@ public class PlotAPI { /** * Get if plot world * - * @param world (to check if plot world) + * @param world + * (to check if plot world) * @return boolean (if plot world or not) * @see com.intellectualcrafters.plot.PlotMain#isPlotWorld(org.bukkit.World) */ @@ -470,25 +505,31 @@ public class PlotAPI { /** * Get plot locations * - * @param p Plot that you want to get the locations for + * @param p + * Plot that you want to get the locations for * @return [0] = bottomLc, [1] = topLoc, [2] = home - * @see com.intellectualcrafters.plot.util.PlotHelper#getPlotBottomLoc(org.bukkit.World, com.intellectualcrafters.plot.object.PlotId) - * @see com.intellectualcrafters.plot.util.PlotHelper#getPlotTopLoc(org.bukkit.World, com.intellectualcrafters.plot.object.PlotId) - * @see com.intellectualcrafters.plot.util.PlotHelper#getPlotHome(org.bukkit.World, com.intellectualcrafters.plot.object.Plot) + * @see com.intellectualcrafters.plot.util.PlotHelper#getPlotBottomLoc(org.bukkit.World, + * com.intellectualcrafters.plot.object.PlotId) + * @see com.intellectualcrafters.plot.util.PlotHelper#getPlotTopLoc(org.bukkit.World, + * com.intellectualcrafters.plot.object.PlotId) + * @see com.intellectualcrafters.plot.util.PlotHelper#getPlotHome(org.bukkit.World, + * com.intellectualcrafters.plot.object.Plot) * @see com.intellectualcrafters.plot.object.PlotHomePosition * @see com.intellectualcrafters.plot.object.Plot */ public Location[] getLocations(@NotNull final Plot p) { final World world = Bukkit.getWorld(p.world); - return new Location[]{PlotHelper.getPlotBottomLoc(world, p.id), PlotHelper.getPlotTopLoc(world, p.id), PlotHelper.getPlotHome(world, p.id)}; + return new Location[] { PlotHelper.getPlotBottomLoc(world, p.id), PlotHelper.getPlotTopLoc(world, p.id), PlotHelper.getPlotHome(world, p.id) }; } /** * Get home location * - * @param p Plot that you want to get the location for + * @param p + * Plot that you want to get the location for * @return plot bottom location - * @see com.intellectualcrafters.plot.util.PlotHelper#getPlotHome(org.bukkit.World, com.intellectualcrafters.plot.object.Plot) + * @see com.intellectualcrafters.plot.util.PlotHelper#getPlotHome(org.bukkit.World, + * com.intellectualcrafters.plot.object.Plot) * @see com.intellectualcrafters.plot.object.PlotHomePosition * @see com.intellectualcrafters.plot.object.Plot */ @@ -499,9 +540,11 @@ public class PlotAPI { /** * Get Bottom Location (min, min, min) * - * @param p Plot that you want to get the location for + * @param p + * Plot that you want to get the location for * @return plot bottom location - * @see com.intellectualcrafters.plot.util.PlotHelper#getPlotBottomLoc(org.bukkit.World, com.intellectualcrafters.plot.object.PlotId) + * @see com.intellectualcrafters.plot.util.PlotHelper#getPlotBottomLoc(org.bukkit.World, + * com.intellectualcrafters.plot.object.PlotId) * @see com.intellectualcrafters.plot.object.Plot */ public Location getBottomLocation(@NotNull final Plot p) { @@ -512,9 +555,11 @@ public class PlotAPI { /** * Get Top Location (max, max, max) * - * @param p Plot that you want to get the location for + * @param p + * Plot that you want to get the location for * @return plot top location - * @see PlotHelper#getPlotTopLoc(org.bukkit.World, com.intellectualcrafters.plot.object.PlotId) + * @see PlotHelper#getPlotTopLoc(org.bukkit.World, + * com.intellectualcrafters.plot.object.PlotId) * @see com.intellectualcrafters.plot.object.Plot */ public Location getTopLocation(@NotNull final Plot p) { @@ -525,7 +570,8 @@ public class PlotAPI { /** * Check whether or not a player is in a plot * - * @param player who we're checking for + * @param player + * who we're checking for * @return true if the player is in a plot, false if not- * @see com.intellectualcrafters.plot.util.PlayerFunctions#isInPlot(org.bukkit.entity.Player) */ @@ -536,7 +582,8 @@ public class PlotAPI { /** * Register a subcommand * - * @param c SubCommand, that we want to register + * @param c + * SubCommand, that we want to register * @see com.intellectualcrafters.plot.commands.MainCommand#subCommands * @see com.intellectualcrafters.plot.commands.SubCommand */ @@ -557,10 +604,13 @@ public class PlotAPI { /** * Get the player plot count * - * @param world Specify the world we want to select the plots from - * @param player Player, for whom we're getting the plot count + * @param world + * Specify the world we want to select the plots from + * @param player + * Player, for whom we're getting the plot count * @return the number of plots the player has - * @see com.intellectualcrafters.plot.util.PlayerFunctions#getPlayerPlotCount(org.bukkit.World, org.bukkit.entity.Player) + * @see com.intellectualcrafters.plot.util.PlayerFunctions#getPlayerPlotCount(org.bukkit.World, + * org.bukkit.entity.Player) */ public int getPlayerPlotCount(@NotNull final World world, @NotNull final Player player) { return PlayerFunctions.getPlayerPlotCount(world, player); @@ -569,10 +619,13 @@ public class PlotAPI { /** * Get a collection containing the players plots * - * @param world Specify the world we want to select the plots from - * @param player Player, for whom we're getting the plots + * @param world + * Specify the world we want to select the plots from + * @param player + * Player, for whom we're getting the plots * @return a set containing the players plots - * @see com.intellectualcrafters.plot.util.PlayerFunctions#getPlayerPlots(org.bukkit.World, org.bukkit.entity.Player) + * @see com.intellectualcrafters.plot.util.PlayerFunctions#getPlayerPlots(org.bukkit.World, + * org.bukkit.entity.Player) * @see com.intellectualcrafters.plot.object.Plot */ public Set getPlayerPlots(@NotNull final World world, @NotNull final Player player) { @@ -582,7 +635,9 @@ public class PlotAPI { /** * Get the numbers of plots, which the player is able to build in * - * @param player Player, for whom we're getting the plots (trusted, helper and owner) + * @param player + * Player, for whom we're getting the plots (trusted, helper and + * owner) * @return the number of allowed plots * @see com.intellectualcrafters.plot.util.PlayerFunctions#getAllowedPlots(org.bukkit.entity.Player) */ diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java index 40c05e706..535c21a2b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java @@ -21,6 +21,12 @@ package com.intellectualcrafters.plot.commands; +import net.milkbowl.vault.economy.Economy; + +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; @@ -33,12 +39,6 @@ import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; -import net.milkbowl.vault.economy.Economy; - -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.entity.Player; - @SuppressWarnings("deprecation") public class Auto extends SubCommand { public static PlotId lastPlot = new PlotId(0, 0); @@ -53,16 +53,20 @@ public class Auto extends SubCommand { if (absX > absY) { if (id.x > 0) { return new PlotId(id.x, id.y + 1); - } else { + } + else { return new PlotId(id.x, id.y - 1); } - } else if (absY > absX) { + } + else if (absY > absX) { if (id.y > 0) { return new PlotId(id.x - 1, id.y); - } else { + } + else { return new PlotId(id.x + 1, id.y); } - } else { + } + else { if (id.x.equals(id.y) && (id.x > 0)) { return new PlotId(id.x, id.y + step); } @@ -85,10 +89,12 @@ public class Auto extends SubCommand { String schematic = ""; if (PlotMain.getPlotWorlds().length == 1) { world = Bukkit.getWorld(PlotMain.getPlotWorlds()[0]); - } else { + } + else { if (PlotMain.isPlotWorld(plr.getWorld())) { world = plr.getWorld(); - } else { + } + else { PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT_WORLD); return false; } @@ -108,7 +114,8 @@ public class Auto extends SubCommand { if (args.length > 1) { schematic = args[1]; } - } catch (final Exception e) { + } + catch (final Exception e) { size_x = 1; size_z = 1; schematic = args[0]; @@ -116,21 +123,22 @@ public class Auto extends SubCommand { // "&cError: Invalid size (X,Y)"); // return false; } - } else { + } + else { schematic = args[0]; // PlayerFunctions.sendMessage(plr, C.NO_PERMISSION); // return false; } } - - if (size_x * size_z > Settings.MAX_AUTO_SIZE) { + + if ((size_x * size_z) > Settings.MAX_AUTO_SIZE) { PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, Settings.MAX_AUTO_SIZE + ""); return false; } - int diff = PlayerFunctions.getPlayerPlotCount(world, plr) - PlayerFunctions.getAllowedPlots(plr); - if (diff + (size_x * size_z) >= 0) { + final int diff = PlayerFunctions.getPlayerPlotCount(world, plr) - PlayerFunctions.getAllowedPlots(plr); + if ((diff + (size_x * size_z)) >= 0) { if (diff < 0) { - PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, - diff - 1 + ""); + PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, (-diff - 1) + ""); } else { PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); @@ -152,7 +160,7 @@ public class Auto extends SubCommand { } } if (!schematic.equals("")) { -// if (pWorld.SCHEMATIC_CLAIM_SPECIFY) { + // if (pWorld.SCHEMATIC_CLAIM_SPECIFY) { if (!pWorld.SCHEMATICS.contains(schematic.toLowerCase())) { sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic); return true; @@ -161,36 +169,35 @@ public class Auto extends SubCommand { PlayerFunctions.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic); return true; } -// } + // } } boolean br = false; if ((size_x == 1) && (size_z == 1)) { while (!br) { - Plot plot = PlotHelper.getPlot(world, Auto.lastPlot); + final Plot plot = PlotHelper.getPlot(world, Auto.lastPlot); if ((plot == null) || (plot.owner == null)) { Claim.claimPlot(plr, plot, true, true); br = true; final PlotWorld pw = PlotMain.getWorldSettings(world); final Plot plot2 = PlotMain.getPlots(world).get(plot.id); if ((pw.DEFAULT_FLAGS != null) && (pw.DEFAULT_FLAGS.size() > 0)) { - Flag[] flags = FlagManager.parseFlags(pw.DEFAULT_FLAGS); + final Flag[] flags = FlagManager.parseFlags(pw.DEFAULT_FLAGS); plot2.settings.setFlags(flags); DBFunc.setFlags(plot2.world, plot2, flags); } } Auto.lastPlot = getNextPlot(Auto.lastPlot, 1); } - } else { + } + else { boolean lastPlot = true; - PlotId lastId = Auto.lastPlot; while (!br) { final PlotId start = getNextPlot(Auto.lastPlot, 1); // Checking if the current set of plots is a viable option. Auto.lastPlot = start; if (lastPlot) { - lastId = start; } - if (PlotMain.getPlots(world).get(start) != null && PlotMain.getPlots(world).get(start).owner != null) { + if ((PlotMain.getPlots(world).get(start) != null) && (PlotMain.getPlots(world).get(start).owner != null)) { continue; } else { @@ -214,7 +221,7 @@ public class Auto extends SubCommand { final PlotWorld pw = PlotMain.getWorldSettings(world); final Plot plot2 = PlotMain.getPlots(world).get(start); if ((pw.DEFAULT_FLAGS != null) && (pw.DEFAULT_FLAGS.size() > 0)) { - Flag[] flags = FlagManager.parseFlags(pw.DEFAULT_FLAGS); + final Flag[] flags = FlagManager.parseFlags(pw.DEFAULT_FLAGS); plot2.settings.setFlags(flags); DBFunc.setFlags(plot2.world, plot2, flags); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Ban.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Ban.java index 42dd0ce2d..2bba9b915 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Ban.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Ban.java @@ -1,9 +1,10 @@ package com.intellectualcrafters.plot.commands; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.util.PlayerFunctions; -import org.bukkit.entity.Player; /** * Created 2014-11-09 for PlotSquared @@ -17,14 +18,14 @@ public class Ban extends SubCommand { } @Override - public boolean execute(Player plr, String... args) { + public boolean execute(final Player plr, final String... args) { if (args.length < 1) { - return PlayerFunctions.sendMessage(plr, "&cUsage: &c" + usage); + return PlayerFunctions.sendMessage(plr, "&cUsage: &c" + this.usage); } if (!PlayerFunctions.isInPlot(plr)) { return sendMessage(plr, C.NOT_IN_PLOT); } - Plot plot = PlayerFunctions.getCurrentPlot(plr); + final Plot plot = PlayerFunctions.getCurrentPlot(plr); if (!plot.hasRights(plr)) { return sendMessage(plr, C.NO_PLOT_PERMS); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java index eb5d40038..9c6961e84 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java @@ -21,6 +21,11 @@ package com.intellectualcrafters.plot.commands; +import net.milkbowl.vault.economy.Economy; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; @@ -34,9 +39,6 @@ import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.SetBlockFast; -import net.milkbowl.vault.economy.Economy; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; /** * @author Citymonstret @@ -47,11 +49,11 @@ public class Claim extends SubCommand { super(Command.CLAIM, "Claim the current plot you're standing on.", "claim", CommandCategory.CLAIMING, true); } - public static boolean claimPlot(final Player player, final Plot plot, final boolean teleport, boolean auto) { + public static boolean claimPlot(final Player player, final Plot plot, final boolean teleport, final boolean auto) { return claimPlot(player, plot, teleport, "", auto); } - public static boolean claimPlot(final Player player, final Plot plot, final boolean teleport, final String schematic, boolean auto) { + public static boolean claimPlot(final Player player, final Plot plot, final boolean teleport, final String schematic, final boolean auto) { final PlayerClaimPlotEvent event = new PlayerClaimPlotEvent(player, plot, auto); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { @@ -69,7 +71,8 @@ public class Claim extends SubCommand { SchematicHandler.Schematic sch; if (schematic.equals("")) { sch = SchematicHandler.getSchematic(world.SCHEMATIC_FILE); - } else { + } + else { sch = SchematicHandler.getSchematic(schematic); if (sch == null) { sch = SchematicHandler.getSchematic(world.SCHEMATIC_FILE); @@ -78,7 +81,7 @@ public class Claim extends SubCommand { SchematicHandler.paste(player.getLocation(), sch, plot2, 0, 0); } if ((world.DEFAULT_FLAGS != null) && (world.DEFAULT_FLAGS.size() > 0)) { - Flag[] flags = FlagManager.parseFlags(world.DEFAULT_FLAGS); + final Flag[] flags = FlagManager.parseFlags(world.DEFAULT_FLAGS); plot2.settings.setFlags(flags); DBFunc.setFlags(plot.world, plot2, flags); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Clear.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Clear.java index 1cc25527a..a6fdbb265 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Clear.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Clear.java @@ -21,6 +21,9 @@ package com.intellectualcrafters.plot.commands; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Plot; @@ -29,9 +32,6 @@ import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; import com.intellectualcrafters.plot.util.UUIDHandler; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - public class Clear extends SubCommand { public Clear() { @@ -44,19 +44,23 @@ public class Clear extends SubCommand { // Is console if (args.length < 2) { PlotMain.sendConsoleSenderMessage("You need to specify two arguments: ID (0;0) & World (world)"); - } else { - PlotId id = PlotId.fromString(args[0]); - String world = args[1]; + } + else { + final PlotId id = PlotId.fromString(args[0]); + final String world = args[1]; if (id == null) { PlotMain.sendConsoleSenderMessage("Invalid Plot ID: " + args[0]); - } else { + } + else { if (!PlotMain.isPlotWorld(world)) { PlotMain.sendConsoleSenderMessage("Invalid plot world: " + world); - } else { - Plot plot = PlotHelper.getPlot(Bukkit.getWorld(world), id); + } + else { + final Plot plot = PlotHelper.getPlot(Bukkit.getWorld(world), id); if (plot == null) { PlotMain.sendConsoleSenderMessage("Could not find plot " + args[0] + " in world " + world); - } else { + } + else { plot.clear(null, false); PlotMain.sendConsoleSenderMessage("Plot " + plot.getId().toString() + " cleared."); } @@ -78,11 +82,11 @@ public class Clear extends SubCommand { } assert plot != null; plot.clear(plr, false); - + // sign - + // wall - + return true; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Clipboard.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Clipboard.java index 060f632ed..90245da2f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Clipboard.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Clipboard.java @@ -21,13 +21,14 @@ package com.intellectualcrafters.plot.commands; +import static com.intellectualcrafters.plot.object.PlotSelection.currentSelection; + +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotSelection; import com.intellectualcrafters.plot.util.PlayerFunctions; -import org.bukkit.entity.Player; - -import static com.intellectualcrafters.plot.object.PlotSelection.currentSelection; public class Clipboard extends SubCommand { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Command.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Command.java index 10309f1da..cd2239c4d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Command.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Command.java @@ -37,7 +37,7 @@ public enum Command { // ratings) // - /plot rate /** - * + * */ UNCLAIM("unclaim"), /** @@ -164,12 +164,12 @@ public enum Command { /** * Command */ - private final String command; + private final String command; /** * Alias */ - private final String alias; + private final String alias; /** * Permission Node @@ -177,7 +177,8 @@ public enum Command { private final CommandPermission permission; /** - * @param command Command "name" (/plot [cmd]) + * @param command + * Command "name" (/plot [cmd]) */ Command(final String command) { this.command = command; @@ -186,8 +187,10 @@ public enum Command { } /** - * @param command Command "name" (/plot [cmd]) - * @param permission Command Permission Node + * @param command + * Command "name" (/plot [cmd]) + * @param permission + * Command Permission Node */ Command(final String command, final CommandPermission permission) { this.command = command; @@ -196,8 +199,10 @@ public enum Command { } /** - * @param command Command "name" (/plot [cmd]) - * @param alias Command Alias + * @param command + * Command "name" (/plot [cmd]) + * @param alias + * Command Alias */ Command(final String command, final String alias) { this.command = command; @@ -206,9 +211,12 @@ public enum Command { } /** - * @param command Command "name" (/plot [cmd]) - * @param alias Command Alias - * @param permission Required Permission Node + * @param command + * Command "name" (/plot [cmd]) + * @param alias + * Command Alias + * @param permission + * Required Permission Node */ Command(final String command, final String alias, final CommandPermission permission) { this.command = command; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/CommandPermission.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/CommandPermission.java index df4aa3a41..a0db47f3b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/CommandPermission.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/CommandPermission.java @@ -21,9 +21,10 @@ package com.intellectualcrafters.plot.commands; -import com.intellectualcrafters.plot.PlotMain; import org.bukkit.entity.Player; +import com.intellectualcrafters.plot.PlotMain; + /** * Created by Citymonstret on 2014-08-03. * @@ -37,14 +38,16 @@ public class CommandPermission { public final String permission; /** - * @param permission Command Permission + * @param permission + * Command Permission */ public CommandPermission(final String permission) { this.permission = permission.toLowerCase(); } /** - * @param player Does the player have the permission? + * @param player + * Does the player have the permission? * @return true of player has the required permission node */ public boolean hasPermission(final Player player) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Comment.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Comment.java index 9a5f53ccf..f5ee8be39 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Comment.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Comment.java @@ -21,17 +21,18 @@ package com.intellectualcrafters.plot.commands; +import java.util.Arrays; +import java.util.List; + +import org.apache.commons.lang.StringUtils; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotComment; import com.intellectualcrafters.plot.util.PlayerFunctions; -import org.apache.commons.lang.StringUtils; -import org.bukkit.entity.Player; - -import java.util.Arrays; -import java.util.List; public class Comment extends SubCommand { @@ -61,7 +62,8 @@ public class Comment extends SubCommand { DBFunc.setComment(plr.getWorld().getName(), plot, comment); return true; - } else { + } + else { return sendMessage(plr, C.NO_PERMISSION, "plots.comment." + args[0].toLowerCase()); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Copy.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Copy.java index 7e011cbe0..12e6d9ead 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Copy.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Copy.java @@ -21,13 +21,14 @@ package com.intellectualcrafters.plot.commands; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotSelection; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; -import org.bukkit.entity.Player; public class Copy extends SubCommand { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DEOP.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DEOP.java index 4999358b6..c48982e6f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DEOP.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DEOP.java @@ -1,9 +1,10 @@ package com.intellectualcrafters.plot.commands; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.util.PlayerFunctions; -import org.bukkit.entity.Player; /** * Created 2014-11-09 for PlotSquared @@ -17,14 +18,14 @@ public class DEOP extends SubCommand { } @Override - public boolean execute(Player plr, String... args) { + public boolean execute(final Player plr, final String... args) { if (args.length < 1) { - return PlayerFunctions.sendMessage(plr, "&cUsage: &c" + usage); + return PlayerFunctions.sendMessage(plr, "&cUsage: &c" + this.usage); } if (!PlayerFunctions.isInPlot(plr)) { return sendMessage(plr, C.NOT_IN_PLOT); } - Plot plot = PlayerFunctions.getCurrentPlot(plr); + final Plot plot = PlayerFunctions.getCurrentPlot(plr); if (!plot.hasRights(plr)) { return sendMessage(plr, C.NO_PLOT_PERMS); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Database.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Database.java index 55595967c..cdf78e998 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Database.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Database.java @@ -1,5 +1,15 @@ package com.intellectualcrafters.plot.commands; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.UUID; + +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.database.MySQL; import com.intellectualcrafters.plot.database.SQLManager; @@ -8,17 +18,6 @@ import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.StringComparison; import com.intellectualcrafters.plot.util.UUIDHandler; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.UUID; - /** * Created 2014-11-15 for PlotSquared * @@ -26,47 +25,51 @@ import java.util.UUID; */ public class Database extends SubCommand { - final String[] tables = new String[]{ - "plot_trusted", "plot_ratings", "plot_comments" - }; + final String[] tables = new String[] { "plot_trusted", "plot_ratings", "plot_comments" }; public Database() { super(Command.DATABASE, "Convert/Backup Storage", "database [type] [...details]", CommandCategory.DEBUG, false); } - private static boolean sendMessageU(UUID uuid, String msg) { + private static boolean sendMessageU(final UUID uuid, final String msg) { if (uuid == null) { PlotMain.sendConsoleSenderMessage(msg); - } else { - Player p = UUIDHandler.uuidWrapper.getPlayer(uuid); - if (p != null && p.isOnline()) + } + else { + final Player p = UUIDHandler.uuidWrapper.getPlayer(uuid); + if ((p != null) && p.isOnline()) { return PlayerFunctions.sendMessage(p, msg); - else + } + else { return sendMessageU(null, msg); + } } return true; } public static void insertPlots(final SQLManager manager, final UUID requester, final Connection c) { - Plugin p = PlotMain.getMain(); + final Plugin p = PlotMain.getMain(); final java.util.Set plots = PlotMain.getPlots(); p.getServer().getScheduler().runTaskAsynchronously(p, new Runnable() { @Override public void run() { try { - ArrayList ps = new ArrayList<>(); - for (Plot p : plots) + final ArrayList ps = new ArrayList<>(); + for (final Plot p : plots) { ps.add(p); + } manager.createPlots(ps); manager.createAllSettingsAndHelpers(ps); sendMessageU(requester, "&6Database conversion finished"); - } catch (Exception e) { + } + catch (final Exception e) { sendMessageU(requester, "Failed to insert plot objects, see stacktrace for info"); e.printStackTrace(); } try { c.close(); - } catch (SQLException e) { + } + catch (final SQLException e) { e.printStackTrace(); } } @@ -74,67 +77,56 @@ public class Database extends SubCommand { } @Override - public boolean execute(Player plr, String... args) { + public boolean execute(final Player plr, final String... args) { if (args.length < 1) { return sendMessage(plr, "/plot database [sqlite/mysql]"); } - String type = new StringComparison(args[0], new String[]{"mysql", "sqlite"}).getBestMatch().toLowerCase(); + final String type = new StringComparison(args[0], new String[] { "mysql", "sqlite" }).getBestMatch().toLowerCase(); switch (type) { case "mysql": if (args.length < 6) { return sendMessage(plr, "/plot database mysql [host] [port] [username] [password] [database] {prefix}"); } - String host = - args[1]; - String port = - args[2]; - String username = - args[3]; - String password = - args[4]; - String database = - args[5]; - String prefix = - ""; + final String host = args[1]; + final String port = args[2]; + final String username = args[3]; + final String password = args[4]; + final String database = args[5]; + String prefix = ""; if (args.length > 6) { prefix = args[6]; } Connection n; try { - n = new MySQL( - PlotMain.getMain(), - host, - port, - database, - username, - password - ).openConnection(); + n = new MySQL(PlotMain.getMain(), host, port, database, username, password).openConnection(); // Connection if (n.isClosed()) { return sendMessage(plr, "Failed to open connection"); } - } catch (SQLException | ClassNotFoundException e) { + } + catch (SQLException | ClassNotFoundException e) { e.printStackTrace(); return sendMessage(plr, "Failed to open connection, read stacktrace for info"); } - SQLManager manager = new SQLManager(n, prefix); + final SQLManager manager = new SQLManager(n, prefix); try { final DatabaseMetaData meta = n.getMetaData(); ResultSet set = meta.getTables(null, null, prefix + "plot", null); if (!set.next()) { manager.createTables("mysql", true); - } else { - for (String s : tables) { + } + else { + for (final String s : this.tables) { set = meta.getTables(null, null, prefix + s, null); if (!set.next()) { manager.createTables("mysql", false); } } } - } catch (SQLException e) { + } + catch (final SQLException e) { e.printStackTrace(); - return sendMessage(plr, "Could not create the required tables and/or load the database") && - sendMessage(plr, "Please see the stacktrace for more information"); + return sendMessage(plr, "Could not create the required tables and/or load the database") && sendMessage(plr, "Please see the stacktrace for more information"); } UUID requester = null; if (plr != null) { @@ -154,10 +146,11 @@ public class Database extends SubCommand { return false; } - private boolean sendMessage(Player player, String msg) { + private boolean sendMessage(final Player player, final String msg) { if (player == null) { PlotMain.sendConsoleSenderMessage(msg); - } else { + } + else { PlayerFunctions.sendMessage(player, msg); } return true; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Debug.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Debug.java index b8e582357..937e2bf6c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Debug.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Debug.java @@ -21,15 +21,16 @@ package com.intellectualcrafters.plot.commands; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.util.Lag; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; import com.intellectualcrafters.plot.util.RUtils; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.entity.Player; public class Debug extends SubCommand { @@ -68,8 +69,8 @@ public class Debug extends SubCommand { information.append(getSection(section, "PlotWorld")); information.append(getLine(line, "Plot Worlds", worlds)); information.append(getLine(line, "Owned Plots", PlotMain.getPlots().size())); - //information.append(getLine(line, "PlotWorld Size", - //PlotHelper.getWorldFolderSize() + "MB")); + // information.append(getLine(line, "PlotWorld Size", + // PlotHelper.getWorldFolderSize() + "MB")); for (final String worldname : PlotMain.getPlotWorlds()) { final World world = Bukkit.getWorld(worldname); information.append(getLine(line, "World: " + world.getName() + " size", PlotHelper.getWorldFolderSize(world))); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java index 465b6aa6f..16c13eb48 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java @@ -21,16 +21,9 @@ package com.intellectualcrafters.plot.commands; -import com.google.common.collect.BiMap; -import com.intellectualcrafters.plot.PlotMain; -import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.database.DBFunc; -import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent; -import com.intellectualcrafters.plot.flag.FlagManager; -import com.intellectualcrafters.plot.object.*; -import com.intellectualcrafters.plot.util.PlayerFunctions; -import com.intellectualcrafters.plot.util.PlotHelper; -import com.intellectualcrafters.plot.util.UUIDHandler; +import java.util.ArrayList; +import java.util.UUID; + import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; @@ -39,8 +32,20 @@ import org.bukkit.block.Block; import org.bukkit.block.Sign; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.UUID; +import com.google.common.collect.BiMap; +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent; +import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotManager; +import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.object.StringWrapper; +import com.intellectualcrafters.plot.util.PlayerFunctions; +import com.intellectualcrafters.plot.util.PlotHelper; +import com.intellectualcrafters.plot.util.UUIDHandler; /** * @author Citymonstret @@ -90,7 +95,8 @@ public class DebugClaimTest extends SubCommand { min = new PlotId(Integer.parseInt(split1[0]), Integer.parseInt(split1[1])); max = new PlotId(Integer.parseInt(split2[0]), Integer.parseInt(split2[1])); - } catch (final Exception e) { + } + catch (final Exception e) { return !PlayerFunctions.sendMessage(null, "&cInvalid min/max values. &7The values are to Plot IDs in the format &cX;Y &7where X,Y are the plot coords\nThe conversion will only check the plots in the selected area."); } PlayerFunctions.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Beginning sign to plot conversion. This may take a while..."); @@ -148,7 +154,8 @@ public class DebugClaimTest extends SubCommand { plot.owner = uuid; plot.hasChanged = true; plots.add(plot); - } else { + } + else { PlayerFunctions.sendMessage(null, " - &cInvalid playername: " + plot.id + " : " + line); } } @@ -167,11 +174,13 @@ public class DebugClaimTest extends SubCommand { PlayerFunctions.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Complete!"); - } else { + } + else { PlayerFunctions.sendMessage(null, "No plots were found for the given search."); } - } else { + } + else { PlayerFunctions.sendMessage(plr, "This debug command can only be executed by console as it has been deemed unsafe if abused."); } return true; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugLoadTest.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugLoadTest.java index 66f81f8db..4a06488ed 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugLoadTest.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugLoadTest.java @@ -21,12 +21,13 @@ package com.intellectualcrafters.plot.commands; +import java.lang.reflect.Field; + +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.util.PlayerFunctions; -import org.bukkit.entity.Player; - -import java.lang.reflect.Field; /** * @author Citymonstret @@ -44,12 +45,14 @@ public class DebugLoadTest extends SubCommand { final Field fPlots = PlotMain.class.getDeclaredField("plots"); fPlots.setAccessible(true); fPlots.set(null, DBFunc.getPlots()); - } catch (final Exception e) { + } + catch (final Exception e) { PlotMain.sendConsoleSenderMessage("&3===FAILED&3==="); e.printStackTrace(); PlotMain.sendConsoleSenderMessage("&3===END OF STACKTRACE==="); } - } else { + } + else { PlayerFunctions.sendMessage(plr, "This debug command can only be executed by console as it has been deemed unsafe if abused."); } return true; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugSaveTest.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugSaveTest.java index c8af90319..3601f3a44 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugSaveTest.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugSaveTest.java @@ -21,13 +21,14 @@ package com.intellectualcrafters.plot.commands; +import java.util.ArrayList; + +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.util.PlayerFunctions; -import org.bukkit.entity.Player; - -import java.util.ArrayList; /** * @author Citymonstret @@ -45,7 +46,8 @@ public class DebugSaveTest extends SubCommand { plots.addAll(PlotMain.getPlots()); DBFunc.createPlots(plots); DBFunc.createAllSettingsAndHelpers(plots); - } else { + } + else { PlayerFunctions.sendMessage(plr, "This debug command can only be executed by console as it has been deemed unsafe if abused."); } return true; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Delete.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Delete.java index 366870db1..e149eb3a8 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Delete.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Delete.java @@ -21,14 +21,16 @@ package com.intellectualcrafters.plot.commands; +import net.milkbowl.vault.economy.Economy; + +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.PlayerFunctions; -import net.milkbowl.vault.economy.Economy; -import org.bukkit.entity.Player; public class Delete extends SubCommand { @@ -50,7 +52,7 @@ public class Delete extends SubCommand { } assert plot != null; final PlotWorld pWorld = PlotMain.getWorldSettings(plot.getWorld()); - if (PlotMain.useEconomy && pWorld.USE_ECONOMY && plot!=null && plot.hasOwner() && plot.getOwner().equals(plr.getUniqueId())) { + if (PlotMain.useEconomy && pWorld.USE_ECONOMY && (plot != null) && plot.hasOwner() && plot.getOwner().equals(plr.getUniqueId())) { final double c = pWorld.SELL_PRICE; if (c > 0d) { final Economy economy = PlotMain.economy; @@ -65,7 +67,8 @@ public class Delete extends SubCommand { if ((Math.abs(plot.id.x) <= Math.abs(Auto.lastPlot.x)) && (Math.abs(plot.id.y) <= Math.abs(Auto.lastPlot.y))) { Auto.lastPlot = plot.id; } - } else { + } + else { PlayerFunctions.sendMessage(plr, "Plot deletion has been denied."); } return true; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Denied.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Denied.java index 5acbebf19..c6cf48e43 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Denied.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Denied.java @@ -21,6 +21,12 @@ package com.intellectualcrafters.plot.commands; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; @@ -29,13 +35,6 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.UUIDHandler; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; - -import java.util.UUID; - - @SuppressWarnings("deprecation") public class Denied extends SubCommand { @@ -63,7 +62,8 @@ public class Denied extends SubCommand { if (args[1].equalsIgnoreCase("*")) { uuid = DBFunc.everyone; - } else { + } + else { uuid = UUIDHandler.getUUID(args[1]); } if (!plot.denied.contains(uuid)) { @@ -88,11 +88,12 @@ public class Denied extends SubCommand { DBFunc.setDenied(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1])); final PlayerPlotDeniedEvent event = new PlayerPlotDeniedEvent(plr, plot, uuid, true); Bukkit.getPluginManager().callEvent(event); - } else { + } + else { PlayerFunctions.sendMessage(plr, C.ALREADY_ADDED); return false; } - Player player = UUIDHandler.uuidWrapper.getPlayer(uuid); + final Player player = UUIDHandler.uuidWrapper.getPlayer(uuid); if (!uuid.equals(DBFunc.everyone) && (player != null) && player.isOnline()) { final Plot pl = PlayerFunctions.getCurrentPlot(player); if ((pl != null) && pl.id.equals(plot.id)) { @@ -102,7 +103,8 @@ public class Denied extends SubCommand { } PlayerFunctions.sendMessage(plr, C.DENIED_ADDED); return true; - } else if (args[0].equalsIgnoreCase("remove")) { + } + else if (args[0].equalsIgnoreCase("remove")) { if (args[1].equalsIgnoreCase("*")) { final UUID uuid = DBFunc.everyone; if (!plot.denied.contains(uuid)) { @@ -132,7 +134,8 @@ public class Denied extends SubCommand { final PlayerPlotDeniedEvent event = new PlayerPlotDeniedEvent(plr, plot, uuid, false); Bukkit.getPluginManager().callEvent(event); PlayerFunctions.sendMessage(plr, C.DENIED_REMOVED); - } else { + } + else { PlayerFunctions.sendMessage(plr, C.DENIED_NEED_ARGUMENT); return true; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Help.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Help.java index 65833d530..439d630a5 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Help.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Help.java @@ -10,7 +10,6 @@ package com.intellectualcrafters.plot.commands; import org.bukkit.entity.Player; - public class Help extends SubCommand { public Help() { super("help", "", "Get this help menu", "help", "he", SubCommand.CommandCategory.INFO, false); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Helpers.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Helpers.java index fa9a02f0c..1702f23b6 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Helpers.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Helpers.java @@ -21,6 +21,12 @@ package com.intellectualcrafters.plot.commands; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; @@ -29,12 +35,6 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.UUIDHandler; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; - -import java.util.UUID; - @SuppressWarnings("deprecation") public class Helpers extends SubCommand { @@ -61,7 +61,8 @@ public class Helpers extends SubCommand { UUID uuid; if (args[1].equalsIgnoreCase("*")) { uuid = DBFunc.everyone; - } else { + } + else { uuid = UUIDHandler.getUUID(args[1]); } if (!plot.helpers.contains(uuid)) { @@ -86,13 +87,15 @@ public class Helpers extends SubCommand { DBFunc.setHelper(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1])); final PlayerPlotHelperEvent event = new PlayerPlotHelperEvent(plr, plot, uuid, true); Bukkit.getPluginManager().callEvent(event); - } else { + } + else { PlayerFunctions.sendMessage(plr, C.ALREADY_ADDED); return false; } PlayerFunctions.sendMessage(plr, C.HELPER_ADDED); return true; - } else if (args[0].equalsIgnoreCase("remove")) { + } + else if (args[0].equalsIgnoreCase("remove")) { if (args[1].equalsIgnoreCase("*")) { final UUID uuid = DBFunc.everyone; if (!plot.helpers.contains(uuid)) { @@ -123,7 +126,8 @@ public class Helpers extends SubCommand { final PlayerPlotHelperEvent event = new PlayerPlotHelperEvent(plr, plot, uuid, false); Bukkit.getPluginManager().callEvent(event); PlayerFunctions.sendMessage(plr, C.HELPER_REMOVED); - } else { + } + else { PlayerFunctions.sendMessage(plr, C.HELPER_NEED_ARGUMENT); return true; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Home.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Home.java index 2dbf6db91..aeed0b43c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Home.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Home.java @@ -21,11 +21,12 @@ package com.intellectualcrafters.plot.commands; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.util.PlayerFunctions; -import org.bukkit.entity.Player; /** * @author Citymonstret @@ -51,14 +52,16 @@ public class Home extends SubCommand { if (plots.length == 1) { PlotMain.teleportPlayer(plr, plr.getLocation(), plots[0]); return true; - } else if (plots.length > 1) { + } + else if (plots.length > 1) { if (args.length < 1) { - args = new String[]{"1"}; + args = new String[] { "1" }; } int id = 0; try { id = Integer.parseInt(args[0]); - } catch (final Exception e) { + } + catch (final Exception e) { Plot temp; if ((temp = isAlias(args[0])) != null) { if (temp.hasOwner()) { @@ -79,7 +82,8 @@ public class Home extends SubCommand { } PlotMain.teleportPlayer(plr, plr.getLocation(), plots[id - 1]); return true; - } else { + } + else { PlayerFunctions.sendMessage(plr, C.NO_PLOTS); return true; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java index f4ea43fc0..e0ab03c8b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java @@ -21,19 +21,20 @@ package com.intellectualcrafters.plot.commands; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotComment; import com.intellectualcrafters.plot.util.PlayerFunctions; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; public class Inbox extends SubCommand { @@ -57,13 +58,17 @@ public class Inbox extends SubCommand { final UUID uuid = plr.getUniqueId(); if (PlotMain.hasPermission(plr, "plots.admin")) { tier = 0; - } else if (plot.owner == uuid) { + } + else if (plot.owner == uuid) { tier = 1; - } else if (plot.helpers.contains(uuid)) { + } + else if (plot.helpers.contains(uuid)) { tier = 2; - } else if (plot.trusted.contains(uuid)) { + } + else if (plot.trusted.contains(uuid)) { tier = 3; - } else { + } + else { tier = 4; } @@ -72,7 +77,8 @@ public class Inbox extends SubCommand { case "admin": if (tier <= 0) { tier = 0; - } else { + } + else { PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX); return false; } @@ -80,7 +86,8 @@ public class Inbox extends SubCommand { case "owner": if (tier <= 1) { tier = 1; - } else { + } + else { PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX); return false; } @@ -88,7 +95,8 @@ public class Inbox extends SubCommand { case "helper": if (tier <= 2) { tier = 2; - } else { + } + else { PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX); return false; } @@ -96,7 +104,8 @@ public class Inbox extends SubCommand { case "trusted": if (tier <= 3) { tier = 3; - } else { + } + else { PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX); return false; } @@ -104,13 +113,14 @@ public class Inbox extends SubCommand { case "everyone": if (tier <= 4) { tier = 4; - } else { + } + else { PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX); return false; } break; case "default": - PlayerFunctions.sendMessage(plr, C.INVALID_INBOX, Arrays.copyOfRange(new String[]{"admin", "owner", "helper", "trusted", "everyone"}, tier, 4)); + PlayerFunctions.sendMessage(plr, C.INVALID_INBOX, Arrays.copyOfRange(new String[] { "admin", "owner", "helper", "trusted", "everyone" }, tier, 4)); return false; } } @@ -141,7 +151,8 @@ public class Inbox extends SubCommand { plot.settings.removeComment(comment); PlayerFunctions.sendMessage(plr, C.COMMENT_REMOVED, "1 comment"); return; - } catch (final Exception e) { + } + catch (final Exception e) { PlayerFunctions.sendMessage(plr, "&cInvalid index:\n/plot inbox [tier] [clear][:#]"); return; } @@ -151,7 +162,8 @@ public class Inbox extends SubCommand { } plot.settings.removeComments(comments); PlayerFunctions.sendMessage(plr, C.COMMENT_REMOVED, "all comments in that category"); - } else { + } + else { final List recipients = Arrays.asList("A", "O", "H", "T", "E"); int count = 1; final StringBuilder message = new StringBuilder(); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java index 1d1673f40..ecdca4d0f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java @@ -21,6 +21,16 @@ package com.intellectualcrafters.plot.commands; +import java.util.ArrayList; +import java.util.UUID; + +import org.apache.commons.lang.StringUtils; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.Biome; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; @@ -31,20 +41,11 @@ import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; import com.intellectualcrafters.plot.util.UUIDHandler; -import org.apache.commons.lang.StringUtils; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.block.Biome; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.UUID; /** * @author Citymonstret */ -@SuppressWarnings({"unused", "deprecated", "javadoc"}) +@SuppressWarnings({ "unused", "deprecated", "javadoc" }) public class Info extends SubCommand { public Info() { @@ -62,7 +63,8 @@ public class Info extends SubCommand { return false; } plot = PlayerFunctions.getCurrentPlot(player); - } else { + } + else { if (args.length < 2) { PlayerFunctions.sendMessage(null, C.INFO_SYNTAX_CONSOLE); return false; @@ -82,17 +84,19 @@ public class Info extends SubCommand { } world = Bukkit.getWorld(args[0]); if (args.length == 3) { - args = new String[]{args[2]}; - } else { + args = new String[] { args[2] }; + } + else { args = new String[0]; } - } catch (final Exception e) { + } + catch (final Exception e) { PlayerFunctions.sendMessage(player, C.INFO_SYNTAX_CONSOLE); return false; } } - if (args.length == 1 && args[0].equalsIgnoreCase("inv")) { + if ((args.length == 1) && args[0].equalsIgnoreCase("inv")) { new InfoInventory(plot, player).build().display(); return true; } @@ -103,8 +107,8 @@ public class Info extends SubCommand { // Wildcard player {added} { - containsEveryone = plot.helpers != null && plot.helpers.contains(DBFunc.everyone); - trustedEveryone = plot.trusted != null && plot.trusted.contains(DBFunc.everyone); + containsEveryone = (plot.helpers != null) && plot.helpers.contains(DBFunc.everyone); + trustedEveryone = (plot.trusted != null) && plot.trusted.contains(DBFunc.everyone); } // Unclaimed? @@ -175,7 +179,7 @@ public class Info extends SubCommand { final String denied = getPlayerList(plot.denied); final String rating = String.format("%.1f", DBFunc.getRatings(plot)); final String flags = "&6" + (StringUtils.join(plot.settings.getFlags(), "").length() > 0 ? StringUtils.join(plot.settings.getFlags(), "&7, &6") : "none"); - final boolean build = player == null || plot.hasRights(player); + final boolean build = (player == null) || plot.hasRights(player); String owner = "none"; if (plot.owner != null) { @@ -211,7 +215,8 @@ public class Info extends SubCommand { for (int x = 0; x < l.size(); x++) { if ((x + 1) == l.size()) { list.append(c.replace("%user%", getPlayerName(l.get(x))).replace(",", "")); - } else { + } + else { list.append(c.replace("%user%", getPlayerName(l.get(x)))); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inventory.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inventory.java index 326ffea40..4921d16ac 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inventory.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inventory.java @@ -21,6 +21,8 @@ package com.intellectualcrafters.plot.commands; +import java.util.ArrayList; + import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -28,8 +30,6 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import java.util.ArrayList; - public class Inventory extends SubCommand { public Inventory() { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Kick.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Kick.java index 3ffd96598..be95b725c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Kick.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Kick.java @@ -21,14 +21,15 @@ package com.intellectualcrafters.plot.commands; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.util.PlayerFunctions; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -@SuppressWarnings({"unused", "deprecation", "javadoc"}) +@SuppressWarnings({ "unused", "deprecation", "javadoc" }) public class Kick extends SubCommand { public Kick() { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index a9a8571e7..902bafd9d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -21,10 +21,10 @@ package com.intellectualcrafters.plot.commands; -import com.intellectualcrafters.plot.PlotMain; -import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.util.PlayerFunctions; -import com.intellectualcrafters.plot.util.StringComparison; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -32,9 +32,10 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.util.PlayerFunctions; +import com.intellectualcrafters.plot.util.StringComparison; /** * PlotMain command class @@ -46,53 +47,11 @@ public class MainCommand implements CommandExecutor, TabCompleter { /** * Main Permission Node */ - public static final String - MAIN_PERMISSION = "plots.use"; + public static final String MAIN_PERMISSION = "plots.use"; - private final static SubCommand[] _subCommands = - new SubCommand[]{ - new Ban(), - new Unban(), - new OP(), - new DEOP(), - new Claim(), - new Paste(), - new Copy(), - new Clipboard(), - new Auto(), - new Home(), - new Visit(), - new TP(), - new Set(), - new Clear(), - new Delete(), - new SetOwner(), - new Denied(), - new Helpers(), - new Trusted(), - new Info(), - new list(), - new Help(), - new Debug(), - new Schematic(), - new plugin(), - new Inventory(), - new Purge(), - new Reload(), - new Merge(), - new Unlink(), - new Kick(), - new Setup(), - new Rate(), - new DebugClaimTest(), - new Inbox(), - new Comment(), - new Database(), - new Unclaim(), - new Swap(), - new MusicSubcommand()}; + private final static SubCommand[] _subCommands = new SubCommand[] { new Ban(), new Unban(), new OP(), new DEOP(), new Claim(), new Paste(), new Copy(), new Clipboard(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(), new Info(), new list(), new Help(), new Debug(), new Schematic(), new plugin(), new Inventory(), new Purge(), new Reload(), new Merge(), new Unlink(), new Kick(), new Setup(), new Rate(), new DebugClaimTest(), new Inbox(), new Comment(), new Database(), new Unclaim(), new Swap(), new MusicSubcommand() }; - public final static ArrayList subCommands = new ArrayList() { + public final static ArrayList subCommands = new ArrayList() { { addAll(Arrays.asList(_subCommands)); } @@ -116,7 +75,7 @@ public class MainCommand implements CommandExecutor, TabCompleter { public static List helpMenu(final Player player, final SubCommand.CommandCategory category, int page) { final List commands = getCommands(category, player); // final int totalPages = ((int) Math.ceil(12 * (commands.size()) / - // 100)); + // 100)); final int perPage = 5; final int totalPages = (int) Math.ceil(commands.size() / perPage); if (page > totalPages) { @@ -131,13 +90,7 @@ public class MainCommand implements CommandExecutor, TabCompleter { help.add(C.HELP_HEADER.s()); // HELP_CATEGORY("&cCategory: &6%category%&c, Page: %current%&c/&6%max%&c, Displaying: &6%dis%&c/&6%total%"), - help.add(C.HELP_CATEGORY.s() - .replace("%category%", category.toString()) - .replace("%current%", "" + (page + 1)) - .replace("%max%", "" + (totalPages + 1)) - .replace("%dis%", "" + (commands.size() % perPage)) - .replace("%total%", "" + commands.size()) - ); + help.add(C.HELP_CATEGORY.s().replace("%category%", category.toString()).replace("%current%", "" + (page + 1)).replace("%max%", "" + (totalPages + 1)).replace("%dis%", "" + (commands.size() % perPage)).replace("%total%", "" + commands.size())); SubCommand cmd; @@ -145,12 +98,7 @@ public class MainCommand implements CommandExecutor, TabCompleter { for (int x = start; x < max; x++) { cmd = commands.get(x); String s = t(C.HELP_ITEM.s()); - s = s - .replace("%alias%", cmd.alias.get(0)) - .replace("%usage%", cmd.usage.contains("plot") ? cmd.usage : "/plot " + cmd.usage) - .replace("%cmd%", cmd.cmd) - .replace("%desc%", cmd.description) - ; + s = s.replace("%alias%", cmd.alias.get(0)).replace("%usage%", cmd.usage.contains("plot") ? cmd.usage : "/plot " + cmd.usage).replace("%cmd%", cmd.cmd).replace("%desc%", cmd.description); help.add(s); } if (help.size() < 2) { @@ -167,8 +115,9 @@ public class MainCommand implements CommandExecutor, TabCompleter { public boolean onCommand(final CommandSender sender, final Command cmd, final String commandLabel, final String[] args) { final Player player = (sender instanceof Player) ? (Player) sender : null; - if (!PlotMain.hasPermission(player, MAIN_PERMISSION)) + if (!PlotMain.hasPermission(player, MAIN_PERMISSION)) { return no_permission(player, MAIN_PERMISSION); + } if ((args.length < 1) || ((args.length >= 1) && (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("he")))) { if (args.length < 2) { @@ -203,7 +152,8 @@ public class MainCommand implements CommandExecutor, TabCompleter { String arg2; if (args.length > 2) { arg2 = args[2]; - } else { + } + else { arg2 = "1"; } @@ -224,8 +174,9 @@ public class MainCommand implements CommandExecutor, TabCompleter { help.append(string).append("\n"); } sender.sendMessage(ChatColor.translateAlternateColorCodes('&', help.toString())); - //return PlayerFunctions.sendMessage(player, help.toString()); - } else { + // return PlayerFunctions.sendMessage(player, help.toString()); + } + else { for (final SubCommand command : subCommands) { if (command.cmd.equalsIgnoreCase(args[0]) || command.alias.contains(args[0].toLowerCase())) { final String[] arguments = new String[args.length - 1]; @@ -233,10 +184,12 @@ public class MainCommand implements CommandExecutor, TabCompleter { if (command.permission.hasPermission(player)) { if ((player != null) || !command.isPlayer) { return command.execute(player, arguments); - } else { + } + else { return !PlayerFunctions.sendMessage(null, C.IS_CONSOLE); } - } else { + } + else { return no_permission(player, command.permission.permission.toLowerCase()); } } @@ -249,9 +202,10 @@ public class MainCommand implements CommandExecutor, TabCompleter { } /* Let's try to get a proper usage string */ - String command = new StringComparison(args[0], commands).getBestMatch(); + final String command = new StringComparison(args[0], commands).getBestMatch(); return PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, "/plot " + command); - //PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, new StringComparsion(args[0], commands).getBestMatch()); + // PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, new + // StringComparsion(args[0], commands).getBestMatch()); } return true; } @@ -280,7 +234,8 @@ public class MainCommand implements CommandExecutor, TabCompleter { if (cmd.permission.hasPermission(player)) { if (cmd.cmd.startsWith(arg)) { tabOptions.add(cmd.cmd); - } else if (cmd.alias.get(0).startsWith(arg)) { + } + else if (cmd.alias.get(0).startsWith(arg)) { tabOptions.add(cmd.alias.get(0)); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Merge.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Merge.java index c4d94fea7..f98c36642 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Merge.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Merge.java @@ -21,6 +21,15 @@ package com.intellectualcrafters.plot.commands; +import java.util.ArrayList; + +import net.milkbowl.vault.economy.Economy; + +import org.apache.commons.lang.StringUtils; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.events.PlotMergeEvent; @@ -30,21 +39,14 @@ import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; import com.intellectualcrafters.plot.util.SetBlockFast; -import net.milkbowl.vault.economy.Economy; -import org.apache.commons.lang.StringUtils; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.entity.Player; - -import java.util.ArrayList; /** * @author Citymonstret */ public class Merge extends SubCommand { - public final static String[] values = new String[]{"north", "east", "south", "west"}; - public final static String[] aliases = new String[]{"n", "e", "s", "w"}; + public final static String[] values = new String[] { "north", "east", "south", "west" }; + public final static String[] aliases = new String[] { "n", "e", "s", "w" }; public Merge() { super(Command.MERGE, "Merge the plot you are standing on with another plot.", "merge", CommandCategory.ACTIONS, true); @@ -157,9 +159,9 @@ public class Merge extends SubCommand { } PlayerFunctions.sendMessage(plr, "&cPlots have been merged"); PlotHelper.mergePlots(world, plots); - + PlotHelper.setSign(world, plr.getName(), plot); - + if (PlotHelper.canSetFast) { SetBlockFast.update(plr); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MusicSubcommand.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MusicSubcommand.java index 426dc02af..b8622f16c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MusicSubcommand.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MusicSubcommand.java @@ -21,17 +21,18 @@ package com.intellectualcrafters.plot.commands; -import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.listeners.PlotPlusListener; -import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.util.PlayerFunctions; +import java.util.Arrays; + import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import java.util.Arrays; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.listeners.PlotPlusListener; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.util.PlayerFunctions; public class MusicSubcommand extends SubCommand { public MusicSubcommand() { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/OP.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/OP.java index aa054e9eb..67d789621 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/OP.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/OP.java @@ -1,9 +1,10 @@ package com.intellectualcrafters.plot.commands; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.util.PlayerFunctions; -import org.bukkit.entity.Player; /** * Created 2014-11-09 for PlotSquared @@ -17,14 +18,14 @@ public class OP extends SubCommand { } @Override - public boolean execute(Player plr, String... args) { + public boolean execute(final Player plr, final String... args) { if (args.length < 1) { - return PlayerFunctions.sendMessage(plr, "&cUsage: &c" + usage); + return PlayerFunctions.sendMessage(plr, "&cUsage: &c" + this.usage); } if (!PlayerFunctions.isInPlot(plr)) { return sendMessage(plr, C.NOT_IN_PLOT); } - Plot plot = PlayerFunctions.getCurrentPlot(plr); + final Plot plot = PlayerFunctions.getCurrentPlot(plr); if (!plot.hasRights(plr)) { return sendMessage(plr, C.NO_PLOT_PERMS); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Paste.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Paste.java index 162d95d83..16fbeb15f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Paste.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Paste.java @@ -21,13 +21,14 @@ package com.intellectualcrafters.plot.commands; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotSelection; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; -import org.bukkit.entity.Player; public class Paste extends SubCommand { @@ -61,7 +62,8 @@ public class Paste extends SubCommand { } selection.paste(plr.getWorld(), plot); sendMessage(plr, C.PASTED); - } else { + } + else { sendMessage(plr, C.NO_CLIPBOARD); return false; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Purge.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Purge.java index ae5255346..33f0d6e8b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Purge.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Purge.java @@ -21,14 +21,15 @@ package com.intellectualcrafters.plot.commands; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.util.PlayerFunctions; -import org.bukkit.entity.Player; -@SuppressWarnings({"unused", "deprecated", "javadoc"}) +@SuppressWarnings({ "unused", "deprecated", "javadoc" }) public class Purge extends SubCommand { public Purge() { @@ -59,7 +60,8 @@ public class Purge extends SubCommand { DBFunc.purge(world, id); PlayerFunctions.sendMessage(null, "&aPurge of '" + args[0] + "' was successful!"); return true; - } catch (final Exception e) { + } + catch (final Exception e) { PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_ID); } } @@ -75,7 +77,8 @@ public class Purge extends SubCommand { DBFunc.purge(args[0]); PlayerFunctions.sendMessage(plr, (C.PURGE_SUCCESS)); return true; - } else { + } + else { PlayerFunctions.sendMessage(plr, "This is a dangerous command, if you are sure, use /plot purge {world} -o"); return false; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java index 96ff4e805..1a8619204 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java @@ -21,13 +21,14 @@ package com.intellectualcrafters.plot.commands; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.util.PlayerFunctions; -import org.bukkit.entity.Player; -@SuppressWarnings({"unused", "deprecated", "javadoc"}) +@SuppressWarnings({ "unused", "deprecated", "javadoc" }) public class Rate extends SubCommand { /* @@ -78,17 +79,19 @@ public class Rate extends SubCommand { boolean rated = true; try { DBFunc.getRatings(plot); - } catch (Exception e) { + } + catch (final Exception e) { rated = false; } if (rated) { sendMessage(plr, C.RATING_ALREADY_EXISTS, plot.getId().toString()); } - boolean success = true; + final boolean success = true; if (success) { sendMessage(plr, C.RATING_APPLIED, plot.getId().toString()); - } else { + } + else { sendMessage(plr, C.COMMAND_WENT_WRONG); } return true; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Reload.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Reload.java index e5a43f8d8..9a286281a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Reload.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Reload.java @@ -21,11 +21,12 @@ package com.intellectualcrafters.plot.commands; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.PlayerFunctions; -import org.bukkit.entity.Player; public class Reload extends SubCommand { @@ -46,7 +47,8 @@ public class Reload extends SubCommand { plotworld.loadDefaultConfiguration(PlotMain.config.getConfigurationSection("worlds." + pw)); } PlotMain.BroadcastWithPerms(C.RELOADED_CONFIGS); - } catch (final Exception e) { + } + catch (final Exception e) { PlayerFunctions.sendMessage(plr, C.RELOAD_FAILED); } return true; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Schematic.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Schematic.java index de5795a73..5ff53f584 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Schematic.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Schematic.java @@ -21,30 +21,35 @@ package com.intellectualcrafters.plot.commands; -import com.intellectualcrafters.jnbt.CompoundTag; -import com.intellectualcrafters.plot.PlotMain; -import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.config.Settings; -import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotId; -import com.intellectualcrafters.plot.util.*; -import com.intellectualcrafters.plot.util.SchematicHandler.DataCollection; -import com.intellectualcrafters.plot.util.SchematicHandler.Dimension; +import java.util.Collection; +import java.util.HashMap; + import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; -import java.util.Collection; -import java.util.HashMap; +import com.intellectualcrafters.jnbt.CompoundTag; +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.util.PlayerFunctions; +import com.intellectualcrafters.plot.util.PlotHelper; +import com.intellectualcrafters.plot.util.SchematicHandler; +import com.intellectualcrafters.plot.util.SchematicHandler.DataCollection; +import com.intellectualcrafters.plot.util.SchematicHandler.Dimension; +import com.intellectualcrafters.plot.util.SetBlockFast; +import com.intellectualcrafters.plot.util.UUIDHandler; public class Schematic extends SubCommand { - private int counter = 0; + private int counter = 0; private boolean running = false; - private Plot[] plots; - private int task; + private Plot[] plots; + private int task; public Schematic() { super("schematic", "plots.schematic", "Schematic Command", "schematic {arg}", "sch", CommandCategory.ACTIONS, false); @@ -114,7 +119,8 @@ public class Schematic extends SubCommand { final Location loc = plr.getLocation(); x = Math.min(length2 - dem.getX(), loc.getBlockX() - bot.getBlockX()); z = Math.min(length2 - dem.getZ(), loc.getBlockZ() - bot.getBlockZ()); - } else { + } + else { x = 0; z = 0; } @@ -211,7 +217,7 @@ public class Schematic extends SubCommand { final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"); - Collection values = plotmap.values(); + final Collection values = plotmap.values(); this.plots = values.toArray(new Plot[values.size()]); this.running = true; this.counter = 0; @@ -231,7 +237,8 @@ public class Schematic extends SubCommand { final String owner = o == null ? "unknown" : o; if (sch == null) { PlayerFunctions.sendMessage(null, "&7 - Skipped plot &c" + plot.id); - } else { + } + else { Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"), new Runnable() { @Override public void run() { @@ -239,7 +246,8 @@ public class Schematic extends SubCommand { final boolean result = SchematicHandler.save(sch, Settings.SCHEMATIC_SAVE_PATH + "/" + plot.id.x + ";" + plot.id.y + "," + worldname + "," + owner + ".schematic"); if (!result) { PlayerFunctions.sendMessage(null, "&7 - Failed to save &c" + plot.id); - } else { + } + else { PlayerFunctions.sendMessage(null, "&7 - &aExport success: " + plot.id); } } @@ -273,7 +281,8 @@ public class Schematic extends SubCommand { } p2 = myplot; world = plr.getWorld().getName(); - } else { + } + else { if (args.length == 3) { try { world = args[0]; @@ -284,11 +293,13 @@ public class Schematic extends SubCommand { return false; } p2 = PlotMain.getPlots(world).get(i); - } catch (final Exception e) { + } + catch (final Exception e) { PlayerFunctions.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save "); return false; } - } else { + } + else { PlayerFunctions.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save "); return false; } @@ -296,7 +307,7 @@ public class Schematic extends SubCommand { final Plugin plugin2 = Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"); - this.plots = new Plot[]{p2}; + this.plots = new Plot[] { p2 }; this.running = true; this.counter = 0; @@ -315,7 +326,8 @@ public class Schematic extends SubCommand { final String owner = o == null ? "unknown" : o; if (sch == null) { PlayerFunctions.sendMessage(plr, "&7 - Skipped plot &c" + plot.id); - } else { + } + else { Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"), new Runnable() { @Override public void run() { @@ -323,7 +335,8 @@ public class Schematic extends SubCommand { final boolean result = SchematicHandler.save(sch, Settings.SCHEMATIC_SAVE_PATH + "/" + plot.id.x + ";" + plot.id.y + "," + world + "," + owner.trim() + ".schematic"); if (!result) { PlayerFunctions.sendMessage(plr, "&7 - Failed to save &c" + plot.id); - } else { + } + else { PlayerFunctions.sendMessage(plr, "&7 - &aExport success: " + plot.id); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java index 3ee4df0d0..766bc08fd 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java @@ -21,6 +21,17 @@ package com.intellectualcrafters.plot.commands; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.apache.commons.lang.StringUtils; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.block.Biome; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; @@ -37,24 +48,14 @@ import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; import com.intellectualcrafters.plot.util.StringComparison; -import org.apache.commons.lang.StringUtils; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.block.Biome; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; /** * @author Citymonstret */ public class Set extends SubCommand { - public final static String[] values = new String[]{"biome", "wall", "wall_filling", "floor", "alias", "home", "flag"}; - public final static String[] aliases = new String[]{"b", "w", "wf", "f", "a", "h", "fl"}; + public final static String[] values = new String[] { "biome", "wall", "wall_filling", "floor", "alias", "home", "flag" }; + public final static String[] aliases = new String[] { "b", "w", "wf", "f", "a", "h", "fl" }; public Set() { super(Command.SET, "Set a plot value", "set {arg} {value...}", CommandCategory.ACTIONS, true); @@ -99,7 +100,8 @@ public class Set extends SubCommand { if (PlotMain.worldGuardListener != null) { if (message.equals("")) { message = StringUtils.join(PlotMain.worldGuardListener.str_flags, "&c, &6"); - } else { + } + else { message += "," + StringUtils.join(PlotMain.worldGuardListener.str_flags, "&c, &6"); } } @@ -111,7 +113,8 @@ public class Set extends SubCommand { try { af = FlagManager.getFlag(args[1].toLowerCase()); - } catch (final Exception e) { + } + catch (final Exception e) { af = new AbstractFlag(args[1].toLowerCase()); } @@ -175,12 +178,13 @@ public class Set extends SubCommand { return false; } plot.settings.addFlag(flag); - java.util.Set flags = plot.settings.getFlags(); + final java.util.Set flags = plot.settings.getFlags(); DBFunc.setFlags(plr.getWorld().getName(), plot, flags.toArray(new Flag[flags.size()])); PlayerFunctions.sendMessage(plr, C.FLAG_ADDED); PlotListener.plotEntry(plr, plot); return true; - } catch (final Exception e) { + } + catch (final Exception e) { PlayerFunctions.sendMessage(plr, "&c" + e.getMessage()); return false; } @@ -271,7 +275,8 @@ public class Set extends SubCommand { Material material; try { material = getMaterial(args[1], PlotWorld.BLOCKS); - } catch (NullPointerException e) { + } + catch (final NullPointerException e) { material = null; } /* @@ -291,7 +296,8 @@ public class Set extends SubCommand { if (args.length > 2) { try { data = (byte) Integer.parseInt(args[2]); - } catch (final Exception e) { + } + catch (final Exception e) { PlayerFunctions.sendMessage(plr, C.NOT_VALID_DATA); return true; } @@ -346,11 +352,13 @@ public class Set extends SubCommand { if (ss.length == 1) { blocks[index] = new PlotBlock((short) m.getId(), (byte) 0); - } else { + } + else { byte b; try { b = (byte) Integer.parseInt(ss[1]); - } catch (final Exception e) { + } + catch (final Exception e) { PlayerFunctions.sendMessage(plr, C.NOT_VALID_DATA); return true; } @@ -394,7 +402,8 @@ public class Set extends SubCommand { if (args.length > 2) { try { data = (byte) Integer.parseInt(args[2]); - } catch (final Exception e) { + } + catch (final Exception e) { PlayerFunctions.sendMessage(plr, C.NOT_VALID_DATA); return true; } @@ -406,7 +415,8 @@ public class Set extends SubCommand { AbstractFlag af; try { af = new AbstractFlag(args[0].toLowerCase()); - } catch (final Exception e) { + } + catch (final Exception e) { af = new AbstractFlag(""); } if (FlagManager.getFlags().contains(af)) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java index a4169ab5e..13dace7bb 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java @@ -21,6 +21,12 @@ package com.intellectualcrafters.plot.commands; +import java.util.ArrayList; +import java.util.UUID; + +import org.bukkit.World; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; @@ -30,12 +36,6 @@ import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; import com.intellectualcrafters.plot.util.UUIDHandler; -import org.bukkit.World; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.UUID; - @SuppressWarnings("deprecation") public class SetOwner extends SubCommand { @@ -64,25 +64,25 @@ public class SetOwner extends SubCommand { PlayerFunctions.sendMessage(plr, C.NEED_USER); return true; } - - World world = plr.getWorld(); - PlotId bot = PlayerFunctions.getBottomPlot(world, plot).id; - PlotId top = PlayerFunctions.getTopPlot(world, plot).id; - - ArrayList plots = PlayerFunctions.getPlotSelectionIds(world, bot, top); - - for (PlotId id : plots) { - Plot current = PlotMain.getPlots(world).get(id); + + final World world = plr.getWorld(); + final PlotId bot = PlayerFunctions.getBottomPlot(world, plot).id; + final PlotId top = PlayerFunctions.getTopPlot(world, plot).id; + + final ArrayList plots = PlayerFunctions.getPlotSelectionIds(world, bot, top); + + for (final PlotId id : plots) { + final Plot current = PlotMain.getPlots(world).get(id); current.owner = getUUID(args[0]); PlotMain.updatePlot(current); DBFunc.setOwner(current, current.owner); - + if (PlotMain.worldGuardListener != null) { PlotMain.worldGuardListener.changeOwner(plr, current.owner, plr.getWorld(), current); } } PlotHelper.setSign(world, args[0], plot); - + PlayerFunctions.sendMessage(plr, C.SET_OWNER); return true; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Setup.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Setup.java index e6555b0de..a00592e89 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Setup.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Setup.java @@ -21,13 +21,11 @@ package com.intellectualcrafters.plot.commands; -import com.intellectualcrafters.plot.PlotMain; -import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.config.ConfigurationNode; -import com.intellectualcrafters.plot.generator.DefaultPlotWorld; -import com.intellectualcrafters.plot.object.PlotGenerator; -import com.intellectualcrafters.plot.object.PlotWorld; -import com.intellectualcrafters.plot.util.PlayerFunctions; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.World; @@ -37,10 +35,13 @@ import org.bukkit.event.Listener; import org.bukkit.generator.ChunkGenerator; import org.bukkit.plugin.Plugin; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.ConfigurationNode; +import com.intellectualcrafters.plot.generator.DefaultPlotWorld; +import com.intellectualcrafters.plot.object.PlotGenerator; +import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.util.PlayerFunctions; /** * Created 2014-09-26 for PlotSquared @@ -61,7 +62,8 @@ public class Setup extends SubCommand implements Listener { if (plr == null) { plrname = ""; - } else { + } + else { plrname = plr.getName(); } @@ -75,17 +77,20 @@ public class Setup extends SubCommand implements Listener { } try { PlotMain.config.save(PlotMain.configFile); - } catch (final IOException e) { + } + catch (final IOException e) { e.printStackTrace(); } // Creating the worlds if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) { Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv create " + world + " normal -g " + object.plugin); - } else { + } + else { if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) { Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + world + " plugin:" + object.plugin); - } else { + } + else { for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) { if (plugin.isEnabled()) { if (plugin.getDefaultWorldGenerator("world", "") != null) { @@ -115,7 +120,8 @@ public class Setup extends SubCommand implements Listener { if (args.length < 1) { sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + ""); return true; - } else { + } + else { if (args[0].equalsIgnoreCase("cancel")) { setupMap.remove(plrname); PlayerFunctions.sendMessage(plr, "&cCancelled setup."); @@ -127,7 +133,8 @@ public class Setup extends SubCommand implements Listener { step = object.step[object.current]; sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + ""); return true; - } else { + } + else { sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + ""); return true; } @@ -144,13 +151,15 @@ public class Setup extends SubCommand implements Listener { step = object.step[object.current]; sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + ""); return true; - } else { + } + else { sendMessage(plr, C.SETUP_INVALID_ARG, args[0], step.getConstant()); sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + ""); return true; } } - } else { + } + else { if (args.length < 1) { sendMessage(plr, C.SETUP_MISSING_WORLD); return true; @@ -193,7 +202,8 @@ public class Setup extends SubCommand implements Listener { PlotWorld plotworld; if (generator instanceof PlotGenerator) { plotworld = ((PlotGenerator) generator).getNewPlotWorld(world); - } else { + } + else { plotworld = new DefaultPlotWorld(world); } @@ -207,10 +217,10 @@ public class Setup extends SubCommand implements Listener { } private class SetupObject { - final String world; - final String plugin; + final String world; + final String plugin; final ConfigurationNode[] step; - int current = 0; + int current = 0; public SetupObject(final String world, final PlotWorld plotworld, final String plugin) { this.world = world; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SubCommand.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SubCommand.java index 84f0bc5cf..7ce75b777 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SubCommand.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SubCommand.java @@ -21,26 +21,26 @@ package com.intellectualcrafters.plot.commands; -import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.util.PlayerFunctions; +import java.util.ArrayList; +import java.util.Arrays; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.Arrays; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.util.PlayerFunctions; /** * SubCommand class * * @author Citymonstret */ -@SuppressWarnings({"deprecation", "unused"}) +@SuppressWarnings({ "deprecation", "unused" }) public abstract class SubCommand { /** * Command */ - public final String cmd; + public final String cmd; /** * Permission node */ @@ -48,7 +48,7 @@ public abstract class SubCommand { /** * Simple description */ - public final String description; + public final String description; /** * Aliases */ @@ -56,23 +56,29 @@ public abstract class SubCommand { /** * Command usage */ - public final String usage; + public final String usage; /** * The category */ - public final CommandCategory category; + public final CommandCategory category; /** * Is this a player-online command? */ - public final boolean isPlayer; + public final boolean isPlayer; /** - * @param cmd Command /plot {cmd} <-- That! - * @param permission Permission Node - * @param description Simple description - * @param usage Usage description: /plot command {args...} - * @param alias Command alias - * @param category CommandCategory. Pick whichever is closest to what you want. + * @param cmd + * Command /plot {cmd} <-- That! + * @param permission + * Permission Node + * @param description + * Simple description + * @param usage + * Usage description: /plot command {args...} + * @param alias + * Command alias + * @param category + * CommandCategory. Pick whichever is closest to what you want. */ public SubCommand(final String cmd, final String permission, final String description, final String usage, final String alias, final CommandCategory category, final boolean isPlayer) { this.cmd = cmd; @@ -84,14 +90,20 @@ public abstract class SubCommand { this.category = category; this.isPlayer = isPlayer; } - + /** - * @param cmd Command /plot {cmd} <-- That! - * @param permission Permission Node - * @param description Simple description - * @param usage Usage description: /plot command {args...} - * @param aliases Command aliases - * @param category CommandCategory. Pick whichever is closest to what you want. + * @param cmd + * Command /plot {cmd} <-- That! + * @param permission + * Permission Node + * @param description + * Simple description + * @param usage + * Usage description: /plot command {args...} + * @param aliases + * Command aliases + * @param category + * CommandCategory. Pick whichever is closest to what you want. */ public SubCommand(final String cmd, final String permission, final String description, final String usage, final CommandCategory category, final boolean isPlayer, final String... aliases) { this.cmd = cmd; @@ -105,10 +117,14 @@ public abstract class SubCommand { } /** - * @param command Command /plot {cmd} <-- That! - * @param description Simple description - * @param usage Usage description: /plot command {args...} - * @param category CommandCategory. Pick whichever closests to what you want. + * @param command + * Command /plot {cmd} <-- That! + * @param description + * Simple description + * @param usage + * Usage description: /plot command {args...} + * @param category + * CommandCategory. Pick whichever closests to what you want. */ public SubCommand(final Command command, final String description, final String usage, final CommandCategory category, final boolean isPlayer) { this.cmd = command.getCommand(); @@ -124,8 +140,10 @@ public abstract class SubCommand { /** * Execute. * - * @param plr executor - * @param args arguments + * @param plr + * executor + * @param args + * arguments * @return true on success, false on failure */ public abstract boolean execute(final Player plr, final String... args); @@ -133,7 +151,8 @@ public abstract class SubCommand { /** * Execute the command as console * - * @param args Arguments + * @param args + * Arguments */ public void executeConsole(final String... args) { this.execute(null, args); @@ -142,10 +161,14 @@ public abstract class SubCommand { /** * Send a message * - * @param plr Player who will receive the mssage - * @param c Caption - * @param args Arguments (%s's) - * @see com.intellectualcrafters.plot.util.PlayerFunctions#sendMessage(org.bukkit.entity.Player, com.intellectualcrafters.plot.config.C, String...) + * @param plr + * Player who will receive the mssage + * @param c + * Caption + * @param args + * Arguments (%s's) + * @see com.intellectualcrafters.plot.util.PlayerFunctions#sendMessage(org.bukkit.entity.Player, + * com.intellectualcrafters.plot.config.C, String...) */ public boolean sendMessage(final Player plr, final C c, final String... args) { PlayerFunctions.sendMessage(plr, c, args); @@ -198,7 +221,8 @@ public abstract class SubCommand { /** * Constructor * - * @param name readable name + * @param name + * readable name */ CommandCategory(final String name) { this.name = name; @@ -209,4 +233,4 @@ public abstract class SubCommand { return this.name; } } -} \ No newline at end of file +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Swap.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Swap.java index 9c7a874ee..afe29c2ec 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Swap.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Swap.java @@ -21,6 +21,9 @@ package com.intellectualcrafters.plot.commands; +import org.bukkit.World; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Plot; @@ -29,8 +32,6 @@ import com.intellectualcrafters.plot.object.PlotSelection; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; import com.intellectualcrafters.plot.util.SetBlockFast; -import org.bukkit.World; -import org.bukkit.entity.Player; /** * Created 2014-08-01 for PlotSquared @@ -73,7 +74,8 @@ public class Swap extends SubCommand { PlayerFunctions.sendMessage(plr, C.NO_PERM_MERGE, plotid.toString()); return false; } - } catch (final Exception e) { + } + catch (final Exception e) { PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_ID); PlayerFunctions.sendMessage(plr, C.SWAP_SYNTAX); return false; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/TP.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/TP.java index 9662bf089..b0953539c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/TP.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/TP.java @@ -21,17 +21,17 @@ package com.intellectualcrafters.plot.commands; +import org.apache.commons.lang.StringUtils; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; -import org.apache.commons.lang.StringUtils; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.entity.Player; - /** * @author Citymonstret @@ -70,7 +70,8 @@ public class TP extends SubCommand { plotid = new PlotId(Integer.parseInt(id.split(";")[0]), Integer.parseInt(id.split(";")[1])); PlotMain.teleportPlayer(plr, plr.getLocation(), PlotHelper.getPlot(world, plotid)); return true; - } catch (final Exception e) { + } + catch (final Exception e) { PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_ID); } return false; @@ -88,10 +89,8 @@ public class TP extends SubCommand { @SuppressWarnings("deprecation") final Player player = Bukkit.getPlayer(a); if (player != null) { - final java.util.Set plotMainPlots = - PlotMain.getPlots(world, player); - final Plot[] plots = - plotMainPlots.toArray(new Plot[plotMainPlots.size()]); + final java.util.Set plotMainPlots = PlotMain.getPlots(world, player); + final Plot[] plots = plotMainPlots.toArray(new Plot[plotMainPlots.size()]); if (plots.length > index) { return plots[index]; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trusted.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trusted.java index 5f171c901..e5d365b8b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trusted.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trusted.java @@ -21,6 +21,12 @@ package com.intellectualcrafters.plot.commands; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; @@ -29,12 +35,6 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.UUIDHandler; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; - -import java.util.UUID; - @SuppressWarnings("deprecation") public class Trusted extends SubCommand { @@ -62,7 +62,8 @@ public class Trusted extends SubCommand { if (args[1].equalsIgnoreCase("*")) { uuid = DBFunc.everyone; - } else { + } + else { uuid = UUIDHandler.getUUID(args[1]); } if (!plot.trusted.contains(uuid)) { @@ -87,13 +88,15 @@ public class Trusted extends SubCommand { DBFunc.setTrusted(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1])); final PlayerPlotTrustedEvent event = new PlayerPlotTrustedEvent(plr, plot, uuid, true); Bukkit.getPluginManager().callEvent(event); - } else { + } + else { PlayerFunctions.sendMessage(plr, C.ALREADY_ADDED); return false; } PlayerFunctions.sendMessage(plr, C.TRUSTED_ADDED); return true; - } else if (args[0].equalsIgnoreCase("remove")) { + } + else if (args[0].equalsIgnoreCase("remove")) { if (args[1].equalsIgnoreCase("*")) { final UUID uuid = DBFunc.everyone; if (!plot.trusted.contains(uuid)) { @@ -124,7 +127,8 @@ public class Trusted extends SubCommand { final PlayerPlotTrustedEvent event = new PlayerPlotTrustedEvent(plr, plot, uuid, false); Bukkit.getPluginManager().callEvent(event); PlayerFunctions.sendMessage(plr, C.TRUSTED_REMOVED); - } else { + } + else { PlayerFunctions.sendMessage(plr, C.TRUSTED_NEED_ARGUMENT); return true; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unban.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unban.java index 9f50df2cf..19ef801e9 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unban.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unban.java @@ -1,9 +1,10 @@ package com.intellectualcrafters.plot.commands; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.util.PlayerFunctions; -import org.bukkit.entity.Player; /** * Created 2014-11-09 for PlotSquared @@ -17,14 +18,14 @@ public class Unban extends SubCommand { } @Override - public boolean execute(Player plr, String... args) { + public boolean execute(final Player plr, final String... args) { if (args.length < 1) { - return PlayerFunctions.sendMessage(plr, "&cUsage: &c" + usage); + return PlayerFunctions.sendMessage(plr, "&cUsage: &c" + this.usage); } if (!PlayerFunctions.isInPlot(plr)) { return sendMessage(plr, C.NOT_IN_PLOT); } - Plot plot = PlayerFunctions.getCurrentPlot(plr); + final Plot plot = PlayerFunctions.getCurrentPlot(plr); if (!plot.hasRights(plr)) { return sendMessage(plr, C.NO_PLOT_PERMS); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unclaim.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unclaim.java index 400ad2670..b64cf0fac 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unclaim.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unclaim.java @@ -21,14 +21,16 @@ package com.intellectualcrafters.plot.commands; +import net.milkbowl.vault.economy.Economy; + +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.PlayerFunctions; -import net.milkbowl.vault.economy.Economy; -import org.bukkit.entity.Player; public class Unclaim extends SubCommand { @@ -64,7 +66,8 @@ public class Unclaim extends SubCommand { if ((Math.abs(plot.id.x) <= Math.abs(Auto.lastPlot.x)) && (Math.abs(plot.id.y) <= Math.abs(Auto.lastPlot.y))) { Auto.lastPlot = plot.id; } - } else { + } + else { PlayerFunctions.sendMessage(plr, "Plot removal has been denied."); } return true; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java index c7a48e808..e0c381b3f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java @@ -21,6 +21,12 @@ package com.intellectualcrafters.plot.commands; +import java.util.ArrayList; + +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; @@ -34,12 +40,6 @@ import com.intellectualcrafters.plot.util.PlotHelper; import com.intellectualcrafters.plot.util.SetBlockFast; import com.intellectualcrafters.plot.util.UUIDHandler; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.entity.Player; - -import java.util.ArrayList; - /** * Created 2014-08-01 for PlotSquared * @@ -86,7 +86,9 @@ public class Unlink extends SubCommand { for (final PlotId id : ids) { final Plot myplot = PlotMain.getPlots(world).get(id); - if (plot == null) continue; + if (plot == null) { + continue; + } if (plot.helpers != null) { myplot.helpers = plot.helpers; @@ -95,7 +97,7 @@ public class Unlink extends SubCommand { myplot.denied = plot.denied; } myplot.deny_entry = plot.deny_entry; - myplot.settings.setMerged(new boolean[]{false, false, false, false}); + myplot.settings.setMerged(new boolean[] { false, false, false, false }); DBFunc.setMerged(world.getName(), myplot, myplot.settings.getMerged()); } @@ -124,12 +126,13 @@ public class Unlink extends SubCommand { if (PlotHelper.canSetFast) { SetBlockFast.update(plr); } - } catch (final Exception e) { + } + catch (final Exception e) { // execute(final Player plr, final String... args) { try { - PlotMain.sendConsoleSenderMessage( - "Error on: " + getClass().getMethod("execute", Player.class, String[].class).toGenericString() + ":119, when trying to use \"SetBlockFast#update\""); - } catch (Exception ex) { + PlotMain.sendConsoleSenderMessage("Error on: " + getClass().getMethod("execute", Player.class, String[].class).toGenericString() + ":119, when trying to use \"SetBlockFast#update\""); + } + catch (final Exception ex) { ex.printStackTrace(); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Visit.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Visit.java index 462c4de26..f3647e772 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Visit.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Visit.java @@ -21,15 +21,16 @@ package com.intellectualcrafters.plot.commands; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.util.UUIDHandler; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; public class Visit extends SubCommand { public Visit() { @@ -67,7 +68,8 @@ public class Visit extends SubCommand { int i; try { i = Integer.parseInt(args[1]); - } catch (final Exception e) { + } + catch (final Exception e) { return sendMessage(plr, C.NOT_VALID_NUMBER); } if ((i < 0) || (i >= plots.size())) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java index 33fb952ea..cd043ceba 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java @@ -21,6 +21,12 @@ package com.intellectualcrafters.plot.commands; +import java.util.HashMap; +import java.util.UUID; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Plot; @@ -28,11 +34,6 @@ import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.StringComparison; import com.intellectualcrafters.plot.util.UUIDHandler; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import java.util.HashMap; -import java.util.UUID; /** * @author Citymonstret @@ -60,9 +61,10 @@ public class list extends SubCommand { final StringBuilder builder = new StringBuilder(); builder.append(C.SUBCOMMAND_SET_OPTIONS_HEADER.s()); if (plr != null) { - builder.append(getArgumentList(new String[]{"mine", "shared", "world", "all"})); - } else { - builder.append(getArgumentList(new String[]{"all"})); + builder.append(getArgumentList(new String[] { "mine", "shared", "world", "all" })); + } + else { + builder.append(getArgumentList(new String[] { "all" })); } PlayerFunctions.sendMessage(plr, builder.toString()); return true; @@ -82,7 +84,8 @@ public class list extends SubCommand { string.append(C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "You have").replaceAll("%num%", idx + "").replaceAll("%plot%", idx == 1 ? "plot" : "plots")); PlayerFunctions.sendMessage(plr, string.toString()); return true; - } else if (args[0].equalsIgnoreCase("shared") && (plr != null)) { + } + else if (args[0].equalsIgnoreCase("shared") && (plr != null)) { final StringBuilder string = new StringBuilder(); string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all")).append("\n"); for (final Plot p : PlotMain.getPlotsSorted()) { @@ -93,7 +96,8 @@ public class list extends SubCommand { string.append(C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "There are").replaceAll("%num%", PlotMain.getPlotsSorted().size() + "").replaceAll("%plot%", PlotMain.getPlotsSorted().size() == 1 ? "plot" : "plots")); PlayerFunctions.sendMessage(plr, string.toString()); return true; - } else if (args[0].equalsIgnoreCase("all")) { + } + else if (args[0].equalsIgnoreCase("all")) { // Current page int page = 0; @@ -105,7 +109,8 @@ public class list extends SubCommand { if (page < 0) { page = 0; } - } catch (final Exception e) { + } + catch (final Exception e) { page = 0; } } @@ -140,7 +145,8 @@ public class list extends SubCommand { string.append(C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "There is").replaceAll("%num%", PlotMain.getPlotsSorted().size() + "").replaceAll("%plot%", PlotMain.getPlotsSorted().size() == 1 ? "plot" : "plots")); PlayerFunctions.sendMessage(plr, string.toString()); return true; - } else if (args[0].equalsIgnoreCase("world") && (plr != null)) { + } + else if (args[0].equalsIgnoreCase("world") && (plr != null)) { final StringBuilder string = new StringBuilder(); string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all")).append("\n"); final HashMap plots = PlotMain.getPlots(plr.getWorld()); @@ -150,9 +156,10 @@ public class list extends SubCommand { string.append(C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "There is").replaceAll("%num%", plots.values().size() + "").replaceAll("%plot%", plots.values().size() == 1 ? "plot" : "plots")); PlayerFunctions.sendMessage(plr, string.toString()); return true; - } else { + } + else { // execute(plr); - sendMessage(plr, C.DID_YOU_MEAN, new StringComparison(args[0], new String[]{"mine", "shared", "world", "all"}).getBestMatch()); + sendMessage(plr, C.DID_YOU_MEAN, new StringComparison(args[0], new String[] { "mine", "shared", "world", "all" }).getBestMatch()); return false; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/plugin.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/plugin.java index 61c2a412a..93424882f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/plugin.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/plugin.java @@ -21,18 +21,19 @@ package com.intellectualcrafters.plot.commands; -import com.intellectualcrafters.plot.PlotMain; -import com.intellectualcrafters.plot.util.PlayerFunctions; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.util.PlayerFunctions; + public class plugin extends SubCommand { public static String downloads, version; @@ -47,7 +48,8 @@ public class plugin extends SubCommand { public void run() { try { downloads = convertToNumericString(getInfo("https://intellectualsites.com/spigot_api.php?method=downloads&url=http://www.spigotmc.org/resources/plotsquared.1177/"), false); - } catch (final Exception e) { + } + catch (final Exception e) { downloads = "unknown"; } } @@ -57,7 +59,8 @@ public class plugin extends SubCommand { public void run() { try { version = convertToNumericString(getInfo("https://intellectualsites.com/spigot_api.php?method=version&resource=1177"), true); - } catch (final Exception e) { + } + catch (final Exception e) { // Let's just ignore this, most likely error 500... version = "unknown"; } @@ -70,7 +73,8 @@ public class plugin extends SubCommand { for (final char c : str.toCharArray()) { if (Character.isDigit(c)) { builder.append(c); - } else if (dividers && ((c == ',') || (c == '.') || (c == '-') || (c == '_'))) { + } + else if (dividers && ((c == ',') || (c == '.') || (c == '-') || (c == '_'))) { builder.append(c); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java index 2a8e9d310..c526684a0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -21,11 +21,16 @@ package com.intellectualcrafters.plot.config; -import com.intellectualcrafters.plot.PlotMain; -import com.intellectualsites.translation.*; -import com.intellectualsites.translation.bukkit.BukkitTranslation; import org.bukkit.ChatColor; +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualsites.translation.TranslationFile; +import com.intellectualsites.translation.TranslationLanguage; +import com.intellectualsites.translation.TranslationManager; +import com.intellectualsites.translation.TranslationObject; +import com.intellectualsites.translation.YamlTranslationFile; +import com.intellectualsites.translation.bukkit.BukkitTranslation; + /** * Captions class. * @@ -240,30 +245,21 @@ public enum C { * Info */ PLOT_INFO_UNCLAIMED("&cPlot &6%s&c is not yet claimed"), - /*PLOT_INFO("" + - "&6ID&7: &a%id%&7\n" + - "&6Alias&7: &a%alias%\n" + - "&6Owner&7: &a%owner%\n" + - "&6Helpers&7: &a%helpers%\n" + - "&6Trusted&7: &a%trusted%\n" + - "&6Denied&7: &a%denied%\n" + - "&6Flags&7: &a%flags%\n" + - "&6Biome&7: &a%biome%\n" + - "&6Rating&7: &a%rating%&7/&a10\n" + - "&6Can build&7: &a%build%" - ),*/ - PLOT_INFO( - "&cID: &6%id%&c\n" + - "&cAlias: &6%alias%&c\n" + - "&cOwner: &6%owner%&c\n" + - "&cBiome: &6%biome%&c\n" + - "&cCan Build: &6%build%&c\n" + - "&cRating: &6%rating%&c/&610&c\n" + - "&cHelpers: &6%helpers%&c\n" + - "&cTrusted: &6%trusted%&c\n" + - "&cDenied: &6%denied%&c\n" + - "&cFlags: &6%flags%" - ), + /* + * PLOT_INFO("" + + * "&6ID&7: &a%id%&7\n" + + * "&6Alias&7: &a%alias%\n" + + * "&6Owner&7: &a%owner%\n" + + * "&6Helpers&7: &a%helpers%\n" + + * "&6Trusted&7: &a%trusted%\n" + + * "&6Denied&7: &a%denied%\n" + + * "&6Flags&7: &a%flags%\n" + + * "&6Biome&7: &a%biome%\n" + + * "&6Rating&7: &a%rating%&7/&a10\n" + + * "&6Can build&7: &a%build%" + * ), + */ + PLOT_INFO("&cID: &6%id%&c\n" + "&cAlias: &6%alias%&c\n" + "&cOwner: &6%owner%&c\n" + "&cBiome: &6%biome%&c\n" + "&cCan Build: &6%build%&c\n" + "&cRating: &6%rating%&c/&610&c\n" + "&cHelpers: &6%helpers%&c\n" + "&cTrusted: &6%trusted%&c\n" + "&cDenied: &6%denied%&c\n" + "&cFlags: &6%flags%"), PLOT_INFO_HELPERS("&6Helpers&7: %helpers%"), PLOT_INFO_TRUSTED("&6Trusted&7: %trusted%"), PLOT_INFO_DENIED("&6Denied&7: %denied%"), @@ -394,24 +390,24 @@ public enum C { * * @see com.intellectualsites.translation.TranslationManager */ - private static TranslationManager manager; + private static TranslationManager manager; /** * The default file * * @see com.intellectualsites.translation.TranslationFile */ - private static TranslationFile defaultFile; + private static TranslationFile defaultFile; /** * Default */ - private String d; + private String d; /** * Translated */ - private String s; + private String s; /** * Constructor for custom strings. @@ -426,7 +422,8 @@ public enum C { /** * Constructor * - * @param d default + * @param d + * default */ C(final String d) { this.d = d; @@ -440,14 +437,11 @@ public enum C { manager = new TranslationManager(); } if (defaultFile == null) { - defaultFile = new YamlTranslationFile(BukkitTranslation.getParent(PlotMain.getMain()), lang, "PlotSquared", manager) - .read(); + defaultFile = new YamlTranslationFile(BukkitTranslation.getParent(PlotMain.getMain()), lang, "PlotSquared", manager).read(); } // register everything in this class - for (C c : values()) { - manager.addTranslationObject( - new TranslationObject(c.toString(), c.d, "", "") - ); + for (final C c : values()) { + manager.addTranslationObject(new TranslationObject(c.toString(), c.d, "", "")); } } @@ -473,16 +467,17 @@ public enum C { public String s() { return manager.getTranslated(toString(), lang).getTranslated().replaceAll("&-", "\n").replaceAll("\\n", "\n"); /* - if (PlotMain.translations != null) { - final String t = PlotMain.translations.getString(this.toString()); - if (t != null) { - this.s = t; - } - } - if (this.s.length() < 1) { - return ""; - } - return this.s.replace("\\n", "\n");*/ + * if (PlotMain.translations != null) { + * final String t = PlotMain.translations.getString(this.toString()); + * if (t != null) { + * this.s = t; + * } + * } + * if (this.s.length() < 1) { + * return ""; + * } + * return this.s.replace("\\n", "\n"); + */ } /** diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Configuration.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Configuration.java index 883598c3e..4df60d037 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Configuration.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Configuration.java @@ -21,12 +21,13 @@ package com.intellectualcrafters.plot.config; -import com.intellectualcrafters.plot.object.PlotBlock; -import org.bukkit.block.Biome; - import java.util.ArrayList; import java.util.List; +import org.bukkit.block.Biome; + +import com.intellectualcrafters.plot.object.PlotBlock; + /** * Main Configuration Utility * @@ -35,7 +36,7 @@ import java.util.List; @SuppressWarnings("unused") public class Configuration { - public static final SettingValue STRING = new SettingValue("STRING") { + public static final SettingValue STRING = new SettingValue("STRING") { @Override public boolean validateValue(final String string) { return true; @@ -59,13 +60,14 @@ public class Configuration { } }; - public static final SettingValue INTEGER = new SettingValue("INTEGER") { + public static final SettingValue INTEGER = new SettingValue("INTEGER") { @Override public boolean validateValue(final String string) { try { - int x = Integer.parseInt(string); + Integer.parseInt(string); return true; - } catch (final Exception e) { + } + catch (final Exception e) { return false; } } @@ -76,13 +78,14 @@ public class Configuration { } }; - public static final SettingValue BOOLEAN = new SettingValue("BOOLEAN") { + public static final SettingValue BOOLEAN = new SettingValue("BOOLEAN") { @Override public boolean validateValue(final String string) { try { - boolean b = Boolean.parseBoolean(string); + Boolean.parseBoolean(string); return true; - } catch (final Exception e) { + } + catch (final Exception e) { return false; } } @@ -93,13 +96,14 @@ public class Configuration { } }; - public static final SettingValue DOUBLE = new SettingValue("DOUBLE") { + public static final SettingValue DOUBLE = new SettingValue("DOUBLE") { @Override public boolean validateValue(final String string) { try { - double d = Double.parseDouble(string); + Double.parseDouble(string); return true; - } catch (final Exception e) { + } + catch (final Exception e) { return false; } } @@ -110,13 +114,14 @@ public class Configuration { } }; - public static final SettingValue BIOME = new SettingValue("BIOME") { + public static final SettingValue BIOME = new SettingValue("BIOME") { @Override public boolean validateValue(final String string) { try { Biome.valueOf(string.toUpperCase()); return true; - } catch (final Exception e) { + } + catch (final Exception e) { return false; } } @@ -137,21 +142,21 @@ public class Configuration { } }; - public static final SettingValue BLOCK = new SettingValue("BLOCK") { + public static final SettingValue BLOCK = new SettingValue("BLOCK") { @Override public boolean validateValue(final String string) { try { if (string.contains(":")) { final String[] split = string.split(":"); - short s = - Short.parseShort(split[0]); - short z = - Short.parseShort(split[1]); - } else { - short s = Short.parseShort(string); + Short.parseShort(split[0]); + Short.parseShort(split[1]); + } + else { + Short.parseShort(string); } return true; - } catch (final Exception e) { + } + catch (final Exception e) { return false; } } @@ -161,7 +166,8 @@ public class Configuration { if (string.contains(":")) { final String[] split = string.split(":"); return new PlotBlock(Short.parseShort(split[0]), Byte.parseByte(split[1])); - } else { + } + else { return new PlotBlock(Short.parseShort(string), (byte) 0); } } @@ -171,26 +177,28 @@ public class Configuration { return ((PlotBlock) object).id + ":" + ((PlotBlock) object).data; } }; - public static final SettingValue BLOCKLIST = new SettingValue("BLOCKLIST") { + public static final SettingValue BLOCKLIST = new SettingValue("BLOCKLIST") { @Override public boolean validateValue(final String string) { try { for (String block : string.split(",")) { if (block.contains("%")) { final String[] split = block.split("%"); - int i = Integer.parseInt(split[0]); + Integer.parseInt(split[0]); block = split[1]; } if (block.contains(":")) { final String[] split = block.split(":"); - short s = Short.parseShort(split[0]); - short z = Short.parseShort(split[1]); - } else { - short s = Short.parseShort(block); + Short.parseShort(split[0]); + Short.parseShort(split[1]); + } + else { + Short.parseShort(block); } } return true; - } catch (final Exception e) { + } + catch (final Exception e) { return false; } } @@ -212,7 +220,8 @@ public class Configuration { if (value < min) { min = value; } - } else { + } + else { counts[i] = 1; if (1 < min) { min = 1; @@ -221,7 +230,8 @@ public class Configuration { if (blocks[i].contains(":")) { final String[] split = blocks[i].split(":"); values[i] = new PlotBlock(Short.parseShort(split[0]), Byte.parseByte(split[1])); - } else { + } + else { values[i] = new PlotBlock(Short.parseShort(blocks[i]), (byte) 0); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/ConfigurationNode.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/ConfigurationNode.java index 0f79f2d0e..787693a12 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/ConfigurationNode.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/ConfigurationNode.java @@ -21,10 +21,11 @@ package com.intellectualcrafters.plot.config; -import com.intellectualcrafters.plot.config.Configuration.SettingValue; +import java.util.Arrays; + import org.apache.commons.lang.StringUtils; -import java.util.Arrays; +import com.intellectualcrafters.plot.config.Configuration.SettingValue; /** * Configuration Node @@ -32,11 +33,11 @@ import java.util.Arrays; * @author Empire92 */ public class ConfigurationNode { - private final String constant; - private final Object default_value; - private final String description; + private final String constant; + private final Object default_value; + private final String description; private final SettingValue type; - private Object value; + private Object value; public ConfigurationNode(final String constant, final Object default_value, final String description, final SettingValue type, final boolean required) { this.constant = constant; @@ -54,7 +55,8 @@ public class ConfigurationNode { try { final Object result = this.type.parseString(string); return result != null; - } catch (final Exception e) { + } + catch (final Exception e) { return false; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java index 4991a619c..45c666af8 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java @@ -29,99 +29,100 @@ package com.intellectualcrafters.plot.config; */ public class Settings { /** - * + * */ - public static int MAX_AUTO_SIZE = 4; + public static int MAX_AUTO_SIZE = 4; /** * Default worldedit-require-selection-in-mask: false */ - public static boolean REQUIRE_SELECTION = true; + public static boolean REQUIRE_SELECTION = true; /** * Default kill road mobs: true */ - public final static boolean KILL_ROAD_MOBS_DEFAULT = true; + public final static boolean KILL_ROAD_MOBS_DEFAULT = true; /** * Default mob pathfinding: true */ - public final static boolean MOB_PATHFINDING_DEFAULT = true; + public final static boolean MOB_PATHFINDING_DEFAULT = true; /** * Teleport to path on login */ - public static boolean TELEPORT_ON_LOGIN = false; + public static boolean TELEPORT_ON_LOGIN = false; /** * Mob Cap Enabled */ - public static boolean MOB_CAP_ENABLED = false; + public static boolean MOB_CAP_ENABLED = false; /** * The Mob Cap */ - public static int MOB_CAP = 20; + public static int MOB_CAP = 20; /** * Display titles */ - public static boolean TITLES = true; + public static boolean TITLES = true; /** * Schematic Save Path */ - public static String SCHEMATIC_SAVE_PATH = "/var/www/schematics"; + public static String SCHEMATIC_SAVE_PATH = "/var/www/schematics"; /** * Max allowed plots */ - public static int MAX_PLOTS = 20; + public static int MAX_PLOTS = 20; /** * WorldGuard region on claimed plots */ - public static boolean WORLDGUARD = false; + public static boolean WORLDGUARD = false; /** * metrics */ - public static boolean METRICS = true; + public static boolean METRICS = true; /** * plot specific resource pack */ - public static String PLOT_SPECIFIC_RESOURCE_PACK = ""; + public static String PLOT_SPECIFIC_RESOURCE_PACK = ""; /** * Kill road mobs? */ - public static boolean KILL_ROAD_MOBS; + public static boolean KILL_ROAD_MOBS; /** * mob pathfinding? */ - public static boolean MOB_PATHFINDING; + public static boolean MOB_PATHFINDING; /** * Delete plots on ban? */ - public static boolean DELETE_PLOTS_ON_BAN = false; + public static boolean DELETE_PLOTS_ON_BAN = false; /** * Verbose? */ - public static boolean DEBUG = true; + public static boolean DEBUG = true; /** * Auto clear enabled */ - public static boolean AUTO_CLEAR = false; + public static boolean AUTO_CLEAR = false; /** * Days until a plot gets cleared */ - public static int AUTO_CLEAR_DAYS = 365; + public static int AUTO_CLEAR_DAYS = 365; /** * API Location */ - public static String API_URL = "http://www.intellectualsites.com/minecraft.php"; + public static String API_URL = "http://www.intellectualsites.com/minecraft.php"; /** * Use the custom API */ - public static boolean CUSTOM_API = true; - + public static boolean CUSTOM_API = true; + /** * Use offline mode storage */ - public static boolean OFFLINE_MODE = false; + public static boolean OFFLINE_MODE = false; + /** * Database settings * @@ -131,7 +132,7 @@ public class Settings { /** * MongoDB enabled? */ - public static boolean USE_MONGO = false; /* + public static boolean USE_MONGO = false; /* * TODO: Implement Mongo * @Brandon */ @@ -142,34 +143,34 @@ public class Settings { /** * MySQL Enabled? */ - public static boolean USE_MYSQL = true; /* NOTE: Fixed connector */ + public static boolean USE_MYSQL = true; /* NOTE: Fixed connector */ /** * SQLite Database name */ - public static String SQLITE_DB = "storage"; + public static String SQLITE_DB = "storage"; /** * MySQL Host name */ - public static String HOST_NAME = "localhost"; + public static String HOST_NAME = "localhost"; /** * MySQL Port */ - public static String PORT = "3306"; + public static String PORT = "3306"; /** * MySQL DB */ - public static String DATABASE = "plot_db"; + public static String DATABASE = "plot_db"; /** * MySQL User */ - public static String USER = "root"; + public static String USER = "root"; /** * MySQL Password */ - public static String PASSWORD = "password"; + public static String PASSWORD = "password"; /** * MySQL Prefix */ - public static String PREFIX = ""; + public static String PREFIX = ""; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java index 3c7c4308b..7d7df55d1 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java @@ -21,18 +21,19 @@ package com.intellectualcrafters.plot.database; -import com.intellectualcrafters.plot.flag.Flag; -import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotComment; -import com.intellectualcrafters.plot.object.PlotId; -import org.bukkit.OfflinePlayer; - import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.UUID; +import org.bukkit.OfflinePlayer; + +import com.intellectualcrafters.plot.flag.Flag; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotComment; +import com.intellectualcrafters.plot.object.PlotId; + /** * @author Citymonstret * @author Empire92 @@ -49,61 +50,73 @@ public interface AbstractDB { /** * Set Plot owner * - * @param plot Plot in which the owner should be set - * @param uuid The uuid of the new owner + * @param plot + * Plot in which the owner should be set + * @param uuid + * The uuid of the new owner */ public void setOwner(final Plot plot, final UUID uuid); /** * Create all settings, and create default helpers, trusted + denied lists * - * @param plots Plots for which the default table entries should be created + * @param plots + * Plots for which the default table entries should be created */ public void createAllSettingsAndHelpers(final ArrayList plots); /** * Create a plot * - * @param plots Plots that should be created + * @param plots + * Plots that should be created */ public void createPlots(final ArrayList plots); /** * Create a plot * - * @param plot That should be created + * @param plot + * That should be created */ public void createPlot(final Plot plot); /** * Create tables * - * @param database Database in which the tables will be created + * @param database + * Database in which the tables will be created * - * @throws SQLException If the database manager is unable to create the tables + * @throws SQLException + * If the database manager is unable to create the tables */ public void createTables(final String database, final boolean add_constraint) throws Exception; /** * Delete a plot * - * @param plot Plot that should be deleted + * @param plot + * Plot that should be deleted */ public void delete(final String world, final Plot plot); /** * Create plot settings * - * @param id Plot Entry ID - * @param plot Plot Object + * @param id + * Plot Entry ID + * @param plot + * Plot Object */ public void createPlotSettings(final int id, final Plot plot); /** * Get the table entry ID * - * @param world Which the plot is located in - * @param id2 Plot ID + * @param world + * Which the plot is located in + * @param id2 + * Plot ID * @return Integer = Plot Entry Id */ public int getId(final String world, final PlotId id2); @@ -116,97 +129,125 @@ public interface AbstractDB { /** * Set the merged status for a plot * - * @param world World in which the plot is located - * @param plot Plot Object - * @param merged boolean[] + * @param world + * World in which the plot is located + * @param plot + * Plot Object + * @param merged + * boolean[] */ public void setMerged(final String world, final Plot plot, final boolean[] merged); /** * Set plot flags * - * @param world World in which the plot is located - * @param plot Plot Object - * @param flags flags to set (flag[]) + * @param world + * World in which the plot is located + * @param plot + * Plot Object + * @param flags + * flags to set (flag[]) */ public void setFlags(final String world, final Plot plot, final Flag[] flags); /** * Set the plot alias * - * @param plot Plot for which the alias should be set - * @param alias Plot Alias + * @param plot + * Plot for which the alias should be set + * @param alias + * Plot Alias */ public void setAlias(final String world, final Plot plot, final String alias); /** * Purgle a plot * - * @param world World in which the plot is located - * @param id Plot ID + * @param world + * World in which the plot is located + * @param id + * Plot ID */ public void purge(final String world, final PlotId id); /** * Purge a whole world * - * @param world World in which the plots should be purged + * @param world + * World in which the plots should be purged */ public void purge(final String world); /** * Set Plot Home Position - * @param plot Plot Object - * @param position Plot Home Position + * + * @param plot + * Plot Object + * @param position + * Plot Home Position */ public void setPosition(final String world, final Plot plot, final String position); /** - * @param id Plot Entry ID + * @param id + * Plot Entry ID * @return Plot Settings */ public HashMap getSettings(final int id); /** - * @param plot Plot Object - * @param player Player that should be removed + * @param plot + * Plot Object + * @param player + * Player that should be removed */ public void removeHelper(final String world, final Plot plot, final OfflinePlayer player); /** - * @param plot Plot Object - * @param player Player that should be removed + * @param plot + * Plot Object + * @param player + * Player that should be removed */ public void removeTrusted(final String world, final Plot plot, final OfflinePlayer player); /** - * @param plot Plot Object - * @param player Player that should be removed + * @param plot + * Plot Object + * @param player + * Player that should be removed */ public void setHelper(final String world, final Plot plot, final OfflinePlayer player); /** - * @param plot Plot Object - * @param player Player that should be added + * @param plot + * Plot Object + * @param player + * Player that should be added */ public void setTrusted(final String world, final Plot plot, final OfflinePlayer player); /** - * @param plot Plot Object - * @param player Player that should be added + * @param plot + * Plot Object + * @param player + * Player that should be added */ public void removeDenied(final String world, final Plot plot, final OfflinePlayer player); /** - * @param plot Plot Object - * @param player Player that should be added + * @param plot + * Plot Object + * @param player + * Player that should be added */ public void setDenied(final String world, final Plot plot, final OfflinePlayer player); /** * Get Plots ratings * - * @param plot Plot Object + * @param plot + * Plot Object * @return Plot Ratings (pre-calculated) */ public double getRatings(final Plot plot); @@ -214,27 +255,36 @@ public interface AbstractDB { /** * Remove a plot comment * - * @param world World in which the plot is located - * @param plot Plot Object - * @param comment Comment to remove + * @param world + * World in which the plot is located + * @param plot + * Plot Object + * @param comment + * Comment to remove */ public void removeComment(final String world, final Plot plot, final PlotComment comment); /** * Set a plot comment * - * @param world World in which the plot is located - * @param plot Plot Object - * @param comment Comment to add + * @param world + * World in which the plot is located + * @param plot + * Plot Object + * @param comment + * Comment to add */ public void setComment(final String world, final Plot plot, final PlotComment comment); /** * Get Plot Comments * - * @param world World in which the plot is located - * @param plot Plot Object - * @param tier Comment Tier + * @param world + * World in which the plot is located + * @param plot + * Plot Object + * @param tier + * Comment Tier * @return Plot Comments within the specified tier */ public ArrayList getComments(final String world, final Plot plot, final int tier); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java index fdce3bb2e..0153f590f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java @@ -21,17 +21,18 @@ package com.intellectualcrafters.plot.database; -import com.intellectualcrafters.plot.flag.Flag; -import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotComment; -import com.intellectualcrafters.plot.object.PlotId; -import org.bukkit.OfflinePlayer; - import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.UUID; +import org.bukkit.OfflinePlayer; + +import com.intellectualcrafters.plot.flag.Flag; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotComment; +import com.intellectualcrafters.plot.object.PlotId; + /** * DB Functions * @@ -51,8 +52,11 @@ public class DBFunc { /** * Set the owner of a plot - * @param plot Plot Object - * @param uuid New Owner + * + * @param plot + * Plot Object + * @param uuid + * New Owner */ public static void setOwner(final Plot plot, final UUID uuid) { dbManager.setOwner(plot, uuid); @@ -60,7 +64,9 @@ public class DBFunc { /** * Create all settings + (helpers, denied, trusted) - * @param plots List containing all plot objects + * + * @param plots + * List containing all plot objects */ public static void createAllSettingsAndHelpers(final ArrayList plots) { dbManager.createAllSettingsAndHelpers(plots); @@ -68,7 +74,9 @@ public class DBFunc { /** * Create all plots - * @param plots A list containing plot objects + * + * @param plots + * A list containing plot objects */ public static void createPlots(final ArrayList plots) { dbManager.createPlots(plots); @@ -77,7 +85,8 @@ public class DBFunc { /** * Create a plot * - * @param plot Plot to create + * @param plot + * Plot to create */ public static void createPlot(final Plot plot) { dbManager.createPlot(plot); @@ -95,7 +104,8 @@ public class DBFunc { /** * Delete a plot * - * @param plot Plot to delete + * @param plot + * Plot to delete */ public static void delete(final String world, final Plot plot) { dbManager.delete(world, plot); @@ -104,8 +114,10 @@ public class DBFunc { /** * Create plot settings * - * @param id Plot ID - * @param plot Plot Object + * @param id + * Plot ID + * @param plot + * Plot Object */ public static void createPlotSettings(final int id, final Plot plot) { dbManager.createPlotSettings(id, plot); @@ -114,8 +126,10 @@ public class DBFunc { /** * Get a plot id * - * @param world World - * @param id2 Plot ID + * @param world + * World + * @param id2 + * Plot ID * @return ID */ /* diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/Database.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/Database.java index fa03cf823..f593837e7 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/Database.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/Database.java @@ -21,12 +21,12 @@ package com.intellectualcrafters.plot.database; -import org.bukkit.plugin.Plugin; - import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; +import org.bukkit.plugin.Plugin; + /** * Abstract Database class, serves as a base for any connection method (MySQL, * SQLite, etc.) @@ -44,7 +44,8 @@ public abstract class Database { /** * Creates a new Database * - * @param plugin Plugin instance + * @param plugin + * Plugin instance */ protected Database(final Plugin plugin) { this.plugin = plugin; @@ -54,8 +55,10 @@ public abstract class Database { * Opens a connection with the database * * @return Opened connection - * @throws SQLException if the connection can not be opened - * @throws ClassNotFoundException if the driver cannot be found + * @throws SQLException + * if the connection can not be opened + * @throws ClassNotFoundException + * if the driver cannot be found */ public abstract Connection openConnection() throws SQLException, ClassNotFoundException; @@ -63,7 +66,8 @@ public abstract class Database { * Checks if a connection is open with the database * * @return true if the connection is open - * @throws SQLException if the connection cannot be checked + * @throws SQLException + * if the connection cannot be checked */ public abstract boolean checkConnection() throws SQLException; @@ -78,7 +82,8 @@ public abstract class Database { * Closes the connection with the database * * @return true if successful - * @throws SQLException if the connection cannot be closed + * @throws SQLException + * if the connection cannot be closed */ public abstract boolean closeConnection() throws SQLException; @@ -86,10 +91,13 @@ public abstract class Database { * Executes a SQL Query
* If the connection is closed, it will be opened * - * @param query Query to be run + * @param query + * Query to be run * @return the results of the query - * @throws SQLException If the query cannot be executed - * @throws ClassNotFoundException If the driver cannot be found; see {@link #openConnection()} + * @throws SQLException + * If the query cannot be executed + * @throws ClassNotFoundException + * If the driver cannot be found; see {@link #openConnection()} */ public abstract ResultSet querySQL(final String query) throws SQLException, ClassNotFoundException; @@ -98,10 +106,13 @@ public abstract class Database { * See {@link java.sql.Statement#executeUpdate(String)}
* If the connection is closed, it will be opened * - * @param query Query to be run + * @param query + * Query to be run * @return Result Code, see {@link java.sql.Statement#executeUpdate(String)} - * @throws SQLException If the query cannot be executed - * @throws ClassNotFoundException If the driver cannot be found; see {@link #openConnection()} + * @throws SQLException + * If the query cannot be executed + * @throws ClassNotFoundException + * If the driver cannot be found; see {@link #openConnection()} */ public abstract int updateSQL(final String query) throws SQLException, ClassNotFoundException; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/MySQL.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/MySQL.java index 6338bee7f..f50312f11 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/MySQL.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/MySQL.java @@ -21,9 +21,13 @@ package com.intellectualcrafters.plot.database; -import org.bukkit.plugin.Plugin; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; -import java.sql.*; +import org.bukkit.plugin.Plugin; /** * Connects to and uses a MySQL database @@ -38,17 +42,23 @@ public class MySQL extends Database { private final String port; private final String hostname; - private Connection connection; + private Connection connection; /** * Creates a new MySQL instance * - * @param plugin Plugin instance - * @param hostname Name of the host - * @param port Port number - * @param database Database name - * @param username Username - * @param password Password + * @param plugin + * Plugin instance + * @param hostname + * Name of the host + * @param port + * Port number + * @param database + * Database name + * @param username + * Username + * @param password + * Password */ public MySQL(final Plugin plugin, final String hostname, final String port, final String database, final String username, final String password) { super(plugin); @@ -65,7 +75,7 @@ public class MySQL extends Database { this.connection = DriverManager.getConnection("jdbc:mysql://" + this.hostname + ":" + this.port + "/" + this.database, this.user, this.password); return this.connection; } - + @Override public Connection openConnection() throws SQLException, ClassNotFoundException { if (checkConnection()) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java index 4411158f2..6930d6a5a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java @@ -21,6 +21,22 @@ package com.intellectualcrafters.plot.database; +import java.io.IOException; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.WorldCreator; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.plugin.Plugin; + import com.google.common.base.Charsets; import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.Settings; @@ -31,16 +47,6 @@ import com.worldcretornica.plotme.PlayerList; import com.worldcretornica.plotme.Plot; import com.worldcretornica.plotme.PlotManager; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.WorldCreator; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.plugin.Plugin; - -import java.io.IOException; -import java.lang.reflect.Field; -import java.util.*; - /** * Created 2014-08-17 for PlotSquared * @@ -57,13 +63,14 @@ public class PlotMeConverter { /** * Constructor * - * @param plugin Plugin Used to run the converter + * @param plugin + * Plugin Used to run the converter */ public PlotMeConverter(final PlotMain plugin) { this.plugin = plugin; } - private void sendMessage(String message) { + private void sendMessage(final String message) { PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: " + message); } @@ -75,17 +82,13 @@ public class PlotMeConverter { public void run() { sendMessage("&7Conversion has started"); sendMessage("7Caching playerdata..."); - final ArrayList createdPlots = - new ArrayList<>(); + final ArrayList createdPlots = new ArrayList<>(); // Online Mode - final boolean online = - Bukkit.getServer().getOnlineMode() && !Settings.OFFLINE_MODE; + final boolean online = Bukkit.getServer().getOnlineMode() && !Settings.OFFLINE_MODE; // PlotMe Plugin - final Plugin plotMePlugin = - Bukkit.getPluginManager().getPlugin("PlotMe"); + final Plugin plotMePlugin = Bukkit.getPluginManager().getPlugin("PlotMe"); // PlotMe Configuration - final FileConfiguration plotConfig = - plotMePlugin.getConfig(); + final FileConfiguration plotConfig = plotMePlugin.getConfig(); // Plot Worlds final Set worlds = new HashSet<>(); // Loop through the worlds @@ -124,7 +127,8 @@ public class PlotMeConverter { final Boolean auto_link = plotConfig.getBoolean("worlds." + world.getName() + ".AutoLinkPlots"); // PlotMain.config.set("worlds." + world.getName() + ".plot.auto_merge", auto_link); - } catch (final Exception e) { + } + catch (final Exception e) { sendMessage("&c-- &lFailed to save configuration for world '" + world.getName() + "'\nThis will need to be done using the setup command, or manually"); } @@ -169,11 +173,13 @@ public class PlotMeConverter { psDenied.add(set.getValue()); } } - } else { + } + else { for (final String user : plot.getAllowed().split(",")) { if (user.equals("*")) { psAdded.add(DBFunc.everyone); - } else { + } + else { final UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + user).getBytes(Charsets.UTF_8)); psAdded.add(uuid); } @@ -182,16 +188,19 @@ public class PlotMeConverter { for (final String user : plot.getDenied().split(",")) { if (user.equals("*")) { psDenied.add(DBFunc.everyone); - } else { + } + else { final UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + user).getBytes(Charsets.UTF_8)); psDenied.add(uuid); } } - } catch (final Throwable e) { + } + catch (final Throwable e) { // Okay, this is evil. } } - } catch (final Throwable e) { + } + catch (final Throwable e) { e.printStackTrace(); } final PlotId id = new PlotId(Integer.parseInt(plot.id.split(";")[0]), Integer.parseInt(plot.id.split(";")[1])); @@ -199,18 +208,20 @@ public class PlotMeConverter { if (online) { pl = new com.intellectualcrafters.plot.object.Plot(id, plot.getOwnerId(), psAdded, psTrusted, psDenied, - "", PlotHomePosition.DEFAULT, null, world.getName(), new boolean[]{false, false, false, false}); - } else { + "", PlotHomePosition.DEFAULT, null, world.getName(), new boolean[] { false, false, false, false }); + } + else { final String owner = plot.getOwner(); pl = new com.intellectualcrafters.plot.object.Plot(id, UUID.nameUUIDFromBytes(("OfflinePlayer:" + owner).getBytes(Charsets.UTF_8)), psAdded, psTrusted, psDenied, - "", PlotHomePosition.DEFAULT, null, world.getName(), new boolean[]{false, false, false, false}); + "", PlotHomePosition.DEFAULT, null, world.getName(), new boolean[] { false, false, false, false }); } if (pl != null) { if (!PlotMain.getPlots(world).containsKey(id)) { createdPlots.add(pl); - } else { + } + else { duplicate++; } } @@ -229,7 +240,8 @@ public class PlotMeConverter { PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8:&7 Saving configuration..."); try { PlotMain.config.save(PlotMain.configFile); - } catch (final IOException e) { + } + catch (final IOException e) { PlotMain.sendConsoleSenderMessage(" - &cFailed to save configuration."); } @@ -238,7 +250,8 @@ public class PlotMeConverter { if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) { MV = true; - } else if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) { + } + else if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) { MW = true; } @@ -253,22 +266,26 @@ public class PlotMeConverter { Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv unload " + worldname); try { Thread.sleep(1000); - } catch (final InterruptedException ex) { + } + catch (final InterruptedException ex) { Thread.currentThread().interrupt(); } // load Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv import " + worldname + " normal -g PlotSquared"); - } else if (MW) { + } + else if (MW) { // unload Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw unload " + worldname); try { Thread.sleep(1000); - } catch (final InterruptedException ex) { + } + catch (final InterruptedException ex) { Thread.currentThread().interrupt(); } // load Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + worldname + " plugin:PlotSquared"); - } else { + } + else { Bukkit.getServer().unloadWorld(world, true); final World myworld = WorldCreator.name(worldname).generator(new WorldGenerator(worldname)).createWorld(); myworld.save(); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index a08d43b79..6eb1bd407 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -21,6 +21,24 @@ package com.intellectualcrafters.plot.database; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.Set; +import java.util.UUID; + +import org.apache.commons.lang.StringUtils; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.block.Biome; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; @@ -32,94 +50,87 @@ import com.intellectualcrafters.plot.util.Logger; import com.intellectualcrafters.plot.util.Logger.LogLevel; import com.intellectualcrafters.plot.util.UUIDHandler; -import org.apache.commons.lang.StringUtils; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.block.Biome; - -import java.sql.*; -import java.util.*; - /** * @author Citymonstret */ public class SQLManager implements AbstractDB { // Public final - public final String SET_OWNER; - public final String GET_ALL_PLOTS; - public final String CREATE_PLOTS; - public final String CREATE_SETTINGS; - public final String CREATE_HELPERS; - public final String CREATE_PLOT; + public final String SET_OWNER; + public final String GET_ALL_PLOTS; + public final String CREATE_PLOTS; + public final String CREATE_SETTINGS; + public final String CREATE_HELPERS; + public final String CREATE_PLOT; // Private Final - private Connection connection; + private Connection connection; private final String prefix; /** * Constructor * - * @param c connection - * @param p prefix + * @param c + * connection + * @param p + * prefix */ - public SQLManager(Connection c, String p) { + public SQLManager(final Connection c, final String p) { // Private final - connection = c; - prefix = p; + this.connection = c; + this.prefix = p; // Set timout -// setTimout(); - - // Public final - SET_OWNER = - "UPDATE `" + prefix + "plot` SET `owner` = ? WHERE `plot_id_x` = ? AND `plot_id_z` = ?"; - GET_ALL_PLOTS = - "SELECT `id`, `plot_id_x`, `plot_id_z`, `world` FROM `" + prefix + "plot`"; - CREATE_PLOTS = - "INSERT INTO `" + prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) values "; - CREATE_SETTINGS = - "INSERT INTO `" + prefix + "plot_settings` (`plot_plot_id`) values "; - CREATE_HELPERS = - "INSERT INTO `" + prefix + "plot_helpers` (`plot_plot_id`, `user_uuid`) values "; - CREATE_PLOT = - "INSERT INTO `" + prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) VALUES(?, ?, ?, ?)"; + // setTimout(); - //schedule reconnect + // Public final + this.SET_OWNER = "UPDATE `" + this.prefix + "plot` SET `owner` = ? WHERE `plot_id_x` = ? AND `plot_id_z` = ?"; + this.GET_ALL_PLOTS = "SELECT `id`, `plot_id_x`, `plot_id_z`, `world` FROM `" + this.prefix + "plot`"; + this.CREATE_PLOTS = "INSERT INTO `" + this.prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) values "; + this.CREATE_SETTINGS = "INSERT INTO `" + this.prefix + "plot_settings` (`plot_plot_id`) values "; + this.CREATE_HELPERS = "INSERT INTO `" + this.prefix + "plot_helpers` (`plot_plot_id`, `user_uuid`) values "; + this.CREATE_PLOT = "INSERT INTO `" + this.prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) VALUES(?, ?, ?, ?)"; + + // schedule reconnect if (PlotMain.getMySQL() != null) { - Bukkit.getScheduler().scheduleSyncRepeatingTask(PlotMain.getMain(), new Runnable(){ - public void run(){ + Bukkit.getScheduler().scheduleSyncRepeatingTask(PlotMain.getMain(), new Runnable() { + @Override + public void run() { try { - connection = PlotMain.getMySQL().forceConnection(); + SQLManager.this.connection = PlotMain.getMySQL().forceConnection(); } - catch (Exception e) { + catch (final Exception e) { e.printStackTrace(); } } }, 11000, 11000); } - + } -// -// public void setTimout() { -// runTask(new Runnable() { -// @Override -// public void run() { -// try { -// final PreparedStatement statement = connection.prepareStatement("SET GLOBAL wait_timeout =28800;"); -// statement.executeQuery(); -// statement.close(); -// } catch (final SQLException e) { -// e.printStackTrace(); -// Logger.add(LogLevel.DANGER, "Could not reset MySQL timout."); -// } -// } -// }); -// } - + + // + // public void setTimout() { + // runTask(new Runnable() { + // @Override + // public void run() { + // try { + // final PreparedStatement statement = + // connection.prepareStatement("SET GLOBAL wait_timeout =28800;"); + // statement.executeQuery(); + // statement.close(); + // } catch (final SQLException e) { + // e.printStackTrace(); + // Logger.add(LogLevel.DANGER, "Could not reset MySQL timout."); + // } + // } + // }); + // } + /** * Set Plot owner * - * @param plot Plot Object - * @param uuid Owner UUID + * @param plot + * Plot Object + * @param uuid + * Owner UUID */ @Override public void setOwner(final Plot plot, final UUID uuid) { @@ -127,13 +138,14 @@ public class SQLManager implements AbstractDB { @Override public void run() { try { - final PreparedStatement statement = connection.prepareStatement(SET_OWNER); + final PreparedStatement statement = SQLManager.this.connection.prepareStatement(SQLManager.this.SET_OWNER); statement.setString(1, uuid.toString()); statement.setInt(2, plot.id.x); statement.setInt(3, plot.id.y); statement.executeUpdate(); statement.close(); - } catch (final SQLException e) { + } + catch (final SQLException e) { e.printStackTrace(); Logger.add(LogLevel.DANGER, "Could not set owner for plot " + plot.id); } @@ -150,7 +162,7 @@ public class SQLManager implements AbstractDB { final HashMap> stored = new HashMap<>(); final HashMap> helpers = new HashMap<>(); try { - final PreparedStatement stmt = connection.prepareStatement(GET_ALL_PLOTS); + final PreparedStatement stmt = this.connection.prepareStatement(this.GET_ALL_PLOTS); final ResultSet result = stmt.executeQuery(); while (result.next()) { final int id = result.getInt("id"); @@ -163,7 +175,8 @@ public class SQLManager implements AbstractDB { } stored.get(world).put(new PlotId(idx, idz), id); } - } catch (final SQLException e) { + } + catch (final SQLException e) { e.printStackTrace(); } @@ -183,26 +196,27 @@ public class SQLManager implements AbstractDB { // add plot settings final Integer[] ids = helpers.keySet().toArray(new Integer[helpers.keySet().size()]); - StringBuilder statement = new StringBuilder(CREATE_SETTINGS); + StringBuilder statement = new StringBuilder(this.CREATE_SETTINGS); for (int i = 0; i < (ids.length - 1); i++) { statement.append("(?),"); } statement.append("(?)"); PreparedStatement stmt = null; try { - stmt = connection.prepareStatement(statement.toString()); + stmt = this.connection.prepareStatement(statement.toString()); for (int i = 0; i < ids.length; i++) { stmt.setInt(i + 1, ids[i]); } stmt.executeUpdate(); stmt.close(); - } catch (final SQLException e) { + } + catch (final SQLException e) { e.printStackTrace(); } // add plot helpers String prefix = ""; - statement = new StringBuilder(CREATE_HELPERS); + statement = new StringBuilder(this.CREATE_HELPERS); for (final Integer id : helpers.keySet()) { for (final UUID helper : helpers.get(id)) { statement.append(prefix + "(?, ?)"); @@ -213,7 +227,7 @@ public class SQLManager implements AbstractDB { return; } try { - stmt = connection.prepareStatement(statement.toString()); + stmt = this.connection.prepareStatement(statement.toString()); int counter = 0; for (final Integer id : helpers.keySet()) { for (final UUID helper : helpers.get(id)) { @@ -225,7 +239,8 @@ public class SQLManager implements AbstractDB { } stmt.executeUpdate(); stmt.close(); - } catch (final SQLException e) { + } + catch (final SQLException e) { Logger.add(LogLevel.WARNING, "Failed to set helper for plots"); e.printStackTrace(); } @@ -245,7 +260,7 @@ public class SQLManager implements AbstractDB { if (plots.size() == 0) { return; } - final StringBuilder statement = new StringBuilder(CREATE_PLOTS); + final StringBuilder statement = new StringBuilder(this.CREATE_PLOTS); for (int i = 0; i < (plots.size() - 1); i++) { statement.append("(?,?,?,?),"); @@ -254,7 +269,7 @@ public class SQLManager implements AbstractDB { PreparedStatement stmt = null; try { - stmt = connection.prepareStatement(statement.toString()); + stmt = this.connection.prepareStatement(statement.toString()); for (int i = 0; i < plots.size(); i++) { final Plot plot = plots.get(i); stmt.setInt((i * 4) + 1, plot.id.x); @@ -264,7 +279,8 @@ public class SQLManager implements AbstractDB { } stmt.executeUpdate(); stmt.close(); - } catch (final SQLException e) { + } + catch (final SQLException e) { e.printStackTrace(); Logger.add(LogLevel.DANGER, "Failed to save plots!"); } @@ -279,14 +295,15 @@ public class SQLManager implements AbstractDB { public void createPlot(final Plot plot) { PreparedStatement stmt = null; try { - stmt = connection.prepareStatement(CREATE_PLOT); + stmt = this.connection.prepareStatement(this.CREATE_PLOT); stmt.setInt(1, plot.id.x); stmt.setInt(2, plot.id.y); stmt.setString(3, plot.owner.toString()); stmt.setString(4, plot.world); stmt.executeUpdate(); stmt.close(); - } catch (final SQLException e) { + } + catch (final SQLException e) { e.printStackTrace(); Logger.add(LogLevel.DANGER, "Failed to save plot " + plot.id); } @@ -299,32 +316,30 @@ public class SQLManager implements AbstractDB { */ @Override public void createTables(final String database, final boolean add_constraint) throws SQLException { - - - - + final boolean mysql = database.equals("mysql"); - final Statement stmt = connection.createStatement(); + final Statement stmt = this.connection.createStatement(); if (mysql) { - stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + prefix + "plot` (" + "`id` INT(11) NOT NULL AUTO_INCREMENT," + "`plot_id_x` INT(11) NOT NULL," + "`plot_id_z` INT(11) NOT NULL," + "`owner` VARCHAR(45) NOT NULL," + "`world` VARCHAR(45) NOT NULL," + "`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP," + "PRIMARY KEY (`id`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=0"); - stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + prefix + "plot_denied` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); - stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + prefix + "plot_helpers` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); - stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + prefix + "plot_comments` (" + "`plot_plot_id` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`tier` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); - stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + prefix + "plot_trusted` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); - stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + prefix + "plot_settings` (" + " `plot_plot_id` INT(11) NOT NULL," + " `biome` VARCHAR(45) DEFAULT 'FOREST'," + " `rain` INT(1) DEFAULT 0," + " `custom_time` TINYINT(1) DEFAULT '0'," + " `time` INT(11) DEFAULT '8000'," + " `deny_entry` TINYINT(1) DEFAULT '0'," + " `alias` VARCHAR(50) DEFAULT NULL," + " `flags` VARCHAR(512) DEFAULT NULL," + " `merged` INT(11) DEFAULT NULL," + " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT'," + " PRIMARY KEY (`plot_plot_id`)," + " UNIQUE KEY `unique_alias` (`alias`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); - stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + prefix + "plot_ratings` ( `plot_plot_id` INT(11) NOT NULL, `rating` INT(2) NOT NULL, `player` VARCHAR(40) NOT NULL, PRIMARY KEY(`plot_plot_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8"); + stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot` (" + "`id` INT(11) NOT NULL AUTO_INCREMENT," + "`plot_id_x` INT(11) NOT NULL," + "`plot_id_z` INT(11) NOT NULL," + "`owner` VARCHAR(45) NOT NULL," + "`world` VARCHAR(45) NOT NULL," + "`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP," + "PRIMARY KEY (`id`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=0"); + stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_denied` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); + stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_helpers` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); + stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_comments` (" + "`plot_plot_id` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`tier` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); + stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_trusted` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); + stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_settings` (" + " `plot_plot_id` INT(11) NOT NULL," + " `biome` VARCHAR(45) DEFAULT 'FOREST'," + " `rain` INT(1) DEFAULT 0," + " `custom_time` TINYINT(1) DEFAULT '0'," + " `time` INT(11) DEFAULT '8000'," + " `deny_entry` TINYINT(1) DEFAULT '0'," + " `alias` VARCHAR(50) DEFAULT NULL," + " `flags` VARCHAR(512) DEFAULT NULL," + " `merged` INT(11) DEFAULT NULL," + " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT'," + " PRIMARY KEY (`plot_plot_id`)," + " UNIQUE KEY `unique_alias` (`alias`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); + stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_ratings` ( `plot_plot_id` INT(11) NOT NULL, `rating` INT(2) NOT NULL, `player` VARCHAR(40) NOT NULL, PRIMARY KEY(`plot_plot_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8"); if (add_constraint) { - stmt.addBatch("ALTER TABLE `" + prefix + "plot_settings` ADD CONSTRAINT `" + prefix + "plot_settings_ibfk_1` FOREIGN KEY (`plot_plot_id`) REFERENCES `" + prefix + "plot` (`id`) ON DELETE CASCADE"); + stmt.addBatch("ALTER TABLE `" + this.prefix + "plot_settings` ADD CONSTRAINT `" + this.prefix + "plot_settings_ibfk_1` FOREIGN KEY (`plot_plot_id`) REFERENCES `" + this.prefix + "plot` (`id`) ON DELETE CASCADE"); } - } else { - stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + prefix + "plot` (" + "`id` INTEGER PRIMARY KEY AUTOINCREMENT," + "`plot_id_x` INT(11) NOT NULL," + "`plot_id_z` INT(11) NOT NULL," + "`owner` VARCHAR(45) NOT NULL," + "`world` VARCHAR(45) NOT NULL," + "`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP)"); - stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + prefix + "plot_denied` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")"); - stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + prefix + "plot_helpers` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")"); - stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + prefix + "plot_trusted` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")"); - stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + prefix + "plot_comments` (" + "`plot_plot_id` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`tier` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ")"); - stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + prefix + "plot_settings` (" + " `plot_plot_id` INT(11) NOT NULL," + " `biome` VARCHAR(45) DEFAULT 'FOREST'," + " `rain` INT(1) DEFAULT 0," + " `custom_time` TINYINT(1) DEFAULT '0'," + " `time` INT(11) DEFAULT '8000'," + " `deny_entry` TINYINT(1) DEFAULT '0'," + " `alias` VARCHAR(50) DEFAULT NULL," + " `flags` VARCHAR(512) DEFAULT NULL," + " `merged` INT(11) DEFAULT NULL," + " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT'," + " PRIMARY KEY (`plot_plot_id`)" + ")"); - stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + prefix + "plot_ratings` (`plot_plot_id` INT(11) NOT NULL, `rating` INT(2) NOT NULL, `player` VARCHAR(40) NOT NULL, PRIMARY KEY(`plot_plot_id`))"); + } + else { + stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot` (" + "`id` INTEGER PRIMARY KEY AUTOINCREMENT," + "`plot_id_x` INT(11) NOT NULL," + "`plot_id_z` INT(11) NOT NULL," + "`owner` VARCHAR(45) NOT NULL," + "`world` VARCHAR(45) NOT NULL," + "`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP)"); + stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_denied` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")"); + stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_helpers` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")"); + stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_trusted` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")"); + stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_comments` (" + "`plot_plot_id` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`tier` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ")"); + stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_settings` (" + " `plot_plot_id` INT(11) NOT NULL," + " `biome` VARCHAR(45) DEFAULT 'FOREST'," + " `rain` INT(1) DEFAULT 0," + " `custom_time` TINYINT(1) DEFAULT '0'," + " `time` INT(11) DEFAULT '8000'," + " `deny_entry` TINYINT(1) DEFAULT '0'," + " `alias` VARCHAR(50) DEFAULT NULL," + " `flags` VARCHAR(512) DEFAULT NULL," + " `merged` INT(11) DEFAULT NULL," + " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT'," + " PRIMARY KEY (`plot_plot_id`)" + ")"); + stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_ratings` (`plot_plot_id` INT(11) NOT NULL, `rating` INT(2) NOT NULL, `player` VARCHAR(40) NOT NULL, PRIMARY KEY(`plot_plot_id`))"); } stmt.executeBatch(); stmt.clearBatch(); @@ -345,26 +360,27 @@ public class SQLManager implements AbstractDB { PreparedStatement stmt = null; final int id = getId(world, plot.id); try { - stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot_settings` WHERE `plot_plot_id` = ?"); + stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_settings` WHERE `plot_plot_id` = ?"); stmt.setInt(1, id); stmt.executeUpdate(); stmt.close(); - stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot_helpers` WHERE `plot_plot_id` = ?"); + stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_helpers` WHERE `plot_plot_id` = ?"); stmt.setInt(1, id); stmt.executeUpdate(); stmt.close(); - stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot_trusted` WHERE `plot_plot_id` = ?"); + stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_trusted` WHERE `plot_plot_id` = ?"); stmt.setInt(1, id); stmt.executeUpdate(); stmt.close(); - stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot_comments` WHERE `plot_plot_id` = ?"); + stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `plot_plot_id` = ?"); stmt.setInt(1, id); stmt.executeUpdate(); - stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot` WHERE `id` = ?"); + stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot` WHERE `id` = ?"); stmt.setInt(1, id); stmt.executeUpdate(); stmt.close(); - } catch (final SQLException e) { + } + catch (final SQLException e) { e.printStackTrace(); Logger.add(LogLevel.DANGER, "Failed to delete plot " + plot.id); } @@ -385,11 +401,12 @@ public class SQLManager implements AbstractDB { public void run() { PreparedStatement stmt = null; try { - stmt = connection.prepareStatement("INSERT INTO `" + prefix + "plot_settings`(`plot_plot_id`) VALUES(" + "?)"); + stmt = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_settings`(`plot_plot_id`) VALUES(" + "?)"); stmt.setInt(1, id); stmt.executeUpdate(); stmt.close(); - } catch (final SQLException e) { + } + catch (final SQLException e) { e.printStackTrace(); } @@ -401,7 +418,7 @@ public class SQLManager implements AbstractDB { public int getId(final String world, final PlotId id2) { PreparedStatement stmt = null; try { - stmt = connection.prepareStatement("SELECT `id` FROM `" + prefix + "plot` WHERE `plot_id_x` = ? AND `plot_id_z` = ? AND world = ? ORDER BY `timestamp` ASC"); + stmt = this.connection.prepareStatement("SELECT `id` FROM `" + this.prefix + "plot` WHERE `plot_id_x` = ? AND `plot_id_z` = ? AND world = ? ORDER BY `timestamp` ASC"); stmt.setInt(1, id2.x); stmt.setInt(2, id2.y); stmt.setString(3, world); @@ -412,7 +429,8 @@ public class SQLManager implements AbstractDB { } stmt.close(); return id; - } catch (final SQLException e) { + } + catch (final SQLException e) { e.printStackTrace(); } return Integer.MAX_VALUE; @@ -425,27 +443,28 @@ public class SQLManager implements AbstractDB { public LinkedHashMap> getPlots() { final LinkedHashMap> newplots = new LinkedHashMap<>(); try { - final DatabaseMetaData data = connection.getMetaData(); - ResultSet rs = data.getColumns(null, null, prefix + "plot", "plot_id"); + final DatabaseMetaData data = this.connection.getMetaData(); + ResultSet rs = data.getColumns(null, null, this.prefix + "plot", "plot_id"); final boolean execute = rs.next(); if (execute) { - final Statement statement = connection.createStatement(); - statement.addBatch("ALTER IGNORE TABLE `" + prefix + "plot` ADD `plot_id_x` int(11) DEFAULT 0"); - statement.addBatch("ALTER IGNORE TABLE `" + prefix + "plot` ADD `plot_id_z` int(11) DEFAULT 0"); - statement.addBatch("UPDATE `" + prefix + "plot` SET\n" + " `plot_id_x` = IF(" + " LOCATE(';', `plot_id`) > 0," + " SUBSTRING(`plot_id`, 1, LOCATE(';', `plot_id`) - 1)," + " `plot_id`" + " )," + " `plot_id_z` = IF(" + " LOCATE(';', `plot_id`) > 0," + " SUBSTRING(`plot_id`, LOCATE(';', `plot_id`) + 1)," + " NULL" + " )"); - statement.addBatch("ALTER TABLE `" + prefix + "plot` DROP `plot_id`"); - statement.addBatch("ALTER IGNORE TABLE `" + prefix + "plot_settings` ADD `flags` VARCHAR(512) DEFAULT NULL"); + final Statement statement = this.connection.createStatement(); + statement.addBatch("ALTER IGNORE TABLE `" + this.prefix + "plot` ADD `plot_id_x` int(11) DEFAULT 0"); + statement.addBatch("ALTER IGNORE TABLE `" + this.prefix + "plot` ADD `plot_id_z` int(11) DEFAULT 0"); + statement.addBatch("UPDATE `" + this.prefix + "plot` SET\n" + " `plot_id_x` = IF(" + " LOCATE(';', `plot_id`) > 0," + " SUBSTRING(`plot_id`, 1, LOCATE(';', `plot_id`) - 1)," + " `plot_id`" + " )," + " `plot_id_z` = IF(" + " LOCATE(';', `plot_id`) > 0," + " SUBSTRING(`plot_id`, LOCATE(';', `plot_id`) + 1)," + " NULL" + " )"); + statement.addBatch("ALTER TABLE `" + this.prefix + "plot` DROP `plot_id`"); + statement.addBatch("ALTER IGNORE TABLE `" + this.prefix + "plot_settings` ADD `flags` VARCHAR(512) DEFAULT NULL"); statement.executeBatch(); statement.close(); } - rs = data.getColumns(null, null, prefix + "plot_settings", "merged"); + rs = data.getColumns(null, null, this.prefix + "plot_settings", "merged"); if (!rs.next()) { - final Statement statement = connection.createStatement(); - statement.addBatch("ALTER TABLE `" + prefix + "plot_settings` ADD `merged` int(11) DEFAULT NULL"); + final Statement statement = this.connection.createStatement(); + statement.addBatch("ALTER TABLE `" + this.prefix + "plot_settings` ADD `merged` int(11) DEFAULT NULL"); statement.executeBatch(); statement.close(); } - } catch (final Exception e) { + } + catch (final Exception e) { e.printStackTrace(); } final HashMap plots = new HashMap<>(); @@ -464,8 +483,8 @@ public class SQLManager implements AbstractDB { /* * Getting plots */ - stmt = connection.createStatement(); - ResultSet r = stmt.executeQuery("SELECT `id`, `plot_id_x`, `plot_id_z`, `owner`, `world` FROM `" + prefix + "plot`"); + stmt = this.connection.createStatement(); + ResultSet r = stmt.executeQuery("SELECT `id`, `plot_id_x`, `plot_id_z`, `owner`, `world` FROM `" + this.prefix + "plot`"); PlotId plot_id; int id; Plot p; @@ -478,7 +497,8 @@ public class SQLManager implements AbstractDB { if (!worlds.contains(worldname)) { if (noExist.containsKey(worldname)) { noExist.put(worldname, noExist.get(worldname) + 1); - } else { + } + else { noExist.put(worldname, 1); } } @@ -488,15 +508,15 @@ public class SQLManager implements AbstractDB { user = UUID.fromString(o); uuids.put(o, user); } - p = new Plot(plot_id, user, new ArrayList(), new ArrayList(), new ArrayList(), "", PlotHomePosition.DEFAULT, null, worldname, new boolean[]{false, false, false, false}); + p = new Plot(plot_id, user, new ArrayList(), new ArrayList(), new ArrayList(), "", PlotHomePosition.DEFAULT, null, worldname, new boolean[] { false, false, false, false }); plots.put(id, p); } -// stmt.close(); + // stmt.close(); /* * Getting helpers */ -// stmt = connection.createStatement(); - r = stmt.executeQuery("SELECT `user_uuid`, `plot_plot_id` FROM `" + prefix + "plot_helpers`"); + // stmt = connection.createStatement(); + r = stmt.executeQuery("SELECT `user_uuid`, `plot_plot_id` FROM `" + this.prefix + "plot_helpers`"); while (r.next()) { id = r.getInt("plot_plot_id"); o = r.getString("user_uuid"); @@ -508,17 +528,18 @@ public class SQLManager implements AbstractDB { final Plot plot = plots.get(id); if (plot != null) { plot.addHelper(user); - } else { + } + else { PlotMain.sendConsoleSenderMessage("&cPLOT " + id + " in plot_helpers does not exist. Please create the plot or remove this entry."); } } -// stmt.close(); + // stmt.close(); /* * Getting trusted */ -// stmt = connection.createStatement(); - r = stmt.executeQuery("SELECT `user_uuid`, `plot_plot_id` FROM `" + prefix + "plot_trusted`"); + // stmt = connection.createStatement(); + r = stmt.executeQuery("SELECT `user_uuid`, `plot_plot_id` FROM `" + this.prefix + "plot_trusted`"); while (r.next()) { id = r.getInt("plot_plot_id"); o = r.getString("user_uuid"); @@ -530,17 +551,18 @@ public class SQLManager implements AbstractDB { final Plot plot = plots.get(id); if (plot != null) { plot.addTrusted(user); - } else { + } + else { PlotMain.sendConsoleSenderMessage("&cPLOT " + id + " in plot_trusted does not exist. Please create the plot or remove this entry."); } } -// stmt.close(); + // stmt.close(); /* * Getting denied */ -// stmt = connection.createStatement(); - r = stmt.executeQuery("SELECT `user_uuid`, `plot_plot_id` FROM `" + prefix + "plot_denied`"); + // stmt = connection.createStatement(); + r = stmt.executeQuery("SELECT `user_uuid`, `plot_plot_id` FROM `" + this.prefix + "plot_denied`"); while (r.next()) { id = r.getInt("plot_plot_id"); o = r.getString("user_uuid"); @@ -552,25 +574,24 @@ public class SQLManager implements AbstractDB { final Plot plot = plots.get(id); if (plot != null) { plot.addDenied(user); - } else { + } + else { PlotMain.sendConsoleSenderMessage("&cPLOT " + id + " in plot_denied does not exist. Please create the plot or remove this entry."); } } -// stmt.close(); + // stmt.close(); -// stmt = connection.createStatement(); - r = stmt.executeQuery("SELECT * FROM `" + prefix + "plot_settings`"); + // stmt = connection.createStatement(); + r = stmt.executeQuery("SELECT * FROM `" + this.prefix + "plot_settings`"); while (r.next()) { id = r.getInt("plot_plot_id"); final Plot plot = plots.get(id); if (plot != null) { final String b = r.getString("biome"); - Biome biome = null; if (b != null) { for (final Biome mybiome : Biome.values()) { if (mybiome.toString().equalsIgnoreCase(b)) { - biome = mybiome; break; } } @@ -599,15 +620,17 @@ public class SQLManager implements AbstractDB { merged[3 - i] = ((m) & (1 << i)) != 0; } plot.settings.setMerged(merged); - } else { - plot.settings.setMerged(new boolean[]{false, false, false, false}); + } + else { + plot.settings.setMerged(new boolean[] { false, false, false, false }); } String[] flags_string; final String myflags = r.getString("flags"); if (myflags == null) { - flags_string = new String[]{}; - } else { + flags_string = new String[] {}; + } + else { flags_string = myflags.split(","); } final ArrayList flags = new ArrayList(); @@ -617,10 +640,12 @@ public class SQLManager implements AbstractDB { final String[] split = element.split(":"); try { flags.add(new Flag(FlagManager.getFlag(split[0], true), split[1].replaceAll("\u00AF", ":").replaceAll("�", ","))); - } catch (final Exception e) { + } + catch (final Exception e) { exception = true; } - } else { + } + else { flags.add(new Flag(FlagManager.getFlag(element, true), "")); } } @@ -629,7 +654,8 @@ public class SQLManager implements AbstractDB { setFlags(id, flags.toArray(new Flag[0])); } plot.settings.setFlags(flags.toArray(new Flag[0])); - } else { + } + else { PlotMain.sendConsoleSenderMessage("&cPLOT " + id + " in plot_settings does not exist. Please create the plot or remove this entry."); } } @@ -649,7 +675,8 @@ public class SQLManager implements AbstractDB { if (invalidPlot) { PlotMain.sendConsoleSenderMessage("&c[WARNING] - Please create the world/s or remove the plots using the purge command"); } - } catch (final SQLException e) { + } + catch (final SQLException e) { Logger.add(LogLevel.WARNING, "Failed to load plots."); e.printStackTrace(); } @@ -667,12 +694,13 @@ public class SQLManager implements AbstractDB { for (int i = 0; i < 4; ++i) { n = (n << 1) + (merged[i] ? 1 : 0); } - final PreparedStatement stmt = connection.prepareStatement("UPDATE `" + prefix + "plot_settings` SET `merged` = ? WHERE `plot_plot_id` = ?"); + final PreparedStatement stmt = SQLManager.this.connection.prepareStatement("UPDATE `" + SQLManager.this.prefix + "plot_settings` SET `merged` = ? WHERE `plot_plot_id` = ?"); stmt.setInt(1, n); stmt.setInt(2, getId(world, plot.id)); stmt.execute(); stmt.close(); - } catch (final SQLException e) { + } + catch (final SQLException e) { e.printStackTrace(); Logger.add(LogLevel.WARNING, "Could not set merged for plot " + plot.id); } @@ -696,12 +724,13 @@ public class SQLManager implements AbstractDB { @Override public void run() { try { - final PreparedStatement stmt = connection.prepareStatement("UPDATE `" + prefix + "plot_settings` SET `flags` = ? WHERE `plot_plot_id` = ?"); + final PreparedStatement stmt = SQLManager.this.connection.prepareStatement("UPDATE `" + SQLManager.this.prefix + "plot_settings` SET `flags` = ? WHERE `plot_plot_id` = ?"); stmt.setString(1, flag_string.toString()); stmt.setInt(2, getId(world, plot.id)); stmt.execute(); stmt.close(); - } catch (final SQLException e) { + } + catch (final SQLException e) { e.printStackTrace(); Logger.add(LogLevel.WARNING, "Could not set flag for plot " + plot.id); } @@ -721,12 +750,13 @@ public class SQLManager implements AbstractDB { @Override public void run() { try { - final PreparedStatement stmt = connection.prepareStatement("UPDATE `" + prefix + "plot_settings` SET `flags` = ? WHERE `plot_plot_id` = ?"); + final PreparedStatement stmt = SQLManager.this.connection.prepareStatement("UPDATE `" + SQLManager.this.prefix + "plot_settings` SET `flags` = ? WHERE `plot_plot_id` = ?"); stmt.setString(1, flag_string); stmt.setInt(2, id); stmt.execute(); stmt.close(); - } catch (final SQLException e) { + } + catch (final SQLException e) { e.printStackTrace(); Logger.add(LogLevel.WARNING, "Could not set flag for plot " + id); } @@ -746,12 +776,13 @@ public class SQLManager implements AbstractDB { public void run() { PreparedStatement stmt = null; try { - stmt = connection.prepareStatement("UPDATE `" + prefix + "plot_settings` SET `alias` = ? WHERE `plot_plot_id` = ?"); + stmt = SQLManager.this.connection.prepareStatement("UPDATE `" + SQLManager.this.prefix + "plot_settings` SET `alias` = ? WHERE `plot_plot_id` = ?"); stmt.setString(1, alias); stmt.setInt(2, getId(world, plot.id)); stmt.executeUpdate(); stmt.close(); - } catch (final SQLException e) { + } + catch (final SQLException e) { Logger.add(LogLevel.WARNING, "Failed to set alias for plot " + plot.id); e.printStackTrace(); } @@ -776,7 +807,7 @@ public class SQLManager implements AbstractDB { // Fetching a list of plot IDs for a world try { - final PreparedStatement stmt = connection.prepareStatement("SELECT `id` FROM `" + prefix + "plot` WHERE `world` = ? AND `plot_id_x` = ? AND `plot_id_z` = ?"); + final PreparedStatement stmt = SQLManager.this.connection.prepareStatement("SELECT `id` FROM `" + SQLManager.this.prefix + "plot` WHERE `world` = ? AND `plot_id_x` = ? AND `plot_id_z` = ?"); stmt.setString(1, world); stmt.setInt(2, id.x); stmt.setInt(3, id.y); @@ -785,7 +816,8 @@ public class SQLManager implements AbstractDB { final int id = result.getInt("id"); ids.add(id); } - } catch (final SQLException e) { + } + catch (final SQLException e) { e.printStackTrace(); Logger.add(LogLevel.WARNING, "FAILED TO PURGE WORLD '" + world + "'!"); return; @@ -801,27 +833,28 @@ public class SQLManager implements AbstractDB { prefix = " OR `plot_plot_id` = "; } - PreparedStatement stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot_helpers` WHERE `plot_plot_id` = " + idstr + ""); + PreparedStatement stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + prefix + "plot_helpers` WHERE `plot_plot_id` = " + idstr + ""); stmt.executeUpdate(); stmt.close(); - stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot_denied` WHERE `plot_plot_id` = " + idstr + ""); + stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + prefix + "plot_denied` WHERE `plot_plot_id` = " + idstr + ""); stmt.executeUpdate(); stmt.close(); - stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot_settings` WHERE `plot_plot_id` = " + idstr + ""); + stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + prefix + "plot_settings` WHERE `plot_plot_id` = " + idstr + ""); stmt.executeUpdate(); stmt.close(); - stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot_trusted` WHERE `plot_plot_id` = " + idstr + ""); + stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + prefix + "plot_trusted` WHERE `plot_plot_id` = " + idstr + ""); stmt.executeUpdate(); stmt.close(); - stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot` WHERE `plot_plot_id` = " + idstr + ""); + stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + prefix + "plot` WHERE `plot_plot_id` = " + idstr + ""); stmt.setString(1, world); stmt.executeUpdate(); stmt.close(); - } catch (final SQLException e) { + } + catch (final SQLException e) { e.printStackTrace(); Logger.add(LogLevel.DANGER, "FAILED TO PURGE PLOT FROM DB '" + world + "' , '" + id + "' !"); return; @@ -841,14 +874,15 @@ public class SQLManager implements AbstractDB { // Fetching a list of plot IDs for a world try { - final PreparedStatement stmt = connection.prepareStatement("SELECT `id` FROM `" + prefix + "plot` WHERE `world` = ?"); + final PreparedStatement stmt = SQLManager.this.connection.prepareStatement("SELECT `id` FROM `" + SQLManager.this.prefix + "plot` WHERE `world` = ?"); stmt.setString(1, world); final ResultSet result = stmt.executeQuery(); while (result.next()) { final int id = result.getInt("id"); ids.add(id); } - } catch (final SQLException e) { + } + catch (final SQLException e) { e.printStackTrace(); Logger.add(LogLevel.WARNING, "FAILED TO PURGE WORLD '" + world + "'!"); return; @@ -864,27 +898,28 @@ public class SQLManager implements AbstractDB { prefix = " OR `plot_plot_id` = "; } - PreparedStatement stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot_helpers` WHERE `plot_plot_id` = " + idstr + ""); + PreparedStatement stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + prefix + "plot_helpers` WHERE `plot_plot_id` = " + idstr + ""); stmt.executeUpdate(); stmt.close(); - stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot_denied` WHERE `plot_plot_id` = " + idstr + ""); + stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + prefix + "plot_denied` WHERE `plot_plot_id` = " + idstr + ""); stmt.executeUpdate(); stmt.close(); - stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot_settings` WHERE `plot_plot_id` = " + idstr + ""); + stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + prefix + "plot_settings` WHERE `plot_plot_id` = " + idstr + ""); stmt.executeUpdate(); stmt.close(); - stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot_trusted` WHERE `plot_plot_id` = " + idstr + ""); + stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + prefix + "plot_trusted` WHERE `plot_plot_id` = " + idstr + ""); stmt.executeUpdate(); stmt.close(); - stmt = connection.prepareStatement("DELETE FROM `" + prefix + "plot` WHERE `world` = ?"); + stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + prefix + "plot` WHERE `world` = ?"); stmt.setString(1, world); stmt.executeUpdate(); stmt.close(); - } catch (final SQLException e) { + } + catch (final SQLException e) { e.printStackTrace(); Logger.add(LogLevel.DANGER, "FAILED TO PURGE WORLD '" + world + "'!"); return; @@ -907,12 +942,13 @@ public class SQLManager implements AbstractDB { public void run() { PreparedStatement stmt = null; try { - stmt = connection.prepareStatement("UPDATE `" + prefix + "plot_settings` SET `position` = ? WHERE `plot_plot_id` = ?"); + stmt = SQLManager.this.connection.prepareStatement("UPDATE `" + SQLManager.this.prefix + "plot_settings` SET `position` = ? WHERE `plot_plot_id` = ?"); stmt.setString(1, position); stmt.setInt(2, getId(world, plot.id)); stmt.executeUpdate(); stmt.close(); - } catch (final SQLException e) { + } + catch (final SQLException e) { Logger.add(LogLevel.WARNING, "Failed to set position for plot " + plot.id); e.printStackTrace(); } @@ -929,7 +965,7 @@ public class SQLManager implements AbstractDB { final HashMap h = new HashMap(); PreparedStatement stmt = null; try { - stmt = connection.prepareStatement("SELECT * FROM `" + prefix + "plot_settings` WHERE `plot_plot_id` = ?"); + stmt = this.connection.prepareStatement("SELECT * FROM `" + this.prefix + "plot_settings` WHERE `plot_plot_id` = ?"); stmt.setInt(1, id); final ResultSet r = stmt.executeQuery(); String var; @@ -964,7 +1000,8 @@ public class SQLManager implements AbstractDB { h.put(var, val); } stmt.close(); - } catch (final SQLException e) { + } + catch (final SQLException e) { Logger.add(LogLevel.WARNING, "Failed to load settings for plot: " + id); e.printStackTrace(); } @@ -977,14 +1014,15 @@ public class SQLManager implements AbstractDB { @Override public void run() { try { - final PreparedStatement statement = connection.prepareStatement("DELETE FROM `" + prefix + "plot_comments` WHERE `plot_plot_id` = ? AND `comment` = ? AND `tier` = ? AND `sender` = ?"); + final PreparedStatement statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `plot_plot_id` = ? AND `comment` = ? AND `tier` = ? AND `sender` = ?"); statement.setInt(1, getId(world, plot.id)); statement.setString(2, comment.comment); statement.setInt(3, comment.tier); statement.setString(4, comment.senderName); statement.executeUpdate(); statement.close(); - } catch (final SQLException e) { + } + catch (final SQLException e) { e.printStackTrace(); Logger.add(LogLevel.WARNING, "Failed to remove helper for plot " + plot.id); } @@ -996,7 +1034,7 @@ public class SQLManager implements AbstractDB { public ArrayList getComments(final String world, final Plot plot, final int tier) { final ArrayList comments = new ArrayList(); try { - final PreparedStatement statement = connection.prepareStatement("SELECT `*` FROM `" + prefix + "plot_comments` WHERE `plot_plot_id` = ? AND `tier` = ?"); + final PreparedStatement statement = this.connection.prepareStatement("SELECT `*` FROM `" + this.prefix + "plot_comments` WHERE `plot_plot_id` = ? AND `tier` = ?"); statement.setInt(1, getId(plot.getWorld().getName(), plot.id)); statement.setInt(2, tier); final ResultSet set = statement.executeQuery(); @@ -1008,7 +1046,8 @@ public class SQLManager implements AbstractDB { comments.add(comment); } statement.close(); - } catch (final SQLException e) { + } + catch (final SQLException e) { Logger.add(LogLevel.WARNING, "Failed to fetch rating for plot " + plot.getId().toString()); e.printStackTrace(); } @@ -1021,14 +1060,15 @@ public class SQLManager implements AbstractDB { @Override public void run() { try { - final PreparedStatement statement = connection.prepareStatement("INSERT INTO `" + prefix + "plot_comments` (`plot_plot_id`, `comment`, `tier`, `sender`) VALUES(?,?,?,?)"); + final PreparedStatement statement = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_comments` (`plot_plot_id`, `comment`, `tier`, `sender`) VALUES(?,?,?,?)"); statement.setInt(1, getId(world, plot.id)); statement.setString(2, comment.comment); statement.setInt(3, comment.tier); statement.setString(4, comment.senderName); statement.executeUpdate(); statement.close(); - } catch (final SQLException e) { + } + catch (final SQLException e) { e.printStackTrace(); Logger.add(LogLevel.WARNING, "Failed to remove helper for plot " + plot.id); } @@ -1047,12 +1087,13 @@ public class SQLManager implements AbstractDB { @Override public void run() { try { - final PreparedStatement statement = connection.prepareStatement("DELETE FROM `" + prefix + "plot_helpers` WHERE `plot_plot_id` = ? AND `user_uuid` = ?"); + final PreparedStatement statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_helpers` WHERE `plot_plot_id` = ? AND `user_uuid` = ?"); statement.setInt(1, getId(world, plot.id)); statement.setString(2, UUIDHandler.getUUID(player).toString()); statement.executeUpdate(); statement.close(); - } catch (final SQLException e) { + } + catch (final SQLException e) { e.printStackTrace(); Logger.add(LogLevel.WARNING, "Failed to remove helper for plot " + plot.id); } @@ -1070,12 +1111,13 @@ public class SQLManager implements AbstractDB { @Override public void run() { try { - final PreparedStatement statement = connection.prepareStatement("DELETE FROM `" + prefix + "plot_trusted` WHERE `plot_plot_id` = ? AND `user_uuid` = ?"); + final PreparedStatement statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_trusted` WHERE `plot_plot_id` = ? AND `user_uuid` = ?"); statement.setInt(1, getId(world, plot.id)); statement.setString(2, UUIDHandler.getUUID(player).toString()); statement.executeUpdate(); statement.close(); - } catch (final SQLException e) { + } + catch (final SQLException e) { e.printStackTrace(); Logger.add(LogLevel.WARNING, "Failed to remove trusted user for plot " + plot.id); } @@ -1093,12 +1135,13 @@ public class SQLManager implements AbstractDB { @Override public void run() { try { - final PreparedStatement statement = connection.prepareStatement("INSERT INTO `" + prefix + "plot_helpers` (`plot_plot_id`, `user_uuid`) VALUES(?,?)"); + final PreparedStatement statement = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_helpers` (`plot_plot_id`, `user_uuid`) VALUES(?,?)"); statement.setInt(1, getId(world, plot.id)); statement.setString(2, UUIDHandler.getUUID(player).toString()); statement.executeUpdate(); statement.close(); - } catch (final SQLException e) { + } + catch (final SQLException e) { Logger.add(LogLevel.WARNING, "Failed to set helper for plot " + plot.id); e.printStackTrace(); } @@ -1116,12 +1159,13 @@ public class SQLManager implements AbstractDB { @Override public void run() { try { - final PreparedStatement statement = connection.prepareStatement("INSERT INTO `" + prefix + "plot_trusted` (`plot_plot_id`, `user_uuid`) VALUES(?,?)"); + final PreparedStatement statement = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_trusted` (`plot_plot_id`, `user_uuid`) VALUES(?,?)"); statement.setInt(1, getId(world, plot.id)); statement.setString(2, UUIDHandler.getUUID(player).toString()); statement.executeUpdate(); statement.close(); - } catch (final SQLException e) { + } + catch (final SQLException e) { Logger.add(LogLevel.WARNING, "Failed to set plot trusted for plot " + plot.id); e.printStackTrace(); } @@ -1139,12 +1183,13 @@ public class SQLManager implements AbstractDB { @Override public void run() { try { - final PreparedStatement statement = connection.prepareStatement("DELETE FROM `" + prefix + "plot_denied` WHERE `plot_plot_id` = ? AND `user_uuid` = ?"); + final PreparedStatement statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_denied` WHERE `plot_plot_id` = ? AND `user_uuid` = ?"); statement.setInt(1, getId(world, plot.id)); statement.setString(2, UUIDHandler.getUUID(player).toString()); statement.executeUpdate(); statement.close(); - } catch (final SQLException e) { + } + catch (final SQLException e) { e.printStackTrace(); Logger.add(LogLevel.WARNING, "Failed to remove denied for plot " + plot.id); } @@ -1162,12 +1207,13 @@ public class SQLManager implements AbstractDB { @Override public void run() { try { - final PreparedStatement statement = connection.prepareStatement("INSERT INTO `" + prefix + "plot_denied` (`plot_plot_id`, `user_uuid`) VALUES(?,?)"); + final PreparedStatement statement = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_denied` (`plot_plot_id`, `user_uuid`) VALUES(?,?)"); statement.setInt(1, getId(world, plot.id)); statement.setString(2, UUIDHandler.getUUID(player).toString()); statement.executeUpdate(); statement.close(); - } catch (final SQLException e) { + } + catch (final SQLException e) { Logger.add(LogLevel.WARNING, "Failed to set denied for plot " + plot.id); e.printStackTrace(); } @@ -1178,7 +1224,7 @@ public class SQLManager implements AbstractDB { @Override public double getRatings(final Plot plot) { try { - final PreparedStatement statement = connection.prepareStatement("SELECT AVG(`rating`) AS `rating` FROM `" + prefix + "plot_ratings` WHERE `plot_plot_id` = ? "); + final PreparedStatement statement = this.connection.prepareStatement("SELECT AVG(`rating`) AS `rating` FROM `" + this.prefix + "plot_ratings` WHERE `plot_plot_id` = ? "); statement.setInt(1, getId(plot.getWorld().getName(), plot.id)); final ResultSet set = statement.executeQuery(); double rating = 0; @@ -1187,7 +1233,8 @@ public class SQLManager implements AbstractDB { } statement.close(); return rating; - } catch (final SQLException e) { + } + catch (final SQLException e) { Logger.add(LogLevel.WARNING, "Failed to fetch rating for plot " + plot.getId().toString()); e.printStackTrace(); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLite.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLite.java index 7b1891b86..ce6d112d6 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLite.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLite.java @@ -21,13 +21,17 @@ package com.intellectualcrafters.plot.database; -import org.bukkit.plugin.Plugin; - import java.io.File; import java.io.IOException; -import java.sql.*; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; import java.util.logging.Level; +import org.bukkit.plugin.Plugin; + /** * Connects to and uses a SQLite database * @@ -37,13 +41,15 @@ import java.util.logging.Level; public class SQLite extends Database { private final String dbLocation; - private Connection connection; + private Connection connection; /** * Creates a new SQLite instance * - * @param plugin Plugin instance - * @param dbLocation Location of the Database (Must end in .db) + * @param plugin + * Plugin instance + * @param dbLocation + * Location of the Database (Must end in .db) */ public SQLite(final Plugin plugin, final String dbLocation) { super(plugin); @@ -62,7 +68,8 @@ public class SQLite extends Database { if (!(file.exists())) { try { file.createNewFile(); - } catch (final IOException e) { + } + catch (final IOException e) { this.plugin.getLogger().log(Level.SEVERE, "Unable to create database!"); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerClaimPlotEvent.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerClaimPlotEvent.java index a11660b37..88b521adc 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerClaimPlotEvent.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerClaimPlotEvent.java @@ -21,12 +21,13 @@ package com.intellectualcrafters.plot.events; -import com.intellectualcrafters.plot.object.Plot; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; import org.bukkit.event.player.PlayerEvent; +import com.intellectualcrafters.plot.object.Plot; + /** * @author Citymonstret * @author Empire92 @@ -34,17 +35,19 @@ import org.bukkit.event.player.PlayerEvent; @SuppressWarnings("unused") public class PlayerClaimPlotEvent extends PlayerEvent implements Cancellable { private static HandlerList handlers = new HandlerList(); - private final Plot plot; - private final boolean auto; - private boolean cancelled; + private final Plot plot; + private final boolean auto; + private boolean cancelled; /** * PlayerClaimPlotEvent: Called when a plot is claimed * - * @param player Player that claimed the plot - * @param plot Plot that was claimed + * @param player + * Player that claimed the plot + * @param plot + * Plot that was claimed */ - public PlayerClaimPlotEvent(final Player player, final Plot plot, boolean auto) { + public PlayerClaimPlotEvent(final Player player, final Plot plot, final boolean auto) { super(player); this.plot = plot; this.auto = auto; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerEnterPlotEvent.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerEnterPlotEvent.java index 25698112b..332e8fb19 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerEnterPlotEvent.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerEnterPlotEvent.java @@ -21,11 +21,12 @@ package com.intellectualcrafters.plot.events; -import com.intellectualcrafters.plot.object.Plot; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; import org.bukkit.event.player.PlayerEvent; +import com.intellectualcrafters.plot.object.Plot; + /** * @author Citymonstret * @author Empire92 @@ -34,13 +35,15 @@ public class PlayerEnterPlotEvent extends PlayerEvent { private static HandlerList handlers = new HandlerList(); - private final Plot plot; + private final Plot plot; /** * PlayerEnterPlotEvent: Called when a player leaves a plot * - * @param player Player that entered the plot - * @param plot Plot that was entered + * @param player + * Player that entered the plot + * @param plot + * Plot that was entered */ public PlayerEnterPlotEvent(final Player player, final Plot plot) { super(player); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerLeavePlotEvent.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerLeavePlotEvent.java index 0414b0dda..22e5b1f5e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerLeavePlotEvent.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerLeavePlotEvent.java @@ -21,11 +21,12 @@ package com.intellectualcrafters.plot.events; -import com.intellectualcrafters.plot.object.Plot; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; import org.bukkit.event.player.PlayerEvent; +import com.intellectualcrafters.plot.object.Plot; + /** * @author Citymonstret * @author Empire92 @@ -33,13 +34,15 @@ import org.bukkit.event.player.PlayerEvent; public class PlayerLeavePlotEvent extends PlayerEvent { private static HandlerList handlers = new HandlerList(); - private final Plot plot; + private final Plot plot; /** * PlayerLeavePlotEvent: Called when a player leaves a plot * - * @param player Player that left the plot - * @param plot Plot that was left + * @param player + * Player that left the plot + * @param plot + * Plot that was left */ public PlayerLeavePlotEvent(final Player player, final Plot plot) { super(player); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerPlotDeniedEvent.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerPlotDeniedEvent.java index 7f1229c54..5193b3ae0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerPlotDeniedEvent.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerPlotDeniedEvent.java @@ -21,12 +21,13 @@ package com.intellectualcrafters.plot.events; -import com.intellectualcrafters.plot.object.Plot; +import java.util.UUID; + import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import java.util.UUID; +import com.intellectualcrafters.plot.object.Plot; /** * @author Citymonstret @@ -35,19 +36,23 @@ import java.util.UUID; public class PlayerPlotDeniedEvent extends Event { private static HandlerList handlers = new HandlerList(); - private final Plot plot; - private final Player initiator; - private final boolean added; - private final UUID player; + private final Plot plot; + private final Player initiator; + private final boolean added; + private final UUID player; /** * PlayerPlotDeniedEvent: Called when the denied UUID list is modified for a * plot * - * @param initiator Player that initiated the event - * @param plot Plot in which the event occurred - * @param player Player that was denied/un-denied - * @param added true of add to deny list, false if removed + * @param initiator + * Player that initiated the event + * @param plot + * Plot in which the event occurred + * @param player + * Player that was denied/un-denied + * @param added + * true of add to deny list, false if removed */ public PlayerPlotDeniedEvent(final Player initiator, final Plot plot, final UUID player, final boolean added) { this.initiator = initiator; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerPlotHelperEvent.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerPlotHelperEvent.java index ea6412512..10538aaa1 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerPlotHelperEvent.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerPlotHelperEvent.java @@ -21,12 +21,13 @@ package com.intellectualcrafters.plot.events; -import com.intellectualcrafters.plot.object.Plot; +import java.util.UUID; + import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import java.util.UUID; +import com.intellectualcrafters.plot.object.Plot; /** * @author Empire92 @@ -35,18 +36,22 @@ import java.util.UUID; public class PlayerPlotHelperEvent extends Event { private static HandlerList handlers = new HandlerList(); - private final Plot plot; - private final Player initiator; - private final boolean added; - private final UUID player; + private final Plot plot; + private final Player initiator; + private final boolean added; + private final UUID player; /** * PlayerPlotHelperEvent: Called when a plot helper is added/removed * - * @param initiator Player that initiated the event - * @param plot Plot in which the event occurred - * @param player Player that was added/removed from the helper list - * @param added true of the player was added, false if the player was removed + * @param initiator + * Player that initiated the event + * @param plot + * Plot in which the event occurred + * @param player + * Player that was added/removed from the helper list + * @param added + * true of the player was added, false if the player was removed */ public PlayerPlotHelperEvent(final Player initiator, final Plot plot, final UUID player, final boolean added) { this.initiator = initiator; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerPlotTrustedEvent.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerPlotTrustedEvent.java index eb608505c..62776895a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerPlotTrustedEvent.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerPlotTrustedEvent.java @@ -21,12 +21,13 @@ package com.intellectualcrafters.plot.events; -import com.intellectualcrafters.plot.object.Plot; +import java.util.UUID; + import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import java.util.UUID; +import com.intellectualcrafters.plot.object.Plot; /** * @author Citymonstret @@ -35,18 +36,22 @@ import java.util.UUID; public class PlayerPlotTrustedEvent extends Event { private static HandlerList handlers = new HandlerList(); - private final Plot plot; - private final Player initiator; - private final boolean added; - private final UUID player; + private final Plot plot; + private final Player initiator; + private final boolean added; + private final UUID player; /** * PlayerPlotTrustedEvent: Called when a plot trusted user is added/removed * - * @param initiator Player that initiated the event - * @param plot Plot in which the event occurred - * @param player Player that was added/removed from the trusted list - * @param added true of the player was added, false if the player was removed + * @param initiator + * Player that initiated the event + * @param plot + * Plot in which the event occurred + * @param player + * Player that was added/removed from the trusted list + * @param added + * true of the player was added, false if the player was removed */ public PlayerPlotTrustedEvent(final Player initiator, final Plot plot, final UUID player, final boolean added) { this.initiator = initiator; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerTeleportToPlotEvent.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerTeleportToPlotEvent.java index 4dab9fd13..9c39babf4 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerTeleportToPlotEvent.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerTeleportToPlotEvent.java @@ -21,13 +21,14 @@ package com.intellectualcrafters.plot.events; -import com.intellectualcrafters.plot.object.Plot; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; import org.bukkit.event.player.PlayerEvent; +import com.intellectualcrafters.plot.object.Plot; + /** * Called when a player teleports to a plot * @@ -37,17 +38,20 @@ import org.bukkit.event.player.PlayerEvent; public class PlayerTeleportToPlotEvent extends PlayerEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); - private final Location from; - private final Plot plot; + private final Location from; + private final Plot plot; - private boolean cancelled; + private boolean cancelled; /** * PlayerTeleportToPlotEvent: Called when a player teleports to a plot * - * @param player That was teleported - * @param from Start location - * @param plot Plot to which the player was teleported + * @param player + * That was teleported + * @param from + * Start location + * @param plot + * Plot to which the player was teleported */ public PlayerTeleportToPlotEvent(final Player player, final Location from, final Plot plot) { super(player); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotClearEvent.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotClearEvent.java index bf5886614..0f247f2a0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotClearEvent.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotClearEvent.java @@ -21,11 +21,12 @@ package com.intellectualcrafters.plot.events; -import com.intellectualcrafters.plot.object.PlotId; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; +import com.intellectualcrafters.plot.object.PlotId; + /** * Called when a plot is cleared * @@ -34,15 +35,17 @@ import org.bukkit.event.HandlerList; */ public class PlotClearEvent extends Event implements Cancellable { private static HandlerList handlers = new HandlerList(); - private final PlotId id; - private final String world; - private boolean cancelled; + private final PlotId id; + private final String world; + private boolean cancelled; /** * PlotDeleteEvent: Called when a plot is cleared * - * @param world The world in which the plot was cleared - * @param id The plot that was cleared + * @param world + * The world in which the plot was cleared + * @param id + * The plot that was cleared */ public PlotClearEvent(final String world, final PlotId id) { this.id = id; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotDeleteEvent.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotDeleteEvent.java index 269dc6ab8..3deeed030 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotDeleteEvent.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotDeleteEvent.java @@ -21,11 +21,12 @@ package com.intellectualcrafters.plot.events; -import com.intellectualcrafters.plot.object.PlotId; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; +import com.intellectualcrafters.plot.object.PlotId; + /** * Called when a plot is deleted * @@ -34,15 +35,17 @@ import org.bukkit.event.HandlerList; */ public class PlotDeleteEvent extends Event implements Cancellable { private static HandlerList handlers = new HandlerList(); - private final PlotId id; - private final String world; - private boolean cancelled; + private final PlotId id; + private final String world; + private boolean cancelled; /** * PlotDeleteEvent: Called when a plot is deleted * - * @param world The world in which the plot was deleted - * @param id The ID of the plot that was deleted + * @param world + * The world in which the plot was deleted + * @param id + * The ID of the plot that was deleted */ public PlotDeleteEvent(final String world, final PlotId id) { this.id = id; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotFlagAddEvent.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotFlagAddEvent.java index 89505350a..a685603cb 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotFlagAddEvent.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotFlagAddEvent.java @@ -21,12 +21,13 @@ package com.intellectualcrafters.plot.events; -import com.intellectualcrafters.plot.flag.Flag; -import com.intellectualcrafters.plot.object.Plot; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; +import com.intellectualcrafters.plot.flag.Flag; +import com.intellectualcrafters.plot.object.Plot; + /** * Called when a Flag is added to a plot * @@ -35,15 +36,17 @@ import org.bukkit.event.HandlerList; */ public class PlotFlagAddEvent extends Event implements Cancellable { private static HandlerList handlers = new HandlerList(); - private final Plot plot; - private final Flag flag; - private boolean cancelled; + private final Plot plot; + private final Flag flag; + private boolean cancelled; /** * PlotFlagAddEvent: Called when a Flag is added to a plot * - * @param flag Flag that was added - * @param plot Plot to which the flag was added + * @param flag + * Flag that was added + * @param plot + * Plot to which the flag was added */ public PlotFlagAddEvent(final Flag flag, final Plot plot) { this.plot = plot; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotFlagRemoveEvent.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotFlagRemoveEvent.java index 23e99bef4..2a5eb0386 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotFlagRemoveEvent.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotFlagRemoveEvent.java @@ -21,12 +21,13 @@ package com.intellectualcrafters.plot.events; -import com.intellectualcrafters.plot.flag.Flag; -import com.intellectualcrafters.plot.object.Plot; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; +import com.intellectualcrafters.plot.flag.Flag; +import com.intellectualcrafters.plot.object.Plot; + /** * Called when a flag is removed from a plot * @@ -35,15 +36,17 @@ import org.bukkit.event.HandlerList; */ public class PlotFlagRemoveEvent extends Event implements Cancellable { private static HandlerList handlers = new HandlerList(); - private final Plot plot; - private final Flag flag; - private boolean cancelled; + private final Plot plot; + private final Flag flag; + private boolean cancelled; /** * PlotFlagRemoveEvent: Called when a flag is removed from a plot * - * @param flag Flag that was removed - * @param plot Plot from which the flag was removed + * @param flag + * Flag that was removed + * @param plot + * Plot from which the flag was removed */ public PlotFlagRemoveEvent(final Flag flag, final Plot plot) { this.plot = plot; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotMergeEvent.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotMergeEvent.java index 4ae4fce83..4a678890b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotMergeEvent.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotMergeEvent.java @@ -21,31 +21,35 @@ package com.intellectualcrafters.plot.events; -import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotId; +import java.util.ArrayList; + import org.bukkit.World; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import java.util.ArrayList; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotId; /** * @author Empire92 */ public class PlotMergeEvent extends Event implements Cancellable { - private static HandlerList handlers = new HandlerList(); + private static HandlerList handlers = new HandlerList(); private final ArrayList plots; - private boolean cancelled; - private Plot plot; - private World world; + private boolean cancelled; + private Plot plot; + private World world; /** * PlotMergeEvent: Called when plots are merged * - * @param world World in which the event occurred - * @param plot Plot that was merged - * @param plots A list of plots involved in the event + * @param world + * World in which the event occurred + * @param plot + * Plot that was merged + * @param plots + * A list of plots involved in the event */ public PlotMergeEvent(final World world, final Plot plot, final ArrayList plots) { this.plots = plots; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotUnlinkEvent.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotUnlinkEvent.java index 6727ab007..ef562f247 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotUnlinkEvent.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotUnlinkEvent.java @@ -21,28 +21,31 @@ package com.intellectualcrafters.plot.events; -import com.intellectualcrafters.plot.object.PlotId; +import java.util.ArrayList; + import org.bukkit.World; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import java.util.ArrayList; +import com.intellectualcrafters.plot.object.PlotId; /** * @author Empire92 */ public class PlotUnlinkEvent extends Event implements Cancellable { - private static HandlerList handlers = new HandlerList(); + private static HandlerList handlers = new HandlerList(); private final ArrayList plots; - private final World world; - private boolean cancelled; + private final World world; + private boolean cancelled; /** * Called when a mega-plot is unlinked. * - * @param world World in which the event occurred - * @param plots Plots that are involved in the event + * @param world + * World in which the event occurred + * @param plots + * Plots that are involved in the event */ public PlotUnlinkEvent(final World world, final ArrayList plots) { this.plots = plots; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/AbstractFlag.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/AbstractFlag.java index 878c9a5d1..9ecf59355 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/AbstractFlag.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/AbstractFlag.java @@ -31,7 +31,7 @@ import org.apache.commons.lang.StringUtils; */ public class AbstractFlag { - private final String key; + private final String key; private final FlagValue value; public AbstractFlag(final String key) { @@ -41,7 +41,8 @@ public class AbstractFlag { /** * AbstractFlag is a parameter used in creating a new Flag * - * @param key The key must be alphabetical characters and <= 16 characters + * @param key + * The key must be alphabetical characters and <= 16 characters * in length */ public AbstractFlag(final String key, final FlagValue value) { @@ -54,7 +55,8 @@ public class AbstractFlag { this.key = key.toLowerCase(); if (value == null) { this.value = new FlagValue.StringValue(); - } else { + } + else { this.value = value; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/Flag.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/Flag.java index 880bf1cc1..e8e12f1f7 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/Flag.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/Flag.java @@ -25,20 +25,23 @@ import org.apache.commons.lang.StringUtils; public class Flag { private final AbstractFlag key; - private final String value; + private final String value; /** * 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 <= 48 - * characters - * @throws IllegalArgumentException if you provide inadequate inputs + * @param key + * AbstractFlag + * @param value + * Value must be alphanumerical (can have spaces) and be <= 48 + * characters + * @throws IllegalArgumentException + * if you provide inadequate inputs */ public Flag(final AbstractFlag key, final String value) { - final char[] allowedCharacters = new char[]{'[', ']', '(', ')', ',', '_', '-', '.', ',', '?', '!', '&', ':', '\u00A7'}; + final char[] allowedCharacters = new char[] { '[', ']', '(', ')', ',', '_', '-', '.', ',', '?', '!', '&', ':', '\u00A7' }; String tempValue = value; for (final char c : allowedCharacters) { tempValue = tempValue.replace(c, 'c'); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java index c72abb56a..086f1b647 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java @@ -21,13 +21,14 @@ package com.intellectualcrafters.plot.flag; -import com.intellectualcrafters.plot.object.Plot; -import org.bukkit.entity.Player; - import java.util.ArrayList; import java.util.List; import java.util.Set; +import org.bukkit.entity.Player; + +import com.intellectualcrafters.plot.object.Plot; + /** * Flag Manager Utility * @@ -47,11 +48,12 @@ public class FlagManager { /** * Register an AbstractFlag with PlotSquared * - * @param flag Flag to register + * @param flag + * Flag to register * @return success? */ public static boolean addFlag(final AbstractFlag flag) { - return getFlag(flag.getKey()) == null && flags.add(flag); + return (getFlag(flag.getKey()) == null) && flags.add(flag); } public static Flag[] removeFlag(final Flag[] flags, final String r) { @@ -88,7 +90,8 @@ public class FlagManager { /** * Get a list of registerd AbstragFlag objects based on player permissions * - * @param player with permissions + * @param player + * with permissions * @return List (AbstractFlag) */ public static List getFlags(final Player player) { @@ -104,7 +107,8 @@ public class FlagManager { /** * Get an AbstractFlag by a string Returns null if flag does not exist * - * @param string Flag Key + * @param string + * Flag Key * @return AbstractFlag */ public static AbstractFlag getFlag(final String string) { @@ -119,8 +123,10 @@ public class FlagManager { /** * Get an AbstractFlag by a string * - * @param string Flag Key - * @param create If to create the flag if it does not exist + * @param string + * Flag Key + * @param create + * If to create the flag if it does not exist * @return AbstractFlag */ public static AbstractFlag getFlag(final String string, final boolean create) { @@ -135,7 +141,8 @@ public class FlagManager { /** * Remove a registered AbstractFlag * - * @param flag Flag Key + * @param flag + * Flag Key * @return boolean Result of operation */ public static boolean removeFlag(final AbstractFlag flag) { @@ -148,7 +155,8 @@ public class FlagManager { final String[] split = flagstrings.get(i).split(";"); if (split.length == 1) { flags[i] = new Flag(getFlag(split[0], true), ""); - } else { + } + else { flags[i] = new Flag(getFlag(split[0], true), split[1]); } } @@ -158,7 +166,8 @@ public class FlagManager { /** * Get the flags for a plot * - * @param plot Plot to search in + * @param plot + * Plot to search in * @return List (AbstractFlag) */ public static List getPlotFlags(final Plot plot) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagValue.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagValue.java index caca56106..1d169c952 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagValue.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagValue.java @@ -7,21 +7,21 @@ package com.intellectualcrafters.plot.flag; */ public abstract class FlagValue { - private Class clazz; + private final Class clazz; public FlagValue() { this.clazz = (Class) getClass(); } - public FlagValue(Class clazz) { + public FlagValue(final Class clazz) { if (clazz == null) { throw new NullPointerException(); } this.clazz = clazz; } - public boolean validValue(Object value) { - return value != null && value.getClass() == clazz; + public boolean validValue(final Object value) { + return (value != null) && (value.getClass() == this.clazz); } public abstract T getValue(String t); @@ -33,12 +33,12 @@ public abstract class FlagValue { public static class BooleanValue extends FlagValue { @Override - public Boolean getValue(String t) { + public Boolean getValue(final String t) { return null; } @Override - public String parse(String t) { + public String parse(final String t) { return null; } @@ -51,7 +51,7 @@ public abstract class FlagValue { public static class StringValue extends FlagValue { @Override - public String parse(String s) { + public String parse(final String s) { return s; } @@ -61,7 +61,7 @@ public abstract class FlagValue { } @Override - public String getValue(String t) { + public String getValue(final String t) { return t; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/DefaultPlotManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/DefaultPlotManager.java index ec34b5a06..234cc7968 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/DefaultPlotManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/DefaultPlotManager.java @@ -21,10 +21,7 @@ package com.intellectualcrafters.plot.generator; -import com.intellectualcrafters.plot.PlotMain; -import com.intellectualcrafters.plot.object.*; -import com.intellectualcrafters.plot.util.PlayerFunctions; -import com.intellectualcrafters.plot.util.PlotHelper; +import java.util.ArrayList; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -33,7 +30,14 @@ import org.bukkit.block.Biome; import org.bukkit.block.Block; import org.bukkit.plugin.Plugin; -import java.util.ArrayList; +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotBlock; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotManager; +import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.util.PlayerFunctions; +import com.intellectualcrafters.plot.util.PlotHelper; @SuppressWarnings("deprecation") public class DefaultPlotManager extends PlotManager { @@ -64,7 +68,8 @@ public class DefaultPlotManager extends PlotManager { int pathWidthLower; if ((dpw.ROAD_WIDTH % 2) == 0) { pathWidthLower = (int) (Math.floor(dpw.ROAD_WIDTH / 2) - 1); - } else { + } + else { pathWidthLower = (int) Math.floor(dpw.ROAD_WIDTH / 2); } @@ -113,7 +118,8 @@ public class DefaultPlotManager extends PlotManager { int pathWidthLower; if ((dpw.ROAD_WIDTH % 2) == 0) { pathWidthLower = (int) (Math.floor(dpw.ROAD_WIDTH / 2) - 1); - } else { + } + else { pathWidthLower = (int) Math.floor(dpw.ROAD_WIDTH / 2); } @@ -189,7 +195,7 @@ public class DefaultPlotManager extends PlotManager { @Override public boolean isInPlotAbs(final PlotWorld plotworld, final Location loc, final PlotId plotid) { final PlotId result = getPlotIdAbs(plotworld, loc); - return result != null && result == plotid; + return (result != null) && (result == plotid); } /** @@ -223,7 +229,7 @@ public class DefaultPlotManager extends PlotManager { return new Location(Bukkit.getWorld(plotworld.worldname), x, 256, z); } - + /** * Clearing the plot needs to only consider removing the blocks - This * implementation has used the SetCuboid function, as it is fast, and uses @@ -233,12 +239,15 @@ public class DefaultPlotManager extends PlotManager { * plots */ @Override - public boolean clearPlot(final World world, final Plot plot, boolean isDelete) { + public boolean clearPlot(final World world, final Plot plot, final boolean isDelete) { PlotHelper.runners.put(plot, 1); - final Plugin plugin = (Plugin) PlotMain.getMain(); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + final Plugin plugin = PlotMain.getMain(); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { PlotHelper.runners.remove(plot); - } }, 90L); + } + }, 90L); final DefaultPlotWorld dpw = ((DefaultPlotWorld) PlotMain.getWorldSettings(world)); @@ -250,7 +259,7 @@ public class DefaultPlotManager extends PlotManager { // PlotBlock wall = dpw.WALL_BLOCK; final PlotBlock wall; - + if (isDelete) { wall = dpw.WALL_BLOCK; } @@ -260,213 +269,335 @@ public class DefaultPlotManager extends PlotManager { final PlotBlock wall_filling = dpw.WALL_FILLING; - Block block = world.getBlockAt(new Location(world, pos1.getBlockX() - 1, 1, pos1.getBlockZ())); + final Block block = world.getBlockAt(new Location(world, pos1.getBlockX() - 1, 1, pos1.getBlockZ())); if ((block.getTypeId() != wall_filling.id) || (block.getData() != wall_filling.data)) { setWallFilling(world, dpw, plot.id, wall_filling); } - - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - Block block = world.getBlockAt(new Location(world, pos1.getBlockX() - 1, dpw.WALL_HEIGHT + 1, pos1.getBlockZ())); - if ((block.getTypeId() != wall.id) || (block.getData() != wall.data)) { - setWall(world, dpw, plot.id, wall); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + + final Block block = world.getBlockAt(new Location(world, pos1.getBlockX() - 1, dpw.WALL_HEIGHT + 1, pos1.getBlockZ())); + if ((block.getTypeId() != wall.id) || (block.getData() != wall.data)) { + setWall(world, dpw, plot.id, wall); + } + + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + if ((pos2.getBlockX() - pos1.getBlockX()) < 48) { + PlotHelper.setSimpleCuboid(world, new Location(world, pos1.getBlockX(), 0, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, 1, pos2.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, pos1.getBlockX(), dpw.PLOT_HEIGHT + 1, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, world.getMaxHeight() + 1, pos2.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setCuboid(world, new Location(world, pos1.getBlockX(), 1, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, dpw.PLOT_HEIGHT, pos2.getBlockZ() + 1), filling); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setCuboid(world, new Location(world, pos1.getBlockX(), dpw.PLOT_HEIGHT, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, pos2.getBlockZ() + 1), plotfloor); + } + }, 5L); + } + }, 5L); + } + }, 5L); + return; + } + + final int startX = (pos1.getBlockX() / 16) * 16; + final int startZ = (pos1.getBlockZ() / 16) * 16; + final int chunkX = 16 + pos2.getBlockX(); + final int chunkZ = 16 + pos2.getBlockZ(); + final Location l1 = PlotHelper.getPlotBottomLoc(world, plot.id); + final Location l2 = PlotHelper.getPlotTopLoc(world, plot.id); + final int plotMinX = l1.getBlockX() + 1; + final int plotMinZ = l1.getBlockZ() + 1; + final int plotMaxX = l2.getBlockX(); + final int plotMaxZ = l2.getBlockZ(); + Location mn = null; + Location mx = null; + for (int i = startX; i < chunkX; i += 16) { + for (int j = startZ; j < chunkZ; j += 16) { + final Plot plot1 = PlotHelper.getCurrentPlot(new Location(world, i, 0, j)); + if ((plot1 != null) && (!plot1.getId().equals(plot.getId()))) { + break; + } + final Plot plot2 = PlotHelper.getCurrentPlot(new Location(world, i + 15, 0, j)); + if ((plot2 != null) && (!plot2.getId().equals(plot.getId()))) { + break; + } + final Plot plot3 = PlotHelper.getCurrentPlot(new Location(world, i + 15, 0, j + 15)); + if ((plot3 != null) && (!plot3.getId().equals(plot.getId()))) { + break; + } + final Plot plot4 = PlotHelper.getCurrentPlot(new Location(world, i, 0, j + 15)); + if ((plot4 != null) && (!plot4.getId().equals(plot.getId()))) { + break; + } + final Plot plot5 = PlotHelper.getCurrentPlot(new Location(world, i + 15, 0, j + 15)); + if ((plot5 != null) && (!plot5.getId().equals(plot.getId()))) { + break; + } + if (mn == null) { + mn = new Location(world, Math.max(i - 1, plotMinX), 0, Math.max(j - 1, plotMinZ)); + mx = new Location(world, Math.min(i + 16, plotMaxX), 0, Math.min(j + 16, plotMaxZ)); + } + else if ((mx.getBlockZ() < (j + 15)) || (mx.getBlockX() < (i + 15))) { + mx = new Location(world, Math.min(i + 16, plotMaxX), 0, Math.min(j + 16, plotMaxZ)); + } + world.regenerateChunk(i / 16, j / 16); + } + } + + final Location max = mx; + final Location min = mn; + + if (min == null) { + PlotHelper.setSimpleCuboid(world, new Location(world, pos1.getBlockX(), 0, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, 1, pos2.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, pos1.getBlockX(), dpw.PLOT_HEIGHT + 1, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, world.getMaxHeight() + 1, pos2.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setCuboid(world, new Location(world, pos1.getBlockX(), 1, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, dpw.PLOT_HEIGHT, pos2.getBlockZ() + 1), filling); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setCuboid(world, new Location(world, pos1.getBlockX(), dpw.PLOT_HEIGHT, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, pos2.getBlockZ() + 1), plotfloor); + } + }, 5L); + } + }, 5L); + } + }, 5L); + return; + } + else { + + if (min.getBlockX() < plotMinX) { + min.setX(plotMinX); + } + if (min.getBlockZ() < plotMinZ) { + min.setZ(plotMinZ); + } + if (max.getBlockX() > plotMaxX) { + max.setX(plotMaxX); + } + if (max.getBlockZ() > plotMaxZ) { + max.setZ(plotMaxZ); + } + + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, plotMinX, 0, plotMinZ), new Location(world, min.getBlockX() + 1, 1, min.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT + 1, plotMinZ), new Location(world, min.getBlockX() + 1, world.getMaxHeight() + 1, min.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setCuboid(world, new Location(world, plotMinX, 1, plotMinZ), new Location(world, min.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, min.getBlockZ() + 1), filling); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT, plotMinZ), new Location(world, min.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, min.getBlockZ() + 1), plotfloor); + } + }, 1L); + } + }, 1L); + } + }, 1L); + } + }, 21L); + + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, min.getBlockX(), 0, plotMinZ), new Location(world, max.getBlockX() + 1, 1, min.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, min.getBlockX(), dpw.PLOT_HEIGHT + 1, plotMinZ), new Location(world, max.getBlockX() + 1, world.getMaxHeight() + 1, min.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setCuboid(world, new Location(world, min.getBlockX(), 1, plotMinZ), new Location(world, max.getBlockX() + 1, dpw.PLOT_HEIGHT, min.getBlockZ() + 1), filling); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setCuboid(world, new Location(world, min.getBlockX(), dpw.PLOT_HEIGHT, plotMinZ), new Location(world, max.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, min.getBlockZ() + 1), plotfloor); + } + }, 1L); + } + }, 1L); + } + }, 1L); + } + }, 25L); + + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, max.getBlockX(), 0, plotMinZ), new Location(world, plotMaxX + 1, 1, min.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT + 1, plotMinZ), new Location(world, plotMaxX + 1, world.getMaxHeight() + 1, min.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setCuboid(world, new Location(world, max.getBlockX(), 1, plotMinZ), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT, min.getBlockZ() + 1), filling); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT, plotMinZ), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT + 1, min.getBlockZ() + 1), plotfloor); + } + }, 1L); + } + }, 1L); + } + }, 1L); + } + }, 29L); + + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, plotMinX, 0, min.getBlockZ()), new Location(world, min.getBlockX() + 1, 1, max.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT + 1, min.getBlockZ()), new Location(world, min.getBlockX() + 1, world.getMaxHeight() + 1, max.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setCuboid(world, new Location(world, plotMinX, 1, min.getBlockZ()), new Location(world, min.getBlockX() + 1, dpw.PLOT_HEIGHT, max.getBlockZ() + 1), filling); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT, min.getBlockZ()), new Location(world, min.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, max.getBlockZ() + 1), plotfloor); + } + }, 1L); + } + }, 1L); + } + }, 1L); + } + }, 33L); + + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, plotMinX, 0, max.getBlockZ()), new Location(world, min.getBlockX() + 1, 1, plotMaxZ + 1), new PlotBlock((short) 7, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT + 1, max.getBlockZ()), new Location(world, min.getBlockX() + 1, world.getMaxHeight() + 1, plotMaxZ + 1), new PlotBlock((short) 0, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setCuboid(world, new Location(world, plotMinX, 1, max.getBlockZ()), new Location(world, min.getBlockX() + 1, dpw.PLOT_HEIGHT, plotMaxZ + 1), filling); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT, max.getBlockZ()), new Location(world, min.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloor); + } + }, 1L); + } + }, 1L); + } + }, 1L); + } + }, 37L); + + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, min.getBlockX(), 0, max.getBlockZ()), new Location(world, max.getBlockX() + 1, 1, plotMaxZ + 1), new PlotBlock((short) 7, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, min.getBlockX(), dpw.PLOT_HEIGHT + 1, max.getBlockZ()), new Location(world, max.getBlockX() + 1, world.getMaxHeight() + 1, plotMaxZ + 1), new PlotBlock((short) 0, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setCuboid(world, new Location(world, min.getBlockX(), 1, max.getBlockZ()), new Location(world, max.getBlockX() + 1, dpw.PLOT_HEIGHT, plotMaxZ + 1), filling); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setCuboid(world, new Location(world, min.getBlockX(), dpw.PLOT_HEIGHT, max.getBlockZ()), new Location(world, max.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloor); + } + }, 1L); + } + }, 1L); + } + }, 1L); + } + }, 41L); + + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, max.getBlockX(), 0, min.getBlockZ()), new Location(world, plotMaxX + 1, 1, max.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT + 1, min.getBlockZ()), new Location(world, plotMaxX + 1, world.getMaxHeight() + 1, max.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setCuboid(world, new Location(world, max.getBlockX(), 1, min.getBlockZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT, max.getBlockZ() + 1), filling); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT, min.getBlockZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT + 1, max.getBlockZ() + 1), plotfloor); + } + }, 1L); + } + }, 1L); + } + }, 1L); + } + }, 45L); + + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, max.getBlockX(), 0, max.getBlockZ()), new Location(world, plotMaxX + 1, 1, plotMaxZ + 1), new PlotBlock((short) 7, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT + 1, max.getBlockZ()), new Location(world, plotMaxX + 1, world.getMaxHeight() + 1, plotMaxZ + 1), new PlotBlock((short) 0, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setCuboid(world, new Location(world, max.getBlockX(), 1, max.getBlockZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT, plotMaxZ + 1), filling); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT, max.getBlockZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloor); + } + }, 1L); + } + }, 1L); + } + }, 1L); + } + }, 49L); + } + } + }, 20L); } - - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - if ((pos2.getBlockX() - pos1.getBlockX()) < 48) { - PlotHelper.setSimpleCuboid(world, new Location(world, pos1.getBlockX(), 0, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, 1, pos2.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setSimpleCuboid(world, new Location(world, pos1.getBlockX(), dpw.PLOT_HEIGHT + 1, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, world.getMaxHeight() + 1, pos2.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setCuboid(world, new Location(world, pos1.getBlockX(), 1, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, dpw.PLOT_HEIGHT, pos2.getBlockZ() + 1), filling); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setCuboid(world, new Location(world, pos1.getBlockX(), dpw.PLOT_HEIGHT, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, pos2.getBlockZ() + 1), plotfloor); - } }, 5L); - } }, 5L); - } }, 5L); - return; - } - - final int startX = (pos1.getBlockX() / 16) * 16; - final int startZ = (pos1.getBlockZ() / 16) * 16; - final int chunkX = 16 + pos2.getBlockX(); - final int chunkZ = 16 + pos2.getBlockZ(); - final Location l1 = PlotHelper.getPlotBottomLoc(world, plot.id); - final Location l2 = PlotHelper.getPlotTopLoc(world, plot.id); - final int plotMinX = l1.getBlockX() + 1; - final int plotMinZ = l1.getBlockZ() + 1; - final int plotMaxX = l2.getBlockX(); - final int plotMaxZ = l2.getBlockZ(); - Location mn = null; - Location mx = null; - for (int i = startX; i < chunkX; i += 16) { - for (int j = startZ; j < chunkZ; j += 16) { - final Plot plot1 = PlotHelper.getCurrentPlot(new Location(world, i, 0, j)); - if ((plot1 != null) && (!plot1.getId().equals(plot.getId()))) { - break; - } - final Plot plot2 = PlotHelper.getCurrentPlot(new Location(world, i + 15, 0, j)); - if ((plot2 != null) && (!plot2.getId().equals(plot.getId()))) { - break; - } - final Plot plot3 = PlotHelper.getCurrentPlot(new Location(world, i + 15, 0, j + 15)); - if ((plot3 != null) && (!plot3.getId().equals(plot.getId()))) { - break; - } - final Plot plot4 = PlotHelper.getCurrentPlot(new Location(world, i, 0, j + 15)); - if ((plot4 != null) && (!plot4.getId().equals(plot.getId()))) { - break; - } - final Plot plot5 = PlotHelper.getCurrentPlot(new Location(world, i + 15, 0, j + 15)); - if ((plot5 != null) && (!plot5.getId().equals(plot.getId()))) { - break; - } - if (mn == null) { - mn = new Location(world, Math.max(i - 1, plotMinX), 0, Math.max(j - 1, plotMinZ)); - mx = new Location(world, Math.min(i + 16, plotMaxX), 0, Math.min(j + 16, plotMaxZ)); - } else if ((mx.getBlockZ() < (j + 15)) || (mx.getBlockX() < (i + 15))) { - mx = new Location(world, Math.min(i + 16, plotMaxX), 0, Math.min(j + 16, plotMaxZ)); - } - world.regenerateChunk(i / 16, j / 16); - } - } - - final Location max = mx; - final Location min = mn; - - if (min == null) { - PlotHelper.setSimpleCuboid(world, new Location(world, pos1.getBlockX(), 0, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, 1, pos2.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setSimpleCuboid(world, new Location(world, pos1.getBlockX(), dpw.PLOT_HEIGHT + 1, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, world.getMaxHeight() + 1, pos2.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setCuboid(world, new Location(world, pos1.getBlockX(), 1, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, dpw.PLOT_HEIGHT, pos2.getBlockZ() + 1), filling); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setCuboid(world, new Location(world, pos1.getBlockX(), dpw.PLOT_HEIGHT, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, pos2.getBlockZ() + 1), plotfloor); - } }, 5L); - } }, 5L); - } }, 5L); - return; - } else { - - if (min.getBlockX() < plotMinX) { - min.setX(plotMinX); - } - if (min.getBlockZ() < plotMinZ) { - min.setZ(plotMinZ); - } - if (max.getBlockX() > plotMaxX) { - max.setX(plotMaxX); - } - if (max.getBlockZ() > plotMaxZ) { - max.setZ(plotMaxZ); - } - - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setSimpleCuboid(world, new Location(world, plotMinX, 0, plotMinZ), new Location(world, min.getBlockX() + 1, 1, min.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setSimpleCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT + 1, plotMinZ), new Location(world, min.getBlockX() + 1, world.getMaxHeight() + 1, min.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setCuboid(world, new Location(world, plotMinX, 1, plotMinZ), new Location(world, min.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, min.getBlockZ() + 1), filling); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT, plotMinZ), new Location(world, min.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, min.getBlockZ() + 1), plotfloor); - } }, 1L); - } }, 1L); - } }, 1L); - } }, 21L); - - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setSimpleCuboid(world, new Location(world, min.getBlockX(), 0, plotMinZ), new Location(world, max.getBlockX() + 1, 1, min.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setSimpleCuboid(world, new Location(world, min.getBlockX(), dpw.PLOT_HEIGHT + 1, plotMinZ), new Location(world, max.getBlockX() + 1, world.getMaxHeight() + 1, min.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setCuboid(world, new Location(world, min.getBlockX(), 1, plotMinZ), new Location(world, max.getBlockX() + 1, dpw.PLOT_HEIGHT, min.getBlockZ() + 1), filling); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setCuboid(world, new Location(world, min.getBlockX(), dpw.PLOT_HEIGHT, plotMinZ), new Location(world, max.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, min.getBlockZ() + 1), plotfloor); - } }, 1L); - } }, 1L); - } }, 1L); - } }, 25L); - - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setSimpleCuboid(world, new Location(world, max.getBlockX(), 0, plotMinZ), new Location(world, plotMaxX + 1, 1, min.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setSimpleCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT + 1, plotMinZ), new Location(world, plotMaxX + 1, world.getMaxHeight() + 1, min.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setCuboid(world, new Location(world, max.getBlockX(), 1, plotMinZ), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT, min.getBlockZ() + 1), filling); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT, plotMinZ), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT + 1, min.getBlockZ() + 1), plotfloor); - } }, 1L); - } }, 1L); - } }, 1L); - } }, 29L); - - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setSimpleCuboid(world, new Location(world, plotMinX, 0, min.getBlockZ()), new Location(world, min.getBlockX() + 1, 1, max.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setSimpleCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT + 1, min.getBlockZ()), new Location(world, min.getBlockX() + 1, world.getMaxHeight() + 1, max.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setCuboid(world, new Location(world, plotMinX, 1, min.getBlockZ()), new Location(world, min.getBlockX() + 1, dpw.PLOT_HEIGHT, max.getBlockZ() + 1), filling); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT, min.getBlockZ()), new Location(world, min.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, max.getBlockZ() + 1), plotfloor); - } }, 1L); - } }, 1L); - } }, 1L); - } }, 33L); - - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setSimpleCuboid(world, new Location(world, plotMinX, 0, max.getBlockZ()), new Location(world, min.getBlockX() + 1, 1, plotMaxZ + 1), new PlotBlock((short) 7, (byte) 0)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setSimpleCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT + 1, max.getBlockZ()), new Location(world, min.getBlockX() + 1, world.getMaxHeight() + 1, plotMaxZ + 1), new PlotBlock((short) 0, (byte) 0)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setCuboid(world, new Location(world, plotMinX, 1, max.getBlockZ()), new Location(world, min.getBlockX() + 1, dpw.PLOT_HEIGHT, plotMaxZ + 1), filling); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT, max.getBlockZ()), new Location(world, min.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloor); - } }, 1L); - } }, 1L); - } }, 1L); - } }, 37L); - - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setSimpleCuboid(world, new Location(world, min.getBlockX(), 0, max.getBlockZ()), new Location(world, max.getBlockX() + 1, 1, plotMaxZ + 1), new PlotBlock((short) 7, (byte) 0)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setSimpleCuboid(world, new Location(world, min.getBlockX(), dpw.PLOT_HEIGHT + 1, max.getBlockZ()), new Location(world, max.getBlockX() + 1, world.getMaxHeight() + 1, plotMaxZ + 1), new PlotBlock((short) 0, (byte) 0)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setCuboid(world, new Location(world, min.getBlockX(), 1, max.getBlockZ()), new Location(world, max.getBlockX() + 1, dpw.PLOT_HEIGHT, plotMaxZ + 1), filling); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setCuboid(world, new Location(world, min.getBlockX(), dpw.PLOT_HEIGHT, max.getBlockZ()), new Location(world, max.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloor); - } }, 1L); - } }, 1L); - } }, 1L); - } }, 41L); - - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setSimpleCuboid(world, new Location(world, max.getBlockX(), 0, min.getBlockZ()), new Location(world, plotMaxX + 1, 1, max.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setSimpleCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT + 1, min.getBlockZ()), new Location(world, plotMaxX + 1, world.getMaxHeight() + 1, max.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setCuboid(world, new Location(world, max.getBlockX(), 1, min.getBlockZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT, max.getBlockZ() + 1), filling); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT, min.getBlockZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT + 1, max.getBlockZ() + 1), plotfloor); - } }, 1L); - } }, 1L); - } }, 1L); - } }, 45L); - - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setSimpleCuboid(world, new Location(world, max.getBlockX(), 0, max.getBlockZ()), new Location(world, plotMaxX + 1, 1, plotMaxZ + 1), new PlotBlock((short) 7, (byte) 0)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setSimpleCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT + 1, max.getBlockZ()), new Location(world, plotMaxX + 1, world.getMaxHeight() + 1, plotMaxZ + 1), new PlotBlock((short) 0, (byte) 0)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setCuboid(world, new Location(world, max.getBlockX(), 1, max.getBlockZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT, plotMaxZ + 1), filling); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT, max.getBlockZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloor); - } }, 1L); - } }, 1L); - } }, 1L); - } }, 49L); - } - } }, 20L); - } }, 20L); + }, 20L); return true; } @@ -580,16 +711,16 @@ public class DefaultPlotManager extends PlotManager { final int bottomZ = PlotHelper.getPlotBottomLoc(world, plot.id).getBlockZ() - 1; final int topZ = PlotHelper.getPlotTopLoc(world, plot.id).getBlockZ() + 1; - Block block = world.getBlockAt(PlotHelper.getPlotBottomLoc(world, plot.id).add(1, 1, 1)); - Biome current = block.getBiome(); + final Block block = world.getBlockAt(PlotHelper.getPlotBottomLoc(world, plot.id).add(1, 1, 1)); + final Biome current = block.getBiome(); if (biome.equals(current)) { return false; } - + for (int x = bottomX; x <= topX; x++) { for (int z = bottomZ; z <= topZ; z++) { - Block blk = world.getBlockAt(x, 0, z); - Biome c = blk.getBiome(); + final Block blk = world.getBlockAt(x, 0, z); + final Biome c = blk.getBiome(); if (c.equals(biome)) { x += 15; continue; @@ -620,7 +751,7 @@ public class DefaultPlotManager extends PlotManager { PlotHelper.setSimpleCuboid(w, new Location(w, sx, Math.min(dpw.WALL_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz + 1), new Location(w, ex + 1, 257 + 1, ez), new PlotBlock((short) 0, (byte) 0)); PlotHelper.setCuboid(w, new Location(w, sx, 1, sz + 1), new Location(w, ex + 1, dpw.PLOT_HEIGHT, ez), new PlotBlock((short) 7, (byte) 0)); - + PlotHelper.setCuboid(w, new Location(w, sx, 1, sz + 1), new Location(w, sx + 1, dpw.WALL_HEIGHT + 1, ez), dpw.WALL_FILLING); PlotHelper.setCuboid(w, new Location(w, sx, dpw.WALL_HEIGHT + 1, sz + 1), new Location(w, sx + 1, dpw.WALL_HEIGHT + 2, ez), dpw.WALL_BLOCK); @@ -644,11 +775,11 @@ public class DefaultPlotManager extends PlotManager { final int ez = (sz + dpw.ROAD_WIDTH) - 1; final int sx = pos1.getBlockX() - 1; final int ex = pos2.getBlockX() + 2; - + PlotHelper.setSimpleCuboid(w, new Location(w, sx, Math.min(dpw.WALL_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz + 1), new Location(w, ex + 1, 257, ez), new PlotBlock((short) 0, (byte) 0)); - PlotHelper.setCuboid(w, new Location(w, sx + 1, 0, sz), new Location(w, ex, 1, ez + 1), new PlotBlock((short) 7, (byte) 0)); - + PlotHelper.setCuboid(w, new Location(w, sx + 1, 0, sz), new Location(w, ex, 1, ez + 1), new PlotBlock((short) 7, (byte) 0)); + PlotHelper.setCuboid(w, new Location(w, sx + 1, 1, sz), new Location(w, ex, dpw.WALL_HEIGHT + 1, sz + 1), dpw.WALL_FILLING); PlotHelper.setCuboid(w, new Location(w, sx + 1, dpw.WALL_HEIGHT + 1, sz), new Location(w, ex, dpw.WALL_HEIGHT + 2, sz + 1), dpw.WALL_BLOCK); @@ -693,7 +824,7 @@ public class DefaultPlotManager extends PlotManager { final int ez = pos2.getBlockZ() + 1; PlotHelper.setSimpleCuboid(w, new Location(w, sx, Math.min(dpw.PLOT_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz), new Location(w, ex + 1, 257, ez + 1), new PlotBlock((short) 0, (byte) 0)); - + PlotHelper.setCuboid(w, new Location(w, sx, 1, sz), new Location(w, ex + 1, dpw.PLOT_HEIGHT, ez + 1), dpw.MAIN_BLOCK); PlotHelper.setCuboid(w, new Location(w, sx, dpw.PLOT_HEIGHT, sz), new Location(w, ex + 1, dpw.PLOT_HEIGHT + 1, ez + 1), dpw.TOP_BLOCK); @@ -714,7 +845,7 @@ public class DefaultPlotManager extends PlotManager { final int ex = pos2.getBlockX() + 1; PlotHelper.setSimpleCuboid(w, new Location(w, sx, Math.min(dpw.PLOT_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz), new Location(w, ex + 1, 257, ez + 1), new PlotBlock((short) 0, (byte) 0)); - + PlotHelper.setCuboid(w, new Location(w, sx, 1, sz), new Location(w, ex + 1, dpw.PLOT_HEIGHT, ez + 1), dpw.MAIN_BLOCK); PlotHelper.setCuboid(w, new Location(w, sx, dpw.PLOT_HEIGHT, sz), new Location(w, ex + 1, dpw.PLOT_HEIGHT + 1, ez + 1), dpw.TOP_BLOCK); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/DefaultPlotWorld.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/DefaultPlotWorld.java index ef898b883..8480d3c3c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/DefaultPlotWorld.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/DefaultPlotWorld.java @@ -21,13 +21,14 @@ package com.intellectualcrafters.plot.generator; +import org.apache.commons.lang.StringUtils; +import org.bukkit.configuration.ConfigurationSection; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.Configuration; import com.intellectualcrafters.plot.config.ConfigurationNode; import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotWorld; -import org.apache.commons.lang.StringUtils; -import org.bukkit.configuration.ConfigurationSection; public class DefaultPlotWorld extends PlotWorld { @@ -40,98 +41,98 @@ public class DefaultPlotWorld extends PlotWorld { /** * Default Road Height: 64 */ - public final static int ROAD_HEIGHT_DEFAULT = 64; + public final static int ROAD_HEIGHT_DEFAULT = 64; /** * Default plot height: 64 */ - public final static int PLOT_HEIGHT_DEFAULT = 64; + public final static int PLOT_HEIGHT_DEFAULT = 64; /** * Default Wall Height: 64 */ - public final static int WALL_HEIGHT_DEFAULT = 64; + public final static int WALL_HEIGHT_DEFAULT = 64; /** * Default plot width: 32 */ - public final static int PLOT_WIDTH_DEFAULT = 32; + public final static int PLOT_WIDTH_DEFAULT = 32; /** * Default road width: 7 */ - public final static int ROAD_WIDTH_DEFAULT = 7; + public final static int ROAD_WIDTH_DEFAULT = 7; /** * Default main block: 1 */ - public final static PlotBlock[] MAIN_BLOCK_DEFAULT = new PlotBlock[]{new PlotBlock((short) 1, (byte) 0)}; + public final static PlotBlock[] MAIN_BLOCK_DEFAULT = new PlotBlock[] { new PlotBlock((short) 1, (byte) 0) }; /** * Default top blocks: {"2"} */ - public final static PlotBlock[] TOP_BLOCK_DEFAULT = new PlotBlock[]{new PlotBlock((short) 2, (byte) 0)}; + public final static PlotBlock[] TOP_BLOCK_DEFAULT = new PlotBlock[] { new PlotBlock((short) 2, (byte) 0) }; /** * Default wall block: 44 */ - public final static PlotBlock WALL_BLOCK_DEFAULT = new PlotBlock((short) 44, (byte) 0); - public final static PlotBlock CLAIMED_WALL_BLOCK_DEFAULT = new PlotBlock((short) 44, (byte) 1); + public final static PlotBlock WALL_BLOCK_DEFAULT = new PlotBlock((short) 44, (byte) 0); + public final static PlotBlock CLAIMED_WALL_BLOCK_DEFAULT = new PlotBlock((short) 44, (byte) 1); /** * Default wall filling: 1 */ - public final static PlotBlock WALL_FILLING_DEFAULT = new PlotBlock((short) 1, (byte) 0); + public final static PlotBlock WALL_FILLING_DEFAULT = new PlotBlock((short) 1, (byte) 0); /** * Default road stripes: 35 */ - public final static PlotBlock ROAD_STRIPES_DEFAULT = new PlotBlock((short) 98, (byte) 0); - public final static boolean ROAD_STRIPES_ENABLED_DEFAULT = false; + public final static PlotBlock ROAD_STRIPES_DEFAULT = new PlotBlock((short) 98, (byte) 0); + public final static boolean ROAD_STRIPES_ENABLED_DEFAULT = false; /** * Default road block: 155 */ - public final static PlotBlock ROAD_BLOCK_DEFAULT = new PlotBlock((short) 155, (byte) 0); + public final static PlotBlock ROAD_BLOCK_DEFAULT = new PlotBlock((short) 155, (byte) 0); /** * Road Height */ - public int ROAD_HEIGHT; + public int ROAD_HEIGHT; /** * plot height */ - public int PLOT_HEIGHT; + public int PLOT_HEIGHT; /** * Wall height */ - public int WALL_HEIGHT; + public int WALL_HEIGHT; /** * plot width */ - public int PLOT_WIDTH; + public int PLOT_WIDTH; /** * Road width */ - public int ROAD_WIDTH; + public int ROAD_WIDTH; /** * Plot main block */ - public PlotBlock[] MAIN_BLOCK; + public PlotBlock[] MAIN_BLOCK; /** * Top blocks */ - public PlotBlock[] TOP_BLOCK; + public PlotBlock[] TOP_BLOCK; /** * Wall block */ - public PlotBlock WALL_BLOCK; - public PlotBlock CLAIMED_WALL_BLOCK; + public PlotBlock WALL_BLOCK; + public PlotBlock CLAIMED_WALL_BLOCK; /** * Wall filling */ - public PlotBlock WALL_FILLING; + public PlotBlock WALL_FILLING; /** * Road stripes */ - public PlotBlock ROAD_STRIPES; + public PlotBlock ROAD_STRIPES; /** * enable road stripes */ - public boolean ROAD_STRIPES_ENABLED; + public boolean ROAD_STRIPES_ENABLED; /** * Road block */ - public PlotBlock ROAD_BLOCK; + public PlotBlock ROAD_BLOCK; /* * Here we are just calling the super method, nothing special @@ -152,8 +153,8 @@ public class DefaultPlotWorld extends PlotWorld { @Override public ConfigurationNode[] getSettingNodes() { // TODO return a set of configuration nodes (used for setup command) - return new ConfigurationNode[]{new ConfigurationNode("plot.height", DefaultPlotWorld.PLOT_HEIGHT_DEFAULT, "Plot height", Configuration.INTEGER, true), new ConfigurationNode("plot.size", DefaultPlotWorld.PLOT_WIDTH_DEFAULT, "Plot width", Configuration.INTEGER, true), new ConfigurationNode("plot.filling", DefaultPlotWorld.MAIN_BLOCK_DEFAULT, "Plot block", Configuration.BLOCKLIST, true), new ConfigurationNode("plot.floor", DefaultPlotWorld.TOP_BLOCK_DEFAULT, "Plot floor block", Configuration.BLOCKLIST, true), new ConfigurationNode("wall.block", DefaultPlotWorld.WALL_BLOCK_DEFAULT, "Top wall block", Configuration.BLOCK, true), new ConfigurationNode("wall.block_claimed", DefaultPlotWorld.CLAIMED_WALL_BLOCK_DEFAULT, "Wall block (claimed)", Configuration.BLOCK, true), new ConfigurationNode("road.width", DefaultPlotWorld.ROAD_WIDTH_DEFAULT, "Road width", Configuration.INTEGER, true), - new ConfigurationNode("road.height", DefaultPlotWorld.ROAD_HEIGHT_DEFAULT, "Road height", Configuration.INTEGER, true), new ConfigurationNode("road.enable_stripes", DefaultPlotWorld.ROAD_STRIPES_ENABLED_DEFAULT, "Enable road stripes", Configuration.BOOLEAN, true), new ConfigurationNode("road.block", DefaultPlotWorld.ROAD_BLOCK_DEFAULT, "Road block", Configuration.BLOCK, true), new ConfigurationNode("road.stripes", DefaultPlotWorld.ROAD_STRIPES_DEFAULT, "Road stripe block", Configuration.BLOCK, true), new ConfigurationNode("wall.filling", DefaultPlotWorld.WALL_FILLING_DEFAULT, "Wall filling block", Configuration.BLOCK, true), new ConfigurationNode("wall.height", DefaultPlotWorld.WALL_HEIGHT_DEFAULT, "Wall height", Configuration.INTEGER, true),}; + return new ConfigurationNode[] { new ConfigurationNode("plot.height", DefaultPlotWorld.PLOT_HEIGHT_DEFAULT, "Plot height", Configuration.INTEGER, true), new ConfigurationNode("plot.size", DefaultPlotWorld.PLOT_WIDTH_DEFAULT, "Plot width", Configuration.INTEGER, true), new ConfigurationNode("plot.filling", DefaultPlotWorld.MAIN_BLOCK_DEFAULT, "Plot block", Configuration.BLOCKLIST, true), new ConfigurationNode("plot.floor", DefaultPlotWorld.TOP_BLOCK_DEFAULT, "Plot floor block", Configuration.BLOCKLIST, true), new ConfigurationNode("wall.block", DefaultPlotWorld.WALL_BLOCK_DEFAULT, "Top wall block", Configuration.BLOCK, true), new ConfigurationNode("wall.block_claimed", DefaultPlotWorld.CLAIMED_WALL_BLOCK_DEFAULT, "Wall block (claimed)", Configuration.BLOCK, true), new ConfigurationNode("road.width", DefaultPlotWorld.ROAD_WIDTH_DEFAULT, "Road width", Configuration.INTEGER, true), + new ConfigurationNode("road.height", DefaultPlotWorld.ROAD_HEIGHT_DEFAULT, "Road height", Configuration.INTEGER, true), new ConfigurationNode("road.enable_stripes", DefaultPlotWorld.ROAD_STRIPES_ENABLED_DEFAULT, "Enable road stripes", Configuration.BOOLEAN, true), new ConfigurationNode("road.block", DefaultPlotWorld.ROAD_BLOCK_DEFAULT, "Road block", Configuration.BLOCK, true), new ConfigurationNode("road.stripes", DefaultPlotWorld.ROAD_STRIPES_DEFAULT, "Road stripe block", Configuration.BLOCK, true), new ConfigurationNode("wall.filling", DefaultPlotWorld.WALL_FILLING_DEFAULT, "Wall filling block", Configuration.BLOCK, true), new ConfigurationNode("wall.height", DefaultPlotWorld.WALL_HEIGHT_DEFAULT, "Wall height", Configuration.INTEGER, true), }; } /** diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/WorldGenerator.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/WorldGenerator.java index cdbd8e63c..ea4a63e6b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/WorldGenerator.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/WorldGenerator.java @@ -21,26 +21,27 @@ package com.intellectualcrafters.plot.generator; -import com.intellectualcrafters.plot.PlotMain; -import com.intellectualcrafters.plot.object.PlotBlock; -import com.intellectualcrafters.plot.object.PlotGenerator; -import com.intellectualcrafters.plot.object.PlotManager; -import com.intellectualcrafters.plot.object.PlotWorld; +import java.util.Arrays; +import java.util.List; +import java.util.Random; + import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.generator.BlockPopulator; -import java.util.Arrays; -import java.util.List; -import java.util.Random; +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.object.PlotBlock; +import com.intellectualcrafters.plot.object.PlotGenerator; +import com.intellectualcrafters.plot.object.PlotManager; +import com.intellectualcrafters.plot.object.PlotWorld; /** * The default generator is very messy, as we have decided - * to try externalize all calculations from within the loop. - You will - * see a lot of slower implementations have a single for loop. - This is - * perfectly fine to do, it will just mean world generation may take - * somewhat longer + * to try externalize all calculations from within the loop. - You will + * see a lot of slower implementations have a single for loop. - This is + * perfectly fine to do, it will just mean world generation may take + * somewhat longer * * @author Citymonstret * @author Empire92 @@ -49,35 +50,35 @@ public class WorldGenerator extends PlotGenerator { /** * Set to static to re-use the same managet for all Default World Generators */ - private static PlotManager manager = null; + private static PlotManager manager = null; /** * Some generator specific variables (implementation dependent) */ - final int plotsize; - final int pathsize; - final PlotBlock wall; - final PlotBlock wallfilling; - final PlotBlock floor1; - final PlotBlock floor2; - final int size; - final Biome biome; - final int roadheight; - final int wallheight; - final int plotheight; - final PlotBlock[] plotfloors; - final PlotBlock[] filling; + final int plotsize; + final int pathsize; + final PlotBlock wall; + final PlotBlock wallfilling; + final PlotBlock floor1; + final PlotBlock floor2; + final int size; + final Biome biome; + final int roadheight; + final int wallheight; + final int plotheight; + final PlotBlock[] plotfloors; + final PlotBlock[] filling; /** * result object is returned for each generated chunk, do stuff to it */ - short[][] result; + short[][] result; /** * plotworld object */ - DefaultPlotWorld plotworld = null; + DefaultPlotWorld plotworld = null; /** * Faster sudo-random number generator than java.util.random */ - private long state; + private long state; /** * Initialize variables, and create plotworld object used in calculations @@ -176,7 +177,8 @@ public class WorldGenerator extends PlotGenerator { private void setCuboidRegion(final int x1, final int x2, final int y1, final int y2, final int z1, final int z2, final PlotBlock[] blocks) { if (blocks.length == 1) { setCuboidRegion(x1, x2, y1, y2, z1, z2, blocks[0]); - } else { + } + else { for (int x = x1; x < x2; x++) { for (int z = z1; z < z2; z++) { for (int y = y1; y < y2; y++) { @@ -243,7 +245,8 @@ public class WorldGenerator extends PlotGenerator { double pathWidthLower; if ((this.pathsize % 2) == 0) { pathWidthLower = Math.floor(this.pathsize / 2) - 1; - } else { + } + else { pathWidthLower = Math.floor(this.pathsize / 2); } cx = (cx % this.size) + (8 * this.size); @@ -298,12 +301,14 @@ public class WorldGenerator extends PlotGenerator { int start, end; if ((plotMinX + 2) <= 16) { start = 16 - plotMinX - 1; - } else { + } + else { start = 16; } if ((roadStartX - 1) <= 16) { end = (16 - roadStartX) + 1; - } else { + } + else { end = 0; } if (!(((plotMinX + 2) <= 16) || ((roadStartX - 1) <= 16))) { @@ -317,12 +322,14 @@ public class WorldGenerator extends PlotGenerator { int start, end; if ((plotMinZ + 2) <= 16) { start = 16 - plotMinZ - 1; - } else { + } + else { start = 16; } if ((roadStartZ - 1) <= 16) { end = (16 - roadStartZ) + 1; - } else { + } + else { end = 0; } if (!(((plotMinZ + 2) <= 16) || ((roadStartZ - 1) <= 16))) { @@ -335,12 +342,14 @@ public class WorldGenerator extends PlotGenerator { int start, end; if ((plotMinX + 2) <= 16) { start = 16 - plotMinX - 1; - } else { + } + else { start = 16; } if ((roadStartX - 1) <= 16) { end = (16 - roadStartX) + 1; - } else { + } + else { end = 0; } if (!(((plotMinX + 2) <= 16) || ((roadStartX - 1) <= 16))) { @@ -353,12 +362,14 @@ public class WorldGenerator extends PlotGenerator { int start, end; if ((plotMinZ + 2) <= 16) { start = 16 - plotMinZ - 1; - } else { + } + else { start = 16; } if ((roadStartZ - 1) <= 16) { end = (16 - roadStartZ) + 1; - } else { + } + else { end = 0; } if (!(((plotMinZ + 2) <= 16) || ((roadStartZ - 1) <= 16))) { @@ -380,7 +391,8 @@ public class WorldGenerator extends PlotGenerator { setCuboidRegion(0, 16 - roadStartX, 1, this.plotheight, 16 - plotMinZ, 16, this.filling); setCuboidRegion(0, 16 - roadStartX, this.plotheight, this.plotheight + 1, 16 - plotMinZ, 16, this.plotfloors); } - } else { + } + else { if (roadStartZ <= 16) { if (plotMinX > 16) { setCuboidRegion(0, 16, 1, this.plotheight, 0, 16 - roadStartZ, this.filling); @@ -392,7 +404,8 @@ public class WorldGenerator extends PlotGenerator { if (plotMinZ <= 16) { setCuboidRegion(16 - plotMinX, 16, 1, this.plotheight, 16 - plotMinZ, 16, this.filling); setCuboidRegion(16 - plotMinX, 16, this.plotheight, this.plotheight + 1, 16 - plotMinZ, 16, this.plotfloors); - } else { + } + else { int z = 16 - roadStartZ; if (z < 0) { z = 16; @@ -403,7 +416,8 @@ public class WorldGenerator extends PlotGenerator { if (roadStartZ <= 16) { setCuboidRegion(16 - plotMinX, 16, 1, this.plotheight, 0, 16 - roadStartZ, this.filling); setCuboidRegion(16 - plotMinX, 16, this.plotheight, this.plotheight + 1, 0, 16 - roadStartZ, this.plotfloors); - } else { + } + else { if (roadStartX <= 16) { if (plotMinZ > 16) { int x = 16 - roadStartX; @@ -415,7 +429,8 @@ public class WorldGenerator extends PlotGenerator { } } } - } else { + } + else { if (plotMinZ <= 16) { if (roadStartX > 16) { int x = 16 - roadStartX; @@ -425,7 +440,8 @@ public class WorldGenerator extends PlotGenerator { setCuboidRegion(0, x, 1, this.plotheight, 16 - plotMinZ, 16, this.filling); setCuboidRegion(0, x, this.plotheight, this.plotheight + 1, 16 - plotMinZ, 16, this.plotfloors); } - } else { + } + else { if (roadStartZ > 16) { int x = 16 - roadStartX; if (x < 0) { @@ -438,14 +454,16 @@ public class WorldGenerator extends PlotGenerator { if (roadStartX > 16) { setCuboidRegion(0, x, 1, this.plotheight, 0, z, this.filling); setCuboidRegion(0, x, this.plotheight, this.plotheight + 1, 0, z, this.plotfloors); - } else { + } + else { setCuboidRegion(0, x, 1, this.plotheight, 0, z, this.filling); setCuboidRegion(0, x, this.plotheight, this.plotheight + 1, 0, z, this.plotfloors); } } } } - } else { + } + else { if (roadStartX <= 16) { if (roadStartZ <= 16) { setCuboidRegion(0, 16 - roadStartX, 1, this.plotheight, 0, 16 - roadStartZ, this.filling); @@ -474,12 +492,14 @@ public class WorldGenerator extends PlotGenerator { int start, end; if ((plotMinX + 2) <= 16) { start = 16 - plotMinX - 1; - } else { + } + else { start = 16; } if ((roadStartX - 1) <= 16) { end = (16 - roadStartX) + 1; - } else { + } + else { end = 0; } if (!(((plotMinX + 2) <= 16) || ((roadStartX - 1) <= 16))) { @@ -494,12 +514,14 @@ public class WorldGenerator extends PlotGenerator { int start, end; if ((plotMinZ + 2) <= 16) { start = 16 - plotMinZ - 1; - } else { + } + else { start = 16; } if ((roadStartZ - 1) <= 16) { end = (16 - roadStartZ) + 1; - } else { + } + else { end = 0; } if (!(((plotMinZ + 2) <= 16) || ((roadStartZ - 1) <= 16))) { @@ -514,12 +536,14 @@ public class WorldGenerator extends PlotGenerator { int start, end; if ((plotMinX + 1) <= 16) { start = 16 - plotMinX; - } else { + } + else { start = 16; } if ((roadStartX + 1) <= 16) { end = (16 - roadStartX) + 1; - } else { + } + else { end = 0; } if (!(((plotMinX + 1) <= 16) || (roadStartX <= 16))) { @@ -534,12 +558,14 @@ public class WorldGenerator extends PlotGenerator { int start, end; if ((plotMinZ + 1) <= 16) { start = 16 - plotMinZ; - } else { + } + else { start = 16; } if ((roadStartZ + 1) <= 16) { end = (16 - roadStartZ) + 1; - } else { + } + else { end = 0; } if (!(((plotMinZ + 1) <= 16) || ((roadStartZ + 1) <= 16))) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/XPopulator.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/XPopulator.java index dc30843b1..90136ba34 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/XPopulator.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/XPopulator.java @@ -21,14 +21,15 @@ package com.intellectualcrafters.plot.generator; -import com.intellectualcrafters.plot.object.PlotBlock; -import com.intellectualcrafters.plot.object.PlotWorld; +import java.util.Random; + import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.generator.BlockPopulator; -import java.util.Random; +import com.intellectualcrafters.plot.object.PlotBlock; +import com.intellectualcrafters.plot.object.PlotWorld; /** * @author Citymonstret @@ -42,24 +43,24 @@ public class XPopulator extends BlockPopulator { * information about how a BlockPopulator works. */ - final int plotsize; - final int pathsize; - final PlotBlock wall; - final PlotBlock wallfilling; - final PlotBlock floor1; - final PlotBlock floor2; - final int size; - final int roadheight; - final int wallheight; - final int plotheight; - final PlotBlock[] plotfloors; - final PlotBlock[] filling; + final int plotsize; + final int pathsize; + final PlotBlock wall; + final PlotBlock wallfilling; + final PlotBlock floor1; + final PlotBlock floor2; + final int size; + final int roadheight; + final int wallheight; + final int plotheight; + final PlotBlock[] plotfloors; + final PlotBlock[] filling; private final DefaultPlotWorld plotworld; - final private double pathWidthLower; - Biome biome; - private int X; - private int Z; - private long state; + final private double pathWidthLower; + Biome biome; + private int X; + private int Z; + private long state; public XPopulator(final PlotWorld pw) { this.plotworld = (DefaultPlotWorld) pw; @@ -85,7 +86,8 @@ public class XPopulator extends BlockPopulator { if ((this.pathsize % 2) == 0) { this.pathWidthLower = Math.floor(this.pathsize / 2) - 1; - } else { + } + else { this.pathWidthLower = Math.floor(this.pathsize / 2); } } @@ -124,7 +126,8 @@ public class XPopulator extends BlockPopulator { private void setCuboidRegion(final int x1, final int x2, final int y1, final int y2, final int z1, final int z2, final PlotBlock[] blocks, final World w) { if (blocks.length == 1) { setCuboidRegion(x1, x2, y1, y2, z1, z2, blocks[0], w); - } else { + } + else { for (int x = x1; x < x2; x++) { for (int z = z1; z < z2; z++) { for (int y = y1; y < y2; y++) { @@ -142,9 +145,9 @@ public class XPopulator extends BlockPopulator { public short[] getBlock(final String block) { if (block.contains(":")) { final String[] split = block.split(":"); - return new short[]{Short.parseShort(split[0]), Short.parseShort(split[1])}; + return new short[] { Short.parseShort(split[0]), Short.parseShort(split[1]) }; } - return new short[]{Short.parseShort(block), 0}; + return new short[] { Short.parseShort(block), 0 }; } @Override @@ -204,12 +207,14 @@ public class XPopulator extends BlockPopulator { int start, end; if ((plotMinX + 2) <= 16) { start = 16 - plotMinX - 1; - } else { + } + else { start = 16; } if ((roadStartX - 1) <= 16) { end = (16 - roadStartX) + 1; - } else { + } + else { end = 0; } if (!(((plotMinX + 2) <= 16) || ((roadStartX - 1) <= 16))) { @@ -223,12 +228,14 @@ public class XPopulator extends BlockPopulator { int start, end; if ((plotMinZ + 2) <= 16) { start = 16 - plotMinZ - 1; - } else { + } + else { start = 16; } if ((roadStartZ - 1) <= 16) { end = (16 - roadStartZ) + 1; - } else { + } + else { end = 0; } if (!(((plotMinZ + 2) <= 16) || ((roadStartZ - 1) <= 16))) { @@ -241,12 +248,14 @@ public class XPopulator extends BlockPopulator { int start, end; if ((plotMinX + 2) <= 16) { start = 16 - plotMinX - 1; - } else { + } + else { start = 16; } if ((roadStartX - 1) <= 16) { end = (16 - roadStartX) + 1; - } else { + } + else { end = 0; } if (!(((plotMinX + 2) <= 16) || ((roadStartX - 1) <= 16))) { @@ -259,12 +268,14 @@ public class XPopulator extends BlockPopulator { int start, end; if ((plotMinZ + 2) <= 16) { start = 16 - plotMinZ - 1; - } else { + } + else { start = 16; } if ((roadStartZ - 1) <= 16) { end = (16 - roadStartZ) + 1; - } else { + } + else { end = 0; } if (!(((plotMinZ + 2) <= 16) || ((roadStartZ - 1) <= 16))) { @@ -280,12 +291,14 @@ public class XPopulator extends BlockPopulator { int start, end; if ((plotMinX + 2) <= 16) { start = 16 - plotMinX - 1; - } else { + } + else { start = 16; } if ((roadStartX - 1) <= 16) { end = (16 - roadStartX) + 1; - } else { + } + else { end = 0; } if (!(((plotMinX + 2) <= 16) || ((roadStartX - 1) <= 16))) { @@ -300,12 +313,14 @@ public class XPopulator extends BlockPopulator { int start, end; if ((plotMinZ + 2) <= 16) { start = 16 - plotMinZ - 1; - } else { + } + else { start = 16; } if ((roadStartZ - 1) <= 16) { end = (16 - roadStartZ) + 1; - } else { + } + else { end = 0; } if (!(((plotMinZ + 2) <= 16) || ((roadStartZ - 1) <= 16))) { @@ -320,12 +335,14 @@ public class XPopulator extends BlockPopulator { int start, end; if ((plotMinX + 1) <= 16) { start = 16 - plotMinX; - } else { + } + else { start = 16; } if ((roadStartX + 1) <= 16) { end = (16 - roadStartX) + 1; - } else { + } + else { end = 0; } if (!(((plotMinX + 1) <= 16) || (roadStartX <= 16))) { @@ -340,12 +357,14 @@ public class XPopulator extends BlockPopulator { int start, end; if ((plotMinZ + 1) <= 16) { start = 16 - plotMinZ; - } else { + } + else { start = 16; } if ((roadStartZ + 1) <= 16) { end = (16 - roadStartZ) + 1; - } else { + } + else { end = 0; } if (!(((plotMinZ + 1) <= 16) || ((roadStartZ + 1) <= 16))) { @@ -370,7 +389,8 @@ public class XPopulator extends BlockPopulator { setCuboidRegion(0, 16 - roadStartX, 1, this.plotheight, 16 - plotMinZ, 16, this.filling, w); setCuboidRegion(0, 16 - roadStartX, this.plotheight, this.plotheight + 1, 16 - plotMinZ, 16, this.plotfloors, w); } - } else { + } + else { if (roadStartZ <= 16) { if (plotMinX > 16) { setCuboidRegion(0, 16, 1, this.plotheight, 0, 16 - roadStartZ, this.filling, w); @@ -382,7 +402,8 @@ public class XPopulator extends BlockPopulator { if (plotMinZ <= 16) { setCuboidRegion(16 - plotMinX, 16, 1, this.plotheight, 16 - plotMinZ, 16, this.filling, w); setCuboidRegion(16 - plotMinX, 16, this.plotheight, this.plotheight + 1, 16 - plotMinZ, 16, this.plotfloors, w); - } else { + } + else { int z = 16 - roadStartZ; if (z < 0) { z = 16; @@ -393,7 +414,8 @@ public class XPopulator extends BlockPopulator { if (roadStartZ <= 16) { setCuboidRegion(16 - plotMinX, 16, 1, this.plotheight, 0, 16 - roadStartZ, this.filling, w); setCuboidRegion(16 - plotMinX, 16, this.plotheight, this.plotheight + 1, 0, 16 - roadStartZ, this.plotfloors, w); - } else { + } + else { if (roadStartX <= 16) { if (plotMinZ > 16) { int x = 16 - roadStartX; @@ -405,7 +427,8 @@ public class XPopulator extends BlockPopulator { } } } - } else { + } + else { if (plotMinZ <= 16) { if (roadStartX > 16) { int x = 16 - roadStartX; @@ -415,7 +438,8 @@ public class XPopulator extends BlockPopulator { setCuboidRegion(0, x, 1, this.plotheight, 16 - plotMinZ, 16, this.filling, w); setCuboidRegion(0, x, this.plotheight, this.plotheight + 1, 16 - plotMinZ, 16, this.plotfloors, w); } - } else { + } + else { if (roadStartZ > 16) { int x = 16 - roadStartX; if (x < 0) { @@ -428,14 +452,16 @@ public class XPopulator extends BlockPopulator { if (roadStartX > 16) { setCuboidRegion(0, x, 1, this.plotheight, 0, z, this.filling, w); setCuboidRegion(0, x, this.plotheight, this.plotheight + 1, 0, z, this.plotfloors, w); - } else { + } + else { setCuboidRegion(0, x, 1, this.plotheight, 0, z, this.filling, w); setCuboidRegion(0, x, this.plotheight, this.plotheight + 1, 0, z, this.plotfloors, w); } } } } - } else { + } + else { if (roadStartX <= 16) { if (roadStartZ <= 16) { setCuboidRegion(0, 16 - roadStartX, 1, this.plotheight, 0, 16 - roadStartZ, this.filling, w); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/EntityListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/EntityListener.java index a872f11ac..b4e9f64c8 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/EntityListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/EntityListener.java @@ -1,12 +1,16 @@ package com.intellectualcrafters.plot.listeners; -import com.intellectualcrafters.plot.PlotMain; -import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.config.Settings; -import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.util.PlayerFunctions; -import com.intellectualcrafters.plot.util.PlotHelper; -import org.bukkit.*; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map.Entry; +import java.util.Set; + +import org.bukkit.Bukkit; +import org.bukkit.Chunk; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -21,45 +25,46 @@ import org.bukkit.event.world.ChunkLoadEvent; import org.bukkit.event.world.ChunkUnloadEvent; import org.bukkit.scheduler.BukkitScheduler; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.Set; +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.util.PlayerFunctions; +import com.intellectualcrafters.plot.util.PlotHelper; /** * @author Empire92 */ -@SuppressWarnings({"unused", "deprecation"}) +@SuppressWarnings({ "unused", "deprecation" }) public class EntityListener implements Listener { public final static HashMap>> entityMap = new HashMap<>(); public EntityListener() { - BukkitScheduler scheduler = Bukkit.getServer().getScheduler(); + final BukkitScheduler scheduler = Bukkit.getServer().getScheduler(); scheduler.scheduleSyncRepeatingTask(PlotMain.getMain(), new Runnable() { @Override public void run() { - Iterator>>> worldIt = entityMap.entrySet().iterator(); + final Iterator>>> worldIt = entityMap.entrySet().iterator(); - Set plots = PlotMain.getPlots(); + final Set plots = PlotMain.getPlots(); while (worldIt.hasNext()) { - Entry>> entry = worldIt.next(); - String worldname = entry.getKey(); + final Entry>> entry = worldIt.next(); + final String worldname = entry.getKey(); if (!PlotMain.isPlotWorld(worldname)) { worldIt.remove(); continue; } - World world = Bukkit.getWorld(worldname); - if (world == null || entry.getValue().size() == 0) { + final World world = Bukkit.getWorld(worldname); + if ((world == null) || (entry.getValue().size() == 0)) { worldIt.remove(); continue; } - Iterator>> it = entry.getValue().entrySet().iterator(); + final Iterator>> it = entry.getValue().entrySet().iterator(); while (it.hasNext()) { - Entry> plotEntry = it.next(); - Plot plot = plotEntry.getKey(); + final Entry> plotEntry = it.next(); + final Plot plot = plotEntry.getKey(); if (!plots.contains(plot)) { it.remove(); continue; @@ -70,8 +75,7 @@ public class EntityListener implements Listener { final Location pos1 = PlotHelper.getPlotBottomLoc(world, plot.id).add(1, 0, 1); final Location pos2 = PlotHelper.getPlotTopLoc(world, plot.id); try { - loops: - for (int i = (pos1.getBlockX() / 16) * 16; i < (16 + ((pos2.getBlockX() / 16) * 16)); i += 16) { + loops: for (int i = (pos1.getBlockX() / 16) * 16; i < (16 + ((pos2.getBlockX() / 16) * 16)); i += 16) { for (int j = (pos1.getBlockZ() / 16) * 16; j < (16 + ((pos2.getBlockZ() / 16) * 16)); j += 16) { final Chunk chunk = world.getChunkAt(i, j); if (chunk.isLoaded()) { @@ -80,7 +84,8 @@ public class EntityListener implements Listener { } } } - } catch (Exception e) { + } + catch (final Exception e) { it.remove(); continue; } @@ -97,17 +102,18 @@ public class EntityListener implements Listener { public static void onPlayerInteract(final PlayerInteractEvent e) { if (e.getAction() == Action.RIGHT_CLICK_BLOCK) { final Player p = e.getPlayer(); - World w = p.getWorld(); - String n = w.getName(); - if (e.getMaterial() == Material.MONSTER_EGG || e.getMaterial() == Material.MONSTER_EGGS) { + final World w = p.getWorld(); + final String n = w.getName(); + if ((e.getMaterial() == Material.MONSTER_EGG) || (e.getMaterial() == Material.MONSTER_EGGS)) { if (entityMap.containsKey(n)) { - Location l = e.getClickedBlock().getLocation(); - Plot plot = PlotHelper.getCurrentPlot(l); - if (plot != null && plot.hasRights(p)) { + final Location l = e.getClickedBlock().getLocation(); + final Plot plot = PlotHelper.getCurrentPlot(l); + if ((plot != null) && plot.hasRights(p)) { int mobs; if (entityMap.get(n).containsKey(plot)) { mobs = entityMap.get(n).get(plot).size(); - } else { + } + else { mobs = 0; } if (!(PlotMain.hasPermissionRange(p, "plots.mobcap", Settings.MOB_CAP) > mobs)) { @@ -120,12 +126,12 @@ public class EntityListener implements Listener { } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public static void onCreatureSpawn(CreatureSpawnEvent e) { - Location l = e.getLocation(); - String w = l.getWorld().getName(); + public static void onCreatureSpawn(final CreatureSpawnEvent e) { + final Location l = e.getLocation(); + final String w = l.getWorld().getName(); if (PlotMain.isPlotWorld(w)) { - Plot plot = PlotHelper.getCurrentPlot(l); - if (plot != null && plot.hasOwner()) { + final Plot plot = PlotHelper.getCurrentPlot(l); + if ((plot != null) && plot.hasOwner()) { addEntity(e.getEntity(), plot); } } @@ -134,10 +140,10 @@ public class EntityListener implements Listener { @EventHandler public static void onChunkLoad(final ChunkLoadEvent e) { if (PlotMain.isPlotWorld(e.getWorld())) { - for (Entity entity : e.getChunk().getEntities()) { + for (final Entity entity : e.getChunk().getEntities()) { if (entity instanceof LivingEntity) { if (!(entity instanceof Player)) { - Plot plot = PlotHelper.getCurrentPlot(entity.getLocation()); + final Plot plot = PlotHelper.getCurrentPlot(entity.getLocation()); if (plot != null) { if (plot.hasOwner()) { addEntity(entity, plot); @@ -149,11 +155,11 @@ public class EntityListener implements Listener { } } - public static void addEntity(Entity entity, Plot plot) { + public static void addEntity(final Entity entity, final Plot plot) { if (!entityMap.containsKey(plot.world)) { entityMap.put(plot.world, new HashMap>()); } - HashMap> section = entityMap.get(plot.world); + final HashMap> section = entityMap.get(plot.world); if (section.containsKey(plot)) { section.put(plot, new HashSet()); } @@ -161,19 +167,20 @@ public class EntityListener implements Listener { } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public static void onEntityDeath(EntityDeathEvent e) { - Entity entity = e.getEntity(); - Location l = entity.getLocation(); - String w = l.getWorld().getName(); + public static void onEntityDeath(final EntityDeathEvent e) { + final Entity entity = e.getEntity(); + final Location l = entity.getLocation(); + final String w = l.getWorld().getName(); if (entityMap.containsKey(w)) { - int id = entity.getEntityId(); - Plot plot = PlotHelper.getCurrentPlot(entity.getLocation()); + final int id = entity.getEntityId(); + final Plot plot = PlotHelper.getCurrentPlot(entity.getLocation()); if (plot != null) { if (entityMap.get(w).containsKey(plot)) { entityMap.get(w).get(plot).remove(id); } - } else { - for (Entry> n : entityMap.get(w).entrySet()) { + } + else { + for (final Entry> n : entityMap.get(w).entrySet()) { n.getValue().remove(id); } } @@ -182,18 +189,19 @@ public class EntityListener implements Listener { @EventHandler public static void onChunkDespawn(final ChunkUnloadEvent e) { - String w = e.getWorld().getName(); + final String w = e.getWorld().getName(); if (entityMap.containsKey(w)) { - for (Entity entity : e.getChunk().getEntities()) { + for (final Entity entity : e.getChunk().getEntities()) { if (entity instanceof LivingEntity) { if (!(entity instanceof Player)) { - Plot plot = PlotHelper.getCurrentPlot(entity.getLocation()); + final Plot plot = PlotHelper.getCurrentPlot(entity.getLocation()); if (plot != null) { if (plot.hasOwner()) { if (entityMap.get(w).containsKey(plot)) { if (entityMap.get(w).get(plot).size() == 1) { entityMap.get(w).remove(plot); - } else { + } + else { entityMap.get(w).get(plot).remove(entity.getEntityId()); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/ForceFieldListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/ForceFieldListener.java index 6760ee76e..9d841f8ac 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/ForceFieldListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/ForceFieldListener.java @@ -21,8 +21,9 @@ package com.intellectualcrafters.plot.listeners; -import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.util.PlayerFunctions; +import java.util.HashSet; +import java.util.Set; + import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -32,8 +33,8 @@ import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; -import java.util.HashSet; -import java.util.Set; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.util.PlayerFunctions; /** * @author Citymonstret @@ -78,17 +79,20 @@ public class ForceFieldListener implements Listener { double x = 0d, y = 0d, z = 0d; if (playerX < oPlayerX) { x = 1.0d; - } else if (playerX > oPlayerX) { + } + else if (playerX > oPlayerX) { x = -1.0d; } if (playerY < oPlayerY) { y = 0.5d; - } else if (playerY > oPlayerY) { + } + else if (playerY > oPlayerY) { y = -0.5d; } if (playerZ < oPlayerZ) { z = 1.0d; - } else if (playerZ > oPlayerZ) { + } + else if (playerZ > oPlayerZ) { z = -1.0d; } return new Vector(x, y, z); @@ -109,7 +113,8 @@ public class ForceFieldListener implements Listener { for (final Player oPlayer : players) { oPlayer.setVelocity(calculateVelocity(player, oPlayer)); } - } else { + } + else { final Player oPlayer = hasNearbyPermitted(player, plot); if (oPlayer == null) { return; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/InventoryListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/InventoryListener.java index 831622c19..81a6eaac3 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/InventoryListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/InventoryListener.java @@ -1,7 +1,5 @@ package com.intellectualcrafters.plot.listeners; -import com.intellectualcrafters.plot.object.InfoInventory; -import com.intellectualcrafters.plot.util.PlayerFunctions; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.EventHandler; @@ -10,6 +8,9 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryInteractEvent; import org.bukkit.inventory.Inventory; +import com.intellectualcrafters.plot.object.InfoInventory; +import com.intellectualcrafters.plot.util.PlayerFunctions; + /** * Created 2014-11-18 for PlotSquared * @@ -19,14 +20,14 @@ import org.bukkit.inventory.Inventory; public class InventoryListener implements Listener { @EventHandler - public void onInventoryAction(InventoryInteractEvent event) { + public void onInventoryAction(final InventoryInteractEvent event) { if (event.getInventory().getHolder() instanceof InfoInventory) { event.setResult(Event.Result.DENY); } } @EventHandler - public void onInventoryClick(InventoryClickEvent event) { + public void onInventoryClick(final InventoryClickEvent event) { final Inventory inventory = event.getInventory(); final Player player = (Player) event.getWhoClicked(); if (inventory.getHolder() instanceof InfoInventory) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java index cf3f06244..5c276decf 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java @@ -21,16 +21,14 @@ package com.intellectualcrafters.plot.listeners; -import com.intellectualcrafters.plot.PlotMain; -import com.intellectualcrafters.plot.commands.Setup; -import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.config.Settings; -import com.intellectualcrafters.plot.database.DBFunc; -import com.intellectualcrafters.plot.object.*; -import com.intellectualcrafters.plot.util.PlayerFunctions; -import com.intellectualcrafters.plot.util.PlotHelper; +import java.util.List; +import java.util.Set; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; @@ -40,21 +38,50 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.block.*; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockDamageEvent; +import org.bukkit.event.block.BlockFadeEvent; +import org.bukkit.event.block.BlockFormEvent; +import org.bukkit.event.block.BlockFromToEvent; +import org.bukkit.event.block.BlockGrowEvent; +import org.bukkit.event.block.BlockIgniteEvent; +import org.bukkit.event.block.BlockPistonExtendEvent; +import org.bukkit.event.block.BlockPistonRetractEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.block.BlockSpreadEvent; +import org.bukkit.event.block.EntityBlockFormEvent; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.player.*; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerBucketEmptyEvent; +import org.bukkit.event.player.PlayerBucketFillEvent; +import org.bukkit.event.player.PlayerEggThrowEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.world.StructureGrowEvent; import org.bukkit.event.world.WorldLoadEvent; -import java.util.List; -import java.util.Set; +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.commands.Setup; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotManager; +import com.intellectualcrafters.plot.object.PlotSelection; +import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.util.PlayerFunctions; +import com.intellectualcrafters.plot.util.PlotHelper; /** * Player Events involving plots @@ -80,7 +107,8 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi if (Settings.TELEPORT_ON_LOGIN) { event.getPlayer().teleport(PlotHelper.getPlotHomeDefault(getPlot(event.getPlayer()))); PlayerFunctions.sendMessage(event.getPlayer(), C.TELEPORTED_TO_ROAD); - } else { + } + else { plotEntry(event.getPlayer(), getCurrentPlot(event.getPlayer().getLocation())); } } @@ -106,12 +134,14 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi return; } plotEntry(player, plot); - } else if (leftPlot(f, q)) { + } + else if (leftPlot(f, q)) { final Plot plot = getCurrentPlot(event.getFrom()); plotExit(player, plot); } } - } catch (final Exception e) { + } + catch (final Exception e) { // Gotta catch 'em all. } } @@ -181,7 +211,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public static void onPeskyMobsChangeTheWorldLikeWTFEvent( // LOL! - final EntityChangeBlockEvent event) { + final EntityChangeBlockEvent event) { final World world = event.getBlock().getWorld(); if (!isPlotWorld(world)) { return; @@ -191,20 +221,23 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi if (!(e instanceof org.bukkit.entity.FallingBlock)) { event.setCancelled(true); } - } else { + } + else { final Block b = event.getBlock(); final Player p = (Player) e; if (!isInPlot(b.getLocation())) { if (!PlotMain.hasPermission(p, "plots.admin")) { event.setCancelled(true); } - } else { + } + else { final Plot plot = getCurrentPlot(b.getLocation()); if (plot == null) { if (!PlotMain.hasPermission(p, "plots.admin")) { event.setCancelled(true); } - } else if (!plot.hasRights(p)) { + } + else if (!plot.hasRights(p)) { if (!PlotMain.hasPermission(p, "plots.admin")) { event.setCancelled(true); } @@ -287,58 +320,58 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public static void onBlockPistonExtend(final BlockPistonExtendEvent e) { if (isInPlot(e.getBlock().getLocation())) { - for (Block block : e.getBlocks()) { + for (final Block block : e.getBlocks()) { if (!isInPlot(block.getLocation())) { e.setCancelled(true); } } } - /*if (isInPlot(e.getBlock().getLocation())) { - - e.getDirection(); - final int modifier = e.getBlocks().size(); - Location l = e.getBlock().getLocation(); - { - if (e.getDirection() == BlockFace.EAST) { - l = e.getBlock().getLocation().subtract(modifier, 0, 0); - } else if (e.getDirection() == BlockFace.NORTH) { - l = e.getBlock().getLocation().subtract(0, 0, modifier); - } else if (e.getDirection() == BlockFace.SOUTH) { - l = e.getBlock().getLocation().add(0, 0, modifier); - } else if (e.getDirection() == BlockFace.WEST) { - l = e.getBlock().getLocation().add(modifier, 0, 0); - } - - if (!isInPlot(l)) { - e.setCancelled(true); - return; - } - } - for (final Block b : e.getBlocks()) { - if (!isInPlot(b.getLocation())) { - return; - } - { - if (e.getDirection() == BlockFace.EAST) { - if (!isInPlot(b.getLocation().subtract(1, 0, 0))) { - e.setCancelled(true); - } - } else if (e.getDirection() == BlockFace.NORTH) { - if (!isInPlot(b.getLocation().subtract(0, 0, 1))) { - e.setCancelled(true); - } - } else if (e.getDirection() == BlockFace.SOUTH) { - if (!isInPlot(b.getLocation().add(0, 0, 1))) { - e.setCancelled(true); - } - } else if (e.getDirection() == BlockFace.WEST) { - if (!isInPlot(b.getLocation().add(1, 0, 0))) { - e.setCancelled(true); - } - } - } - } - }*/ + /* + * if (isInPlot(e.getBlock().getLocation())) { + * e.getDirection(); + * final int modifier = e.getBlocks().size(); + * Location l = e.getBlock().getLocation(); + * { + * if (e.getDirection() == BlockFace.EAST) { + * l = e.getBlock().getLocation().subtract(modifier, 0, 0); + * } else if (e.getDirection() == BlockFace.NORTH) { + * l = e.getBlock().getLocation().subtract(0, 0, modifier); + * } else if (e.getDirection() == BlockFace.SOUTH) { + * l = e.getBlock().getLocation().add(0, 0, modifier); + * } else if (e.getDirection() == BlockFace.WEST) { + * l = e.getBlock().getLocation().add(modifier, 0, 0); + * } + * if (!isInPlot(l)) { + * e.setCancelled(true); + * return; + * } + * } + * for (final Block b : e.getBlocks()) { + * if (!isInPlot(b.getLocation())) { + * return; + * } + * { + * if (e.getDirection() == BlockFace.EAST) { + * if (!isInPlot(b.getLocation().subtract(1, 0, 0))) { + * e.setCancelled(true); + * } + * } else if (e.getDirection() == BlockFace.NORTH) { + * if (!isInPlot(b.getLocation().subtract(0, 0, 1))) { + * e.setCancelled(true); + * } + * } else if (e.getDirection() == BlockFace.SOUTH) { + * if (!isInPlot(b.getLocation().add(0, 0, 1))) { + * e.setCancelled(true); + * } + * } else if (e.getDirection() == BlockFace.WEST) { + * if (!isInPlot(b.getLocation().add(1, 0, 0))) { + * e.setCancelled(true); + * } + * } + * } + * } + * } + */ } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @@ -419,9 +452,11 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi final CreatureSpawnEvent.SpawnReason reason = event.getSpawnReason(); if ((reason == CreatureSpawnEvent.SpawnReason.SPAWNER_EGG) && pW.SPAWN_EGGS) { return; - } else if ((reason == CreatureSpawnEvent.SpawnReason.BREEDING) && pW.SPAWN_BREEDING) { + } + else if ((reason == CreatureSpawnEvent.SpawnReason.BREEDING) && pW.SPAWN_BREEDING) { return; - } else if ((reason == CreatureSpawnEvent.SpawnReason.CUSTOM) && pW.SPAWN_CUSTOM) { + } + else if ((reason == CreatureSpawnEvent.SpawnReason.CUSTOM) && pW.SPAWN_CUSTOM) { return; } if (event.getEntity() instanceof Player) { @@ -438,11 +473,14 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi if (e.getBlock() != null) { world = e.getBlock().getWorld(); - } else if (e.getIgnitingEntity() != null) { + } + else if (e.getIgnitingEntity() != null) { world = e.getIgnitingEntity().getWorld(); - } else if (e.getPlayer() != null) { + } + else if (e.getPlayer() != null) { world = e.getPlayer().getWorld(); - } else { + } + else { return; } @@ -461,19 +499,22 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi if (!PlotMain.hasPermission(p, "plots.admin")) { e.setCancelled(true); } - } else { + } + else { final Plot plot = getCurrentPlot(b.getLocation()); if (plot == null) { if (!PlotMain.hasPermission(p, "plots.admin")) { e.setCancelled(true); } - } else if (!plot.hasRights(p)) { + } + else if (!plot.hasRights(p)) { if (!PlotMain.hasPermission(p, "plots.admin")) { e.setCancelled(true); } } } - } else { + } + else { e.setCancelled(true); } } @@ -491,12 +532,14 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi if (plot.deny_entry(event.getPlayer())) { PlayerFunctions.sendMessage(event.getPlayer(), C.YOU_BE_DENIED); event.setCancelled(true); - } else { + } + else { if (enteredPlot(f, t)) { plotEntry(event.getPlayer(), plot); } } - } else { + } + else { if (leftPlot(f, t)) { final Plot plot = getCurrentPlot(event.getFrom()); plotExit(event.getPlayer(), plot); @@ -517,12 +560,14 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi if (!isInPlot(b.getLocation())) { PlayerFunctions.sendMessage(e.getPlayer(), C.NO_PLOT_PERMS); e.setCancelled(true); - } else { + } + else { final Plot plot = getCurrentPlot(b.getLocation()); if (plot == null) { PlayerFunctions.sendMessage(e.getPlayer(), C.NO_PLOT_PERMS); e.setCancelled(true); - } else if (!plot.hasRights(e.getPlayer())) { + } + else if (!plot.hasRights(e.getPlayer())) { PlayerFunctions.sendMessage(e.getPlayer(), C.NO_PLOT_PERMS); e.setCancelled(true); } @@ -565,12 +610,14 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi if (!isInPlot(b.getLocation())) { PlayerFunctions.sendMessage(e.getPlayer(), C.NO_PLOT_PERMS); e.setCancelled(true); - } else { + } + else { final Plot plot = getCurrentPlot(b.getLocation()); if (plot == null) { PlayerFunctions.sendMessage(e.getPlayer(), C.NO_PLOT_PERMS); e.setCancelled(true); - } else if (!plot.hasRights(e.getPlayer())) { + } + else if (!plot.hasRights(e.getPlayer())) { PlayerFunctions.sendMessage(e.getPlayer(), C.NO_PLOT_PERMS); e.setCancelled(true); } @@ -589,14 +636,16 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setCancelled(true); } - } else { + } + else { final Plot plot = getCurrentPlot(b.getLocation()); if (plot == null) { if (!PlotMain.hasPermission(p, "plots.admin")) { PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setCancelled(true); } - } else if (!plot.hasRights(p)) { + } + else if (!plot.hasRights(p)) { if (!PlotMain.hasPermission(p, "plots.admin")) { PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setCancelled(true); @@ -618,14 +667,16 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setCancelled(true); } - } else { + } + else { final Plot plot = getCurrentPlot(l); if (plot == null) { if (!PlotMain.hasPermission(p, "plots.admin")) { PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setCancelled(true); } - } else if (!plot.hasRights(p)) { + } + else if (!plot.hasRights(p)) { if (!PlotMain.hasPermission(p, "plots.admin")) { PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setCancelled(true); @@ -646,14 +697,16 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setCancelled(true); } - } else { + } + else { final Plot plot = getCurrentPlot(l); if (plot == null) { if (!PlotMain.hasPermission(p, "plots.admin")) { PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setCancelled(true); } - } else if (!plot.hasRights(p)) { + } + else if (!plot.hasRights(p)) { if (!PlotMain.hasPermission(p, "plots.admin")) { PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setCancelled(true); @@ -675,7 +728,8 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi final PlotWorld pW = getPlotWorld(l.getWorld()); if (!aPlr && pW.PVE && (!(a instanceof ItemFrame))) { return; - } else if (aPlr && pW.PVP) { + } + else if (aPlr && pW.PVP) { return; } if (!isInPlot(l)) { @@ -683,7 +737,8 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setCancelled(true); } - } else { + } + else { final Plot plot = getCurrentPlot(l); if (plot == null) { if (!PlotMain.hasPermission(p, "plots.admin")) { @@ -691,7 +746,8 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi e.setCancelled(true); return; } - } else if (aPlr && !booleanFlag(plot, "pvp")) { + } + else if (aPlr && !booleanFlag(plot, "pvp")) { return; } if (!aPlr && !booleanFlag(plot, "pve")) { @@ -719,14 +775,16 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setHatching(false); } - } else { + } + else { final Plot plot = getCurrentPlot(l); if (plot == null) { if (!PlotMain.hasPermission(p, "plots.admin")) { PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setHatching(false); } - } else if (!plot.hasRights(p)) { + } + else if (!plot.hasRights(p)) { if (!PlotMain.hasPermission(p, "plots.admin")) { PlayerFunctions.sendMessage(p, C.NO_PLOT_PERMS); e.setHatching(false); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotListener.java index 2553e3740..ff1e0fbd3 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotListener.java @@ -21,30 +21,40 @@ package com.intellectualcrafters.plot.listeners; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.WeatherType; +import org.bukkit.World; +import org.bukkit.block.Biome; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.events.PlayerEnterPlotEvent; import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent; import com.intellectualcrafters.plot.flag.FlagManager; -import com.intellectualcrafters.plot.object.*; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotManager; +import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.object.Title; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.UUIDHandler; -import org.bukkit.*; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.UUID; /** * @author Citymonstret * @author Empire92 */ -@SuppressWarnings({"unused", "deprecation"}) +@SuppressWarnings({ "unused", "deprecation" }) public class PlotListener { public static void textures(final Player p) { @@ -94,14 +104,14 @@ public class PlotListener { public static boolean enteredPlot(final Location l1, final Location l2) { final PlotId p1 = PlayerFunctions.getPlot(new Location(l1.getWorld(), l1.getBlockX(), 64, l1.getBlockZ())); final PlotId p2 = PlayerFunctions.getPlot(new Location(l2.getWorld(), l2.getBlockX(), 64, l2.getBlockZ())); - return p2 != null && (p1 == null || !p1.equals(p2)); + return (p2 != null) && ((p1 == null) || !p1.equals(p2)); } public static boolean leftPlot(final Location l1, final Location l2) { final PlotId p1 = PlayerFunctions.getPlot(new Location(l1.getWorld(), l1.getBlockX(), 64, l1.getBlockZ())); final PlotId p2 = PlayerFunctions.getPlot(new Location(l2.getWorld(), l2.getBlockX(), 64, l2.getBlockZ())); - return p1 != null && (p2 == null || !p1.equals(p2)); + return (p1 != null) && ((p2 == null) || !p1.equals(p2)); } public static boolean isPlotWorld(final Location l) { @@ -128,7 +138,8 @@ public class PlotListener { str = str.toLowerCase(); if (str.equals("rain")) { return WeatherType.DOWNFALL; - } else { + } + else { return WeatherType.CLEAR; } } @@ -179,7 +190,8 @@ public class PlotListener { try { final Long time = Long.parseLong(plot.settings.getFlag("time").getValue()); player.setPlayerTime(time, true); - } catch (final Exception e) { + } + catch (final Exception e) { plot.settings.setFlags(FlagManager.removeFlag(plot.settings.getFlags(), "time")); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java index 970c19e35..fc5cc82ea 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java @@ -21,14 +21,18 @@ package com.intellectualcrafters.plot.listeners; -import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.events.PlayerEnterPlotEvent; -import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent; -import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.util.PlayerFunctions; -import com.intellectualcrafters.plot.util.UUIDHandler; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Effect; +import org.bukkit.GameMode; +import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -42,14 +46,19 @@ import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; -import java.util.*; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.events.PlayerEnterPlotEvent; +import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.util.PlayerFunctions; +import com.intellectualcrafters.plot.util.UUIDHandler; /** * Created 2014-10-30 for PlotSquared * * @author Citymonstret */ -@SuppressWarnings({"deprecation", "unused"}) +@SuppressWarnings({ "deprecation", "unused" }) public class PlotPlusListener extends PlotListener implements Listener { private final static HashMap feedRunnable = new HashMap<>(); @@ -177,7 +186,7 @@ public class PlotPlusListener extends PlotListener implements Listener { } if (booleanFlag(plot, "notify-enter")) { if (plot.hasOwner()) { - + final Player player = UUIDHandler.uuidWrapper.getPlayer(plot.getOwner()); if (player == null) { return; @@ -235,7 +244,7 @@ public class PlotPlusListener extends PlotListener implements Listener { public final int interval; public final int amount; public final int max; - public int count = 0; + public int count = 0; public Interval(final int interval, final int amount, final int max) { this.interval = interval; @@ -258,8 +267,8 @@ public class PlotPlusListener extends PlotListener implements Listener { } } - private final String name; - private final Material material; + private final String name; + private final Material material; public RecordMeta(final String name, final Material material) { this.name = name; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEditListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEditListener.java index 7d4fe3945..4b57f93e8 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEditListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEditListener.java @@ -21,6 +21,25 @@ package com.intellectualcrafters.plot.listeners; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerPortalEvent; +import org.bukkit.event.player.PlayerTeleportEvent; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; @@ -36,23 +55,6 @@ import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.bukkit.selections.Selection; import com.sk89q.worldedit.function.mask.Mask; -import com.sk89q.worldedit.regions.CuboidRegion; -import com.sk89q.worldedit.world.World; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.player.*; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; /** * @author Citymonstret @@ -61,9 +63,9 @@ import java.util.Set; @SuppressWarnings("unused") public class WorldEditListener implements Listener { - final List monitored = Arrays.asList(new String[] { "set", "replace", "overlay", "walls", "outline", "deform", "hollow", "smooth", "move", "stack", "naturalize", "paste", "count", "regen", "copy", "cut", "" }); - - public final Set blockedcmds = new HashSet<>(Arrays.asList("/gmask", "//gmask", "/worldedit:gmask")); + final List monitored = Arrays.asList(new String[] { "set", "replace", "overlay", "walls", "outline", "deform", "hollow", "smooth", "move", "stack", "naturalize", "paste", "count", "regen", "copy", "cut", "" }); + + public final Set blockedcmds = new HashSet<>(Arrays.asList("/gmask", "//gmask", "/worldedit:gmask")); public final Set restrictedcmds = new HashSet<>(Arrays.asList("/up", "//up", "/worldedit:up")); private boolean isPlotWorld(final Location l) { @@ -131,14 +133,15 @@ public class WorldEditListener implements Listener { e.setCancelled(true); } return; - } else if (this.blockedcmds.contains(cmd)) { + } + else if (this.blockedcmds.contains(cmd)) { e.setCancelled(true); return; } if (!Settings.REQUIRE_SELECTION) { return; } - for (final String c : monitored) { + for (final String c : this.monitored) { if (cmd.equals("//" + c) || cmd.equals("/" + c) || cmd.equals("/worldedit:/" + c)) { final Selection selection = PlotMain.worldEdit.getSelection(p); if (selection == null) { @@ -146,16 +149,16 @@ public class WorldEditListener implements Listener { } final BlockVector pos1 = selection.getNativeMinimumPoint().toBlockVector(); final BlockVector pos2 = selection.getNativeMaximumPoint().toBlockVector(); - - LocalSession session = PlotMain.worldEdit.getSession(p); - Mask mask = session.getMask(); + + final LocalSession session = PlotMain.worldEdit.getSession(p); + final Mask mask = session.getMask(); if (mask == null) { PlayerFunctions.sendMessage(p, C.REQUIRE_SELECTION_IN_MASK, "Both points"); return; } if (!mask.test(pos1)) { e.setCancelled(true); - PlayerFunctions.sendMessage(p, C.REQUIRE_SELECTION_IN_MASK, "Position 1"); + PlayerFunctions.sendMessage(p, C.REQUIRE_SELECTION_IN_MASK, "Position 1"); } if (!mask.test(pos2)) { e.setCancelled(true); @@ -163,7 +166,7 @@ public class WorldEditListener implements Listener { } } } - + } @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @@ -175,7 +178,8 @@ public class WorldEditListener implements Listener { final Location l = p.getLocation(); if (isPlotWorld(l)) { PWE.setMask(p, l); - } else { + } + else { PWE.removeMask(p); } } @@ -234,7 +238,8 @@ public class WorldEditListener implements Listener { if (!isPlotWorld(q)) { if (isPlotWorld(f)) { PWE.removeMask(p); - } else { + } + else { return; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldGuardListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldGuardListener.java index 0c8d61e7e..6bb1559a5 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldGuardListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldGuardListener.java @@ -21,6 +21,19 @@ package com.intellectualcrafters.plot.listeners; +import java.util.ArrayList; +import java.util.Map; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.permissions.PermissionAttachment; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent; import com.intellectualcrafters.plot.events.PlotDeleteEvent; @@ -37,19 +50,6 @@ import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.permissions.PermissionAttachment; -import org.bukkit.plugin.java.JavaPlugin; - -import java.util.ArrayList; -import java.util.Map; -import java.util.UUID; /** * Created 2014-09-24 for PlotSquared @@ -58,13 +58,13 @@ import java.util.UUID; * @author Empire92 */ public class WorldGuardListener implements Listener { - public final ArrayList str_flags; + public final ArrayList str_flags; public final ArrayList> flags; public WorldGuardListener(final PlotMain plugin) { plugin.getServer().getPluginManager().registerEvents(this, plugin); - str_flags = new ArrayList<>(); - flags = new ArrayList<>(); + this.str_flags = new ArrayList<>(); + this.flags = new ArrayList<>(); for (final Flag flag : DefaultFlag.getFlags()) { this.str_flags.add(flag.getName()); this.flags.add(flag); @@ -87,10 +87,12 @@ public class WorldGuardListener implements Listener { manager.getRegion(plot.id.x + "-" + plot.id.y); requester.performCommand("region setowner " + (plot.id.x + "-" + plot.id.y) + " " + UUIDHandler.getName(owner)); requester.performCommand("region removeowner " + (plot.id.x + "-" + plot.id.y) + " " + UUIDHandler.getName(plot.getOwner())); - } catch (final Exception e) { + } + catch (final Exception e) { // requester.setOp(op); - } finally { + } + finally { add.remove(); remove.remove(); } @@ -107,9 +109,11 @@ public class WorldGuardListener implements Listener { requester.performCommand("region flag " + (plot.id.x + "-" + plot.id.y) + " " + key); } } - } catch (final Exception e) { + } + catch (final Exception e) { requester.setOp(op); - } finally { + } + finally { requester.setOp(op); } } @@ -125,9 +129,11 @@ public class WorldGuardListener implements Listener { requester.performCommand("region flag " + (plot.id.x + "-" + plot.id.y) + " " + key + " " + value); } } - } catch (final Exception e) { + } + catch (final Exception e) { requester.setOp(op); - } finally { + } + finally { requester.setOp(op); } } @@ -199,7 +205,8 @@ public class WorldGuardListener implements Listener { manager.addRegion(rg); } - } catch (final Exception e) { + } + catch (final Exception e) { // } } @@ -226,7 +233,8 @@ public class WorldGuardListener implements Listener { region.setOwners(owner); manager.addRegion(region); - } catch (final Exception e) { + } + catch (final Exception e) { // } } @@ -240,7 +248,8 @@ public class WorldGuardListener implements Listener { final RegionManager manager = PlotMain.worldGuard.getRegionManager(world); manager.removeRegion(plot.x + "-" + plot.y); - } catch (final Exception e) { + } + catch (final Exception e) { // } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BlockWrapper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BlockWrapper.java index 1e0055842..531923332 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BlockWrapper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BlockWrapper.java @@ -21,10 +21,11 @@ package com.intellectualcrafters.plot.object; -import com.sun.istack.internal.NotNull; import org.bukkit.World; import org.bukkit.block.Block; +import com.sun.istack.internal.NotNull; + /** * Wrapper class for blocks, using * pure data rather than the object. @@ -39,22 +40,22 @@ public class BlockWrapper { /** * X Coordinate */ - public final int x; + public final int x; /** * Y Coordinate */ - public final int y; + public final int y; /** * Z Coordinate */ - public final int z; + public final int z; /** * Block ID */ - public final int id; + public final int id; /** * Block Data Value @@ -64,11 +65,16 @@ public class BlockWrapper { /** * Constructor * - * @param x X Loc Value - * @param y Y Loc Value - * @param z Z Loc Value - * @param id Material ID - * @param data Data Value + * @param x + * X Loc Value + * @param y + * Y Loc Value + * @param z + * Z Loc Value + * @param id + * Material ID + * @param data + * Data Value */ public BlockWrapper(final int x, final int y, final int z, final short id, final byte data) { this.x = x; @@ -82,9 +88,10 @@ public class BlockWrapper { * Alternative Constructor * Uses block data, rather than typed data * - * @param block Block from which we get the data + * @param block + * Block from which we get the data */ - @SuppressWarnings({"deprecation", "unused"}) + @SuppressWarnings({ "deprecation", "unused" }) public BlockWrapper(@NotNull final Block block) { this.x = block.getX(); this.y = block.getY(); @@ -96,13 +103,14 @@ public class BlockWrapper { /** * Get a block based on the block wrapper * - * @param world World in which the block is/will be, located + * @param world + * World in which the block is/will be, located * @return block created/fetched from settings */ - @SuppressWarnings({"unused", "deprecation"}) + @SuppressWarnings({ "unused", "deprecation" }) public Block toBlock(@NotNull final World world) { - Block block = world.getBlockAt(x, y, z); - block.setTypeIdAndData(id, data, true); + final Block block = world.getBlockAt(this.x, this.y, this.z); + block.setTypeIdAndData(this.id, this.data, true); return block; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/InfoInventory.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/InfoInventory.java index 2874493ca..6834171d3 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/InfoInventory.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/InfoInventory.java @@ -1,6 +1,8 @@ package com.intellectualcrafters.plot.object; -import com.intellectualcrafters.plot.util.UUIDHandler; +import java.util.ArrayList; +import java.util.List; + import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -10,8 +12,7 @@ import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import java.util.ArrayList; -import java.util.List; +import com.intellectualcrafters.plot.util.UUIDHandler; /** * Created 2014-11-18 for PlotSquared @@ -20,14 +21,15 @@ import java.util.List; */ public class InfoInventory implements InventoryHolder { - private final Plot plot; + private final Plot plot; private final Inventory inventory; - private final Player player; + private final Player player; /** * Constructor * - * @param plot from which we take information + * @param plot + * from which we take information */ public InfoInventory(final Plot plot, final Player player) { this.plot = plot; @@ -37,60 +39,37 @@ public class InfoInventory implements InventoryHolder { @Override public Inventory getInventory() { - return inventory; + return this.inventory; } public InfoInventory build() { - ItemStack generalInfo = - getItem(Material.EMERALD, "&cPlot Info", - "&cID: &6" + plot.getId().toString(), - "&cOwner: &6" + UUIDHandler.getName(plot.getOwner()), - "&cAlias: &6" + plot.settings.getAlias(), - "&cBiome: &6" + plot.settings.getBiome().toString().replaceAll("_", "").toLowerCase(), - "&cCan Build: &6" + plot.hasRights(player), - "&cIs Denied: &6" + plot.deny_entry(player) - ); - ItemStack helpers = - getItem(Material.EMERALD, "&cHelpers", - "&cAmount: &6" + plot.helpers.size(), - "&8Click to view a list of the plot helpers" - ); - ItemStack trusted = - getItem(Material.EMERALD, "&cTrusted", - "&cAmount: &6" + plot.trusted.size(), - "&8Click to view a list of trusted players" - ); - ItemStack denied = - getItem(Material.EMERALD, "&cDenied", - "&cAmount: &6" + plot.denied.size(), - "&8Click to view a list of denied players" - ); - ItemStack flags = - getItem(Material.EMERALD, "&cFlags", - "&cAmount: &6" + plot.settings.getFlags().size(), - "&8Click to view a list of plot flags" - ); - inventory.setItem(2, generalInfo); - inventory.setItem(3, helpers); - inventory.setItem(4, trusted); - inventory.setItem(5, denied); - inventory.setItem(6, flags); + final ItemStack generalInfo = getItem(Material.EMERALD, "&cPlot Info", "&cID: &6" + this.plot.getId().toString(), "&cOwner: &6" + UUIDHandler.getName(this.plot.getOwner()), "&cAlias: &6" + this.plot.settings.getAlias(), "&cBiome: &6" + this.plot.settings.getBiome().toString().replaceAll("_", "").toLowerCase(), "&cCan Build: &6" + this.plot.hasRights(this.player), "&cIs Denied: &6" + this.plot.deny_entry(this.player)); + final ItemStack helpers = getItem(Material.EMERALD, "&cHelpers", "&cAmount: &6" + this.plot.helpers.size(), "&8Click to view a list of the plot helpers"); + final ItemStack trusted = getItem(Material.EMERALD, "&cTrusted", "&cAmount: &6" + this.plot.trusted.size(), "&8Click to view a list of trusted players"); + final ItemStack denied = getItem(Material.EMERALD, "&cDenied", "&cAmount: &6" + this.plot.denied.size(), "&8Click to view a list of denied players"); + final ItemStack flags = getItem(Material.EMERALD, "&cFlags", "&cAmount: &6" + this.plot.settings.getFlags().size(), "&8Click to view a list of plot flags"); + this.inventory.setItem(2, generalInfo); + this.inventory.setItem(3, helpers); + this.inventory.setItem(4, trusted); + this.inventory.setItem(5, denied); + this.inventory.setItem(6, flags); return this; } public InfoInventory display() { - player.closeInventory(); - player.openInventory(inventory); + this.player.closeInventory(); + this.player.openInventory(this.inventory); return this; } - private ItemStack getItem(Material material, String name, String... lore) { - ItemStack stack = new ItemStack(material); - ItemMeta meta = stack.getItemMeta(); + private ItemStack getItem(final Material material, final String name, final String... lore) { + final ItemStack stack = new ItemStack(material); + final ItemMeta meta = stack.getItemMeta(); meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); - List lList = new ArrayList<>(); - for (String l : lore) + final List lList = new ArrayList<>(); + for (final String l : lore) { lList.add(ChatColor.translateAlternateColorCodes('&', l)); + } meta.setLore(lList); stack.setItemMeta(meta); return stack; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java index 3afc1fd54..cfe1cd895 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -21,19 +21,19 @@ package com.intellectualcrafters.plot.object; -import com.intellectualcrafters.plot.PlotMain; -import com.intellectualcrafters.plot.database.DBFunc; -import com.intellectualcrafters.plot.flag.Flag; -import com.intellectualcrafters.plot.util.PlotHelper; -import com.intellectualcrafters.plot.util.UUIDHandler; +import java.util.ArrayList; +import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.UUID; +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.flag.Flag; +import com.intellectualcrafters.plot.util.PlotHelper; +import com.intellectualcrafters.plot.util.UUIDHandler; /** * The plot class @@ -47,19 +47,19 @@ public class Plot implements Cloneable { /** * plot ID */ - public final PlotId id; + public final PlotId id; /** * plot world */ - public final String world; + public final String world; /** * plot owner */ - public UUID owner; + public UUID owner; /** * Deny Entry */ - public boolean deny_entry; + public boolean deny_entry; /** * List of helpers (with plot permissions) */ @@ -75,16 +75,16 @@ public class Plot implements Cloneable { /** * External settings class */ - public PlotSettings settings; + public PlotSettings settings; /** * Delete on next save cycle? */ - public boolean delete; + public boolean delete; /** * Has the plot changed since the last save cycle? */ - public boolean hasChanged = false; - public boolean countsTowardsMax = true; + public boolean hasChanged = false; + public boolean countsTowardsMax = true; /** * Primary constructor @@ -163,7 +163,8 @@ public class Plot implements Cloneable { this.delete = false; if (flags != null) { this.settings.setFlags(flags); - } else { + } + else { this.settings.setFlags(new Flag[0]); } this.world = world; @@ -192,7 +193,8 @@ public class Plot implements Cloneable { this.delete = false; if (flags != null) { this.settings.setFlags(flags); - } else { + } + else { this.settings.setFlags(new Flag[0]); } this.world = world; @@ -264,9 +266,9 @@ public class Plot implements Cloneable { */ @Override public Object clone() throws CloneNotSupportedException { - Plot p = (Plot) super.clone(); - if (!p.equals(this) || p != this) { - return new Plot(id, owner, helpers, trusted, denied, settings.getAlias(), settings.getPosition(), settings.getFlags().toArray(new Flag[settings.getFlags().size()]), getWorld().getName(), settings.getMerged()); + final Plot p = (Plot) super.clone(); + if (!p.equals(this) || (p != this)) { + return new Plot(this.id, this.owner, this.helpers, this.trusted, this.denied, this.settings.getAlias(), this.settings.getPosition(), this.settings.getFlags().toArray(new Flag[this.settings.getFlags().size()]), getWorld().getName(), this.settings.getMerged()); } return p; } @@ -340,9 +342,10 @@ public class Plot implements Cloneable { /** * Clear a plot * - * @param plr initiator + * @param plr + * initiator */ - public void clear(final Player plr, boolean isDelete) { + public void clear(final Player plr, final boolean isDelete) { PlotHelper.clear(plr, this, isDelete); } @@ -365,29 +368,32 @@ public class Plot implements Cloneable { * Get the plot hashcode * * @return integer. You can easily make this a character array
- * xI = c[0] - * x = c[1 -> xI...] - * yI = c[xI ... + 1] - * y = c[xI ... + 2 -> yI ...] + * xI = c[0] + * x = c[1 -> xI...] + * yI = c[xI ... + 1] + * y = c[xI ... + 2 -> yI ...] */ @Override public int hashCode() { - int x = id.x; - int y = id.y; + final int x = this.id.x; + final int y = this.id.y; if (x >= 0) { if (y >= 0) { - return x * x + 3 * x + 2 * x * y + y + y * y; - } else { - int y1 = -y; - return x * x + 3 * x + 2 * x * y1 + y1 + y1 * y1 + 1; + return (x * x) + (3 * x) + (2 * x * y) + y + (y * y); } - } else { - int x1 = -x; + else { + final int y1 = -y; + return (x * x) + (3 * x) + (2 * x * y1) + y1 + (y1 * y1) + 1; + } + } + else { + final int x1 = -x; if (y >= 0) { - return -(x1 * x1 + 3 * x1 + 2 * x1 * y + y + y * y); - } else { - int y1 = -y; - return -(x1 * x1 + 3 * x1 + 2 * x1 * y1 + y1 + y1 * y1 + 1); + return -((x1 * x1) + (3 * x1) + (2 * x1 * y) + y + (y * y)); + } + else { + final int y1 = -y; + return -((x1 * x1) + (3 * x1) + (2 * x1 * y1) + y1 + (y1 * y1) + 1); } } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotBlock.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotBlock.java index 849ff6493..4fd8a68e9 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotBlock.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotBlock.java @@ -26,15 +26,15 @@ package com.intellectualcrafters.plot.object; */ public class PlotBlock { public final short id; - public final byte data; + public final byte data; public PlotBlock(final short id, final byte data) { this.id = id; this.data = data; } - + @Override public String toString() { - return this.id+":"+this.data; + return this.id + ":" + this.data; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotComment.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotComment.java index 1472435bb..91026bbf0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotComment.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotComment.java @@ -26,7 +26,7 @@ package com.intellectualcrafters.plot.object; */ public class PlotComment { public final String comment; - public final int tier; + public final int tier; public final String senderName; public PlotComment(final String comment, final String senderName, final int tier) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java index 0d319045e..73935683e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java @@ -21,9 +21,10 @@ package com.intellectualcrafters.plot.object; -import com.intellectualcrafters.plot.PlotMain; import org.bukkit.generator.ChunkGenerator; +import com.intellectualcrafters.plot.PlotMain; + public abstract class PlotGenerator extends ChunkGenerator { public PlotGenerator(final String world) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotHomePosition.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotHomePosition.java index c344012cb..a880dd436 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotHomePosition.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotHomePosition.java @@ -29,7 +29,7 @@ public enum PlotHomePosition { DEFAULT("Default", 'd'); private final String string; - private final char ch; + private final char ch; PlotHomePosition(final String string, final char ch) { this.string = string; @@ -37,7 +37,7 @@ public enum PlotHomePosition { } public boolean isMatching(final String string) { - return (string.length() < 2) && (string.charAt(0) == this.ch) || string.equalsIgnoreCase(this.string); + return ((string.length() < 2) && (string.charAt(0) == this.ch)) || string.equalsIgnoreCase(this.string); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotId.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotId.java index 6dd13795e..39d5d6c56 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotId.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotId.java @@ -35,8 +35,10 @@ public class PlotId { /** * PlotId class (PlotId x,y values do not correspond to Block locations) * - * @param x The plot x coordinate - * @param y The plot y coordinate + * @param x + * The plot x coordinate + * @param y + * The plot y coordinate */ public PlotId(final int x, final int y) { this.x = x; @@ -46,18 +48,21 @@ public class PlotId { /** * Get a Plot Id based on a string * - * @param string to create id from + * @param string + * to create id from * @return null if the string is invalid */ public static PlotId fromString(final String string) { int x, y; - String[] parts = string.split(";"); - if (parts.length < 2) + final String[] parts = string.split(";"); + if (parts.length < 2) { return null; + } try { x = Integer.parseInt(parts[0]); y = Integer.parseInt(parts[1]); - } catch (Exception e) { + } + catch (final Exception e) { return null; } return new PlotId(x, y); @@ -85,20 +90,23 @@ public class PlotId { @Override public int hashCode() { - if (x >= 0) { - if (y >= 0) { - return x * x + 3 * x + 2 * x * y + y + y * y; - } else { - int y1 = -y; - return x * x + 3 * x + 2 * x * y1 + y1 + y1 * y1 + 1; + if (this.x >= 0) { + if (this.y >= 0) { + return (this.x * this.x) + (3 * this.x) + (2 * this.x * this.y) + this.y + (this.y * this.y); } - } else { - int x1 = -x; - if (y >= 0) { - return -(x1 * x1 + 3 * x1 + 2 * x1 * y + y + y * y); - } else { - int y1 = -y; - return -(x1 * x1 + 3 * x1 + 2 * x1 * y1 + y1 + y1 * y1 + 1); + else { + final int y1 = -this.y; + return (this.x * this.x) + (3 * this.x) + (2 * this.x * y1) + y1 + (y1 * y1) + 1; + } + } + else { + final int x1 = -this.x; + if (this.y >= 0) { + return -((x1 * x1) + (3 * x1) + (2 * x1 * this.y) + this.y + (this.y * this.y)); + } + else { + final int y1 = -this.y; + return -((x1 * x1) + (3 * x1) + (2 * x1 * y1) + y1 + (y1 * y1) + 1); } } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotManager.java index 323571256..ca0950efc 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotManager.java @@ -21,12 +21,12 @@ package com.intellectualcrafters.plot.object; +import java.util.ArrayList; + import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.Biome; -import java.util.ArrayList; - @SuppressWarnings("unused") public abstract class PlotManager { @@ -52,7 +52,7 @@ public abstract class PlotManager { */ public abstract boolean clearPlot(final World world, final Plot plot, boolean isDelete); - + public abstract Location getSignLoc(final World world, final PlotWorld plotworld, final Plot plot); /* diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotSelection.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotSelection.java index 72b407e6f..ff22b3dd5 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotSelection.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotSelection.java @@ -21,14 +21,15 @@ package com.intellectualcrafters.plot.object; -import com.intellectualcrafters.plot.util.PlotHelper; -import com.intellectualcrafters.plot.util.SetBlockFast; +import java.util.HashMap; + import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.block.Block; -import java.util.HashMap; +import com.intellectualcrafters.plot.util.PlotHelper; +import com.intellectualcrafters.plot.util.SetBlockFast; /** * Created 2014-10-12 for PlotSquared @@ -40,13 +41,13 @@ public class PlotSelection { public final static HashMap currentSelection = new HashMap<>(); - private final PlotBlock[] plotBlocks; + private final PlotBlock[] plotBlocks; - private final int width; + private final int width; - private final Plot plot; + private final Plot plot; - private final Biome biome; + private final Biome biome; public PlotSelection(final int width, final World world, final Plot plot) { this.width = width; @@ -100,17 +101,21 @@ public class PlotSelection { try { SetBlockFast.set(world, b1.x, b1.y, b1.z, b2.id, b2.data); SetBlockFast.set(world, b2.x, b2.y, b2.z, b1.id, b1.data); - } catch (final NoSuchMethodException e) { + } + catch (final NoSuchMethodException e) { PlotHelper.canSetFast = false; } - } else { + } + else { if ((b1.id != b2.id) && (b1.data != b2.data)) { block1.setTypeIdAndData(b2.id, b2.data, false); block2.setTypeIdAndData(b1.id, b1.data, false); - } else if (b1.id != b2.id) { + } + else if (b1.id != b2.id) { block1.setTypeId(b2.id); block2.setTypeId(b1.id); - } else { + } + else { block1.setData(b2.data); block2.setData(b1.data); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotSettings.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotSettings.java index 2edbe19ef..f9a46a09a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotSettings.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotSettings.java @@ -21,16 +21,17 @@ package com.intellectualcrafters.plot.object; -import com.intellectualcrafters.plot.flag.Flag; -import com.intellectualcrafters.plot.util.PlotHelper; -import com.sun.istack.internal.NotNull; -import org.bukkit.block.Biome; - import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.Set; +import org.bukkit.block.Biome; + +import com.intellectualcrafters.plot.flag.Flag; +import com.intellectualcrafters.plot.util.PlotHelper; +import com.sun.istack.internal.NotNull; + /** * plot settings * @@ -42,15 +43,15 @@ public class PlotSettings { /** * Plot */ - private final Plot plot; + private final Plot plot; /** * merged plots */ - private boolean[] merged = new boolean[]{false, false, false, false}; + private boolean[] merged = new boolean[] { false, false, false, false }; /** * plot alias */ - private String alias; + private String alias; /** * Comments */ @@ -58,16 +59,17 @@ public class PlotSettings { /** * Flags */ - private Set flags; + private Set flags; /** * Home Position */ - private PlotHomePosition position; + private PlotHomePosition position; /** * Constructor * - * @param plot object + * @param plot + * object */ public PlotSettings(final Plot plot) { this.alias = ""; @@ -81,7 +83,8 @@ public class PlotSettings { * 2 = South
* 3 = West
* - * @param direction Direction to check + * @param direction + * Direction to check * @return boolean merged */ public boolean getMerged(final int direction) { @@ -111,11 +114,12 @@ public class PlotSettings { * @return biome at plot loc */ public Biome getBiome() { - return PlotHelper.getPlotBottomLoc(plot.getWorld(), plot.getId()).add(1, 0, 1).getBlock().getBiome(); + return PlotHelper.getPlotBottomLoc(this.plot.getWorld(), this.plot.getId()).add(1, 0, 1).getBlock().getBiome(); } /** - * @param flag to add + * @param flag + * to add */ public void addFlag(final Flag flag) { final Flag hasFlag = getFlag(flag.getKey()); @@ -137,7 +141,8 @@ public class PlotSettings { /** * Set multiple flags * - * @param flags Flag Array + * @param flags + * Flag Array */ public void setFlags(@NotNull final Flag[] flags) { this.flags = new HashSet<>(Arrays.asList(flags)); @@ -146,7 +151,8 @@ public class PlotSettings { /** * Get a flag * - * @param flag Flag to get + * @param flag + * Flag to get * @return flag */ public Flag getFlag(final String flag) { @@ -173,14 +179,15 @@ public class PlotSettings { /** * 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; } public String getJoinMessage() { - Flag greeting = getFlag("greeting"); + final Flag greeting = getFlag("greeting"); if (greeting != null) { return greeting.getValue(); } @@ -193,7 +200,7 @@ public class PlotSettings { * @return Farewell flag */ public String getLeaveMessage() { - Flag farewell = getFlag("farewell"); + final Flag farewell = getFlag("farewell"); if (farewell != null) { return farewell.getValue(); } @@ -214,14 +221,14 @@ public class PlotSettings { this.comments = comments; } - public void removeComment(PlotComment comment) { + public void removeComment(final PlotComment comment) { if (this.comments.contains(comment)) { this.comments.remove(comment); } } - public void removeComments(ArrayList comments) { - for (PlotComment comment : comments) { + public void removeComments(final ArrayList comments) { + for (final PlotComment comment : comments) { removeComment(comment); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java index c232caf15..f2b9993d1 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java @@ -21,119 +21,267 @@ package com.intellectualcrafters.plot.object; -import com.intellectualcrafters.plot.config.Configuration; -import com.intellectualcrafters.plot.config.ConfigurationNode; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; import org.bukkit.Material; import org.bukkit.block.Biome; import org.bukkit.configuration.ConfigurationSection; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; +import com.intellectualcrafters.plot.config.Configuration; +import com.intellectualcrafters.plot.config.ConfigurationNode; /** * @author Jesse Boyd */ public abstract class PlotWorld { - public final static boolean AUTO_MERGE_DEFAULT = false; - public final static boolean MOB_SPAWNING_DEFAULT = false; - public final static Biome PLOT_BIOME_DEFAULT = Biome.FOREST; - public final static boolean PLOT_CHAT_DEFAULT = false; - public final static boolean SCHEMATIC_CLAIM_SPECIFY_DEFAULT = false; - public final static boolean SCHEMATIC_ON_CLAIM_DEFAULT = false; - public final static String SCHEMATIC_FILE_DEFAULT = "null"; - public final static List SCHEMATICS_DEFAULT = null; - public final static List DEFAULT_FLAGS_DEFAULT = Arrays.asList(); - public final static boolean USE_ECONOMY_DEFAULT = false; - public final static double PLOT_PRICE_DEFAULT = 100; - public final static double MERGE_PRICE_DEFAULT = 100; - public final static double SELL_PRICE_DEFAULT = 75; - public final static boolean PVP_DEFAULT = false; - public final static boolean PVE_DEFAULT = false; - public final static boolean SPAWN_EGGS_DEFAULT = false; - public final static boolean SPAWN_CUSTOM_DEFAULT = true; - public final static boolean SPAWN_BREEDING_DEFAULT = false; + public final static boolean AUTO_MERGE_DEFAULT = false; + public final static boolean MOB_SPAWNING_DEFAULT = false; + public final static Biome PLOT_BIOME_DEFAULT = Biome.FOREST; + public final static boolean PLOT_CHAT_DEFAULT = false; + public final static boolean SCHEMATIC_CLAIM_SPECIFY_DEFAULT = false; + public final static boolean SCHEMATIC_ON_CLAIM_DEFAULT = false; + public final static String SCHEMATIC_FILE_DEFAULT = "null"; + public final static List SCHEMATICS_DEFAULT = null; + public final static List DEFAULT_FLAGS_DEFAULT = Arrays.asList(); + public final static boolean USE_ECONOMY_DEFAULT = false; + public final static double PLOT_PRICE_DEFAULT = 100; + public final static double MERGE_PRICE_DEFAULT = 100; + public final static double SELL_PRICE_DEFAULT = 75; + public final static boolean PVP_DEFAULT = false; + public final static boolean PVE_DEFAULT = false; + public final static boolean SPAWN_EGGS_DEFAULT = false; + public final static boolean SPAWN_CUSTOM_DEFAULT = true; + public final static boolean SPAWN_BREEDING_DEFAULT = false; // TODO make this configurable // make non static and static_default_valu + add config option @SuppressWarnings("deprecation") - public static List BLOCKS; /*= new ArrayList<>( - Arrays.asList( - new Material[]{ - ACACIA_STAIRS, BEACON, - BEDROCK, BIRCH_WOOD_STAIRS, - BOOKSHELF, BREWING_STAND, - BRICK, BRICK_STAIRS, - BURNING_FURNACE, CAKE_BLOCK, - CAULDRON, CLAY_BRICK, - CLAY, COAL_BLOCK, - COAL_ORE, COBBLE_WALL, - COBBLESTONE, COBBLESTONE_STAIRS, - COMMAND, DARK_OAK_STAIRS, - DAYLIGHT_DETECTOR, DIAMOND_ORE, - DIAMOND_BLOCK, DIRT, - DISPENSER, DROPPER, - EMERALD_BLOCK, EMERALD_ORE, - ENCHANTMENT_TABLE, ENDER_PORTAL_FRAME, - ENDER_STONE, FURNACE, - GLOWSTONE, GOLD_ORE, - GOLD_BLOCK, GRASS, GRAVEL, GLASS, - HARD_CLAY, HAY_BLOCK, - HUGE_MUSHROOM_1, HUGE_MUSHROOM_2, - IRON_BLOCK, IRON_ORE, - JACK_O_LANTERN, JUKEBOX, - JUNGLE_WOOD_STAIRS, LAPIS_BLOCK, - LAPIS_ORE, LEAVES, - LEAVES_2, LOG, LOG_2, - MELON_BLOCK, MOB_SPAWNER, - MOSSY_COBBLESTONE, MYCEL, - NETHER_BRICK, NETHER_BRICK_STAIRS, - NETHERRACK, NOTE_BLOCK, - OBSIDIAN, PACKED_ICE, - PUMPKIN, QUARTZ_BLOCK, - QUARTZ_ORE, QUARTZ_STAIRS, - REDSTONE_BLOCK, SANDSTONE, - SAND, SANDSTONE_STAIRS, - SMOOTH_BRICK, SMOOTH_STAIRS, - SNOW_BLOCK, SOUL_SAND, - SPONGE, SPRUCE_WOOD_STAIRS, - STONE, WOOD, - WOOD_STAIRS, WORKBENCH, - WOOL, getMaterial(44), getMaterial(126) - } - ) - );*/ + public static List BLOCKS; /* + * = + * new + * ArrayList + * < + * > + * ( + * Arrays + * . + * asList + * ( + * new + * Material + * [ + * ] + * { + * ACACIA_STAIRS + * , + * BEACON + * , + * BEDROCK + * , + * BIRCH_WOOD_STAIRS + * , + * BOOKSHELF + * , + * BREWING_STAND + * , + * BRICK + * , + * BRICK_STAIRS + * , + * BURNING_FURNACE + * , + * CAKE_BLOCK + * , + * CAULDRON + * , + * CLAY_BRICK + * , + * CLAY + * , + * COAL_BLOCK + * , + * COAL_ORE + * , + * COBBLE_WALL + * , + * COBBLESTONE + * , + * COBBLESTONE_STAIRS + * , + * COMMAND + * , + * DARK_OAK_STAIRS + * , + * DAYLIGHT_DETECTOR + * , + * DIAMOND_ORE + * , + * DIAMOND_BLOCK + * , + * DIRT + * , + * DISPENSER + * , + * DROPPER + * , + * EMERALD_BLOCK + * , + * EMERALD_ORE + * , + * ENCHANTMENT_TABLE + * , + * ENDER_PORTAL_FRAME + * , + * ENDER_STONE + * , + * FURNACE + * , + * GLOWSTONE + * , + * GOLD_ORE + * , + * GOLD_BLOCK + * , + * GRASS + * , + * GRAVEL + * , + * GLASS + * , + * HARD_CLAY + * , + * HAY_BLOCK + * , + * HUGE_MUSHROOM_1 + * , + * HUGE_MUSHROOM_2 + * , + * IRON_BLOCK + * , + * IRON_ORE + * , + * JACK_O_LANTERN + * , + * JUKEBOX + * , + * JUNGLE_WOOD_STAIRS + * , + * LAPIS_BLOCK + * , + * LAPIS_ORE + * , + * LEAVES + * , + * LEAVES_2 + * , + * LOG + * , + * LOG_2 + * , + * MELON_BLOCK + * , + * MOB_SPAWNER + * , + * MOSSY_COBBLESTONE + * , + * MYCEL + * , + * NETHER_BRICK + * , + * NETHER_BRICK_STAIRS + * , + * NETHERRACK + * , + * NOTE_BLOCK + * , + * OBSIDIAN + * , + * PACKED_ICE + * , + * PUMPKIN + * , + * QUARTZ_BLOCK + * , + * QUARTZ_ORE + * , + * QUARTZ_STAIRS + * , + * REDSTONE_BLOCK + * , + * SANDSTONE + * , + * SAND + * , + * SANDSTONE_STAIRS + * , + * SMOOTH_BRICK + * , + * SMOOTH_STAIRS + * , + * SNOW_BLOCK + * , + * SOUL_SAND + * , + * SPONGE + * , + * SPRUCE_WOOD_STAIRS + * , + * STONE + * , + * WOOD + * , + * WOOD_STAIRS + * , + * WORKBENCH + * , + * WOOL + * , + * getMaterial + * ( + * 44 + * ) + * , + * getMaterial + * ( + * 126 + * ) + * } + * ) + * ) + * ; + */ static { // TODO: Let jesse decide if this is stupid or not BLOCKS = new ArrayList<>(); - for (Material material : Material.values()) { - if (material.isBlock() && material.isSolid() && !material.hasGravity() && !material.isTransparent() && material.isOccluding() && material!=Material.DROPPER) { + for (final Material material : Material.values()) { + if (material.isBlock() && material.isSolid() && !material.hasGravity() && !material.isTransparent() && material.isOccluding() && (material != Material.DROPPER)) { BLOCKS.add(material); } } } - public final String worldname; - public boolean AUTO_MERGE; - public boolean MOB_SPAWNING; - public Biome PLOT_BIOME; - public boolean PLOT_CHAT; - public boolean SCHEMATIC_CLAIM_SPECIFY = false; - public boolean SCHEMATIC_ON_CLAIM; - public String SCHEMATIC_FILE; - public List SCHEMATICS; - public List DEFAULT_FLAGS; - public boolean USE_ECONOMY; - public double PLOT_PRICE; - public double MERGE_PRICE; - public double SELL_PRICE; - public boolean PVP; - public boolean PVE; - public boolean SPAWN_EGGS; - public boolean SPAWN_CUSTOM; - public boolean SPAWN_BREEDING; + public final String worldname; + public boolean AUTO_MERGE; + public boolean MOB_SPAWNING; + public Biome PLOT_BIOME; + public boolean PLOT_CHAT; + public boolean SCHEMATIC_CLAIM_SPECIFY = false; + public boolean SCHEMATIC_ON_CLAIM; + public String SCHEMATIC_FILE; + public List SCHEMATICS; + public List DEFAULT_FLAGS; + public boolean USE_ECONOMY; + public double PLOT_PRICE; + public double MERGE_PRICE; + public double SELL_PRICE; + public boolean PVP; + public boolean PVE; + public boolean SPAWN_EGGS; + public boolean SPAWN_CUSTOM; + public boolean SPAWN_BREEDING; public PlotWorld(final String worldname) { this.worldname = worldname; @@ -142,7 +290,8 @@ public abstract class PlotWorld { /** * When a world is created, the following method will be called for each * - * @param config Configuration Section + * @param config + * Configuration Section */ public void loadDefaultConfiguration(final ConfigurationSection config) { this.MOB_SPAWNING = config.getBoolean("natural_mob_spawning"); @@ -171,7 +320,8 @@ public abstract class PlotWorld { /** * Saving core plotworld settings * - * @param config Configuration Section + * @param config + * Configuration Section */ public void saveConfiguration(final ConfigurationSection config) { final HashMap options = new HashMap<>(); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/StringWrapper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/StringWrapper.java index ccd9d9a0a..631190fee 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/StringWrapper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/StringWrapper.java @@ -32,7 +32,8 @@ public class StringWrapper { /** * Constructor * - * @param value to wrap + * @param value + * to wrap */ public StringWrapper(final String value) { this.value = value; @@ -41,7 +42,8 @@ public class StringWrapper { /** * Check if a wrapped string equals another one * - * @param obj to compare + * @param obj + * to compare * @return true if obj equals the stored value */ @Override diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Title.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Title.java index f3881123f..97562b6ec 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Title.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Title.java @@ -21,15 +21,15 @@ package com.intellectualcrafters.plot.object; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + /** * Minecraft 1.8 Title * @@ -45,27 +45,28 @@ public class Title { } /* Title packet */ - private Class packetTitle; + private Class packetTitle; /* Title packet actions ENUM */ - private Class packetActions; + private Class packetActions; /* Chat serializer */ - private Class nmsChatSerializer; + private Class nmsChatSerializer; /* Title text and color */ - private String title; - private ChatColor titleColor = ChatColor.WHITE; + private String title; + private ChatColor titleColor = ChatColor.WHITE; /* Subtitle text and color */ - private String subtitle = ""; - private ChatColor subtitleColor = ChatColor.WHITE; + private String subtitle = ""; + private ChatColor subtitleColor = ChatColor.WHITE; /* Title timings */ - private int fadeInTime = -1; - private int stayTime = -1; - private int fadeOutTime = -1; - private boolean ticks = false; + private int fadeInTime = -1; + private int stayTime = -1; + private int fadeOutTime = -1; + private boolean ticks = false; /** * Create a new 1.8 title * - * @param title Title + * @param title + * Title */ public Title(final String title) { this.title = title; @@ -75,8 +76,10 @@ public class Title { /** * Create a new 1.8 title * - * @param title Title text - * @param subtitle Subtitle text + * @param title + * Title text + * @param subtitle + * Subtitle text */ public Title(final String title, final String subtitle) { this.title = ""; @@ -88,11 +91,16 @@ public class Title { /** * Create a new 1.8 title * - * @param title Title text - * @param subtitle Subtitle text - * @param fadeInTime Fade in time - * @param stayTime Stay on screen time - * @param fadeOutTime Fade out time + * @param title + * Title text + * @param subtitle + * Subtitle text + * @param fadeInTime + * Fade in time + * @param stayTime + * Stay on screen time + * @param fadeOutTime + * Fade out time */ public Title(final String title, final String subtitle, final int fadeInTime, final int stayTime, final int fadeOutTime) { this.title = ""; @@ -128,7 +136,8 @@ public class Title { /** * Set the title color * - * @param color Chat color + * @param color + * Chat color */ public void setTitleColor(final ChatColor color) { this.titleColor = color; @@ -137,7 +146,8 @@ public class Title { /** * Set the subtitle color * - * @param color Chat color + * @param color + * Chat color */ public void setSubtitleColor(final ChatColor color) { this.subtitleColor = color; @@ -146,7 +156,8 @@ public class Title { /** * Set title fade in time * - * @param time Time + * @param time + * Time */ public void setFadeInTime(final int time) { this.fadeInTime = time; @@ -155,7 +166,8 @@ public class Title { /** * Set title fade out time * - * @param time Time + * @param time + * Time */ public void setFadeOutTime(final int time) { this.fadeOutTime = time; @@ -164,7 +176,8 @@ public class Title { /** * Set title stay time * - * @param time Time + * @param time + * Time */ public void setStayTime(final int time) { this.stayTime = time; @@ -187,7 +200,8 @@ public class Title { /** * Send the title to a player * - * @param player Player + * @param player + * Player */ public void send(final Player player) { if ((getProtocolVersion(player) >= 47) && isSpigot() && (this.packetTitle != null)) { @@ -215,7 +229,8 @@ public class Title { packet = this.packetTitle.getConstructor(this.packetActions, getNMSClass("IChatBaseComponent")).newInstance(actions[1], serialized); sendPacket.invoke(connection, packet); } - } catch (final Exception e) { + } + catch (final Exception e) { e.printStackTrace(); } } @@ -233,7 +248,8 @@ public class Title { /** * Clear the title * - * @param player Player + * @param player + * Player */ public void clearTitle(final Player player) { if ((getProtocolVersion(player) >= 47) && isSpigot()) { @@ -245,7 +261,8 @@ public class Title { final Method sendPacket = getMethod(connection.getClass(), "sendPacket"); final Object packet = this.packetTitle.getConstructor(this.packetActions).newInstance(actions[3]); sendPacket.invoke(connection, packet); - } catch (final Exception e) { + } + catch (final Exception e) { e.printStackTrace(); } } @@ -254,7 +271,8 @@ public class Title { /** * Reset the title settings * - * @param player Player + * @param player + * Player */ public void resetTitle(final Player player) { if ((getProtocolVersion(player) >= 47) && isSpigot()) { @@ -266,7 +284,8 @@ public class Title { final Method sendPacket = getMethod(connection.getClass(), "sendPacket"); final Object packet = this.packetTitle.getConstructor(this.packetActions).newInstance(actions[4]); sendPacket.invoke(connection, packet); - } catch (final Exception e) { + } + catch (final Exception e) { e.printStackTrace(); } } @@ -275,7 +294,8 @@ public class Title { /** * Get the protocol version of the player * - * @param player Player + * @param player + * Player * @return Protocol version */ private int getProtocolVersion(final Player player) { @@ -287,7 +307,8 @@ public class Title { version = (Integer) getMethod("getVersion", networkManager.getClass()).invoke(networkManager); return version; - } catch (final Exception ex) { + } + catch (final Exception ex) { // ex.printStackTrace(); <-- spammy console } return version; @@ -305,13 +326,15 @@ public class Title { /** * Get class by url * - * @param namespace Namespace url + * @param namespace + * Namespace url * @return Class */ private Class getClass(final String namespace) { try { return Class.forName(namespace); - } catch (final Exception e) { + } + catch (final Exception e) { return null; } } @@ -342,7 +365,8 @@ public class Title { private Object getHandle(final Object obj) { try { return getMethod("getHandle", obj.getClass()).invoke(obj); - } catch (final Exception e) { + } + catch (final Exception e) { e.printStackTrace(); return null; } @@ -369,7 +393,8 @@ public class Title { Class clazz = null; try { clazz = Class.forName(fullName); - } catch (final Exception e) { + } + catch (final Exception e) { e.printStackTrace(); } return clazz; @@ -380,7 +405,8 @@ public class Title { final Field field = clazz.getDeclaredField(name); field.setAccessible(true); return field; - } catch (final Exception e) { + } + catch (final Exception e) { e.printStackTrace(); return null; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/LSetCube.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/LSetCube.java index 8ae392e45..20054e709 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/LSetCube.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/LSetCube.java @@ -28,7 +28,7 @@ import org.bukkit.Location; * * @author Citymonstret */ -@SuppressWarnings({"javadoc", "unused"}) +@SuppressWarnings({ "javadoc", "unused" }) public class LSetCube { /** @@ -106,7 +106,7 @@ public class LSetCube { /** * */ - private Location current; + private Location current; /** * @param cube diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/Lag.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/Lag.java index 66751a9f7..62004a176 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/Lag.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/Lag.java @@ -31,16 +31,16 @@ public class Lag implements Runnable { /** * Ticks */ - public final static long[] T = new long[600]; + public final static long[] T = new long[600]; /** * Tick count */ - public static int TC = 0; + public static int TC = 0; /** * something :_: */ @SuppressWarnings("unused") - public static long LT = 0L; + public static long LT = 0L; /** * Get the server TPS @@ -54,7 +54,8 @@ public class Lag implements Runnable { /** * Return the tick per second (measured in $ticks) * - * @param ticks Ticks + * @param ticks + * Ticks * @return ticks per second */ public static double getTPS(final int ticks) { @@ -69,7 +70,8 @@ public class Lag implements Runnable { /** * Get number of ticks since * - * @param tI Ticks < + * @param tI + * Ticks < * @return number of ticks since $tI */ @SuppressWarnings("unused") diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/Logger.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/Logger.java index df2d8ea2d..3c0342e4f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/Logger.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/Logger.java @@ -21,13 +21,17 @@ package com.intellectualcrafters.plot.util; -import com.intellectualcrafters.plot.PlotMain; -import com.intellectualcrafters.plot.config.C; - -import java.io.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; import java.util.ArrayList; import java.util.Date; +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.config.C; + /** * Logging of errors and debug messages. * @@ -36,7 +40,7 @@ import java.util.Date; public class Logger { private static ArrayList entries; - private static File log; + private static File log; public static void setup(final File file) { log = file; @@ -48,7 +52,8 @@ public class Logger { entries.add(line); } reader.close(); - } catch (final IOException e) { + } + catch (final IOException e) { PlotMain.sendConsoleSenderMessage(C.PREFIX.s() + "File setup error Logger#setup"); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/Metrics.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/Metrics.java index d258f82ae..c186b965e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/Metrics.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/Metrics.java @@ -21,6 +21,27 @@ package com.intellectualcrafters.plot.util; +import java.io.BufferedReader; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; +import java.lang.reflect.InvocationTargetException; +import java.net.Proxy; +import java.net.URL; +import java.net.URLConnection; +import java.net.URLEncoder; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.Set; +import java.util.UUID; +import java.util.logging.Level; +import java.util.zip.GZIPOutputStream; + import org.bukkit.Bukkit; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; @@ -29,41 +50,31 @@ import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.scheduler.BukkitTask; -import java.io.*; -import java.lang.reflect.InvocationTargetException; -import java.net.Proxy; -import java.net.URL; -import java.net.URLConnection; -import java.net.URLEncoder; -import java.util.*; -import java.util.logging.Level; -import java.util.zip.GZIPOutputStream; - public class Metrics { /** * The current revision number */ - private final static int REVISION = 7; + private final static int REVISION = 7; /** * The base url of the metrics domain */ - private static final String BASE_URL = "http://report.mcstats.org"; + private static final String BASE_URL = "http://report.mcstats.org"; /** * The url used to report a server's status */ - private static final String REPORT_URL = "/plugin/%s"; + private static final String REPORT_URL = "/plugin/%s"; /** * Interval of time to ping (in minutes) */ - private static final int PING_INTERVAL = 15; + private static final int PING_INTERVAL = 15; /** * The plugin this metrics submits for */ - private final Plugin plugin; + private final Plugin plugin; /** * All of the custom graphs to submit to metrics */ - private final Set graphs = Collections.synchronizedSet(new HashSet()); + private final Set graphs = Collections.synchronizedSet(new HashSet()); /** * The plugin configuration file */ @@ -71,23 +82,23 @@ public class Metrics { /** * The plugin configuration file */ - private final File configurationFile; + private final File configurationFile; /** * Unique server id */ - private final String guid; + private final String guid; /** * Debug mode */ - private final boolean debug; + private final boolean debug; /** * Lock for synchronization */ - private final Object optOutLock = new Object(); + private final Object optOutLock = new Object(); /** * The scheduled task */ - private volatile BukkitTask task = null; + private volatile BukkitTask task = null; public Metrics(final Plugin plugin) throws IOException { if (plugin == null) { @@ -123,13 +134,16 @@ public class Metrics { try { gzos = new GZIPOutputStream(baos); gzos.write(input.getBytes("UTF-8")); - } catch (final IOException e) { + } + catch (final IOException e) { e.printStackTrace(); - } finally { + } + finally { if (gzos != null) { try { gzos.close(); - } catch (final IOException ignore) { + } + catch (final IOException ignore) { } } } @@ -151,7 +165,8 @@ public class Metrics { Double.parseDouble(value); isValueNumeric = true; } - } catch (final NumberFormatException e) { + } + catch (final NumberFormatException e) { isValueNumeric = false; } if (json.charAt(json.length() - 1) != '{') { @@ -161,7 +176,8 @@ public class Metrics { json.append(':'); if (isValueNumeric) { json.append(value); - } else { + } + else { json.append(escapeJSON(value)); } } @@ -199,7 +215,8 @@ public class Metrics { if (chr < ' ') { final String t = "000" + Integer.toHexString(chr); builder.append("\\u" + t.substring(t.length() - 4)); - } else { + } + else { builder.append(chr); } break; @@ -212,7 +229,8 @@ public class Metrics { /** * Encode text as UTF-8 * - * @param text the text to encode + * @param text + * the text to encode * @return the encoded text, as UTF-8 */ private static String urlEncode(final String text) throws UnsupportedEncodingException { @@ -224,9 +242,10 @@ public class Metrics { * plotters to their own graphs on the metrics website. Plotters can be * added to the graph object returned. * - * @param name The name of the graph + * @param name + * The name of the graph * @return Graph object created. Will never return NULL under normal - * circumstances unless bad parameters are given + * circumstances unless bad parameters are given */ public Graph createGraph(final String name) { if (name == null) { @@ -244,7 +263,8 @@ public class Metrics { * Add a Graph object to BukkitMetrics that represents data for the plugin * that should be sent to the backend * - * @param graph The name of the graph + * @param graph + * The name of the graph */ public void addGraph(final Graph graph) { if (graph == null) { @@ -308,7 +328,8 @@ public class Metrics { // false // Each post thereafter will be a ping this.firstPost = false; - } catch (final IOException e) { + } + catch (final IOException e) { if (Metrics.this.debug) { Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage()); } @@ -329,12 +350,14 @@ public class Metrics { try { // Reload the metrics file this.configuration.load(getConfigFile()); - } catch (final IOException ex) { + } + catch (final IOException ex) { if (this.debug) { Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); } return true; - } catch (final InvalidConfigurationException ex) { + } + catch (final InvalidConfigurationException ex) { if (this.debug) { Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); } @@ -428,10 +451,12 @@ public class Metrics { try { if (Bukkit.class.getMethod("getOnlinePlayers", new Class[0]).getReturnType() == Collection.class) { playersOnline = ((Collection) Bukkit.class.getMethod("getOnlinePlayers", new Class[0]).invoke(null, new Object[0])).size(); - } else { + } + else { playersOnline = ((Player[]) Bukkit.class.getMethod("getOnlinePlayers", new Class[0]).invoke(null, new Object[0])).length; } - } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) { + } + catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) { } // END server software specific section -- all code below does not use @@ -474,7 +499,7 @@ public class Metrics { json.append(':'); json.append('{'); boolean firstGraph = true; - for (Graph graph : this.graphs) { + for (final Graph graph : this.graphs) { final StringBuilder graphJson = new StringBuilder(); graphJson.append('{'); for (final Plotter plotter : graph.getPlotters()) { @@ -502,7 +527,8 @@ public class Metrics { // It does not reroute POST requests so we need to go around it if (isMineshafterPresent()) { connection = url.openConnection(Proxy.NO_PROXY); - } else { + } + else { connection = url.openConnection(); } final byte[] uncompressed = json.toString().getBytes(); @@ -531,15 +557,17 @@ public class Metrics { if ((response == null) || response.startsWith("ERR") || response.startsWith("7")) { if (response == null) { response = "null"; - } else if (response.startsWith("7")) { + } + else if (response.startsWith("7")) { response = response.substring(response.startsWith("7,") ? 2 : 1); } throw new IOException(response); - } else { + } + else { // Is this the first update this hour? if (response.equals("1") || response.contains("This is your first update this hour")) { synchronized (this.graphs) { - for (Graph graph : this.graphs) { + for (final Graph graph : this.graphs) { for (final Plotter plotter : graph.getPlotters()) { plotter.reset(); } @@ -559,7 +587,8 @@ public class Metrics { try { Class.forName("mineshafter.MineServer"); return true; - } catch (final Exception e) { + } + catch (final Exception e) { return false; } } @@ -572,7 +601,7 @@ public class Metrics { * The graph's name, alphanumeric and spaces only :) If it does not * comply to the above when submitted, it is rejected */ - private final String name; + private final String name; /** * The set of plotters that are contained within this graph */ @@ -594,7 +623,8 @@ public class Metrics { /** * Add a plotter to the graph, which will be used to plot entries * - * @param plotter the plotter to add to the graph + * @param plotter + * the plotter to add to the graph */ public void addPlotter(final Plotter plotter) { this.plotters.add(plotter); @@ -603,7 +633,8 @@ public class Metrics { /** * Remove a plotter from the graph * - * @param plotter the plotter to remove from the graph + * @param plotter + * the plotter to remove from the graph */ public void removePlotter(final Plotter plotter) { this.plotters.remove(plotter); @@ -659,8 +690,9 @@ public class Metrics { /** * Construct a plotter with a specific plot name * - * @param name the name of the plotter to use, which will show up on the - * website + * @param name + * the name of the plotter to use, which will show up on the + * website */ public Plotter(final String name) { this.name = name; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PWE.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PWE.java index 442cb8af6..5099cd910 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PWE.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PWE.java @@ -21,6 +21,10 @@ package com.intellectualcrafters.plot.util; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Plot; @@ -33,9 +37,6 @@ import com.sk89q.worldedit.bukkit.BukkitPlayer; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.RegionMask; import com.sk89q.worldedit.regions.CuboidRegion; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.entity.Player; /** * @author Citymonstret @@ -49,7 +50,8 @@ public class PWE { LocalSession s; if (PlotMain.worldEdit == null) { s = WorldEdit.getInstance().getSession(p.getName()); - } else { + } + else { s = PlotMain.worldEdit.getSession(p); } @@ -64,7 +66,8 @@ public class PWE { removeMask(p, s); return; } - } else { + } + else { final World w = p.getWorld(); @@ -88,7 +91,8 @@ public class PWE { final Vector p1 = new Vector(69, 69, 69), p2 = new Vector(69, 69, 69); s.setMask(new RegionMask(new CuboidRegion(plr.getWorld(), p1, p2))); } - } catch (final Exception e) { + } + catch (final Exception e) { // throw new // PlotSquaredException(PlotSquaredException.PlotError.MISSING_DEPENDENCY, // "WorldEdit == Null?"); @@ -105,13 +109,15 @@ public class PWE { LocalSession s; if (PlotMain.worldEdit == null) { s = WorldEdit.getInstance().getSession(p.getName()); - } else { + } + else { s = PlotMain.worldEdit.getSession(p); } final BukkitPlayer plr = PlotMain.worldEdit.wrapPlayer(p); final Vector p1 = new Vector(69, 69, 69), p2 = new Vector(69, 69, 69); s.setMask(new RegionMask(new CuboidRegion(plr.getWorld(), p1, p2))); - } catch (final Exception e) { + } + catch (final Exception e) { // } } @@ -126,11 +132,13 @@ public class PWE { LocalSession s; if (PlotMain.worldEdit == null) { s = WorldEdit.getInstance().getSession(p.getName()); - } else { + } + else { s = PlotMain.worldEdit.getSession(p); } removeMask(p, s); - } catch (final Exception e) { + } + catch (final Exception e) { // throw new // PlotSquaredException(PlotSquaredException.PlotError.MISSING_DEPENDENCY, // "WorldEdit == Null?"); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlayerFunctions.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlayerFunctions.java index f989abf0f..2abbca33b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlayerFunctions.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlayerFunctions.java @@ -21,6 +21,19 @@ package com.intellectualcrafters.plot.util; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.OfflinePlayer; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.util.ChatPaginator; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; @@ -28,11 +41,6 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotWorld; -import org.bukkit.*; -import org.bukkit.entity.Player; -import org.bukkit.util.ChatPaginator; - -import java.util.*; /** * Functions involving players, plots and locations. @@ -43,7 +51,8 @@ import java.util.*; public class PlayerFunctions { /** - * @param player player + * @param player + * player * @return */ public static boolean isInPlot(final Player player) { @@ -51,7 +60,8 @@ public class PlayerFunctions { } /** - * @param plot plot + * @param plot + * plot * @return */ public static boolean hasExpired(final Plot plot) { @@ -245,13 +255,14 @@ public class PlayerFunctions { * \\previous\\ * * @param plr - * @param msg Was used to wrap the chat client length (Packets out--) + * @param msg + * Was used to wrap the chat client length (Packets out--) */ public static void sendMessageWrapped(final Player plr, String msg) { if (msg.length() > ChatPaginator.AVERAGE_CHAT_PAGE_WIDTH) { - String[] ss = ChatPaginator.wordWrap(msg, ChatPaginator.AVERAGE_CHAT_PAGE_WIDTH); - StringBuilder b = new StringBuilder(); - for (String p : ss) { + final String[] ss = ChatPaginator.wordWrap(msg, ChatPaginator.AVERAGE_CHAT_PAGE_WIDTH); + final StringBuilder b = new StringBuilder(); + for (final String p : ss) { b.append(p).append(p.equals(ss[ss.length - 1]) ? "" : "\n "); } msg = b.toString(); @@ -265,45 +276,51 @@ public class PlayerFunctions { /** * Send a message to the player * - * @param plr Player to recieve message - * @param msg Message to send + * @param plr + * Player to recieve message + * @param msg + * Message to send * @return true - * Can be used in things such as commands (return PlayerFunctions.sendMessage(...)) + * Can be used in things such as commands (return + * PlayerFunctions.sendMessage(...)) */ public static boolean sendMessage(final Player plr, final String msg) { - if (msg.length() > 0 && !msg.equals("")) { + if ((msg.length() > 0) && !msg.equals("")) { if (plr == null) { PlotMain.sendConsoleSenderMessage(C.PREFIX.s() + msg); - } else { + } + else { sendMessageWrapped(plr, ChatColor.translateAlternateColorCodes('&', C.PREFIX.s() + msg)); } } return true; /* - if ((msg.length() == 0) || msg.equalsIgnoreCase("")) { - return ; - } - - if (plr == null) { - PlotMain.sendConsoleSenderMessage(C.PREFIX.s() + msg); - return; - } - - sendMessageWrapped(plr, ChatColor.translateAlternateColorCodes('&', C.PREFIX.s() + msg)); - */ + * if ((msg.length() == 0) || msg.equalsIgnoreCase("")) { + * return ; + * } + * if (plr == null) { + * PlotMain.sendConsoleSenderMessage(C.PREFIX.s() + msg); + * return; + * } + * sendMessageWrapped(plr, ChatColor.translateAlternateColorCodes('&', + * C.PREFIX.s() + msg)); + */ } /** * Send a message to the player * - * @param plr Player to recieve message - * @param c Caption to send + * @param plr + * Player to recieve message + * @param c + * Caption to send * @return */ public static boolean sendMessage(final Player plr, final C c, final String... args) { if (c.s().length() > 1) { - if (plr == null) + if (plr == null) { PlotMain.sendConsoleSenderMessage(c); + } else { String msg = c.s(); if ((args != null) && (args.length > 0)) { @@ -318,26 +335,25 @@ public class PlayerFunctions { } return true; /* - if (plr == null) { - PlotMain.sendConsoleSenderMessage(c); - return; - } - ->>>>>>> origin/master - if (c.s().length() < 1) { - return; - } - String msg = c.s(); - if ((args != null) && (args.length > 0)) { - for (final String str : args) { - msg = msg.replaceFirst("%s", str); - } - } - if (plr == null) { - PlotMain.sendConsoleSenderMessage(c); - return; - } - sendMessage(plr, msg); - */ + * if (plr == null) { + * PlotMain.sendConsoleSenderMessage(c); + * return; + * } + * >>>>>>> origin/master + * if (c.s().length() < 1) { + * return; + * } + * String msg = c.s(); + * if ((args != null) && (args.length > 0)) { + * for (final String str : args) { + * msg = msg.replaceFirst("%s", str); + * } + * } + * if (plr == null) { + * PlotMain.sendConsoleSenderMessage(c); + * return; + * } + * sendMessage(plr, msg); + */ } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java index a7b66e220..b05d5fb4b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java @@ -21,42 +21,50 @@ package com.intellectualcrafters.plot.util; -import com.intellectualcrafters.plot.PlotMain; -import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.database.DBFunc; -import com.intellectualcrafters.plot.listeners.PlotListener; -import com.intellectualcrafters.plot.object.*; +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.UUID; import net.milkbowl.vault.economy.Economy; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.Chunk; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.OfflinePlayer; +import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.block.Block; -import org.bukkit.block.BlockState; import org.bukkit.block.Sign; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.UUID; +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.listeners.PlotListener; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotBlock; +import com.intellectualcrafters.plot.object.PlotHomePosition; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotManager; +import com.intellectualcrafters.plot.object.PlotWorld; /** * plot functions * * @author Citymonstret */ -@SuppressWarnings({"unused", "javadoc", "deprecation"}) +@SuppressWarnings({ "unused", "javadoc", "deprecation" }) public class PlotHelper { - public final static HashMap runners = new HashMap<>(); - public static boolean canSetFast = false; - public static boolean canSendChunk = false; - public static ArrayList runners_p = new ArrayList<>(); - static long state = 1; + public final static HashMap runners = new HashMap<>(); + public static boolean canSetFast = false; + public static boolean canSendChunk = false; + public static ArrayList runners_p = new ArrayList<>(); + static long state = 1; /** * direction 0 = north, 1 = south, etc: @@ -141,13 +149,13 @@ public class PlotHelper { final boolean ly = y < pos2.y; final PlotId id = new PlotId(x, y); - + final Plot plot = PlotMain.getPlots(world).get(id); - + Plot plot2 = null; removeSign(world, plot); - + if (lx) { if (ly) { if (!plot.settings.getMerged(1) || !plot.settings.getMerged(2)) { @@ -183,7 +191,7 @@ public class PlotHelper { } manager.finishPlotMerge(world, plotworld, plotIds); - + return result; } @@ -208,7 +216,8 @@ public class PlotHelper { greaterPlot.settings.setMerged(0, true); manager.removeRoadSouth(plotworld, lesserPlot); } - } else { + } + else { if (!lesserPlot.settings.getMerged(1)) { lesserPlot.settings.setMerged(1, true); greaterPlot.settings.setMerged(3, true); @@ -242,7 +251,7 @@ public class PlotHelper { return 0; } final long r = ((nextLong() >>> 32) * n) >> 32; - return (int) r; + return (int) r; } public static void removeSign(final World world, final Plot p) { @@ -307,7 +316,8 @@ public class PlotHelper { try { SetBlockFast.set(block.getWorld(), block.getX(), block.getY(), block.getZ(), plotblock.id, plotblock.data); return true; - } catch (final Throwable e) { + } + catch (final Throwable e) { canSetFast = false; } } @@ -317,10 +327,12 @@ public class PlotHelper { if (block.getTypeId() != plotblock.id) { block.setTypeId(plotblock.id); } - } else { + } + else { if (block.getTypeId() == plotblock.id) { block.setData(plotblock.data); - } else { + } + else { block.setTypeIdAndData(plotblock.id, plotblock.data, false); } } @@ -661,22 +673,23 @@ public class PlotHelper { public static short[] getBlock(final String block) { if (block.contains(":")) { final String[] split = block.split(":"); - return new short[]{Short.parseShort(split[0]), Short.parseShort(split[1])}; + return new short[] { Short.parseShort(split[0]), Short.parseShort(split[1]) }; } - return new short[]{Short.parseShort(block), 0}; + return new short[] { Short.parseShort(block), 0 }; } public static void clearAllEntities(final World world, final Plot plot, final boolean tile) { - - List entities = world.getEntities(); - for (Entity entity : entities) { - PlotId id = PlayerFunctions.getPlot(entity.getLocation()); + + final List entities = world.getEntities(); + for (final Entity entity : entities) { + final PlotId id = PlayerFunctions.getPlot(entity.getLocation()); if (plot.id.equals(id)) { if (entity instanceof Player) { - Player player = (Player) entity; + final Player player = (Player) entity; PlotMain.teleportPlayer(player, entity.getLocation(), plot); PlotListener.plotExit(player, plot); - } else { + } + else { entity.remove(); } } @@ -701,11 +714,14 @@ public class PlotHelper { manager.clearPlot(world, plot, isDelete); if (canSetFast) { - final Plugin plugin = (Plugin) PlotMain.getMain(); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlotHelper.setBiome(world, plot, Biome.FOREST); - refreshPlotChunks(world, plot); - } }, 90L); + final Plugin plugin = PlotMain.getMain(); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlotHelper.setBiome(world, plot, Biome.FOREST); + refreshPlotChunks(world, plot); + } + }, 90L); } } @@ -737,10 +753,13 @@ public class PlotHelper { clearAllEntities(world, plot, false); clear(world, plot, isDelete); removeSign(world, plot); - final Plugin plugin = (Plugin) PlotMain.getMain(); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - PlayerFunctions.sendMessage(requester, C.CLEARING_DONE.s().replaceAll("%time%", "" + ((System.currentTimeMillis() - start)))); - } }, 90L); + final Plugin plugin = PlotMain.getMain(); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + PlayerFunctions.sendMessage(requester, C.CLEARING_DONE.s().replaceAll("%time%", "" + ((System.currentTimeMillis() - start)))); + } + }, 90L); } @@ -756,7 +775,8 @@ public class PlotHelper { } } } - } else { + } + else { try { for (int y = pos1.getBlockY(); y < pos2.getBlockY(); y++) { for (int x = pos1.getBlockX(); x < pos2.getBlockX(); x++) { @@ -768,12 +788,13 @@ public class PlotHelper { } } } - } catch (final Exception e) { + } + catch (final Exception e) { // } - } + } } - + public static void setCuboid(final World world, final Location pos1, final Location pos2, final PlotBlock[] blocks) { if (blocks.length == 1) { setCuboid(world, pos1, pos2, blocks[0]); @@ -792,7 +813,8 @@ public class PlotHelper { } } } - } else { + } + else { try { for (int y = pos1.getBlockY(); y < pos2.getBlockY(); y++) { for (int x = pos1.getBlockX(); x < pos2.getBlockX(); x++) { @@ -806,7 +828,8 @@ public class PlotHelper { } } } - } catch (final Exception e) { + } + catch (final Exception e) { // } } @@ -824,7 +847,8 @@ public class PlotHelper { } } } - } else { + } + else { try { for (int y = pos1.getBlockY(); y < pos2.getBlockY(); y++) { for (int x = pos1.getBlockX(); x < pos2.getBlockX(); x++) { @@ -836,7 +860,8 @@ public class PlotHelper { } } } - } catch (final Exception e) { + } + catch (final Exception e) { // } } @@ -847,18 +872,18 @@ public class PlotHelper { final int topX = getPlotTopLoc(world, plot.id).getBlockX() + 1; final int bottomZ = getPlotBottomLoc(world, plot.id).getBlockZ(); final int topZ = getPlotTopLoc(world, plot.id).getBlockZ() + 1; - - Block block = world.getBlockAt(getPlotBottomLoc(world, plot.id).add(1, 1, 1)); - Biome biome = block.getBiome(); - + + final Block block = world.getBlockAt(getPlotBottomLoc(world, plot.id).add(1, 1, 1)); + final Biome biome = block.getBiome(); + if (biome.equals(b)) { return; } - + for (int x = bottomX; x <= topX; x++) { for (int z = bottomZ; z <= topZ; z++) { - Block blk = world.getBlockAt(x, 0, z); - Biome c = blk.getBiome(); + final Block blk = world.getBlockAt(x, 0, z); + final Biome c = blk.getBiome(); if (c.equals(b)) { x += 15; continue; @@ -885,8 +910,10 @@ public class PlotHelper { /** * Get plot home * - * @param w World in which the plot is located - * @param plotid Plot ID + * @param w + * World in which the plot is located + * @param plotid + * Plot ID * @return Home Location */ public static Location getPlotHome(final World w, final PlotId plotid) { @@ -899,7 +926,8 @@ public class PlotHelper { final int z = bot.getBlockZ() - 2; final int y = getHeighestBlock(w, x, z); return new Location(w, x, y, z); - } else { + } + else { final Location bot = getPlotBottomLoc(w, plotid), top = getPlotTopLoc(w, plotid); final int x = top.getBlockX() - bot.getBlockX(); final int z = top.getBlockZ() - bot.getBlockZ(); @@ -911,7 +939,8 @@ public class PlotHelper { /** * Retrieve the location of the default plot home position * - * @param plot Plot + * @param plot + * Plot * @return the location */ public static Location getPlotHomeDefault(final Plot plot) { @@ -923,10 +952,13 @@ public class PlotHelper { /** * Get the plot home * - * @param w World - * @param plot Plot Object + * @param w + * World + * @param plot + * Plot Object * @return Plot Home Location - * @see #getPlotHome(org.bukkit.World, com.intellectualcrafters.plot.object.PlotId) + * @see #getPlotHome(org.bukkit.World, + * com.intellectualcrafters.plot.object.PlotId) */ public static Location getPlotHome(final World w, final Plot plot) { return getPlotHome(w, plot.id); @@ -935,8 +967,10 @@ public class PlotHelper { /** * Refresh the plot chunks * - * @param world World in which the plot is located - * @param plot Plot Object + * @param world + * World in which the plot is located + * @param plot + * Plot Object */ public static void refreshPlotChunks(final World world, final Plot plot) { final int bottomX = getPlotBottomLoc(world, plot.id).getBlockX(); @@ -949,21 +983,23 @@ public class PlotHelper { final int minChunkZ = (int) Math.floor((double) bottomZ / 16); final int maxChunkZ = (int) Math.floor((double) topZ / 16); - ArrayList chunks = new ArrayList<>(); + final ArrayList chunks = new ArrayList<>(); for (int x = minChunkX; x <= maxChunkX; x++) { for (int z = minChunkZ; z <= maxChunkZ; z++) { if (canSendChunk) { - Chunk chunk = world.getChunkAt(x, z); + final Chunk chunk = world.getChunkAt(x, z); chunks.add(chunk); - } else { + } + else { world.refreshChunk(x, z); } } } try { SendChunk.sendChunk(chunks); - } catch (Throwable e) { + } + catch (final Throwable e) { canSendChunk = false; for (int x = minChunkX; x <= maxChunkX; x++) { for (int z = minChunkZ; z <= maxChunkZ; z++) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/RUtils.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/RUtils.java index 778517c74..6147337a6 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/RUtils.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/RUtils.java @@ -21,11 +21,12 @@ package com.intellectualcrafters.plot.util; -import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.config.Settings; import org.bukkit.Location; import org.bukkit.entity.Player; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.Settings; + /** * Random utilities * @@ -45,6 +46,7 @@ public class RUtils { /** * Get the total free ram + * * @return free ram */ public static long getFreeRam() { @@ -53,6 +55,7 @@ public class RUtils { /** * Percentage of used ram + * * @return percentage */ public static long getRamPercentage() { @@ -61,7 +64,9 @@ public class RUtils { /** * Get formatted time - * @param sec seconds + * + * @param sec + * seconds * @return formatted time */ public static String formatTime(final double sec) { @@ -79,7 +84,8 @@ public class RUtils { /** * Force textures on the client * - * @param p texture to force + * @param p + * texture to force */ public void forceTexture(final Player p) { p.setResourcePack(Settings.PLOT_SPECIFIC_RESOURCE_PACK); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java index e6229b4b8..76f932a34 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java @@ -21,9 +21,6 @@ package com.intellectualcrafters.plot.util; -import org.bukkit.Bukkit; -import org.bukkit.Server; - import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -32,25 +29,28 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import org.bukkit.Bukkit; +import org.bukkit.Server; + /** * @author DPOH-VAR * @version 1.0 */ -@SuppressWarnings({"UnusedDeclaration", "rawtypes"}) +@SuppressWarnings({ "UnusedDeclaration", "rawtypes" }) public class ReflectionUtils { /** * prefix of bukkit classes */ - private static String preClassB = "org.bukkit.craftbukkit"; + private static String preClassB = "org.bukkit.craftbukkit"; /** * prefix of minecraft classes */ - private static String preClassM = "net.minecraft.server"; + private static String preClassM = "net.minecraft.server"; /** * boolean value, TRUE if server uses forge or MCPC+ */ - private static boolean forge = false; + private static boolean forge = false; /** check server version and class names */ static { @@ -74,7 +74,8 @@ public class ReflectionUtils { final String verM = pas[3]; preClassM += "." + verM; } - } catch (final Exception ignored) { + } + catch (final Exception ignored) { } } } @@ -90,16 +91,19 @@ public class ReflectionUtils { * Get class for name. Replace {nms} to net.minecraft.server.V*. Replace * {cb} to org.bukkit.craftbukkit.V*. Replace {nm} to net.minecraft * - * @param classes possible class paths + * @param classes + * possible class paths * @return RefClass object - * @throws RuntimeException if no class found + * @throws RuntimeException + * if no class found */ public static RefClass getRefClass(final String... classes) throws RuntimeException { for (String className : classes) { try { className = className.replace("{cb}", preClassB).replace("{nms}", preClassM).replace("{nm}", "net.minecraft"); return getRefClass(Class.forName(className)); - } catch (final ClassNotFoundException ignored) { + } + catch (final ClassNotFoundException ignored) { } } throw new RuntimeException("no class found"); @@ -108,7 +112,8 @@ public class ReflectionUtils { /** * get RefClass object by real class * - * @param clazz class + * @param clazz + * class * @return RefClass based on passed class */ public static RefClass getRefClass(final Class clazz) { @@ -137,7 +142,8 @@ public class ReflectionUtils { /** * see {@link Class#isInstance(Object)} * - * @param object the object to check + * @param object + * the object to check * @return true if object is an instance of this class */ public boolean isInstance(final Object object) { @@ -147,10 +153,13 @@ public class ReflectionUtils { /** * get existing method by name and types * - * @param name name - * @param types method parameters. can be Class or RefClass + * @param name + * name + * @param types + * method parameters. can be Class or RefClass * @return RefMethod object - * @throws RuntimeException if method not found + * @throws RuntimeException + * if method not found */ public RefMethod getMethod(final String name, final Object... types) throws NoSuchMethodException { try { @@ -159,18 +168,22 @@ public class ReflectionUtils { for (final Object e : types) { if (e instanceof Class) { classes[i++] = (Class) e; - } else if (e instanceof RefClass) { + } + else if (e instanceof RefClass) { classes[i++] = ((RefClass) e).getRealClass(); - } else { + } + else { classes[i++] = e.getClass(); } } try { return new RefMethod(this.clazz.getMethod(name, classes)); - } catch (final NoSuchMethodException ignored) { + } + catch (final NoSuchMethodException ignored) { return new RefMethod(this.clazz.getDeclaredMethod(name, classes)); } - } catch (final Exception e) { + } + catch (final Exception e) { throw new RuntimeException(e); } } @@ -178,9 +191,11 @@ public class ReflectionUtils { /** * get existing constructor by types * - * @param types parameters. can be Class or RefClass + * @param types + * parameters. can be Class or RefClass * @return RefMethod object - * @throws RuntimeException if constructor not found + * @throws RuntimeException + * if constructor not found */ public RefConstructor getConstructor(final Object... types) { try { @@ -189,18 +204,22 @@ public class ReflectionUtils { for (final Object e : types) { if (e instanceof Class) { classes[i++] = (Class) e; - } else if (e instanceof RefClass) { + } + else if (e instanceof RefClass) { classes[i++] = ((RefClass) e).getRealClass(); - } else { + } + else { classes[i++] = e.getClass(); } } try { return new RefConstructor(this.clazz.getConstructor(classes)); - } catch (final NoSuchMethodException ignored) { + } + catch (final NoSuchMethodException ignored) { return new RefConstructor(this.clazz.getDeclaredConstructor(classes)); } - } catch (final Exception e) { + } + catch (final Exception e) { throw new RuntimeException(e); } } @@ -208,9 +227,11 @@ public class ReflectionUtils { /** * find method by type parameters * - * @param types parameters. can be Class or RefClass + * @param types + * parameters. can be Class or RefClass * @return RefMethod object - * @throws RuntimeException if method not found + * @throws RuntimeException + * if method not found */ public RefMethod findMethod(final Object... types) { final Class[] classes = new Class[types.length]; @@ -218,22 +239,23 @@ public class ReflectionUtils { for (final Object e : types) { if (e instanceof Class) { classes[t++] = (Class) e; - } else if (e instanceof RefClass) { + } + else if (e instanceof RefClass) { classes[t++] = ((RefClass) e).getRealClass(); - } else { + } + else { classes[t++] = e.getClass(); } } final List methods = new ArrayList<>(); Collections.addAll(methods, this.clazz.getMethods()); Collections.addAll(methods, this.clazz.getDeclaredMethods()); - findMethod: - for (final Method m : methods) { + findMethod: for (final Method m : methods) { final Class[] methodTypes = m.getParameterTypes(); if (methodTypes.length != classes.length) { continue; } - for (Class aClass : classes) { + for (final Class aClass : classes) { if (!Arrays.equals(classes, methodTypes)) { continue findMethod; } @@ -246,9 +268,11 @@ public class ReflectionUtils { /** * find method by name * - * @param names possible names of method + * @param names + * possible names of method * @return RefMethod object - * @throws RuntimeException if method not found + * @throws RuntimeException + * if method not found */ public RefMethod findMethodByName(final String... names) { final List methods = new ArrayList<>(); @@ -267,9 +291,11 @@ public class ReflectionUtils { /** * find method by return value * - * @param type type of returned value + * @param type + * type of returned value * @return RefMethod - * @throws RuntimeException if method not found + * @throws RuntimeException + * if method not found */ public RefMethod findMethodByReturnType(final RefClass type) { return findMethodByReturnType(type.clazz); @@ -278,9 +304,11 @@ public class ReflectionUtils { /** * find method by return value * - * @param type type of returned value + * @param type + * type of returned value * @return RefMethod - * @throws RuntimeException if method not found + * @throws RuntimeException + * if method not found */ public RefMethod findMethodByReturnType(Class type) { if (type == null) { @@ -300,9 +328,11 @@ public class ReflectionUtils { /** * find constructor by number of arguments * - * @param number number of arguments + * @param number + * number of arguments * @return RefConstructor - * @throws RuntimeException if constructor not found + * @throws RuntimeException + * if constructor not found */ public RefConstructor findConstructor(final int number) { final List constructors = new ArrayList<>(); @@ -319,18 +349,22 @@ public class ReflectionUtils { /** * get field by name * - * @param name field name + * @param name + * field name * @return RefField - * @throws RuntimeException if field not found + * @throws RuntimeException + * if field not found */ public RefField getField(final String name) { try { try { return new RefField(this.clazz.getField(name)); - } catch (final NoSuchFieldException ignored) { + } + catch (final NoSuchFieldException ignored) { return new RefField(this.clazz.getDeclaredField(name)); } - } catch (final Exception e) { + } + catch (final Exception e) { throw new RuntimeException(e); } } @@ -338,9 +372,11 @@ public class ReflectionUtils { /** * find field by type * - * @param type field type + * @param type + * field type * @return RefField - * @throws RuntimeException if field not found + * @throws RuntimeException + * if field not found */ public RefField findField(final RefClass type) { return findField(type.clazz); @@ -349,9 +385,11 @@ public class ReflectionUtils { /** * find field by type * - * @param type field type + * @param type + * field type * @return RefField - * @throws RuntimeException if field not found + * @throws RuntimeException + * if field not found */ public RefField findField(Class type) { if (type == null) { @@ -404,7 +442,8 @@ public class ReflectionUtils { /** * apply method to object * - * @param e object to which the method is applied + * @param e + * object to which the method is applied * @return RefExecutor with method call(...) */ public RefExecutor of(final Object e) { @@ -414,13 +453,15 @@ public class ReflectionUtils { /** * call static method * - * @param params sent parameters + * @param params + * sent parameters * @return return value */ public Object call(final Object... params) { try { return this.method.invoke(null, params); - } catch (final Exception e) { + } + catch (final Exception e) { throw new RuntimeException(e); } } @@ -435,14 +476,17 @@ public class ReflectionUtils { /** * apply method for selected object * - * @param params sent parameters + * @param params + * sent parameters * @return return value - * @throws RuntimeException if something went wrong + * @throws RuntimeException + * if something went wrong */ public Object call(final Object... params) { try { return RefMethod.this.method.invoke(this.e, params); - } catch (final Exception e) { + } + catch (final Exception e) { throw new RuntimeException(e); } } @@ -477,14 +521,17 @@ public class ReflectionUtils { /** * create new instance with constructor * - * @param params parameters for constructor + * @param params + * parameters for constructor * @return new object - * @throws RuntimeException if something went wrong + * @throws RuntimeException + * if something went wrong */ public Object create(final Object... params) { try { return this.constructor.newInstance(params); - } catch (final Exception e) { + } + catch (final Exception e) { throw new RuntimeException(e); } } @@ -522,7 +569,8 @@ public class ReflectionUtils { /** * apply fiend for object * - * @param e applied object + * @param e + * applied object * @return RefExecutor with getter and setter */ public RefExecutor of(final Object e) { @@ -539,12 +587,14 @@ public class ReflectionUtils { /** * set field value for applied object * - * @param param value + * @param param + * value */ public void set(final Object param) { try { RefField.this.field.set(this.e, param); - } catch (final Exception e) { + } + catch (final Exception e) { throw new RuntimeException(e); } } @@ -557,7 +607,8 @@ public class ReflectionUtils { public Object get() { try { return RefField.this.field.get(this.e); - } catch (final Exception e) { + } + catch (final Exception e) { throw new RuntimeException(e); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java index 2234a65fb..c5d600258 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java @@ -21,24 +21,37 @@ package com.intellectualcrafters.plot.util; -import com.intellectualcrafters.jnbt.*; -import com.intellectualcrafters.plot.PlotMain; -import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotBlock; -import com.intellectualcrafters.plot.object.PlotId; -import org.bukkit.Chunk; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.plugin.java.JavaPlugin; - -import java.io.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; +import org.bukkit.Chunk; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.Block; + +import com.intellectualcrafters.jnbt.ByteArrayTag; +import com.intellectualcrafters.jnbt.CompoundTag; +import com.intellectualcrafters.jnbt.IntTag; +import com.intellectualcrafters.jnbt.ListTag; +import com.intellectualcrafters.jnbt.NBTInputStream; +import com.intellectualcrafters.jnbt.NBTOutputStream; +import com.intellectualcrafters.jnbt.ShortTag; +import com.intellectualcrafters.jnbt.StringTag; +import com.intellectualcrafters.jnbt.Tag; +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotBlock; +import com.intellectualcrafters.plot.object.PlotId; + /** * Schematic Handler * @@ -49,9 +62,12 @@ public class SchematicHandler { /** * Paste a schematic * - * @param location origin - * @param schematic schematic to paste - * @param plot plot to paste in + * @param location + * origin + * @param schematic + * schematic to paste + * @param plot + * plot to paste in * @return true if succeeded */ public static boolean paste(final Location location, final Schematic schematic, final Plot plot, final int x_offset, final int z_offset) { @@ -79,7 +95,8 @@ public class SchematicHandler { int y_offset; if (HEIGHT == location.getWorld().getMaxHeight()) { y_offset = 0; - } else { + } + else { y_offset = l1.getBlockY(); } @@ -108,7 +125,8 @@ public class SchematicHandler { } } } - } catch (final Exception e) { + } + catch (final Exception e) { return false; } return true; @@ -117,7 +135,8 @@ public class SchematicHandler { /** * Get a schematic * - * @param name to check + * @param name + * to check * @return schematic if found, else null */ public static Schematic getSchematic(final String name) { @@ -161,10 +180,12 @@ public class SchematicHandler { if ((index >> 1) >= addId.length) { // No corresponding // AddBlocks index blocks[index] = (short) (b[index] & 0xFF); - } else { + } + else { if ((index & 1) == 0) { blocks[index] = (short) (((addId[index >> 1] & 0x0F) << 8) + (b[index] & 0xFF)); - } else { + } + else { blocks[index] = (short) (((addId[index >> 1] & 0xF0) << 4) + (b[index] & 0xFF)); } } @@ -212,7 +233,8 @@ public class SchematicHandler { // } // } schematic = new Schematic(collection, dimension, file); - } catch (final Exception e) { + } + catch (final Exception e) { e.printStackTrace(); return null; } @@ -222,8 +244,10 @@ public class SchematicHandler { /** * Saves a schematic to a file path * - * @param tag to save - * @param path to save in + * @param tag + * to save + * @param path + * to save in * @return true if succeeded */ public static boolean save(final CompoundTag tag, final String path) { @@ -239,7 +263,8 @@ public class SchematicHandler { output.writeTag(tag); output.close(); stream.close(); - } catch (final IOException e) { + } + catch (final IOException e) { e.printStackTrace(); return false; } @@ -249,8 +274,10 @@ public class SchematicHandler { /** * Gets the schematic of a plot * - * @param world to check - * @param id plot + * @param world + * to check + * @param id + * plot * @return tag */ @SuppressWarnings("deprecation") @@ -279,7 +306,8 @@ public class SchematicHandler { } } } - } catch (final Exception e) { + } + catch (final Exception e) { PlotMain.sendConsoleSenderMessage("&7 - Cannot save: corrupt chunk at " + (i / 16) + ", " + (j / 16)); return null; } @@ -380,8 +408,8 @@ public class SchematicHandler { */ public static class Schematic { private final DataCollection[] blockCollection; - private final Dimension schematicDimension; - private final File file; + private final Dimension schematicDimension; + private final File file; public Schematic(final DataCollection[] blockCollection, final Dimension schematicDimension, final File file) { this.blockCollection = blockCollection; @@ -438,7 +466,7 @@ public class SchematicHandler { */ public static class DataCollection { private final short block; - private final byte data; + private final byte data; // public CompoundTag tag; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SendChunk.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SendChunk.java index 6477eb85a..9fc7ed03c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SendChunk.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SendChunk.java @@ -1,16 +1,17 @@ package com.intellectualcrafters.plot.util; +import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.Chunk; + import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass; import com.intellectualcrafters.plot.util.ReflectionUtils.RefConstructor; import com.intellectualcrafters.plot.util.ReflectionUtils.RefField; import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod; -import org.bukkit.Bukkit; -import org.bukkit.Chunk; - -import java.util.ArrayList; -import java.util.List; - -import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass; /** * An utility that can be used to send chunks, rather than @@ -21,21 +22,21 @@ import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass; public class SendChunk { // Ref Class - private static final RefClass classWorld = getRefClass("{nms}.World"); - private static final RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer"); + private static final RefClass classWorld = getRefClass("{nms}.World"); + private static final RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer"); private static final RefClass classChunkCoordIntPair = getRefClass("{nms}.ChunkCoordIntPair"); - private static final RefClass classCraftChunk = getRefClass("{cb}.CraftChunk"); - private static final RefClass classChunk = getRefClass("{nms}.Chunk"); + private static final RefClass classCraftChunk = getRefClass("{cb}.CraftChunk"); + private static final RefClass classChunk = getRefClass("{nms}.Chunk"); // Ref Method - private static RefMethod methodGetHandle; + private static RefMethod methodGetHandle; // Ref Field - private static RefField chunkCoordIntPairQueue; - private static RefField players; - private static RefField locX; - private static RefField locZ; - private static RefField world; + private static RefField chunkCoordIntPairQueue; + private static RefField players; + private static RefField locX; + private static RefField locZ; + private static RefField world; // Ref Constructor private static RefConstructor ChunkCoordIntPairCon; @@ -58,23 +59,23 @@ public class SendChunk { ChunkCoordIntPairCon = classChunkCoordIntPair.getConstructor(int.class, int.class); } - public static void sendChunk(ArrayList chunks) { + public static void sendChunk(final ArrayList chunks) { int diffx, diffz; - int view = Bukkit.getServer().getViewDistance() << 4; - for (Chunk chunk : chunks) { + final int view = Bukkit.getServer().getViewDistance() << 4; + for (final Chunk chunk : chunks) { final Object c = methodGetHandle.of(chunk).call(); final Object w = world.of(c).get(); final Object p = players.of(w).get(); - for (Object ep : (List) p) { - int x = ((Double) locX.of(ep).get()).intValue(); - int z = ((Double) locZ.of(ep).get()).intValue(); + for (final Object ep : (List) p) { + final int x = ((Double) locX.of(ep).get()).intValue(); + final int z = ((Double) locZ.of(ep).get()).intValue(); diffx = Math.abs(x - (chunk.getX() << 4)); diffz = Math.abs(z - (chunk.getZ() << 4)); - if (diffx <= view && diffz <= view) { - Object pair = ChunkCoordIntPairCon.create(chunk.getX(), chunk.getZ()); - Object pq = chunkCoordIntPairQueue.of(ep).get(); + if ((diffx <= view) && (diffz <= view)) { + final Object pair = ChunkCoordIntPairCon.create(chunk.getX(), chunk.getZ()); + final Object pq = chunkCoordIntPairQueue.of(ep).get(); ((List) pq).add(pair); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SetBlockFast.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SetBlockFast.java index 1896f7208..5b29b5c09 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SetBlockFast.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SetBlockFast.java @@ -21,15 +21,15 @@ package com.intellectualcrafters.plot.util; -import java.util.ArrayList; +import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass; -import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass; -import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod; +import java.util.ArrayList; import org.bukkit.Bukkit; import org.bukkit.Chunk; -import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass; +import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass; +import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod; /** * SetBlockFast class
@@ -39,15 +39,15 @@ import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass; */ public class SetBlockFast { - private static final RefClass classBlock = getRefClass("{nms}.Block"); - private static final RefClass classChunk = getRefClass("{nms}.Chunk"); - private static final RefClass classWorld = getRefClass("{nms}.World"); + private static final RefClass classBlock = getRefClass("{nms}.Block"); + private static final RefClass classChunk = getRefClass("{nms}.Chunk"); + private static final RefClass classWorld = getRefClass("{nms}.World"); private static final RefClass classCraftWorld = getRefClass("{cb}.CraftWorld"); - private static RefMethod methodGetHandle; - private static RefMethod methodGetChunkAt; - private static RefMethod methodA; - private static RefMethod methodGetById; + private static RefMethod methodGetHandle; + private static RefMethod methodGetChunkAt; + private static RefMethod methodA; + private static RefMethod methodGetById; /** * Constructor @@ -63,12 +63,19 @@ public class SetBlockFast { /** * Set the block at the location - * @param world World in which the block should be set - * @param x X Coordinate - * @param y Y Coordinate - * @param z Z Coordinate - * @param blockId Block ID - * @param data Block Data Value + * + * @param world + * World in which the block should be set + * @param x + * X Coordinate + * @param y + * Y Coordinate + * @param z + * Z Coordinate + * @param blockId + * Block ID + * @param data + * Block Data Value * @return true * @throws NoSuchMethodException */ @@ -83,34 +90,36 @@ public class SetBlockFast { /** * Update chunks - * @param player Player whose chunks we're updating + * + * @param player + * Player whose chunks we're updating */ public static void update(final org.bukkit.entity.Player player) { if (!PlotHelper.canSendChunk) { - + final int distance = Bukkit.getViewDistance(); for (int cx = -distance; cx < distance; cx++) { for (int cz = -distance; cz < distance; cz++) { player.getWorld().refreshChunk(player.getLocation().getChunk().getX() + cx, player.getLocation().getChunk().getZ() + cz); } } - + return; } - ArrayList chunks = new ArrayList<>(); - + final ArrayList chunks = new ArrayList<>(); + final int distance = Bukkit.getViewDistance(); for (int cx = -distance; cx < distance; cx++) { for (int cz = -distance; cz < distance; cz++) { - Chunk chunk = player.getWorld().getChunkAt(player.getLocation().getChunk().getX() + cx, player.getLocation().getChunk().getZ() + cz); + final Chunk chunk = player.getWorld().getChunkAt(player.getLocation().getChunk().getX() + cx, player.getLocation().getChunk().getZ() + cz); chunks.add(chunk); } } - + try { SendChunk.sendChunk(chunks); } - catch (Throwable e) { + catch (final Throwable e) { PlotHelper.canSendChunk = false; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/StringComparison.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/StringComparison.java index 487126a78..fcbdf4c27 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/StringComparison.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/StringComparison.java @@ -52,8 +52,10 @@ public class StringComparison { /** * Constructor * - * @param input Input Base Value - * @param objects Objects to compare + * @param input + * Input Base Value + * @param objects + * Objects to compare */ public StringComparison(final String input, final Object[] objects) { double c; @@ -71,8 +73,10 @@ public class StringComparison { /** * Compare two strings * - * @param s1 String Base - * @param s2 Object + * @param s1 + * String Base + * @param s2 + * Object * @return match */ public static double compare(final String s1, final String s2) { @@ -94,7 +98,8 @@ public class StringComparison { /** * Create an ArrayList containing pairs of letters * - * @param s string to split + * @param s + * string to split * @return ArrayList */ public static ArrayList wLetterPair(final String s) { @@ -110,7 +115,8 @@ public class StringComparison { /** * Get an array containing letter pairs * - * @param s string to split + * @param s + * string to split * @return Array */ public static String[] sLetterPair(final String s) { @@ -146,7 +152,7 @@ public class StringComparison { * @return object[] containing: double, String */ public Object[] getBestMatchAdvanced() { - return new Object[]{this.match, this.bestMatch}; + return new Object[] { this.match, this.bestMatch }; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java index 8a7a0eedb..cc0822a29 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java @@ -21,6 +21,14 @@ package com.intellectualcrafters.plot.util; +import java.util.Arrays; +import java.util.HashMap; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + import com.google.common.base.Charsets; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; @@ -34,14 +42,6 @@ import com.intellectualcrafters.plot.uuid.UUIDFetcher; import com.intellectualcrafters.plot.uuid.UUIDSaver; import com.intellectualcrafters.plot.uuid.UUIDWrapper; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.UUID; - /** * This class can be used to efficiently translate UUIDs and names back and * forth. @@ -53,10 +53,8 @@ import java.util.UUID; * restarted. *

* You can use getUuidMap() to save the uuids/names to a file (SQLite db for - * example). - * Primary methods: getUUID(String name) & getName(UUID uuid) <-- You should - * ONLY use these. - * Call startFetch(JavaPlugin plugin) in your onEnable(). + * example). Primary methods: getUUID(String name) & getName(UUID uuid) <-- You + * should ONLY use these. Call startFetch(JavaPlugin plugin) in your onEnable(). *

* Originally created by: * @@ -66,22 +64,22 @@ import java.util.UUID; */ @SuppressWarnings("unused") public class UUIDHandler { - - public static UUIDWrapper uuidWrapper = null; + + public static UUIDWrapper uuidWrapper = null; /** * Online mode * * @see org.bukkit.Server#getOnlineMode() */ - private final static boolean online = Bukkit.getServer().getOnlineMode() && !Settings.OFFLINE_MODE; + private final static boolean online = Bukkit.getServer().getOnlineMode() && !Settings.OFFLINE_MODE; /** * Map containing names and UUIDs * * @see com.google.common.collect.BiMap */ - private final static BiMap uuidMap = HashBiMap.create(new HashMap()); + private final static BiMap uuidMap = HashBiMap.create(new HashMap()); /** * Get the map containing all names/uuids @@ -96,7 +94,8 @@ public class UUIDHandler { /** * Check if a uuid is cached * - * @param uuid to check + * @param uuid + * to check * @return true of the uuid is cached * @see com.google.common.collect.BiMap#containsValue(Object) */ @@ -107,7 +106,8 @@ public class UUIDHandler { /** * Check if a name is cached * - * @param name to check + * @param name + * to check * @return true of the name is cached * @see com.google.common.collect.BiMap#containsKey(Object) */ @@ -118,8 +118,10 @@ public class UUIDHandler { /** * Add a set to the cache * - * @param name to cache - * @param uuid to cache + * @param name + * to cache + * @param uuid + * to cache */ public static void add(final StringWrapper name, final UUID uuid) { if (!uuidMap.containsKey(name) && !uuidMap.inverse().containsKey(uuid)) { @@ -128,7 +130,8 @@ public class UUIDHandler { } /** - * @param name to use as key + * @param name + * to use as key * @return uuid */ public static UUID getUUID(final String name) { @@ -151,32 +154,38 @@ public class UUIDHandler { } try { return PlotMain.getUUIDSaver().mojangUUID(name); - } catch (final Exception e) { + } + catch (final Exception e) { try { final UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name)); uuid = fetcher.call().get(name); add(nameWrap, uuid); - } catch (final Exception ex) { + } + catch (final Exception ex) { ex.printStackTrace(); } } - } else { + } + else { try { final UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name)); uuid = fetcher.call().get(name); add(nameWrap, uuid); - } catch (final Exception ex) { + } + catch (final Exception ex) { ex.printStackTrace(); } } - } else { + } + else { return getUuidOfflineMode(nameWrap); } return null; } /** - * @param uuid to use as key + * @param uuid + * to use as key * @return name (cache) */ private static StringWrapper loopSearch(final UUID uuid) { @@ -184,7 +193,8 @@ public class UUIDHandler { } /** - * @param uuid to use as key + * @param uuid + * to use as key * @return Name */ public static String getName(final UUID uuid) { @@ -205,43 +215,51 @@ public class UUIDHandler { name = fetcher.call().get(uuid); add(new StringWrapper(name), uuid); return name; - } catch (final Exception ex) { + } + catch (final Exception ex) { ex.printStackTrace(); } - } else { + } + else { try { return PlotMain.getUUIDSaver().mojangName(uuid); - } catch (final Exception e) { + } + catch (final Exception e) { try { final NameFetcher fetcher = new NameFetcher(Arrays.asList(uuid)); name = fetcher.call().get(uuid); add(new StringWrapper(name), uuid); return name; - } catch (final Exception ex) { + } + catch (final Exception ex) { e.printStackTrace(); } } } try { return PlotMain.getUUIDSaver().mojangName(uuid); - } catch (final Exception e) { + } + catch (final Exception e) { try { final NameFetcher fetcher = new NameFetcher(Arrays.asList(uuid)); name = fetcher.call().get(uuid); add(new StringWrapper(name), uuid); return name; - } catch (final Exception ex) { + } + catch (final Exception ex) { ex.printStackTrace(); } } - } else { + } + else { return "unknown"; } return ""; } /** - * @param name to use as key + * @param name + * to use as key * @return UUID (name hash) */ private static UUID getUuidOfflineMode(final StringWrapper name) { @@ -251,7 +269,8 @@ public class UUIDHandler { } /** - * @param uuid to use as key + * @param uuid + * to use as key * @return String - name */ private static String getNameOnlinePlayer(final UUID uuid) { @@ -263,11 +282,10 @@ public class UUIDHandler { add(new StringWrapper(name), uuid); return name; } - - /** - * @param uuid to use as key + * @param uuid + * to use as key * @return String - name */ private static String getNameOfflinePlayer(final UUID uuid) { @@ -281,7 +299,8 @@ public class UUIDHandler { } /** - * @param name to use as key + * @param name + * to use as key * @return UUID */ private static UUID getUuidOnlinePlayer(final StringWrapper name) { @@ -305,26 +324,27 @@ public class UUIDHandler { final UUIDSaver saver = PlotMain.getUUIDSaver(); saver.globalSave(getUuidMap()); } - - public static UUID getUUID(Player player) { + + public static UUID getUUID(final Player player) { if (uuidWrapper == null) { try { getUUID(player); uuidWrapper = new DefaultUUIDWrapper(); } - catch (Throwable e) { + catch (final Throwable e) { uuidWrapper = new OfflineUUIDWrapper(); } } return uuidWrapper.getUUID(player); } - + /** - * Safely provide the correct UUID provider. Ignores user preference if not possible rather than break the plugin. + * Safely provide the correct UUID provider. Ignores user preference if not + * possible rather than break the plugin. */ - public static UUID getUUID(OfflinePlayer player) { + public static UUID getUUID(final OfflinePlayer player) { if (uuidWrapper == null) { - + if (Settings.OFFLINE_MODE) { uuidWrapper = new OfflineUUIDWrapper(); } @@ -333,7 +353,7 @@ public class UUIDHandler { getUUID(player); uuidWrapper = new DefaultUUIDWrapper(); } - catch (Throwable e) { + catch (final Throwable e) { uuidWrapper = new OfflineUUIDWrapper(); } } @@ -341,7 +361,7 @@ public class UUIDHandler { try { return uuidWrapper.getUUID(player); } - catch (Throwable e) { + catch (final Throwable e) { uuidWrapper = new OfflineUUIDWrapper(); return uuidWrapper.getUUID(player); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/DefaultUUIDWrapper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/DefaultUUIDWrapper.java index f5be0b554..85d7be275 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/DefaultUUIDWrapper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/DefaultUUIDWrapper.java @@ -9,23 +9,23 @@ import org.bukkit.entity.Player; public class DefaultUUIDWrapper extends UUIDWrapper { @Override - public UUID getUUID(Player player) { - return player.getUniqueId(); - } - - @Override - public UUID getUUID(OfflinePlayer player) { + public UUID getUUID(final Player player) { return player.getUniqueId(); } @Override - public OfflinePlayer getOfflinePlayer(UUID uuid) { + public UUID getUUID(final OfflinePlayer player) { + return player.getUniqueId(); + } + + @Override + public OfflinePlayer getOfflinePlayer(final UUID uuid) { return Bukkit.getOfflinePlayer(uuid); } @Override - public Player getPlayer(UUID uuid) { + public Player getPlayer(final UUID uuid) { return Bukkit.getPlayer(uuid); } - + } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/NameFetcher.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/NameFetcher.java index 5adc83cb8..bc88cbb7c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/NameFetcher.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/NameFetcher.java @@ -21,10 +21,6 @@ package com.intellectualcrafters.plot.uuid; -import com.google.common.collect.ImmutableList; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; - import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; @@ -34,14 +30,19 @@ import java.util.Map; import java.util.UUID; import java.util.concurrent.Callable; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; + +import com.google.common.collect.ImmutableList; + /** * Name Fetcher Class * From Bukkit */ public class NameFetcher implements Callable> { private static final String PROFILE_URL = "https://sessionserver.mojang.com/session/minecraft/profile/"; - private final JSONParser jsonParser = new JSONParser(); - private final List uuids; + private final JSONParser jsonParser = new JSONParser(); + private final List uuids; public NameFetcher(final List uuids) { this.uuids = ImmutableList.copyOf(uuids); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/OfflineUUIDWrapper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/OfflineUUIDWrapper.java index d4c4a3eb0..55286ce26 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/OfflineUUIDWrapper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/OfflineUUIDWrapper.java @@ -14,24 +14,24 @@ import com.intellectualcrafters.plot.util.UUIDHandler; public class OfflineUUIDWrapper extends UUIDWrapper { @Override - public UUID getUUID(Player player) { + public UUID getUUID(final Player player) { return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8)); } @Override - public UUID getUUID(OfflinePlayer player) { + public UUID getUUID(final OfflinePlayer player) { return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8)); } @Override - public OfflinePlayer getOfflinePlayer(UUID uuid) { - BiMap map = UUIDHandler.getUuidMap().inverse(); - String name = map.get(uuid).value; + public OfflinePlayer getOfflinePlayer(final UUID uuid) { + final BiMap map = UUIDHandler.getUuidMap().inverse(); + final String name = map.get(uuid).value; if (name != null) { return Bukkit.getOfflinePlayer(name); } else { - for (OfflinePlayer player : Bukkit.getOfflinePlayers()) { + for (final OfflinePlayer player : Bukkit.getOfflinePlayers()) { if (getUUID(player).equals(uuid)) { return player; } @@ -41,15 +41,13 @@ public class OfflineUUIDWrapper extends UUIDWrapper { } @Override - public Player getPlayer(UUID uuid) { - for (Player player : Bukkit.getOnlinePlayers()) { + public Player getPlayer(final UUID uuid) { + for (final Player player : Bukkit.getOnlinePlayers()) { if (getUUID(player).equals(uuid)) { return player; } } return null; } - - - + } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/PlotUUIDSaver.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/PlotUUIDSaver.java index 5b9bcc034..da6165de6 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/PlotUUIDSaver.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/PlotUUIDSaver.java @@ -21,6 +21,13 @@ package com.intellectualcrafters.plot.uuid; +import java.net.URL; +import java.net.URLConnection; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; + import com.google.common.collect.BiMap; import com.intellectualcrafters.json.JSONObject; import com.intellectualcrafters.json.JSONTokener; @@ -28,13 +35,6 @@ import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.util.UUIDHandler; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.plugin.java.JavaPlugin; - -import java.net.URL; -import java.net.URLConnection; -import java.util.UUID; /** * Plot UUID Saver/Fetcher @@ -70,7 +70,8 @@ public class PlotUUIDSaver implements UUIDSaver { double ups; if ((time == 0l) || (size == 0)) { ups = size; - } else { + } + else { ups = size / time; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDFetcher.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDFetcher.java index e7e36550f..e3351725b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDFetcher.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDFetcher.java @@ -21,29 +21,34 @@ package com.intellectualcrafters.plot.uuid; -import com.google.common.collect.ImmutableList; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; - import java.io.InputStreamReader; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.nio.ByteBuffer; -import java.util.*; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; import java.util.concurrent.Callable; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; + +import com.google.common.collect.ImmutableList; + /** * UUID Fetcher * From Bukkit */ public class UUIDFetcher implements Callable> { private static final double PROFILES_PER_REQUEST = 100; - private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft"; - private final JSONParser jsonParser = new JSONParser(); - private final List names; - private final boolean rateLimiting; + private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft"; + private final JSONParser jsonParser = new JSONParser(); + private final List names; + private final boolean rateLimiting; public UUIDFetcher(final List names, final boolean rateLimiting) { this.names = ImmutableList.copyOf(names); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDSaver.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDSaver.java index d0c4ee827..673682d24 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDSaver.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDSaver.java @@ -21,11 +21,11 @@ package com.intellectualcrafters.plot.uuid; +import java.util.UUID; + import com.google.common.collect.BiMap; import com.intellectualcrafters.plot.object.StringWrapper; -import java.util.UUID; - /** * @author Citymonstret */ @@ -39,21 +39,24 @@ public interface UUIDSaver { /** * Save the UUIDs * - * @param biMap Map containing names and UUIDs + * @param biMap + * Map containing names and UUIDs */ public void globalSave(final BiMap biMap); /** * Save a single UUIDSet * - * @param set Set to save + * @param set + * Set to save */ public void save(final UUIDSet set); /** * Get a single UUIDSet * - * @param name Username + * @param name + * Username * @return UUID Set */ public UUIDSet get(final String name); @@ -61,7 +64,8 @@ public interface UUIDSaver { /** * Get a single UUIDSet * - * @param uuid UUID + * @param uuid + * UUID * @return UUID Set */ public UUIDSet get(final UUID uuid); @@ -69,7 +73,8 @@ public interface UUIDSaver { /** * Fetch uuid from mojang servers * - * @param name Username + * @param name + * Username * @return uuid * @throws Exception */ @@ -78,7 +83,8 @@ public interface UUIDSaver { /** * Fetch username from mojang servers * - * @param uuid UUID + * @param uuid + * UUID * @return username * @throws Exception */ diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDSet.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDSet.java index 8b8071bec..71251c23f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDSet.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDSet.java @@ -36,13 +36,15 @@ public class UUIDSet { /** * Player UUID */ - private final UUID uuid; + private final UUID uuid; /** * Constructor * - * @param name Username - * @param uuid UUID + * @param name + * Username + * @param uuid + * UUID */ public UUIDSet(final String name, final UUID uuid) { this.name = name; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDWrapper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDWrapper.java index 454e9343f..8e37da72f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDWrapper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/UUIDWrapper.java @@ -9,8 +9,8 @@ public abstract class UUIDWrapper { public abstract UUID getUUID(Player player); public abstract UUID getUUID(OfflinePlayer player); - + public abstract OfflinePlayer getOfflinePlayer(UUID uuid); - + public abstract Player getPlayer(UUID uuid); } diff --git a/PlotSquared/src/main/java/com/intellectualsites/translation/TranslationAsset.java b/PlotSquared/src/main/java/com/intellectualsites/translation/TranslationAsset.java index a98014f91..1d5aa3b4f 100644 --- a/PlotSquared/src/main/java/com/intellectualsites/translation/TranslationAsset.java +++ b/PlotSquared/src/main/java/com/intellectualsites/translation/TranslationAsset.java @@ -7,25 +7,25 @@ package com.intellectualsites.translation; */ public class TranslationAsset { - private final TranslationObject trans; - private final String translated; + private final TranslationObject trans; + private final String translated; private final TranslationLanguage lang; - public TranslationAsset(TranslationObject trans, String translated, TranslationLanguage lang) { + public TranslationAsset(final TranslationObject trans, final String translated, final TranslationLanguage lang) { this.trans = trans; this.translated = translated; this.lang = lang; } public TranslationObject getObject() { - return trans; + return this.trans; } public String getTranslated() { - return translated.replace("\n", "&-"); + return this.translated.replace("\n", "&-"); } public TranslationLanguage getLang() { - return lang; + return this.lang; } } diff --git a/PlotSquared/src/main/java/com/intellectualsites/translation/TranslationFile.java b/PlotSquared/src/main/java/com/intellectualsites/translation/TranslationFile.java index eb7aa89d0..fca767221 100644 --- a/PlotSquared/src/main/java/com/intellectualsites/translation/TranslationFile.java +++ b/PlotSquared/src/main/java/com/intellectualsites/translation/TranslationFile.java @@ -29,8 +29,10 @@ public abstract class TranslationFile { /** * Add a value * - * @param key name - * @param value value + * @param key + * name + * @param value + * value */ public abstract void add(String key, String value); diff --git a/PlotSquared/src/main/java/com/intellectualsites/translation/TranslationLanguage.java b/PlotSquared/src/main/java/com/intellectualsites/translation/TranslationLanguage.java index d7165244e..4b3cc711a 100644 --- a/PlotSquared/src/main/java/com/intellectualsites/translation/TranslationLanguage.java +++ b/PlotSquared/src/main/java/com/intellectualsites/translation/TranslationLanguage.java @@ -2,47 +2,39 @@ package com.intellectualsites.translation; public class TranslationLanguage { - public static final TranslationLanguage englishAmerican - = (new TranslationLanguage("American English", "us", "en")); - public static final TranslationLanguage englishBritish - = (new TranslationLanguage("British English", "gb", "en")); - public static final TranslationLanguage swedishSwedish - = (new TranslationLanguage("Swedish", "sv", "se")); - public static final TranslationLanguage russianRussian - = (new TranslationLanguage("Russian", "ru", "ru")); - private final String countryCode; - private final String languageCode; - private final String friendlyName; + public static final TranslationLanguage englishAmerican = (new TranslationLanguage("American English", "us", "en")); + public static final TranslationLanguage englishBritish = (new TranslationLanguage("British English", "gb", "en")); + public static final TranslationLanguage swedishSwedish = (new TranslationLanguage("Swedish", "sv", "se")); + public static final TranslationLanguage russianRussian = (new TranslationLanguage("Russian", "ru", "ru")); + private final String countryCode; + private final String languageCode; + private final String friendlyName; - public TranslationLanguage(String friendlyName, String countryCode, String languageCode) { + public TranslationLanguage(final String friendlyName, final String countryCode, final String languageCode) { this.friendlyName = friendlyName; this.countryCode = countryCode; this.languageCode = languageCode; } public static TranslationLanguage[] values() { - return new TranslationLanguage[]{ - englishAmerican, - englishBritish, - swedishSwedish - }; + return new TranslationLanguage[] { englishAmerican, englishBritish, swedishSwedish }; } public String getName() { - return friendlyName; + return this.friendlyName; } public String getCountryCode() { - return countryCode; + return this.countryCode; } public String getLanguageCode() { - return languageCode; + return this.languageCode; } @Override public String toString() { /* en_US */ - return languageCode.toLowerCase() + "_" + countryCode.toUpperCase(); + return this.languageCode.toLowerCase() + "_" + this.countryCode.toUpperCase(); } } diff --git a/PlotSquared/src/main/java/com/intellectualsites/translation/TranslationManager.java b/PlotSquared/src/main/java/com/intellectualsites/translation/TranslationManager.java index 59dcce1da..a107c8d58 100644 --- a/PlotSquared/src/main/java/com/intellectualsites/translation/TranslationManager.java +++ b/PlotSquared/src/main/java/com/intellectualsites/translation/TranslationManager.java @@ -3,7 +3,11 @@ package com.intellectualsites.translation; import java.io.PrintStream; import java.lang.annotation.Annotation; import java.lang.reflect.Field; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; /** * Translation Manager Main class @@ -15,7 +19,7 @@ public class TranslationManager { /** * Objects */ - private final LinkedList translationObjects; + private final LinkedList translationObjects; /** * The translations */ @@ -25,50 +29,41 @@ public class TranslationManager { * Constructor */ public TranslationManager() { - this(new TranslationObject[]{}); + this(new TranslationObject[] {}); } /** * Constructor * - * @param translationObjects pre-init + * @param translationObjects + * pre-init */ - public TranslationManager(TranslationObject[] translationObjects) { - this.translationObjects - = new LinkedList(Arrays.asList(translationObjects)); - this.translatedObjects - = new LinkedHashMap(); + public TranslationManager(final TranslationObject[] translationObjects) { + this.translationObjects = new LinkedList(Arrays.asList(translationObjects)); + this.translatedObjects = new LinkedHashMap(); } - public static List transformEnum(Object[] os) { - List eList = new ArrayList(); - for (Object o : os) { - eList.add( - new TranslationObject(o.toString(), o.toString().toLowerCase().replace("_", " "), "", "") - ); + public static List transformEnum(final Object[] os) { + final List eList = new ArrayList(); + for (final Object o : os) { + eList.add(new TranslationObject(o.toString(), o.toString().toLowerCase().replace("_", " "), "", "")); } return eList; } - public static void scan(Class c, TranslationManager manager) throws IllegalAccessException { - Field[] fields = c.getDeclaredFields(); + public static void scan(final Class c, final TranslationManager manager) throws IllegalAccessException { + final Field[] fields = c.getDeclaredFields(); Annotation annotation; - for (Field field : fields) { - if (field.getType() != String.class || (annotation = field.getAnnotation(Translation.class)) == null) + for (final Field field : fields) { + if ((field.getType() != String.class) || ((annotation = field.getAnnotation(Translation.class)) == null)) { continue; - Translation t = (Translation) annotation; - String key = field.getName(); + } + final Translation t = (Translation) annotation; + final String key = field.getName(); // Make sure we can get the value field.setAccessible(true); - String defaultValue = (String) field.get(c); - manager.addTranslationObject( - new TranslationObject( - key, - defaultValue, - t.description(), - t.creationDescription() - ) - ); + final String defaultValue = (String) field.get(c); + manager.addTranslationObject(new TranslationObject(key, defaultValue, t.description(), t.creationDescription())); } } @@ -87,33 +82,35 @@ public class TranslationManager { * @return objects */ public List translations() { - return translationObjects; + return this.translationObjects; } /** * Add an object * - * @param t object + * @param t + * object * @return instance */ - public TranslationManager addTranslationObject(TranslationObject t) { - translationObjects.add(t); + public TranslationManager addTranslationObject(final TranslationObject t) { + this.translationObjects.add(t); return instance(); } /** * Remove an object * - * @param t object + * @param t + * object * @return instance */ - public TranslationManager removeTranslationObject(TranslationObject t) { - translationObjects.remove(t); + public TranslationManager removeTranslationObject(final TranslationObject t) { + this.translationObjects.remove(t); return instance(); } - public String getDescription(String key) { - for (TranslationObject o : translations()) { + public String getDescription(final String key) { + for (final TranslationObject o : translations()) { if (o.getKey().equals(key) && !o.getDescription().equals("")) { return "# " + o.getDescription(); } @@ -121,70 +118,74 @@ public class TranslationManager { return ""; } - public TranslationManager addTranslation(TranslationObject t, TranslationAsset a) { + public TranslationManager addTranslation(final TranslationObject t, final TranslationAsset a) { return addTranslation(t.getKey(), a); } - public TranslationManager addTranslation(String key, TranslationAsset a) { + public TranslationManager addTranslation(final String key, final TranslationAsset a) { String eKey = key + "." + a.getLang().toString(); eKey = eKey.toLowerCase(); - if (translatedObjects.containsKey(eKey)) - translatedObjects.remove(eKey); - translatedObjects.put(eKey, a); + if (this.translatedObjects.containsKey(eKey)) { + this.translatedObjects.remove(eKey); + } + this.translatedObjects.put(eKey, a); return instance(); } - public TranslationAsset getTranslated(String key, String language) { + public TranslationAsset getTranslated(final String key, final String language) { String eKey = key + "." + language; eKey = eKey.toLowerCase(); - if (!translatedObjects.containsKey(eKey)) + if (!this.translatedObjects.containsKey(eKey)) { return new TranslationAsset(getDefault(key), getDefault(key).getKey(), TranslationLanguage.englishAmerican); - return translatedObjects.get(key); + } + return this.translatedObjects.get(key); } - public TranslationAsset getTranslated(String key, TranslationLanguage language) { + public TranslationAsset getTranslated(final String key, final TranslationLanguage language) { String eKey = key + "." + language.toString(); eKey = eKey.toLowerCase(); - if (!translatedObjects.containsKey(eKey)) { + if (!this.translatedObjects.containsKey(eKey)) { return new TranslationAsset(getDefault(key), getDefault(key).getDefaultValue(), TranslationLanguage.englishAmerican); } - return translatedObjects.get(eKey); + return this.translatedObjects.get(eKey); } - public TranslationAsset getTranslated(TranslationObject t, TranslationLanguage l) { + public TranslationAsset getTranslated(final TranslationObject t, final TranslationLanguage l) { return getTranslated(t.getKey(), l); } - public String getTranslation(String key, TranslationLanguage l) { + public String getTranslation(final String key, final TranslationLanguage l) { return getTranslated(key, l).getTranslated(); } - public TranslationObject getDefault(String key) { - for (TranslationObject o : translations()) - if (o.getKey().equals(key.toLowerCase())) + public TranslationObject getDefault(final String key) { + for (final TranslationObject o : translations()) { + if (o.getKey().equals(key.toLowerCase())) { return o; + } + } return null; } - public TranslationManager saveAll(TranslationFile file) { - for (TranslationObject object : translations()) { - TranslationAsset o = getTranslated(object.getKey(), file.getLanguage()); + public TranslationManager saveAll(final TranslationFile file) { + for (final TranslationObject object : translations()) { + final TranslationAsset o = getTranslated(object.getKey(), file.getLanguage()); file.add(object.getKey(), o.getTranslated()); } return instance(); } - public TranslationManager debug(PrintStream out) { - for (TranslationObject object : translations()) { + public TranslationManager debug(final PrintStream out) { + for (final TranslationObject object : translations()) { out.println(object.getKey() + ":"); - for (TranslationLanguage language : TranslationLanguage.values()) { + for (final TranslationLanguage language : TranslationLanguage.values()) { out.println(language.toString() + ": " + getTranslated(object.getKey(), language).getTranslated()); } } return instance(); } - public TranslationManager saveFile(TranslationFile file) { + public TranslationManager saveFile(final TranslationFile file) { file.saveFile(); return instance(); } diff --git a/PlotSquared/src/main/java/com/intellectualsites/translation/TranslationObject.java b/PlotSquared/src/main/java/com/intellectualsites/translation/TranslationObject.java index fa6aaa19b..fded67201 100644 --- a/PlotSquared/src/main/java/com/intellectualsites/translation/TranslationObject.java +++ b/PlotSquared/src/main/java/com/intellectualsites/translation/TranslationObject.java @@ -5,28 +5,24 @@ import com.sun.istack.internal.NotNull; public class TranslationObject { // can include a suffix | not null - private String key; - //The default ("no-translation" value) | not null - private String defaultValue; + private final String key; + // The default ("no-translation" value) | not null + private final String defaultValue; // ... "Join message" ... | can be null - private String description; + private final String description; // Like a plugin name for example | can be null - private String creationDescription; + private final String creationDescription; - public TranslationObject(@NotNull String key, @NotNull String defaultValue, String description, String creationDescription) { + public TranslationObject(@NotNull final String key, @NotNull final String defaultValue, String description, String creationDescription) { if (description == null) { description = ""; } if (creationDescription == null) { creationDescription = ""; } - for (char c : key.toCharArray()) { - if (!Character.isDigit(c) && !Character.isAlphabetic(c) && c != '_' && c != '&' && c != '\u00A7' && c != ':') { - throw new RuntimeException( - String.format("Translation: '%s' is invalid (Character: '%s') - Only alphanumeric + (\\, _, &, §, :) charcters are allowed", - key, c + "" - ) - ); + for (final char c : key.toCharArray()) { + if (!Character.isDigit(c) && !Character.isAlphabetic(c) && (c != '_') && (c != '&') && (c != '\u00A7') && (c != ':')) { + throw new RuntimeException(String.format("Translation: '%s' is invalid (Character: '%s') - Only alphanumeric + (\\, _, &, §, :) charcters are allowed", key, c + "")); } } this.key = key.toLowerCase(); @@ -36,19 +32,19 @@ public class TranslationObject { } public String getKey() { - return key; + return this.key; } public String getDefaultValue() { - return defaultValue; + return this.defaultValue; } public String getDescription() { - return description; + return this.description; } public String getCreationDescription() { - return creationDescription; + return this.creationDescription; } } diff --git a/PlotSquared/src/main/java/com/intellectualsites/translation/YamlTranslationFile.java b/PlotSquared/src/main/java/com/intellectualsites/translation/YamlTranslationFile.java index 7e6c0bc66..5d52f43ec 100644 --- a/PlotSquared/src/main/java/com/intellectualsites/translation/YamlTranslationFile.java +++ b/PlotSquared/src/main/java/com/intellectualsites/translation/YamlTranslationFile.java @@ -1,8 +1,5 @@ package com.intellectualsites.translation; -import org.yaml.snakeyaml.DumperOptions; -import org.yaml.snakeyaml.Yaml; - import java.io.File; import java.io.FileReader; import java.io.FileWriter; @@ -11,6 +8,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.Yaml; + /** * The YAML implementation of TranslationFile * Relies heavily on SnakeYAML @@ -20,26 +20,29 @@ import java.util.Map; public class YamlTranslationFile extends TranslationFile { final private TranslationLanguage language; - final private String name; - final private TranslationManager manager; - private File file; - private HashMap map; - private String[] header; - private boolean fancyHead = false; - private YamlTranslationFile instance; + final private String name; + final private TranslationManager manager; + private final File file; + private HashMap map; + private String[] header; + private boolean fancyHead = false; + private YamlTranslationFile instance; /** * YAML Object */ - private Yaml yaml; + private Yaml yaml; /** * Constructor * - * @param path save path - * @param language translation language - * @param name project name + * @param path + * save path + * @param language + * translation language + * @param name + * project name */ - public YamlTranslationFile(File path, TranslationLanguage language, String name, TranslationManager manager) { + public YamlTranslationFile(final File path, final TranslationLanguage language, final String name, final TranslationManager manager) { this.language = language; this.name = name; this.manager = manager; @@ -49,16 +52,17 @@ public class YamlTranslationFile extends TranslationFile { } } this.file = new File(path + File.separator + name + "." + language.toString() + ".yml"); - if (!file.exists()) { + if (!this.file.exists()) { try { - if (!file.createNewFile()) { - throw new RuntimeException("Could not create: " + file.getName()); + if (!this.file.createNewFile()) { + throw new RuntimeException("Could not create: " + this.file.getName()); } - } catch (Exception e) { + } + catch (final Exception e) { e.printStackTrace(); } } - instance = this; + this.instance = this; this.instance = this; } @@ -73,29 +77,31 @@ public class YamlTranslationFile extends TranslationFile { /** * Set the header * - * @param header Comment header + * @param header + * Comment header * @return instance */ - public YamlTranslationFile header(String... header) { + public YamlTranslationFile header(final String... header) { this.header = header; this.fancyHead = false; - return instance; + return this.instance; } /** * Set a fancy header * - * @param header Comment header + * @param header + * Comment header * @return instance */ - public YamlTranslationFile fancyHeader(String... header) { + public YamlTranslationFile fancyHeader(final String... header) { final String line = "################################################################################################"; final int lineLength = line.length(); - List strings = new ArrayList(); + final List strings = new ArrayList(); strings.add(line + "\n"); for (String s : header) { s = "# " + s; - while (s.length() < lineLength - 1) { + while (s.length() < (lineLength - 1)) { s = s + " "; } s = s + "#\n"; @@ -104,21 +110,23 @@ public class YamlTranslationFile extends TranslationFile { strings.add(line + "\n"); this.header = strings.toArray(new String[strings.size()]); this.fancyHead = true; - return instance; + return this.instance; } /** * Add a translation * - * @param key translation name - * @param value translation value + * @param key + * translation name + * @param value + * translation value */ - public void add(String key, String value) { - if (map.containsKey(key)) + @Override + public void add(final String key, final String value) { + if (this.map.containsKey(key)) { return; - map.put( - key, value - ); + } + this.map.put(key, value); } /** @@ -128,7 +136,7 @@ public class YamlTranslationFile extends TranslationFile { */ @Override public TranslationLanguage getLanguage() { - return language; + return this.language; } /** @@ -137,31 +145,35 @@ public class YamlTranslationFile extends TranslationFile { @Override public void saveFile() { try { - FileWriter writer = new FileWriter(file); - //String s = getYaml().dump(map); - if (header != null && !fancyHead) { - for (String head : header) { + final FileWriter writer = new FileWriter(this.file); + // String s = getYaml().dump(map); + if ((this.header != null) && !this.fancyHead) { + for (final String head : this.header) { writer.write("# " + head + "\n"); } - } else if (header != null && fancyHead) { - for (String head : header) { + } + else if ((this.header != null) && this.fancyHead) { + for (final String head : this.header) { writer.write(head); } } - int length = map.size(); + final int length = this.map.size(); int current = 0; - for (Map.Entry entry : map.entrySet()) { - String var = entry.getKey(); - String val = entry.getValue(); - String des = manager.getDescription(var); - if (des.equals("")) - writer.write(var + ": \"" + val + "\"" + (current < length - 1 ? "\n" : "")); - else - writer.write(des + "\n" + var + ": \"" + val + "\"" + (current < length - 1 ? "\n" : "")); + for (final Map.Entry entry : this.map.entrySet()) { + final String var = entry.getKey(); + final String val = entry.getValue(); + final String des = this.manager.getDescription(var); + if (des.equals("")) { + writer.write(var + ": \"" + val + "\"" + (current < (length - 1) ? "\n" : "")); + } + else { + writer.write(des + "\n" + var + ": \"" + val + "\"" + (current < (length - 1) ? "\n" : "")); + } ++current; } writer.close(); - } catch (Exception e) { + } + catch (final Exception e) { e.printStackTrace(); } } @@ -172,16 +184,16 @@ public class YamlTranslationFile extends TranslationFile { * @return yaml object with correct settings */ public Yaml getYaml() { - if (yaml == null) { - DumperOptions options = new DumperOptions(); + if (this.yaml == null) { + final DumperOptions options = new DumperOptions(); options.setAllowUnicode(true); options.setPrettyFlow(true); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); options.setDefaultScalarStyle(DumperOptions.ScalarStyle.DOUBLE_QUOTED); - yaml = new Yaml(options); - yaml.setName(name + "." + language.toString()); + this.yaml = new Yaml(options); + this.yaml.setName(this.name + "." + this.language.toString()); } - return yaml; + return this.yaml; } /** @@ -192,22 +204,20 @@ public class YamlTranslationFile extends TranslationFile { @Override public YamlTranslationFile read() { try { - map = (HashMap) getYaml().load(new FileReader(file)); - } catch (Exception e) { + this.map = (HashMap) getYaml().load(new FileReader(this.file)); + } + catch (final Exception e) { e.printStackTrace(); } - if (map == null) { - map = new HashMap(); + if (this.map == null) { + this.map = new HashMap(); System.out.println("Was null..."); } - for (Map.Entry objects : map.entrySet()) { - String key = objects.getKey(); - String val = objects.getValue(); - manager.addTranslation( - key, - new TranslationAsset(null, val, language) - ); + for (final Map.Entry objects : this.map.entrySet()) { + final String key = objects.getKey(); + final String val = objects.getValue(); + this.manager.addTranslation(key, new TranslationAsset(null, val, this.language)); } - return instance; + return this.instance; } } diff --git a/PlotSquared/src/main/java/com/intellectualsites/translation/bukkit/BukkitTranslation.java b/PlotSquared/src/main/java/com/intellectualsites/translation/bukkit/BukkitTranslation.java index 1221173b4..9deae1248 100644 --- a/PlotSquared/src/main/java/com/intellectualsites/translation/bukkit/BukkitTranslation.java +++ b/PlotSquared/src/main/java/com/intellectualsites/translation/bukkit/BukkitTranslation.java @@ -1,13 +1,14 @@ package com.intellectualsites.translation.bukkit; +import java.io.File; + +import org.bukkit.Material; +import org.bukkit.plugin.java.JavaPlugin; + import com.intellectualsites.translation.TranslationAsset; import com.intellectualsites.translation.TranslationLanguage; import com.intellectualsites.translation.TranslationManager; import com.intellectualsites.translation.TranslationObject; -import org.bukkit.Material; -import org.bukkit.plugin.java.JavaPlugin; - -import java.io.File; /** * @author Citymonstret @@ -17,11 +18,13 @@ public class BukkitTranslation { /** * Get the converted string * - * @param asset asset + * @param asset + * asset * @return converted asset */ - public static String convert(TranslationAsset asset) { - // In some cases newline can screw stuff up, so I added a new character thing + public static String convert(final TranslationAsset asset) { + // In some cases newline can screw stuff up, so I added a new character + // thing // &- = new line return asset.getTranslated().replace("&-", "\n").replace('&', '\u00A7'); } @@ -29,10 +32,11 @@ public class BukkitTranslation { /** * Get the universal parent based on the plugin data folder * - * @param plugin to check + * @param plugin + * to check * @return parent folder */ - public static File getParent(JavaPlugin plugin) { + public static File getParent(final JavaPlugin plugin) { return new File(plugin.getDataFolder() + File.separator + "translations"); } @@ -49,11 +53,9 @@ public class BukkitTranslation { * Add material names to the translation list * Will default to a somewhat friendly name */ - public static void addMaterials(TranslationManager manager) { - for (Material material : Material.values()) { - manager.addTranslationObject( - new TranslationObject(material.name(), material.name().replace("_", " ").toLowerCase(), "Material." + material.toString(), "") - ); + public static void addMaterials(final TranslationManager manager) { + for (final Material material : Material.values()) { + manager.addTranslationObject(new TranslationObject(material.name(), material.name().replace("_", " ").toLowerCase(), "Material." + material.toString(), "")); } } } diff --git a/PlotSquared/src/main/java/com/intellectualsites/translation/bukkit/TranslationPlugin.java b/PlotSquared/src/main/java/com/intellectualsites/translation/bukkit/TranslationPlugin.java index c811210b6..db2582deb 100644 --- a/PlotSquared/src/main/java/com/intellectualsites/translation/bukkit/TranslationPlugin.java +++ b/PlotSquared/src/main/java/com/intellectualsites/translation/bukkit/TranslationPlugin.java @@ -1,21 +1,26 @@ package com.intellectualsites.translation.bukkit; -import com.intellectualsites.translation.*; +import java.util.logging.Level; + import org.bukkit.plugin.java.JavaPlugin; -import java.util.logging.Level; +import com.intellectualsites.translation.Translation; +import com.intellectualsites.translation.TranslationFile; +import com.intellectualsites.translation.TranslationLanguage; +import com.intellectualsites.translation.TranslationManager; +import com.intellectualsites.translation.YamlTranslationFile; public class TranslationPlugin extends JavaPlugin { @Translation(description = "Printed when the translator is fully loaded") - private static final String TRANSLATOR_LOADED = "The translator has been loaded"; + private static final String TRANSLATOR_LOADED = "The translator has been loaded"; @Translation(description = "Printed when the translator has been disabled") - private static final String TRANSLATOR_DISABLED = "The translator has been disabled"; + private static final String TRANSLATOR_DISABLED = "The translator has been disabled"; private static TranslationManager manager; - private TranslationFile english; + private TranslationFile english; @Override public void onEnable() { @@ -24,17 +29,12 @@ public class TranslationPlugin extends JavaPlugin { // Scan this file for all @Translations try { TranslationManager.scan(TranslationPlugin.class, manager); - } catch (Exception e) { + } + catch (final Exception e) { e.printStackTrace(); } // Now let's create some default files :D - english = - new YamlTranslationFile( - BukkitTranslation.getParent(this), - TranslationLanguage.englishAmerican, - getName(), - manager - ).read().header("Example file", "@author Citymonstret"); + this.english = new YamlTranslationFile(BukkitTranslation.getParent(this), TranslationLanguage.englishAmerican, getName(), manager).read().header("Example file", "@author Citymonstret"); // That created the file, read it, and made a default header getLogger().log(Level.INFO, BukkitTranslation.convert(manager.getTranslated("translator_loaded", TranslationLanguage.englishAmerican))); } @@ -42,7 +42,7 @@ public class TranslationPlugin extends JavaPlugin { @Override public void onDisable() { // Add all translations and save the file - manager.saveAll(english).saveFile(english); + manager.saveAll(this.english).saveFile(this.english); getLogger().log(Level.INFO, BukkitTranslation.convert(manager.getTranslated("translator_disabled", TranslationLanguage.englishAmerican))); } diff --git a/PlotSquared/src/test/java/Test1.java b/PlotSquared/src/test/java/Test1.java index 6d7ca4c31..c2f8790f4 100644 --- a/PlotSquared/src/test/java/Test1.java +++ b/PlotSquared/src/test/java/Test1.java @@ -1,3 +1,13 @@ +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.UUID; + +import org.bukkit.OfflinePlayer; +import org.bukkit.block.Biome; +import org.junit.Assert; +import org.junit.Test; + import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.AbstractDB; @@ -5,18 +15,14 @@ import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.generator.DefaultPlotManager; import com.intellectualcrafters.plot.generator.DefaultPlotWorld; -import com.intellectualcrafters.plot.object.*; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotComment; +import com.intellectualcrafters.plot.object.PlotHomePosition; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotManager; +import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.PlotHelper; import com.intellectualcrafters.plot.util.SetBlockFast; -import org.bukkit.OfflinePlayer; -import org.bukkit.block.Biome; -import org.junit.Assert; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.UUID; public class Test1 { @@ -24,14 +30,13 @@ public class Test1 { // I have no idea what I should actually test :p - public boolean nextTest() { Test1.count++; switch (Test1.count) { case 1: return test1_Square(); case 2: - return true; //test2_InitMain(); // fails + return true; // test2_InitMain(); // fails case 3: return test3_InitPlotId(); case 4: @@ -39,13 +44,13 @@ public class Test1 { case 5: return test5_InitDBFunc(); case 6: - return true; //test6_Plots(); // fails + return true; // test6_Plots(); // fails case 7: - return true; //test7_OnEnable(); // fails + return true; // test7_OnEnable(); // fails case 8: - return true; //test8_AddPlotWorld(); // fails + return true; // test8_AddPlotWorld(); // fails case 9: - return true; //test9_CanSetFast(); // fails + return true; // test9_CanSetFast(); // fails } return false; } @@ -102,9 +107,10 @@ public class Test1 { public boolean test2_InitMain() { boolean passed = false; try { - PlotMain plugin = PlotMain.getMain(); + final PlotMain plugin = PlotMain.getMain(); passed = plugin != null; - } catch (Throwable e) { + } + catch (final Throwable e) { } return passed; @@ -113,9 +119,10 @@ public class Test1 { public boolean test3_InitPlotId() { boolean passed = false; try { - Object id = new PlotId(0, 0); + final Object id = new PlotId(0, 0); passed = id != null; - } catch (Throwable e) { + } + catch (final Throwable e) { } return passed; @@ -124,9 +131,10 @@ public class Test1 { public boolean test4_InitPlot() { boolean passed = false; try { - Object plot = new Plot(new PlotId(0, 0), DBFunc.everyone, Biome.FOREST, new ArrayList(), new ArrayList(), new ArrayList(), null, PlotHomePosition.DEFAULT, null, "testworld", new boolean[]{false, false, false, false}); + new Plot(new PlotId(0, 0), DBFunc.everyone, Biome.FOREST, new ArrayList(), new ArrayList(), new ArrayList(), null, PlotHomePosition.DEFAULT, null, "testworld", new boolean[] { false, false, false, false }); passed = true; - } catch (Throwable ignored) { + } + catch (final Throwable ignored) { } return passed; @@ -143,140 +151,130 @@ public class Test1 { DBFunc.dbManager = new AbstractDB() { @Override - public void setTrusted(String world, Plot plot, OfflinePlayer player) { + public void setTrusted(final String world, final Plot plot, final OfflinePlayer player) { } @Override - public void setPosition(String world, Plot plot, String position) { + public void setPosition(final String world, final Plot plot, final String position) { } @Override - public void setOwner(Plot plot, UUID uuid) { + public void setOwner(final Plot plot, final UUID uuid) { } @Override - public void setMerged(String world, Plot plot, boolean[] merged) { + public void setMerged(final String world, final Plot plot, final boolean[] merged) { } @Override - public void setHelper(String world, Plot plot, OfflinePlayer player) { + public void setHelper(final String world, final Plot plot, final OfflinePlayer player) { } @Override - public void setFlags(String world, Plot plot, Flag[] flags) { + public void setFlags(final String world, final Plot plot, final Flag[] flags) { } @Override - public void setDenied(String world, Plot plot, OfflinePlayer player) { + public void setDenied(final String world, final Plot plot, final OfflinePlayer player) { } @Override - public void setComment(String world, Plot plot, PlotComment comment) { + public void setComment(final String world, final Plot plot, final PlotComment comment) { } @Override - public void setAlias(String world, Plot plot, String alias) { + public void setAlias(final String world, final Plot plot, final String alias) { } @Override - public void removeTrusted(String world, Plot plot, OfflinePlayer player) { + public void removeTrusted(final String world, final Plot plot, final OfflinePlayer player) { } @Override - public void removeHelper(String world, Plot plot, OfflinePlayer player) { + public void removeHelper(final String world, final Plot plot, final OfflinePlayer player) { } @Override - public void removeDenied(String world, Plot plot, OfflinePlayer player) { + public void removeDenied(final String world, final Plot plot, final OfflinePlayer player) { } @Override - public void removeComment(String world, Plot plot, PlotComment comment) { + public void removeComment(final String world, final Plot plot, final PlotComment comment) { } @Override - public void purge(String world) { + public void purge(final String world) { } @Override - public void purge(String world, PlotId id) { + public void purge(final String world, final PlotId id) { } @Override - public HashMap getSettings(int id) { + public HashMap getSettings(final int id) { return null; } @Override - public double getRatings(Plot plot) { + public double getRatings(final Plot plot) { return 0; } @Override public LinkedHashMap> getPlots() { - LinkedHashMap> plots = new LinkedHashMap>(); + final LinkedHashMap> plots = new LinkedHashMap>(); plots.put("testworld", new HashMap()); - PlotId id = new PlotId(0, 0); + final PlotId id = new PlotId(0, 0); - plots.get("testworld").put(id, - new Plot(id, - DBFunc.everyone, - new ArrayList(), - new ArrayList(), - new ArrayList(), - null, - PlotHomePosition.DEFAULT, - null, - "testworld", - new boolean[]{false, false, false, false})); + plots.get("testworld").put(id, new Plot(id, DBFunc.everyone, new ArrayList(), new ArrayList(), new ArrayList(), null, PlotHomePosition.DEFAULT, null, "testworld", new boolean[] { false, false, false, false })); return plots; } @Override - public int getId(String world, PlotId id2) { + public int getId(final String world, final PlotId id2) { return 0; } @Override - public ArrayList getComments(String world, Plot plot, int tier) { + public ArrayList getComments(final String world, final Plot plot, final int tier) { return null; } @Override - public void delete(String world, Plot plot) { + public void delete(final String world, final Plot plot) { } @Override - public void createTables(String database, boolean add_constraint) throws Exception { + public void createTables(final String database, final boolean add_constraint) throws Exception { } @Override - public void createPlots(ArrayList plots) { + public void createPlots(final ArrayList plots) { } @Override - public void createPlotSettings(int id, Plot plot) { + public void createPlotSettings(final int id, final Plot plot) { } @Override - public void createPlot(Plot plot) { + public void createPlot(final Plot plot) { } @Override - public void createAllSettingsAndHelpers(ArrayList plots) { + public void createAllSettingsAndHelpers(final ArrayList plots) { } }; passed = true; - } catch (Throwable e) { + } + catch (final Throwable e) { } return passed; } - public boolean test6_Plots() { return PlotMain.getAllPlotsRaw() != null; } @@ -286,7 +284,8 @@ public class Test1 { try { PlotMain.getMain().onEnable(); passed = true; - } catch (Throwable e) { + } + catch (final Throwable e) { } return passed; @@ -299,23 +298,23 @@ public class Test1 { final PlotManager manager = new DefaultPlotManager(); PlotMain.addPlotWorld("poop", plotworld, manager); passed = (PlotMain.getPlotManager("poop") != null) && (PlotMain.getWorldSettings("poop") != null); - } catch (final Throwable e) { + } + catch (final Throwable e) { } return passed; } - public boolean test9_CanSetFast() { boolean passed = false; try { new SetBlockFast(); passed = true; - } catch (Throwable e) { + } + catch (final Throwable e) { } return passed; } - }