New check placeholder condition

This commit is contained in:
PikaMug 2020-10-27 06:05:15 -04:00
parent 85ec7e14a4
commit 71e0a01717
8 changed files with 340 additions and 15 deletions

View File

@ -633,6 +633,17 @@ public class Quester {
msg += ChatColor.AQUA + "\n \u2515 " + r;
}
p.sendMessage(ChatColor.YELLOW + msg);
} else if (!c.getPlaceholdersCheckIdentifier().isEmpty()) {
String msg = "- " + Lang.get("conditionEditorCheckPlaceholder");
int index = 0;
for (final String r : c.getPlaceholdersCheckIdentifier()) {
if (c.getPlaceholdersCheckValue().size() > index) {
msg += ChatColor.AQUA + "\n \u2515 " + r + ChatColor.GRAY + " = "
+ ChatColor.AQUA + c.getPlaceholdersCheckValue().get(index);
}
index++;
}
p.sendMessage(ChatColor.YELLOW + msg);
}
}
}

View File

@ -3462,6 +3462,24 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
throw new ConditionFormatException("stay-within-region is not a list of regions", conditionKey);
}
}
if (data.contains(conditionKey + "check-placeholder-id")) {
if (ConfigUtil.checkList(data.getList(conditionKey + "check-placeholder-id"), String.class)) {
if (data.contains(conditionKey + "check-placeholder-value")) {
if (ConfigUtil.checkList(data.getList(conditionKey + "check-placeholder-value"), String.class)) {
final LinkedList<String> identifiers = new LinkedList<String>();
final LinkedList<String> values = new LinkedList<String>();
identifiers.addAll(data.getStringList(conditionKey + "check-placeholder-id"));
values.addAll(data.getStringList(conditionKey + "check-placeholder-value"));
condition.setPlaceholdersCheckIdentifier(identifiers);
condition.setPlaceholdersCheckValue(values);
} else {
throw new ConditionFormatException("check-placeholder-value is not a list of values", conditionKey);
}
}
} else {
throw new ConditionFormatException("check-placeholder-id is not a list of identifiers", conditionKey);
}
}
return condition;
}

View File

@ -22,6 +22,7 @@ import me.blackvein.quests.Quester;
import me.blackvein.quests.Quests;
import me.blackvein.quests.util.ItemUtil;
import me.blackvein.quests.util.MiscUtil;
import me.clip.placeholderapi.PlaceholderAPI;
public class Condition {
@ -34,6 +35,8 @@ public class Condition {
private LinkedList<String> worldsWhileStayingWithin = new LinkedList<String>();
private LinkedList<String> biomesWhileStayingWithin = new LinkedList<String>();
private LinkedList<String> regionsWhileStayingWithin = new LinkedList<String>();
private LinkedList<String> placeholdersCheckIdentifier = new LinkedList<String>();
private LinkedList<String> placeholdersCheckValue = new LinkedList<String>();
public Condition(final Quests plugin) {
this.plugin = plugin;
@ -103,6 +106,22 @@ public class Condition {
this.regionsWhileStayingWithin = biomesWhileStayingWithin;
}
public LinkedList<String> getPlaceholdersCheckIdentifier() {
return placeholdersCheckIdentifier;
}
public void setPlaceholdersCheckIdentifier(final LinkedList<String> placeholdersCheckIdentifier) {
this.placeholdersCheckIdentifier = placeholdersCheckIdentifier;
}
public LinkedList<String> getPlaceholdersCheckValue() {
return placeholdersCheckValue;
}
public void setPlaceholdersCheckValue(final LinkedList<String> placeholdersCheckValue) {
this.placeholdersCheckValue = placeholdersCheckValue;
}
@SuppressWarnings("deprecation")
public boolean check(final Quester quester, final Quest quest) {
final Player player = quester.getPlayer();
@ -161,6 +180,21 @@ public class Condition {
plugin.getLogger().info("DEBUG: Condition region mismatch for " + player.getName() + ": " + r);
}
}
} else if (!placeholdersCheckIdentifier.isEmpty()) {
int index = 0;
for (final String i : placeholdersCheckIdentifier) {
if (plugin.getDependencies().isPluginAvailable("PlaceholderAPI")) {
if (placeholdersCheckValue.size() > index &&
placeholdersCheckValue.get(index).equals(PlaceholderAPI.setPlaceholders(player, i))) {
return true;
} else if (plugin.getSettings().getConsoleLogging() > 2) {
plugin.getLogger().info("DEBUG: Condition placeholder mismatch for " + player.getName() + ": " + i);
}
} else {
plugin.getLogger().warning("PAPI must be installed for placeholder checks: " + i);
}
index++;
}
}
return false;
}

View File

@ -115,6 +115,18 @@ public class ConditionFactory implements ConversationAbandonedListener {
regions.addAll(condition.getRegionsWhileStayingWithin());
context.setSessionData(CK.C_WHILE_WITHIN_REGION, regions);
}
if (condition.getPlaceholdersCheckIdentifier() != null
&& condition.getPlaceholdersCheckIdentifier().isEmpty() == false) {
final LinkedList<String> identifiers = new LinkedList<String>();
identifiers.addAll(condition.getPlaceholdersCheckIdentifier());
context.setSessionData(CK.C_WHILE_PLACEHOLDER_ID, identifiers);
}
if (condition.getPlaceholdersCheckValue() != null
&& condition.getPlaceholdersCheckValue().isEmpty() == false) {
final LinkedList<String> values = new LinkedList<String>();
values.addAll(condition.getPlaceholdersCheckValue());
context.setSessionData(CK.C_WHILE_PLACEHOLDER_VAL, values);
}
}
public void clearData(final ConversationContext context) {
@ -127,6 +139,8 @@ public class ConditionFactory implements ConversationAbandonedListener {
context.setSessionData(CK.C_WHILE_WITHIN_WORLD, 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);
context.setSessionData(CK.C_WHILE_PLACEHOLDER_VAL, null);
}
public void deleteCondition(final ConversationContext context) {
@ -231,6 +245,14 @@ public class ConditionFactory implements ConversationAbandonedListener {
section.set("stay-within-region",
context.getSessionData(CK.C_WHILE_WITHIN_REGION));
}
if (context.getSessionData(CK.C_WHILE_PLACEHOLDER_ID) != null) {
section.set("check-placeholder-id",
context.getSessionData(CK.C_WHILE_PLACEHOLDER_ID));
}
if (context.getSessionData(CK.C_WHILE_PLACEHOLDER_VAL) != null) {
section.set("check-placeholder-value",
context.getSessionData(CK.C_WHILE_PLACEHOLDER_VAL));
}
try {
data.save(conditionsFile);
} catch (final IOException e) {

View File

@ -12,6 +12,7 @@
package me.blackvein.quests.convo.conditions.main;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
@ -42,7 +43,7 @@ public class ConditionMainPrompt extends ConditionsEditorNumericPrompt {
this.plugin = (Quests)context.getPlugin();
}
private final int size = 7;
private final int size = 8;
@Override
public int getSize() {
@ -62,10 +63,11 @@ public class ConditionMainPrompt extends ConditionsEditorNumericPrompt {
case 3:
case 4:
case 5:
return ChatColor.BLUE;
case 6:
return ChatColor.GREEN;
return ChatColor.BLUE;
case 7:
return ChatColor.GREEN;
case 8:
return ChatColor.RED;
default:
return null;
@ -84,10 +86,12 @@ public class ConditionMainPrompt extends ConditionsEditorNumericPrompt {
case 4:
return ChatColor.GOLD + Lang.get("conditionEditorWorld");
case 5:
return ChatColor.YELLOW + Lang.get("conditionEditorFailQuest") + ":";
return ChatColor.YELLOW + Lang.get("conditionEditorCheckPlaceholder");
case 6:
return ChatColor.GREEN + Lang.get("save");
return ChatColor.YELLOW + Lang.get("conditionEditorFailQuest") + ":";
case 7:
return ChatColor.GREEN + Lang.get("save");
case 8:
return ChatColor.RED + Lang.get("exit");
default:
return null;
@ -101,14 +105,15 @@ public class ConditionMainPrompt extends ConditionsEditorNumericPrompt {
case 2:
case 3:
case 4:
return "";
case 5:
return "";
case 6:
if (context.getSessionData(CK.C_FAIL_QUEST) == null) {
context.setSessionData(CK.C_FAIL_QUEST, Lang.get("noWord"));
}
return "" + ChatColor.AQUA + context.getSessionData(CK.C_FAIL_QUEST);
case 6:
case 7:
case 8:
return "";
default:
return null;
@ -141,6 +146,8 @@ public class ConditionMainPrompt extends ConditionsEditorNumericPrompt {
case 4:
return new WorldPrompt(context);
case 5:
return new ConditionPlaceholderListPrompt(context);
case 6:
final String s = (String) context.getSessionData(CK.C_FAIL_QUEST);
if (s.equalsIgnoreCase(Lang.get("yesWord"))) {
context.setSessionData(CK.C_FAIL_QUEST, Lang.get("noWord"));
@ -148,13 +155,13 @@ public class ConditionMainPrompt extends ConditionsEditorNumericPrompt {
context.setSessionData(CK.C_FAIL_QUEST, Lang.get("yesWord"));
}
return new ConditionMainPrompt(context);
case 6:
case 7:
if (context.getSessionData(CK.C_OLD_CONDITION) != null) {
return new ConditionSavePrompt(context, (String) context.getSessionData(CK.C_OLD_CONDITION));
} else {
return new ConditionSavePrompt(context, null);
}
case 7:
case 8:
return new ConditionExitPrompt(context);
default:
return new ConditionMainPrompt(context);
@ -213,6 +220,229 @@ public class ConditionMainPrompt extends ConditionsEditorNumericPrompt {
}
}
public class ConditionPlaceholderListPrompt extends ConditionsEditorNumericPrompt {
public ConditionPlaceholderListPrompt(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("conditionEditorPlaceholderTitle");
}
@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("conditionEditorSetPlaceholderId");
case 2:
return ChatColor.YELLOW + Lang.get("conditionEditorSetPlaceholderVal");
case 3:
return ChatColor.RED + Lang.get("clear");
case 4:
return ChatColor.GREEN + Lang.get("done");
default:
return null;
}
}
@Override
@SuppressWarnings("unchecked")
public String getAdditionalText(final ConversationContext context, final int number) {
switch(number) {
case 1:
if (plugin.getDependencies().getPlaceholderApi() != null) {
if (context.getSessionData(CK.C_WHILE_PLACEHOLDER_ID) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
for (final String i : (List<String>) context.getSessionData(CK.C_WHILE_PLACEHOLDER_ID)) {
text += ChatColor.GRAY + " - " + ChatColor.AQUA + i + "\n";
}
return text;
}
} else {
return ChatColor.GRAY + "(" + Lang.get("notInstalled") + ")";
}
case 2:
if (plugin.getDependencies().getPlaceholderApi() != null) {
if (context.getSessionData(CK.C_WHILE_PLACEHOLDER_VAL) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
for (final String i : (List<String>) context.getSessionData(CK.C_WHILE_PLACEHOLDER_VAL)) {
text += ChatColor.GRAY + " - " + ChatColor.AQUA + i + "\n";
}
return text;
}
} else {
return ChatColor.GRAY + "(" + Lang.get("notInstalled") + ")";
}
case 3:
case 4:
return "";
default:
return null;
}
}
@Override
public String getPromptText(final ConversationContext context) {
final ConditionsEditorPostOpenNumericPromptEvent event
= new ConditionsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
String text = ChatColor.AQUA + getTitle(context) + "\n";
for (int i = 1; i <= size; i++) {
text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ getSelectionText(context, i) + " " + getAdditionalText(context, i) + "\n";
}
return text;
}
@SuppressWarnings("unchecked")
@Override
protected Prompt acceptValidatedInput(final ConversationContext context, final Number input) {
switch(input.intValue()) {
case 1:
return new ConditionPlaceholderIdentifierPrompt(context);
case 2:
return new ConditionPlaceholderValuePrompt(context);
case 3:
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("conditionEditorPlaceholderCleared"));
context.setSessionData(CK.C_WHILE_PLACEHOLDER_ID, null);
context.setSessionData(CK.C_WHILE_PLACEHOLDER_VAL, null);
return new ConditionPlaceholderListPrompt(context);
case 4:
int one;
int two;
if (context.getSessionData(CK.C_WHILE_PLACEHOLDER_ID) != null) {
one = ((List<String>) context.getSessionData(CK.C_WHILE_PLACEHOLDER_ID)).size();
} else {
one = 0;
}
if (context.getSessionData(CK.C_WHILE_PLACEHOLDER_VAL) != null) {
two = ((List<String>) context.getSessionData(CK.C_WHILE_PLACEHOLDER_VAL)).size();
} else {
two = 0;
}
if (one == two) {
return new ConditionMainPrompt(context);
} else {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("listsNotSameSize"));
return new ConditionPlaceholderListPrompt(context);
}
default:
return new ConditionPlaceholderListPrompt(context);
}
}
}
public class ConditionPlaceholderIdentifierPrompt extends ConditionsEditorStringPrompt {
public ConditionPlaceholderIdentifierPrompt(final ConversationContext context) {
super(context);
}
@Override
public String getTitle(final ConversationContext context) {
return null;
}
@Override
public String getQueryText(final ConversationContext context) {
return Lang.get("conditionEditorEnterPlaceholderId");
}
@Override
public String getPromptText(final ConversationContext context) {
final ConditionsEditorPostOpenStringPromptEvent event
= new ConditionsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
return ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
final String[] args = input.split(" ");
final List<String> identifiers = new LinkedList<String>();
for (String arg : args) {
if (!arg.trim().startsWith("%")) {
arg = "%" + arg.trim();
}
if (!arg.endsWith("%")) {
arg = arg + "%";
}
identifiers.add(arg);
}
context.setSessionData(CK.C_WHILE_PLACEHOLDER_ID, identifiers);
}
return new ConditionPlaceholderListPrompt(context);
}
}
public class ConditionPlaceholderValuePrompt extends ConditionsEditorStringPrompt {
public ConditionPlaceholderValuePrompt(final ConversationContext context) {
super(context);
}
@Override
public String getTitle(final ConversationContext context) {
return null;
}
@Override
public String getQueryText(final ConversationContext context) {
return Lang.get("conditionEditorEnterPlaceholderVal");
}
@Override
public String getPromptText(final ConversationContext context) {
final ConditionsEditorPostOpenStringPromptEvent event
= new ConditionsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
return ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
final String[] args = input.split(" ");
final List<String> values = new LinkedList<String>();
values.addAll(Arrays.asList(args));
context.setSessionData(CK.C_WHILE_PLACEHOLDER_VAL, values);
}
return new ConditionPlaceholderListPrompt(context);
}
}
public class ConditionSavePrompt extends ConditionsEditorStringPrompt {
String modName = null;

View File

@ -657,7 +657,7 @@ public class RewardsPrompt extends QuestsEditorNumericPrompt {
switch(number) {
case 1:
if (context.getSessionData(CK.REW_ITEMS) == null) {
return ChatColor.GRAY + " (" + Lang.get("noneSet") + ")";
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
for (final ItemStack is : (List<ItemStack>) context.getSessionData(CK.REW_ITEMS)) {
@ -1049,7 +1049,7 @@ public class RewardsPrompt extends QuestsEditorNumericPrompt {
switch(number) {
case 1:
if (context.getSessionData(CK.REW_MCMMO_SKILLS) == null) {
return ChatColor.GRAY + " (" + Lang.get("noneSet") + ")";
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
for (final String s : (List<String>) context.getSessionData(CK.REW_MCMMO_SKILLS)) {
@ -1059,7 +1059,7 @@ public class RewardsPrompt extends QuestsEditorNumericPrompt {
}
case 2:
if (context.getSessionData(CK.REW_MCMMO_AMOUNTS) == null) {
return ChatColor.GRAY + " (" + Lang.get("noneSet") + ")";
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
for (final Integer i : (List<Integer>) context.getSessionData(CK.REW_MCMMO_AMOUNTS)) {
@ -1068,6 +1068,7 @@ public class RewardsPrompt extends QuestsEditorNumericPrompt {
return text;
}
case 3:
case 4:
return "";
default:
return null;
@ -1121,7 +1122,7 @@ public class RewardsPrompt extends QuestsEditorNumericPrompt {
if (one == two) {
return new RewardsPrompt(context);
} else {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("rewMcMMOListsNotSameSize"));
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("listsNotSameSize"));
return new RewardsMcMMOListPrompt(context);
}
default:
@ -1289,7 +1290,7 @@ public class RewardsPrompt extends QuestsEditorNumericPrompt {
switch(number) {
case 1:
if (context.getSessionData(CK.REW_HEROES_CLASSES) == null) {
return ChatColor.GRAY + " (" + Lang.get("noneSet") + ")";
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
for (final String s : (List<String>) context.getSessionData(CK.REW_HEROES_CLASSES)) {
@ -1299,7 +1300,7 @@ public class RewardsPrompt extends QuestsEditorNumericPrompt {
}
case 2:
if (context.getSessionData(CK.REW_HEROES_AMOUNTS) == null) {
return ChatColor.GRAY + " (" + Lang.get("noneSet") + ")";
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
for (final Double d : (List<Double>) context.getSessionData(CK.REW_HEROES_AMOUNTS)) {

View File

@ -187,4 +187,6 @@ public class CK {
public static final String C_WHILE_WITHIN_WORLD = "conWithinWorld";
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";
public static final String C_WHILE_PLACEHOLDER_VAL = "conPlaceholderVal";
}

View File

@ -404,6 +404,7 @@ conditionEditorForcedToQuit: "If you save the condition, anyone who is actively
conditionEditorSetName: "Set name"
conditionEditorEntity: "Entity"
conditionEditorWorld: "World"
conditionEditorCheckPlaceholder: "Check placeholder"
conditionEditorFailQuest: "Fail the quest"
conditionEditorConditionCleared: "Condition cleared."
conditionEditorRideEntity: "Ride entity"
@ -426,6 +427,12 @@ conditionEditorRegionsTitle: "- Regions -"
conditionEditorRegionsPrompt: "Enter region names, <space>, <cancel>"
conditionEditorStayWithinRegion: "Stay within region"
conditionEditorInvalidRegion: "is not a valid region name!"
conditionEditorPlaceholderTitle: "- PlaceholderAPI -"
conditionEditorSetPlaceholderId: "Set placeholder identifiers"
conditionEditorSetPlaceholderVal: "Set placeholder values"
conditionEditorPlaceholderCleared: "Placeholder condition cleared."
conditionEditorEnterPlaceholderId: "Enter placeholder identifiers, <space>, <cancel>"
conditionEditorEnterPlaceholderVal: "Enter placeholder values, <space>, <cancel>"
reqSetMoney: "Set money requirement"
reqSetQuestPoints: "Set <points> requirement"
reqSetItem: "Set item requirements"