From 95fcccb35b0eecdba564829872734f866ce653ab Mon Sep 17 00:00:00 2001 From: Rukes Date: Mon, 14 Aug 2017 06:25:03 +0200 Subject: [PATCH] Added JobsSchedulerStartEvent & JobsSchedulerStopEvent to developer API --- .../jobs/api/JobsScheduleStartEvent.java | 39 +++++++++++++++++++ .../jobs/api/JobsScheduleStopEvent.java | 39 +++++++++++++++++++ .../jobs/config/ScheduleManager.java | 12 ++++++ 3 files changed, 90 insertions(+) create mode 100644 src/main/java/com/gamingmesh/jobs/api/JobsScheduleStartEvent.java create mode 100644 src/main/java/com/gamingmesh/jobs/api/JobsScheduleStopEvent.java diff --git a/src/main/java/com/gamingmesh/jobs/api/JobsScheduleStartEvent.java b/src/main/java/com/gamingmesh/jobs/api/JobsScheduleStartEvent.java new file mode 100644 index 00000000..58fe248f --- /dev/null +++ b/src/main/java/com/gamingmesh/jobs/api/JobsScheduleStartEvent.java @@ -0,0 +1,39 @@ +package com.gamingmesh.jobs.api; + +import com.gamingmesh.jobs.container.Schedule; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class JobsScheduleStartEvent extends Event implements Cancellable { + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled; + private Schedule schedule; + + public JobsScheduleStartEvent(Schedule schedule){ + this.schedule = schedule; + } + + public Schedule getSchedule() { + return schedule; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + cancelled = cancel; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/src/main/java/com/gamingmesh/jobs/api/JobsScheduleStopEvent.java b/src/main/java/com/gamingmesh/jobs/api/JobsScheduleStopEvent.java new file mode 100644 index 00000000..cda44e36 --- /dev/null +++ b/src/main/java/com/gamingmesh/jobs/api/JobsScheduleStopEvent.java @@ -0,0 +1,39 @@ +package com.gamingmesh.jobs.api; + +import com.gamingmesh.jobs.container.Schedule; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class JobsScheduleStopEvent extends Event implements Cancellable { + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled; + private Schedule schedule; + + public JobsScheduleStopEvent(Schedule schedule){ + this.schedule = schedule; + } + + public Schedule getSchedule() { + return schedule; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + cancelled = cancel; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/src/main/java/com/gamingmesh/jobs/config/ScheduleManager.java b/src/main/java/com/gamingmesh/jobs/config/ScheduleManager.java index c2eb1b8f..b4f8f9a5 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ScheduleManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ScheduleManager.java @@ -8,6 +8,8 @@ import java.util.Calendar; import java.util.Date; import java.util.List; +import com.gamingmesh.jobs.api.JobsScheduleStartEvent; +import com.gamingmesh.jobs.api.JobsScheduleStopEvent; import org.bukkit.Bukkit; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; @@ -83,6 +85,11 @@ public class ScheduleManager { .isStarted()) || !one.isNextDay() && (Current >= From && Current < Until)) && (days.contains(CurrentDayName) || days.contains("all")) && !one .isStarted()) { + JobsScheduleStartEvent event = new JobsScheduleStartEvent(one); + Bukkit.getPluginManager().callEvent(event); + if(event.isCancelled()){ + continue; + } if (one.isBroadcastOnStart()) if (one.GetMessageOnStart().size() == 0) Bukkit.broadcastMessage(Jobs.getLanguage().getMessage("message.boostStarted")); @@ -102,6 +109,11 @@ public class ScheduleManager { break; } else if (((one.isNextDay() && Current > one.GetNextUntil() && Current < one.GetFrom() && !one.isStoped()) || !one.isNextDay() && Current > Until && ((days.contains(CurrentDayName)) || days.contains("all"))) && !one.isStoped()) { + JobsScheduleStopEvent event = new JobsScheduleStopEvent(one); + Bukkit.getPluginManager().callEvent(event); + if(event.isCancelled()){ + continue; + } if (one.isBroadcastOnStop()) if (one.GetMessageOnStop().size() == 0) Bukkit.broadcastMessage(Jobs.getLanguage().getMessage("message.boostStoped"));