New API event for opening a quest selection GUI, fixes #1010

This commit is contained in:
PikaMug 2019-12-25 18:12:17 -05:00
parent 80909e87b4
commit 7a56fec67d
2 changed files with 83 additions and 0 deletions

View File

@ -53,6 +53,7 @@ import com.alessiodp.parties.api.interfaces.Party;
import de.erethon.dungeonsxl.player.DGroup; import de.erethon.dungeonsxl.player.DGroup;
import me.blackvein.quests.events.quest.QuestTakeEvent; import me.blackvein.quests.events.quest.QuestTakeEvent;
import me.blackvein.quests.events.quester.QuesterPostStartQuestEvent; 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.events.quester.QuesterPreStartQuestEvent;
import me.blackvein.quests.tasks.StageTimer; import me.blackvein.quests.tasks.StageTimer;
import me.blackvein.quests.util.ConfigUtil; import me.blackvein.quests.util.ConfigUtil;
@ -3182,6 +3183,14 @@ public class Quester {
* @param quests List of quests to use for displaying items * @param quests List of quests to use for displaying items
*/ */
public void showGUIDisplay(NPC npc, LinkedList<Quest> quests) { public void showGUIDisplay(NPC npc, LinkedList<Quest> 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(); Player player = getPlayer();
int size = ((quests.size() / 9) + 1) * 9; int size = ((quests.size() / 9) + 1) * 9;
Inventory inv = Bukkit.getServer().createInventory(player, size, Lang.get(player, "quests") + " | " Inventory inv = Bukkit.getServer().createInventory(player, size, Lang.get(player, "quests") + " | "

View File

@ -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<Quest> quests;
private boolean cancel = false;
public QuesterPreOpenGUIEvent(Quester quester, NPC npc, LinkedList<Quest> 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<Quest> 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;
}
}