mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-26 20:55:54 +01:00
Supply external conversation hooks, part 41
This commit is contained in:
parent
fe327f4a20
commit
7f9ca56c30
@ -21,6 +21,7 @@ import me.blackvein.quests.conditions.Condition;
|
|||||||
import me.blackvein.quests.conditions.ConditionFactory;
|
import me.blackvein.quests.conditions.ConditionFactory;
|
||||||
import me.blackvein.quests.convo.QuestsStringPrompt;
|
import me.blackvein.quests.convo.QuestsStringPrompt;
|
||||||
import me.blackvein.quests.convo.npcs.NpcOfferQuestPrompt;
|
import me.blackvein.quests.convo.npcs.NpcOfferQuestPrompt;
|
||||||
|
import me.blackvein.quests.events.misc.MiscPostQuestAcceptEvent;
|
||||||
import me.blackvein.quests.exceptions.ActionFormatException;
|
import me.blackvein.quests.exceptions.ActionFormatException;
|
||||||
import me.blackvein.quests.exceptions.ConditionFormatException;
|
import me.blackvein.quests.exceptions.ConditionFormatException;
|
||||||
import me.blackvein.quests.exceptions.QuestFormatException;
|
import me.blackvein.quests.exceptions.QuestFormatException;
|
||||||
@ -564,10 +565,49 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
|
|
||||||
public class QuestAcceptPrompt extends QuestsStringPrompt {
|
public class QuestAcceptPrompt extends QuestsStringPrompt {
|
||||||
|
|
||||||
|
private final int size = 2;
|
||||||
|
|
||||||
|
public int getSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle(final ConversationContext context) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChatColor getNumberColor(final ConversationContext context, final int number) {
|
||||||
|
switch (number) {
|
||||||
|
case 1:
|
||||||
|
return ChatColor.GREEN;
|
||||||
|
case 2:
|
||||||
|
return ChatColor.RED;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSelectionText(final ConversationContext context, final int number) {
|
||||||
|
switch (number) {
|
||||||
|
case 1:
|
||||||
|
return ChatColor.GREEN + Lang.get("yesWord");
|
||||||
|
case 2:
|
||||||
|
return ChatColor.RED + Lang.get("noWord");
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getQueryText(final ConversationContext context) {
|
||||||
|
return Lang.get("acceptQuest");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nonnull String getPromptText(final ConversationContext context) {
|
public @Nonnull String getPromptText(final ConversationContext context) {
|
||||||
return ChatColor.YELLOW + Lang.get((Player) context.getForWhom(), "acceptQuest") + " " + ChatColor.GREEN
|
final MiscPostQuestAcceptEvent event = new MiscPostQuestAcceptEvent(context, this);
|
||||||
+ Lang.get("yesWord") + " / " + Lang.get("noWord");
|
getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
|
return ChatColor.YELLOW + getQueryText(context) + " " + ChatColor.GREEN
|
||||||
|
+ getSelectionText(context, 1) + " / " + getSelectionText(context, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -16,6 +16,7 @@ import me.blackvein.quests.Quest;
|
|||||||
import me.blackvein.quests.Quester;
|
import me.blackvein.quests.Quester;
|
||||||
import me.blackvein.quests.Quests;
|
import me.blackvein.quests.Quests;
|
||||||
import me.blackvein.quests.convo.QuestsStringPrompt;
|
import me.blackvein.quests.convo.QuestsStringPrompt;
|
||||||
|
import me.blackvein.quests.events.misc.MiscPostNpcOfferQuestEvent;
|
||||||
import me.blackvein.quests.util.Lang;
|
import me.blackvein.quests.util.Lang;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.conversations.ConversationContext;
|
import org.bukkit.conversations.ConversationContext;
|
||||||
@ -28,6 +29,10 @@ import java.util.LinkedList;
|
|||||||
|
|
||||||
public class NpcOfferQuestPrompt extends QuestsStringPrompt {
|
public class NpcOfferQuestPrompt extends QuestsStringPrompt {
|
||||||
|
|
||||||
|
public String getQueryText(final ConversationContext context) {
|
||||||
|
return Lang.get("questNPCListTitle");
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public @Nonnull String getPromptText(final ConversationContext context) {
|
public @Nonnull String getPromptText(final ConversationContext context) {
|
||||||
@ -37,8 +42,12 @@ public class NpcOfferQuestPrompt extends QuestsStringPrompt {
|
|||||||
if (plugin == null || quests == null || npc == null) {
|
if (plugin == null || quests == null || npc == null) {
|
||||||
return ChatColor.RED + "Bad offer";
|
return ChatColor.RED + "Bad offer";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final MiscPostNpcOfferQuestEvent event = new MiscPostNpcOfferQuestEvent(context, this);
|
||||||
|
plugin.getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
final Quester quester = plugin.getQuester(((Player) context.getForWhom()).getUniqueId());
|
final Quester quester = plugin.getQuester(((Player) context.getForWhom()).getUniqueId());
|
||||||
final String text = Lang.get("questNPCListTitle").replace("<npc>", npc);
|
final String text = getQueryText(context).replace("<npc>", npc);
|
||||||
String menu = text + "\n";
|
String menu = text + "\n";
|
||||||
for (int i = 1; i <= quests.size(); i++) {
|
for (int i = 1; i <= quests.size(); i++) {
|
||||||
final Quest quest = quests.get(i - 1);
|
final Quest quest = quests.get(i - 1);
|
||||||
|
@ -0,0 +1,65 @@
|
|||||||
|
/*******************************************************************************************************
|
||||||
|
* Copyright (c) 2014 PikaMug and contributors. 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.misc;
|
||||||
|
|
||||||
|
import me.blackvein.quests.events.QuestsEvent;
|
||||||
|
import org.bukkit.conversations.ConversationContext;
|
||||||
|
import org.bukkit.conversations.Prompt;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a miscellaneous editor-related event
|
||||||
|
*/
|
||||||
|
public class MiscEditorEvent extends QuestsEvent {
|
||||||
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
|
protected ConversationContext context;
|
||||||
|
private final Prompt prompt;
|
||||||
|
|
||||||
|
public MiscEditorEvent(final ConversationContext context, final Prompt prompt) {
|
||||||
|
this.context = context;
|
||||||
|
this.prompt = prompt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MiscEditorEvent(final ConversationContext context, final Prompt prompt, final boolean async) {
|
||||||
|
super(async);
|
||||||
|
this.context = context;
|
||||||
|
this.prompt = prompt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the context involved in this event
|
||||||
|
*
|
||||||
|
* @return ConversationContext which is involved in this event
|
||||||
|
*/
|
||||||
|
public ConversationContext getConversationContext() {
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the prompt involved in this event
|
||||||
|
*
|
||||||
|
* @return Prompt which is involved in this event
|
||||||
|
*/
|
||||||
|
public Prompt getPrompt() {
|
||||||
|
return prompt;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
/*******************************************************************************************************
|
||||||
|
* Copyright (c) 2014 PikaMug and contributors. 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.misc;
|
||||||
|
|
||||||
|
import org.bukkit.conversations.ConversationContext;
|
||||||
|
import org.bukkit.conversations.Prompt;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class MiscPostNpcOfferQuestEvent extends MiscEditorEvent {
|
||||||
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
|
private final Prompt prompt;
|
||||||
|
|
||||||
|
public MiscPostNpcOfferQuestEvent(final ConversationContext context, final Prompt prompt) {
|
||||||
|
super(context, prompt);
|
||||||
|
this.context = context;
|
||||||
|
this.prompt = prompt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the context involved in this event
|
||||||
|
*
|
||||||
|
* @return ConversationContext which is involved in this event
|
||||||
|
*/
|
||||||
|
public ConversationContext getConversationContext() {
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the prompt involved in this event
|
||||||
|
*
|
||||||
|
* @return Prompt which is involved in this event
|
||||||
|
*/
|
||||||
|
public Prompt getPrompt() {
|
||||||
|
return prompt;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
/*******************************************************************************************************
|
||||||
|
* Copyright (c) 2014 PikaMug and contributors. 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.misc;
|
||||||
|
|
||||||
|
import org.bukkit.conversations.ConversationContext;
|
||||||
|
import org.bukkit.conversations.Prompt;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class MiscPostQuestAcceptEvent extends MiscEditorEvent {
|
||||||
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
|
private final Prompt prompt;
|
||||||
|
|
||||||
|
public MiscPostQuestAcceptEvent(final ConversationContext context, final Prompt prompt) {
|
||||||
|
super(context, prompt);
|
||||||
|
this.context = context;
|
||||||
|
this.prompt = prompt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the context involved in this event
|
||||||
|
*
|
||||||
|
* @return ConversationContext which is involved in this event
|
||||||
|
*/
|
||||||
|
public ConversationContext getConversationContext() {
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the prompt involved in this event
|
||||||
|
*
|
||||||
|
* @return Prompt which is involved in this event
|
||||||
|
*/
|
||||||
|
public Prompt getPrompt() {
|
||||||
|
return prompt;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user