From 07895be660fcfddae28aa1da2d8a92aa899312e3 Mon Sep 17 00:00:00 2001 From: Sauilitired Date: Sun, 16 Nov 2014 09:56:42 +0100 Subject: [PATCH] Minor fixes :D --- .../plot/AbstractFlag.java | 5 +- .../plot/BlockWrapper.java | 33 +++++++-- .../plot/Configuration.java | 68 +++++++++-------- .../plot/ConfigurationNode.java | 9 +-- .../plot/ConsoleColors.java | 74 +++++++++---------- .../plot/FlagManager.java | 28 +++---- .../plot/PlayerFunctions.java | 8 +- .../com/intellectualcrafters/plot/Plot.java | 2 +- .../plot/PlotSelection.java | 29 ++++---- 9 files changed, 143 insertions(+), 113 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/AbstractFlag.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/AbstractFlag.java index 771353508..d310ac892 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/AbstractFlag.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/AbstractFlag.java @@ -24,7 +24,10 @@ package com.intellectualcrafters.plot; import org.apache.commons.lang.StringUtils; /** - * Created by Citymonstret on 2014-09-23. + * Created 2014-09-23 for PlotSquared + * + * @author Citymonstret + * @author Empire92 */ public class AbstractFlag { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BlockWrapper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BlockWrapper.java index b06091933..fed5e594d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BlockWrapper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BlockWrapper.java @@ -21,15 +21,34 @@ package com.intellectualcrafters.plot; - +/** + * Wrapper class for blocks, using + * pure data rather than the object. + *

+ * Useful for NMS + * + * @author Empire92 + */ public class BlockWrapper { - public int x; - public int y; - public int z; - public int id; - public byte data; - public BlockWrapper(final int x, final int y, final int z, final short id, final byte data) { + // Public Final ////////////////////////// + public final int x; // + public final int y; // + public final int z; // + public final int id; // + public final byte data; // + ////////////////////////////////////////// + + /** + * Constructor + * + * @param x X Loc Value + * @param y Y Loc Value + * @param z Z Loc Value + * @param id Material ID + * @param data Data Value + */ + public BlockWrapper(int x, int y, int z, short id, byte data) { this.x = x; this.y = y; this.z = z; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/Configuration.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/Configuration.java index 95829919d..fc968ed9c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/Configuration.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/Configuration.java @@ -26,7 +26,14 @@ import org.bukkit.block.Biome; import java.util.ArrayList; import java.util.List; +/** + * Main Configuration Utility + * + * @author Empire92 + */ +@SuppressWarnings("unused") public class Configuration { + public static final SettingValue STRING = new SettingValue("STRING") { @Override public boolean validateValue(final String string) { @@ -55,7 +62,7 @@ public class Configuration { @Override public boolean validateValue(final String string) { try { - Integer.parseInt(string); + int x = Integer.parseInt(string); return true; } catch (final Exception e) { return false; @@ -72,7 +79,7 @@ public class Configuration { @Override public boolean validateValue(final String string) { try { - Boolean.parseBoolean(string); + boolean b = Boolean.parseBoolean(string); return true; } catch (final Exception e) { return false; @@ -89,7 +96,7 @@ public class Configuration { @Override public boolean validateValue(final String string) { try { - Double.parseDouble(string); + double d = Double.parseDouble(string); return true; } catch (final Exception e) { return false; @@ -125,7 +132,7 @@ public class Configuration { @Override public Object parseObject(final Object object) { - return ((Biome) object).toString(); + return (((Biome) object)).toString(); } }; @@ -135,10 +142,12 @@ public class Configuration { try { if (string.contains(":")) { final String[] split = string.split(":"); - Short.parseShort(split[0]); - Short.parseShort(split[1]); + short s = + Short.parseShort(split[0]); + short z = + Short.parseShort(split[1]); } else { - Short.parseShort(string); + short s = Short.parseShort(string); } return true; } catch (final Exception e) { @@ -161,22 +170,6 @@ public class Configuration { return ((PlotBlock) object).id + ":" + ((PlotBlock) object).data; } }; - - public static int gcd(final int a, final int b) { - if (b == 0) { - return a; - } - return gcd(b, a % b); - } - - private static int gcd(final int[] a) { - int result = a[0]; - for (int i = 1; i < a.length; i++) { - result = gcd(result, a[i]); - } - return result; - } - public static final SettingValue BLOCKLIST = new SettingValue("BLOCKLIST") { @Override public boolean validateValue(final String string) { @@ -184,15 +177,15 @@ public class Configuration { for (String block : string.split(",")) { if (block.contains("%")) { final String[] split = block.split("%"); - Integer.parseInt(split[0]); + int i = Integer.parseInt(split[0]); block = split[1]; } if (block.contains(":")) { final String[] split = block.split(":"); - Short.parseShort(split[0]); - Short.parseShort(split[1]); + short s = Short.parseShort(split[0]); + short z = Short.parseShort(split[1]); } else { - Short.parseShort(block); + short s = Short.parseShort(block); } } return true; @@ -204,7 +197,7 @@ public class Configuration { @Override public Object parseString(final String string) { final String[] blocks = string.split(","); - final ArrayList parsedvalues = new ArrayList(); + final ArrayList parsedvalues = new ArrayList<>(); final PlotBlock[] values = new PlotBlock[blocks.length]; final int[] counts = new int[blocks.length]; @@ -239,12 +232,12 @@ public class Configuration { } } - return parsedvalues.toArray(new PlotBlock[0]); + return parsedvalues.toArray(new PlotBlock[parsedvalues.size()]); } @Override public Object parseObject(final Object object) { - final List list = new ArrayList(); + final List list = new ArrayList<>(); for (final PlotBlock block : (PlotBlock[]) object) { list.add((block.id + ":" + (block.data))); } @@ -252,6 +245,21 @@ public class Configuration { } }; + public static int gcd(final int a, final int b) { + if (b == 0) { + return a; + } + return gcd(b, a % b); + } + + private static int gcd(final int[] a) { + int result = a[0]; + for (int i = 1; i < a.length; i++) { + result = gcd(result, a[i]); + } + return result; + } + /** * Create your own SettingValue object to make the management of plotworld * configuration easier diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/ConfigurationNode.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/ConfigurationNode.java index 7af05b139..a2fc1933e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/ConfigurationNode.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/ConfigurationNode.java @@ -30,10 +30,10 @@ public class ConfigurationNode { private final String constant; private final Object default_value; private final String description; - private Object value; private final SettingValue type; + private Object value; - public ConfigurationNode(final String constant, final Object default_value, final String description, final SettingValue type, final boolean required) { + public ConfigurationNode(final String constant, final Object default_value, final String description, final SettingValue type, @SuppressWarnings("unused") final boolean required) { this.constant = constant; this.default_value = default_value; this.description = description; @@ -48,10 +48,7 @@ public class ConfigurationNode { public boolean isValid(final String string) { try { final Object result = this.type.parseString(string); - if (result == null) { - return false; - } - return true; + return result != null; } catch (final Exception e) { return false; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/ConsoleColors.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/ConsoleColors.java index 122b52ffb..d70d62106 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/ConsoleColors.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/ConsoleColors.java @@ -23,40 +23,12 @@ package com.intellectualcrafters.plot; import org.bukkit.ChatColor; -/** - * Created by Citymonstret on 2014-09-22. - */ public class ConsoleColors { - static enum ConsoleColor { - RESET("\u001B[0m"), - BLACK("\u001B[30m"), - RED("\u001B[31m"), - GREEN("\u001B[32m"), - YELLOW("\u001B[33m"), - BLUE("\u001B[34m"), - PURPLE("\u001B[35m"), - CYAN("\u001B[36m"), - WHITE("\u001B[37m"), - BOLD("\033[1m"), - UNDERLINE("\033[0m"), - ITALIC("\033[3m"); - - private final String win; - private final String lin; - - ConsoleColor(final String lin) { - this.lin = lin; - this.win = this.win; - } - - public String getWin() { - return this.win; - } - - public String getLin() { - return this.lin; - } + public static String fromString(String input) { + input = input.replaceAll("&0", fromChatColor(ChatColor.BLACK)).replaceAll("&1", fromChatColor(ChatColor.DARK_BLUE)).replaceAll("&2", fromChatColor(ChatColor.DARK_GREEN)).replaceAll("&3", fromChatColor(ChatColor.DARK_AQUA)).replaceAll("&4", fromChatColor(ChatColor.DARK_RED)).replaceAll("&5", fromChatColor(ChatColor.DARK_PURPLE)).replaceAll("&6", fromChatColor(ChatColor.GOLD)).replaceAll("&7", fromChatColor(ChatColor.GRAY)).replaceAll("&8", fromChatColor(ChatColor.DARK_GRAY)).replaceAll("&9", fromChatColor(ChatColor.BLUE)).replaceAll("&a", fromChatColor(ChatColor.GREEN)).replaceAll("&b", fromChatColor(ChatColor.AQUA)).replaceAll("&c", fromChatColor(ChatColor.RED)).replaceAll("&d", fromChatColor(ChatColor.LIGHT_PURPLE)).replaceAll("&e", fromChatColor(ChatColor.YELLOW)).replaceAll("&f", fromChatColor(ChatColor.WHITE)).replaceAll("&k", fromChatColor(ChatColor.MAGIC)).replaceAll("&l", fromChatColor(ChatColor.BOLD)).replaceAll("&m", fromChatColor(ChatColor.STRIKETHROUGH)) + .replaceAll("&n", fromChatColor(ChatColor.UNDERLINE)).replaceAll("&o", fromChatColor(ChatColor.ITALIC)).replaceAll("&r", fromChatColor(ChatColor.RESET)); + return input + "\u001B[0m"; } /* @@ -72,12 +44,6 @@ public class ConsoleColors { * = "\033[3m]"; */ - public static String fromString(String input) { - input = input.replaceAll("&0", fromChatColor(ChatColor.BLACK)).replaceAll("&1", fromChatColor(ChatColor.DARK_BLUE)).replaceAll("&2", fromChatColor(ChatColor.DARK_GREEN)).replaceAll("&3", fromChatColor(ChatColor.DARK_AQUA)).replaceAll("&4", fromChatColor(ChatColor.DARK_RED)).replaceAll("&5", fromChatColor(ChatColor.DARK_PURPLE)).replaceAll("&6", fromChatColor(ChatColor.GOLD)).replaceAll("&7", fromChatColor(ChatColor.GRAY)).replaceAll("&8", fromChatColor(ChatColor.DARK_GRAY)).replaceAll("&9", fromChatColor(ChatColor.BLUE)).replaceAll("&a", fromChatColor(ChatColor.GREEN)).replaceAll("&b", fromChatColor(ChatColor.AQUA)).replaceAll("&c", fromChatColor(ChatColor.RED)).replaceAll("&d", fromChatColor(ChatColor.LIGHT_PURPLE)).replaceAll("&e", fromChatColor(ChatColor.YELLOW)).replaceAll("&f", fromChatColor(ChatColor.WHITE)).replaceAll("&k", fromChatColor(ChatColor.MAGIC)).replaceAll("&l", fromChatColor(ChatColor.BOLD)).replaceAll("&m", fromChatColor(ChatColor.STRIKETHROUGH)) - .replaceAll("&n", fromChatColor(ChatColor.UNDERLINE)).replaceAll("&o", fromChatColor(ChatColor.ITALIC)).replaceAll("&r", fromChatColor(ChatColor.RESET)); - return input + "\u001B[0m"; - } - public static String fromChatColor(final ChatColor color) { return chatColor(color).getLin(); } @@ -119,4 +85,36 @@ public class ConsoleColors { return ConsoleColor.RESET; } } + + static enum ConsoleColor { + RESET("\u001B[0m"), + BLACK("\u001B[30m"), + RED("\u001B[31m"), + GREEN("\u001B[32m"), + YELLOW("\u001B[33m"), + BLUE("\u001B[34m"), + PURPLE("\u001B[35m"), + CYAN("\u001B[36m"), + WHITE("\u001B[37m"), + BOLD("\033[1m"), + UNDERLINE("\033[0m"), + ITALIC("\033[3m"); + + private final String win; + private final String lin; + + ConsoleColor(final String lin) { + this.lin = lin; + this.win = lin; + } + + @SuppressWarnings("unused") + public String getWin() { + return this.win; + } + + public String getLin() { + return this.lin; + } + } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/FlagManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/FlagManager.java index 9fc9bc45d..af93135e3 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/FlagManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/FlagManager.java @@ -27,28 +27,30 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; +/** + * Flag Manager Utility + * + * @author Citymonstret + * @author Empire92 + */ +@SuppressWarnings("unused") public class FlagManager { // TODO add some flags // - Plot clear interval // - Mob cap // - customized plot composition - // - greeting / leaving message - // OR in the flag command, allow users to set worldguard flags. - private static ArrayList flags = new ArrayList(); + private static ArrayList flags = new ArrayList<>(); /** * Register an AbstractFlag with PlotSquared * - * @param flag - * @return + * @param flag Flag to register + * @return success? */ public static boolean addFlag(final AbstractFlag flag) { - if (getFlag(flag.getKey()) != null) { - return false; - } - return flags.add(flag); + return getFlag(flag.getKey()) == null && flags.add(flag); } public static Flag[] removeFlag(final Flag[] flags, final String r) { @@ -101,7 +103,7 @@ public class FlagManager { /** * Get an AbstractFlag by a string Returns null if flag does not exist * - * @param string + * @param string Flag Key * @return AbstractFlag */ public static AbstractFlag getFlag(final String string) { @@ -116,7 +118,7 @@ public class FlagManager { /** * Get an AbstractFlag by a string * - * @param string + * @param string Flag Key * @param create If to create the flag if it does not exist * @return AbstractFlag */ @@ -132,7 +134,7 @@ public class FlagManager { /** * Remove a registered AbstractFlag * - * @param flag + * @param flag Flag Key * @return boolean Result of operation */ public static boolean removeFlag(final AbstractFlag flag) { @@ -155,7 +157,7 @@ public class FlagManager { /** * Get the flags for a plot * - * @param plot + * @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/PlayerFunctions.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlayerFunctions.java index e6176868e..d69608228 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlayerFunctions.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlayerFunctions.java @@ -55,8 +55,8 @@ public class PlayerFunctions { return (lp - cu) > 30l; } - public static ArrayList getPlotSelectionIds(final World world, final PlotId pos1, final PlotId pos2) { - final ArrayList myplots = new ArrayList(); + public static ArrayList getPlotSelectionIds(@SuppressWarnings("unused") final World world, final PlotId pos1, final PlotId pos2) { + final ArrayList myplots = new ArrayList<>(); for (int x = pos1.x; x <= pos2.x; x++) { for (int y = pos1.y; y <= pos2.y; y++) { myplots.add(new PlotId(x, y)); @@ -78,7 +78,7 @@ public class PlayerFunctions { pos2 = getTopPlot(world, plot2).id; } - final ArrayList myplots = new ArrayList(); + final ArrayList myplots = new ArrayList<>(); for (int x = pos1.x; x <= pos2.x; x++) { for (int y = pos1.y; y <= pos2.y; y++) { myplots.add(new PlotId(x, y)); @@ -193,7 +193,7 @@ public class PlayerFunctions { public static Set getPlayerPlots(final World world, final Player plr) { final Set p = PlotMain.getPlots(world, plr); if (p == null) { - return new HashSet(); + return new HashSet<>(); } return p; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/Plot.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/Plot.java index d57649f3d..88b3b04c5 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/Plot.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/Plot.java @@ -97,7 +97,7 @@ public class Plot implements Cloneable { this.deny_entry = this.owner == null; this.helpers = helpers; this.denied = denied; - this.trusted = new ArrayList(); + this.trusted = new ArrayList<>(); this.settings.setAlias(""); this.settings.setPosition(PlotHomePosition.DEFAULT); this.delete = false; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSelection.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSelection.java index f1acfbe9c..f556c52dd 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSelection.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSelection.java @@ -29,8 +29,11 @@ import org.bukkit.block.Block; import java.util.HashMap; /** - * Created by Citymonstret on 2014-10-12. + * Created 2014-10-12 for PlotSquared + * + * @author Citymonstret */ +@SuppressWarnings("deprecation") public class PlotSelection { public static HashMap currentSelection = new HashMap<>(); @@ -68,18 +71,6 @@ public class PlotSelection { // Yay :D } - public PlotBlock[] getBlocks() { - return this.plotBlocks; - } - - public int getWidth() { - return this.width; - } - - public Plot getPlot() { - return this.plot; - } - public static boolean swap(final World world, final PlotId id1, final PlotId id2) { final Location bot2 = PlotHelper.getPlotBottomLocAbs(world, id2).add(1, 0, 1); @@ -133,6 +124,18 @@ public class PlotSelection { return new BlockWrapper(block.getX(), block.getY(), block.getZ(), (short) block.getTypeId(), block.getData()); } + public PlotBlock[] getBlocks() { + return this.plotBlocks; + } + + public int getWidth() { + return this.width; + } + + public Plot getPlot() { + return this.plot; + } + public void paste(final World world, final Plot plot) { final Location bot = PlotHelper.getPlotBottomLocAbs(world, plot.getId()), top = PlotHelper.getPlotTopLocAbs(world, plot.getId());