Implement requirement, reward and trigger events

This commit is contained in:
Daniel Saukel 2016-01-13 00:28:47 +01:00
parent 6d0b6f3b6e
commit 9d78ce5db1
12 changed files with 156 additions and 11 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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();

View File

@ -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();

View File

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

View File

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

View File

@ -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();

View File

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

View File

@ -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();