diff --git a/src/io/github/dre2n/dungeonsxl/dungeon/game/GameWorld.java b/src/io/github/dre2n/dungeonsxl/dungeon/game/GameWorld.java index eee9e914..dc913d85 100644 --- a/src/io/github/dre2n/dungeonsxl/dungeon/game/GameWorld.java +++ b/src/io/github/dre2n/dungeonsxl/dungeon/game/GameWorld.java @@ -8,6 +8,7 @@ import io.github.dre2n.dungeonsxl.dungeon.EditWorld; import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldLoadEvent; import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldStartGameEvent; import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldUnloadEvent; +import io.github.dre2n.dungeonsxl.event.requirement.RequirementCheckEvent; import io.github.dre2n.dungeonsxl.mob.DMob; import io.github.dre2n.dungeonsxl.player.DPlayer; import io.github.dre2n.dungeonsxl.requirement.Requirement; @@ -419,6 +420,11 @@ public class GameWorld { WorldConfig worldConfig = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + dungeon, "config.yml")); for (Requirement requirement : worldConfig.getRequirements()) { + RequirementCheckEvent event = new RequirementCheckEvent(requirement, player); + if (event.isCancelled()) { + continue; + } + if ( !requirement.check(player)) { return false; } diff --git a/src/io/github/dre2n/dungeonsxl/event/requirement/RequirementCheckEvent.java b/src/io/github/dre2n/dungeonsxl/event/requirement/RequirementCheckEvent.java index 068e43fb..2ef9400c 100644 --- a/src/io/github/dre2n/dungeonsxl/event/requirement/RequirementCheckEvent.java +++ b/src/io/github/dre2n/dungeonsxl/event/requirement/RequirementCheckEvent.java @@ -13,24 +13,26 @@ public class RequirementCheckEvent extends RequirementEvent implements Cancellab private Player player; - public RequirementCheckEvent(Requirement requirement) { + public RequirementCheckEvent(Requirement requirement, Player player) { super(requirement); + this.player = player; } /** * @return the player */ - public Player getPlayer() { - return player; - } - + public Player getPlayer() { + return player; + } + /** - * @param player the player to set + * @param player + * the player to set */ - public void setPlayer(Player player) { - this.player = player; - } - + public void setPlayer(Player player) { + this.player = player; + } + @Override public HandlerList getHandlers() { return handlers; diff --git a/src/io/github/dre2n/dungeonsxl/event/requirement/RequirementDemandEvent.java b/src/io/github/dre2n/dungeonsxl/event/requirement/RequirementDemandEvent.java new file mode 100644 index 00000000..73be67bd --- /dev/null +++ b/src/io/github/dre2n/dungeonsxl/event/requirement/RequirementDemandEvent.java @@ -0,0 +1,55 @@ +package io.github.dre2n.dungeonsxl.event.requirement; + +import io.github.dre2n.dungeonsxl.requirement.Requirement; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; + +public class RequirementDemandEvent extends RequirementEvent implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled; + + private Player player; + + public RequirementDemandEvent(Requirement requirement, Player player) { + super(requirement); + this.player = player; + } + + /** + * @return the player + */ + public Player getPlayer() { + return player; + } + + /** + * @param player + * the player to set + */ + public void setPlayer(Player player) { + this.player = player; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + +} diff --git a/src/io/github/dre2n/dungeonsxl/event/reward/RewardAdditionEvent.java b/src/io/github/dre2n/dungeonsxl/event/reward/RewardAdditionEvent.java index 4d85d8f3..38e525ad 100644 --- a/src/io/github/dre2n/dungeonsxl/event/reward/RewardAdditionEvent.java +++ b/src/io/github/dre2n/dungeonsxl/event/reward/RewardAdditionEvent.java @@ -1,5 +1,6 @@ package io.github.dre2n.dungeonsxl.event.reward; +import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.reward.Reward; import org.bukkit.event.Cancellable; @@ -10,8 +11,26 @@ public class RewardAdditionEvent extends RewardEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); private boolean cancelled; - public RewardAdditionEvent(Reward reward) { + private DGroup dGroup; + + public RewardAdditionEvent(Reward reward, DGroup dGroup) { super(reward); + this.dGroup = dGroup; + } + + /** + * @return the dGroup + */ + public DGroup getDGroup() { + return dGroup; + } + + /** + * @param dGroup + * the dGroup to set + */ + public void setDGroup(DGroup dGroup) { + this.dGroup = dGroup; } @Override diff --git a/src/io/github/dre2n/dungeonsxl/player/DGroup.java b/src/io/github/dre2n/dungeonsxl/player/DGroup.java index 479416e4..0ccf6523 100644 --- a/src/io/github/dre2n/dungeonsxl/player/DGroup.java +++ b/src/io/github/dre2n/dungeonsxl/player/DGroup.java @@ -4,6 +4,8 @@ import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.dungeon.Dungeon; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; import io.github.dre2n.dungeonsxl.event.dgroup.DGroupStartFloorEvent; +import io.github.dre2n.dungeonsxl.event.requirement.RequirementDemandEvent; +import io.github.dre2n.dungeonsxl.event.reward.RewardAdditionEvent; import io.github.dre2n.dungeonsxl.file.DMessages.Messages; import io.github.dre2n.dungeonsxl.global.GroupSign; import io.github.dre2n.dungeonsxl.requirement.Requirement; @@ -216,6 +218,12 @@ public class DGroup { * the rewards to add */ public void addReward(Reward reward) { + RewardAdditionEvent event = new RewardAdditionEvent(reward, this); + + if (event.isCancelled()) { + return; + } + rewards.add(reward); } @@ -261,6 +269,12 @@ public class DGroup { } for (Requirement requirement : gameWorld.getConfig().getRequirements()) { + RequirementDemandEvent requirementDemandEvent = new RequirementDemandEvent(requirement, player); + + if (requirementDemandEvent.isCancelled()) { + continue; + } + requirement.demand(player); } diff --git a/src/io/github/dre2n/dungeonsxl/trigger/DistanceTrigger.java b/src/io/github/dre2n/dungeonsxl/trigger/DistanceTrigger.java index 1cd72adf..d1e5c51d 100644 --- a/src/io/github/dre2n/dungeonsxl/trigger/DistanceTrigger.java +++ b/src/io/github/dre2n/dungeonsxl/trigger/DistanceTrigger.java @@ -1,6 +1,7 @@ package io.github.dre2n.dungeonsxl.trigger; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; +import io.github.dre2n.dungeonsxl.event.trigger.TriggerActionEvent; import java.util.ArrayList; import java.util.HashMap; @@ -30,6 +31,12 @@ public class DistanceTrigger extends Trigger { } public void onTrigger(Player player) { + TriggerActionEvent event = new TriggerActionEvent(this); + + if (event.isCancelled()) { + return; + } + setTriggered(true); this.setPlayer(player); updateDSigns(); diff --git a/src/io/github/dre2n/dungeonsxl/trigger/InteractTrigger.java b/src/io/github/dre2n/dungeonsxl/trigger/InteractTrigger.java index 44d479e5..3db6bdcf 100644 --- a/src/io/github/dre2n/dungeonsxl/trigger/InteractTrigger.java +++ b/src/io/github/dre2n/dungeonsxl/trigger/InteractTrigger.java @@ -1,6 +1,7 @@ package io.github.dre2n.dungeonsxl.trigger; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; +import io.github.dre2n.dungeonsxl.event.trigger.TriggerActionEvent; import java.util.ArrayList; import java.util.HashMap; @@ -24,6 +25,12 @@ public class InteractTrigger extends Trigger { } public void onTrigger(Player player) { + TriggerActionEvent event = new TriggerActionEvent(this); + + if (event.isCancelled()) { + return; + } + setTriggered(true); this.setPlayer(player); updateDSigns(); diff --git a/src/io/github/dre2n/dungeonsxl/trigger/MobTrigger.java b/src/io/github/dre2n/dungeonsxl/trigger/MobTrigger.java index ee048b05..8b17d54c 100644 --- a/src/io/github/dre2n/dungeonsxl/trigger/MobTrigger.java +++ b/src/io/github/dre2n/dungeonsxl/trigger/MobTrigger.java @@ -1,6 +1,7 @@ package io.github.dre2n.dungeonsxl.trigger; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; +import io.github.dre2n.dungeonsxl.event.trigger.TriggerActionEvent; import java.util.ArrayList; import java.util.HashMap; @@ -19,6 +20,12 @@ public class MobTrigger extends Trigger { } public void onTrigger() { + TriggerActionEvent event = new TriggerActionEvent(this); + + if (event.isCancelled()) { + return; + } + setTriggered(true); updateDSigns(); } diff --git a/src/io/github/dre2n/dungeonsxl/trigger/RedstoneTrigger.java b/src/io/github/dre2n/dungeonsxl/trigger/RedstoneTrigger.java index e66ada51..e910dd83 100644 --- a/src/io/github/dre2n/dungeonsxl/trigger/RedstoneTrigger.java +++ b/src/io/github/dre2n/dungeonsxl/trigger/RedstoneTrigger.java @@ -1,6 +1,7 @@ package io.github.dre2n.dungeonsxl.trigger; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; +import io.github.dre2n.dungeonsxl.event.trigger.TriggerActionEvent; import java.util.ArrayList; import java.util.HashMap; @@ -24,6 +25,12 @@ public class RedstoneTrigger extends Trigger { } public void onTrigger() { + TriggerActionEvent event = new TriggerActionEvent(this); + + if (event.isCancelled()) { + return; + } + if (rtBlock.isBlockPowered()) { if ( !isTriggered()) { setTriggered(true); diff --git a/src/io/github/dre2n/dungeonsxl/trigger/SignTrigger.java b/src/io/github/dre2n/dungeonsxl/trigger/SignTrigger.java index 05cb61ca..68ed6aee 100644 --- a/src/io/github/dre2n/dungeonsxl/trigger/SignTrigger.java +++ b/src/io/github/dre2n/dungeonsxl/trigger/SignTrigger.java @@ -1,6 +1,7 @@ package io.github.dre2n.dungeonsxl.trigger; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; +import io.github.dre2n.dungeonsxl.event.trigger.TriggerActionEvent; import java.util.ArrayList; import java.util.HashMap; @@ -19,6 +20,12 @@ public class SignTrigger extends Trigger { } public void onTrigger(boolean enable) { + TriggerActionEvent event = new TriggerActionEvent(this); + + if (event.isCancelled()) { + return; + } + if (enable != isTriggered()) { setTriggered(enable); updateDSigns(); diff --git a/src/io/github/dre2n/dungeonsxl/trigger/Trigger.java b/src/io/github/dre2n/dungeonsxl/trigger/Trigger.java index 6973c053..5036cfcb 100644 --- a/src/io/github/dre2n/dungeonsxl/trigger/Trigger.java +++ b/src/io/github/dre2n/dungeonsxl/trigger/Trigger.java @@ -2,6 +2,7 @@ package io.github.dre2n.dungeonsxl.trigger; import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; +import io.github.dre2n.dungeonsxl.event.trigger.TriggerRegistrationEvent; import io.github.dre2n.dungeonsxl.sign.DSign; import io.github.dre2n.dungeonsxl.util.NumberUtil; @@ -149,6 +150,12 @@ public abstract class Trigger { } } + TriggerRegistrationEvent event = new TriggerRegistrationEvent(trigger); + + if (event.isCancelled()) { + return null; + } + return trigger; } diff --git a/src/io/github/dre2n/dungeonsxl/trigger/UseItemTrigger.java b/src/io/github/dre2n/dungeonsxl/trigger/UseItemTrigger.java index eb5307a2..17c72d8f 100644 --- a/src/io/github/dre2n/dungeonsxl/trigger/UseItemTrigger.java +++ b/src/io/github/dre2n/dungeonsxl/trigger/UseItemTrigger.java @@ -1,6 +1,7 @@ package io.github.dre2n.dungeonsxl.trigger; import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld; +import io.github.dre2n.dungeonsxl.event.trigger.TriggerActionEvent; import java.util.ArrayList; import java.util.HashMap; @@ -27,6 +28,12 @@ public class UseItemTrigger extends Trigger { } public void onTrigger(Player player) { + TriggerActionEvent event = new TriggerActionEvent(this); + + if (event.isCancelled()) { + return; + } + setTriggered(true); this.setPlayer(player); updateDSigns();