From 12b8ae3eed063ebed67ddbb1ed69418ceb89af69 Mon Sep 17 00:00:00 2001 From: Sauilitired Date: Fri, 28 Dec 2018 07:39:39 +0100 Subject: [PATCH] Clean up some events and utility classes. Try to use as general type declarations as possible. Add configurable override for the unsafe block checker. --- .../bukkit/events/PlotMergeEvent.java | 39 ++- .../bukkit/events/PlotUnlinkEvent.java | 45 ++-- .../bukkit/util/BukkitEventUtil.java | 16 +- .../plotsquared/plot/commands/Auto.java | 2 +- .../plotsquared/plot/commands/Cluster.java | 8 +- .../plot/config/Configuration.java | 60 +---- .../plotsquared/plot/config/Settings.java | 2 + .../plot/generator/ClassicPlotManager.java | 10 +- .../plot/generator/ClassicPlotWorld.java | 28 +- .../plotsquared/plot/object/Plot.java | 3 +- .../plotsquared/plot/object/PlotArea.java | 240 ++++++++---------- .../plotsquared/plot/object/PlotManager.java | 10 +- .../plot/object/worlds/SinglePlotArea.java | 25 +- .../plot/object/worlds/SinglePlotManager.java | 10 +- .../plotsquared/plot/util/EventUtil.java | 12 +- .../plotsquared/plot/util/EventUtilTest.java | 6 +- 16 files changed, 226 insertions(+), 290 deletions(-) diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotMergeEvent.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotMergeEvent.java index 20e88f90a..b03729be0 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotMergeEvent.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotMergeEvent.java @@ -2,18 +2,26 @@ package com.github.intellectualsites.plotsquared.bukkit.events; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import lombok.Getter; +import lombok.Setter; import org.bukkit.World; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; -import java.util.ArrayList; +import javax.annotation.Nonnull; +import java.util.Collections; +import java.util.List; -public class PlotMergeEvent extends PlotEvent implements Cancellable { +/** + * Event called when several plots are merged + * {@inheritDoc} + */ +public final class PlotMergeEvent extends PlotEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); - private final ArrayList plots; - private final World world; - private boolean cancelled; + private final List plots; + @Getter private final World world; + @Getter @Setter private boolean cancelled; /** * PlotMergeEvent: Called when plots are merged @@ -22,7 +30,8 @@ public class PlotMergeEvent extends PlotEvent implements Cancellable { * @param plot Plot that was merged * @param plots A list of plots involved in the event */ - public PlotMergeEvent(World world, Plot plot, ArrayList plots) { + public PlotMergeEvent(@Nonnull final World world, @Nonnull final Plot plot, + @Nonnull final List plots) { super(plot); this.world = world; this.plots = plots; @@ -35,25 +44,13 @@ public class PlotMergeEvent extends PlotEvent implements Cancellable { /** * Get the plots being added. * - * @return Plot + * @return Unmodifiable list containing the merging plots */ - public ArrayList getPlots() { - return this.plots; - } - - public World getWorld() { - return this.world; + public List getPlots() { + return Collections.unmodifiableList(this.plots); } @Override public HandlerList getHandlers() { return handlers; } - - @Override public boolean isCancelled() { - return this.cancelled; - } - - @Override public void setCancelled(boolean b) { - this.cancelled = b; - } } diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotUnlinkEvent.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotUnlinkEvent.java index 914f394fd..675f10d8f 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotUnlinkEvent.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotUnlinkEvent.java @@ -2,20 +2,28 @@ package com.github.intellectualsites.plotsquared.bukkit.events; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import lombok.Getter; +import lombok.Setter; import org.bukkit.World; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import java.util.ArrayList; +import javax.annotation.Nonnull; +import java.util.Collections; +import java.util.List; -public class PlotUnlinkEvent extends Event implements Cancellable { +/** + * Event called when several merged plots are unlinked + * {@inheritDoc} + */ +public final class PlotUnlinkEvent extends Event implements Cancellable { private static final HandlerList handlers = new HandlerList(); - private final ArrayList plots; - private final World world; - private final PlotArea area; - private boolean cancelled; + private final List plots; + @Getter private final World world; + @Getter private final PlotArea area; + @Getter @Setter private boolean cancelled; /** * Called when a mega-plot is unlinked. @@ -23,7 +31,8 @@ public class PlotUnlinkEvent extends Event implements Cancellable { * @param world World in which the event occurred * @param plots Plots that are involved in the event */ - public PlotUnlinkEvent(World world, PlotArea area, ArrayList plots) { + public PlotUnlinkEvent(@Nonnull final World world, @Nonnull final PlotArea area, + @Nonnull final List plots) { this.plots = plots; this.world = world; this.area = area; @@ -36,29 +45,13 @@ public class PlotUnlinkEvent extends Event implements Cancellable { /** * Get the plots involved. * - * @return The {@link PlotId}'s of the plots involved + * @return Unmodifiable list containing {@link PlotId PlotIds} of the plots involved */ - public ArrayList getPlots() { - return this.plots; - } - - public World getWorld() { - return this.world; - } - - public PlotArea getArea() { - return this.area; + public List getPlots() { + return Collections.unmodifiableList(this.plots); } @Override public HandlerList getHandlers() { return handlers; } - - @Override public boolean isCancelled() { - return this.cancelled; - } - - @Override public void setCancelled(boolean b) { - this.cancelled = b; - } } diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitEventUtil.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitEventUtil.java index 4b7df7471..b198084d6 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitEventUtil.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitEventUtil.java @@ -10,20 +10,24 @@ import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; +import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.ArrayList; +import java.util.List; import java.util.UUID; -public class BukkitEventUtil extends EventUtil { +/** + * Utility class for handling Bukkit {@link Event events} + */ +public final class BukkitEventUtil extends EventUtil { - public Player getPlayer(PlotPlayer player) { + @Nullable public Player getPlayer(final PlotPlayer player) { if (player instanceof BukkitPlayer) { return ((BukkitPlayer) player).player; } return null; } - public boolean callEvent(Event event) { + private boolean callEvent(@Nonnull final Event event) { Bukkit.getServer().getPluginManager().callEvent(event); return !(event instanceof Cancellable) || !((Cancellable) event).isCancelled(); } @@ -56,11 +60,11 @@ public class BukkitEventUtil extends EventUtil { return callEvent(new PlotFlagRemoveEvent(flag, plot)); } - @Override public boolean callMerge(Plot plot, ArrayList plots) { + @Override public boolean callMerge(Plot plot, List plots) { return callEvent(new PlotMergeEvent(BukkitUtil.getWorld(plot.getWorldName()), plot, plots)); } - @Override public boolean callUnlink(PlotArea area, ArrayList plots) { + @Override public boolean callUnlink(PlotArea area, List plots) { return callEvent(new PlotUnlinkEvent(BukkitUtil.getWorld(area.worldname), area, plots)); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java index a8636d1e1..33048e0fd 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java @@ -244,7 +244,7 @@ public class Auto extends SubCommand { } } if (!plotarea - .mergePlots(MainUtil.getPlotSelectionIds(start, end), true, true)) { + .mergePlots(MainUtil.getPlotSelectionIds(start, end), true)) { return false; } break; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Cluster.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Cluster.java index 154a8f914..c8360f696 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Cluster.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Cluster.java @@ -244,10 +244,12 @@ import java.util.UUID; MainUtil.sendMessage(player, C.CLUSTER_INTERSECTION, intersect.getName()); return false; } - HashSet existing = + Set existing = area.getPlotSelectionOwned(cluster.getP1(), cluster.getP2()); - HashSet newPlots = area.getPlotSelectionOwned(pos1, pos2); - HashSet removed = (HashSet) existing.clone(); + Set newPlots = area.getPlotSelectionOwned(pos1, pos2); + // Set removed = (HashSet) existing.clone(); + Set removed = new HashSet<>(existing); + removed.removeAll(newPlots); // Check expand / shrink if (!removed.isEmpty()) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Configuration.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Configuration.java index 470421cc3..b50de8ca6 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Configuration.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Configuration.java @@ -12,25 +12,6 @@ import lombok.NonNull; */ public class Configuration { - public static final SettingValue STRING = new SettingValue("STRING") { - @Override public boolean validateValue(String string) { - return true; - } - - @Override public String parseString(String string) { - return string; - } - }; - public static final SettingValue STRINGLIST = - new SettingValue("STRINGLIST") { - @Override public boolean validateValue(String string) { - return true; - } - - @Override public String[] parseString(String string) { - return string.split(","); - } - }; public static final SettingValue INTEGER = new SettingValue("INTEGER") { @Override public boolean validateValue(String string) { try { @@ -47,6 +28,7 @@ public class Configuration { }; public static final SettingValue BOOLEAN = new SettingValue("BOOLEAN") { @Override public boolean validateValue(String string) { + //noinspection ResultOfMethodCallIgnored Boolean.parseBoolean(string); return true; } @@ -55,20 +37,6 @@ public class Configuration { return Boolean.parseBoolean(string); } }; - public static final SettingValue DOUBLE = new SettingValue("DOUBLE") { - @Override public boolean validateValue(String string) { - try { - Double.parseDouble(string); - return true; - } catch (NumberFormatException ignored) { - return false; - } - } - - @Override public Double parseString(String string) { - return Double.parseDouble(string); - } - }; public static final SettingValue BIOME = new SettingValue("BIOME") { @Override public boolean validateValue(String string) { try { @@ -112,7 +80,8 @@ public class Configuration { WorldUtil.IMP.getClosestBlock(block); if (value == null) { throw new UnknownBlockException(block); - } else if (!value.best.isAir() && !WorldUtil.IMP.isBlockSolid(value.best)) { + } else if (Settings.Enabled_Components.PREVENT_UNSAFE && !value.best.isAir() && + !WorldUtil.IMP.isBlockSolid(value.best)) { throw new UnsafeBlockException(value.best); } blockBucket.addBlock(value.best, chance); @@ -145,7 +114,7 @@ public class Configuration { WorldUtil.IMP.getClosestBlock(block); if (value == null || value.match > 1) { return false; - } else if (!value.best.isAir() && !WorldUtil.IMP.isBlockSolid(value.best)) { + } else if (Settings.Enabled_Components.PREVENT_UNSAFE && !value.best.isAir() && !WorldUtil.IMP.isBlockSolid(value.best)) { throw new UnsafeBlockException(value.best); } } @@ -156,27 +125,12 @@ public class Configuration { } }; - public static int gcd(int a, int b) { - if (b == 0) { - return a; - } - return gcd(b, a % b); - } - - private static int gcd(int[] a) { - int result = a[0]; - for (int i = 1; i < a.length; i++) { - result = gcd(result, a[i]); - } - return result; - } - public static final class UnknownBlockException extends IllegalArgumentException { @Getter private final String unknownValue; - public UnknownBlockException(@NonNull final String unknownValue) { + UnknownBlockException(@NonNull final String unknownValue) { super(String.format("\"%s\" is not a valid block", unknownValue)); this.unknownValue = unknownValue; } @@ -191,7 +145,7 @@ public class Configuration { private final String type; - public SettingValue(String type) { + SettingValue(String type) { this.type = type; } @@ -209,7 +163,7 @@ public class Configuration { @Getter private final PlotBlock unsafeBlock; - public UnsafeBlockException(@NonNull final PlotBlock unsafeBlock) { + UnsafeBlockException(@NonNull final PlotBlock unsafeBlock) { super(String.format("%s is not a valid block", unsafeBlock)); this.unsafeBlock = unsafeBlock; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Settings.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Settings.java index 7c9d3542b..d67a0ea0c 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Settings.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Settings.java @@ -354,5 +354,7 @@ public class Settings extends Config { @Comment("Actively purge invalid database entries") public static boolean DATABASE_PURGER = false; @Comment("Delete plots when a player is banned") public static boolean BAN_DELETER = false; + @Comment("Prevent possibly unsafe blocks from being used in plot components") public static + boolean PREVENT_UNSAFE = true; } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotManager.java index f69ea6785..a553140b2 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotManager.java @@ -5,7 +5,7 @@ import com.github.intellectualsites.plotsquared.plot.util.MathMan; import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; -import java.util.ArrayList; +import java.util.List; /** * A plot manager with square plots which tessellate on a square grid with the following sections: ROAD, WALL, BORDER (wall), PLOT, FLOOR (plot). @@ -424,23 +424,23 @@ public class ClassicPlotManager extends SquarePlotManager { /** * Finishing off plot merging by adding in the walls surrounding the plot (OPTIONAL)(UNFINISHED). */ - @Override public boolean finishPlotMerge(PlotArea plotArea, ArrayList plotIds) { + @Override public boolean finishPlotMerge(PlotArea plotArea, List plotIds) { final BlockBucket block = ((ClassicPlotWorld) plotArea).CLAIMED_WALL_BLOCK; plotIds.forEach(id -> setWall(plotArea, id, block)); return true; } - @Override public boolean finishPlotUnlink(PlotArea plotArea, ArrayList plotIds) { + @Override public boolean finishPlotUnlink(PlotArea plotArea, List plotIds) { final BlockBucket block = ((ClassicPlotWorld) plotArea).CLAIMED_WALL_BLOCK; plotIds.forEach(id -> setWall(plotArea, id, block)); return true; } - @Override public boolean startPlotMerge(PlotArea plotArea, ArrayList plotIds) { + @Override public boolean startPlotMerge(PlotArea plotArea, List plotIds) { return true; } - @Override public boolean startPlotUnlink(PlotArea plotArea, ArrayList plotIds) { + @Override public boolean startPlotUnlink(PlotArea plotArea, List plotIds) { return true; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotWorld.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotWorld.java index 745770fe2..816adbf55 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotWorld.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/ClassicPlotWorld.java @@ -1,12 +1,19 @@ package com.github.intellectualsites.plotsquared.plot.generator; import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection; +import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Configuration; import com.github.intellectualsites.plotsquared.plot.config.ConfigurationNode; +import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import javax.annotation.Nonnull; +import java.lang.reflect.Field; +import java.util.Locale; + +@SuppressWarnings("WeakerAccess") public abstract class ClassicPlotWorld extends SquarePlotWorld { public int ROAD_HEIGHT = 62; @@ -38,7 +45,7 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld { * command - this may be useful if a config value can be changed at a later date, and has no impact on the actual * world generation

*/ - @Override public ConfigurationNode[] getSettingNodes() { + @Nonnull @Override public ConfigurationNode[] getSettingNodes() { return new ConfigurationNode[] { new ConfigurationNode("plot.height", this.PLOT_HEIGHT, "Plot height", Configuration.INTEGER), @@ -84,5 +91,24 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld { this.WALL_HEIGHT = Math.min(254, config.getInt("wall.height")); this.CLAIMED_WALL_BLOCK = Configuration.BLOCK_BUCKET.parseString(config.getString("wall.block_claimed")); + + // Dump world settings + if (Settings.DEBUG) { + PlotSquared.debug(String.format("- Dumping settings for ClassicPlotWorld with name %s", this.worldname)); + final Field[] fields = this.getClass().getFields(); + for (final Field field : fields) { + final String name = field.getName().toLowerCase(Locale.ENGLISH); + Object value; + try { + final boolean accessible = field.isAccessible(); + field.setAccessible(true); + value = field.get(this); + field.setAccessible(accessible); + } catch (final IllegalAccessException e) { + value = String.format("Failed to parse: %s", e.getMessage()); + } + PlotSquared.debug(String.format("-- %s = %s", name, value)); + } + } } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java index f330bad3c..fe5db5e8f 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java @@ -21,6 +21,7 @@ import com.google.common.collect.BiMap; import com.google.common.collect.ImmutableSet; import com.sk89q.jnbt.CompoundTag; +import javax.annotation.Nullable; import java.awt.geom.Area; import java.awt.geom.PathIterator; import java.awt.geom.Rectangle2D; @@ -2052,7 +2053,7 @@ public class Plot { * @param player the claiming player * @return */ - public boolean canClaim(PlotPlayer player) { + public boolean canClaim(@Nullable PlotPlayer player) { PlotCluster cluster = this.getCluster(); if (cluster != null && player != null) { if (!cluster.isAdded(player.getUUID()) && !Permissions diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java index 498119dec..c8173ed15 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java @@ -15,13 +15,14 @@ import com.github.intellectualsites.plotsquared.plot.util.area.QuadMap; import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.*; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; /** - * @author Jesse Boyd + * @author Jesse Boyd, Alexander Söderberg */ public abstract class PlotArea { @@ -65,8 +66,8 @@ public abstract class PlotArea { private ConcurrentHashMap meta; private QuadMap clusters; - public PlotArea(String worldName, String id, IndependentPlotGenerator generator, PlotId min, - PlotId max) { + public PlotArea(@Nonnull final String worldName, @Nullable final String id, @Nullable IndependentPlotGenerator generator, + @Nullable final PlotId min, @Nullable final PlotId max) { this.worldname = worldName; this.id = id; this.manager = generator != null ? generator.getNewPlotManager() : null; @@ -88,11 +89,8 @@ public abstract class PlotArea { /** * Create a new PlotArea object with no functionality/information. * - Mainly used during startup before worlds are created as a temporary object - * - * @param world - * @return */ - public static PlotArea createGeneric(String world) { + public static PlotArea createGeneric(@Nonnull final String world) { return new PlotArea(world, null, null, null, null) { @Override public void loadConfiguration(ConfigurationSection config) { } @@ -103,7 +101,7 @@ public abstract class PlotArea { }; } - public LocalBlockQueue getQueue(boolean autoQueue) { + public LocalBlockQueue getQueue(final boolean autoQueue) { return GlobalBlockQueue.IMP.getNewQueue(worldname, autoQueue); } @@ -127,7 +125,7 @@ public abstract class PlotArea { * * @return RegionWrapper or null if no applicable region */ - public RegionWrapper getRegionAbs() { + private RegionWrapper getRegionAbs() { if (this.region == null) { if (this.min != null) { Location bot = getPlotManager().getPlotBottomLocAbs(this, this.min); @@ -179,7 +177,7 @@ public abstract class PlotArea { } public Set getClusters() { - return this.clusters == null ? new HashSet() : this.clusters.getAll(); + return this.clusters == null ? new HashSet<>() : this.clusters.getAll(); } /** @@ -377,7 +375,7 @@ public abstract class PlotArea { } } - @Override public String toString() { + @Nonnull @Override public String toString() { if (this.id == null) { return this.worldname; } else { @@ -397,7 +395,7 @@ public abstract class PlotArea { * * @return ConfigurationNode[] */ - public abstract ConfigurationNode[] getSettingNodes(); + public abstract ConfigurationNode[] getSettingNodes(); /** * Gets the {@code Plot} at a location. @@ -405,8 +403,8 @@ public abstract class PlotArea { * @param location the location * @return the {@code Plot} or null if none exists */ - public Plot getPlotAbs(Location location) { - PlotId pid = + @Nullable public Plot getPlotAbs(@Nonnull final Location location) { + final PlotId pid = this.manager.getPlotId(this, location.getX(), location.getY(), location.getZ()); if (pid == null) { return null; @@ -420,8 +418,8 @@ public abstract class PlotArea { * @param location the location * @return base Plot */ - public Plot getPlot(Location location) { - PlotId pid = + @Nullable public Plot getPlot(@Nonnull final Location location) { + final PlotId pid = this.manager.getPlotId(this, location.getX(), location.getY(), location.getZ()); if (pid == null) { return null; @@ -435,8 +433,8 @@ public abstract class PlotArea { * @param location the location * @return the base plot or null */ - public Plot getOwnedPlot(Location location) { - PlotId pid = + @Nullable public Plot getOwnedPlot(@Nonnull final Location location) { + final PlotId pid = this.manager.getPlotId(this, location.getX(), location.getY(), location.getZ()); if (pid == null) { return null; @@ -451,8 +449,8 @@ public abstract class PlotArea { * @param location the location * @return Plot or null */ - public Plot getOwnedPlotAbs(Location location) { - PlotId pid = + @Nullable public Plot getOwnedPlotAbs(@Nonnull final Location location) { + final PlotId pid = this.manager.getPlotId(this, location.getX(), location.getY(), location.getZ()); if (pid == null) { return null; @@ -466,30 +464,30 @@ public abstract class PlotArea { * @param id the {@code PlotId} * @return the plot or null */ - public Plot getOwnedPlotAbs(PlotId id) { + @Nullable public Plot getOwnedPlotAbs(@Nonnull final PlotId id) { return this.plots.get(id); } - public Plot getOwnedPlot(PlotId id) { + @Nullable public Plot getOwnedPlot(@Nonnull final PlotId id) { Plot plot = this.plots.get(id); return plot == null ? null : plot.getBasePlot(false); } - public boolean contains(int x, int z) { + public boolean contains(final int x, final int z) { return this.TYPE != 2 || getRegionAbs().isIn(x, z); } - public boolean contains(PlotId id) { + public boolean contains(@Nonnull final PlotId id) { return this.min == null || (id.x >= this.min.x && id.x <= this.max.x && id.y >= this.min.y && id.y <= this.max.y); } - public boolean contains(Location location) { + public boolean contains(@Nonnull final Location location) { return StringMan.isEqual(location.getWorld(), this.worldname) && (getRegionAbs() == null || this.region.isIn(location.getX(), location.getZ())); } - public Set getPlotsAbs(final UUID uuid) { + @Nonnull Set getPlotsAbs(final UUID uuid) { if (uuid == null) { return Collections.emptySet(); } @@ -504,19 +502,17 @@ public abstract class PlotArea { return myPlots; } - public Set getPlots(UUID uuid) { - HashSet myplots = new HashSet<>(); - for (Plot plot : getPlots()) { - if (plot.isBasePlot()) { - if (plot.isOwner(uuid)) { - myplots.add(plot); - } + @Nonnull public Set getPlots(@Nonnull final UUID uuid) { + final Set myplots = new HashSet<>(); + for (final Plot plot : getPlots()) { + if (plot.isBasePlot() && plot.isOwner(uuid)) { + myplots.add(plot); } } return myplots; } - public Set getPlots(PlotPlayer player) { + public Set getPlots(@Nonnull final PlotPlayer player) { return getPlots(player.getUUID()); } @@ -529,11 +525,7 @@ public abstract class PlotArea { return this.plots.values(); } - public Set getPlotsAbs(PlotPlayer player) { - return player != null ? getPlotsAbs(player.getUUID()) : new HashSet(); - } - - public int getPlotCount(UUID uuid) { + public int getPlotCount(@Nonnull final UUID uuid) { if (!Settings.Done.COUNTS_TOWARDS_LIMIT) { int count = 0; for (Plot plot : getPlotsAbs(uuid)) { @@ -546,7 +538,7 @@ public abstract class PlotArea { return getPlotsAbs(uuid).size(); } - public boolean hasPlot(UUID uuid) { + public boolean hasPlot(@Nonnull final UUID uuid) { for (Entry entry : this.plots.entrySet()) { if (entry.getValue().isOwner(uuid)) return true; @@ -554,11 +546,11 @@ public abstract class PlotArea { return false; } - public int getPlotCount(PlotPlayer player) { + public int getPlotCount(@Nullable final PlotPlayer player) { return player != null ? getPlotCount(player.getUUID()) : 0; } - public Plot getPlotAbs(PlotId id) { + @Nullable public Plot getPlotAbs(@Nonnull final PlotId id) { Plot plot = getOwnedPlotAbs(id); if (plot == null) { if (this.min != null && (id.x < this.min.x || id.x > this.max.x || id.y < this.min.y @@ -570,8 +562,8 @@ public abstract class PlotArea { return plot; } - public Plot getPlot(PlotId id) { - Plot plot = getOwnedPlotAbs(id); + @Nullable public Plot getPlot(@Nonnull final PlotId id) { + final Plot plot = getOwnedPlotAbs(id); if (plot == null) { if (this.min != null && (id.x < this.min.x || id.x > this.max.x || id.y < this.min.y || id.y > this.max.y)) { @@ -591,15 +583,15 @@ public abstract class PlotArea { return this.plots.size(); } - public PlotCluster getCluster(Location location) { - Plot plot = getPlot(location); + @Nullable public PlotCluster getCluster(@Nonnull final Location location) { + final Plot plot = getPlot(location); if (plot == null) { return null; } return this.clusters != null ? this.clusters.get(plot.getId().x, plot.getId().y) : null; } - public PlotCluster getFirstIntersectingCluster(PlotId pos1, PlotId pos2) { + @Nullable public PlotCluster getFirstIntersectingCluster(@Nonnull final PlotId pos1, @Nonnull final PlotId pos2) { if (this.clusters == null) { return null; } @@ -611,7 +603,7 @@ public abstract class PlotArea { return null; } - public PlotCluster getCluster(PlotId id) { + @Nullable PlotCluster getCluster(@Nonnull final PlotId id) { return this.clusters != null ? this.clusters.get(id.x, id.y) : null; } @@ -623,20 +615,17 @@ public abstract class PlotArea { * Session only plot metadata (session is until the server stops). *
* For persistent metadata use the flag system - * - * @param key - * @param value * @see FlagManager */ - public void setMeta(String key, Object value) { + public void setMeta(@Nonnull final String key, @Nullable final Object value) { if (this.meta == null) { this.meta = new ConcurrentHashMap<>(); } this.meta.put(key, value); } - public T getMeta(String key, T def) { - Object v = getMeta(key); + @Nullable public T getMeta(@Nullable final String key, @Nullable final T def) { + final Object v = getMeta(key); return v == null ? def : (T) v; } @@ -644,59 +633,50 @@ public abstract class PlotArea { * Get the metadata for a key
*
* For persistent metadata use the flag system - * - * @param key - * @return */ - public Object getMeta(String key) { + @Nullable public Object getMeta(@Nonnull final String key) { if (this.meta != null) { return this.meta.get(key); } return null; } - public Set getBasePlots() { - HashSet myPlots = new HashSet<>(getPlots()); - Iterator iterator = myPlots.iterator(); - while (iterator.hasNext()) { - if (!iterator.next().isBasePlot()) { - iterator.remove(); - } - } + @SuppressWarnings("unused") @Nonnull public Set getBasePlots() { + final HashSet myPlots = new HashSet<>(getPlots()); + myPlots.removeIf(plot -> !plot.isBasePlot()); return myPlots; } - public void foreachPlotAbs(RunnableVal run) { - for (Entry entry : this.plots.entrySet()) { + private void foreachPlotAbs(@Nonnull final RunnableVal run) { + for (final Entry entry : this.plots.entrySet()) { run.run(entry.getValue()); } - } - public void foreachBasePlot(RunnableVal run) { - for (Plot plot : getPlots()) { + public void foreachBasePlot(@Nonnull final RunnableVal run) { + for (final Plot plot : getPlots()) { if (plot.isBasePlot()) { run.run(plot); } } } - public Map getPlotsRaw() { + @Nonnull public Map getPlotsRaw() { return this.plots; } - public Set> getPlotEntries() { + @Nonnull public Set> getPlotEntries() { return this.plots.entrySet(); } - public boolean addPlot(Plot plot) { + public boolean addPlot(@Nonnull final Plot plot) { for (PlotPlayer pp : plot.getPlayersInPlot()) { pp.setMeta(PlotPlayer.META_LAST_PLOT, plot); } return this.plots.put(plot.getId(), plot) == null; } - public Plot getNextFreePlot(PlotPlayer player, @Nullable PlotId start) { + public Plot getNextFreePlot(final PlotPlayer player, @Nullable PlotId start) { int plots; PlotId center; PlotId min = getMin(); @@ -710,7 +690,7 @@ public abstract class PlotArea { center = new PlotId(0, 0); plots = Integer.MAX_VALUE; } - PlotId currentId = new PlotId(0, 0); + PlotId currentId; for (int i = 0; i < plots; i++) { if (start == null) { start = getMeta("lastPlot", new PlotId(0, 0)); @@ -727,7 +707,7 @@ public abstract class PlotArea { return null; } - public boolean addPlotIfAbsent(Plot plot) { + public boolean addPlotIfAbsent(@Nonnull final Plot plot) { if (this.plots.putIfAbsent(plot.getId(), plot) == null) { for (PlotPlayer pp : plot.getPlayersInPlot()) { pp.setMeta(PlotPlayer.META_LAST_PLOT, plot); @@ -737,46 +717,17 @@ public abstract class PlotArea { return false; } - public boolean addPlotAbs(Plot plot) { + public boolean addPlotAbs(@Nonnull final Plot plot) { return this.plots.put(plot.getId(), plot) == null; } - /** - * Check if the plots in a selection are unowned. - * - * @param pos1 first corner of selection - * @param pos2 second corner of selection - * @return are plots in selection unowned - */ - public boolean isUnowned(PlotId pos1, PlotId pos2) { - int area = (pos2.x - pos1.x + 1) * (pos2.y - pos1.y + 1); - if (area > getPlotCount()) { - for (Plot plot : getPlots()) { - if (plot.getId().x >= pos1.x && plot.getId().x <= pos2.x && plot.getId().y >= pos1.y - && plot.getId().y <= pos2.y) { - return false; - } - } - } else { - 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 (this.plots.get(id) != null) { - return false; - } - } - } - } - return true; - } - /** * Get the plot border distance for a world
* * @return The border distance or Integer.MAX_VALUE if no border is set */ public int getBorder() { - Integer meta = (Integer) getMeta("worldBorder"); + final Integer meta = (Integer) getMeta("worldBorder"); if (meta != null) { int border = meta + 1; if (border == 0) { @@ -795,11 +746,11 @@ public abstract class PlotArea { if (!this.WORLD_BORDER) { return; } - Integer meta = (Integer) getMeta("worldBorder"); + final Integer meta = (Integer) getMeta("worldBorder"); if (meta == null) { setMeta("worldBorder", 1); } - for (Plot plot : getPlots()) { + for (final Plot plot : getPlots()) { plot.updateWorldBorder(); } } @@ -809,30 +760,33 @@ public abstract class PlotArea { * - metadata is session only * - deleting other plugin's metadata may cause issues * - * @param key + * @param key Meta data key */ - public void deleteMeta(String key) { + public void deleteMeta(@Nonnull final String key) { if (this.meta != null) { this.meta.remove(key); } } - public boolean canClaim(PlotPlayer player, PlotId pos1, PlotId pos2) { + public boolean canClaim(@Nullable final PlotPlayer player, @Nonnull final PlotId pos1, + @Nonnull final PlotId pos2) { if (pos1.x == pos2.x && pos1.y == pos2.y) { if (getOwnedPlot(pos1) != null) { return false; } - Plot plot = getPlotAbs(pos1); - if (plot == null) + final Plot plot = getPlotAbs(pos1); + if (plot == null) { return false; + } return plot.canClaim(player); } for (int x = pos1.x; x <= pos2.x; x++) { for (int y = pos1.y; y <= pos2.y; y++) { - PlotId id = new PlotId(x, y); - Plot plot = getPlotAbs(id); - if (plot == null) + final PlotId id = new PlotId(x, y); + final Plot plot = getPlotAbs(id); + if (plot == null) { return false; + } if (!plot.canClaim(player)) { return false; } @@ -841,27 +795,27 @@ public abstract class PlotArea { return true; } - public boolean removePlot(PlotId id) { + public boolean removePlot(@Nonnull final PlotId id) { return this.plots.remove(id) != null; } - public boolean mergePlots(ArrayList plotIds, boolean removeRoads, - boolean updateDatabase) { + public boolean mergePlots(@Nonnull final List plotIds, final boolean removeRoads) { if (plotIds.size() < 2) { return false; } - PlotId pos1 = plotIds.get(0); - PlotId pos2 = plotIds.get(plotIds.size() - 1); - PlotManager manager = getPlotManager(); - boolean result = EventUtil.manager.callMerge(getPlotAbs(pos1), plotIds); + final PlotId pos1 = plotIds.get(0); + final PlotId pos2 = plotIds.get(plotIds.size() - 1); + final PlotManager manager = getPlotManager(); + + final boolean result = EventUtil.manager.callMerge(getPlotAbs(pos1), plotIds); if (!result) { return false; } - HashSet trusted = new HashSet<>(); - HashSet members = new HashSet<>(); - HashSet denied = new HashSet<>(); + final Set trusted = new HashSet<>(); + final Set members = new HashSet<>(); + final Set denied = new HashSet<>(); manager.startPlotMerge(this, plotIds); for (int x = pos1.x; x <= pos2.x; x++) { @@ -881,13 +835,15 @@ public abstract class PlotArea { denied.removeAll(members); 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); - Plot plot = getPlotAbs(id); + final boolean lx = x < pos2.x; + final boolean ly = y < pos2.y; + final PlotId id = new PlotId(x, y); + final Plot plot = getPlotAbs(id); + plot.setTrusted(trusted); plot.setMembers(members); plot.setDenied(denied); + Plot plot2; if (lx) { if (ly) { @@ -922,12 +878,12 @@ public abstract class PlotArea { * @param pos2 second corner of selection * @return the plots in the selection which are owned */ - public HashSet getPlotSelectionOwned(PlotId pos1, PlotId pos2) { - int size = (1 + pos2.x - pos1.x) * (1 + pos2.y - pos1.y); - HashSet result = new HashSet<>(); + public Set getPlotSelectionOwned(@Nonnull final PlotId pos1, @Nonnull final PlotId pos2) { + final int size = (1 + pos2.x - pos1.x) * (1 + pos2.y - pos1.y); + final Set result = new HashSet<>(); if (size < 16 || size < getPlotCount()) { - for (PlotId pid : MainUtil.getPlotSelectionIds(pos1, pos2)) { - Plot plot = getPlotAbs(pid); + for (final PlotId pid : MainUtil.getPlotSelectionIds(pos1, pos2)) { + final Plot plot = getPlotAbs(pid); if (plot.hasOwner()) { if (plot.getId().x > pos1.x || plot.getId().y > pos1.y || plot.getId().x < pos2.x || plot.getId().y < pos2.y) { @@ -936,7 +892,7 @@ public abstract class PlotArea { } } } else { - for (Plot plot : getPlots()) { + for (final Plot plot : getPlots()) { if (plot.getId().x > pos1.x || plot.getId().y > pos1.y || plot.getId().x < pos2.x || plot.getId().y < pos2.y) { result.add(plot); @@ -946,14 +902,15 @@ public abstract class PlotArea { return result; } - public void removeCluster(PlotCluster plotCluster) { + @SuppressWarnings("WeakerAccess") + public void removeCluster(@Nullable final PlotCluster plotCluster) { if (this.clusters == null) { throw new IllegalAccessError("Clusters not enabled!"); } this.clusters.remove(plotCluster); } - public void addCluster(PlotCluster plotCluster) { + public void addCluster(@Nullable final PlotCluster plotCluster) { if (this.clusters == null) { this.clusters = new QuadMap(Integer.MAX_VALUE, 0, 0, 62) { @Override public RegionWrapper getRegion(PlotCluster value) { @@ -965,7 +922,7 @@ public abstract class PlotArea { this.clusters.add(plotCluster); } - public PlotCluster getCluster(String string) { + @Nullable public PlotCluster getCluster(final String string) { for (PlotCluster cluster : getClusters()) { if (cluster.getName().equalsIgnoreCase(string)) { return cluster; @@ -973,4 +930,5 @@ public abstract class PlotArea { } return null; } + } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotManager.java index 4a7b3b8a2..0e99ce00a 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotManager.java @@ -4,9 +4,9 @@ import com.github.intellectualsites.plotsquared.plot.commands.Template; import com.github.intellectualsites.plotsquared.plot.config.Settings; import java.io.IOException; -import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; +import java.util.List; public abstract class PlotManager { @@ -60,13 +60,13 @@ public abstract class PlotManager { public abstract boolean removeRoadSouthEast(PlotArea plotArea, Plot plot); - public abstract boolean startPlotMerge(PlotArea plotArea, ArrayList plotIds); + public abstract boolean startPlotMerge(PlotArea plotArea, List plotIds); - public abstract boolean startPlotUnlink(PlotArea plotArea, ArrayList plotIds); + public abstract boolean startPlotUnlink(PlotArea plotArea, List plotIds); - public abstract boolean finishPlotMerge(PlotArea plotArea, ArrayList plotIds); + public abstract boolean finishPlotMerge(PlotArea plotArea, List plotIds); - public abstract boolean finishPlotUnlink(PlotArea plotArea, ArrayList plotIds); + public abstract boolean finishPlotUnlink(PlotArea plotArea, List plotIds); public void exportTemplate(PlotArea plotArea) throws IOException { HashSet files = new HashSet<>(Collections.singletonList( diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java index bca105f6d..1cc49f682 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java @@ -9,6 +9,9 @@ import com.github.intellectualsites.plotsquared.plot.util.SetupUtils; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + public class SinglePlotArea extends GridPlotWorld { public boolean VOID = false; @@ -58,7 +61,7 @@ public class SinglePlotArea extends GridPlotWorld { new ConfigurationNode("void", this.VOID, "Void world", Configuration.BOOLEAN)}; } - @Override public Plot getOwnedPlot(Location location) { + @Nullable @Override public Plot getOwnedPlot(@Nonnull final Location location) { PlotId pid = PlotId.fromString(location.getWorld()); if (pid == null) { return null; @@ -67,7 +70,7 @@ public class SinglePlotArea extends GridPlotWorld { return plot == null ? null : plot.getBasePlot(false); } - @Override public Plot getOwnedPlotAbs(Location location) { + @Nullable @Override public Plot getOwnedPlotAbs(@Nonnull Location location) { PlotId pid = PlotId.fromString(location.getWorld()); if (pid == null) { return null; @@ -75,7 +78,7 @@ public class SinglePlotArea extends GridPlotWorld { return plots.get(pid); } - @Override public Plot getPlot(Location location) { + @Nullable @Override public Plot getPlot(@Nonnull final Location location) { PlotId pid = PlotId.fromString(location.getWorld()); if (pid == null) { return null; @@ -83,30 +86,30 @@ public class SinglePlotArea extends GridPlotWorld { return getPlot(pid); } - @Override public Plot getPlotAbs(Location location) { - PlotId pid = PlotId.fromString(location.getWorld()); + @Nullable @Override public Plot getPlotAbs(@Nonnull final Location location) { + final PlotId pid = PlotId.fromString(location.getWorld()); if (pid == null) { return null; } return getPlotAbs(pid); } - public boolean addPlot(Plot plot) { + public boolean addPlot(@Nonnull Plot plot) { plot = adapt(plot); return super.addPlot(plot); } - @Override public boolean addPlotAbs(Plot plot) { + @Override public boolean addPlotAbs(@Nonnull Plot plot) { plot = adapt(plot); return super.addPlotAbs(plot); } - @Override public boolean addPlotIfAbsent(Plot plot) { + @Override public boolean addPlotIfAbsent(@Nonnull Plot plot) { plot = adapt(plot); return super.addPlotIfAbsent(plot); } - protected Plot adapt(Plot p) { + private Plot adapt(Plot p) { if (p instanceof SinglePlot) { return p; } @@ -117,7 +120,7 @@ public class SinglePlotArea extends GridPlotWorld { return p; } - public Plot getPlotAbs(PlotId id) { + @Nullable public Plot getPlotAbs(@Nonnull final PlotId id) { Plot plot = getOwnedPlotAbs(id); if (plot == null) { return new SinglePlot(this, id); @@ -125,7 +128,7 @@ public class SinglePlotArea extends GridPlotWorld { return plot; } - public Plot getPlot(PlotId id) { + @Nullable public Plot getPlot(@Nonnull PlotId id) { // TODO Plot plot = getOwnedPlotAbs(id); if (plot == null) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotManager.java index 0222dc815..8e5a6da12 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotManager.java @@ -7,7 +7,7 @@ import com.github.intellectualsites.plotsquared.plot.util.SetupUtils; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import java.io.File; -import java.util.ArrayList; +import java.util.List; public class SinglePlotManager extends PlotManager { @Override public PlotId getPlotIdAbs(PlotArea plotArea, int x, int y, int z) { @@ -88,19 +88,19 @@ public class SinglePlotManager extends PlotManager { return false; } - @Override public boolean startPlotMerge(PlotArea plotArea, ArrayList plotIds) { + @Override public boolean startPlotMerge(PlotArea plotArea, List plotIds) { return false; } - @Override public boolean startPlotUnlink(PlotArea plotArea, ArrayList plotIds) { + @Override public boolean startPlotUnlink(PlotArea plotArea, List plotIds) { return false; } - @Override public boolean finishPlotMerge(PlotArea plotArea, ArrayList plotIds) { + @Override public boolean finishPlotMerge(PlotArea plotArea, List plotIds) { return false; } - @Override public boolean finishPlotUnlink(PlotArea plotArea, ArrayList plotIds) { + @Override public boolean finishPlotUnlink(PlotArea plotArea, List plotIds) { return false; } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java index 45052042a..1a7d8bb8c 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java @@ -11,8 +11,8 @@ import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; import com.google.common.base.Optional; import javax.annotation.Nullable; -import java.util.ArrayList; import java.util.HashSet; +import java.util.List; import java.util.UUID; public abstract class EventUtil { @@ -45,9 +45,9 @@ public abstract class EventUtil { public abstract boolean callFlagRemove(Flag flag, Object value, PlotCluster cluster); - public abstract boolean callMerge(Plot plot, ArrayList plots); + public abstract boolean callMerge(Plot plot, List plots); - public abstract boolean callUnlink(PlotArea area, ArrayList plots); + public abstract boolean callUnlink(PlotArea area, List plots); public abstract void callEntry(PlotPlayer player, Plot plot); @@ -90,11 +90,7 @@ public abstract class EventUtil { public void doRespawnTask(final PlotPlayer player) { final Plot plot = player.getCurrentPlot(); if (Settings.Teleport.ON_DEATH && plot != null) { - TaskManager.runTask(new Runnable() { - @Override public void run() { - plot.teleportPlayer(player); - } - }); + TaskManager.runTask(() -> plot.teleportPlayer(player)); MainUtil.sendMessage(player, C.TELEPORTED_TO_ROAD); } } diff --git a/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/util/EventUtilTest.java b/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/util/EventUtilTest.java index 566a459b3..aee8176b9 100644 --- a/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/util/EventUtilTest.java +++ b/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/util/EventUtilTest.java @@ -3,7 +3,7 @@ package com.github.intellectualsites.plotsquared.plot.util; import com.github.intellectualsites.plotsquared.plot.flag.Flag; import com.github.intellectualsites.plotsquared.plot.object.*; -import java.util.ArrayList; +import java.util.List; import java.util.UUID; public class EventUtilTest extends EventUtil { @@ -43,11 +43,11 @@ public class EventUtilTest extends EventUtil { return true; } - @Override public boolean callMerge(Plot plot, ArrayList plots) { + @Override public boolean callMerge(Plot plot, List plots) { return false; } - @Override public boolean callUnlink(PlotArea area, ArrayList plots) { + @Override public boolean callUnlink(PlotArea area, List plots) { return false; }