mirror of
https://github.com/PikaMug/Quests.git
synced 2025-02-19 22:11:40 +01:00
Supply external conversation hooks, part 42
This commit is contained in:
parent
7f9ca56c30
commit
3e481a8214
@ -19,8 +19,8 @@ import me.blackvein.quests.actions.Action;
|
|||||||
import me.blackvein.quests.actions.ActionFactory;
|
import me.blackvein.quests.actions.ActionFactory;
|
||||||
import me.blackvein.quests.conditions.Condition;
|
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.misc.MiscStringPrompt;
|
||||||
import me.blackvein.quests.convo.npcs.NpcOfferQuestPrompt;
|
import me.blackvein.quests.convo.misc.NpcOfferQuestPrompt;
|
||||||
import me.blackvein.quests.events.misc.MiscPostQuestAcceptEvent;
|
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;
|
||||||
@ -563,7 +563,17 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class QuestAcceptPrompt extends QuestsStringPrompt {
|
public class QuestAcceptPrompt extends MiscStringPrompt {
|
||||||
|
|
||||||
|
private ConversationContext cc;
|
||||||
|
|
||||||
|
public QuestAcceptPrompt() {
|
||||||
|
super(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public QuestAcceptPrompt(final ConversationContext context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
private final int size = 2;
|
private final int size = 2;
|
||||||
|
|
||||||
@ -603,11 +613,13 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nonnull String getPromptText(final ConversationContext context) {
|
public @Nonnull String getPromptText(final ConversationContext context) {
|
||||||
|
this.cc = context;
|
||||||
|
|
||||||
final MiscPostQuestAcceptEvent event = new MiscPostQuestAcceptEvent(context, this);
|
final MiscPostQuestAcceptEvent event = new MiscPostQuestAcceptEvent(context, this);
|
||||||
getServer().getPluginManager().callEvent(event);
|
getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
return ChatColor.YELLOW + getQueryText(context) + " " + ChatColor.GREEN
|
return ChatColor.YELLOW + getQueryText(context) + " " + ChatColor.GREEN
|
||||||
+ getSelectionText(context, 1) + " / " + getSelectionText(context, 2);
|
+ getSelectionText(context, 1) + ChatColor.RESET + " / " + getSelectionText(context, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -650,7 +662,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
.replace("<yes>", Lang.get(player, "yesWord"))
|
.replace("<yes>", Lang.get(player, "yesWord"))
|
||||||
.replace("<no>", Lang.get(player, "noWord"));
|
.replace("<no>", Lang.get(player, "noWord"));
|
||||||
Lang.send(player, ChatColor.RED + msg);
|
Lang.send(player, ChatColor.RED + msg);
|
||||||
return new QuestAcceptPrompt();
|
return new QuestAcceptPrompt(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,44 @@
|
|||||||
|
/*******************************************************************************************************
|
||||||
|
* 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.convo.misc;
|
||||||
|
|
||||||
|
import me.blackvein.quests.convo.QuestsNumericPrompt;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.conversations.ConversationContext;
|
||||||
|
|
||||||
|
public abstract class MiscNumericPrompt extends QuestsNumericPrompt {
|
||||||
|
private final ConversationContext context;
|
||||||
|
|
||||||
|
public MiscNumericPrompt(final ConversationContext context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return getClass().getSimpleName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConversationContext getConversationContext() {
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract int getSize();
|
||||||
|
|
||||||
|
public abstract String getTitle(ConversationContext context);
|
||||||
|
|
||||||
|
public abstract ChatColor getNumberColor(ConversationContext context, int number);
|
||||||
|
|
||||||
|
public abstract String getSelectionText(ConversationContext context, int number);
|
||||||
|
|
||||||
|
public abstract String getAdditionalText(ConversationContext context, int number);
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
/*******************************************************************************************************
|
||||||
|
* 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.convo.misc;
|
||||||
|
|
||||||
|
import me.blackvein.quests.convo.QuestsStringPrompt;
|
||||||
|
import org.bukkit.conversations.ConversationContext;
|
||||||
|
|
||||||
|
public abstract class MiscStringPrompt extends QuestsStringPrompt {
|
||||||
|
private final ConversationContext context;
|
||||||
|
|
||||||
|
public MiscStringPrompt(final ConversationContext context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return getClass().getSimpleName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConversationContext getConversationContext() {
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract int getSize();
|
||||||
|
|
||||||
|
public abstract String getTitle(ConversationContext context);
|
||||||
|
|
||||||
|
public abstract String getQueryText(ConversationContext context);
|
||||||
|
}
|
@ -10,12 +10,11 @@
|
|||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************************************/
|
*******************************************************************************************************/
|
||||||
|
|
||||||
package me.blackvein.quests.convo.npcs;
|
package me.blackvein.quests.convo.misc;
|
||||||
|
|
||||||
import me.blackvein.quests.Quest;
|
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.events.misc.MiscPostNpcOfferQuestEvent;
|
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;
|
||||||
@ -27,43 +26,119 @@ import javax.annotation.Nonnull;
|
|||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
public class NpcOfferQuestPrompt extends QuestsStringPrompt {
|
public class NpcOfferQuestPrompt extends MiscStringPrompt {
|
||||||
|
|
||||||
|
private ConversationContext cc;
|
||||||
|
|
||||||
|
public NpcOfferQuestPrompt() {
|
||||||
|
super(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NpcOfferQuestPrompt(ConversationContext context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConversationContext getConversationContext() {
|
||||||
|
return cc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int size = 3;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTitle(final ConversationContext context) {
|
||||||
|
final String npc = (String) context.getSessionData("npc");
|
||||||
|
return Lang.get("questNPCListTitle").replace("<npc>", npc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public ChatColor getNumberColor(final ConversationContext context, final int number) {
|
||||||
|
final Quests plugin = (Quests)context.getPlugin();
|
||||||
|
final LinkedList<Quest> quests = (LinkedList<Quest>) context.getSessionData("npcQuests");
|
||||||
|
final Quester quester = plugin.getQuester(((Player) context.getForWhom()).getUniqueId());
|
||||||
|
if (quests != null && number > 0) {
|
||||||
|
if (number < (quests.size() + 1)) {
|
||||||
|
final Quest quest = quests.get(number - 1);
|
||||||
|
if (quester.getCompletedQuests().contains(quest)) {
|
||||||
|
return ChatColor.GREEN;
|
||||||
|
} else {
|
||||||
|
return ChatColor.GOLD;
|
||||||
|
}
|
||||||
|
} else if (number == (quests.size() + 1)) {
|
||||||
|
//return ChatColor.RED;
|
||||||
|
return ChatColor.GOLD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public String getSelectionText(final ConversationContext context, final int number) {
|
||||||
|
final Quests plugin = (Quests)context.getPlugin();
|
||||||
|
final LinkedList<Quest> quests = (LinkedList<Quest>) context.getSessionData("npcQuests");
|
||||||
|
final Quester quester = plugin.getQuester(((Player) context.getForWhom()).getUniqueId());
|
||||||
|
if (quests != null && number > 0) {
|
||||||
|
if (number < (quests.size() + 1)) {
|
||||||
|
final Quest quest = quests.get(number - 1);
|
||||||
|
if (quester.getCompletedQuests().contains(quest)) {
|
||||||
|
return ChatColor.GREEN + "" + ChatColor.ITALIC + quest.getName();
|
||||||
|
} else {
|
||||||
|
return ChatColor.YELLOW + "" + ChatColor.ITALIC + quest.getName();
|
||||||
|
}
|
||||||
|
} else if (number == (quests.size() + 1)) {
|
||||||
|
return ChatColor.GRAY + Lang.get("cancel");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public String getAdditionalText(final ConversationContext context, final int number) {
|
||||||
|
final Quests plugin = (Quests)context.getPlugin();
|
||||||
|
final LinkedList<Quest> quests = (LinkedList<Quest>) context.getSessionData("npcQuests");
|
||||||
|
final Quester quester = plugin.getQuester(((Player) context.getForWhom()).getUniqueId());
|
||||||
|
if (quests != null && number > 0) {
|
||||||
|
if (number < (quests.size() + 1)) {
|
||||||
|
final Quest quest = quests.get(number - 1);
|
||||||
|
if (quester.getCompletedQuests().contains(quest)) {
|
||||||
|
return ChatColor.GREEN + "" + Lang.get("redoCompleted");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
public String getQueryText(final ConversationContext context) {
|
public String getQueryText(final ConversationContext context) {
|
||||||
return Lang.get("questNPCListTitle");
|
return Lang.get("enterAnOption");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public @Nonnull String getPromptText(final ConversationContext context) {
|
public @Nonnull String getPromptText(final ConversationContext context) {
|
||||||
|
this.cc = context;
|
||||||
final Quests plugin = (Quests)context.getPlugin();
|
final Quests plugin = (Quests)context.getPlugin();
|
||||||
final LinkedList<Quest> quests = (LinkedList<Quest>) context.getSessionData("npcQuests");
|
final LinkedList<Quest> quests = (LinkedList<Quest>) context.getSessionData("npcQuests");
|
||||||
final String npc = (String) context.getSessionData("npc");
|
final String npc = (String) context.getSessionData("npc");
|
||||||
if (plugin == null || quests == null || npc == null) {
|
if (plugin == null || quests == null || npc == null) {
|
||||||
return ChatColor.RED + "Bad offer";
|
return ChatColor.YELLOW + Lang.get("unknownError");
|
||||||
}
|
}
|
||||||
|
|
||||||
final MiscPostNpcOfferQuestEvent event = new MiscPostNpcOfferQuestEvent(context, this);
|
final MiscPostNpcOfferQuestEvent event = new MiscPostNpcOfferQuestEvent(context, this);
|
||||||
plugin.getServer().getPluginManager().callEvent(event);
|
plugin.getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
final Quester quester = plugin.getQuester(((Player) context.getForWhom()).getUniqueId());
|
String text = ChatColor.WHITE + getTitle(context);
|
||||||
final String text = getQueryText(context).replace("<npc>", npc);
|
size = quests.size();
|
||||||
String menu = text + "\n";
|
for (int i = 1; i <= size + 1; i++) {
|
||||||
for (int i = 1; i <= quests.size(); i++) {
|
text += "\n" + getNumberColor(context, i) + "" + ChatColor.BOLD + i + ". " + ChatColor.RESET
|
||||||
final Quest quest = quests.get(i - 1);
|
+ getSelectionText(context, i) + " " + getAdditionalText(context, i);
|
||||||
if (quester.getCompletedQuests().contains(quest)) {
|
|
||||||
menu += ChatColor.DARK_GREEN + "" + ChatColor.BOLD + "" + i + ". " + ChatColor.RESET + ""
|
|
||||||
+ ChatColor.GREEN + "" + ChatColor.ITALIC + quest.getName() + ChatColor.RESET + ""
|
|
||||||
+ ChatColor.GREEN + " " + Lang.get("redoCompleted") + "\n";
|
|
||||||
} else {
|
|
||||||
menu += ChatColor.GOLD + "" + ChatColor.BOLD + "" + i + ". " + ChatColor.RESET + "" + ChatColor.YELLOW
|
|
||||||
+ "" + ChatColor.ITALIC + quest.getName() + "\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
menu += ChatColor.GOLD + "" + ChatColor.BOLD + "" + (quests.size() + 1) + ". " + ChatColor.RESET + ""
|
text += "\n" + ChatColor.WHITE + getQueryText(context);
|
||||||
+ ChatColor.GRAY + Lang.get("cancel") + "\n";
|
return text;
|
||||||
menu += ChatColor.WHITE + Lang.get("enterAnOption");
|
|
||||||
return menu;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -110,7 +185,7 @@ public class NpcOfferQuestPrompt extends QuestsStringPrompt {
|
|||||||
}
|
}
|
||||||
if (q == null) {
|
if (q == null) {
|
||||||
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidOption"));
|
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidOption"));
|
||||||
return new NpcOfferQuestPrompt();
|
return new NpcOfferQuestPrompt(context);
|
||||||
} else {
|
} else {
|
||||||
final Player player = quester.getPlayer();
|
final Player player = quester.getPlayer();
|
||||||
if (quester.canAcceptOffer(q, true)) {
|
if (quester.canAcceptOffer(q, true)) {
|
@ -46,7 +46,7 @@ public class StageMenuPrompt extends QuestsEditorNumericPrompt {
|
|||||||
public ChatColor getNumberColor(final ConversationContext context, final int number) {
|
public ChatColor getNumberColor(final ConversationContext context, final int number) {
|
||||||
final int stages = getStages(context);
|
final int stages = getStages(context);
|
||||||
if (number > 0) {
|
if (number > 0) {
|
||||||
if (number < (stages + 1) && number > 0) {
|
if (number < (stages + 1)) {
|
||||||
return ChatColor.BLUE;
|
return ChatColor.BLUE;
|
||||||
} else if (number == (stages + 1)) {
|
} else if (number == (stages + 1)) {
|
||||||
return ChatColor.BLUE;
|
return ChatColor.BLUE;
|
||||||
@ -95,7 +95,7 @@ public class StageMenuPrompt extends QuestsEditorNumericPrompt {
|
|||||||
final int i = input.intValue();
|
final int i = input.intValue();
|
||||||
final int stages = getStages(context);
|
final int stages = getStages(context);
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
if (i < (stages + 1) && i > 0) {
|
if (i < (stages + 1)) {
|
||||||
return new StageMainPrompt((i), context);
|
return new StageMainPrompt((i), context);
|
||||||
} else if (i == (stages + 1)) {
|
} else if (i == (stages + 1)) {
|
||||||
return new StageMainPrompt((stages + 1), context);
|
return new StageMainPrompt((stages + 1), context);
|
||||||
|
Loading…
Reference in New Issue
Block a user