Apply API changes to events

This commit is contained in:
Hannes Greule 2020-02-18 18:56:02 +01:00
parent 161bf3db23
commit 9adaa4ae79
6 changed files with 84 additions and 49 deletions

View File

@ -1,6 +1,6 @@
package com.github.intellectualsites.plotsquared.bukkit.events; 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 com.github.intellectualsites.plotsquared.plot.object.Plot;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@ -8,10 +8,9 @@ import org.bukkit.event.HandlerList;
/** /**
* Called when a Flag is added to a plot. * 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 static final HandlerList handlers = new HandlerList();
private final Flag flag;
private boolean cancelled; private boolean cancelled;
/** /**
@ -20,24 +19,14 @@ public class PlotFlagAddEvent extends PlotEvent implements Cancellable {
* @param flag Flag that was added * @param flag Flag that was added
* @param plot Plot to which the flag was added * @param plot Plot to which the flag was added
*/ */
public PlotFlagAddEvent(Flag flag, Plot plot) { public PlotFlagAddEvent(PlotFlag<?, ?> flag, Plot plot) {
super(plot); super(plot, flag);
this.flag = flag;
} }
public static HandlerList getHandlerList() { public static HandlerList getHandlerList() {
return handlers; return handlers;
} }
/**
* Get the flag involved.
*
* @return Flag
*/
public Flag getFlag() {
return this.flag;
}
@Override public HandlerList getHandlers() { @Override public HandlerList getHandlers() {
return handlers; return handlers;
} }

View File

@ -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;
}
}

View File

@ -1,6 +1,6 @@
package com.github.intellectualsites.plotsquared.bukkit.events; 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 com.github.intellectualsites.plotsquared.plot.object.Plot;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@ -8,10 +8,9 @@ import org.bukkit.event.HandlerList;
/** /**
* Called when a flag is removed from a plot * 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 static final HandlerList handlers = new HandlerList();
private final Flag flag;
private boolean cancelled; private boolean cancelled;
/** /**
@ -20,24 +19,14 @@ public class PlotFlagRemoveEvent extends PlotEvent implements Cancellable {
* @param flag Flag that was removed * @param flag Flag that was removed
* @param plot Plot from which the flag was removed * @param plot Plot from which the flag was removed
*/ */
public PlotFlagRemoveEvent(Flag flag, Plot plot) { public PlotFlagRemoveEvent(PlotFlag<?, ?> flag, Plot plot) {
super(plot); super(plot, flag);
this.flag = flag;
} }
public static HandlerList getHandlerList() { public static HandlerList getHandlerList() {
return handlers; return handlers;
} }
/**
* Get the flag involved
*
* @return Flag
*/
public Flag getFlag() {
return this.flag;
}
@Override public HandlerList getHandlers() { @Override public HandlerList getHandlers() {
return handlers; return handlers;
} }

View File

@ -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.Captions;
import com.github.intellectualsites.plotsquared.plot.config.Settings; 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.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.AnimalInteractFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.BlockBurnFlag; 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.BlockIgnitionFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.BlockedCmdsFlag; 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.DenyTeleportFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DisablePhysicsFlag; 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.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.ExplosionFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.GrassGrowFlag; 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.HangingBreakFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.HangingPlaceFlag; 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.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.HostileInteractFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.IceFormFlag; 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.IceMeltFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.KelpGrowFlag; 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.LiquidFlowFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.MiscBreakFlag; 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.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.MobPlaceFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.MycelGrowFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.MycelGrowFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.PlaceFlag; 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.UntrustedVisitFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.UseFlag; 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.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.VehicleUseFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.VillagerInteractFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.VillagerInteractFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.VineGrowFlag; 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) { public static boolean checkEntity(Entity entity, Plot plot) {
if (plot == null || !plot.hasOwner() || plot.getFlags().isEmpty() && plot if (plot == null || !plot.hasOwner() || plot.getFlags().isEmpty() && plot
.getArea().DEFAULT_FLAGS.isEmpty()) { .getArea().getFlagContainer().getFlagMap().isEmpty()) {
return false; return false;
} }
switch (entity.getType()) { switch (entity.getType()) {
@ -258,11 +265,13 @@ import java.util.regex.Pattern;
case UNKNOWN: case UNKNOWN:
case WITHER_SKULL: case WITHER_SKULL:
// non moving / unmovable // non moving / unmovable
return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP); return EntityUtil.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED);
case ARMOR_STAND: case ARMOR_STAND:
case ITEM_FRAME: case ITEM_FRAME:
case PAINTING: 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 // misc
case BOAT: case BOAT:
case MINECART: case MINECART:
@ -272,7 +281,9 @@ import java.util.regex.Pattern;
case MINECART_HOPPER: case MINECART_HOPPER:
case MINECART_MOB_SPAWNER: case MINECART_MOB_SPAWNER:
case MINECART_TNT: 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 BAT:
case CHICKEN: case CHICKEN:
case CAT: case CAT:
@ -305,8 +316,10 @@ import java.util.regex.Pattern;
case WOLF: case WOLF:
case ZOMBIE_HORSE: case ZOMBIE_HORSE:
// animal // animal
return EntityUtil return EntityUtil.checkEntity(plot,
.checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.ANIMAL_CAP); EntityCapFlag.ENTITY_CAP_UNLIMITED,
MobCapFlag.MOB_CAP_UNLIMITED,
AnimalCapFlag.ANIMAL_CAP_UNLIMITED);
case BLAZE: case BLAZE:
case CAVE_SPIDER: case CAVE_SPIDER:
case CREEPER: case CREEPER:
@ -341,26 +354,39 @@ import java.util.regex.Pattern;
case RAVAGER: case RAVAGER:
// monster // monster
return EntityUtil 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: default:
if (entity instanceof LivingEntity) { if (entity instanceof LivingEntity) {
if (entity instanceof Animals || entity instanceof WaterMob) { if (entity instanceof Animals || entity instanceof WaterMob) {
return EntityUtil return EntityUtil.checkEntity(plot,
.checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.ANIMAL_CAP); EntityCapFlag.ENTITY_CAP_UNLIMITED,
MobCapFlag.MOB_CAP_UNLIMITED,
AnimalCapFlag.ANIMAL_CAP_UNLIMITED);
} else if (entity instanceof Monster) { } else if (entity instanceof Monster) {
return EntityUtil return EntityUtil.checkEntity(plot,
.checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.HOSTILE_CAP); EntityCapFlag.ENTITY_CAP_UNLIMITED,
MobCapFlag.MOB_CAP_UNLIMITED,
HostileCapFlag.HOSTILE_CAP_UNLIMITED);
} else { } 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) { 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) { 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); PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
if (victim instanceof Hanging) { // hanging if (victim instanceof Hanging) { // hanging
if (plot != null && (plot.getFlag(HangingBreakFlag.class)) || plot if (plot != null && (plot.getFlag(HangingBreakFlag.class)) || plot
.isAdded(plotPlayer.getUUID()))) { .isAdded(plotPlayer.getUUID())) {
if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) { if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
if (!Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { if (!Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_OTHER)) {
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_OTHER); MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_OTHER);

View File

@ -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.PlotRateEvent;
import com.github.intellectualsites.plotsquared.bukkit.events.PlotUnlinkEvent; import com.github.intellectualsites.plotsquared.bukkit.events.PlotUnlinkEvent;
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer; 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.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
@ -75,11 +75,11 @@ public final class BukkitEventUtil extends EventUtil {
return callEvent(new PlotDeleteEvent(plot)); 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)); 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)); return callEvent(new PlotFlagRemoveEvent(flag, plot));
} }

View File

@ -1085,6 +1085,15 @@ public class Plot {
PlotAnalysis.analyzePlot(this, whenDone); PlotAnalysis.analyzePlot(this, whenDone);
} }
/**
* Gets all flags applied to this plot
*
* @return all applied flags
*/
public Set<PlotFlag<?, ?>> getFlags() {
return ImmutableSet.copyOf(flagContainer.getFlagMap().values());
}
/** /**
* Sets a flag for this plot * Sets a flag for this plot
* *