Call events properly

This commit is contained in:
Daniel Saukel 2016-05-06 15:28:19 +02:00
parent 5699cc142b
commit 5a3a77cabf
23 changed files with 48 additions and 0 deletions

View File

@ -120,6 +120,7 @@ public class GroupCommand extends BRCommand {
DGroup dGroup = new DGroup(args[2], player);
DGroupCreateEvent event = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.COMMAND);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
dGroup.delete();
@ -133,6 +134,7 @@ public class GroupCommand extends BRCommand {
public void disbandGroup(DGroup dGroup) {
if (dGroup != null) {
DGroupDisbandEvent event = new DGroupDisbandEvent(dGroup, player, DGroupDisbandEvent.Cause.COMMAND);
plugin.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
dGroup.delete();
@ -212,6 +214,7 @@ public class GroupCommand extends BRCommand {
Player toKick = plugin.getServer().getPlayer(args[2]);
if (toKick != null) {
DPlayerKickEvent event = new DPlayerKickEvent(DGamePlayer.getByPlayer(toKick.getPlayer()), DPlayerKickEvent.Cause.COMMAND);
plugin.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
if (dGroup.getPlayers().contains(toKick)) {

View File

@ -61,7 +61,9 @@ public class LeaveCommand extends BRCommand {
DGroup dGroup = DGroup.getByPlayer(player);
DPlayerEscapeEvent dPlayerEscapeEvent = new DPlayerEscapeEvent(dPlayer);
plugin.getServer().getPluginManager().callEvent(dPlayerEscapeEvent);
DPlayerLeaveDGroupEvent dPlayerLeaveDGroupEvent = new DPlayerLeaveDGroupEvent(dPlayer, dGroup);
plugin.getServer().getPluginManager().callEvent(dPlayerLeaveDGroupEvent);
if (dPlayerEscapeEvent.isCancelled() || dPlayerLeaveDGroupEvent.isCancelled()) {
return;

View File

@ -143,6 +143,7 @@ public class PlayCommand extends BRCommand {
}
DGroupCreateEvent event = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.COMMAND);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
plugin.getDGroups().remove(dGroup);

View File

@ -96,6 +96,7 @@ public class PlayerListener implements Listener {
}
DPlayerDeathEvent dPlayerDeathEvent = new DPlayerDeathEvent(dPlayer, event, 1);
plugin.getServer().getPluginManager().callEvent(dPlayerDeathEvent);
if (dPlayerDeathEvent.isCancelled()) {
return;
@ -128,6 +129,7 @@ public class PlayerListener implements Listener {
if (dPlayer.getLives() == 0 && dPlayer.isReady()) {
DPlayerKickEvent dPlayerKickEvent = new DPlayerKickEvent(dPlayer, DPlayerKickEvent.Cause.DEATH);
plugin.getServer().getPluginManager().callEvent(dPlayerKickEvent);
if (!dPlayerKickEvent.isCancelled()) {
MessageUtil.broadcastMessage(DMessages.PLAYER_DEATH_KICK.getMessage(player.getName()));
@ -533,6 +535,7 @@ public class PlayerListener implements Listener {
DGroup dGroup = new DGroup(player, plugin.getMainConfig().getTutorialDungeon(), false);
DGroupCreateEvent createEvent = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.GROUP_SIGN);
plugin.getServer().getPluginManager().callEvent(createEvent);
if (createEvent.isCancelled()) {
dGroup = null;

View File

@ -23,6 +23,7 @@ import io.github.dre2n.dungeonsxl.trigger.WaveTrigger;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import java.util.Random;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.EntityDeathEvent;
@ -71,6 +72,7 @@ public class DMob {
}
DMobDeathEvent dMobDeathEvent = new DMobDeathEvent(this, event);
Bukkit.getServer().getPluginManager().callEvent(dMobDeathEvent);
if (dMobDeathEvent.isCancelled()) {
return;

View File

@ -698,6 +698,7 @@ public class DGamePlayer extends DGlobalPlayer {
}
DGroupFinishFloorEvent event = new DGroupFinishFloorEvent(dGroup, dGroup.getGameWorld(), newFloor);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
@ -756,6 +757,7 @@ public class DGamePlayer extends DGlobalPlayer {
}
DPlayerFinishEvent dPlayerFinishEvent = new DPlayerFinishEvent(this, first, hasToWait);
plugin.getServer().getPluginManager().callEvent(dPlayerFinishEvent);
if (dPlayerFinishEvent.isCancelled()) {
finished = false;
@ -767,6 +769,7 @@ public class DGamePlayer extends DGlobalPlayer {
}
DGroupFinishDungeonEvent dGroupFinishDungeonEvent = new DGroupFinishDungeonEvent(dGroup);
plugin.getServer().getPluginManager().callEvent(dGroupFinishDungeonEvent);
if (dGroupFinishDungeonEvent.isCancelled()) {
return;
@ -928,6 +931,7 @@ public class DGamePlayer extends DGlobalPlayer {
}
DPlayerUpdateEvent event = new DPlayerUpdateEvent(this, locationValid, teleportWolf, respawnInventory, offline, kick, triggerAllInDistance);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
@ -947,6 +951,7 @@ public class DGamePlayer extends DGlobalPlayer {
if (kick) {
DPlayerKickEvent dPlayerKickEvent = new DPlayerKickEvent(this, DPlayerKickEvent.Cause.OFFLINE);
plugin.getServer().getPluginManager().callEvent(dPlayerKickEvent);
if (!dPlayerKickEvent.isCancelled()) {
leave();

View File

@ -164,6 +164,7 @@ public class DGroup {
// Check group
if (isEmpty()) {
DGroupDisbandEvent event = new DGroupDisbandEvent(this, player, DGroupDisbandEvent.Cause.GROUP_IS_EMPTY);
plugin.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
delete();
@ -385,6 +386,7 @@ public class DGroup {
*/
public void addReward(Reward reward) {
RewardAdditionEvent event = new RewardAdditionEvent(reward, this);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
@ -466,6 +468,7 @@ public class DGroup {
}
DGroupStartFloorEvent event = new DGroupStartFloorEvent(this, gameWorld);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
@ -502,6 +505,7 @@ public class DGroup {
if (config != null) {
for (Requirement requirement : config.getRequirements()) {
RequirementDemandEvent requirementDemandEvent = new RequirementDemandEvent(requirement, player);
plugin.getServer().getPluginManager().callEvent(event);
if (requirementDemandEvent.isCancelled()) {
continue;

View File

@ -21,6 +21,7 @@ import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.event.requirement.RequirementRegistrationEvent;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
/**
@ -45,6 +46,7 @@ public abstract class Requirement {
}
RequirementRegistrationEvent event = new RequirementRegistrationEvent(requirement);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return null;

View File

@ -21,6 +21,7 @@ import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.event.reward.RewardRegistrationEvent;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
/**
@ -45,6 +46,7 @@ public abstract class Reward {
}
RewardRegistrationEvent event = new RewardRegistrationEvent(reward);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return null;

View File

@ -190,6 +190,7 @@ public abstract class DSign {
}
DSignRegistrationEvent event = new DSignRegistrationEvent(sign, gameWorld, dSign);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return null;

View File

@ -65,6 +65,7 @@ public class LeaveSign extends DSign {
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
if (dPlayer != null) {
DPlayerEscapeEvent event = new DPlayerEscapeEvent(dPlayer);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return false;
@ -80,6 +81,7 @@ public class LeaveSign extends DSign {
public void onTrigger() {
for (DGamePlayer dPlayer : plugin.getDPlayers().getDGamePlayers()) {
DPlayerEscapeEvent event = new DPlayerEscapeEvent(dPlayer);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;

View File

@ -23,6 +23,7 @@ import io.github.dre2n.dungeonsxl.config.DMessages;
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerKickEvent;
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
import io.github.dre2n.dungeonsxl.player.DGroup;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
@ -66,6 +67,7 @@ public class TimeIsRunningTask extends BukkitRunnable {
}
DPlayerKickEvent dPlayerKickEvent = new DPlayerKickEvent(dPlayer, DPlayerKickEvent.Cause.TIME_EXPIRED);
Bukkit.getServer().getPluginManager().callEvent(dPlayerKickEvent);
if (!dPlayerKickEvent.isCancelled()) {
MessageUtil.broadcastMessage(DMessages.PLAYER_TIME_KICK.getMessage(player.getName()));

View File

@ -49,6 +49,7 @@ public class DistanceTrigger extends Trigger {
public void onTrigger(Player player) {
TriggerActionEvent event = new TriggerActionEvent(this);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;

View File

@ -43,6 +43,7 @@ public class InteractTrigger extends Trigger {
public void onTrigger(Player player) {
TriggerActionEvent event = new TriggerActionEvent(this);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;

View File

@ -39,6 +39,7 @@ public class MobTrigger extends Trigger {
public void onTrigger() {
TriggerActionEvent event = new TriggerActionEvent(this);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;

View File

@ -95,6 +95,7 @@ public class ProgressTrigger extends Trigger {
/* Actions */
public void onTrigger() {
TriggerActionEvent event = new TriggerActionEvent(this);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;

View File

@ -43,6 +43,7 @@ public class RedstoneTrigger extends Trigger {
public void onTrigger() {
TriggerActionEvent event = new TriggerActionEvent(this);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;

View File

@ -39,6 +39,7 @@ public class SignTrigger extends Trigger {
public void onTrigger(boolean enable) {
TriggerActionEvent event = new TriggerActionEvent(this);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;

View File

@ -188,6 +188,7 @@ public abstract class Trigger {
}
TriggerRegistrationEvent event = new TriggerRegistrationEvent(trigger);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return null;

View File

@ -46,6 +46,7 @@ public class UseItemTrigger extends Trigger {
public void onTrigger(Player player) {
TriggerActionEvent event = new TriggerActionEvent(this);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;

View File

@ -56,6 +56,7 @@ public class WaveTrigger extends Trigger {
public void onTrigger() {
TriggerActionEvent event = new TriggerActionEvent(this);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;

View File

@ -208,6 +208,7 @@ public class EditWorld {
creator.generateStructures(false);
EditWorldGenerateEvent event = new EditWorldGenerateEvent(this);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
@ -218,6 +219,7 @@ public class EditWorld {
public void save() {
EditWorldSaveEvent event = new EditWorldSaveEvent(this);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
@ -256,6 +258,7 @@ public class EditWorld {
public void delete() {
EditWorldUnloadEvent event = new EditWorldUnloadEvent(this, true);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
@ -276,6 +279,7 @@ public class EditWorld {
public void deleteNoSave() {
EditWorldUnloadEvent event = new EditWorldUnloadEvent(this, false);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
@ -329,6 +333,7 @@ public class EditWorld {
public static EditWorld load(String name) {
EditWorldLoadEvent event = new EditWorldLoadEvent(name);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return null;

View File

@ -398,6 +398,7 @@ public class GameWorld {
public void startGame() {
GameWorldStartGameEvent event = new GameWorldStartGameEvent(this, getGame());
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
@ -434,6 +435,7 @@ public class GameWorld {
public void delete() {
GameWorldUnloadEvent event = new GameWorldUnloadEvent(this);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
@ -471,6 +473,7 @@ public class GameWorld {
/* Statics */
public static GameWorld load(String name) {
GameWorldLoadEvent event = new GameWorldLoadEvent(name);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return null;
@ -632,6 +635,8 @@ public class GameWorld {
for (Requirement requirement : worldConfig.getRequirements()) {
RequirementCheckEvent event = new RequirementCheckEvent(requirement, player);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
continue;
}