mirror of
https://github.com/PikaMug/Quests.git
synced 2025-01-09 01:47:45 +01:00
Activate fail Action during stage of Quests Editor, fixes #1054
This commit is contained in:
parent
cff11e2dae
commit
6fd7973605
@ -805,14 +805,30 @@ public class Quest {
|
||||
*
|
||||
* @param quester The quester to be ejected
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public void failQuest(final Quester quester) {
|
||||
failQuest(quester, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Force player to quit quest and inform them of their failure
|
||||
*
|
||||
* @param quester The quester to be ejected
|
||||
* @param ignoreFailAction Whether or not to ignore quest fail Action
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public void failQuest(final Quester quester, final boolean ignoreFailAction) {
|
||||
final QuesterPreFailQuestEvent preEvent = new QuesterPreFailQuestEvent(quester, this);
|
||||
plugin.getServer().getPluginManager().callEvent(preEvent);
|
||||
if (preEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
final Player player = quester.getPlayer();
|
||||
if (!ignoreFailAction) {
|
||||
final Stage stage = quester.getCurrentStage(this);
|
||||
if (stage != null && stage.getFailAction() != null) {
|
||||
quester.getCurrentStage(this).getFailAction().fire(quester, this);
|
||||
}
|
||||
}
|
||||
final String[] messages = {
|
||||
ChatColor.GOLD + Lang.get(player, "questObjectivesTitle").replace("<quest>", name),
|
||||
ChatColor.RED + Lang.get(player, "questFailed")
|
||||
|
@ -493,6 +493,9 @@ public class QuestFactory implements ConversationAbandonedListener {
|
||||
if (stage.getFinishAction() != null) {
|
||||
context.setSessionData(pref + CK.S_FINISH_EVENT, stage.getFinishAction().getName());
|
||||
}
|
||||
if (stage.getFailAction() != null) {
|
||||
context.setSessionData(pref + CK.S_FAIL_EVENT, stage.getFailAction().getName());
|
||||
}
|
||||
if (stage.getDeathAction() != null) {
|
||||
context.setSessionData(pref + CK.S_DEATH_EVENT, stage.getDeathAction().getName());
|
||||
}
|
||||
@ -816,6 +819,8 @@ public class QuestFactory implements ConversationAbandonedListener {
|
||||
? context.getSessionData(pref + CK.S_START_EVENT) : null);
|
||||
stage.set("finish-event", context.getSessionData(pref + CK.S_FINISH_EVENT) != null
|
||||
? context.getSessionData(pref + CK.S_FINISH_EVENT) : null);
|
||||
stage.set("fail-event", context.getSessionData(pref + CK.S_FAIL_EVENT) != null
|
||||
? context.getSessionData(pref + CK.S_FAIL_EVENT) : null);
|
||||
stage.set("death-event", context.getSessionData(pref + CK.S_DEATH_EVENT) != null
|
||||
? context.getSessionData(pref + CK.S_DEATH_EVENT) : null);
|
||||
stage.set("disconnect-event", context.getSessionData(pref + CK.S_DISCONNECT_EVENT) != null
|
||||
|
@ -2861,6 +2861,15 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
throw new StageFormatException("finish-event failed to load", quest, stageNum);
|
||||
}
|
||||
}
|
||||
if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".fail-event")) {
|
||||
final Action action = loadAction(config.getString("quests." + questKey + ".stages.ordered." + stageNum
|
||||
+ ".fail-event"));
|
||||
if (action != null) {
|
||||
oStage.failAction = action;
|
||||
} else {
|
||||
throw new StageFormatException("fail-event failed to load", quest, stageNum);
|
||||
}
|
||||
}
|
||||
if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".death-event")) {
|
||||
final Action action = loadAction(config.getString("quests." + questKey + ".stages.ordered." + stageNum
|
||||
+ ".death-event"));
|
||||
|
@ -123,11 +123,12 @@ public class Stage {
|
||||
protected LinkedList<LinkedList<String>> passwordPhrases = new LinkedList<LinkedList<String>>();
|
||||
protected String script;
|
||||
protected Action startAction = null;
|
||||
protected Action finishAction = null;
|
||||
protected Action failAction = null;
|
||||
protected Action deathAction = null;
|
||||
protected Map<String, Action> chatActions = new HashMap<String, Action>();
|
||||
protected Map<String, Action> commandActions = new HashMap<String, Action>();
|
||||
protected Action disconnectAction = null;
|
||||
protected Action finishAction = null;
|
||||
protected Condition condition = null;
|
||||
protected long delay = -1;
|
||||
protected String delayMessage = null;
|
||||
@ -411,6 +412,22 @@ public class Stage {
|
||||
public void setStartAction(final Action startAction) {
|
||||
this.startAction = startAction;
|
||||
}
|
||||
|
||||
public Action getFinishAction() {
|
||||
return finishAction;
|
||||
}
|
||||
|
||||
public void setFinishAction(final Action finishAction) {
|
||||
this.finishAction = finishAction;
|
||||
}
|
||||
|
||||
public Action getFailAction() {
|
||||
return failAction;
|
||||
}
|
||||
|
||||
public void setFailAction(final Action failAction) {
|
||||
this.failAction = failAction;
|
||||
}
|
||||
|
||||
public Action getDeathAction() {
|
||||
return deathAction;
|
||||
@ -443,14 +460,6 @@ public class Stage {
|
||||
public void setDisconnectAction(final Action disconnectAction) {
|
||||
this.disconnectAction = disconnectAction;
|
||||
}
|
||||
|
||||
public Action getFinishAction() {
|
||||
return finishAction;
|
||||
}
|
||||
|
||||
public void setFinishAction(final Action finishAction) {
|
||||
this.finishAction = finishAction;
|
||||
}
|
||||
|
||||
public Condition getCondition() {
|
||||
return condition;
|
||||
|
@ -351,7 +351,7 @@ public class Action {
|
||||
}
|
||||
}
|
||||
if (failQuest == true) {
|
||||
quest.failQuest(quester);
|
||||
quest.failQuest(quester, true);
|
||||
}
|
||||
if (timer > 0) {
|
||||
player.sendMessage(ChatColor.GREEN + Lang.get(player, "timerStart")
|
||||
|
@ -1166,7 +1166,7 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
|
||||
super(context);
|
||||
}
|
||||
|
||||
private final int size = 7;
|
||||
private final int size = 8;
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
@ -1187,8 +1187,9 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
return ChatColor.BLUE;
|
||||
case 7:
|
||||
return ChatColor.BLUE;
|
||||
case 8:
|
||||
return ChatColor.GREEN;
|
||||
default:
|
||||
return null;
|
||||
@ -1203,14 +1204,16 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
|
||||
case 2:
|
||||
return ChatColor.YELLOW + Lang.get("stageEditorFinishEvent");
|
||||
case 3:
|
||||
return ChatColor.YELLOW + Lang.get("stageEditorDeathEvent");
|
||||
return ChatColor.YELLOW + Lang.get("stageEditorFailEvent");
|
||||
case 4:
|
||||
return ChatColor.YELLOW + Lang.get("stageEditorDisconnectEvent");
|
||||
return ChatColor.YELLOW + Lang.get("stageEditorDeathEvent");
|
||||
case 5:
|
||||
return ChatColor.YELLOW + Lang.get("stageEditorChatEvents");
|
||||
return ChatColor.YELLOW + Lang.get("stageEditorDisconnectEvent");
|
||||
case 6:
|
||||
return ChatColor.YELLOW + Lang.get("stageEditorCommandEvents");
|
||||
return ChatColor.YELLOW + Lang.get("stageEditorChatEvents");
|
||||
case 7:
|
||||
return ChatColor.YELLOW + Lang.get("stageEditorCommandEvents");
|
||||
case 8:
|
||||
return ChatColor.GREEN + Lang.get("done");
|
||||
default:
|
||||
return null;
|
||||
@ -1236,20 +1239,27 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
|
||||
+ ChatColor.YELLOW + ")\n";
|
||||
}
|
||||
case 3:
|
||||
if (context.getSessionData(stagePrefix + CK.S_FAIL_EVENT) == null) {
|
||||
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
|
||||
} else {
|
||||
return "(" + ChatColor.AQUA + ((String) context.getSessionData(stagePrefix + CK.S_FAIL_EVENT))
|
||||
+ ChatColor.YELLOW + ")\n";
|
||||
}
|
||||
case 4:
|
||||
if (context.getSessionData(stagePrefix + CK.S_DEATH_EVENT) == null) {
|
||||
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
|
||||
} else {
|
||||
return "(" + ChatColor.AQUA + ((String) context.getSessionData(stagePrefix + CK.S_DEATH_EVENT))
|
||||
+ ChatColor.YELLOW + ")\n";
|
||||
}
|
||||
case 4:
|
||||
case 5:
|
||||
if (context.getSessionData(stagePrefix + CK.S_DISCONNECT_EVENT) == null) {
|
||||
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
|
||||
} else {
|
||||
return "(" + ChatColor.AQUA + ((String) context.getSessionData(stagePrefix + CK.S_DISCONNECT_EVENT))
|
||||
+ ChatColor.YELLOW + ")\n";
|
||||
}
|
||||
case 5:
|
||||
case 6:
|
||||
if (context.getSessionData(stagePrefix + CK.S_CHAT_EVENTS) == null) {
|
||||
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
|
||||
} else {
|
||||
@ -1264,7 +1274,7 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
|
||||
}
|
||||
return text;
|
||||
}
|
||||
case 6:
|
||||
case 7:
|
||||
if (context.getSessionData(stagePrefix + CK.S_COMMAND_EVENTS) == null) {
|
||||
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
|
||||
} else {
|
||||
@ -1280,7 +1290,7 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
|
||||
}
|
||||
return text;
|
||||
}
|
||||
case 7:
|
||||
case 8:
|
||||
return "";
|
||||
default:
|
||||
return null;
|
||||
@ -1308,14 +1318,16 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
|
||||
case 2:
|
||||
return new FinishActionPrompt(context);
|
||||
case 3:
|
||||
return new DeathActionPrompt(context);
|
||||
return new FailActionPrompt(context);
|
||||
case 4:
|
||||
return new DisconnectActionPrompt(context);
|
||||
return new DeathActionPrompt(context);
|
||||
case 5:
|
||||
return new ChatActionPrompt(context);
|
||||
return new DisconnectActionPrompt(context);
|
||||
case 6:
|
||||
return new CommandActionPrompt(context);
|
||||
return new ChatActionPrompt(context);
|
||||
case 7:
|
||||
return new CommandActionPrompt(context);
|
||||
case 8:
|
||||
return new StageMainPrompt(stageNum, context);
|
||||
default:
|
||||
return new ActionListPrompt(context);
|
||||
@ -1379,7 +1391,7 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
|
||||
return new ActionListPrompt(context);
|
||||
} else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) {
|
||||
context.setSessionData(stagePrefix + CK.S_START_EVENT, null);
|
||||
player.sendMessage(ChatColor.YELLOW + Lang.get("stageEditorStartEventCleared"));
|
||||
player.sendMessage(ChatColor.YELLOW + Lang.get("stageEditorEventCleared"));
|
||||
return new ActionListPrompt(context);
|
||||
} else {
|
||||
return new StartActionPrompt(context);
|
||||
@ -1443,13 +1455,77 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
|
||||
return new ActionListPrompt(context);
|
||||
} else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) {
|
||||
context.setSessionData(stagePrefix + CK.S_FINISH_EVENT, null);
|
||||
player.sendMessage(ChatColor.YELLOW + Lang.get("stageEditorFinishEventCleared"));
|
||||
player.sendMessage(ChatColor.YELLOW + Lang.get("stageEditorEventCleared"));
|
||||
return new ActionListPrompt(context);
|
||||
} else {
|
||||
return new FinishActionPrompt(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class FailActionPrompt extends QuestsEditorStringPrompt {
|
||||
|
||||
public FailActionPrompt(final ConversationContext context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle(final ConversationContext context) {
|
||||
return Lang.get("stageEditorFailEvent");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQueryText(final ConversationContext context) {
|
||||
return Lang.get("stageEditorEventsPrompt");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPromptText(final ConversationContext context) {
|
||||
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
|
||||
context.getPlugin().getServer().getPluginManager().callEvent(event);
|
||||
|
||||
String text = ChatColor.AQUA + "- " + getTitle(context) + " -\n";
|
||||
if (plugin.getActions().isEmpty()) {
|
||||
text += ChatColor.RED + "- " + Lang.get("none");
|
||||
} else {
|
||||
for (final Action a : plugin.getActions()) {
|
||||
text += ChatColor.GREEN + "- " + a.getName() + "\n";
|
||||
}
|
||||
}
|
||||
return text + ChatColor.YELLOW + getQueryText(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Prompt acceptInput(final ConversationContext context, final String input) {
|
||||
final Player player = (Player) context.getForWhom();
|
||||
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false
|
||||
&& input.equalsIgnoreCase(Lang.get("cmdClear")) == false) {
|
||||
Action found = null;
|
||||
for (final Action a : plugin.getActions()) {
|
||||
if (a.getName().equalsIgnoreCase(input)) {
|
||||
found = a;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found == null) {
|
||||
player.sendMessage(ChatColor.RED + input + ChatColor.YELLOW + " "
|
||||
+ Lang.get("stageEditorInvalidEvent"));
|
||||
return new FailActionPrompt(context);
|
||||
} else {
|
||||
context.setSessionData(stagePrefix + CK.S_FAIL_EVENT, found.getName());
|
||||
return new ActionListPrompt(context);
|
||||
}
|
||||
} else if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
|
||||
return new ActionListPrompt(context);
|
||||
} else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) {
|
||||
context.setSessionData(stagePrefix + CK.S_FAIL_EVENT, null);
|
||||
player.sendMessage(ChatColor.YELLOW + Lang.get("stageEditorEventCleared"));
|
||||
return new ActionListPrompt(context);
|
||||
} else {
|
||||
return new FailActionPrompt(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class DeathActionPrompt extends QuestsEditorStringPrompt {
|
||||
|
||||
@ -1507,7 +1583,7 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
|
||||
return new ActionListPrompt(context);
|
||||
} else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) {
|
||||
context.setSessionData(stagePrefix + CK.S_DEATH_EVENT, null);
|
||||
player.sendMessage(ChatColor.YELLOW + Lang.get("stageEditorDeathEventCleared"));
|
||||
player.sendMessage(ChatColor.YELLOW + Lang.get("stageEditorEventCleared"));
|
||||
return new ActionListPrompt(context);
|
||||
} else {
|
||||
return new DeathActionPrompt(context);
|
||||
@ -1571,7 +1647,7 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
|
||||
return new ActionListPrompt(context);
|
||||
} else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) {
|
||||
context.setSessionData(stagePrefix + CK.S_DISCONNECT_EVENT, null);
|
||||
player.sendMessage(ChatColor.YELLOW + Lang.get("stageEditorDisconnectEventCleared"));
|
||||
player.sendMessage(ChatColor.YELLOW + Lang.get("stageEditorEventCleared"));
|
||||
return new ActionListPrompt(context);
|
||||
} else {
|
||||
return new DisconnectActionPrompt(context);
|
||||
|
@ -37,7 +37,7 @@ public class ActionTimer extends BukkitRunnable {
|
||||
public void run() {
|
||||
quester.removeTimer(getTaskId());
|
||||
if (last) {
|
||||
quest.failQuest(quester);
|
||||
quest.failQuest(quester, false);
|
||||
quester.updateJournal();
|
||||
} else {
|
||||
quester.getPlayer().sendMessage(ChatColor.GREEN + Lang.get(quester.getPlayer(), "timerMessage")
|
||||
|
@ -92,6 +92,7 @@ public class CK {
|
||||
public static final String S_SHEAR_AMOUNTS = "shearAmounts";
|
||||
public static final String S_START_EVENT = "startEvent";
|
||||
public static final String S_FINISH_EVENT = "finishEvent";
|
||||
public static final String S_FAIL_EVENT = "failEvent";
|
||||
public static final String S_CHAT_EVENTS = "chatEvents";
|
||||
public static final String S_CHAT_EVENT_TRIGGERS = "chatEventTriggers";
|
||||
public static final String S_CHAT_TEMP_EVENT = "chatTempEvent";
|
||||
|
@ -144,22 +144,18 @@ stageEditorShearSheep: "Shear sheep"
|
||||
stageEditorKillPlayers: "Kill players"
|
||||
stageEditorPlayers: "players"
|
||||
stageEditorEvents: "Actions"
|
||||
stageEditorEventCleared: "Action cleared."
|
||||
stageEditorStageEvents: "Stage Actions"
|
||||
stageEditorStartEvent: "Start Action"
|
||||
stageEditorStartEventCleared: "Start action cleared."
|
||||
stageEditorFinishEvent: "Finish Action"
|
||||
stageEditorFinishEventCleared: "Finish action cleared."
|
||||
stageEditorFinishEvent: "Fail Action"
|
||||
stageEditorChatEvents: "Chat Action"
|
||||
stageEditorChatTrigger: "Chat Trigger"
|
||||
stageEditorChatEventsCleared: "Chat action cleared."
|
||||
stageEditorCommandEvents: "Command Action"
|
||||
stageEditorCommandTrigger: "Command Trigger"
|
||||
stageEditorCommandEventsCleared: "Command action cleared."
|
||||
stageEditorTriggeredBy: "Triggered by"
|
||||
stageEditorDeathEvent: "Death Action"
|
||||
stageEditorDeathEventCleared: "Death action cleared."
|
||||
stageEditorDisconnectEvent: "Disconnect Action"
|
||||
stageEditorDisconnectEventCleared: "Disconnect action cleared."
|
||||
stageEditorConditions: "Conditions"
|
||||
stageEditorConditionCleared: "Condition cleared."
|
||||
stageEditorDelayMessage: "Delay message"
|
||||
|
Loading…
Reference in New Issue
Block a user