From 980499a193dc713bb8279bd7ef1c9a2a520299e4 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Fri, 3 Oct 2014 12:36:30 +1000 Subject: [PATCH] Time for our weekly code cleanup! Please tell me if doing this annoys you. --- .../plot/AbstractFlag.java | 8 +- .../src/com/intellectualcrafters/plot/C.java | 34 +- .../com/intellectualcrafters/plot/Flag.java | 17 +- .../plot/FlagManager.java | 27 +- .../com/intellectualcrafters/plot/PWE.java | 56 +-- .../plot/PlayerFunctions.java | 106 ++-- .../com/intellectualcrafters/plot/Plot.java | 7 +- .../intellectualcrafters/plot/PlotHelper.java | 281 ++++++----- .../com/intellectualcrafters/plot/PlotId.java | 9 +- .../intellectualcrafters/plot/PlotMain.java | 277 ++++++---- .../plot/PlotSettings.java | 20 +- .../plot/PlotSquaredException.java | 4 +- .../intellectualcrafters/plot/PlotWorld.java | 45 +- .../plot/SetBlockFast.java | 4 +- .../intellectualcrafters/plot/Settings.java | 5 +- .../plot/WorldGenerator.java | 65 ++- .../intellectualcrafters/plot/XPopulator.java | 13 +- .../plot/api/PlotAPI.java | 1 - .../plot/commands/Auto.java | 50 +- .../plot/commands/Claim.java | 32 +- .../plot/commands/Clear.java | 5 +- .../plot/commands/Command.java | 25 +- .../plot/commands/Copy.java | 5 +- .../plot/commands/Debug.java | 13 +- .../plot/commands/Delete.java | 2 +- .../plot/commands/Home.java | 1 + .../plot/commands/Info.java | 26 +- .../plot/commands/Kick.java | 11 +- .../plot/commands/Merge.java | 103 ++-- .../plot/commands/Rate.java | 30 +- .../plot/commands/Set.java | 471 +++++++++--------- .../plot/commands/Setup.java | 183 +++---- .../plot/commands/SubCommand.java | 3 +- .../plot/commands/TP.java | 8 +- .../plot/commands/Unlink.java | 137 ++--- .../plot/commands/Visit.java | 13 +- .../plot/database/DBFunc.java | 108 ++-- .../plot/database/PlotMeConverter.java | 102 ++-- .../plot/events/PlayerClaimPlotEvent.java | 4 +- .../plot/events/PlayerEnterPlotEvent.java | 2 + .../plot/events/PlayerLeavePlotEvent.java | 6 +- .../plot/events/PlayerPlotDeniedEvent.java | 12 +- .../plot/events/PlayerPlotHelperEvent.java | 13 +- .../plot/events/PlayerPlotTrustedEvent.java | 13 +- .../events/PlayerTeleportToPlotEvent.java | 5 + .../plot/events/PlotClearEvent.java | 4 + .../plot/events/PlotDeleteEvent.java | 4 + .../plot/events/PlotFlagAddEvent.java | 3 + .../plot/events/PlotFlagRemoveEvent.java | 7 +- .../plot/events/PlotMergeEvent.java | 13 +- .../plot/events/PlotUnlinkEvent.java | 10 +- .../plot/listeners/PlayerEvents.java | 15 +- .../plot/listeners/WorldEditListener.java | 12 +- .../plot/listeners/WorldGuardListener.java | 120 +++-- .../com/intellectualsites/web/PlotWeb.java | 2 +- 55 files changed, 1366 insertions(+), 1186 deletions(-) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/AbstractFlag.java b/PlotSquared/src/com/intellectualcrafters/plot/AbstractFlag.java index 684488cdc..246591f13 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/AbstractFlag.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/AbstractFlag.java @@ -11,8 +11,10 @@ public class AbstractFlag { /** * AbstractFlag is a parameter used in creating a new Flag + * * @param key - * The key must be alphabetical characters and <= 16 characters in length + * The key must be alphabetical characters and <= 16 characters + * in length */ public AbstractFlag(String key) { if (!StringUtils.isAlpha(key)) { @@ -23,14 +25,16 @@ public class AbstractFlag { } this.key = key.toLowerCase(); } + /** * AbstractFlag key + * * @return String */ public String getKey() { return this.key; } - + @Override public String toString() { return this.key; diff --git a/PlotSquared/src/com/intellectualcrafters/plot/C.java b/PlotSquared/src/com/intellectualcrafters/plot/C.java index 4f050e645..94b085059 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/C.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/C.java @@ -21,27 +21,15 @@ public enum C { /* * Ratings */ - RATING_NOT_VALID("&cYou need to specify a number between 1 and 10"), - RATING_ALREADY_EXISTS("&cYou have already rated plot &c%s"), - RATING_APPLIED("&cYou successfully rated plot &6%s"), - RATING_NOT_YOUR_OWN("&cYou cannot rate your own plot"), - RATING_NOT_OWNED("&cYou cannot rate a plot that is not claimed by anyone"), + RATING_NOT_VALID("&cYou need to specify a number between 1 and 10"), RATING_ALREADY_EXISTS("&cYou have already rated plot &c%s"), RATING_APPLIED("&cYou successfully rated plot &6%s"), RATING_NOT_YOUR_OWN("&cYou cannot rate your own plot"), RATING_NOT_OWNED("&cYou cannot rate a plot that is not claimed by anyone"), /* * Economy Stuff */ - CANNOT_AFFORD_PLOT("&cYou cannot afford to buy this plot. It costs &6%s"), - CANNOT_AFFORD_MERGE("&cYou cannot afford to merge the plots. It costs &6%s"), - REMOVED_BALANCE("&6%s &chas been taken from your balance"), + CANNOT_AFFORD_PLOT("&cYou cannot afford to buy this plot. It costs &6%s"), CANNOT_AFFORD_MERGE("&cYou cannot afford to merge the plots. It costs &6%s"), REMOVED_BALANCE("&6%s &chas been taken from your balance"), /* * Setup Stuff */ - SETUP_INIT("&6PlotSquared Setup -> Setup a new plotworld"), - SETUP_STEP("&cStep &6%s&c: %s &c"), - SETUP_INVALID_ARG("&c%s is not a valid argument for step %s. To cancel setup use: /plot setup cancel"), - SETUP_VALID_ARG("&cValue &6%s &cset for step %s"), - SETUP_FINISHED("&cFinished setup for world &c%s.\n&4If you are using MULTIVERSE or MULTIWORLD you will need to import this world. Otherwise you will need to add this world to the 'bukkit.yml' file (See installation tutorial for more info)"), - SETUP_WORLD_TAKEN("&c%s is already a registered plotworld"), - SETUP_MISSING_WORLD("&cYou need to specify a world name (&6/p setup {world}&c)\n&6Additional commands:\n&c - &6/p setup \n&c - &6/p setup back\n&c - &6/p setup cancel"), + SETUP_INIT("&6PlotSquared Setup -> Setup a new plotworld"), SETUP_STEP("&cStep &6%s&c: %s &c"), SETUP_INVALID_ARG("&c%s is not a valid argument for step %s. To cancel setup use: /plot setup cancel"), SETUP_VALID_ARG("&cValue &6%s &cset for step %s"), SETUP_FINISHED("&cFinished setup for world &c%s.\n&4If you are using MULTIVERSE or MULTIWORLD you will need to import this world. Otherwise you will need to add this world to the 'bukkit.yml' file (See installation tutorial for more info)"), SETUP_WORLD_TAKEN("&c%s is already a registered plotworld"), SETUP_MISSING_WORLD("&cYou need to specify a world name (&6/p setup {world}&c)\n&6Additional commands:\n&c - &6/p setup \n&c - &6/p setup back\n&c - &6/p setup cancel"), /* * Schematic Stuff */ @@ -77,11 +65,9 @@ public enum C { /* * Permission */ - NO_SCHEMATIC_PERMISSION("&cYou don't have the permission required to use schematic &6%s"), - NO_PERMISSION("&cYou don't have the permissions required to use this command."), NO_PLOT_PERMS("&cYou don't have the permissions to do that in this plot"), CANT_CLAIM_MORE_PLOTS("&cYou can't claim more plots."), YOU_BE_DENIED("&cYou are not allowed to enter this plot"), + NO_SCHEMATIC_PERMISSION("&cYou don't have the permission required to use schematic &6%s"), NO_PERMISSION("&cYou don't have the permissions required to use this command."), NO_PLOT_PERMS("&cYou don't have the permissions to do that in this plot"), CANT_CLAIM_MORE_PLOTS("&cYou can't claim more plots."), YOU_BE_DENIED("&cYou are not allowed to enter this plot"), - NO_PERM_MERGE("&cYou are not the owner of the plot: &6%plot%"), UNLINK_REQUIRED("&cAn unlink is required to do this."), UNLINK_IMPOSSIBLE("&cYou can only unlink a mega-plot"), - NO_MERGE_TO_MEGA("&cMega plots cannot be merged into. Please merge from the desired mega plot."), + NO_PERM_MERGE("&cYou are not the owner of the plot: &6%plot%"), UNLINK_REQUIRED("&cAn unlink is required to do this."), UNLINK_IMPOSSIBLE("&cYou can only unlink a mega-plot"), NO_MERGE_TO_MEGA("&cMega plots cannot be merged into. Please merge from the desired mega plot."), /* * Commands */ @@ -223,13 +209,13 @@ public enum C { /** * Constructor - * + * * @param d * default */ C(String d) { this.d = d; - if(PlotMain.translations == null) { + if (PlotMain.translations == null) { this.s = d; } else { this.s = PlotMain.translations.getString(this.toString()); @@ -241,7 +227,7 @@ public enum C { /** * Get the default string - * + * * @return default */ @SuppressWarnings("unused") @@ -251,7 +237,7 @@ public enum C { /** * Get translated if exists - * + * * @return translated if exists else default */ public String s() { @@ -262,7 +248,7 @@ public enum C { } /** - * + * * @return translated and color decoded */ public String translated() { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/Flag.java b/PlotSquared/src/com/intellectualcrafters/plot/Flag.java index 19e98b3dd..0cb83b667 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/Flag.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/Flag.java @@ -8,15 +8,17 @@ public class Flag { private 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. + * 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 + * AbstractFlag * @param value - * Value must be alphanumerical (can have spaces) and be <= 48 characters - * @throws IllegalArgumentException if you provide inadequate inputs + * Value must be alphanumerical (can have spaces) and be <= 48 + * characters + * @throws IllegalArgumentException + * if you provide inadequate inputs */ public Flag(AbstractFlag key, String value) { if (!StringUtils.isAlphanumericSpace(ChatColor.stripColor(value))) { @@ -31,6 +33,7 @@ public class Flag { /** * Get the AbstractFlag used in creating the flag + * * @return AbstractFlag */ public AbstractFlag getAbstractFlag() { @@ -39,6 +42,7 @@ public class Flag { /** * Get the key for the AbstractFlag + * * @return String */ public String getKey() { @@ -47,6 +51,7 @@ public class Flag { /** * Get the value + * * @return String */ public String getValue() { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/FlagManager.java b/PlotSquared/src/com/intellectualcrafters/plot/FlagManager.java index 6b8e962cc..e7681bf3c 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/FlagManager.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/FlagManager.java @@ -5,18 +5,19 @@ import java.util.List; import java.util.Set; 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. + // - 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(); /** * Register an AbstractFlag with PlotSquared + * * @param flag * @return */ @@ -29,6 +30,7 @@ public class FlagManager { /** * Get a list of registered AbstractFlag objects + * * @return List (AbstractFlag) */ public static List getFlags() { @@ -36,8 +38,8 @@ public class FlagManager { } /** - * Get an AbstractFlag by a string - * Returns null if flag does not exist + * Get an AbstractFlag by a string Returns null if flag does not exist + * * @param string * @return AbstractFlag */ @@ -55,7 +57,7 @@ public class FlagManager { * * @param string * @param create - * If to create the flag if it does not exist + * If to create the flag if it does not exist * @return AbstractFlag */ public static AbstractFlag getFlag(String string, boolean create) { @@ -66,12 +68,12 @@ public class FlagManager { } return getFlag(string); } - + /** * Remove a registered AbstractFlag + * * @param flag - * @return boolean - * Result of operation + * @return boolean Result of operation */ public static boolean removeFlag(AbstractFlag flag) { return flags.remove(flag); @@ -79,6 +81,7 @@ public class FlagManager { /** * Get the flags for a plot + * * @param plot * @return List (AbstractFlag) */ diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PWE.java b/PlotSquared/src/com/intellectualcrafters/plot/PWE.java index f4fef6e42..c2cfd10b2 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PWE.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PWE.java @@ -1,12 +1,14 @@ package com.intellectualcrafters.plot; -import com.intellectualcrafters.plot.database.DBFunc; -import com.sk89q.worldedit.*; - import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; +import com.intellectualcrafters.plot.database.DBFunc; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.LocalWorld; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.bukkit.BukkitPlayer; import com.sk89q.worldedit.regions.CuboidRegion; @@ -16,7 +18,7 @@ import com.sk89q.worldedit.regions.CuboidRegion; * */ public class PWE { - + @SuppressWarnings("unused") public static void setMask(Player p, Location l) { try { @@ -26,14 +28,14 @@ public class PWE { } else { s = PlotMain.worldEdit.getSession(p); } - + PlotId id = PlayerFunctions.getPlot(l); if (id != null) { Plot plot = PlotMain.getPlots(l.getWorld()).get(id); - if (plot!=null) { + if (plot != null) { boolean r; - r = plot.getOwner() != null && plot.getOwner().equals(p.getUniqueId()); - + r = (plot.getOwner() != null) && plot.getOwner().equals(p.getUniqueId()); + if (!r) { if (p.hasPermission("plots.worldedit.member") && (plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(p.getUniqueId()))) { r = true; @@ -41,57 +43,53 @@ public class PWE { removeMask(p, s); return; } - } - else { - + } else { + World w = p.getWorld(); - + Location bloc = PlotHelper.getPlotBottomLoc(w, plot.id); Location tloc = PlotHelper.getPlotTopLoc(w, plot.id); - + Vector bvec = new Vector(bloc.getBlockX() + 1, bloc.getBlockY() + 1, bloc.getBlockZ() + 1); Vector tvec = new Vector(tloc.getBlockX(), tloc.getBlockY(), tloc.getBlockZ()); - + LocalWorld lw = PlotMain.worldEdit.wrapPlayer(p).getWorld(); - + CuboidRegion region = new CuboidRegion(lw, bvec, tvec); com.sk89q.worldedit.masks.RegionMask mask = new com.sk89q.worldedit.masks.RegionMask(region); - + s.setMask(mask); return; } } } if (noMask(s)) { - System.out.print("NONE"); BukkitPlayer plr = PlotMain.worldEdit.wrapPlayer(p); Vector p1 = new Vector(69, 69, 69), p2 = new Vector(69, 69, 69); - + s.setMask(new com.sk89q.worldedit.masks.RegionMask(new CuboidRegion(plr.getWorld(), p1, p2))); } - } catch(Exception e) { + } catch (Exception e) { throw new PlotSquaredException(PlotSquaredException.PlotError.MISSING_DEPENDENCY, "WorldEdit == Null?"); } } - + public static boolean noMask(LocalSession s) { try { com.sk89q.worldedit.masks.Mask mask = s.getMask(); - return mask==null; - } - catch (Throwable e) { + return mask == null; + } catch (Throwable e) { return true; } } - + public static void removeMask(Player p, LocalSession s) { System.out.print(0); try { System.out.print(1); s.setMask(null); System.out.print(2); - } - catch (Throwable e) { + } catch (Throwable e) { System.out.print(3); com.sk89q.worldedit.masks.Mask mask = null; s.setMask(mask); @@ -99,17 +97,17 @@ public class PWE { } System.out.print(5); } - + public static void removeMask(Player p) { try { LocalSession s; - if(PlotMain.worldEdit == null) { + if (PlotMain.worldEdit == null) { s = WorldEdit.getInstance().getSession(p.getName()); } else { s = PlotMain.worldEdit.getSession(p); } removeMask(p, s); - } catch(Exception e) { + } catch (Exception e) { throw new PlotSquaredException(PlotSquaredException.PlotError.MISSING_DEPENDENCY, "WorldEdit == Null?"); } } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java b/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java index b8c9e3b74..a22a0b9ab 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java @@ -15,7 +15,6 @@ import java.util.HashSet; import java.util.Set; import java.util.UUID; -import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; @@ -56,36 +55,38 @@ public class PlayerFunctions { long cu = System.currentTimeMillis(); return (lp - cu) > 30l; } - + public static ArrayList getPlotSelectionIds(World world, PlotId pos1, PlotId pos2) { 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)); + myplots.add(new PlotId(x, y)); } } - + return myplots; } - + public static Plot getBottomPlot(World world, Plot plot) { if (plot.settings.getMerged(0)) { - return getBottomPlot(world, PlotMain.getPlots(world).get(new PlotId(plot.id.x, plot.id.y-1))); + return getBottomPlot(world, PlotMain.getPlots(world).get(new PlotId(plot.id.x, plot.id.y - 1))); } if (plot.settings.getMerged(3)) { - return getBottomPlot(world, PlotMain.getPlots(world).get(new PlotId(plot.id.x-1, plot.id.y))); + return getBottomPlot(world, PlotMain.getPlots(world).get(new PlotId(plot.id.x - 1, plot.id.y))); } return plot; } + public static Plot getTopPlot(World world, Plot plot) { if (plot.settings.getMerged(2)) { - return getTopPlot(world, PlotMain.getPlots(world).get(new PlotId(plot.id.x, plot.id.y+1))); + return getTopPlot(world, PlotMain.getPlots(world).get(new PlotId(plot.id.x, plot.id.y + 1))); } if (plot.settings.getMerged(1)) { - return getTopPlot(world, PlotMain.getPlots(world).get(new PlotId(plot.id.x+1, plot.id.y))); + return getTopPlot(world, PlotMain.getPlots(world).get(new PlotId(plot.id.x + 1, plot.id.y))); } return plot; } + /** * * @param loc @@ -100,80 +101,78 @@ public class PlayerFunctions { int size = plotworld.PLOT_WIDTH + plotworld.ROAD_WIDTH; int pathWidthLower; if ((plotworld.ROAD_WIDTH % 2) == 0) { - pathWidthLower = (int) (Math.floor(plotworld.ROAD_WIDTH / 2)-1); - } - else { + pathWidthLower = (int) (Math.floor(plotworld.ROAD_WIDTH / 2) - 1); + } else { pathWidthLower = (int) Math.floor(plotworld.ROAD_WIDTH / 2); } - - int dx = x/size; - int dz = z/size; - if (x<0) { + int dx = x / size; + int dz = z / size; + + if (x < 0) { dx--; - x+=((-dx) * size); + x += ((-dx) * size); } - if (z<0) { + if (z < 0) { dz--; - z+=((-dz) * size); + z += ((-dz) * size); } - int rx = (x)%size; - int rz = (z)%size; - - int end = pathWidthLower+plotworld.PLOT_WIDTH; - boolean northSouth = rz<=pathWidthLower || rz>pathWidthLower+plotworld.PLOT_WIDTH; - boolean eastWest = rx<=pathWidthLower || rx>end; - + int rx = (x) % size; + int rz = (z) % size; + + int end = pathWidthLower + plotworld.PLOT_WIDTH; + boolean northSouth = (rz <= pathWidthLower) || (rz > (pathWidthLower + plotworld.PLOT_WIDTH)); + boolean eastWest = (rx <= pathWidthLower) || (rx > end); + if (northSouth || eastWest) { return null; } - return new PlotId(dx+1,dz+1); + return new PlotId(dx + 1, dz + 1); } - + public static PlotId getPlot(Location loc) { int x = loc.getBlockX(); int z = loc.getBlockZ(); String world = loc.getWorld().getName(); PlotWorld plotworld = PlotMain.getWorldSettings(world); - if (plotworld==null) { + if (plotworld == null) { return null; } int size = plotworld.PLOT_WIDTH + plotworld.ROAD_WIDTH; int pathWidthLower; if ((plotworld.ROAD_WIDTH % 2) == 0) { - pathWidthLower = (int) (Math.floor(plotworld.ROAD_WIDTH / 2)-1); - } - else { + pathWidthLower = (int) (Math.floor(plotworld.ROAD_WIDTH / 2) - 1); + } else { pathWidthLower = (int) Math.floor(plotworld.ROAD_WIDTH / 2); } - - int dx = x/size; - int dz = z/size; - if (x<0) { + int dx = x / size; + int dz = z / size; + + if (x < 0) { dx--; - x+=((-dx) * size); + x += ((-dx) * size); } - if (z<0) { + if (z < 0) { dz--; - z+=((-dz) * size); + z += ((-dz) * size); } - int rx = (x)%size; - int rz = (z)%size; - - int end = pathWidthLower+plotworld.PLOT_WIDTH; - - boolean northSouth = rz<=pathWidthLower || rz>pathWidthLower+plotworld.PLOT_WIDTH; - boolean eastWest = rx<=pathWidthLower || rx>end; - + int rx = (x) % size; + int rz = (z) % size; + + int end = pathWidthLower + plotworld.PLOT_WIDTH; + + boolean northSouth = (rz <= pathWidthLower) || (rz > (pathWidthLower + plotworld.PLOT_WIDTH)); + boolean eastWest = (rx <= pathWidthLower) || (rx > end); + if (northSouth && eastWest) { // This means you are in the intersection PlotId id = getPlotAbs(loc.add(plotworld.ROAD_WIDTH, 0, plotworld.ROAD_WIDTH)); Plot plot = PlotMain.getPlots(loc.getWorld()).get(id); - if (plot==null) { + if (plot == null) { return null; } if ((plot.settings.getMerged(0) && plot.settings.getMerged(3))) { @@ -182,10 +181,11 @@ public class PlayerFunctions { return null; } if (northSouth) { - // You are on a road running West to East (yeah, I named the var poorly) + // You are on a road running West to East (yeah, I named the var + // poorly) PlotId id = getPlotAbs(loc.add(0, 0, plotworld.ROAD_WIDTH)); Plot plot = PlotMain.getPlots(loc.getWorld()).get(id); - if (plot==null) { + if (plot == null) { return null; } if (plot.settings.getMerged(0)) { @@ -197,7 +197,7 @@ public class PlayerFunctions { // This is the road separating an Eastern and Western plot PlotId id = getPlotAbs(loc.add(plotworld.ROAD_WIDTH, 0, 0)); Plot plot = PlotMain.getPlots(loc.getWorld()).get(id); - if (plot==null) { + if (plot == null) { return null; } if (plot.settings.getMerged(3)) { @@ -205,9 +205,9 @@ public class PlayerFunctions { } return null; } - PlotId id = new PlotId(dx+1,dz+1); + PlotId id = new PlotId(dx + 1, dz + 1); Plot plot = PlotMain.getPlots(loc.getWorld()).get(id); - if (plot==null) { + if (plot == null) { return id; } return getBottomPlot(loc.getWorld(), plot).id; diff --git a/PlotSquared/src/com/intellectualcrafters/plot/Plot.java b/PlotSquared/src/com/intellectualcrafters/plot/Plot.java index e52f23e3d..beeb81be1 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/Plot.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/Plot.java @@ -106,7 +106,7 @@ public class Plot implements Cloneable { * @param denied * @param changeTime * @param time - * @param merged + * @param merged */ public Plot(PlotId id, UUID owner, Biome plotBiome, ArrayList helpers, ArrayList trusted, ArrayList denied, boolean changeTime, long time, boolean rain, String alias, PlotHomePosition position, Flag[] flags, String world, boolean[] merged) { this.id = id; @@ -157,7 +157,7 @@ public class Plot implements Cloneable { * @return true if the player is added as a helper or is the owner */ public boolean hasRights(Player player) { - return player.hasPermission("plots.admin") || ((this.helpers != null) && this.helpers.contains(DBFunc.everyone)) || ((this.helpers != null) && this.helpers.contains(player.getUniqueId())) || ((this.owner != null) && this.owner.equals(player.getUniqueId())) || (this.owner != null && this.trusted != null && Bukkit.getPlayer(this.owner) != null && (this.trusted.contains(player.getUniqueId()) || this.trusted.contains(DBFunc.everyone))); + return player.hasPermission("plots.admin") || ((this.helpers != null) && this.helpers.contains(DBFunc.everyone)) || ((this.helpers != null) && this.helpers.contains(player.getUniqueId())) || ((this.owner != null) && this.owner.equals(player.getUniqueId())) || ((this.owner != null) && (this.trusted != null) && (Bukkit.getPlayer(this.owner) != null) && (this.trusted.contains(player.getUniqueId()) || this.trusted.contains(DBFunc.everyone))); } /** @@ -225,7 +225,6 @@ public class Plot implements Cloneable { public void addHelper(UUID uuid) { this.helpers.add(uuid); } - /** * Add someone as a trusted user (use DBFunc as well) @@ -265,7 +264,7 @@ public class Plot implements Cloneable { public void removeHelper(UUID uuid) { this.helpers.remove(uuid); } - + /** * Remove a trusted user (use DBFunc as well) * diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java index a901f29af..0ccdd891b 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java @@ -9,8 +9,19 @@ package com.intellectualcrafters.plot; -import com.intellectualcrafters.plot.database.DBFunc; -import org.bukkit.*; +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Random; +import java.util.UUID; + +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; @@ -19,8 +30,7 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; -import java.io.File; -import java.util.*; +import com.intellectualcrafters.plot.database.DBFunc; /** * plot functions @@ -35,48 +45,51 @@ public class PlotHelper { private static double calculateNeededTime(double blocks, double blocks_per_second) { return (blocks / blocks_per_second); } - + /** * direction 0 = north, 1 = south, etc: + * * @param plot * @param direction * @return */ public static PlotId getPlotIdRelative(PlotId id, int direction) { switch (direction) { - case 0: - return new PlotId(id.x,id.y-1); - case 1: - return new PlotId(id.x+1,id.y); - case 2: - return new PlotId(id.x,id.y+1); - case 3: - return new PlotId(id.x-1,id.y); + case 0: + return new PlotId(id.x, id.y - 1); + case 1: + return new PlotId(id.x + 1, id.y); + case 2: + return new PlotId(id.x, id.y + 1); + case 3: + return new PlotId(id.x - 1, id.y); } return id; } - + /** * Completely merges a set of plots
- * (There are no checks to make sure you supply the correct arguments)
- * - Misuse of this method can result in unusable plots
- * - the set of plots must belong to one owner and be rectangular
- * - the plot array must be sorted in ascending order
- * - Road will be removed where required
- * - changes will be saved to DB
+ * (There are no checks to make sure you supply the correct + * arguments)
+ * - Misuse of this method can result in unusable plots
+ * - the set of plots must belong to one owner and be rectangular
+ * - the plot array must be sorted in ascending order
+ * - Road will be removed where required
+ * - changes will be saved to DB
+ * * @param world * @param plotIds * @return boolean (success) */ - public static boolean mergePlots(World world, ArrayList plotIds) { + public static boolean mergePlots(World world, ArrayList plotIds) { PlotWorld plotworld = PlotMain.getWorldSettings(world); int pathsize = plotworld.ROAD_WIDTH; int plotheight = plotworld.PLOT_HEIGHT; - if (plotIds.size()<2) { + if (plotIds.size() < 2) { return false; } - + final short[] plotfloors = new short[plotworld.TOP_BLOCK.length]; final short[] plotfloors_data = new short[plotworld.TOP_BLOCK.length]; @@ -93,37 +106,37 @@ public class PlotHelper { filling[i] = result[0]; filling_data[i] = result[1]; } - + PlotId pos1 = plotIds.get(0); - PlotId pos2 = plotIds.get(plotIds.size()-1); - + PlotId pos2 = plotIds.get(plotIds.size() - 1); + for (int x = pos1.x; x <= pos2.x; x++) { for (int y = pos1.y; y <= pos2.y; y++) { - + boolean lx = x < pos2.x; boolean ly = y < pos2.y; - - PlotId id = new PlotId(x,y); + + PlotId id = new PlotId(x, y); Plot plot = PlotMain.getPlots(world).get(id); - + if (lx) { if (ly) { if (!plot.settings.getMerged(1) || !plot.settings.getMerged(2)) { Location loc = getPlotTopLocAbs(world, id); - - int sx = loc.getBlockX()+1; - int ex = sx + pathsize - 1; - int sz = loc.getBlockZ()+1; - int ez = sz + pathsize - 1; - - PlotHelper.setSimpleCuboid(world, new Location(world,sx,plotheight+1,sz), new Location(world,ex+1,257+1,ez+1), (short) 0); - - PlotHelper.setCuboid(world, new Location(world,sx+1,1,sz+1), new Location(world,ex,plotheight,ez), filling,filling_data); - PlotHelper.setCuboid(world, new Location(world,sx+1,plotheight,sz+1), new Location(world,ex,plotheight+1,ez), plotfloors,plotfloors_data); + + int sx = loc.getBlockX() + 1; + int ex = (sx + pathsize) - 1; + int sz = loc.getBlockZ() + 1; + int ez = (sz + pathsize) - 1; + + PlotHelper.setSimpleCuboid(world, new Location(world, sx, plotheight + 1, sz), new Location(world, ex + 1, 257 + 1, ez + 1), (short) 0); + + PlotHelper.setCuboid(world, new Location(world, sx + 1, 1, sz + 1), new Location(world, ex, plotheight, ez), filling, filling_data); + PlotHelper.setCuboid(world, new Location(world, sx + 1, plotheight, sz + 1), new Location(world, ex, plotheight + 1, ez), plotfloors, plotfloors_data); } } if (!plot.settings.getMerged(1)) { - Plot plot2 = PlotMain.getPlots(world).get(new PlotId(x+1,y)); + Plot plot2 = PlotMain.getPlots(world).get(new PlotId(x + 1, y)); mergePlot(world, plot, plot2); plot.settings.setMerged(1, true); plot2.settings.setMerged(3, true); @@ -131,64 +144,64 @@ public class PlotHelper { } if (ly) { if (!plot.settings.getMerged(2)) { - Plot plot2 = PlotMain.getPlots(world).get(new PlotId(x,y+1)); + Plot plot2 = PlotMain.getPlots(world).get(new PlotId(x, y + 1)); mergePlot(world, plot, plot2); plot.settings.setMerged(2, true); plot2.settings.setMerged(0, true); } } - + } } - + Location megaPlotBot = getPlotBottomLoc(world, pos1); - Location megaPlotTop = getPlotTopLoc(world, pos2).add(1,0,1); - + Location megaPlotTop = getPlotTopLoc(world, pos2).add(1, 0, 1); + short[] result_w = PlotHelper.getBlock(plotworld.WALL_BLOCK); short w_id = result_w[0]; byte w_v = (byte) result_w[1]; - - for (int x = megaPlotBot.getBlockX(); x<=megaPlotTop.getBlockX(); x++) { - for (int z = megaPlotBot.getBlockZ(); z<=megaPlotTop.getBlockZ(); z++) { - if (z == megaPlotBot.getBlockZ() || z==megaPlotTop.getBlockZ() || x==megaPlotBot.getBlockX() || x==megaPlotTop.getBlockX()) { - world.getBlockAt(x, plotworld.WALL_HEIGHT+1, z).setTypeIdAndData(w_id, w_v, false); + + for (int x = megaPlotBot.getBlockX(); x <= megaPlotTop.getBlockX(); x++) { + for (int z = megaPlotBot.getBlockZ(); z <= megaPlotTop.getBlockZ(); z++) { + if ((z == megaPlotBot.getBlockZ()) || (z == megaPlotTop.getBlockZ()) || (x == megaPlotBot.getBlockX()) || (x == megaPlotTop.getBlockX())) { + world.getBlockAt(x, plotworld.WALL_HEIGHT + 1, z).setTypeIdAndData(w_id, w_v, false); } } } - + return true; } /** - * Merges 2 plots - * Removes the road inbetween - *
- Assumes the first plot parameter is lower - *
- Assumes neither are a Mega-plot - *
- Assumes plots are directly next to each other - *
- Saves to DB + * Merges 2 plots Removes the road inbetween
+ * - Assumes the first plot parameter is lower
+ * - Assumes neither are a Mega-plot
+ * - Assumes plots are directly next to each other
+ * - Saves to DB + * * @param world * @param lesserPlot * @param greaterPlot */ public static void mergePlot(World world, Plot lesserPlot, Plot greaterPlot) { - Location pos1 = getPlotBottomLocAbs(world, lesserPlot.id).add(1,0,1); + Location pos1 = getPlotBottomLocAbs(world, lesserPlot.id).add(1, 0, 1); Location pos2 = getPlotTopLocAbs(world, lesserPlot.id); - - Location pos3 = getPlotBottomLocAbs(world, greaterPlot.id).add(1,0,1); + + Location pos3 = getPlotBottomLocAbs(world, greaterPlot.id).add(1, 0, 1); Location pos4 = getPlotTopLocAbs(world, greaterPlot.id); - - int sx = Math.max(pos1.getBlockX(),pos2.getBlockX()); - int ex = Math.min(pos3.getBlockX(),pos4.getBlockX()); - int sz = Math.max(pos1.getBlockZ(),pos2.getBlockZ()); - int ez = Math.min(pos3.getBlockZ(),pos4.getBlockZ()); - - int startx = Math.min(sx,ex); - int startz = Math.min(sz,ez); - int endx = Math.max(sx,ex)+1; - int endz = Math.max(sz,ez)+1; - + + int sx = Math.max(pos1.getBlockX(), pos2.getBlockX()); + int ex = Math.min(pos3.getBlockX(), pos4.getBlockX()); + int sz = Math.max(pos1.getBlockZ(), pos2.getBlockZ()); + int ez = Math.min(pos3.getBlockZ(), pos4.getBlockZ()); + + int startx = Math.min(sx, ex); + int startz = Math.min(sz, ez); + int endx = Math.max(sx, ex) + 1; + int endz = Math.max(sz, ez) + 1; + PlotWorld plotworld = PlotMain.getWorldSettings(world); - + final short[] plotfloors = new short[plotworld.TOP_BLOCK.length]; final short[] plotfloors_data = new short[plotworld.TOP_BLOCK.length]; @@ -205,22 +218,21 @@ public class PlotHelper { filling[i] = result[0]; filling_data[i] = result[1]; } - + boolean noMerge = false; - + if (lesserPlot.id.x == greaterPlot.id.x) { - + noMerge = lesserPlot.settings.getMerged(2); - + lesserPlot.settings.setMerged(2, true); greaterPlot.settings.setMerged(0, true); startx--; endx++; - } - else { - + } else { + noMerge = lesserPlot.settings.getMerged(1); - + lesserPlot.settings.setMerged(1, true); greaterPlot.settings.setMerged(3, true); startz--; @@ -235,7 +247,7 @@ public class PlotHelper { setCuboid(world, new Location(world, startx, plotworld.PLOT_HEIGHT, startz), new Location(world, endx, plotworld.PLOT_HEIGHT + 1, endz), plotfloors, plotfloors_data); } } - + public static final long nextLong() { long a = state; state = xorShift64(a); @@ -341,44 +353,44 @@ public class PlotHelper { setWall(block, "" + id + ":" + data); } } - + public static void autoMerge(World world, Plot plot, Player player) { - if (plot==null) { + if (plot == null) { return; } - if(plot.owner==null) { + if (plot.owner == null) { return; } if (!plot.owner.equals(player.getUniqueId())) { return; } - + ArrayList plots; boolean merge = true; while (merge) { PlotId bot = PlayerFunctions.getBottomPlot(world, plot).id; PlotId top = PlayerFunctions.getTopPlot(world, plot).id; merge = false; - plots = PlayerFunctions.getPlotSelectionIds(world, new PlotId(bot.x,bot.y-1), new PlotId(top.x,top.y)); - if (ownsPlots(world,plots,player, 0)) { + plots = PlayerFunctions.getPlotSelectionIds(world, new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y)); + if (ownsPlots(world, plots, player, 0)) { merge = true; mergePlots(world, plots); continue; } - plots = PlayerFunctions.getPlotSelectionIds(world, new PlotId(bot.x,bot.y), new PlotId(top.x+1,top.y)); - if (ownsPlots(world,plots,player, 1)) { + plots = PlayerFunctions.getPlotSelectionIds(world, new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y)); + if (ownsPlots(world, plots, player, 1)) { merge = true; mergePlots(world, plots); continue; } - plots = PlayerFunctions.getPlotSelectionIds(world, new PlotId(bot.x,bot.y), new PlotId(top.x,top.y+1)); - if (ownsPlots(world,plots,player, 2)) { + plots = PlayerFunctions.getPlotSelectionIds(world, new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1)); + if (ownsPlots(world, plots, player, 2)) { merge = true; mergePlots(world, plots); continue; } - plots = PlayerFunctions.getPlotSelectionIds(world, new PlotId(bot.x-1,bot.y), new PlotId(top.x,top.y)); - if (ownsPlots(world,plots,player, 3)) { + plots = PlayerFunctions.getPlotSelectionIds(world, new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y)); + if (ownsPlots(world, plots, player, 3)) { merge = true; mergePlots(world, plots); continue; @@ -388,20 +400,21 @@ public class PlotHelper { SetBlockFast.update(player); } } + private static boolean ownsPlots(World world, ArrayList plots, Player player, int dir) { PlotId id_min = plots.get(0); - PlotId id_max = plots.get(plots.size()-1); - for (PlotId myid:plots) { + PlotId id_max = plots.get(plots.size() - 1); + for (PlotId myid : plots) { Plot myplot = PlotMain.getPlots(world).get(myid); - if (myplot==null || !myplot.hasOwner() || !(myplot.getOwner().equals(player.getUniqueId()))) { + if ((myplot == null) || !myplot.hasOwner() || !(myplot.getOwner().equals(player.getUniqueId()))) { return false; } PlotId top = PlayerFunctions.getTopPlot(world, myplot).id; - if ((top.x > id_max.x && dir != 1) || (top.y > id_max.y && dir != 2)) { + if (((top.x > id_max.x) && (dir != 1)) || ((top.y > id_max.y) && (dir != 2))) { return false; } PlotId bot = PlayerFunctions.getBottomPlot(world, myplot).id; - if ((bot.x < id_min.x && dir != 3) || (bot.y < id_min.y && dir != 0)) { + if (((bot.x < id_min.x) && (dir != 3)) || ((bot.y < id_min.y) && (dir != 0))) { return false; } } @@ -419,7 +432,7 @@ public class PlotHelper { if (plotworld.AUTO_MERGE) { autoMerge(w, p, player); } - + return true; } @@ -441,7 +454,7 @@ public class PlotHelper { } public static double getWorldFolderSize(World world) { - //long size = FileUtil.sizeOfDirectory(world.getWorldFolder()); + // long size = FileUtil.sizeOfDirectory(world.getWorldFolder()); File folder = world.getWorldFolder(); long size = folder.length(); return (((size) / 1024) / 1024); @@ -729,12 +742,12 @@ public class PlotHelper { public static void teleportPlayers(World world, Plot plot, boolean tile) { final Location pos1 = getPlotBottomLoc(world, plot.id).add(1, 0, 1); final Location pos2 = getPlotTopLoc(world, plot.id); - for (int i = (pos2.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) { + for (int i = (pos2.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) { Chunk chunk = world.getChunkAt(i, j); for (Entity entity : chunk.getEntities()) { PlotId id = PlayerFunctions.getPlot(entity.getLocation()); - if(id != null && id.equals(plot.id) && entity.getType() == EntityType.PLAYER) { + if ((id != null) && id.equals(plot.id) && (entity.getType() == EntityType.PLAYER)) { entity.teleport(world.getSpawnLocation()); // Should this teleport them to floor instead? } @@ -742,29 +755,31 @@ public class PlotHelper { } } } - public static void clearAllEntities(World world, Plot plot, boolean tile) { + + public static void clearAllEntities(World world, Plot plot, boolean tile) { final Location pos1 = getPlotBottomLoc(world, plot.id).add(1, 0, 1); final Location pos2 = getPlotTopLoc(world, plot.id); - 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) { + 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) { Chunk chunk = world.getChunkAt(i, j); - for (Entity entity:chunk.getEntities()) { + for (Entity entity : chunk.getEntities()) { PlotId id = PlayerFunctions.getPlot(entity.getLocation()); - if (id!=null && id.equals(plot.id)) { + if ((id != null) && id.equals(plot.id)) { entity.remove(); } } if (tile) { - for (BlockState entity:chunk.getTileEntities()) { + for (BlockState entity : chunk.getTileEntities()) { entity.setRawData((byte) 0); } } } } } - + /** * Clear a plot + * * @param requester * @param plot */ @@ -772,10 +787,10 @@ public class PlotHelper { final long start = System.nanoTime(); final World world = requester.getWorld(); - + // clear entities: clearAllEntities(world, plot, false); - //teleport players + // teleport players teleportPlayers(world, plot, false); final PlotWorld plotworld = PlotMain.getWorldSettings(world); @@ -783,7 +798,7 @@ public class PlotHelper { PlayerFunctions.sendMessage(requester, C.CLEARING_PLOT); final Location pos1 = getPlotBottomLoc(world, plot.id).add(1, 0, 1); final Location pos2 = getPlotTopLoc(world, plot.id); - + final short[] plotfloors = new short[plotworld.TOP_BLOCK.length]; final short[] plotfloors_data = new short[plotworld.TOP_BLOCK.length]; @@ -856,7 +871,7 @@ public class PlotHelper { world.regenerateChunk(i / 16, j / 16); } } - + if (min == null) { setSimpleCuboid(world, new Location(world, pos1.getBlockX(), 0, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, 1, pos2.getBlockZ() + 1), (short) 7); setSimpleCuboid(world, new Location(world, pos1.getBlockX(), plotworld.PLOT_HEIGHT + 1, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, world.getMaxHeight() + 1, pos2.getBlockZ() + 1), (short) 0); @@ -867,37 +882,37 @@ public class PlotHelper { setSimpleCuboid(world, new Location(world, plotMinX, plotworld.PLOT_HEIGHT + 1, plotMinZ), new Location(world, min.getBlockX() + 1, world.getMaxHeight() + 1, min.getBlockZ() + 1), (short) 0); setCuboid(world, new Location(world, plotMinX, 1, plotMinZ), new Location(world, min.getBlockX() + 1, plotworld.PLOT_HEIGHT + 1, min.getBlockZ() + 1), filling, filling_data); setCuboid(world, new Location(world, plotMinX, plotworld.PLOT_HEIGHT, plotMinZ), new Location(world, min.getBlockX() + 1, plotworld.PLOT_HEIGHT + 1, min.getBlockZ() + 1), plotfloors, plotfloors_data); - + setSimpleCuboid(world, new Location(world, min.getBlockX(), 0, plotMinZ), new Location(world, max.getBlockX() + 1, 1, min.getBlockZ() + 1), (short) 7); setSimpleCuboid(world, new Location(world, min.getBlockX(), plotworld.PLOT_HEIGHT + 1, plotMinZ), new Location(world, max.getBlockX() + 1, world.getMaxHeight() + 1, min.getBlockZ() + 1), (short) 0); setCuboid(world, new Location(world, min.getBlockX(), 1, plotMinZ), new Location(world, max.getBlockX() + 1, plotworld.PLOT_HEIGHT, min.getBlockZ() + 1), filling, filling_data); setCuboid(world, new Location(world, min.getBlockX(), plotworld.PLOT_HEIGHT, plotMinZ), new Location(world, max.getBlockX() + 1, plotworld.PLOT_HEIGHT + 1, min.getBlockZ() + 1), plotfloors, plotfloors_data); - + setSimpleCuboid(world, new Location(world, max.getBlockX(), 0, plotMinZ), new Location(world, plotMaxX + 1, 1, min.getBlockZ() + 1), (short) 7); setSimpleCuboid(world, new Location(world, max.getBlockX(), plotworld.PLOT_HEIGHT + 1, plotMinZ), new Location(world, plotMaxX + 1, world.getMaxHeight() + 1, min.getBlockZ() + 1), (short) 0); setCuboid(world, new Location(world, max.getBlockX(), 1, plotMinZ), new Location(world, plotMaxX + 1, plotworld.PLOT_HEIGHT, min.getBlockZ() + 1), filling, filling_data); setCuboid(world, new Location(world, max.getBlockX(), plotworld.PLOT_HEIGHT, plotMinZ), new Location(world, plotMaxX + 1, plotworld.PLOT_HEIGHT + 1, min.getBlockZ() + 1), plotfloors, plotfloors_data); - + setSimpleCuboid(world, new Location(world, plotMinX, 0, min.getBlockZ()), new Location(world, min.getBlockX() + 1, 1, max.getBlockZ() + 1), (short) 7); setSimpleCuboid(world, new Location(world, plotMinX, plotworld.PLOT_HEIGHT + 1, min.getBlockZ()), new Location(world, min.getBlockX() + 1, world.getMaxHeight() + 1, max.getBlockZ() + 1), (short) 0); setCuboid(world, new Location(world, plotMinX, 1, min.getBlockZ()), new Location(world, min.getBlockX() + 1, plotworld.PLOT_HEIGHT, max.getBlockZ() + 1), filling, filling_data); setCuboid(world, new Location(world, plotMinX, plotworld.PLOT_HEIGHT, min.getBlockZ()), new Location(world, min.getBlockX() + 1, plotworld.PLOT_HEIGHT + 1, max.getBlockZ() + 1), plotfloors, plotfloors_data); - + setSimpleCuboid(world, new Location(world, plotMinX, 0, max.getBlockZ()), new Location(world, min.getBlockX() + 1, 1, plotMaxZ + 1), (short) 7); setSimpleCuboid(world, new Location(world, plotMinX, plotworld.PLOT_HEIGHT + 1, max.getBlockZ()), new Location(world, min.getBlockX() + 1, world.getMaxHeight() + 1, plotMaxZ + 1), (short) 0); setCuboid(world, new Location(world, plotMinX, 1, max.getBlockZ()), new Location(world, min.getBlockX() + 1, plotworld.PLOT_HEIGHT, plotMaxZ + 1), filling, filling_data); setCuboid(world, new Location(world, plotMinX, plotworld.PLOT_HEIGHT, max.getBlockZ()), new Location(world, min.getBlockX() + 1, plotworld.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloors, plotfloors_data); - + setSimpleCuboid(world, new Location(world, min.getBlockX(), 0, max.getBlockZ()), new Location(world, max.getBlockX() + 1, 1, plotMaxZ + 1), (short) 7); setSimpleCuboid(world, new Location(world, min.getBlockX(), plotworld.PLOT_HEIGHT + 1, max.getBlockZ()), new Location(world, max.getBlockX() + 1, world.getMaxHeight() + 1, plotMaxZ + 1), (short) 0); setCuboid(world, new Location(world, min.getBlockX(), 1, max.getBlockZ()), new Location(world, max.getBlockX() + 1, plotworld.PLOT_HEIGHT, plotMaxZ + 1), filling, filling_data); setCuboid(world, new Location(world, min.getBlockX(), plotworld.PLOT_HEIGHT, max.getBlockZ()), new Location(world, max.getBlockX() + 1, plotworld.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloors, plotfloors_data); - + setSimpleCuboid(world, new Location(world, max.getBlockX(), 0, min.getBlockZ()), new Location(world, plotMaxX + 1, 1, max.getBlockZ() + 1), (short) 7); setSimpleCuboid(world, new Location(world, max.getBlockX(), plotworld.PLOT_HEIGHT + 1, max.getBlockZ()), new Location(world, plotMaxX + 1, world.getMaxHeight() + 1, plotMaxZ + 1), (short) 0); setCuboid(world, new Location(world, max.getBlockX(), 1, min.getBlockZ()), new Location(world, plotMaxX + 1, plotworld.PLOT_HEIGHT, max.getBlockZ() + 1), filling, filling_data); setCuboid(world, new Location(world, max.getBlockX(), plotworld.PLOT_HEIGHT, min.getBlockZ()), new Location(world, plotMaxX + 1, plotworld.PLOT_HEIGHT + 1, max.getBlockZ() + 1), plotfloors, plotfloors_data); - + setSimpleCuboid(world, new Location(world, max.getBlockX(), 0, max.getBlockZ()), new Location(world, plotMaxX + 1, 1, plotMaxZ + 1), (short) 7); setSimpleCuboid(world, new Location(world, max.getBlockX(), plotworld.PLOT_HEIGHT + 1, max.getBlockZ()), new Location(world, plotMaxX + 1, world.getMaxHeight() + 1, plotMaxZ + 1), (short) 0); setCuboid(world, new Location(world, max.getBlockX(), 1, max.getBlockZ()), new Location(world, plotMaxX + 1, plotworld.PLOT_HEIGHT, plotMaxZ + 1), filling, filling_data); @@ -925,8 +940,7 @@ public class PlotHelper { } } } - } - else { + } else { try { for (int y = pos1.getBlockY(); y < pos2.getBlockY(); y++) { for (int x = pos1.getBlockX(); x < pos2.getBlockX(); x++) { @@ -941,8 +955,7 @@ public class PlotHelper { } } } - } - catch (Exception e) { + } catch (Exception e) { } } } @@ -959,8 +972,7 @@ public class PlotHelper { } } } - } - else { + } else { try { for (int y = pos1.getBlockY(); y < pos2.getBlockY(); y++) { for (int x = pos1.getBlockX(); x < pos2.getBlockX(); x++) { @@ -972,9 +984,8 @@ public class PlotHelper { } } } - } - catch (Exception e) { - + } catch (Exception e) { + } } } @@ -1074,7 +1085,7 @@ public class PlotHelper { return new Location(world, x, 255, z); } - + public static Location getPlotBottomLocAbs(World world, PlotId id) { PlotWorld plotworld = PlotMain.getWorldSettings(world); int px = id.x; @@ -1085,10 +1096,10 @@ public class PlotHelper { return new Location(world, x, 1, z); } - + public static Location getPlotTopLoc(World world, PlotId id) { Plot plot = PlotMain.getPlots(world).get(id); - if (plot!=null) { + if (plot != null) { id = PlayerFunctions.getTopPlot(world, plot).id; } PlotWorld plotworld = PlotMain.getWorldSettings(world); @@ -1103,7 +1114,7 @@ public class PlotHelper { public static Location getPlotBottomLoc(World world, PlotId id) { Plot plot = PlotMain.getPlots(world).get(id); - if (plot!=null) { + if (plot != null) { id = PlayerFunctions.getBottomPlot(world, plot).id; } PlotWorld plotworld = PlotMain.getWorldSettings(world); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotId.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotId.java index 312324fd4..eeedb0b2c 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotId.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotId.java @@ -12,10 +12,11 @@ public class PlotId { /** * PlotId class (PlotId x,y values do not correspond to Block locations) + * * @param x - * The plot x coordinate + * The plot x coordinate * @param y - * The plot y coordinate + * The plot y coordinate */ public PlotId(int x, int y) { this.x = x; @@ -36,10 +37,10 @@ public class PlotId { PlotId other = (PlotId) obj; return ((this.x == other.x) && (this.y == other.y)); } - + @Override public String toString() { - return this.x+";"+this.y; + return this.x + ";" + this.y; } @Override diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java index 0af961899..5f2e8aea3 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java @@ -9,6 +9,126 @@ package com.intellectualcrafters.plot; +import static org.bukkit.Material.ACACIA_STAIRS; +import static org.bukkit.Material.BEACON; +import static org.bukkit.Material.BEDROCK; +import static org.bukkit.Material.BIRCH_WOOD_STAIRS; +import static org.bukkit.Material.BOOKSHELF; +import static org.bukkit.Material.BREWING_STAND; +import static org.bukkit.Material.BRICK; +import static org.bukkit.Material.BRICK_STAIRS; +import static org.bukkit.Material.BURNING_FURNACE; +import static org.bukkit.Material.CAKE_BLOCK; +import static org.bukkit.Material.CAULDRON; +import static org.bukkit.Material.CLAY; +import static org.bukkit.Material.CLAY_BRICK; +import static org.bukkit.Material.COAL_BLOCK; +import static org.bukkit.Material.COAL_ORE; +import static org.bukkit.Material.COBBLESTONE; +import static org.bukkit.Material.COBBLESTONE_STAIRS; +import static org.bukkit.Material.COBBLE_WALL; +import static org.bukkit.Material.COMMAND; +import static org.bukkit.Material.DARK_OAK_STAIRS; +import static org.bukkit.Material.DAYLIGHT_DETECTOR; +import static org.bukkit.Material.DIAMOND_BLOCK; +import static org.bukkit.Material.DIAMOND_ORE; +import static org.bukkit.Material.DIRT; +import static org.bukkit.Material.DISPENSER; +import static org.bukkit.Material.DROPPER; +import static org.bukkit.Material.EMERALD_BLOCK; +import static org.bukkit.Material.EMERALD_ORE; +import static org.bukkit.Material.ENCHANTMENT_TABLE; +import static org.bukkit.Material.ENDER_PORTAL_FRAME; +import static org.bukkit.Material.ENDER_STONE; +import static org.bukkit.Material.FURNACE; +import static org.bukkit.Material.GLASS; +import static org.bukkit.Material.GLOWSTONE; +import static org.bukkit.Material.GOLD_BLOCK; +import static org.bukkit.Material.GOLD_ORE; +import static org.bukkit.Material.GRASS; +import static org.bukkit.Material.GRAVEL; +import static org.bukkit.Material.HARD_CLAY; +import static org.bukkit.Material.HAY_BLOCK; +import static org.bukkit.Material.HUGE_MUSHROOM_1; +import static org.bukkit.Material.HUGE_MUSHROOM_2; +import static org.bukkit.Material.IRON_BLOCK; +import static org.bukkit.Material.IRON_ORE; +import static org.bukkit.Material.JACK_O_LANTERN; +import static org.bukkit.Material.JUKEBOX; +import static org.bukkit.Material.JUNGLE_WOOD_STAIRS; +import static org.bukkit.Material.LAPIS_BLOCK; +import static org.bukkit.Material.LAPIS_ORE; +import static org.bukkit.Material.LEAVES; +import static org.bukkit.Material.LEAVES_2; +import static org.bukkit.Material.LOG; +import static org.bukkit.Material.LOG_2; +import static org.bukkit.Material.MELON_BLOCK; +import static org.bukkit.Material.MOB_SPAWNER; +import static org.bukkit.Material.MOSSY_COBBLESTONE; +import static org.bukkit.Material.MYCEL; +import static org.bukkit.Material.NETHERRACK; +import static org.bukkit.Material.NETHER_BRICK; +import static org.bukkit.Material.NETHER_BRICK_STAIRS; +import static org.bukkit.Material.NOTE_BLOCK; +import static org.bukkit.Material.OBSIDIAN; +import static org.bukkit.Material.PACKED_ICE; +import static org.bukkit.Material.PUMPKIN; +import static org.bukkit.Material.QUARTZ_BLOCK; +import static org.bukkit.Material.QUARTZ_ORE; +import static org.bukkit.Material.QUARTZ_STAIRS; +import static org.bukkit.Material.REDSTONE_BLOCK; +import static org.bukkit.Material.SAND; +import static org.bukkit.Material.SANDSTONE; +import static org.bukkit.Material.SANDSTONE_STAIRS; +import static org.bukkit.Material.SMOOTH_BRICK; +import static org.bukkit.Material.SMOOTH_STAIRS; +import static org.bukkit.Material.SNOW_BLOCK; +import static org.bukkit.Material.SOUL_SAND; +import static org.bukkit.Material.SPONGE; +import static org.bukkit.Material.SPRUCE_WOOD_STAIRS; +import static org.bukkit.Material.STONE; +import static org.bukkit.Material.WOOD; +import static org.bukkit.Material.WOOD_STAIRS; +import static org.bukkit.Material.WOOL; +import static org.bukkit.Material.WORKBENCH; +import static org.bukkit.Material.getMaterial; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.UUID; + +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.configuration.file.YamlConfiguration; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Tameable; +import org.bukkit.generator.ChunkGenerator; +import org.bukkit.plugin.RegisteredServiceProvider; +import org.bukkit.plugin.java.JavaPlugin; + import ca.mera.CameraAPI; import com.intellectualcrafters.plot.Logger.LogLevel; @@ -27,31 +147,6 @@ import com.intellectualcrafters.plot.listeners.WorldGuardListener; 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.configuration.file.YamlConfiguration; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.entity.Tameable; -import org.bukkit.generator.ChunkGenerator; -import org.bukkit.plugin.RegisteredServiceProvider; -import org.bukkit.plugin.java.JavaPlugin; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.*; -import java.util.Map.Entry; - -import static org.bukkit.Material.*; - /** * @awesome @author Citymonstret, Empire92 PlotMain class. */ @@ -120,10 +215,11 @@ public class PlotMain extends JavaPlugin { } }, 0l, 12 * 60 * 60 * 20l); } - + /** * Check a range of permissions e.g. 'plots.plot.<0-100>'
* Returns highest integer in range. + * * @param player * @param stub * @param range @@ -133,21 +229,22 @@ public class PlotMain extends JavaPlugin { if (player.isOp()) { return range; } - if (player.hasPermission(stub+".*")) { + if (player.hasPermission(stub + ".*")) { return range; } - for (int i = range; i>0; i--) { - if (player.hasPermission(stub+"."+i)) { + for (int i = range; i > 0; i--) { + if (player.hasPermission(stub + "." + i)) { return i; } } return 0; } - + /** * Check a player for a permission
- * - Op has all permissions
- * - checks for '*' nodes + * - Op has all permissions
+ * - checks for '*' nodes + * * @param player * @param perm * @return @@ -156,33 +253,34 @@ public class PlotMain extends JavaPlugin { if (player.isOp()) { return true; } - for (String perm:perms) { + for (String perm : perms) { boolean hasperm = false; if (player.hasPermission(perm)) { hasperm = true; - } - else { + } else { String[] nodes = perm.split("\\."); StringBuilder n = new StringBuilder(); - for(int i = 0; i < nodes.length-1; i++) { - n.append(nodes[i]+"."); - if (player.hasPermission(n+"*")) { + for (int i = 0; i < (nodes.length - 1); i++) { + n.append(nodes[i] + "."); + if (player.hasPermission(n + "*")) { hasperm = true; break; } } } - if (!hasperm) + if (!hasperm) { return false; + } } - + return true; } /** * Check a player for a permission
- * - Op has all permissions
- * - checks for '*' nodes + * - Op has all permissions
+ * - checks for '*' nodes + * * @param player * @param perm * @return @@ -196,16 +294,16 @@ public class PlotMain extends JavaPlugin { } String[] nodes = perm.split("\\."); StringBuilder n = new StringBuilder(); - for(int i = 0; i < nodes.length-1; i++) { - n.append(nodes[i]+"."); - if (player.hasPermission(n+"*")) { + for (int i = 0; i < (nodes.length - 1); i++) { + n.append(nodes[i] + "."); + if (player.hasPermission(n + "*")) { return true; } } - + return false; } - + /** * All loaded plots */ @@ -214,6 +312,7 @@ public class PlotMain extends JavaPlugin { * All loaded plot worlds */ private static HashMap worlds = new HashMap(); + /** * Get all plots * @@ -277,6 +376,7 @@ public class PlotMain extends JavaPlugin { } return new HashMap(); } + /** * get all plot worlds */ @@ -363,21 +463,20 @@ public class PlotMain extends JavaPlugin { } /** - * TODO: Implement better system - * The whole point of this system is to recycle old plots - * So why not just allow users to claim old plots, and try to hide the fact that the are owned. - * Reduce amount of expired plots: - * - On /plot auto - allow claiming of old plot, clear it so the user doesn't know - * - On /plot info, - show that the plot is expired and allowed to be claimed + * TODO: Implement better system The whole point of this system is to + * recycle old plots So why not just allow users to claim old plots, and try + * to hide the fact that the are owned. Reduce amount of expired plots: - On + * /plot auto - allow claiming of old plot, clear it so the user doesn't + * know - On /plot info, - show that the plot is expired and allowed to be + * claimed * - * Have the task run less often: - * - Run the task when there are very little, or no players online (great for small servers) - * - Run the task at startup (also only useful for small servers) - * - * Also, in terms of faster code: - * - Have an array of plots, sorted by expiry time. - * - Add new plots to the end. - * - The task then only needs to go through the first few plots + * Have the task run less often: - Run the task when there are very little, + * or no players online (great for small servers) - Run the task at startup + * (also only useful for small servers) + * + * Also, in terms of faster code: - Have an array of plots, sorted by expiry + * time. - Add new plots to the end. - The task then only needs to go + * through the first few plots * * @param plugin * Plugin @@ -396,8 +495,10 @@ public class PlotMain extends JavaPlugin { continue; } long lastPlayed = getLastPlayed(plot.owner); - if(lastPlayed == 0) continue; - int days = (int) (lastPlayed / (1000*60*60*24)); + if (lastPlayed == 0) { + continue; + } + int days = (int) (lastPlayed / (1000 * 60 * 60 * 24)); if (days >= Settings.AUTO_CLEAR_DAYS) { PlotDeleteEvent event = new PlotDeleteEvent(world, plot.id); Bukkit.getServer().getPluginManager().callEvent(event); @@ -501,12 +602,11 @@ public class PlotMain extends JavaPlugin { DatabaseMetaData meta = connection.getMetaData(); ResultSet res = meta.getTables(null, null, "plot", null); if (!res.next()) { - DBFunc.createTables("mysql",true); - } - else { + DBFunc.createTables("mysql", true); + } else { res = meta.getTables(null, null, "plot_trusted", null); if (!res.next()) { - DBFunc.createTables("mysql",false); + DBFunc.createTables("mysql", false); } } } @@ -579,19 +679,20 @@ public class PlotMain extends JavaPlugin { worldEdit = (WorldEditPlugin) getServer().getPluginManager().getPlugin("WorldEdit"); getServer().getPluginManager().registerEvents(new WorldEditListener(), this); } - if (Settings.WORLDGUARD) - if (getServer().getPluginManager().getPlugin("WorldGuard") != null) { - worldGuard = (WorldGuardPlugin) getServer().getPluginManager().getPlugin("WorldGuard"); - worldGuardListener = new WorldGuardListener(this); - getServer().getPluginManager().registerEvents(worldGuardListener, this); + if (Settings.WORLDGUARD) { + if (getServer().getPluginManager().getPlugin("WorldGuard") != null) { + worldGuard = (WorldGuardPlugin) getServer().getPluginManager().getPlugin("WorldGuard"); + worldGuardListener = new WorldGuardListener(this); + getServer().getPluginManager().registerEvents(worldGuardListener, this); + } } - if(Settings.AUTO_CLEAR) { + if (Settings.AUTO_CLEAR) { checkExpired(PlotMain.getMain(), true); checkForExpiredPlots(); } - if(getServer().getPluginManager().getPlugin("Vault") != null) { + if (getServer().getPluginManager().getPlugin("Vault") != null) { RegisteredServiceProvider economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); - if(economyProvider != null) { + if (economyProvider != null) { economy = economyProvider.getProvider(); } useEconomy = (economy != null); @@ -601,14 +702,14 @@ public class PlotMain extends JavaPlugin { if (Web.ENABLED) { sendConsoleSenderMessage(C.PREFIX.s() + "Web Is not implemented yet. Please bear with us."); } - + try { new SetBlockFast(); PlotHelper.canSetFast = true; } catch (Exception e) { PlotHelper.canSetFast = false; } - + } /** @@ -720,13 +821,16 @@ public class PlotMain extends JavaPlugin { } public static long getLastPlayed(UUID uuid) { - if(uuid == null) return 0; + if (uuid == null) { + return 0; + } OfflinePlayer player; - if((player = Bukkit.getOfflinePlayer(uuid)) == null || !player.hasPlayedBefore()) { + if (((player = Bukkit.getOfflinePlayer(uuid)) == null) || !player.hasPlayedBefore()) { return 0; } return player.getLastPlayed(); } + /** * Load configuration files */ @@ -797,10 +901,10 @@ public class PlotMain extends JavaPlugin { Settings.AUTO_CLEAR = config.getBoolean("clear.auto.enabled"); Settings.AUTO_CLEAR_DAYS = config.getInt("clear.auto.days"); } - if(Settings.DEBUG) { + if (Settings.DEBUG) { Map settings = new HashMap<>(); settings.put("Kill Road Mobs", "" + Settings.KILL_ROAD_MOBS); - settings.put("Use Metrics", "" + Settings.METRICS); + settings.put("Use Metrics", "" + Settings.METRICS); settings.put("Mob Pathfinding", "" + Settings.MOB_PATHFINDING); settings.put("Web Enabled", "" + Web.ENABLED); settings.put("Web Port", "" + Web.PORT); @@ -808,7 +912,7 @@ public class PlotMain extends JavaPlugin { settings.put("DB SQLite Enabled", "" + Settings.DB.USE_SQLITE); settings.put("Auto Clear Enabled", "" + Settings.AUTO_CLEAR); settings.put("Auto Clear Days", "" + Settings.AUTO_CLEAR_DAYS); - for(Entry setting : settings.entrySet()) { + for (Entry setting : settings.entrySet()) { sendConsoleSenderMessage(C.PREFIX.s() + String.format("&cKey: &6%s&c, Value: &6%s", setting.getKey(), setting.getValue())); } } @@ -891,7 +995,7 @@ public class PlotMain extends JavaPlugin { default: pos = this.location; break; - + } if (PlayerEvents.isInPlot(pos)) { entity.teleport(pos.add(0.5, 0, 0.5)); @@ -899,8 +1003,9 @@ public class PlotMain extends JavaPlugin { break; } } - // Welp! how did this entity get here? - entity.teleport(location.subtract(location.getDirection().normalize().multiply(2))); + // Welp! how did this entity get + // here? + entity.teleport(this.location.subtract(this.location.getDirection().normalize().multiply(2))); } } if (!tamed) { @@ -944,7 +1049,7 @@ public class PlotMain extends JavaPlugin { } } Settings.DEBUG = config.getBoolean("debug"); - if(Settings.DEBUG) { + if (Settings.DEBUG) { sendConsoleSenderMessage(C.PREFIX.s() + "&6Debug Mode Enabled (Default). Edit the config to turn this off."); } Web.ENABLED = config.getBoolean("web.enabled"); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotSettings.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotSettings.java index 32bc4fefb..6d61526b5 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotSettings.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotSettings.java @@ -15,8 +15,6 @@ import java.util.Set; import org.bukkit.block.Biome; -import com.intellectualcrafters.plot.RUtils.Direction; - /** * plot settings * @@ -27,7 +25,7 @@ public class PlotSettings { /** * merged plots */ - private boolean[] merged = new boolean[] {false,false,false,false}; + private boolean[] merged = new boolean[] { false, false, false, false }; /** * plot alias */ @@ -62,35 +60,37 @@ public class PlotSettings { public PlotSettings(Plot plot) { this.alias = ""; } - + /** * Check if the plot is merged in a direction
* 0 = North
* 1 = East
* 2 = South
* 3 = West
+ * * @param direction * @return boolean */ public boolean getMerged(int direction) { - return merged[direction]; + return this.merged[direction]; } - + public boolean isMerged() { - return (merged[0] || merged[1] || merged[2] || merged[3]); + return (this.merged[0] || this.merged[1] || this.merged[2] || this.merged[3]); } - + public boolean[] getMerged() { return this.merged; } - + public void setMerged(boolean[] merged) { this.merged = merged; } - + public void setMerged(int direction, boolean merged) { this.merged[direction] = merged; } + /** * * @param b diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotSquaredException.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotSquaredException.java index d119b2e62..af84478f4 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotSquaredException.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotSquaredException.java @@ -11,9 +11,9 @@ public class PlotSquaredException extends RuntimeException { } public static enum PlotError { - MISSING_DEPENDENCY("Missing Dependency") - ; + MISSING_DEPENDENCY("Missing Dependency"); private String errorHeader; + PlotError(String errorHeader) { this.errorHeader = errorHeader; } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotWorld.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotWorld.java index 174ad9eb9..2faf59b4c 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotWorld.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotWorld.java @@ -1,28 +1,35 @@ package com.intellectualcrafters.plot; -import org.bukkit.Material; - import java.util.ArrayList; import java.util.List; +import org.bukkit.Material; + /** - * This is the PlotWorld class (obviously) - *
- All existing PlotWorld instances should be kept in PlotMain (worlds variable) - *
- The accessors and mutators are: - *
PlotMain.isPlotWorld(world) - *
PlotMain.getPlotWorlds() or PlotMain.getPlotWorldsString() <- use this if you don't need to get world objects - *
PlotMain.getWorldSettings(World) - get the PlotWorld class for a world - *
- *
Also added is getWorldPlots(World) as the plots are now sorted per world - *
- *
To get the world of a plot, you can use plot.world - (string) or plot.getWorld() (world object) - *
- *
All PlotWorld settings are per world in the settings.yml (these settings are automatically added when a world is loaded, either at startup or if a new world is created): - *
- You can find this in the WorldGenerator class (yeah, it's possibly not the best place, but it makes sure worlds are added to the settings.yml) - *
- *
All new DEFAULT CONSTANTS should be static and be given a value - *
All new variables should not be static and should not be given any values here, but rather in the WorldGenerator class - * + * This is the PlotWorld class (obviously)
+ * - All existing PlotWorld instances should be kept in PlotMain (worlds + * variable)
+ * - The accessors and mutators are:
+ * PlotMain.isPlotWorld(world)
+ * PlotMain.getPlotWorlds() or PlotMain.getPlotWorldsString() <- use this if you + * don't need to get world objects
+ * PlotMain.getWorldSettings(World) - get the PlotWorld class for a world
+ *
+ * Also added is getWorldPlots(World) as the plots are now sorted per world
+ *
+ * To get the world of a plot, you can use plot.world - (string) or + * plot.getWorld() (world object)
+ *
+ * All PlotWorld settings are per world in the settings.yml (these settings are + * automatically added when a world is loaded, either at startup or if a new + * world is created):
+ * - You can find this in the WorldGenerator class (yeah, it's possibly not the + * best place, but it makes sure worlds are added to the settings.yml)
+ *
+ * All new DEFAULT CONSTANTS should be static and be given a value
+ * All new variables should not be static and should not be given any values + * here, but rather in the WorldGenerator class + * **/ public class PlotWorld { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/SetBlockFast.java b/PlotSquared/src/com/intellectualcrafters/plot/SetBlockFast.java index be4b4f166..47a52c77b 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/SetBlockFast.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/SetBlockFast.java @@ -11,7 +11,7 @@ import com.intellectualcrafters.plot.ReflectionUtils.RefMethod; * * SetBlockFast class
* Used to do fast world editing - * + * */ public class SetBlockFast { @@ -42,7 +42,7 @@ public class SetBlockFast { } public static void update(org.bukkit.entity.Player player) { - int distance = Bukkit.getViewDistance()+1; + int distance = Bukkit.getViewDistance() + 1; 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); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/Settings.java b/PlotSquared/src/com/intellectualcrafters/plot/Settings.java index c7d9e1304..cdc031aef 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/Settings.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/Settings.java @@ -81,7 +81,10 @@ public class Settings { * */ public static class DB { - public static boolean USE_MONGO = false; /* TODO: Implement Mongo @Brandon */; + public static boolean USE_MONGO = false; /* + * TODO: Implement Mongo + * @Brandon + */; public static boolean USE_SQLITE = false; public static boolean USE_MYSQL = true; /* NOTE: Fixed connector */ public static String SQLITE_DB = "storage"; diff --git a/PlotSquared/src/com/intellectualcrafters/plot/WorldGenerator.java b/PlotSquared/src/com/intellectualcrafters/plot/WorldGenerator.java index 98757d2f8..085c2578a 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/WorldGenerator.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/WorldGenerator.java @@ -1,5 +1,32 @@ package com.intellectualcrafters.plot; +import static com.intellectualcrafters.plot.PlotWorld.AUTO_MERGE_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.DEFAULT_FLAGS_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.MAIN_BLOCK_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.PLOT_BIOME_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.PLOT_CHAT_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.PLOT_HEIGHT_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.PLOT_WIDTH_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.ROAD_BLOCK_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.ROAD_HEIGHT_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.ROAD_STRIPES_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.ROAD_STRIPES_ENABLED_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.ROAD_WIDTH_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.SCHEMATIC_FILE_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.SCHEMATIC_ON_CLAIM_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.TOP_BLOCK_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.WALL_BLOCK_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.WALL_FILLING_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.WALL_HEIGHT_DEFAULT; + +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Random; + import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; @@ -8,14 +35,8 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.ChunkGenerator; -import java.io.IOException; -import java.util.*; -import java.util.Map.Entry; - -import static com.intellectualcrafters.plot.PlotWorld.*; - /** - * + * * @auther Empire92 * @author Citymonstret * @@ -69,7 +90,7 @@ public class WorldGenerator extends ChunkGenerator { } public WorldGenerator(String world) { - + YamlConfiguration config = PlotMain.config; this.plotworld = new PlotWorld(); Map options = new HashMap(); @@ -91,11 +112,20 @@ public class WorldGenerator extends ChunkGenerator { options.put("worlds." + world + ".schematic.on_claim", SCHEMATIC_ON_CLAIM_DEFAULT); options.put("worlds." + world + ".schematic.file", SCHEMATIC_FILE_DEFAULT); options.put("worlds." + world + ".flags.default", DEFAULT_FLAGS_DEFAULT); - options.put("worlds." + world + ".schematic.schematics", plotworld.SCHEMATICS); - options.put("worlds." + world + ".schematic.specify_on_claim", plotworld.SCHEMATIC_CLAIM_SPECIFY); - options.put("worlds." + world + ".economy.use", plotworld.USE_ECONOMY); // Access should be static - options.put("worlds." + world + ".economy.prices.claim", plotworld.PLOT_PRICE); // Access should be static - options.put("worlds." + world + ".economy.prices.merge", plotworld.MERGE_PRICE); // Access should be static + options.put("worlds." + world + ".schematic.schematics", this.plotworld.SCHEMATICS); + options.put("worlds." + world + ".schematic.specify_on_claim", this.plotworld.SCHEMATIC_CLAIM_SPECIFY); + options.put("worlds." + world + ".economy.use", this.plotworld.USE_ECONOMY); // Access + // should + // be + // static + options.put("worlds." + world + ".economy.prices.claim", this.plotworld.PLOT_PRICE); // Access + // should + // be + // static + options.put("worlds." + world + ".economy.prices.merge", this.plotworld.MERGE_PRICE); // Access + // should + // be + // static options.put("worlds." + world + ".chat.enabled", PLOT_CHAT_DEFAULT); for (Entry node : options.entrySet()) { if (!config.contains(node.getKey())) { @@ -220,12 +250,11 @@ public class WorldGenerator extends ChunkGenerator { public short[][] generateExtBlockSections(World world, Random random, int cx, int cz, BiomeGrid biomes) { int maxY = world.getMaxHeight(); - this.result = new short[maxY / 16][]; + this.result = new short[maxY / 16][]; double pathWidthLower; - if ((pathsize % 2) == 0) { - pathWidthLower = Math.floor(this.pathsize / 2)-1; - } - else { + if ((this.pathsize % 2) == 0) { + pathWidthLower = Math.floor(this.pathsize / 2) - 1; + } else { pathWidthLower = Math.floor(this.pathsize / 2); } final int prime = 31; diff --git a/PlotSquared/src/com/intellectualcrafters/plot/XPopulator.java b/PlotSquared/src/com/intellectualcrafters/plot/XPopulator.java index 716f30e89..f7b47bf15 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/XPopulator.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/XPopulator.java @@ -1,13 +1,13 @@ package com.intellectualcrafters.plot; +import java.util.Random; + import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.generator.BlockPopulator; -import java.util.Random; - /** - * + * * @author Citymonstret * */ @@ -124,10 +124,9 @@ public class XPopulator extends BlockPopulator { this.f_id[i] = result[0]; this.f_v[i] = result[1]; } - if ((pathsize % 2) == 0) { - pathWidthLower = Math.floor(this.pathsize / 2)-1; - } - else { + if ((this.pathsize % 2) == 0) { + this.pathWidthLower = Math.floor(this.pathsize / 2) - 1; + } else { this.pathWidthLower = Math.floor(this.pathsize / 2); } } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/api/PlotAPI.java b/PlotSquared/src/com/intellectualcrafters/plot/api/PlotAPI.java index edf9ecc1c..254dd24cf 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/api/PlotAPI.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/api/PlotAPI.java @@ -20,7 +20,6 @@ import org.bukkit.plugin.java.JavaPlugin; import com.intellectualcrafters.plot.AbstractFlag; import com.intellectualcrafters.plot.C; -import com.intellectualcrafters.plot.Flag; import com.intellectualcrafters.plot.FlagManager; import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.Plot; diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Auto.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Auto.java index 96a75ce9e..dd3069c34 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Auto.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Auto.java @@ -1,26 +1,30 @@ /* -* Copyright (c) IntellectualCrafters - 2014. -* You are not allowed to distribute and/or monetize any of our intellectual property. -* IntellectualCrafters is not affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. -* -* >> File = Auto.java -* >> Generated by: Citymonstret at 2014-08-09 01:40 -*/ + * Copyright (c) IntellectualCrafters - 2014. + * You are not allowed to distribute and/or monetize any of our intellectual property. + * IntellectualCrafters is not affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. + * + * >> File = Auto.java + * >> Generated by: Citymonstret at 2014-08-09 01:40 + */ package com.intellectualcrafters.plot.commands; + import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.C; import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.Plot; import com.intellectualcrafters.plot.PlotHelper; import com.intellectualcrafters.plot.PlotId; import com.intellectualcrafters.plot.PlotMain; + @SuppressWarnings("deprecation") public class Auto extends SubCommand { public Auto() { super("auto", "plots.auto", "Claim the nearest plot", "auto", "a", CommandCategory.CLAIMING); } + // TODO auto claim a mega plot!!!!!!!!!!!! @Override public boolean execute(Player plr, String... args) { @@ -43,19 +47,17 @@ public class Auto extends SubCommand { String[] split = args[0].split(","); size_x = Integer.parseInt(split[0]); size_z = Integer.parseInt(split[1]); - if (size_x < 1 || size_z < 1) { + if ((size_x < 1) || (size_z < 1)) { PlayerFunctions.sendMessage(plr, "&cError: size<=0"); } - if (size_x > 4 || size_z > 4) { + if ((size_x > 4) || (size_z > 4)) { PlayerFunctions.sendMessage(plr, "&cError: size>4"); } - } - catch (Exception e) { + } catch (Exception e) { PlayerFunctions.sendMessage(plr, "&cError: Invalid size (X,Y)"); return false; } - } - else { + } else { PlayerFunctions.sendMessage(plr, C.NO_PERMISSION); return false; } @@ -67,7 +69,7 @@ public class Auto extends SubCommand { boolean br = false; int x = 0, z = 0, q = 100; PlotId id; - if (size_x == 1 && size_z == 1) { + if ((size_x == 1) && (size_z == 1)) { while (!br) { id = new PlotId(x, z); if (PlotHelper.getPlot(world, id).owner == null) { @@ -86,18 +88,17 @@ public class Auto extends SubCommand { z = q; } } - } - else { + } else { while (!br) { PlotId start = new PlotId(x, z); - PlotId end = new PlotId(x+size_x-1, z+size_z-1); + PlotId end = new PlotId((x + size_x) - 1, (z + size_z) - 1); if (isUnowned(world, start, end)) { // TODO claim event // Claim.claimPlot calls that event... for (int i = start.x; i <= end.x; i++) { for (int j = start.y; j <= end.y; j++) { - Plot plot = PlotHelper.getPlot(world, new PlotId(i,j)); - boolean teleport = (i == end.x && j == end.y) ? true : false; + Plot plot = PlotHelper.getPlot(world, new PlotId(i, j)); + boolean teleport = ((i == end.x) && (j == end.y)) ? true : false; Claim.claimPlot(plr, plot, teleport); } } @@ -105,9 +106,9 @@ public class Auto extends SubCommand { br = true; } if ((z < q) && ((z - x) < q)) { - z+=size_z; + z += size_z; } else if (x < q) { - x+=size_x; + x += size_x; z = q - 100; } else { q += 100; @@ -118,11 +119,12 @@ public class Auto extends SubCommand { } return true; } + public boolean isUnowned(World world, PlotId pos1, PlotId pos2) { for (int x = pos1.x; x <= pos2.x; x++) { for (int y = pos1.y; y <= pos2.y; y++) { - PlotId id = new PlotId(x,y); - if (PlotMain.getPlots(world).get(id)!=null) { + PlotId id = new PlotId(x, y); + if (PlotMain.getPlots(world).get(id) != null) { if (PlotMain.getPlots(world).get(id).owner != null) { return false; } @@ -131,4 +133,4 @@ public class Auto extends SubCommand { } return true; } -} \ No newline at end of file +} diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Claim.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Claim.java index 281aa3d68..ca0570474 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Claim.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Claim.java @@ -9,12 +9,20 @@ package com.intellectualcrafters.plot.commands; -import com.intellectualcrafters.plot.*; -import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent; import net.milkbowl.vault.economy.Economy; + import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import com.intellectualcrafters.plot.C; +import com.intellectualcrafters.plot.PlayerFunctions; +import com.intellectualcrafters.plot.Plot; +import com.intellectualcrafters.plot.PlotHelper; +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.PlotWorld; +import com.intellectualcrafters.plot.SchematicHandler; +import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent; + /** * * @author Citymonstret @@ -29,7 +37,7 @@ public class Claim extends SubCommand { @Override public boolean execute(Player plr, String... args) { String schematic = ""; - if(args.length >= 1) { + if (args.length >= 1) { schematic = args[0]; } if (!PlayerFunctions.isInPlot(plr)) { @@ -46,11 +54,11 @@ public class Claim extends SubCommand { return false; } PlotWorld world = PlotMain.getWorldSettings(plot.getWorld()); - if(PlotMain.useEconomy && world.USE_ECONOMY) { + if (PlotMain.useEconomy && world.USE_ECONOMY) { double cost = world.PLOT_PRICE; - if(cost > 0d) { + if (cost > 0d) { Economy economy = PlotMain.economy; - if(economy.getBalance(plr) < cost) { + if (economy.getBalance(plr) < cost) { sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost); return true; } @@ -58,13 +66,13 @@ public class Claim extends SubCommand { sendMessage(plr, C.REMOVED_BALANCE, cost + ""); } } - if(!schematic.equals("")) { - if(world.SCHEMATIC_CLAIM_SPECIFY) { - if(!world.SCHEMATICS.contains(schematic.toLowerCase())) { + if (!schematic.equals("")) { + if (world.SCHEMATIC_CLAIM_SPECIFY) { + if (!world.SCHEMATICS.contains(schematic.toLowerCase())) { sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent"); return true; } - if(!plr.hasPermission("plots.claim." + schematic) && !plr.hasPermission("plots.admin")) { + if (!plr.hasPermission("plots.claim." + schematic) && !plr.hasPermission("plots.admin")) { PlayerFunctions.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic); return true; } @@ -97,11 +105,11 @@ public class Claim extends SubCommand { if (world.SCHEMATIC_ON_CLAIM) { SchematicHandler handler = new SchematicHandler(); SchematicHandler.Schematic sch; - if(schematic.equals("")) { + if (schematic.equals("")) { sch = handler.getSchematic(world.SCHEMATIC_FILE); } else { sch = handler.getSchematic(schematic); - if(sch == null) { + if (sch == null) { sch = handler.getSchematic(world.SCHEMATIC_FILE); } } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Clear.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Clear.java index 3496cff7e..5f599450f 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Clear.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Clear.java @@ -14,9 +14,6 @@ import org.bukkit.entity.Player; import com.intellectualcrafters.plot.C; import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.Plot; -import com.intellectualcrafters.plot.PlotHelper; -import com.intellectualcrafters.plot.PlotMain; -import com.intellectualcrafters.plot.database.DBFunc; /** * Created by Citymonstret on 2014-08-01. @@ -34,7 +31,7 @@ public class Clear extends SubCommand { return false; } Plot plot = PlayerFunctions.getCurrentPlot(plr); - if ((plot==null || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId())) && !plr.hasPermission("plots.admin")) { + if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId())) && !plr.hasPermission("plots.admin")) { PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS); return false; } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Command.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Command.java index 95208a10d..d2c35774f 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Command.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Command.java @@ -15,18 +15,21 @@ package com.intellectualcrafters.plot.commands; * @author Citymonstret */ public enum Command { - + // TODO new commands - // (allow a plot to be transferred from one plot to another of the same size) - // - /plot copy - // - /plot paste + // (allow a plot to be transferred from one plot to another of the same + // size) + // - /plot copy + // - /plot paste // (economy) - // - /plot buy - // - /plot sell - // (Rating system) (ratings can be stored as the average, and number of ratings) - // - /plot rate - // - /plot list - TRUSTED("trusted","trust"), + // - /plot buy + // - /plot sell + // (Rating system) (ratings can be stored as the average, and number of + // ratings) + // - /plot rate + // - /plot list + TRUSTED("trusted", "trust"), /** * */ @@ -34,7 +37,7 @@ public enum Command { /** * */ - KICK("kick","k"), + KICK("kick", "k"), /** * */ diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Copy.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Copy.java index e7cd2b7e3..ecd8ad95a 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Copy.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Copy.java @@ -14,9 +14,6 @@ import org.bukkit.entity.Player; import com.intellectualcrafters.plot.C; import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.Plot; -import com.intellectualcrafters.plot.PlotHelper; -import com.intellectualcrafters.plot.PlotMain; -import com.intellectualcrafters.plot.database.DBFunc; /** * Created by Citymonstret on 2014-08-01. @@ -34,7 +31,7 @@ public class Copy extends SubCommand { return false; } Plot plot = PlayerFunctions.getCurrentPlot(plr); - if ((plot==null || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId())) && !plr.hasPermission("plots.admin")) { + if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId())) && !plr.hasPermission("plots.admin")) { PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS); return false; } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Debug.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Debug.java index b63a518f3..fb7ea0961 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Debug.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Debug.java @@ -9,10 +9,16 @@ package com.intellectualcrafters.plot.commands; -import com.intellectualcrafters.plot.*; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import com.intellectualcrafters.plot.C; +import com.intellectualcrafters.plot.Lag; +import com.intellectualcrafters.plot.PlayerFunctions; +import com.intellectualcrafters.plot.PlotHelper; +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.RUtils; + /** * @author Citymonstret \\SuperCharged Compiler made by Citymonstret\\ * ||#Compiler:ALPHA-1.0######################### @@ -80,8 +86,9 @@ 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")); - for(String world : PlotMain.getPlotWorlds()) { + // information.append(getLine(line, "PlotWorld Size", + // PlotHelper.getWorldFolderSize() + "MB")); + for (String world : PlotMain.getPlotWorlds()) { information.append(getLine(line, "World: " + world + " size", PlotHelper.getWorldFolderSize(Bukkit.getWorld(world)))); } information.append(getLine(line, "Entities", PlotHelper.getEntities(plr.getWorld()))); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Delete.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Delete.java index 5ffcee8e0..790b71f5a 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Delete.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Delete.java @@ -38,7 +38,7 @@ public class Delete extends SubCommand { PlayerFunctions.sendMessage(plr, C.UNLINK_REQUIRED); return false; } - if ((plot==null || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId())) && !plr.hasPermission("plots.admin")) { + if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId())) && !plr.hasPermission("plots.admin")) { PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS); return false; } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Home.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Home.java index cec046070..f95a23fb7 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Home.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Home.java @@ -26,6 +26,7 @@ public class Home extends SubCommand { public Home() { super(Command.HOME, "Go to your plot", "home {id|alias}", CommandCategory.TELEPORT); } + private Plot isAlias(String a) { for (Plot p : PlotMain.getPlots()) { if ((p.settings.getAlias().length() > 0) && p.settings.getAlias().equalsIgnoreCase(a)) { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java index f46fbd838..1d8ffa50a 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java @@ -9,11 +9,9 @@ package com.intellectualcrafters.plot.commands; -import com.intellectualcrafters.plot.C; -import com.intellectualcrafters.plot.PlayerFunctions; -import com.intellectualcrafters.plot.Plot; -import com.intellectualcrafters.plot.PlotHelper; -import com.intellectualcrafters.plot.database.DBFunc; +import java.util.ArrayList; +import java.util.UUID; + import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -22,8 +20,11 @@ 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.C; +import com.intellectualcrafters.plot.PlayerFunctions; +import com.intellectualcrafters.plot.Plot; +import com.intellectualcrafters.plot.PlotHelper; +import com.intellectualcrafters.plot.database.DBFunc; /** * @@ -76,7 +77,7 @@ public class Info extends SubCommand { if (plot.owner != null) { owner = Bukkit.getOfflinePlayer(plot.owner).getName(); } - if (owner==null) { + if (owner == null) { owner = plot.owner.toString(); } @@ -92,14 +93,17 @@ public class Info extends SubCommand { info = info.replaceAll("%denied%", getPlayerList(plot.denied)); info = info.replaceAll("%rating%", "" + DBFunc.getRatings(plot)); info = info.replaceAll("%flags%", StringUtils.join(plot.settings.getFlags(), "").length() > 0 ? StringUtils.join(plot.settings.getFlags(), ",") : "none"); - //PlayerFunctions.sendMessage(player, PlayerFunctions.getTopPlot(player.getWorld(), plot).id.toString()); - //PlayerFunctions.sendMessage(player, PlayerFunctions.getBottomPlot(player.getWorld(), plot).id.toString()); + // PlayerFunctions.sendMessage(player, + // PlayerFunctions.getTopPlot(player.getWorld(), plot).id.toString()); + // PlayerFunctions.sendMessage(player, + // PlayerFunctions.getBottomPlot(player.getWorld(), + // plot).id.toString()); PlayerFunctions.sendMessage(player, info); return true; } private String getPlayerList(ArrayList l) { - if (l == null || l.size() < 1) { + if ((l == null) || (l.size() < 1)) { return " none"; } String c = C.PLOT_USER_LIST.s(); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Kick.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Kick.java index cb05c9a52..03f77481a 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Kick.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Kick.java @@ -15,9 +15,6 @@ import org.bukkit.entity.Player; import com.intellectualcrafters.plot.C; import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.Plot; -import com.intellectualcrafters.plot.PlotHelper; -import com.intellectualcrafters.plot.PlotMain; -import com.intellectualcrafters.plot.database.DBFunc; /** * Created by Citymonstret on 2014-08-01. @@ -35,11 +32,11 @@ public class Kick extends SubCommand { return false; } Plot plot = PlayerFunctions.getCurrentPlot(plr); - if ((plot==null || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId())) && !plr.hasPermission("plots.admin")) { + if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId())) && !plr.hasPermission("plots.admin")) { PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS); return false; } - if (args.length!=1) { + if (args.length != 1) { PlayerFunctions.sendMessage(plr, "&c/plot kick "); return false; } @@ -47,8 +44,8 @@ public class Kick extends SubCommand { PlayerFunctions.sendMessage(plr, C.INVALID_PLAYER.s().replaceAll("%player%", args[0])); return false; } - Player player = Bukkit.getPlayer(args[0]); - if (!player.getWorld().equals(plr.getWorld()) || !PlayerFunctions.isInPlot(player) || PlayerFunctions.getCurrentPlot(player)==null || !PlayerFunctions.getCurrentPlot(player).equals(plot)) { + Player player = Bukkit.getPlayer(args[0]); + if (!player.getWorld().equals(plr.getWorld()) || !PlayerFunctions.isInPlot(player) || (PlayerFunctions.getCurrentPlot(player) == null) || !PlayerFunctions.getCurrentPlot(player).equals(plot)) { PlayerFunctions.sendMessage(plr, C.INVALID_PLAYER.s().replaceAll("%player%", args[0])); return false; } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java index 2feac7cf5..63b231e28 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java @@ -9,15 +9,24 @@ package com.intellectualcrafters.plot.commands; -import com.intellectualcrafters.plot.*; -import com.intellectualcrafters.plot.events.PlotMergeEvent; +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 java.util.ArrayList; +import com.intellectualcrafters.plot.C; +import com.intellectualcrafters.plot.PlayerFunctions; +import com.intellectualcrafters.plot.Plot; +import com.intellectualcrafters.plot.PlotHelper; +import com.intellectualcrafters.plot.PlotId; +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.PlotWorld; +import com.intellectualcrafters.plot.SetBlockFast; +import com.intellectualcrafters.plot.events.PlotMergeEvent; /** * @@ -27,8 +36,8 @@ import java.util.ArrayList; public class Merge extends SubCommand { public static String[] values = new String[] { "north", "east", "south", "west" }; - public static String[] aliases = new String[] { "n", "e", "s", "w"}; - + public 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); } @@ -36,25 +45,25 @@ public class Merge extends SubCommand { public static String direction(float yaw) { yaw = yaw / 90; int i = Math.round(yaw); - switch(i) { - case -4: - case 0: - case 4: - return "SOUTH"; - case -1: - case 3: - return "EAST"; - case -2: - case 2: - return "NORTH"; - case -3: - case 1: - return "WEST"; - default: - return ""; + switch (i) { + case -4: + case 0: + case 4: + return "SOUTH"; + case -1: + case 3: + return "EAST"; + case -2: + case 2: + return "NORTH"; + case -3: + case 1: + return "WEST"; + default: + return ""; } } - + @Override public boolean execute(Player plr, String... args) { if (!PlayerFunctions.isInPlot(plr)) { @@ -62,7 +71,7 @@ public class Merge extends SubCommand { return true; } Plot plot = PlayerFunctions.getCurrentPlot(plr); - if (plot==null || !plot.hasOwner()) { + if ((plot == null) || !plot.hasOwner()) { PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS); return false; } @@ -70,20 +79,20 @@ public class Merge extends SubCommand { PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS); return false; } - if (args.length<1) { - PlayerFunctions.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringUtils.join(values,C.BLOCK_LIST_SEPARATER.s())); + if (args.length < 1) { + PlayerFunctions.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringUtils.join(values, C.BLOCK_LIST_SEPARATER.s())); PlayerFunctions.sendMessage(plr, C.DIRECTION.s().replaceAll("%dir%", direction(plr.getLocation().getYaw()))); return false; } int direction = -1; - for (int i = 0; i plots; switch (direction) { - case 0: // north = -y - plots = PlayerFunctions.getPlotSelectionIds(plr.getWorld(), new PlotId(bot.x,bot.y-1), new PlotId(top.x,top.y)); - break; - case 1: // east = +x - plots = PlayerFunctions.getPlotSelectionIds(plr.getWorld(), new PlotId(bot.x,bot.y), new PlotId(top.x+1,top.y)); - break; - case 2: // south = +y - plots = PlayerFunctions.getPlotSelectionIds(plr.getWorld(), new PlotId(bot.x,bot.y), new PlotId(top.x,top.y+1)); - break; - case 3: // west = -x - plots = PlayerFunctions.getPlotSelectionIds(plr.getWorld(), new PlotId(bot.x-1,bot.y), new PlotId(top.x,top.y)); - break; - default: - return false; + case 0: // north = -y + plots = PlayerFunctions.getPlotSelectionIds(plr.getWorld(), new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y)); + break; + case 1: // east = +x + plots = PlayerFunctions.getPlotSelectionIds(plr.getWorld(), new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y)); + break; + case 2: // south = +y + plots = PlayerFunctions.getPlotSelectionIds(plr.getWorld(), new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1)); + break; + case 3: // west = -x + plots = PlayerFunctions.getPlotSelectionIds(plr.getWorld(), new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y)); + break; + default: + return false; } for (PlotId myid : plots) { Plot myplot = PlotMain.getPlots(world).get(myid); - if (myplot==null || !myplot.hasOwner() || !(myplot.getOwner().equals(plr.getUniqueId()))) { + if ((myplot == null) || !myplot.hasOwner() || !(myplot.getOwner().equals(plr.getUniqueId()))) { PlayerFunctions.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString())); return false; } } PlotWorld plotWorld = PlotMain.getWorldSettings(world); - if(PlotMain.useEconomy && plotWorld.USE_ECONOMY) { + if (PlotMain.useEconomy && plotWorld.USE_ECONOMY) { double cost = plotWorld.MERGE_PRICE; - if(cost > 0d) { + if (cost > 0d) { Economy economy = PlotMain.economy; - if(economy.getBalance(plr) < cost) { + if (economy.getBalance(plr) < cost) { sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + ""); return false; } @@ -130,7 +139,7 @@ public class Merge extends SubCommand { } PlotMergeEvent event = new PlotMergeEvent(world, plot, plots); - + Bukkit.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { event.setCancelled(true); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Rate.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Rate.java index a74aa68eb..893f8cad2 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Rate.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Rate.java @@ -1,9 +1,10 @@ package com.intellectualcrafters.plot.commands; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.C; import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.Plot; -import org.bukkit.entity.Player; /** * Created by Citymonstret on 2014-10-02. @@ -11,7 +12,8 @@ import org.bukkit.entity.Player; public class Rate extends SubCommand { /* - String cmd, String permission, String description, String usage, String alias, CommandCategory category + * String cmd, String permission, String description, String usage, String + * alias, CommandCategory category */ public Rate() { @@ -20,47 +22,47 @@ public class Rate extends SubCommand { @Override public boolean execute(Player plr, String... args) { - if(args.length < 1) { + if (args.length < 1) { sendMessage(plr, C.RATING_NOT_VALID); return true; } - if(!PlayerFunctions.isInPlot(plr)) { + if (!PlayerFunctions.isInPlot(plr)) { sendMessage(plr, C.NOT_IN_PLOT); return true; } Plot plot = PlayerFunctions.getCurrentPlot(plr); - if(!plot.hasOwner()) { + if (!plot.hasOwner()) { sendMessage(plr, C.RATING_NOT_OWNED); return true; } - if(plot.getOwner().equals(plr.getUniqueId())) { + if (plot.getOwner().equals(plr.getUniqueId())) { sendMessage(plr, C.RATING_NOT_YOUR_OWN); return true; } String arg = args[0]; boolean o = false; - for(char c : arg.toCharArray()) { - if(!Character.isDigit(c)) { + for (char c : arg.toCharArray()) { + if (!Character.isDigit(c)) { o = true; break; } } int rating = 0; - if(!o) { + if (!o) { rating = Integer.parseInt(arg); } - if(o || (rating < 0 || rating > 10)) { + if (o || ((rating < 0) || (rating > 10))) { sendMessage(plr, C.RATING_NOT_VALID); return true; } - //TODO implement check for already rated + // TODO implement check for already rated boolean rated = false; - if(rated) { + if (rated) { sendMessage(plr, C.RATING_ALREADY_EXISTS, plot.getId().toString()); } - //TODO actually do something... + // TODO actually do something... boolean success = false; - if(success) { + if (success) { sendMessage(plr, C.RATING_APPLIED, plot.getId().toString()); } else { sendMessage(plr, C.COMMAND_WENT_WRONG); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java index 56a334af8..bed151b16 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java @@ -9,10 +9,9 @@ package com.intellectualcrafters.plot.commands; -import com.intellectualcrafters.plot.*; -import com.intellectualcrafters.plot.database.DBFunc; -import com.intellectualcrafters.plot.events.PlotFlagAddEvent; -import com.intellectualcrafters.plot.events.PlotFlagRemoveEvent; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; @@ -22,16 +21,25 @@ import org.bukkit.WeatherType; import org.bukkit.block.Biome; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import com.intellectualcrafters.plot.C; +import com.intellectualcrafters.plot.Flag; +import com.intellectualcrafters.plot.FlagManager; +import com.intellectualcrafters.plot.PlayerFunctions; +import com.intellectualcrafters.plot.Plot; +import com.intellectualcrafters.plot.PlotHelper; +import com.intellectualcrafters.plot.PlotHomePosition; +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.PlotWorld; +import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.events.PlotFlagAddEvent; +import com.intellectualcrafters.plot.events.PlotFlagRemoveEvent; /** * * @author Citymonstret - * + * */ -public class Set extends SubCommand{ +public class Set extends SubCommand { public Set() { super(Command.SET, "Set a plot value", "set {arg} {value...}", CommandCategory.ACTIONS); @@ -53,41 +61,42 @@ public class Set extends SubCommand{ PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS); return false; } - if(args.length < 1) { - StringBuilder builder = new StringBuilder(); - builder.append(C.SUBCOMMAND_SET_OPTIONS_HEADER.s()); - builder.append(getArgumentList(values)); - PlayerFunctions.sendMessage(plr, builder.toString()); - return false; - } - for(int i = 0; i < aliases.length; i++) { - if(aliases[i].equalsIgnoreCase(args[0])) { - args[0] = values[i]; - break; - } - } + if (args.length < 1) { + StringBuilder builder = new StringBuilder(); + builder.append(C.SUBCOMMAND_SET_OPTIONS_HEADER.s()); + builder.append(getArgumentList(values)); + PlayerFunctions.sendMessage(plr, builder.toString()); + return false; + } + for (int i = 0; i < aliases.length; i++) { + if (aliases[i].equalsIgnoreCase(args[0])) { + args[0] = values[i]; + break; + } + } /* TODO: Implement option */ boolean advanced_permissions = false; - if(advanced_permissions) { - if(!plr.hasPermission("plots.set." + args[0].toLowerCase())) { + if (advanced_permissions) { + if (!plr.hasPermission("plots.set." + args[0].toLowerCase())) { PlayerFunctions.sendMessage(plr, C.NO_PERMISSION); return false; } } - - if(args[0].equalsIgnoreCase("flag")) { - if(args.length < 2) { - String message = StringUtils.join(FlagManager.getFlags(),"&c, &6"); + + if (args[0].equalsIgnoreCase("flag")) { + if (args.length < 2) { + String message = StringUtils.join(FlagManager.getFlags(), "&c, &6"); if (PlotMain.worldGuardListener != null) { - if (message.equals("")) - message = StringUtils.join(PlotMain.worldGuardListener.str_flags,"&c, &6"); - else - message += ","+StringUtils.join(PlotMain.worldGuardListener.str_flags,"&c, &6"); + if (message.equals("")) { + message = StringUtils.join(PlotMain.worldGuardListener.str_flags, "&c, &6"); + } else { + message += "," + StringUtils.join(PlotMain.worldGuardListener.str_flags, "&c, &6"); + } } PlayerFunctions.sendMessage(plr, C.NEED_KEY.s().replaceAll("%values%", message)); return false; } - if (!FlagManager.getFlags().contains(args[1].toLowerCase()) && PlotMain.worldGuardListener != null && !PlotMain.worldGuardListener.str_flags.contains(args[1].toLowerCase())) { + if (!FlagManager.getFlags().contains(args[1].toLowerCase()) && (PlotMain.worldGuardListener != null) && !PlotMain.worldGuardListener.str_flags.contains(args[1].toLowerCase())) { PlayerFunctions.sendMessage(plr, C.NOT_VALID_FLAG); return false; } @@ -95,8 +104,8 @@ public class Set extends SubCommand{ PlayerFunctions.sendMessage(plr, C.NO_PERMISSION); return false; } - if (args.length==2) { - if (plot.settings.getFlag(args[1].toLowerCase())==null) { + if (args.length == 2) { + if (plot.settings.getFlag(args[1].toLowerCase()) == null) { if (PlotMain.worldGuardListener != null) { if (PlotMain.worldGuardListener.str_flags.contains(args[1].toLowerCase())) { PlotMain.worldGuardListener.removeFlag(plr, plr.getWorld(), plot, args[1]); @@ -107,32 +116,33 @@ public class Set extends SubCommand{ return false; } Flag flag = plot.settings.getFlag(args[1].toLowerCase()); - PlotFlagRemoveEvent event = new PlotFlagRemoveEvent(flag,plot); + PlotFlagRemoveEvent event = new PlotFlagRemoveEvent(flag, plot); Bukkit.getServer().getPluginManager().callEvent(event); - if(event.isCancelled()) { + if (event.isCancelled()) { PlayerFunctions.sendMessage(plr, C.FLAG_NOT_REMOVED); event.setCancelled(true); return false; } java.util.Set newflags = plot.settings.getFlags(); Flag oldFlag = plot.settings.getFlag(args[1].toLowerCase()); - if (oldFlag!=null) + if (oldFlag != null) { newflags.remove(oldFlag); + } plot.settings.setFlags(newflags.toArray(new Flag[0])); DBFunc.setFlags(plr.getWorld().getName(), plot, newflags.toArray(new Flag[0])); PlayerFunctions.sendMessage(plr, C.FLAG_REMOVED); return true; } try { - String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length)," "); - if (FlagManager.getFlag(args[1].toLowerCase())==null && PlotMain.worldGuardListener != null) { + String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " "); + if ((FlagManager.getFlag(args[1].toLowerCase()) == null) && (PlotMain.worldGuardListener != null)) { PlotMain.worldGuardListener.addFlag(plr, plr.getWorld(), plot, args[1], value); return false; } Flag flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), value); - PlotFlagAddEvent event = new PlotFlagAddEvent(flag,plot); + PlotFlagAddEvent event = new PlotFlagAddEvent(flag, plot); Bukkit.getServer().getPluginManager().callEvent(event); - if(event.isCancelled()) { + if (event.isCancelled()) { PlayerFunctions.sendMessage(plr, C.FLAG_NOT_ADDED); event.setCancelled(true); return false; @@ -141,44 +151,48 @@ public class Set extends SubCommand{ DBFunc.setFlags(plr.getWorld().getName(), plot, plot.settings.getFlags().toArray(new Flag[0])); PlayerFunctions.sendMessage(plr, C.FLAG_ADDED); return true; - } - catch (Exception e) { - PlayerFunctions.sendMessage(plr, "&c"+e.getMessage()); + } catch (Exception e) { + PlayerFunctions.sendMessage(plr, "&c" + e.getMessage()); return false; } } - if(args[0].equalsIgnoreCase("rain")) { - if(args.length < 2) { + if (args[0].equalsIgnoreCase("rain")) { + if (args.length < 2) { PlayerFunctions.sendMessage(plr, C.NEED_ON_OFF); return false; } String word = args[1]; - if(!word.equalsIgnoreCase("on") && !word.equalsIgnoreCase("off")) { + if (!word.equalsIgnoreCase("on") && !word.equalsIgnoreCase("off")) { PlayerFunctions.sendMessage(plr, C.NEED_ON_OFF); return true; } boolean b = word.equalsIgnoreCase("on"); DBFunc.setWeather(plr.getWorld().getName(), plot, b); PlayerFunctions.sendMessage(plr, C.SETTING_UPDATED); - for(Player p : Bukkit.getOnlinePlayers()) { - if(PlayerFunctions.getCurrentPlot(plr).id == plot.id) { - if(b) p.setPlayerWeather(WeatherType.DOWNFALL); - else p.resetPlayerWeather(); + for (Player p : Bukkit.getOnlinePlayers()) { + if (PlayerFunctions.getCurrentPlot(plr).id == plot.id) { + if (b) { + p.setPlayerWeather(WeatherType.DOWNFALL); + } else { + p.resetPlayerWeather(); + } } } return true; } - if(args[0].equalsIgnoreCase("home")) { - if(args.length < 2) { + if (args[0].equalsIgnoreCase("home")) { + if (args.length < 2) { PlayerFunctions.sendMessage(plr, C.MISSING_POSITION); return false; } PlotHomePosition position = null; - for(PlotHomePosition p : PlotHomePosition.values()) { - if(p.isMatching(args[1])) position = p; + for (PlotHomePosition p : PlotHomePosition.values()) { + if (p.isMatching(args[1])) { + position = p; + } } - if(position == null) { + if (position == null) { PlayerFunctions.sendMessage(plr, C.INVALID_POSITION); return false; } @@ -187,14 +201,14 @@ public class Set extends SubCommand{ return true; } - if(args[0].equalsIgnoreCase("alias")) { - if(args.length < 2) { + if (args[0].equalsIgnoreCase("alias")) { + if (args.length < 2) { PlayerFunctions.sendMessage(plr, C.MISSING_ALIAS); return false; } String alias = args[1]; - for(Plot p : PlotMain.getPlots(plr.getWorld()).values()) { - if(p.settings.getAlias().equalsIgnoreCase(alias)) { + for (Plot p : PlotMain.getPlots(plr.getWorld()).values()) { + if (p.settings.getAlias().equalsIgnoreCase(alias)) { PlayerFunctions.sendMessage(plr, C.ALIAS_IS_TAKEN); return false; } @@ -207,165 +221,165 @@ public class Set extends SubCommand{ PlayerFunctions.sendMessage(plr, C.ALIAS_SET_TO.s().replaceAll("%alias%", alias)); return true; } - if(args[0].equalsIgnoreCase("biome")) { - if(args.length < 2) { - PlayerFunctions.sendMessage(plr, C.NEED_BIOME); - return true; - } - Biome biome = null; - for(Biome b : Biome.values()) { - if(b.toString().equalsIgnoreCase(args[1])) { - biome = b; - break; - } - } - if(biome == null) { - PlayerFunctions.sendMessage(plr, getBiomeList(Arrays.asList(Biome.values()))); - return true; - } - PlotHelper.setBiome(plr.getWorld(), plot, biome); - PlayerFunctions.sendMessage(plr, C.BIOME_SET_TO.s() + biome.toString().toLowerCase()); - return true; - } - if(args[0].equalsIgnoreCase("wall")) { - PlotWorld plotworld = PlotMain.getWorldSettings(plr.getWorld()); - if (plotworld==null) { - PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT_WORLD); - return true; - } - if(args.length < 2) { - PlayerFunctions.sendMessage(plr, C.NEED_BLOCK); - return true; - } - Material material = null; - for(Material m : plotworld.BLOCKS) { - if(m.toString().equalsIgnoreCase(args[1])) { - material = m; - break; - } - } - if(material == null) { - PlayerFunctions.sendMessage(plr, getBlockList(plotworld.BLOCKS)); - return true; - } - byte data = 0; - - if(args.length > 2) { - try { - data = (byte) Integer.parseInt(args[2]); - } catch(Exception e) { - PlayerFunctions.sendMessage(plr, C.NOT_VALID_DATA); - return true; - } - } - PlayerFunctions.sendMessage(plr, C.GENERATING_WALL); - PlotHelper.adjustWall(plr.getWorld(), plot, (short)material.getId(), data); - return true; - } - if(args[0].equalsIgnoreCase("floor")) { - if(args.length < 2) { - PlayerFunctions.sendMessage(plr, C.NEED_BLOCK); - return true; - } - PlotWorld plotworld = PlotMain.getWorldSettings(plr.getWorld()); - if (plotworld==null) { + if (args[0].equalsIgnoreCase("biome")) { + if (args.length < 2) { + PlayerFunctions.sendMessage(plr, C.NEED_BIOME); + return true; + } + Biome biome = null; + for (Biome b : Biome.values()) { + if (b.toString().equalsIgnoreCase(args[1])) { + biome = b; + break; + } + } + if (biome == null) { + PlayerFunctions.sendMessage(plr, getBiomeList(Arrays.asList(Biome.values()))); + return true; + } + PlotHelper.setBiome(plr.getWorld(), plot, biome); + PlayerFunctions.sendMessage(plr, C.BIOME_SET_TO.s() + biome.toString().toLowerCase()); + return true; + } + if (args[0].equalsIgnoreCase("wall")) { + PlotWorld plotworld = PlotMain.getWorldSettings(plr.getWorld()); + if (plotworld == null) { PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT_WORLD); return true; } - // - @SuppressWarnings("unchecked") - ArrayList materials = (ArrayList) plotworld.BLOCKS.clone(); - materials.add(Material.AIR); - // - String[] strings = args[1].split(","); - // - Material[] material = new Material[strings.length]; - byte[] data = new byte[strings.length]; - // - int index = 0; - // - byte b = (byte) 0; - Material m = null; - // - for(String s : strings) { - s = s.replaceAll(",", ""); - String[] ss = s.split(";"); - ss[0] = ss[0].replaceAll(";", ""); - for(Material ma : materials) { - if(ma.toString().equalsIgnoreCase(ss[0])) { - m = ma; - } - } - if(m == null) { - PlayerFunctions.sendMessage(plr, C.NOT_VALID_BLOCK); - return true; - } - if(ss.length == 1) { - data[index] = (byte) 0; - material[index] = m; - } else { - try { - b = (byte) Integer.parseInt(ss[1]); - } catch(Exception e) { - PlayerFunctions.sendMessage(plr, C.NOT_VALID_DATA); - return true; - } - data[index] = b; - material[index] = m; - } - index++; - } - PlotHelper.setFloor(plr, plot, material, data); - return true; - } - if(args[0].equalsIgnoreCase("wall_filling")) { - if(args.length < 2) { - PlayerFunctions.sendMessage(plr, C.NEED_BLOCK); - return true; - } - PlotWorld plotworld = PlotMain.getWorldSettings(plr.getWorld()); - if (plotworld==null) { + if (args.length < 2) { + PlayerFunctions.sendMessage(plr, C.NEED_BLOCK); + return true; + } + Material material = null; + for (Material m : PlotWorld.BLOCKS) { + if (m.toString().equalsIgnoreCase(args[1])) { + material = m; + break; + } + } + if (material == null) { + PlayerFunctions.sendMessage(plr, getBlockList(PlotWorld.BLOCKS)); + return true; + } + byte data = 0; + + if (args.length > 2) { + try { + data = (byte) Integer.parseInt(args[2]); + } catch (Exception e) { + PlayerFunctions.sendMessage(plr, C.NOT_VALID_DATA); + return true; + } + } + PlayerFunctions.sendMessage(plr, C.GENERATING_WALL); + PlotHelper.adjustWall(plr.getWorld(), plot, (short) material.getId(), data); + return true; + } + if (args[0].equalsIgnoreCase("floor")) { + if (args.length < 2) { + PlayerFunctions.sendMessage(plr, C.NEED_BLOCK); + return true; + } + PlotWorld plotworld = PlotMain.getWorldSettings(plr.getWorld()); + if (plotworld == null) { PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT_WORLD); return true; } - Material material = null; - for(Material m : plotworld.BLOCKS) { - if(m.toString().equalsIgnoreCase(args[1])) { - material = m; - break; - } - } - if(material == null) { - PlayerFunctions.sendMessage(plr, getBlockList(plotworld.BLOCKS)); - return true; - } - byte data = 0; - - if(args.length > 2) { - try { - data = (byte) Integer.parseInt(args[2]); - } catch(Exception e) { - PlayerFunctions.sendMessage(plr, C.NOT_VALID_DATA); - return true; - } - } - PlotHelper.adjustWallFilling(plr, plr.getWorld(), plot, (short)material.getId(), data); - return true; - } - StringBuilder builder = new StringBuilder(); + // + @SuppressWarnings("unchecked") + ArrayList materials = (ArrayList) PlotWorld.BLOCKS.clone(); + materials.add(Material.AIR); + // + String[] strings = args[1].split(","); + // + Material[] material = new Material[strings.length]; + byte[] data = new byte[strings.length]; + // + int index = 0; + // + byte b = (byte) 0; + Material m = null; + // + for (String s : strings) { + s = s.replaceAll(",", ""); + String[] ss = s.split(";"); + ss[0] = ss[0].replaceAll(";", ""); + for (Material ma : materials) { + if (ma.toString().equalsIgnoreCase(ss[0])) { + m = ma; + } + } + if (m == null) { + PlayerFunctions.sendMessage(plr, C.NOT_VALID_BLOCK); + return true; + } + if (ss.length == 1) { + data[index] = (byte) 0; + material[index] = m; + } else { + try { + b = (byte) Integer.parseInt(ss[1]); + } catch (Exception e) { + PlayerFunctions.sendMessage(plr, C.NOT_VALID_DATA); + return true; + } + data[index] = b; + material[index] = m; + } + index++; + } + PlotHelper.setFloor(plr, plot, material, data); + return true; + } + if (args[0].equalsIgnoreCase("wall_filling")) { + if (args.length < 2) { + PlayerFunctions.sendMessage(plr, C.NEED_BLOCK); + return true; + } + PlotWorld plotworld = PlotMain.getWorldSettings(plr.getWorld()); + if (plotworld == null) { + PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT_WORLD); + return true; + } + Material material = null; + for (Material m : PlotWorld.BLOCKS) { + if (m.toString().equalsIgnoreCase(args[1])) { + material = m; + break; + } + } + if (material == null) { + PlayerFunctions.sendMessage(plr, getBlockList(PlotWorld.BLOCKS)); + return true; + } + byte data = 0; + + if (args.length > 2) { + try { + data = (byte) Integer.parseInt(args[2]); + } catch (Exception e) { + PlayerFunctions.sendMessage(plr, C.NOT_VALID_DATA); + return true; + } + } + PlotHelper.adjustWallFilling(plr, plr.getWorld(), plot, (short) material.getId(), data); + return true; + } + StringBuilder builder = new StringBuilder(); builder.append(C.SUBCOMMAND_SET_OPTIONS_HEADER.s()); builder.append(getArgumentList(values)); PlayerFunctions.sendMessage(plr, builder.toString()); - return false; - } - - private String getMaterial(Material m) { - return ChatColor.translateAlternateColorCodes('&', C.BLOCK_LIST_ITEM.s().replaceAll("%mat%", m.toString().toLowerCase())); - } - - private String getBiome(Biome b) { - return ChatColor.translateAlternateColorCodes('&', C.BLOCK_LIST_ITEM.s().replaceAll("%mat%", b.toString().toLowerCase())); - } + return false; + } + + private String getMaterial(Material m) { + return ChatColor.translateAlternateColorCodes('&', C.BLOCK_LIST_ITEM.s().replaceAll("%mat%", m.toString().toLowerCase())); + } + + private String getBiome(Biome b) { + return ChatColor.translateAlternateColorCodes('&', C.BLOCK_LIST_ITEM.s().replaceAll("%mat%", b.toString().toLowerCase())); + } private String getString(String s) { return ChatColor.translateAlternateColorCodes('&', C.BLOCK_LIST_ITEM.s().replaceAll("%mat%", s)); @@ -373,29 +387,28 @@ public class Set extends SubCommand{ private String getArgumentList(String[] strings) { StringBuilder builder = new StringBuilder(); - for(String s : strings) { + for (String s : strings) { builder.append(getString(s)); } return builder.toString().substring(1, builder.toString().length() - 1); } - private String getBiomeList(List biomes) { - StringBuilder builder = new StringBuilder(); - builder.append(ChatColor.translateAlternateColorCodes('&', C.NOT_VALID_BLOCK_LIST_HEADER.s())); - for(Biome b : biomes) { - builder.append(getBiome(b)); - } - return builder.toString().substring(1,builder.toString().length() - 1); - } - - private String getBlockList(List blocks) { - StringBuilder builder = new StringBuilder(); - builder.append(ChatColor.translateAlternateColorCodes('&', C.NOT_VALID_BLOCK_LIST_HEADER.s())); - for(Material b : blocks) { - builder.append(getMaterial(b)); - } - return builder.toString().substring(1,builder.toString().length() - 1); - } + private String getBiomeList(List biomes) { + StringBuilder builder = new StringBuilder(); + builder.append(ChatColor.translateAlternateColorCodes('&', C.NOT_VALID_BLOCK_LIST_HEADER.s())); + for (Biome b : biomes) { + builder.append(getBiome(b)); + } + return builder.toString().substring(1, builder.toString().length() - 1); + } + private String getBlockList(List blocks) { + StringBuilder builder = new StringBuilder(); + builder.append(ChatColor.translateAlternateColorCodes('&', C.NOT_VALID_BLOCK_LIST_HEADER.s())); + for (Material b : blocks) { + builder.append(getMaterial(b)); + } + return builder.toString().substring(1, builder.toString().length() - 1); + } } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Setup.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Setup.java index b893aea21..533bfb5d3 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Setup.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Setup.java @@ -1,49 +1,19 @@ package com.intellectualcrafters.plot.commands; -import static com.intellectualcrafters.plot.PlotWorld.AUTO_MERGE_DEFAULT; -import static com.intellectualcrafters.plot.PlotWorld.DEFAULT_FLAGS_DEFAULT; -import static com.intellectualcrafters.plot.PlotWorld.MAIN_BLOCK_DEFAULT; -import static com.intellectualcrafters.plot.PlotWorld.PLOT_BIOME_DEFAULT; -import static com.intellectualcrafters.plot.PlotWorld.PLOT_HEIGHT_DEFAULT; -import static com.intellectualcrafters.plot.PlotWorld.PLOT_WIDTH_DEFAULT; -import static com.intellectualcrafters.plot.PlotWorld.ROAD_BLOCK_DEFAULT; -import static com.intellectualcrafters.plot.PlotWorld.ROAD_HEIGHT_DEFAULT; -import static com.intellectualcrafters.plot.PlotWorld.ROAD_STRIPES_DEFAULT; -import static com.intellectualcrafters.plot.PlotWorld.ROAD_STRIPES_ENABLED_DEFAULT; -import static com.intellectualcrafters.plot.PlotWorld.ROAD_WIDTH_DEFAULT; -import static com.intellectualcrafters.plot.PlotWorld.SCHEMATIC_FILE_DEFAULT; -import static com.intellectualcrafters.plot.PlotWorld.SCHEMATIC_ON_CLAIM_DEFAULT; -import static com.intellectualcrafters.plot.PlotWorld.TOP_BLOCK_DEFAULT; -import static com.intellectualcrafters.plot.PlotWorld.WALL_BLOCK_DEFAULT; -import static com.intellectualcrafters.plot.PlotWorld.WALL_FILLING_DEFAULT; -import static com.intellectualcrafters.plot.PlotWorld.WALL_HEIGHT_DEFAULT; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.lang.StringUtils; +import org.bukkit.block.Biome; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; import com.intellectualcrafters.plot.C; import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotWorld; -import com.intellectualcrafters.plot.WorldGenerator; -import com.intellectualcrafters.plot.listeners.PlayerEvents; - -import org.apache.commons.lang.StringUtils; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.WorldCreator; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; - -import sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType; - -import java.io.IOException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; /** * Created by Citymonstret on 2014-09-26. @@ -58,18 +28,14 @@ public class Setup extends SubCommand implements Listener { private String description; private Object value = 0; private String type; - private boolean require_previous; + public SetupStep(String constant, Object default_value, String description, String type, boolean require_previous) { this.constant = constant; this.default_value = default_value; this.description = description; this.type = type; - this.require_previous = require_previous; } - public boolean getRequire() { - return this.require_previous; - } - + public String getType() { return this.type; } @@ -79,33 +45,34 @@ public class Setup extends SubCommand implements Listener { return false; } switch (this.type) { - case "integer": - value = Integer.parseInt(string); - break; - case "boolean": - value = Boolean.parseBoolean(string); - break; - case "double": - value = Double.parseDouble(string); - break; - case "float": - value = Float.parseFloat(string); - break; - case "biome": - value = (string.toUpperCase()); - break; - case "block": - value = string; - break; - case "blocklist": - value = string.split(","); - break; - case "string": - value = string; - break; + case "integer": + this.value = Integer.parseInt(string); + break; + case "boolean": + this.value = Boolean.parseBoolean(string); + break; + case "double": + this.value = Double.parseDouble(string); + break; + case "float": + this.value = Float.parseFloat(string); + break; + case "biome": + this.value = (string.toUpperCase()); + break; + case "block": + this.value = string; + break; + case "blocklist": + this.value = string.split(","); + break; + case "string": + this.value = string; + break; } return true; } + public boolean validValue(String string) { try { if (this.type.equals("integer")) { @@ -133,20 +100,18 @@ public class Setup extends SubCommand implements Listener { String[] split = string.split(":"); Short.parseShort(split[0]); Short.parseShort(split[1]); - } - else { + } else { Short.parseShort(string); } return true; } if (this.type.equals("blocklist")) { - for (String block:string.split(",")) { + for (String block : string.split(",")) { if (block.contains(":")) { String[] split = block.split(":"); Short.parseShort(split[0]); Short.parseShort(split[1]); - } - else { + } else { Short.parseShort(block); } } @@ -155,14 +120,14 @@ public class Setup extends SubCommand implements Listener { if (this.type.equals("string")) { return true; } + } catch (Exception e) { } - catch (Exception e) {} return false; } public Object getValue() { if (this.value instanceof String[]) { - return (List)(List) Arrays.asList((String[]) this.value); + return Arrays.asList((String[]) this.value); } return this.value; } @@ -173,7 +138,7 @@ public class Setup extends SubCommand implements Listener { public Object getDefaultValue() { if (this.default_value instanceof String[]) { - return StringUtils.join((String[]) this.default_value,","); + return StringUtils.join((String[]) this.default_value, ","); } return this.default_value; } @@ -186,37 +151,17 @@ public class Setup extends SubCommand implements Listener { private class SetupObject { String world; int current = 0; - - SetupStep[] step = new SetupStep[] { - new SetupStep("road.height", PlotWorld.ROAD_HEIGHT_DEFAULT, "Height of road", "integer", false), - new SetupStep("plot.height", PlotWorld.PLOT_HEIGHT_DEFAULT, "Height of plot", "integer", false), - new SetupStep("wall.height", PlotWorld.WALL_HEIGHT_DEFAULT, "Height of wall", "integer", false), - new SetupStep("plot.size", PlotWorld.PLOT_WIDTH_DEFAULT, "Size of plot", "integer", false), - new SetupStep("road.width", PlotWorld.ROAD_WIDTH_DEFAULT, "Width of road", "integer", false), - new SetupStep("plot.biome", PlotWorld.PLOT_BIOME_DEFAULT, "Plot biome", "biome", false), - new SetupStep("plot.filling", PlotWorld.MAIN_BLOCK_DEFAULT, "Plot filling", "blocklist", false), - new SetupStep("plot.floor", PlotWorld.TOP_BLOCK_DEFAULT, "Plot floor", "blocklist", false), - new SetupStep("wall.block", PlotWorld.WALL_BLOCK_DEFAULT, "Wall block", "block", false), - new SetupStep("wall.filling", PlotWorld.WALL_FILLING_DEFAULT, "Wall filling", "block", false), - new SetupStep("road.enable_stripes", PlotWorld.ROAD_STRIPES_ENABLED_DEFAULT, "Enable road stripes", "boolean", false), - new SetupStep("road.stripes", PlotWorld.ROAD_STRIPES_DEFAULT, "Road stripes block", "block", true), - new SetupStep("road.block", PlotWorld.ROAD_BLOCK_DEFAULT, "Road block", "block", false), - }; + + SetupStep[] step = new SetupStep[] { new SetupStep("road.height", PlotWorld.ROAD_HEIGHT_DEFAULT, "Height of road", "integer", false), new SetupStep("plot.height", PlotWorld.PLOT_HEIGHT_DEFAULT, "Height of plot", "integer", false), new SetupStep("wall.height", PlotWorld.WALL_HEIGHT_DEFAULT, "Height of wall", "integer", false), new SetupStep("plot.size", PlotWorld.PLOT_WIDTH_DEFAULT, "Size of plot", "integer", false), new SetupStep("road.width", PlotWorld.ROAD_WIDTH_DEFAULT, "Width of road", "integer", false), new SetupStep("plot.biome", PlotWorld.PLOT_BIOME_DEFAULT, "Plot biome", "biome", false), new SetupStep("plot.filling", PlotWorld.MAIN_BLOCK_DEFAULT, "Plot filling", "blocklist", false), new SetupStep("plot.floor", PlotWorld.TOP_BLOCK_DEFAULT, "Plot floor", "blocklist", false), new SetupStep("wall.block", PlotWorld.WALL_BLOCK_DEFAULT, "Wall block", "block", false), new SetupStep("wall.filling", PlotWorld.WALL_FILLING_DEFAULT, "Wall filling", "block", false), + new SetupStep("road.enable_stripes", PlotWorld.ROAD_STRIPES_ENABLED_DEFAULT, "Enable road stripes", "boolean", false), new SetupStep("road.stripes", PlotWorld.ROAD_STRIPES_DEFAULT, "Road stripes block", "block", true), new SetupStep("road.block", PlotWorld.ROAD_BLOCK_DEFAULT, "Road block", "block", false), }; + public SetupObject(String world) { this.world = world; } - - public SetupStep getNextStep() { - return this.step[current++]; - } public int getCurrent() { return this.current; } - - public void setCurrent(String string) { - this.step[current].setValue(string); - } public int getMax() { return this.step.length; @@ -226,34 +171,35 @@ public class Setup extends SubCommand implements Listener { public Setup() { super("setup", "plots.admin", "Setup a PlotWorld", "/plot setup {world}", "setup", CommandCategory.ACTIONS); } - + @Override public boolean execute(Player plr, String... args) { - if(setupMap.containsKey(plr.getName())) { + if (setupMap.containsKey(plr.getName())) { SetupObject object = setupMap.get(plr.getName()); - if(object.getCurrent() == object.getMax()) { + if (object.getCurrent() == object.getMax()) { sendMessage(plr, C.SETUP_FINISHED, object.world); - + SetupStep[] steps = object.step; String world = object.world; - for (SetupStep step:steps) { - PlotMain.config.set("worlds."+world+"."+step.constant, step.getValue()); + for (SetupStep step : steps) { + PlotMain.config.set("worlds." + world + "." + step.constant, step.getValue()); } try { PlotMain.config.save(PlotMain.configFile); } catch (IOException e) { e.printStackTrace(); } - -// World newWorld = WorldCreator.name(world).generator(new WorldGenerator(world)).createWorld(); -// plr.teleport(newWorld.getSpawnLocation()); - + + // World newWorld = WorldCreator.name(world).generator(new + // WorldGenerator(world)).createWorld(); + // plr.teleport(newWorld.getSpawnLocation()); + setupMap.remove(plr.getName()); - + return true; } SetupStep step = object.step[object.current]; - if(args.length < 1) { + if (args.length < 1) { sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType(), step.getDefaultValue() + ""); return true; } else { @@ -263,23 +209,22 @@ public class Setup extends SubCommand implements Listener { return true; } if (args[0].equalsIgnoreCase("back")) { - if (object.current>0) { + if (object.current > 0) { object.current--; step = object.step[object.current]; sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType(), step.getDefaultValue() + ""); return true; - } - else { + } else { sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType(), step.getDefaultValue() + ""); return true; } } boolean valid = step.validValue(args[0]); - if(valid) { + if (valid) { sendMessage(plr, C.SETUP_VALID_ARG, step.getConstant(), args[0]); step.setValue(args[0]); object.current++; - if(object.getCurrent() == object.getMax()) { + if (object.getCurrent() == object.getMax()) { execute(plr, args); return true; } @@ -302,7 +247,7 @@ public class Setup extends SubCommand implements Listener { sendMessage(plr, C.SETUP_WORLD_TAKEN, world); return true; } - if (PlotMain.getWorldSettings(world)!=null) { + if (PlotMain.getWorldSettings(world) != null) { sendMessage(plr, C.SETUP_WORLD_TAKEN, world); return true; } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/SubCommand.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/SubCommand.java index b36355332..37e93996d 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/SubCommand.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/SubCommand.java @@ -90,8 +90,6 @@ public abstract class SubCommand { this.category = category; } - - /** * Execute. * @@ -109,6 +107,7 @@ public abstract class SubCommand { /** * Send a message + * * @param plr * @param c * @param args diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/TP.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/TP.java index 43c95d6aa..e555f3096 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/TP.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/TP.java @@ -9,8 +9,6 @@ package com.intellectualcrafters.plot.commands; -import java.util.Set; - import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.World; @@ -71,13 +69,13 @@ public class TP extends SubCommand { int index = 0; if (a.contains(";")) { String[] split = a.split(";"); - if (split[1].length()>0 && StringUtils.isNumeric(split[1])) { + if ((split[1].length() > 0) && StringUtils.isNumeric(split[1])) { index = Integer.parseInt(split[1]); } a = split[0]; } - Player player = Bukkit.getPlayer(a); - if (player!=null) { + Player player = Bukkit.getPlayer(a); + if (player != null) { Plot[] plots = PlotMain.getPlots(world, player).toArray(new Plot[0]); if (plots.length > index) { return plots[index]; diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Unlink.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Unlink.java index cd6ff6048..299be8e4e 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Unlink.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Unlink.java @@ -22,11 +22,9 @@ import com.intellectualcrafters.plot.Plot; import com.intellectualcrafters.plot.PlotHelper; import com.intellectualcrafters.plot.PlotId; import com.intellectualcrafters.plot.PlotMain; -import com.intellectualcrafters.plot.PlotSettings; import com.intellectualcrafters.plot.PlotWorld; import com.intellectualcrafters.plot.SetBlockFast; import com.intellectualcrafters.plot.database.DBFunc; -import com.intellectualcrafters.plot.events.PlotMergeEvent; import com.intellectualcrafters.plot.events.PlotUnlinkEvent; /** @@ -43,6 +41,7 @@ public class Unlink extends SubCommand { private int pathsize; private int wallheight; private int roadheight; + public Unlink() { super(Command.UNLINK, "Unlink a mega-plot", "unlink", CommandCategory.ACTIONS); } @@ -54,7 +53,7 @@ public class Unlink extends SubCommand { return true; } Plot plot = PlayerFunctions.getCurrentPlot(plr); - if ((plot==null || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId())) && !plr.hasPermission("plots.admin")) { + if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId())) && !plr.hasPermission("plots.admin")) { PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS); return true; } @@ -66,28 +65,30 @@ public class Unlink extends SubCommand { PlotId pos1 = PlayerFunctions.getBottomPlot(world, plot).id; PlotId pos2 = PlayerFunctions.getTopPlot(world, plot).id; ArrayList ids = PlayerFunctions.getPlotSelectionIds(world, pos1, pos2); - + PlotUnlinkEvent event = new PlotUnlinkEvent(world, ids); - + Bukkit.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { event.setCancelled(true); PlayerFunctions.sendMessage(plr, "&cUnlink has been cancelled"); return false; } - - for (PlotId id:ids) { + + for (PlotId id : ids) { Plot myplot = PlotMain.getPlots(world).get(id); - - if (plot.helpers!=null) + + if (plot.helpers != null) { myplot.helpers = plot.helpers; - if (plot.denied!=null) + } + if (plot.denied != null) { 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()); } - + PlotWorld plotworld = PlotMain.getWorldSettings(world); this.pathsize = plotworld.ROAD_WIDTH; this.roadheight = plotworld.ROAD_HEIGHT; @@ -108,105 +109,109 @@ public class Unlink extends SubCommand { this.f1_v = (byte) result_f1[1]; // - // Floor 2 - short[] result_f2 = PlotHelper.getBlock(plotworld.ROAD_STRIPES); + PlotHelper.getBlock(plotworld.ROAD_STRIPES); for (int x = pos1.x; x <= pos2.x; x++) { for (int y = pos1.y; y <= pos2.y; y++) { boolean lx = x < pos2.x; boolean ly = y < pos2.y; - - PlotId id = new PlotId(x,y); - + + PlotId id = new PlotId(x, y); + if (lx) { setRoadX(world, id); - + if (ly) { setRoadXY(world, id); } - + } - + if (ly) { setRoadY(world, id); } - + } } - + try { SetBlockFast.update(plr); + } catch (Exception e) { + } - catch (Exception e) { - - } - + PlayerFunctions.sendMessage(plr, "&6Plots unlinked successfully!"); return true; } + /** * Setting the road with the greatest X value + * * @param world * @param id */ public void setRoadX(World w, PlotId id) { Location pos1 = PlotHelper.getPlotBottomLocAbs(w, id); Location pos2 = PlotHelper.getPlotTopLocAbs(w, id); - - int sx = pos2.getBlockX()+1; - int ex = sx + pathsize - 1; - int sz = pos1.getBlockZ()-1; - int ez = pos2.getBlockZ()+2; - - PlotHelper.setSimpleCuboid(w, new Location(w,sx,Math.min(wallheight, roadheight)+1,sz+1), new Location(w,ex+1,257+1,ez), (short) 0); - - PlotHelper.setCuboid(w, new Location(w,sx,1,sz+1), new Location(w,sx+1,wallheight+1,ez), new short[] {wf_id}, new short[] {wf_v}); - PlotHelper.setCuboid(w, new Location(w,sx,wallheight+1,sz+1), new Location(w,sx+1,wallheight+2,ez), new short[] {w_id}, new short[] {w_v}); - - PlotHelper.setCuboid(w, new Location(w,ex,1,sz+1), new Location(w,ex+1,wallheight+1,ez), new short[] {wf_id}, new short[] {wf_v}); - PlotHelper.setCuboid(w, new Location(w,ex,wallheight+1,sz+1), new Location(w,ex+1,wallheight+2,ez), new short[] {w_id}, new short[] {w_v}); - - PlotHelper.setCuboid(w, new Location(w,sx+1,1,sz+1), new Location(w,ex,roadheight+1,ez), new short[] {f1_id}, new short[] {f1_v}); + + int sx = pos2.getBlockX() + 1; + int ex = (sx + this.pathsize) - 1; + int sz = pos1.getBlockZ() - 1; + int ez = pos2.getBlockZ() + 2; + + PlotHelper.setSimpleCuboid(w, new Location(w, sx, Math.min(this.wallheight, this.roadheight) + 1, sz + 1), new Location(w, ex + 1, 257 + 1, ez), (short) 0); + + PlotHelper.setCuboid(w, new Location(w, sx, 1, sz + 1), new Location(w, sx + 1, this.wallheight + 1, ez), new short[] { this.wf_id }, new short[] { this.wf_v }); + PlotHelper.setCuboid(w, new Location(w, sx, this.wallheight + 1, sz + 1), new Location(w, sx + 1, this.wallheight + 2, ez), new short[] { this.w_id }, new short[] { this.w_v }); + + PlotHelper.setCuboid(w, new Location(w, ex, 1, sz + 1), new Location(w, ex + 1, this.wallheight + 1, ez), new short[] { this.wf_id }, new short[] { this.wf_v }); + PlotHelper.setCuboid(w, new Location(w, ex, this.wallheight + 1, sz + 1), new Location(w, ex + 1, this.wallheight + 2, ez), new short[] { this.w_id }, new short[] { this.w_v }); + + PlotHelper.setCuboid(w, new Location(w, sx + 1, 1, sz + 1), new Location(w, ex, this.roadheight + 1, ez), new short[] { this.f1_id }, new short[] { this.f1_v }); } + /** * Setting the road with the greatest Y value + * * @param world * @param id */ - + public void setRoadY(World w, PlotId id) { Location pos1 = PlotHelper.getPlotBottomLocAbs(w, id); Location pos2 = PlotHelper.getPlotTopLocAbs(w, id); - - int sz = pos2.getBlockZ()+1; - int ez = sz + pathsize - 1; - int sx = pos1.getBlockX()-1; - int ex = pos2.getBlockX()+2; - - PlotHelper.setSimpleCuboid(w, new Location(w,sx,Math.min(wallheight, roadheight)+1,sz+1), new Location(w,ex+1,257+1,ez), (short) 0); - - PlotHelper.setCuboid(w, new Location(w,sx+1,1,sz), new Location(w,ex,wallheight+1,sz+1), new short[] {wf_id}, new short[] {wf_v}); - PlotHelper.setCuboid(w, new Location(w,sx+1,wallheight+1,sz), new Location(w,ex,wallheight+2,sz+1), new short[] {w_id}, new short[] {w_v}); - - PlotHelper.setCuboid(w, new Location(w,sx+1,1,sz), new Location(w,ex,wallheight+1,sz+1), new short[] {wf_id}, new short[] {wf_v}); - PlotHelper.setCuboid(w, new Location(w,sx+1,wallheight+1,ez), new Location(w,ex,wallheight+2,ez+1), new short[] {w_id}, new short[] {w_v}); - - PlotHelper.setCuboid(w, new Location(w,sx+1,1,sz+1), new Location(w,ex,roadheight+1,ez), new short[] {f1_id}, new short[] {f1_v}); + + int sz = pos2.getBlockZ() + 1; + int ez = (sz + this.pathsize) - 1; + int sx = pos1.getBlockX() - 1; + int ex = pos2.getBlockX() + 2; + + PlotHelper.setSimpleCuboid(w, new Location(w, sx, Math.min(this.wallheight, this.roadheight) + 1, sz + 1), new Location(w, ex + 1, 257 + 1, ez), (short) 0); + + PlotHelper.setCuboid(w, new Location(w, sx + 1, 1, sz), new Location(w, ex, this.wallheight + 1, sz + 1), new short[] { this.wf_id }, new short[] { this.wf_v }); + PlotHelper.setCuboid(w, new Location(w, sx + 1, this.wallheight + 1, sz), new Location(w, ex, this.wallheight + 2, sz + 1), new short[] { this.w_id }, new short[] { this.w_v }); + + PlotHelper.setCuboid(w, new Location(w, sx + 1, 1, sz), new Location(w, ex, this.wallheight + 1, sz + 1), new short[] { this.wf_id }, new short[] { this.wf_v }); + PlotHelper.setCuboid(w, new Location(w, sx + 1, this.wallheight + 1, ez), new Location(w, ex, this.wallheight + 2, ez + 1), new short[] { this.w_id }, new short[] { this.w_v }); + + PlotHelper.setCuboid(w, new Location(w, sx + 1, 1, sz + 1), new Location(w, ex, this.roadheight + 1, ez), new short[] { this.f1_id }, new short[] { this.f1_v }); } + /** * Setting the intersection with the greatest X and Y value + * * @param world * @param id */ public void setRoadXY(World w, PlotId id) { Location pos2 = PlotHelper.getPlotTopLocAbs(w, id); - - int sx = pos2.getBlockX()+1; - int ex = sx + pathsize - 1; - int sz = pos2.getBlockZ()+1; - int ez = sz + pathsize - 1; - - PlotHelper.setSimpleCuboid(w, new Location(w,sx,roadheight+1,sz+1), new Location(w,ex+1,257+1,ez), (short) 0); - - PlotHelper.setCuboid(w, new Location(w,sx+1,1,sz+1), new Location(w,ex,roadheight+1,ez), new short[] {f1_id}, new short[] {f1_v}); + + int sx = pos2.getBlockX() + 1; + int ex = (sx + this.pathsize) - 1; + int sz = pos2.getBlockZ() + 1; + int ez = (sz + this.pathsize) - 1; + + PlotHelper.setSimpleCuboid(w, new Location(w, sx, this.roadheight + 1, sz + 1), new Location(w, ex + 1, 257 + 1, ez), (short) 0); + + PlotHelper.setCuboid(w, new Location(w, sx + 1, 1, sz + 1), new Location(w, ex, this.roadheight + 1, ez), new short[] { this.f1_id }, new short[] { this.f1_v }); } } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Visit.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Visit.java index 3553ef447..949280841 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Visit.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Visit.java @@ -9,16 +9,17 @@ package com.intellectualcrafters.plot.commands; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + import com.intellectualcrafters.plot.C; import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.Plot; import com.intellectualcrafters.plot.PlotMain; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; public class Visit extends SubCommand { public Visit() { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java b/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java index 46d9f10df..93cae208e 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java @@ -38,7 +38,7 @@ import com.intellectualcrafters.plot.PlotMain; * @author Citymonstret */ public class DBFunc { - + // TODO MongoDB @Brandon /** @@ -65,9 +65,9 @@ public class DBFunc { } }); } - + public static void createAllSettingsAndHelpers(ArrayList plots) { - HashMap> stored = new HashMap< String, HashMap>(); + HashMap> stored = new HashMap>(); HashMap> helpers = new HashMap>(); try { PreparedStatement stmt = connection.prepareStatement("SELECT `id`, `plot_id_x`, `plot_id_z`, `world` FROM `plot`"); @@ -77,55 +77,55 @@ public class DBFunc { int idx = result.getInt("plot_id_x"); int idz = result.getInt("plot_id_z"); String world = result.getString("world"); - + if (!stored.containsKey(world)) { - stored.put(world,new HashMap()); + stored.put(world, new HashMap()); } - stored.get(world).put(new PlotId(idx,idz), id); + stored.get(world).put(new PlotId(idx, idz), id); } } catch (SQLException e) { e.printStackTrace(); } - - for (Plot plot:plots) { + + for (Plot plot : plots) { String world = Bukkit.getWorld(plot.world).getName(); if (stored.containsKey(world)) { Integer id = stored.get(world).get(plot.id); - if (id!=null) { - helpers.put(id,plot.helpers); + if (id != null) { + helpers.put(id, plot.helpers); } } } - - if (helpers.size()==0) { + + if (helpers.size() == 0) { return; } - + // add plot settings Integer[] ids = helpers.keySet().toArray(new Integer[0]); StringBuilder statement = new StringBuilder("INSERT INTO `plot_settings` (`plot_plot_id`) values "); - for (int i = 0; i plots) { - if (plots.size()==0) { + if (plots.size() == 0) { return; } StringBuilder statement = new StringBuilder("INSERT INTO `plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) values "); - - for (int i = 0; i uuidMap = new HashMap(); for (World world : Bukkit.getWorlds()) { HashMap plots = PlotManager.getPlots(world); - if (plots!=null) { - + if (plots != null) { + // TODO generate configuration based on PlotMe config - // - Plugin doesn't display a message if database is not setup at all - + // - Plugin doesn't display a message if database is not + // setup at all + PlotMain.sendConsoleSenderMessage("Converting " + plots.size() + " plots for '" + world.toString() + "'..."); for (Plot plot : plots.values()) { PlayerList denied = null; @@ -59,8 +60,10 @@ public class PlotMeConverter { } long eR3040bl230 = 22392948l; try { - - // TODO It just comes up with a NoSuchFieldException. Y U NO WORK!!! (I didn't change anything here btw) + + // TODO It just comes up with a + // NoSuchFieldException. Y U NO WORK!!! (I + // didn't change anything here btw) Field fAdded = plot.getClass().getDeclaredField("allowed"); Field fDenied = plot.getClass().getDeclaredField("denied"); fAdded.setAccessible(true); @@ -68,24 +71,24 @@ public class PlotMeConverter { added = (PlayerList) fAdded.get(plot); denied = (PlayerList) fDenied.get(plot); for (Map.Entry set : added.getAllPlayers().entrySet()) { - if (set.getValue() != null || set.getKey().equals("*")) { + if ((set.getValue() != null) || set.getKey().equals("*")) { if (set.getKey().equalsIgnoreCase("*") || set.getValue().toString().equals("*")) { psAdded.add(DBFunc.everyone); continue; } - } - else { - + } else { + /* - * Does this work for offline mode servers? + * Does this work for offline mode + * servers? */ - + if (uuidMap.containsKey(set.getKey())) { psAdded.add(uuidMap.get(set.getKey())); continue; } UUID value = Bukkit.getOfflinePlayer(set.getKey()).getUniqueId(); - if (value!=null) { + if (value != null) { uuidMap.put(set.getKey(), value); psAdded.add(value); continue; @@ -94,19 +97,18 @@ public class PlotMeConverter { psAdded.add(set.getValue()); } for (Map.Entry set : denied.getAllPlayers().entrySet()) { - if (set.getValue() != null || set.getKey().equals("*")) { + if ((set.getValue() != null) || set.getKey().equals("*")) { if (set.getKey().equals("*") || set.getValue().toString().equals("*")) { psDenied.add(DBFunc.everyone); continue; } - } - else { + } else { if (uuidMap.containsKey(set.getKey())) { psDenied.add(uuidMap.get(set.getKey())); continue; } UUID value = Bukkit.getOfflinePlayer(set.getKey()).getUniqueId(); - if (value!=null) { + if (value != null) { uuidMap.put(set.getKey(), value); psDenied.add(value); continue; @@ -116,38 +118,32 @@ public class PlotMeConverter { } } catch (Exception e) { // Doing it the slow way like a n00b. - for (String user:plot.getAllowed().split(",")) { + for (String user : plot.getAllowed().split(",")) { try { if (user.equals("*")) { psAdded.add(DBFunc.everyone); - } - else if (uuidMap.containsKey(user)) { + } else if (uuidMap.containsKey(user)) { psAdded.add(uuidMap.get(user)); - } - else { + } else { UUID uuid = Bukkit.getOfflinePlayer(user).getUniqueId(); uuidMap.put(user, uuid); psAdded.add(uuid); } - } - catch (Exception e2) { + } catch (Exception e2) { } } - for (String user:plot.getDenied().split(",")) { + for (String user : plot.getDenied().split(",")) { try { if (user.equals("*")) { psDenied.add(DBFunc.everyone); - } - else if (uuidMap.containsKey(user)) { + } else if (uuidMap.containsKey(user)) { psDenied.add(uuidMap.get(user)); - } - else { + } else { UUID uuid = Bukkit.getOfflinePlayer(user).getUniqueId(); uuidMap.put(user, uuid); psDenied.add(uuid); } - } - catch (Exception e2) { + } catch (Exception e2) { } } eR3040bl230 = 232000499888388747l; @@ -156,10 +152,11 @@ public class PlotMeConverter { } stream.println(eR3040bl230); PlotId id = new PlotId(Integer.parseInt(plot.id.split(";")[0]), Integer.parseInt(plot.id.split(";")[1])); - com.intellectualcrafters.plot.Plot pl = new com.intellectualcrafters.plot.Plot(id, plot.getOwnerId(), plot.getBiome(), psAdded, psTrusted, psDenied, false, 8000l, false, "", PlotHomePosition.DEFAULT, null, world.getName(), new boolean[] {false, false, false, false} ); - - // TODO createPlot doesn't add helpers / denied users - + com.intellectualcrafters.plot.Plot pl = new com.intellectualcrafters.plot.Plot(id, plot.getOwnerId(), plot.getBiome(), psAdded, psTrusted, psDenied, false, 8000l, false, "", PlotHomePosition.DEFAULT, null, world.getName(), new boolean[] { false, false, false, false }); + + // TODO createPlot doesn't add helpers / denied + // users + createdPlots.add(pl); } } @@ -168,13 +165,16 @@ public class PlotMeConverter { DBFunc.createPlots(createdPlots); PlotMain.sendConsoleSenderMessage("PlotMe->PlotSquared Creating settings/helpers DB"); DBFunc.createAllSettingsAndHelpers(createdPlots); - + stream.close(); PlotMain.sendConsoleSenderMessage("PlotMe->PlotSquared Conversion has finished"); - - // TODO disable PlotMe -> Unload all plot worlds, change the generator, restart the server automatically - // Possibly use multiverse / multiworld if it's to difficult modifying a world's generator while the server is running - // Should really do that? Would seem pretty bad from our side + bukkit wouldn't approve + + // TODO disable PlotMe -> Unload all plot worlds, change the + // generator, restart the server automatically + // Possibly use multiverse / multiworld if it's to difficult + // modifying a world's generator while the server is running + // Should really do that? Would seem pretty bad from our side + + // bukkit wouldn't approve Bukkit.getPluginManager().disablePlugin(PlotMeConverter.this.plugin); } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerClaimPlotEvent.java b/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerClaimPlotEvent.java index 2a38037b3..1a6c554b3 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerClaimPlotEvent.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerClaimPlotEvent.java @@ -27,6 +27,7 @@ public class PlayerClaimPlotEvent extends PlayerEvent implements Cancellable { /** * PlayerClaimPlotEvent: Called when a plot is claimed + * * @param player * @param plot */ @@ -34,9 +35,10 @@ public class PlayerClaimPlotEvent extends PlayerEvent implements Cancellable { super(player); this.plot = plot; } - + /** * Get the plot involved + * * @return Plot */ public Plot getPlot() { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerEnterPlotEvent.java b/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerEnterPlotEvent.java index 78bb31cd8..b1eca0e82 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerEnterPlotEvent.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerEnterPlotEvent.java @@ -17,6 +17,7 @@ public class PlayerEnterPlotEvent extends PlayerEvent { /** * PlayerEnterPlotEvent: Called when a player leaves a plot + * * @param player * @param plot */ @@ -27,6 +28,7 @@ public class PlayerEnterPlotEvent extends PlayerEvent { /** * Get the plot involved + * * @return Plot */ public Plot getPlot() { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerLeavePlotEvent.java b/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerLeavePlotEvent.java index 1f1a197f0..2a54dbdcc 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerLeavePlotEvent.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerLeavePlotEvent.java @@ -13,8 +13,10 @@ public class PlayerLeavePlotEvent extends PlayerEvent { private static HandlerList handlers = new HandlerList(); private Plot plot; + /** * PlayerLeavePlotEvent: Called when a player leaves a plot + * * @param player * @param plot */ @@ -22,14 +24,16 @@ public class PlayerLeavePlotEvent extends PlayerEvent { super(player); this.plot = plot; } + /** * Get the plot involved + * * @return Plot */ public Plot getPlot() { return this.plot; } - + @Override public HandlerList getHandlers() { return handlers; diff --git a/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerPlotDeniedEvent.java b/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerPlotDeniedEvent.java index 04ce2eb56..d53fb32ba 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerPlotDeniedEvent.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerPlotDeniedEvent.java @@ -18,8 +18,11 @@ public class PlayerPlotDeniedEvent extends Event { private Player initiator; private boolean added; private UUID player; + /** - * PlayerPlotDeniedEvent: Called when the denied UUID list is modified for a plot + * PlayerPlotDeniedEvent: Called when the denied UUID list is modified for a + * plot + * * @param initiator * @param plot * @param player @@ -34,27 +37,34 @@ public class PlayerPlotDeniedEvent extends Event { /** * If a user was added + * * @return boolean */ public boolean wasAdded() { return this.added; } + /** * The player added/removed + * * @return UUID */ public UUID getPlayer() { return this.player; } + /** * The plot involved + * * @return Plot */ public Plot getPlot() { return this.plot; } + /** * The player initiating the action + * * @return Player */ public Player getInitiator() { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerPlotHelperEvent.java b/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerPlotHelperEvent.java index e5ba69ed1..2f111e425 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerPlotHelperEvent.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerPlotHelperEvent.java @@ -18,8 +18,10 @@ public class PlayerPlotHelperEvent extends Event { private Player initiator; private boolean added; private UUID player; + /** * PlayerPlotHelperEvent: Called when a plot helper is added/removed + * * @param initiator * @param plot * @param player @@ -31,30 +33,37 @@ public class PlayerPlotHelperEvent extends Event { this.added = added; this.player = player; } - + /** - * If a player was added + * If a player was added + * * @return boolean */ public boolean wasAdded() { return this.added; } + /** * The UUID added/removed + * * @return UUID */ public UUID getPlayer() { return this.player; } + /** * The plot involved + * * @return Plot */ public Plot getPlot() { return this.plot; } + /** * The player initiating the action + * * @return Player */ public Player getInitiator() { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerPlotTrustedEvent.java b/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerPlotTrustedEvent.java index 16823168d..59cf68ca7 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerPlotTrustedEvent.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerPlotTrustedEvent.java @@ -18,8 +18,10 @@ public class PlayerPlotTrustedEvent extends Event { private Player initiator; private boolean added; private UUID player; + /** * PlayerPlotTrustedEvent: Called when a plot trusted user is added/removed + * * @param initiator * @param plot * @param player @@ -31,30 +33,37 @@ public class PlayerPlotTrustedEvent extends Event { this.added = added; this.player = player; } - + /** - * If a player was added + * If a player was added + * * @return boolean */ public boolean wasAdded() { return this.added; } + /** * The UUID added/removed + * * @return UUID */ public UUID getPlayer() { return this.player; } + /** * The plot involved + * * @return Plot */ public Plot getPlot() { return this.plot; } + /** * The player initiating the action + * * @return Player */ public Player getInitiator() { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerTeleportToPlotEvent.java b/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerTeleportToPlotEvent.java index c00d09e99..e07f423fb 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerTeleportToPlotEvent.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerTeleportToPlotEvent.java @@ -16,6 +16,7 @@ import org.bukkit.event.HandlerList; import org.bukkit.event.player.PlayerEvent; import com.intellectualcrafters.plot.Plot; + /** * Called when a player teleports to a plot */ @@ -26,8 +27,10 @@ public class PlayerTeleportToPlotEvent extends PlayerEvent implements Cancellabl private Plot plot; private boolean cancelled; + /** * PlayerTeleportToPlotEvent: Called when a player teleports to a plot + * * @param player * @param from * @param plot @@ -45,6 +48,7 @@ public class PlayerTeleportToPlotEvent extends PlayerEvent implements Cancellabl /** * Get the from location + * * @return Location */ public Location getFrom() { @@ -53,6 +57,7 @@ public class PlayerTeleportToPlotEvent extends PlayerEvent implements Cancellabl /** * Get the plot involved + * * @return Plot */ public Plot getPlot() { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/events/PlotClearEvent.java b/PlotSquared/src/com/intellectualcrafters/plot/events/PlotClearEvent.java index 331a10195..330947c93 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/events/PlotClearEvent.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/events/PlotClearEvent.java @@ -24,8 +24,10 @@ public class PlotClearEvent extends Event implements Cancellable { private PlotId id; private String world; + /** * PlotDeleteEvent: Called when a plot is cleared + * * @param world * @param id */ @@ -36,6 +38,7 @@ public class PlotClearEvent extends Event implements Cancellable { /** * Get the PlotId + * * @return PlotId */ public PlotId getPlotId() { @@ -44,6 +47,7 @@ public class PlotClearEvent extends Event implements Cancellable { /** * Get the world name + * * @return String */ public String getWorld() { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/events/PlotDeleteEvent.java b/PlotSquared/src/com/intellectualcrafters/plot/events/PlotDeleteEvent.java index 9828543b7..caa3a6e64 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/events/PlotDeleteEvent.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/events/PlotDeleteEvent.java @@ -24,8 +24,10 @@ public class PlotDeleteEvent extends Event implements Cancellable { private PlotId id; private String world; + /** * PlotDeleteEvent: Called when a plot is deleted + * * @param world * @param id */ @@ -36,6 +38,7 @@ public class PlotDeleteEvent extends Event implements Cancellable { /** * Get the PlotId + * * @return PlotId */ public PlotId getPlotId() { @@ -44,6 +47,7 @@ public class PlotDeleteEvent extends Event implements Cancellable { /** * Get the world name + * * @return String */ public String getWorld() { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/events/PlotFlagAddEvent.java b/PlotSquared/src/com/intellectualcrafters/plot/events/PlotFlagAddEvent.java index 601b30bd0..0204b2f1b 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/events/PlotFlagAddEvent.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/events/PlotFlagAddEvent.java @@ -28,6 +28,7 @@ public class PlotFlagAddEvent extends Event implements Cancellable { /** * PlotFlagAddEvent: Called when a Flag is added to a plot + * * @param flag * @param plot */ @@ -38,6 +39,7 @@ public class PlotFlagAddEvent extends Event implements Cancellable { /** * Get the plot involved + * * @return Plot */ public Plot getPlot() { @@ -46,6 +48,7 @@ public class PlotFlagAddEvent extends Event implements Cancellable { /** * Get the flag involved + * * @return Flag */ public Flag getFlag() { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/events/PlotFlagRemoveEvent.java b/PlotSquared/src/com/intellectualcrafters/plot/events/PlotFlagRemoveEvent.java index 7c2cd9350..0f3007484 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/events/PlotFlagRemoveEvent.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/events/PlotFlagRemoveEvent.java @@ -28,6 +28,7 @@ public class PlotFlagRemoveEvent extends Event implements Cancellable { /** * PlotFlagRemoveEvent: Called when a flag is removed from a plot + * * @param flag * @param plot */ @@ -35,21 +36,25 @@ public class PlotFlagRemoveEvent extends Event implements Cancellable { this.plot = plot; this.flag = flag; } + /** * Get the plot involved + * * @return Plot */ public Plot getPlot() { return this.plot; } + /** * Get the flag involved + * * @return Flag */ public Flag getFlag() { return this.flag; } - + public static HandlerList getHandlerList() { return handlers; } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/events/PlotMergeEvent.java b/PlotSquared/src/com/intellectualcrafters/plot/events/PlotMergeEvent.java index b620133f1..b836a5946 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/events/PlotMergeEvent.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/events/PlotMergeEvent.java @@ -10,14 +10,11 @@ package com.intellectualcrafters.plot.events; import java.util.ArrayList; -import java.util.Set; import org.bukkit.World; -import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import org.bukkit.event.player.PlayerEvent; import com.intellectualcrafters.plot.Plot; import com.intellectualcrafters.plot.PlotId; @@ -35,32 +32,36 @@ public class PlotMergeEvent extends Event implements Cancellable { /** * PlotMergeEvent: Called when plots are merged + * * @param player * @param plot */ public PlotMergeEvent(World world, Plot plot, ArrayList plots) { this.plots = plots; } - + /** * Get the plots being added; + * * @return Plot */ public ArrayList getPlots() { return this.plots; } + /** * Get the main plot + * * @return Plot */ public Plot getPlot() { return this.plot; } - + public World getWorld() { return this.world; } - + public static HandlerList getHandlerList() { return handlers; } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/events/PlotUnlinkEvent.java b/PlotSquared/src/com/intellectualcrafters/plot/events/PlotUnlinkEvent.java index 6f018114e..7891a9fd1 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/events/PlotUnlinkEvent.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/events/PlotUnlinkEvent.java @@ -10,16 +10,12 @@ package com.intellectualcrafters.plot.events; import java.util.ArrayList; -import java.util.Set; import org.bukkit.World; -import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import org.bukkit.event.player.PlayerEvent; -import com.intellectualcrafters.plot.Plot; import com.intellectualcrafters.plot.PlotId; /** @@ -34,6 +30,7 @@ public class PlotUnlinkEvent extends Event implements Cancellable { /** * Called when a mega-plot is unlinked. + * * @param world * @param plots */ @@ -41,9 +38,10 @@ public class PlotUnlinkEvent extends Event implements Cancellable { this.plots = plots; this.world = world; } - + /** * Get the plots involved + * * @return PlotId */ public ArrayList getPlots() { @@ -53,7 +51,7 @@ public class PlotUnlinkEvent extends Event implements Cancellable { public World getWorld() { return this.world; } - + public static HandlerList getHandlerList() { return handlers; } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlayerEvents.java b/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlayerEvents.java index dee15d2a3..595434f79 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlayerEvents.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlayerEvents.java @@ -19,7 +19,6 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; 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; @@ -65,7 +64,6 @@ import org.bukkit.event.world.StructureGrowEvent; import com.intellectualcrafters.plot.C; import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.Plot; -import com.intellectualcrafters.plot.PlotHelper; import com.intellectualcrafters.plot.PlotId; import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotWorld; @@ -138,7 +136,7 @@ public class PlayerEvents implements Listener { @EventHandler public void onChangeWorld(PlayerChangedWorldEvent event) { - if (isPlotWorld(event.getFrom()) && Settings.PLOT_SPECIFIC_RESOURCE_PACK.length() > 1) { + if (isPlotWorld(event.getFrom()) && (Settings.PLOT_SPECIFIC_RESOURCE_PACK.length() > 1)) { event.getPlayer().setResourcePack(""); } else { textures(event.getPlayer()); @@ -174,7 +172,7 @@ public class PlayerEvents implements Listener { Bukkit.getPluginManager().callEvent(callEvent); } boolean admin = player.hasPermission("plots.admin"); - + PlayerFunctions.sendMessage(player, plot.settings.getJoinMessage()); if (plot.deny_entry(player) && !admin) { event.setCancelled(true); @@ -198,8 +196,7 @@ public class PlayerEvents implements Listener { PlayerFunctions.sendMessage(player, plot.settings.getLeaveMessage()); } } - } - catch (Exception e) { + } catch (Exception e) { // Gotta catch 'em all. } } @@ -251,7 +248,7 @@ public class PlayerEvents implements Listener { event.setCancelled(true); } } - if (PlayerFunctions.getPlot(event.getBlock().getLocation())==null) { + if (PlayerFunctions.getPlot(event.getBlock().getLocation()) == null) { event.setCancelled(true); } } @@ -271,7 +268,7 @@ public class PlayerEvents implements Listener { event.setCancelled(true); } } - if (PlayerFunctions.getPlot(event.getBlockPlaced().getLocation())==null) { + if (PlayerFunctions.getPlot(event.getBlockPlaced().getLocation()) == null) { event.setCancelled(true); } } @@ -488,7 +485,7 @@ public class PlayerEvents implements Listener { event.setCancelled(true); } } - if (PlayerFunctions.getPlot(event.getClickedBlock().getLocation())==null) { + if (PlayerFunctions.getPlot(event.getClickedBlock().getLocation()) == null) { event.setCancelled(true); } } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/listeners/WorldEditListener.java b/PlotSquared/src/com/intellectualcrafters/plot/listeners/WorldEditListener.java index 379d58189..398d21e78 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/listeners/WorldEditListener.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/listeners/WorldEditListener.java @@ -57,7 +57,7 @@ public class WorldEditListener implements Listener { } Plot plot = PlotHelper.getCurrentPlot(b.getLocation()); if (plot != null) { - if ((plot != null) && plot.hasOwner() && plot.helpers!=null && (plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(p.getUniqueId()))) { + if ((plot != null) && plot.hasOwner() && (plot.helpers != null) && (plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(p.getUniqueId()))) { PWE.setMask(p, l); } } @@ -106,14 +106,14 @@ public class WorldEditListener implements Listener { } Location f = e.getFrom(); Player p = e.getPlayer(); - + if ((f.getBlockX() != t.getBlockX()) || (f.getBlockZ() != t.getBlockZ())) { PlotId idF = PlayerFunctions.getPlot(f); PlotId idT = PlayerFunctions.getPlot(t); if (PlotMain.hasPermission(e.getPlayer(), "plots.worldedit.bypass")) { return; } - if (idT!=null && !(idF == idT)) { + if ((idT != null) && !(idF == idT)) { PWE.setMask(p, t); } } @@ -130,8 +130,7 @@ public class WorldEditListener implements Listener { if (!isPlotWorld(t)) { if (isPlotWorld(f)) { PWE.removeMask(p); - } - else { + } else { return; } } @@ -149,8 +148,7 @@ public class WorldEditListener implements Listener { if (!isPlotWorld(t)) { if (isPlotWorld(f)) { PWE.removeMask(p); - } - else { + } else { return; } } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/listeners/WorldGuardListener.java b/PlotSquared/src/com/intellectualcrafters/plot/listeners/WorldGuardListener.java index 042f58f4a..1fc5ab339 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/listeners/WorldGuardListener.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/listeners/WorldGuardListener.java @@ -1,10 +1,15 @@ package com.intellectualcrafters.plot.listeners; import java.util.ArrayList; -import java.util.HashSet; import java.util.Map; -import java.util.Set; -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 com.intellectualcrafters.plot.Plot; import com.intellectualcrafters.plot.PlotHelper; @@ -15,8 +20,6 @@ import com.intellectualcrafters.plot.events.PlotDeleteEvent; import com.intellectualcrafters.plot.events.PlotMergeEvent; import com.intellectualcrafters.plot.events.PlotUnlinkEvent; import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldguard.LocalPlayer; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.domains.DefaultDomain; import com.sk89q.worldguard.protection.flags.DefaultFlag; import com.sk89q.worldguard.protection.flags.Flag; @@ -24,116 +27,105 @@ 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; - /** * Created by Citymonstret on 2014-09-24. */ public class WorldGuardListener implements Listener { public ArrayList str_flags = new ArrayList(); public ArrayList> flags = new ArrayList>(); - - + public WorldGuardListener(PlotMain plugin) { plugin.getServer().getPluginManager().registerEvents(this, plugin); - for (Flag flag:DefaultFlag.getFlags()) { - str_flags.add(flag.getName()); - flags.add(flag); + for (Flag flag : DefaultFlag.getFlags()) { + this.str_flags.add(flag.getName()); + this.flags.add(flag); } } - public void removeFlag(Player requester, World world, Plot plot,String key) { + + public void removeFlag(Player requester, World world, Plot plot, String key) { boolean op = requester.isOp(); requester.setOp(true); try { RegionManager manager = PlotMain.worldGuard.getRegionManager(world); - ProtectedRegion region = manager.getRegion(plot.id.x + "-" + plot.id.y); - for (Flag flag:flags) { + manager.getRegion(plot.id.x + "-" + plot.id.y); + for (Flag flag : this.flags) { if (flag.getName().equalsIgnoreCase(key)) { - requester.performCommand("region flag "+(plot.id.x + "-" + plot.id.y)+" "+key); + requester.performCommand("region flag " + (plot.id.x + "-" + plot.id.y) + " " + key); } } - } - catch (Exception e) { + } catch (Exception e) { requester.setOp(op); - } - finally { - requester.setOp(op); - } - } - - public void addFlag(Player requester, World world, Plot plot,String key, String value) { - boolean op = requester.isOp(); - requester.setOp(true); - try { - RegionManager manager = PlotMain.worldGuard.getRegionManager(world); - ProtectedRegion region = manager.getRegion(plot.id.x + "-" + plot.id.y); - for (Flag flag:flags) { - if (flag.getName().equalsIgnoreCase(key)) { - requester.performCommand("region flag "+(plot.id.x + "-" + plot.id.y)+" "+key+" "+value); - } - } - } - catch (Exception e) { - requester.setOp(op); - } - finally { + } finally { requester.setOp(op); } } - @EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) - public void onMerge(PlotMergeEvent event) { + public void addFlag(Player requester, World world, Plot plot, String key, String value) { + boolean op = requester.isOp(); + requester.setOp(true); + try { + RegionManager manager = PlotMain.worldGuard.getRegionManager(world); + manager.getRegion(plot.id.x + "-" + plot.id.y); + for (Flag flag : this.flags) { + if (flag.getName().equalsIgnoreCase(key)) { + requester.performCommand("region flag " + (plot.id.x + "-" + plot.id.y) + " " + key + " " + value); + } + } + } catch (Exception e) { + requester.setOp(op); + } finally { + requester.setOp(op); + } + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onMerge(PlotMergeEvent event) { Plot main = event.getPlot(); ArrayList plots = event.getPlots(); World world = event.getWorld(); RegionManager manager = PlotMain.worldGuard.getRegionManager(world); - for (PlotId plot:plots) { - if (!plot.equals(main)) + for (PlotId plot : plots) { + if (!plot.equals(main)) { manager.removeRegion(plot.x + "-" + plot.y); + } } ProtectedRegion region = manager.getRegion(main.id.x + "-" + main.id.y); DefaultDomain owner = region.getOwners(); Map, Object> flags = region.getFlags(); DefaultDomain members = region.getMembers(); manager.removeRegion(main.id.x + "-" + main.id.y); - + Location location1 = PlotHelper.getPlotBottomLocAbs(world, plots.get(0)); - Location location2 = PlotHelper.getPlotTopLocAbs(world, plots.get(plots.size()-1)); + Location location2 = PlotHelper.getPlotTopLocAbs(world, plots.get(plots.size() - 1)); BlockVector vector1 = new BlockVector(location1.getBlockX(), 1, location1.getBlockZ()); BlockVector vector2 = new BlockVector(location2.getBlockX(), world.getMaxHeight(), location2.getBlockZ()); ProtectedRegion rg = new ProtectedCuboidRegion(main.id.x + "-" + main.id.y, vector1, vector2); - + rg.setFlags(flags); rg.setOwners(owner); - + rg.setMembers(members); manager.addRegion(rg); } - - @EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) - public void onUnlink(PlotUnlinkEvent event) { + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onUnlink(PlotUnlinkEvent event) { World w = event.getWorld(); ArrayList plots = event.getPlots(); Plot main = PlotMain.getPlots(w).get(plots.get(0)); - + RegionManager manager = PlotMain.worldGuard.getRegionManager(w); ProtectedRegion region = manager.getRegion(main.id.x + "-" + main.id.y); - + DefaultDomain owner = region.getOwners(); Map, Object> flags = region.getFlags(); DefaultDomain members = region.getMembers(); - + manager.removeRegion(main.id.x + "-" + main.id.y); - for (int i = 1;i