NEW while within ticks condition, fixes #1634

This commit is contained in:
PikaMug 2023-02-11 16:33:29 -05:00
parent 609d8e9c4d
commit 64aa1387a0
10 changed files with 412 additions and 145 deletions

View File

@ -48,6 +48,14 @@ public interface ICondition extends Comparable<ICondition> {
void setWorldsWhileStayingWithin(final LinkedList<String> worldsWhileStayingWithin);
int getTickStartWhileStayingWithin();
void setTickStartWhileStayingWithin(final int tickStartWhileStayingWithin);
int getTickEndWhileStayingWithin();
void setTickEndWhileStayingWithin(final int tickEndWhileStayingWithin);
LinkedList<String> getBiomesWhileStayingWithin();
void setBiomesWhileStayingWithin(final LinkedList<String> biomesWhileStayingWithin);

View File

@ -20,7 +20,6 @@ import com.herocraftonline.heroes.characters.Hero;
import io.github.znetworkw.znpcservers.npc.NPC;
import me.blackvein.quests.actions.Action;
import me.blackvein.quests.actions.IAction;
import me.blackvein.quests.conditions.ICondition;
import me.blackvein.quests.dependencies.IDependencies;
import me.blackvein.quests.events.quest.QuestUpdateCompassEvent;
import me.blackvein.quests.events.quester.QuesterPostChangeStageEvent;
@ -348,72 +347,7 @@ public class Quest implements IQuest {
if (stageStartMessage != null) {
p.sendMessage(ConfigUtil.parseStringWithPossibleLineBreaks(stageStartMessage, this, p));
}
final ICondition c = nextStage.getCondition();
if (c != null && nextStage.getObjectiveOverrides().isEmpty()) {
p.sendMessage(ChatColor.LIGHT_PURPLE + Lang.get("stageEditorConditions"));
if (!c.getEntitiesWhileRiding().isEmpty()) {
final StringBuilder msg = new StringBuilder("- " + Lang.get("conditionEditorRideEntity"));
for (final String e : c.getEntitiesWhileRiding()) {
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(e);
}
p.sendMessage(ChatColor.YELLOW + msg.toString());
} else if (!c.getNpcsWhileRiding().isEmpty()) {
final StringBuilder msg = new StringBuilder("- " + Lang.get("conditionEditorRideNPC"));
for (final UUID u : c.getNpcsWhileRiding()) {
if (plugin.getDependencies().getCitizens() != null) {
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(plugin.getDependencies()
.getCitizens().getNPCRegistry().getByUniqueId(u).getName());
} else {
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(u);
}
}
p.sendMessage(ChatColor.YELLOW + msg.toString());
} else if (!c.getPermissions().isEmpty()) {
final StringBuilder msg = new StringBuilder("- " + Lang.get("conditionEditorPermissions"));
for (final String e : c.getPermissions()) {
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(e);
}
p.sendMessage(ChatColor.YELLOW + msg.toString());
} else if (!c.getItemsWhileHoldingMainHand().isEmpty()) {
final StringBuilder msg = new StringBuilder("- " + Lang.get("conditionEditorItemsInMainHand"));
for (final ItemStack is : c.getItemsWhileHoldingMainHand()) {
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(ItemUtil.getPrettyItemName(is
.getType().name()));
}
p.sendMessage(ChatColor.YELLOW + msg.toString());
} else if (!c.getWorldsWhileStayingWithin().isEmpty()) {
final StringBuilder msg = new StringBuilder("- " + Lang.get("conditionEditorStayWithinWorld"));
for (final String w : c.getWorldsWhileStayingWithin()) {
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(w);
}
p.sendMessage(ChatColor.YELLOW + msg.toString());
} else if (!c.getBiomesWhileStayingWithin().isEmpty()) {
final StringBuilder msg = new StringBuilder("- " + Lang.get("conditionEditorStayWithinBiome"));
for (final String b : c.getBiomesWhileStayingWithin()) {
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(MiscUtil
.snakeCaseToUpperCamelCase(b));
}
p.sendMessage(ChatColor.YELLOW + msg.toString());
} else if (!c.getRegionsWhileStayingWithin().isEmpty()) {
final StringBuilder msg = new StringBuilder("- " + Lang.get("conditionEditorStayWithinRegion"));
for (final String r : c.getRegionsWhileStayingWithin()) {
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(r);
}
p.sendMessage(ChatColor.YELLOW + msg.toString());
} else if (!c.getPlaceholdersCheckIdentifier().isEmpty()) {
final StringBuilder msg = new StringBuilder("- " + Lang.get("conditionEditorCheckPlaceholder"));
int index = 0;
for (final String r : c.getPlaceholdersCheckIdentifier()) {
if (c.getPlaceholdersCheckValue().size() > index) {
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(r).append(ChatColor.GRAY)
.append(" = ").append(ChatColor.AQUA).append(c.getPlaceholdersCheckValue()
.get(index));
}
index++;
}
p.sendMessage(ChatColor.YELLOW + msg.toString());
}
}
plugin.showConditions(this, quester);
}
quester.updateJournal();
quester.saveData();

View File

@ -816,72 +816,7 @@ public class Quester implements IQuester {
if (stageStartMessage != null) {
p.sendMessage(ConfigUtil.parseStringWithPossibleLineBreaks(stageStartMessage, quest, getPlayer()));
}
final ICondition c = stage.getCondition();
if (c != null && stage.getObjectiveOverrides().isEmpty()) {
sendMessage(ChatColor.LIGHT_PURPLE + Lang.get("stageEditorConditions"));
if (!c.getEntitiesWhileRiding().isEmpty()) {
final StringBuilder msg = new StringBuilder("- " + Lang.get("conditionEditorRideEntity"));
for (final String e : c.getEntitiesWhileRiding()) {
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(e);
}
sendMessage(ChatColor.YELLOW + msg.toString());
} else if (!c.getNpcsWhileRiding().isEmpty()) {
final StringBuilder msg = new StringBuilder("- " + Lang.get("conditionEditorRideNPC"));
for (final UUID u : c.getNpcsWhileRiding()) {
if (plugin.getDependencies().getCitizens() != null) {
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(CitizensAPI.getNPCRegistry()
.getByUniqueId(u).getName());
} else {
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(u);
}
}
sendMessage(ChatColor.YELLOW + msg.toString());
} else if (!c.getPermissions().isEmpty()) {
final StringBuilder msg = new StringBuilder("- " + Lang.get("conditionEditorPermissions"));
for (final String e : c.getPermissions()) {
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(e);
}
sendMessage(ChatColor.YELLOW + msg.toString());
} else if (!c.getItemsWhileHoldingMainHand().isEmpty()) {
final StringBuilder msg = new StringBuilder("- " + Lang.get("conditionEditorItemsInMainHand"));
for (final ItemStack is : c.getItemsWhileHoldingMainHand()) {
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(ItemUtil.getPrettyItemName(is
.getType().name()));
}
sendMessage(ChatColor.YELLOW + msg.toString());
} else if (!c.getWorldsWhileStayingWithin().isEmpty()) {
final StringBuilder msg = new StringBuilder("- " + Lang.get("conditionEditorStayWithinWorld"));
for (final String w : c.getWorldsWhileStayingWithin()) {
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(w);
}
sendMessage(ChatColor.YELLOW + msg.toString());
} else if (!c.getBiomesWhileStayingWithin().isEmpty()) {
final StringBuilder msg = new StringBuilder("- " + Lang.get("conditionEditorStayWithinBiome"));
for (final String b : c.getBiomesWhileStayingWithin()) {
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(MiscUtil
.snakeCaseToUpperCamelCase(b));
}
sendMessage(ChatColor.YELLOW + msg.toString());
} else if (!c.getRegionsWhileStayingWithin().isEmpty()) {
final StringBuilder msg = new StringBuilder("- " + Lang.get("conditionEditorStayWithinRegion"));
for (final String r : c.getRegionsWhileStayingWithin()) {
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(r);
}
sendMessage(ChatColor.YELLOW + msg.toString());
} else if (!c.getPlaceholdersCheckIdentifier().isEmpty()) {
final StringBuilder msg = new StringBuilder("- " + Lang.get("conditionEditorCheckPlaceholder"));
int index = 0;
for (final String r : c.getPlaceholdersCheckIdentifier()) {
if (c.getPlaceholdersCheckValue().size() > index) {
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(r).append(ChatColor.GRAY)
.append(" = ").append(ChatColor.AQUA).append(c.getPlaceholdersCheckValue()
.get(index));
}
index++;
}
sendMessage(ChatColor.YELLOW + msg.toString());
}
}
plugin.showConditions(quest, this);
}
if (quest.getInitialAction() != null) {
quest.getInitialAction().fire(this, quest);

View File

@ -1099,12 +1099,13 @@ public class Quests extends JavaPlugin implements QuestsAPI {
getLogger().warning("Quest data was null when showing objectives for " + quest.getName());
return;
}
final IStage stage = quester.getCurrentStage(quest);
if (quester.getCurrentStage(quest) == null) {
getLogger().warning("Current stage was null when showing objectives for " + quest.getName());
return;
}
if (!ignoreOverrides && !quester.getCurrentStage(quest).getObjectiveOverrides().isEmpty()) {
for (final String s: quester.getCurrentStage(quest).getObjectiveOverrides()) {
if (!ignoreOverrides && !stage.getObjectiveOverrides().isEmpty()) {
for (final String s: stage.getObjectiveOverrides()) {
String message = ChatColor.GREEN + (s.trim().length() > 0 ? "- " : "") + ConfigUtil
.parseString(s, quest, quester.getPlayer());
if (depends.getPlaceholderApi() != null) {
@ -1115,7 +1116,6 @@ public class Quests extends JavaPlugin implements QuestsAPI {
return;
}
final QuestData data = quester.getQuestData(quest);
final IStage stage = quester.getCurrentStage(quest);
for (final ItemStack e : stage.getBlocksToBreak()) {
for (final ItemStack e2 : data.blocksBroken) {
if (e2.getType().equals(e.getType()) && e2.getDurability() == e.getDurability()) {
@ -1629,6 +1629,99 @@ public class Quests extends JavaPlugin implements QuestsAPI {
customIndex++;
}
}
/**
* Show all of a player's conditions for the current stage of a quest.<p>
*
* @param quest The quest to get current stage objectives of
* @param quester The player to show current stage objectives to
*/
public void showConditions(final IQuest quest, final IQuester quester) {
if (quest == null) {
getLogger().severe("Quest was null when getting conditions for " + quester.getLastKnownName());
return;
}
if (quester.getQuestData(quest) == null) {
getLogger().warning("Quest data was null when showing conditions for " + quest.getName());
return;
}
final IStage stage = quester.getCurrentStage(quest);
if (stage == null) {
getLogger().warning("Current stage was null when showing conditions for " + quest.getName());
return;
}
final ICondition c = stage.getCondition();
if (c != null && stage.getObjectiveOverrides().isEmpty()) {
quester.sendMessage(ChatColor.LIGHT_PURPLE + Lang.get("stageEditorConditions"));
if (!c.getEntitiesWhileRiding().isEmpty()) {
final StringBuilder msg = new StringBuilder("- " + Lang.get("conditionEditorRideEntity"));
for (final String e : c.getEntitiesWhileRiding()) {
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(e);
}
quester.sendMessage(ChatColor.YELLOW + msg.toString());
} else if (!c.getNpcsWhileRiding().isEmpty()) {
final StringBuilder msg = new StringBuilder("- " + Lang.get("conditionEditorRideNPC"));
for (final UUID u : c.getNpcsWhileRiding()) {
if (getDependencies().getCitizens() != null) {
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(CitizensAPI.getNPCRegistry()
.getByUniqueId(u).getName());
} else {
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(u);
}
}
quester.sendMessage(ChatColor.YELLOW + msg.toString());
} else if (!c.getPermissions().isEmpty()) {
final StringBuilder msg = new StringBuilder("- " + Lang.get("conditionEditorPermissions"));
for (final String e : c.getPermissions()) {
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(e);
}
quester.sendMessage(ChatColor.YELLOW + msg.toString());
} else if (!c.getItemsWhileHoldingMainHand().isEmpty()) {
final StringBuilder msg = new StringBuilder("- " + Lang.get("conditionEditorItemsInMainHand"));
for (final ItemStack is : c.getItemsWhileHoldingMainHand()) {
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(ItemUtil.getPrettyItemName(is
.getType().name()));
}
quester.sendMessage(ChatColor.YELLOW + msg.toString());
} else if (!c.getWorldsWhileStayingWithin().isEmpty()) {
final StringBuilder msg = new StringBuilder("- " + Lang.get("conditionEditorStayWithinWorld"));
for (final String w : c.getWorldsWhileStayingWithin()) {
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(w);
}
quester.sendMessage(ChatColor.YELLOW + msg.toString());
} else if (c.getTickStartWhileStayingWithin() > -1 && c.getTickEndWhileStayingWithin() > -1) {
final StringBuilder msg = new StringBuilder("- ").append(Lang.get("conditionEditorStayWithinTicks"));
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(c.getTickStartWhileStayingWithin())
.append(" - ").append(c.getTickEndWhileStayingWithin());
quester.sendMessage(ChatColor.YELLOW + msg.toString());
} else if (!c.getBiomesWhileStayingWithin().isEmpty()) {
final StringBuilder msg = new StringBuilder("- " + Lang.get("conditionEditorStayWithinBiome"));
for (final String b : c.getBiomesWhileStayingWithin()) {
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(MiscUtil
.snakeCaseToUpperCamelCase(b));
}
quester.sendMessage(ChatColor.YELLOW + msg.toString());
} else if (!c.getRegionsWhileStayingWithin().isEmpty()) {
final StringBuilder msg = new StringBuilder("- " + Lang.get("conditionEditorStayWithinRegion"));
for (final String r : c.getRegionsWhileStayingWithin()) {
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(r);
}
quester.sendMessage(ChatColor.YELLOW + msg.toString());
} else if (!c.getPlaceholdersCheckIdentifier().isEmpty()) {
final StringBuilder msg = new StringBuilder("- " + Lang.get("conditionEditorCheckPlaceholder"));
int index = 0;
for (final String r : c.getPlaceholdersCheckIdentifier()) {
if (c.getPlaceholdersCheckValue().size() > index) {
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(r).append(ChatColor.GRAY)
.append(" = ").append(ChatColor.AQUA).append(c.getPlaceholdersCheckValue()
.get(index));
}
index++;
}
quester.sendMessage(ChatColor.YELLOW + msg.toString());
}
}
}
/**
* Show the player a list of their available quests
@ -3981,6 +4074,18 @@ public class Quests extends JavaPlugin implements QuestsAPI {
throw new ConditionFormatException("stay-within-world is not a list of worlds", conditionKey);
}
}
if (data.contains(conditionKey + "stay-within-ticks")) {
if (data.isInt(conditionKey + "stay-within-ticks.start")) {
condition.setTickStartWhileStayingWithin(data.getInt(conditionKey + "stay-within-ticks.start"));
} else {
throw new ConditionFormatException("start tick is not a number", conditionKey);
}
if (data.isInt(conditionKey + "stay-within-ticks.end")) {
condition.setTickEndWhileStayingWithin(data.getInt(conditionKey + "stay-within-ticks.end"));
} else {
throw new ConditionFormatException("end tick is not a number", conditionKey);
}
}
if (data.contains(conditionKey + "stay-within-biome")) {
if (ConfigUtil.checkList(data.getList(conditionKey + "stay-within-biome"), String.class)) {
final LinkedList<String> biomes = new LinkedList<>();

View File

@ -112,6 +112,14 @@ public class BukkitConditionFactory implements ConditionFactory, ConversationAba
final LinkedList<String> worlds = new LinkedList<>(condition.getBiomesWhileStayingWithin());
context.setSessionData(CK.C_WHILE_WITHIN_WORLD, worlds);
}
if (condition.getTickStartWhileStayingWithin() > -1) {
final int tick = condition.getTickStartWhileStayingWithin();
context.setSessionData(CK.C_WHILE_WITHIN_TICKS_START, tick);
}
if (condition.getTickEndWhileStayingWithin() > -1) {
final int tick = condition.getTickEndWhileStayingWithin();
context.setSessionData(CK.C_WHILE_WITHIN_TICKS_END, tick);
}
if (condition.getBiomesWhileStayingWithin() != null && !condition.getBiomesWhileStayingWithin().isEmpty()) {
final LinkedList<String> biomes = new LinkedList<>(condition.getBiomesWhileStayingWithin());
context.setSessionData(CK.C_WHILE_WITHIN_BIOME, biomes);
@ -140,6 +148,8 @@ public class BukkitConditionFactory implements ConditionFactory, ConversationAba
context.setSessionData(CK.C_WHILE_PERMISSION, null);
context.setSessionData(CK.C_WHILE_HOLDING_MAIN_HAND, null);
context.setSessionData(CK.C_WHILE_WITHIN_WORLD, null);
context.setSessionData(CK.C_WHILE_WITHIN_TICKS_START, null);
context.setSessionData(CK.C_WHILE_WITHIN_TICKS_END, null);
context.setSessionData(CK.C_WHILE_WITHIN_BIOME, null);
context.setSessionData(CK.C_WHILE_WITHIN_REGION, null);
context.setSessionData(CK.C_WHILE_PLACEHOLDER_ID, null);
@ -229,6 +239,12 @@ public class BukkitConditionFactory implements ConditionFactory, ConversationAba
if (context.getSessionData(CK.C_WHILE_WITHIN_WORLD) != null) {
section.set("stay-within-world", context.getSessionData(CK.C_WHILE_WITHIN_WORLD));
}
if (context.getSessionData(CK.C_WHILE_WITHIN_TICKS_START) != null) {
section.set("stay-within-ticks.start", context.getSessionData(CK.C_WHILE_WITHIN_TICKS_START));
}
if (context.getSessionData(CK.C_WHILE_WITHIN_TICKS_END) != null) {
section.set("stay-within-ticks.end", context.getSessionData(CK.C_WHILE_WITHIN_TICKS_END));
}
if (context.getSessionData(CK.C_WHILE_WITHIN_BIOME) != null) {
section.set("stay-within-biome", context.getSessionData(CK.C_WHILE_WITHIN_BIOME));
}

View File

@ -35,6 +35,8 @@ public class Condition implements ICondition {
private LinkedList<String> permissions = new LinkedList<>();
private LinkedList<ItemStack> itemsWhileHoldingMainHand = new LinkedList<>();
private LinkedList<String> worldsWhileStayingWithin = new LinkedList<>();
private int tickStartWhileStayingWithin = -1;
private int tickEndWhileStayingWithin = -1;
private LinkedList<String> biomesWhileStayingWithin = new LinkedList<>();
private LinkedList<String> regionsWhileStayingWithin = new LinkedList<>();
private LinkedList<String> placeholdersCheckIdentifier = new LinkedList<>();
@ -119,6 +121,26 @@ public class Condition implements ICondition {
this.worldsWhileStayingWithin = worldsWhileStayingWithin;
}
@Override
public int getTickStartWhileStayingWithin() {
return tickStartWhileStayingWithin;
}
@Override
public void setTickStartWhileStayingWithin(final int tickStartWhileStayingWithin) {
this.tickStartWhileStayingWithin = tickStartWhileStayingWithin;
}
@Override
public int getTickEndWhileStayingWithin() {
return tickEndWhileStayingWithin;
}
@Override
public void setTickEndWhileStayingWithin(final int tickEndWhileStayingWithin) {
this.tickEndWhileStayingWithin = tickEndWhileStayingWithin;
}
@Override
public LinkedList<String> getBiomesWhileStayingWithin() {
return biomesWhileStayingWithin;
@ -241,6 +263,11 @@ public class Condition implements ICondition {
if (!atLeastOne) {
failed = true;
}
} else if (tickStartWhileStayingWithin > -1 && tickEndWhileStayingWithin > -1) {
long t = player.getWorld().getTime();
if (t < tickStartWhileStayingWithin || t > tickEndWhileStayingWithin) {
failed = true;
}
} else if (!biomesWhileStayingWithin.isEmpty()) {
boolean atLeastOne = false;
for (final String b : biomesWhileStayingWithin) {

View File

@ -165,7 +165,6 @@ public class EffectPrompt extends ActionsEditorNumericPrompt {
public class EffectSoundListPrompt extends ActionsEditorNumericPrompt {
public EffectSoundListPrompt(final ConversationContext context) {
super(context);

View File

@ -14,9 +14,11 @@ package me.blackvein.quests.convo.conditions.tasks;
import com.sk89q.worldguard.protection.managers.RegionManager;
import me.blackvein.quests.Quests;
import me.blackvein.quests.convo.conditions.ConditionsEditorNumericPrompt;
import me.blackvein.quests.convo.conditions.main.ConditionMainPrompt;
import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt;
import me.blackvein.quests.convo.quests.QuestsEditorStringPrompt;
import me.blackvein.quests.events.editor.conditions.ConditionsEditorPostOpenNumericPromptEvent;
import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent;
import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenStringPromptEvent;
import me.blackvein.quests.reflect.worldguard.WorldGuardAPI;
@ -34,6 +36,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
public class WorldPrompt extends QuestsEditorNumericPrompt {
@ -44,7 +47,7 @@ public class WorldPrompt extends QuestsEditorNumericPrompt {
this.plugin = (Quests)context.getPlugin();
}
private final int size = 4;
private final int size = 5;
@Override
public int getSize() {
@ -62,8 +65,9 @@ public class WorldPrompt extends QuestsEditorNumericPrompt {
case 1:
case 2:
case 3:
return ChatColor.BLUE;
case 4:
return ChatColor.BLUE;
case 5:
return ChatColor.GREEN;
default:
return null;
@ -76,14 +80,16 @@ public class WorldPrompt extends QuestsEditorNumericPrompt {
case 1:
return ChatColor.YELLOW + Lang.get("conditionEditorStayWithinWorld");
case 2:
return ChatColor.YELLOW + Lang.get("conditionEditorStayWithinBiome");
return ChatColor.YELLOW + Lang.get("conditionEditorStayWithinTicks");
case 3:
return ChatColor.YELLOW + Lang.get("conditionEditorStayWithinBiome");
case 4:
if (plugin.getDependencies().getWorldGuardApi() != null) {
return ChatColor.YELLOW + Lang.get("conditionEditorStayWithinRegion");
} else {
return ChatColor.GRAY + Lang.get("conditionEditorStayWithinRegion");
}
case 4:
case 5:
return ChatColor.GREEN + Lang.get("done");
default:
return null;
@ -108,6 +114,14 @@ public class WorldPrompt extends QuestsEditorNumericPrompt {
return text.toString();
}
case 2:
if (context.getSessionData(CK.C_WHILE_WITHIN_TICKS_START) == null
|| context.getSessionData(CK.C_WHILE_WITHIN_TICKS_END) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
return ChatColor.GRAY + "(" + ChatColor.AQUA + context.getSessionData(CK.C_WHILE_WITHIN_TICKS_START)
+ " - " + context.getSessionData(CK.C_WHILE_WITHIN_TICKS_END)+ ChatColor.GRAY + ")";
}
case 3:
if (context.getSessionData(CK.C_WHILE_WITHIN_BIOME) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
@ -120,7 +134,7 @@ public class WorldPrompt extends QuestsEditorNumericPrompt {
}
return text.toString();
}
case 3:
case 4:
if (plugin.getDependencies().getWorldGuardApi() != null) {
if (context.getSessionData(CK.C_WHILE_WITHIN_REGION) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
@ -138,7 +152,7 @@ public class WorldPrompt extends QuestsEditorNumericPrompt {
} else {
return ChatColor.GRAY + "(" + Lang.get("notInstalled") + ")";
}
case 4:
case 5:
return "";
default:
return null;
@ -168,10 +182,12 @@ public class WorldPrompt extends QuestsEditorNumericPrompt {
case 1:
return new WorldsPrompt(context);
case 2:
return new BiomesPrompt(context);
return new TicksListPrompt(context);
case 3:
return new RegionsPrompt(context);
return new BiomesPrompt(context);
case 4:
return new RegionsPrompt(context);
case 5:
try {
return new ConditionMainPrompt(context);
} catch (final Exception e) {
@ -240,6 +256,225 @@ public class WorldPrompt extends QuestsEditorNumericPrompt {
return new WorldPrompt(context);
}
}
public class TicksListPrompt extends ConditionsEditorNumericPrompt {
public TicksListPrompt(final ConversationContext context) {
super(context);
}
private final int size = 4;
@Override
public int getSize() {
return size;
}
@Override
public String getTitle(final ConversationContext context) {
return Lang.get("conditionEditorTicksTitle");
}
@Override
public ChatColor getNumberColor(final ConversationContext context, final int number) {
switch (number) {
case 1:
case 2:
return ChatColor.BLUE;
case 3:
return ChatColor.RED;
case 4:
return ChatColor.GREEN;
default:
return null;
}
}
@Override
public String getSelectionText(final ConversationContext context, final int number) {
switch (number) {
case 1:
return ChatColor.YELLOW + Lang.get("conditionEditorSetStartTick");
case 2:
return ChatColor.YELLOW + Lang.get("conditionEditorSetEndTick");
case 3:
return ChatColor.RED + Lang.get("clear");
case 4:
return ChatColor.GREEN + Lang.get("done");
default:
return null;
}
}
@Override
public String getAdditionalText(final ConversationContext context, final int number) {
switch (number) {
case 1:
if (context.getSessionData(CK.C_WHILE_WITHIN_TICKS_START) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
final int i = (int) Objects.requireNonNull(context.getSessionData(CK.C_WHILE_WITHIN_TICKS_START));
return ChatColor.GRAY + "(" + ChatColor.AQUA + i + ChatColor.GRAY + ")";
}
case 2:
if (context.getSessionData(CK.C_WHILE_WITHIN_TICKS_END) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
final int i = (int) Objects.requireNonNull(context.getSessionData(CK.C_WHILE_WITHIN_TICKS_END));
return ChatColor.GRAY + "(" + ChatColor.AQUA + i + ChatColor.GRAY + ")";
}
case 3:
case 4:
return "";
default:
return null;
}
}
@Override
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
final ConditionsEditorPostOpenNumericPromptEvent event
= new ConditionsEditorPostOpenNumericPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event);
final StringBuilder text = new StringBuilder(ChatColor.GOLD + getTitle(context));
for (int i = 1; i <= size; i++) {
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i)
.append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i)).append(" ")
.append(getAdditionalText(context, i));
}
return text.toString();
}
@Override
protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
switch (input.intValue()) {
case 1:
return new TickStartPrompt(context);
case 2:
return new TickEndPrompt(context);
case 3:
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("conditionEditorConditionCleared"));
context.setSessionData(CK.C_WHILE_WITHIN_TICKS_START, null);
context.setSessionData(CK.C_WHILE_WITHIN_TICKS_END, null);
return new WorldPrompt(context);
case 4:
if (context.getSessionData(CK.C_WHILE_WITHIN_TICKS_START) != null
&& context.getSessionData(CK.C_WHILE_WITHIN_TICKS_END) != null) {
return new ConditionMainPrompt(context);
} else {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("listsNotSameSize"));
return new WorldPrompt.TicksListPrompt(context);
}
default:
return new WorldPrompt.TicksListPrompt(context);
}
}
}
public class TickStartPrompt extends QuestsEditorStringPrompt {
public TickStartPrompt(final ConversationContext context) {
super(context);
}
@Override
public String getTitle(final ConversationContext context) {
return null;
}
@Override
public String getQueryText(final ConversationContext context) {
return Lang.get("conditionEditorTicksPrompt");
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenStringPromptEvent event
= new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
return ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
if (input == null) {
return null;
}
if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
try {
final int i = Integer.parseInt(input);
if (i < 0 || i > 24000) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidRange")
.replace("<least>", "0").replace("<greatest>", "24000"));
return new TickStartPrompt(context);
} else {
context.setSessionData(CK.C_WHILE_WITHIN_TICKS_START, i);
}
} catch (final NumberFormatException e) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("reqNotANumber")
.replace("<input>", input));
return new TickStartPrompt(context);
}
}
return new TicksListPrompt(context);
}
}
public class TickEndPrompt extends QuestsEditorStringPrompt {
public TickEndPrompt(final ConversationContext context) {
super(context);
}
@Override
public String getTitle(final ConversationContext context) {
return null;
}
@Override
public String getQueryText(final ConversationContext context) {
return Lang.get("conditionEditorTicksPrompt");
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenStringPromptEvent event
= new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
return ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
if (input == null) {
return null;
}
if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
try {
final int i = Integer.parseInt(input);
if (i < 0 || i > 24000) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidRange")
.replace("<least>", "0").replace("<greatest>", "24000"));
return new TickEndPrompt(context);
} else {
context.setSessionData(CK.C_WHILE_WITHIN_TICKS_END, i);
}
} catch (final NumberFormatException e) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("reqNotANumber")
.replace("<input>", input));
return new TickEndPrompt(context);
}
}
return new TicksListPrompt(context);
}
}
public class BiomesPrompt extends QuestsEditorStringPrompt {

View File

@ -188,6 +188,8 @@ public class CK {
public static final String C_WHILE_PERMISSION = "conPermission";
public static final String C_WHILE_HOLDING_MAIN_HAND = "conHoldingMainHand";
public static final String C_WHILE_WITHIN_WORLD = "conWithinWorld";
public static final String C_WHILE_WITHIN_TICKS_START = "conWithinTicksStart";
public static final String C_WHILE_WITHIN_TICKS_END = "conWithinTicksEnd";
public static final String C_WHILE_WITHIN_BIOME = "conWithinBiome";
public static final String C_WHILE_WITHIN_REGION = "conWithinRegion";
public static final String C_WHILE_PLACEHOLDER_ID = "conPlaceholderId";

View File

@ -409,6 +409,12 @@ conditionEditorInvalidBiome: "<input> is not a valid biome name!"
conditionEditorRegionsTitle: "- Regions -"
conditionEditorRegionsPrompt: "Enter region names, <space>, <cancel>"
conditionEditorStayWithinRegion: "Stay within region"
conditionEditorTicksTitle: "- Ticks -"
conditionEditorSetStartTick: "Set start tick"
conditionEditorSetEndTick: "Set end tick"
conditionEditorTicksPrompt: "Enter tick value, <space>, <cancel>"
conditionEditorStayWithinTicks: "Stay within ticks"
conditionEditorInvalidTicks: "<input> is not a valid tick value!"
conditionEditorPlaceholderTitle: "- PlaceholderAPI -"
conditionEditorSetPlaceholderId: "Set placeholder identifiers"
conditionEditorSetPlaceholderVal: "Set placeholder values"