diff --git a/main/src/main/java/me/blackvein/quests/Quester.java b/main/src/main/java/me/blackvein/quests/Quester.java index ca0fd7fc6..0b4e5ed16 100644 --- a/main/src/main/java/me/blackvein/quests/Quester.java +++ b/main/src/main/java/me/blackvein/quests/Quester.java @@ -53,6 +53,7 @@ import com.alessiodp.parties.api.interfaces.Party; import de.erethon.dungeonsxl.player.DGroup; import me.blackvein.quests.events.quest.QuestTakeEvent; import me.blackvein.quests.events.quester.QuesterPostStartQuestEvent; +import me.blackvein.quests.events.quester.QuesterPreOpenGUIEvent; import me.blackvein.quests.events.quester.QuesterPreStartQuestEvent; import me.blackvein.quests.tasks.StageTimer; import me.blackvein.quests.util.ConfigUtil; @@ -3182,6 +3183,14 @@ public class Quester { * @param quests List of quests to use for displaying items */ public void showGUIDisplay(NPC npc, LinkedList quests) { + if (npc == null || quests == null) { + return; + } + QuesterPreOpenGUIEvent preEvent = new QuesterPreOpenGUIEvent(this, npc, quests); + plugin.getServer().getPluginManager().callEvent(preEvent); + if (preEvent.isCancelled()) { + return; + } Player player = getPlayer(); int size = ((quests.size() / 9) + 1) * 9; Inventory inv = Bukkit.getServer().createInventory(player, size, Lang.get(player, "quests") + " | " diff --git a/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreOpenGUIEvent.java b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreOpenGUIEvent.java new file mode 100644 index 000000000..644ebd0bd --- /dev/null +++ b/main/src/main/java/me/blackvein/quests/events/quester/QuesterPreOpenGUIEvent.java @@ -0,0 +1,74 @@ +/******************************************************************************************************* + * Continued by PikaMug (formerly HappyPikachu) with permission from _Blackvein_. All rights reserved. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN + * NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *******************************************************************************************************/ + +package me.blackvein.quests.events.quester; + +import java.util.LinkedList; + +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; + +import me.blackvein.quests.Quest; +import me.blackvein.quests.Quester; +import net.citizensnpcs.api.npc.NPC; + +/** + * Called before a quester opens a quest selection GUI + */ +public class QuesterPreOpenGUIEvent extends QuesterEvent implements Cancellable { + private static final HandlerList handlers = new HandlerList(); + private NPC npc; + LinkedList quests; + private boolean cancel = false; + + public QuesterPreOpenGUIEvent(Quester quester, NPC npc, LinkedList quests) { + super(quester); + this.npc = npc; + this.quests = quests; + } + + /** + * Returns the NPC involved in this event + * + * @return NPC who is involved in this event + */ + public NPC getNPC() { + return npc; + } + + /** + * Returns the list of quests involved in this event + * + * @return List of quests involved in this event + */ + public LinkedList getQuests() { + return quests; + } + + @Override + public boolean isCancelled() { + return cancel; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancel = cancel; + } + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +}