From 9adaa4ae79baf7793caffa83542bbadd285c2247 Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Tue, 18 Feb 2020 18:56:02 +0100 Subject: [PATCH] Apply API changes to events --- .../bukkit/events/PlotFlagAddEvent.java | 19 ++---- .../bukkit/events/PlotFlagEvent.java | 22 +++++++ .../bukkit/events/PlotFlagRemoveEvent.java | 19 ++---- .../bukkit/listeners/PlayerEvents.java | 58 ++++++++++++++----- .../bukkit/util/BukkitEventUtil.java | 6 +- .../plotsquared/plot/object/Plot.java | 9 +++ 6 files changed, 84 insertions(+), 49 deletions(-) create mode 100644 Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotFlagEvent.java diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotFlagAddEvent.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotFlagAddEvent.java index e8c4ac63c..6f28f707c 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotFlagAddEvent.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotFlagAddEvent.java @@ -1,6 +1,6 @@ package com.github.intellectualsites.plotsquared.bukkit.events; -import com.github.intellectualsites.plotsquared.plot.flag.Flag; +import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag; import com.github.intellectualsites.plotsquared.plot.object.Plot; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; @@ -8,10 +8,9 @@ import org.bukkit.event.HandlerList; /** * Called when a Flag is added to a plot. */ -public class PlotFlagAddEvent extends PlotEvent implements Cancellable { +public class PlotFlagAddEvent extends PlotFlagEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); - private final Flag flag; private boolean cancelled; /** @@ -20,24 +19,14 @@ public class PlotFlagAddEvent extends PlotEvent implements Cancellable { * @param flag Flag that was added * @param plot Plot to which the flag was added */ - public PlotFlagAddEvent(Flag flag, Plot plot) { - super(plot); - this.flag = flag; + public PlotFlagAddEvent(PlotFlag flag, Plot plot) { + super(plot, flag); } public static HandlerList getHandlerList() { return handlers; } - /** - * Get the flag involved. - * - * @return Flag - */ - public Flag getFlag() { - return this.flag; - } - @Override public HandlerList getHandlers() { return handlers; } diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotFlagEvent.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotFlagEvent.java new file mode 100644 index 000000000..830c3b567 --- /dev/null +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotFlagEvent.java @@ -0,0 +1,22 @@ +package com.github.intellectualsites.plotsquared.bukkit.events; + +import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag; +import com.github.intellectualsites.plotsquared.plot.object.Plot; + +public abstract class PlotFlagEvent extends PlotEvent { + private final PlotFlag flag; + + protected PlotFlagEvent(Plot plot, PlotFlag flag) { + super(plot); + this.flag = flag; + } + + /** + * Get the flag involved + * + * @return Flag + */ + public PlotFlag getFlag() { + return flag; + } +} diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotFlagRemoveEvent.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotFlagRemoveEvent.java index 3e3e48b55..d0d5724d4 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotFlagRemoveEvent.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotFlagRemoveEvent.java @@ -1,6 +1,6 @@ package com.github.intellectualsites.plotsquared.bukkit.events; -import com.github.intellectualsites.plotsquared.plot.flag.Flag; +import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag; import com.github.intellectualsites.plotsquared.plot.object.Plot; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; @@ -8,10 +8,9 @@ import org.bukkit.event.HandlerList; /** * Called when a flag is removed from a plot */ -public class PlotFlagRemoveEvent extends PlotEvent implements Cancellable { +public class PlotFlagRemoveEvent extends PlotFlagEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); - private final Flag flag; private boolean cancelled; /** @@ -20,24 +19,14 @@ public class PlotFlagRemoveEvent extends PlotEvent implements Cancellable { * @param flag Flag that was removed * @param plot Plot from which the flag was removed */ - public PlotFlagRemoveEvent(Flag flag, Plot plot) { - super(plot); - this.flag = flag; + public PlotFlagRemoveEvent(PlotFlag flag, Plot plot) { + super(plot, flag); } public static HandlerList getHandlerList() { return handlers; } - /** - * Get the flag involved - * - * @return Flag - */ - public Flag getFlag() { - return this.flag; - } - @Override public HandlerList getHandlers() { return handlers; } diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java index 60d8ed763..6f703ff39 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java @@ -8,25 +8,31 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.flags.implementations.AnimalAttackFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.AnimalCapFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.AnimalInteractFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.BlockBurnFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.BlockIgnitionFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.BlockedCmdsFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.BreakFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.DenyTeleportFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.DisablePhysicsFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.DoneFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.EntityCapFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.ExplosionFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.GrassGrowFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.HangingBreakFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.HangingPlaceFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.HostileAttackFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.HostileCapFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.HostileInteractFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.IceFormFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.IceMeltFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.KelpGrowFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.LiquidFlowFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.MiscBreakFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.MiscCapFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.MiscInteractFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.MobCapFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.MobPlaceFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.MycelGrowFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.PlaceFlag; @@ -42,6 +48,7 @@ import com.github.intellectualsites.plotsquared.plot.flags.implementations.Tamed import com.github.intellectualsites.plotsquared.plot.flags.implementations.UntrustedVisitFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.UseFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.VehicleBreakFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.VehicleCapFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.VehicleUseFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.VillagerInteractFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.VineGrowFlag; @@ -223,7 +230,7 @@ import java.util.regex.Pattern; public static boolean checkEntity(Entity entity, Plot plot) { if (plot == null || !plot.hasOwner() || plot.getFlags().isEmpty() && plot - .getArea().DEFAULT_FLAGS.isEmpty()) { + .getArea().getFlagContainer().getFlagMap().isEmpty()) { return false; } switch (entity.getType()) { @@ -258,11 +265,13 @@ import java.util.regex.Pattern; case UNKNOWN: case WITHER_SKULL: // non moving / unmovable - return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP); + return EntityUtil.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED); case ARMOR_STAND: case ITEM_FRAME: case PAINTING: - return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.MISC_CAP); + return EntityUtil.checkEntity(plot, + EntityCapFlag.ENTITY_CAP_UNLIMITED, + MiscCapFlag.MISC_CAP_UNLIMITED); // misc case BOAT: case MINECART: @@ -272,7 +281,9 @@ import java.util.regex.Pattern; case MINECART_HOPPER: case MINECART_MOB_SPAWNER: case MINECART_TNT: - return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.VEHICLE_CAP); + return EntityUtil.checkEntity(plot, + EntityCapFlag.ENTITY_CAP_UNLIMITED, + VehicleCapFlag.VEHICLE_CAP_UNLIMITED); case BAT: case CHICKEN: case CAT: @@ -305,8 +316,10 @@ import java.util.regex.Pattern; case WOLF: case ZOMBIE_HORSE: // animal - return EntityUtil - .checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.ANIMAL_CAP); + return EntityUtil.checkEntity(plot, + EntityCapFlag.ENTITY_CAP_UNLIMITED, + MobCapFlag.MOB_CAP_UNLIMITED, + AnimalCapFlag.ANIMAL_CAP_UNLIMITED); case BLAZE: case CAVE_SPIDER: case CREEPER: @@ -341,26 +354,39 @@ import java.util.regex.Pattern; case RAVAGER: // monster return EntityUtil - .checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.HOSTILE_CAP); + .checkEntity(plot, + EntityCapFlag.ENTITY_CAP_UNLIMITED, + MobCapFlag.MOB_CAP_UNLIMITED, + HostileCapFlag.HOSTILE_CAP_UNLIMITED); default: if (entity instanceof LivingEntity) { if (entity instanceof Animals || entity instanceof WaterMob) { - return EntityUtil - .checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.ANIMAL_CAP); + return EntityUtil.checkEntity(plot, + EntityCapFlag.ENTITY_CAP_UNLIMITED, + MobCapFlag.MOB_CAP_UNLIMITED, + AnimalCapFlag.ANIMAL_CAP_UNLIMITED); } else if (entity instanceof Monster) { - return EntityUtil - .checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.HOSTILE_CAP); + return EntityUtil.checkEntity(plot, + EntityCapFlag.ENTITY_CAP_UNLIMITED, + MobCapFlag.MOB_CAP_UNLIMITED, + HostileCapFlag.HOSTILE_CAP_UNLIMITED); } else { - return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP); + return EntityUtil.checkEntity(plot, + EntityCapFlag.ENTITY_CAP_UNLIMITED, + MobCapFlag.MOB_CAP_UNLIMITED); } } if (entity instanceof Vehicle) { - return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.VEHICLE_CAP); + return EntityUtil.checkEntity(plot, + EntityCapFlag.ENTITY_CAP_UNLIMITED, + VehicleCapFlag.VEHICLE_CAP_UNLIMITED); } if (entity instanceof Hanging) { - return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.MISC_CAP); + return EntityUtil.checkEntity(plot, + EntityCapFlag.ENTITY_CAP_UNLIMITED, + MiscCapFlag.MISC_CAP_UNLIMITED); } - return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP); + return EntityUtil.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED); } } @@ -2763,7 +2789,7 @@ import java.util.regex.Pattern; PlotPlayer plotPlayer = BukkitUtil.getPlayer(player); if (victim instanceof Hanging) { // hanging if (plot != null && (plot.getFlag(HangingBreakFlag.class)) || plot - .isAdded(plotPlayer.getUUID()))) { + .isAdded(plotPlayer.getUUID())) { if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) { if (!Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_OTHER); 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 e76a1e23e..58d6b6c11 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 @@ -18,7 +18,7 @@ import com.github.intellectualsites.plotsquared.bukkit.events.PlotMergeEvent; import com.github.intellectualsites.plotsquared.bukkit.events.PlotRateEvent; import com.github.intellectualsites.plotsquared.bukkit.events.PlotUnlinkEvent; import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer; -import com.github.intellectualsites.plotsquared.plot.flag.Flag; +import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; @@ -75,11 +75,11 @@ public final class BukkitEventUtil extends EventUtil { return callEvent(new PlotDeleteEvent(plot)); } - @Override public boolean callFlagAdd(Flag flag, Plot plot) { + @Override public boolean callFlagAdd(PlotFlag flag, Plot plot) { return callEvent(new PlotFlagAddEvent(flag, plot)); } - @Override public boolean callFlagRemove(Flag flag, Plot plot, Object value) { + @Override public boolean callFlagRemove(PlotFlag flag, Plot plot, Object value) { return callEvent(new PlotFlagRemoveEvent(flag, plot)); } 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 2d46090d5..2f121fd25 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 @@ -1085,6 +1085,15 @@ public class Plot { PlotAnalysis.analyzePlot(this, whenDone); } + /** + * Gets all flags applied to this plot + * + * @return all applied flags + */ + public Set> getFlags() { + return ImmutableSet.copyOf(flagContainer.getFlagMap().values()); + } + /** * Sets a flag for this plot *