mirror of
https://github.com/PikaMug/Quests.git
synced 2025-01-06 00:18:39 +01:00
Save quest path requirements using ID, see #1715
This commit is contained in:
parent
a7eebe7919
commit
9b402c28bf
@ -188,12 +188,12 @@ public class QuestFactory implements ConversationAbandonedListener {
|
||||
context.setSessionData(CK.REQ_ITEMS_REMOVE, reqs.getRemoveItems());
|
||||
}
|
||||
if (!reqs.getNeededQuests().isEmpty()) {
|
||||
final List<String> names = reqs.getNeededQuests().stream().map(Quest::getName).collect(Collectors.toList());
|
||||
context.setSessionData(CK.REQ_QUEST, names);
|
||||
final List<String> ids = reqs.getNeededQuests().stream().map(Quest::getId).collect(Collectors.toList());
|
||||
context.setSessionData(CK.REQ_QUEST, ids);
|
||||
}
|
||||
if (!reqs.getBlockQuests().isEmpty()) {
|
||||
final List<String> names = reqs.getBlockQuests().stream().map(Quest::getName).collect(Collectors.toList());
|
||||
context.setSessionData(CK.REQ_QUEST_BLOCK, names);
|
||||
final List<String> ids = reqs.getBlockQuests().stream().map(Quest::getId).collect(Collectors.toList());
|
||||
context.setSessionData(CK.REQ_QUEST_BLOCK, ids);
|
||||
}
|
||||
if (!reqs.getMcmmoSkills().isEmpty()) {
|
||||
context.setSessionData(CK.REQ_MCMMO_SKILLS, reqs.getMcmmoAmounts());
|
||||
|
@ -683,7 +683,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
private void setupLang() throws IOException, URISyntaxException {
|
||||
final String path = "lang";
|
||||
final File jarFile = new File(getClass().getProtectionDomain().getCodeSource().getLocation().getPath());
|
||||
if(jarFile.isFile()) {
|
||||
if (jarFile.isFile()) {
|
||||
final JarFile jar = new JarFile(jarFile);
|
||||
final Enumeration<JarEntry> entries = jar.entries();
|
||||
final Set<String> results = new HashSet<>();
|
||||
@ -1769,7 +1769,6 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
boolean exists = false;
|
||||
for (final World world : getServer().getWorlds()) {
|
||||
if (world != null && getDependencies().getWorldGuardApi().getRegionManager(world) != null) {
|
||||
|
||||
if (Objects.requireNonNull(getDependencies().getWorldGuardApi().getRegionManager(world))
|
||||
.hasRegion(region)) {
|
||||
quest.regionStart = region;
|
||||
@ -1831,7 +1830,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
@SuppressWarnings({"unchecked", "deprecation"})
|
||||
private void loadQuestRewards(final FileConfiguration config, final Quest quest, final String questKey)
|
||||
throws QuestFormatException {
|
||||
final Rewards rews = quest.getRewards();
|
||||
final Rewards rewards = quest.getRewards();
|
||||
if (config.contains("quests." + questKey + ".rewards.items")) {
|
||||
final LinkedList<ItemStack> temp = new LinkedList<>();
|
||||
final List<ItemStack> stackList = (List<ItemStack>) config.get("quests." + questKey + ".rewards.items");
|
||||
@ -1859,25 +1858,25 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
throw new QuestFormatException("Reward items has invalid formatting", questKey);
|
||||
}
|
||||
}
|
||||
rews.setItems(temp);
|
||||
rewards.setItems(temp);
|
||||
}
|
||||
if (config.contains("quests." + questKey + ".rewards.money")) {
|
||||
if (config.getInt("quests." + questKey + ".rewards.money", -999) != -999) {
|
||||
rews.setMoney(config.getInt("quests." + questKey + ".rewards.money"));
|
||||
rewards.setMoney(config.getInt("quests." + questKey + ".rewards.money"));
|
||||
} else {
|
||||
throw new QuestFormatException("Reward money is not a number", questKey);
|
||||
}
|
||||
}
|
||||
if (config.contains("quests." + questKey + ".rewards.exp")) {
|
||||
if (config.getInt("quests." + questKey + ".rewards.exp", -999) != -999) {
|
||||
rews.setExp(config.getInt("quests." + questKey + ".rewards.exp"));
|
||||
rewards.setExp(config.getInt("quests." + questKey + ".rewards.exp"));
|
||||
} else {
|
||||
throw new QuestFormatException("Reward exp is not a number", questKey);
|
||||
}
|
||||
}
|
||||
if (config.contains("quests." + questKey + ".rewards.commands")) {
|
||||
if (ConfigUtil.checkList(config.getList("quests." + questKey + ".rewards.commands"), String.class)) {
|
||||
rews.setCommands(config.getStringList("quests." + questKey + ".rewards.commands"));
|
||||
rewards.setCommands(config.getStringList("quests." + questKey + ".rewards.commands"));
|
||||
} else {
|
||||
throw new QuestFormatException("Reward commands is not a list of commands", questKey);
|
||||
}
|
||||
@ -1886,7 +1885,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
// Legacy
|
||||
if (ConfigUtil.checkList(config.getList("quests." + questKey + ".rewards.commands-override-display"),
|
||||
String.class)) {
|
||||
rews.setCommandsOverrideDisplay(config.getStringList("quests." + questKey
|
||||
rewards.setCommandsOverrideDisplay(config.getStringList("quests." + questKey
|
||||
+ ".rewards.commands-override-display"));
|
||||
} else {
|
||||
throw new QuestFormatException("Reward commands-override-display is not a list of strings", questKey);
|
||||
@ -1894,7 +1893,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
}
|
||||
if (config.contains("quests." + questKey + ".rewards.permissions")) {
|
||||
if (ConfigUtil.checkList(config.getList("quests." + questKey + ".rewards.permissions"), String.class)) {
|
||||
rews.setPermissions(config.getStringList("quests." + questKey + ".rewards.permissions"));
|
||||
rewards.setPermissions(config.getStringList("quests." + questKey + ".rewards.permissions"));
|
||||
} else {
|
||||
throw new QuestFormatException("Reward permissions is not a list of permissions", questKey);
|
||||
}
|
||||
@ -1902,14 +1901,14 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
if (config.contains("quests." + questKey + ".rewards.permission-worlds")) {
|
||||
if (ConfigUtil.checkList(config.getList("quests." + questKey
|
||||
+ ".rewards.permission-worlds"), String.class)) {
|
||||
rews.setPermissionWorlds(config.getStringList("quests." + questKey + ".rewards.permission-worlds"));
|
||||
rewards.setPermissionWorlds(config.getStringList("quests." + questKey + ".rewards.permission-worlds"));
|
||||
} else {
|
||||
throw new QuestFormatException("Reward permissions is not a list of worlds", questKey);
|
||||
}
|
||||
}
|
||||
if (config.contains("quests." + questKey + ".rewards.quest-points")) {
|
||||
if (config.getInt("quests." + questKey + ".rewards.quest-points", -999) != -999) {
|
||||
rews.setQuestPoints(config.getInt("quests." + questKey + ".rewards.quest-points"));
|
||||
rewards.setQuestPoints(config.getInt("quests." + questKey + ".rewards.quest-points"));
|
||||
} else {
|
||||
throw new QuestFormatException("Reward quest-points is not a number", questKey);
|
||||
}
|
||||
@ -1930,8 +1929,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
+ skill, questKey);
|
||||
}
|
||||
}
|
||||
rews.setMcmmoSkills(config.getStringList("quests." + questKey + ".rewards.mcmmo-skills"));
|
||||
rews.setMcmmoAmounts(config.getIntegerList("quests." + questKey + ".rewards.mcmmo-levels"));
|
||||
rewards.setMcmmoSkills(config.getStringList("quests." + questKey
|
||||
+ ".rewards.mcmmo-skills"));
|
||||
rewards.setMcmmoAmounts(config.getIntegerList("quests." + questKey
|
||||
+ ".rewards.mcmmo-levels"));
|
||||
} else {
|
||||
throw new QuestFormatException("Reward mcmmo-levels is not a list of numbers", questKey);
|
||||
}
|
||||
@ -1959,9 +1960,9 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
+ heroClass, questKey);
|
||||
}
|
||||
}
|
||||
rews.setHeroesClasses(config.getStringList("quests." + questKey
|
||||
rewards.setHeroesClasses(config.getStringList("quests." + questKey
|
||||
+ ".rewards.heroes-exp-classes"));
|
||||
rews.setHeroesAmounts(config.getDoubleList("quests." + questKey
|
||||
rewards.setHeroesAmounts(config.getDoubleList("quests." + questKey
|
||||
+ ".rewards.heroes-exp-amounts"));
|
||||
} else {
|
||||
throw new QuestFormatException("Reward heroes-exp-amounts is not a list of decimal numbers",
|
||||
@ -1979,7 +1980,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
if (depends.isPluginAvailable("Parties")) {
|
||||
if (config.contains("quests." + questKey + ".rewards.parties-experience")) {
|
||||
if (config.getInt("quests." + questKey + ".rewards.parties-experience", -999) != -999) {
|
||||
rews.setPartiesExperience(config.getInt("quests." + questKey + ".rewards.parties-experience"));
|
||||
rewards.setPartiesExperience(config.getInt("quests." + questKey + ".rewards.parties-experience"));
|
||||
} else {
|
||||
throw new QuestFormatException("Reward parties-experience is not a number", questKey);
|
||||
}
|
||||
@ -1996,7 +1997,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
questKey);
|
||||
}
|
||||
}
|
||||
rews.setPhatLoots(config.getStringList("quests." + questKey + ".rewards.phat-loots"));
|
||||
rewards.setPhatLoots(config.getStringList("quests." + questKey + ".rewards.phat-loots"));
|
||||
} else {
|
||||
throw new QuestFormatException("Reward phat-loots is not a list of PhatLoots", questKey);
|
||||
}
|
||||
@ -2005,7 +2006,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
if (config.contains("quests." + questKey + ".rewards.details-override")) {
|
||||
if (ConfigUtil.checkList(config.getList("quests." + questKey
|
||||
+ ".rewards.details-override"), String.class)) {
|
||||
rews.setDetailsOverride(config.getStringList("quests." + questKey + ".rewards.details-override"));
|
||||
rewards.setDetailsOverride(config.getStringList("quests." + questKey + ".rewards.details-override"));
|
||||
} else {
|
||||
throw new QuestFormatException("Reward details-override is not a list of strings", questKey);
|
||||
}
|
||||
@ -2015,17 +2016,17 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
@SuppressWarnings({ "unchecked", "deprecation" })
|
||||
private void loadQuestRequirements(final FileConfiguration config, final ConfigurationSection questsSection,
|
||||
final Quest quest, final String questKey) throws QuestFormatException {
|
||||
final Requirements reqs = quest.getRequirements();
|
||||
final Requirements requires = quest.getRequirements();
|
||||
if (config.contains("quests." + questKey + ".requirements.fail-requirement-message")) {
|
||||
final Object o = config.get("quests." + questKey + ".requirements.fail-requirement-message");
|
||||
if (o instanceof List) {
|
||||
reqs.setDetailsOverride(config.getStringList("quests." + questKey
|
||||
requires.setDetailsOverride(config.getStringList("quests." + questKey
|
||||
+ ".requirements.fail-requirement-message"));
|
||||
} else {
|
||||
// Legacy
|
||||
final List<String> override = new LinkedList<>();
|
||||
override.add((String) o);
|
||||
reqs.setDetailsOverride(override);
|
||||
requires.setDetailsOverride(override);
|
||||
}
|
||||
}
|
||||
if (config.contains("quests." + questKey + ".requirements.items")) {
|
||||
@ -2057,11 +2058,11 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
throw new QuestFormatException("Requirement items has invalid formatting", questKey);
|
||||
}
|
||||
}
|
||||
reqs.setItems(temp);
|
||||
requires.setItems(temp);
|
||||
if (config.contains("quests." + questKey + ".requirements.remove-items")) {
|
||||
if (ConfigUtil.checkList(config.getList("quests." + questKey + ".requirements.remove-items"),
|
||||
Boolean.class)) {
|
||||
reqs.setRemoveItems(config.getBooleanList("quests." + questKey + ".requirements.remove-items"));
|
||||
requires.setRemoveItems(config.getBooleanList("quests." + questKey + ".requirements.remove-items"));
|
||||
} else {
|
||||
throw new QuestFormatException("Requirement remove-items is not a list of true/false values",
|
||||
questKey);
|
||||
@ -2072,14 +2073,14 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
}
|
||||
if (config.contains("quests." + questKey + ".requirements.money")) {
|
||||
if (config.getInt("quests." + questKey + ".requirements.money", -999) != -999) {
|
||||
reqs.setMoney(config.getInt("quests." + questKey + ".requirements.money"));
|
||||
requires.setMoney(config.getInt("quests." + questKey + ".requirements.money"));
|
||||
} else {
|
||||
throw new QuestFormatException("Requirement money is not a number", questKey);
|
||||
}
|
||||
}
|
||||
if (config.contains("quests." + questKey + ".requirements.quest-points")) {
|
||||
if (config.getInt("quests." + questKey + ".requirements.quest-points", -999) != -999) {
|
||||
reqs.setQuestPoints(config.getInt("quests." + questKey + ".requirements.quest-points"));
|
||||
requires.setQuestPoints(config.getInt("quests." + questKey + ".requirements.quest-points"));
|
||||
} else {
|
||||
throw new QuestFormatException("Requirement quest-points is not a number", questKey);
|
||||
}
|
||||
@ -2087,21 +2088,23 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
if (config.contains("quests." + questKey + ".requirements.quest-blocks")) {
|
||||
if (ConfigUtil.checkList(config.getList("quests." + questKey + ".requirements.quest-blocks"),
|
||||
String.class)) {
|
||||
final List<String> names = config.getStringList("quests." + questKey + ".requirements.quest-blocks");
|
||||
final List<String> nodes = config.getStringList("quests." + questKey + ".requirements.quest-blocks");
|
||||
boolean failed = false;
|
||||
String failedQuest = "NULL";
|
||||
final List<Quest> temp = new LinkedList<>();
|
||||
for (final String name : names) {
|
||||
for (final String node : nodes) {
|
||||
boolean done = false;
|
||||
for (final String id : questsSection.getKeys(false)) {
|
||||
final String name2 = config.getString("quests." + id + ".name");
|
||||
if (name2 != null && (name2.equalsIgnoreCase(name)
|
||||
|| ChatColor.stripColor(name2).equalsIgnoreCase(ChatColor.stripColor(name)))) {
|
||||
if (getQuest(name) != null) {
|
||||
temp.add(getQuest(name));
|
||||
final String node2 = config.getString("quests." + id + ".name");
|
||||
if (node2 != null && (id.equals(node) || node2.equalsIgnoreCase(node)
|
||||
|| ChatColor.stripColor(node2).equalsIgnoreCase(ChatColor.stripColor(node)))) {
|
||||
if (getQuest(node) != null) {
|
||||
temp.add(getQuest(node));
|
||||
} else if (getQuestById(node) != null) {
|
||||
temp.add(getQuestById(node));
|
||||
} else {
|
||||
throw new QuestFormatException("Requirement quest-blocks has unknown quest name "
|
||||
+ name + ", place it earlier in file so it loads first", questKey);
|
||||
throw new QuestFormatException("Requirement quest-blocks has unknown quest name/id "
|
||||
+ node + ", place it earlier in file so it loads first", questKey);
|
||||
}
|
||||
done = true;
|
||||
break;
|
||||
@ -2109,13 +2112,13 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
}
|
||||
if (!done) {
|
||||
failed = true;
|
||||
failedQuest = name;
|
||||
failedQuest = node;
|
||||
break;
|
||||
}
|
||||
}
|
||||
reqs.setBlockQuests(temp);
|
||||
requires.setBlockQuests(temp);
|
||||
if (failed) {
|
||||
throw new QuestFormatException("Requirement quest-blocks has invalid quest name " + failedQuest,
|
||||
throw new QuestFormatException("Requirement quest-blocks has invalid quest name/id " + failedQuest,
|
||||
questKey);
|
||||
}
|
||||
} else {
|
||||
@ -2124,21 +2127,23 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
}
|
||||
if (config.contains("quests." + questKey + ".requirements.quests")) {
|
||||
if (ConfigUtil.checkList(config.getList("quests." + questKey + ".requirements.quests"), String.class)) {
|
||||
final List<String> names = config.getStringList("quests." + questKey + ".requirements.quests");
|
||||
final List<String> nodes = config.getStringList("quests." + questKey + ".requirements.quests");
|
||||
boolean failed = false;
|
||||
String failedQuest = "NULL";
|
||||
final List<Quest> temp = new LinkedList<>();
|
||||
for (final String name : names) {
|
||||
for (final String node : nodes) {
|
||||
boolean done = false;
|
||||
for (final String id : questsSection.getKeys(false)) {
|
||||
final String name2 = config.getString("quests." + id + ".name");
|
||||
if (name2 != null && (name2.equalsIgnoreCase(name)
|
||||
|| ChatColor.stripColor(name2).equalsIgnoreCase(ChatColor.stripColor(name)))) {
|
||||
if (getQuest(name) != null) {
|
||||
temp.add(getQuest(name));
|
||||
final String node2 = config.getString("quests." + id + ".name");
|
||||
if (node2 != null && (id.equals(node) || node2.equalsIgnoreCase(node)
|
||||
|| ChatColor.stripColor(node2).equalsIgnoreCase(ChatColor.stripColor(node)))) {
|
||||
if (getQuest(node) != null) {
|
||||
temp.add(getQuest(node));
|
||||
} else if (getQuestById(node) != null) {
|
||||
temp.add(getQuestById(node));
|
||||
} else {
|
||||
throw new QuestFormatException("Requirement quests has unknown quest name "
|
||||
+ name + ", place it earlier in file so it loads first", questKey);
|
||||
+ node + ", place it earlier in file so it loads first", questKey);
|
||||
}
|
||||
done = true;
|
||||
break;
|
||||
@ -2146,13 +2151,13 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
}
|
||||
if (!done) {
|
||||
failed = true;
|
||||
failedQuest = name;
|
||||
failedQuest = node;
|
||||
break;
|
||||
}
|
||||
}
|
||||
reqs.setNeededQuests(temp);
|
||||
requires.setNeededQuests(temp);
|
||||
if (failed) {
|
||||
throw new QuestFormatException("Requirement quests has invalid quest name "
|
||||
throw new QuestFormatException("Requirement quests has invalid quest name/id "
|
||||
+ failedQuest, questKey);
|
||||
}
|
||||
} else {
|
||||
@ -2162,7 +2167,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
if (config.contains("quests." + questKey + ".requirements.permissions")) {
|
||||
if (ConfigUtil.checkList(config.getList("quests." + questKey + ".requirements.permissions"),
|
||||
String.class)) {
|
||||
reqs.setPermissions(config.getStringList("quests." + questKey + ".requirements.permissions"));
|
||||
requires.setPermissions(config.getStringList("quests." + questKey + ".requirements.permissions"));
|
||||
} else {
|
||||
throw new QuestFormatException("Requirement permissions is not a list of permissions", questKey);
|
||||
}
|
||||
@ -2181,8 +2186,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
throw new QuestFormatException("Requirement mcmmo-skills: and mcmmo-amounts are not the " +
|
||||
"same size", questKey);
|
||||
}
|
||||
reqs.setMcmmoSkills(skills);
|
||||
reqs.setMcmmoAmounts(amounts);
|
||||
requires.setMcmmoSkills(skills);
|
||||
requires.setMcmmoAmounts(amounts);
|
||||
} else {
|
||||
throw new QuestFormatException("Requirement mcmmo-amounts is not a list of numbers", questKey);
|
||||
}
|
||||
@ -2197,7 +2202,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
final String className = config.getString("quests." + questKey + ".requirements.heroes-primary-class");
|
||||
final HeroClass hc = depends.getHeroes().getClassManager().getClass(className);
|
||||
if (hc != null && hc.isPrimary()) {
|
||||
reqs.setHeroesPrimaryClass(hc.getName());
|
||||
requires.setHeroesPrimaryClass(hc.getName());
|
||||
} else if (hc != null) {
|
||||
throw new QuestFormatException("Requirement heroes-primary-class is not a primary Heroes class",
|
||||
questKey);
|
||||
@ -2209,7 +2214,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
final String className = config.getString("quests." + questKey + ".requirements.heroes-secondary-class");
|
||||
final HeroClass hc = depends.getHeroes().getClassManager().getClass(className);
|
||||
if (hc != null && hc.isSecondary()) {
|
||||
reqs.setHeroesSecondaryClass(hc.getName());
|
||||
requires.setHeroesSecondaryClass(hc.getName());
|
||||
} else if (hc != null) {
|
||||
throw new QuestFormatException("Requirement heroes-secondary-class is not a secondary Heroes class",
|
||||
questKey);
|
||||
@ -2220,7 +2225,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
if (config.contains("quests." + questKey + ".requirements.details-override")) {
|
||||
if (ConfigUtil.checkList(config.getList("quests." + questKey
|
||||
+ ".requirements.details-override"), String.class)) {
|
||||
reqs.setDetailsOverride(config.getStringList("quests." + questKey + ".requirements.details-override"));
|
||||
requires.setDetailsOverride(config.getStringList("quests." + questKey + ".requirements.details-override"));
|
||||
} else {
|
||||
throw new QuestFormatException("Requirement details-override is not a list of strings", questKey);
|
||||
}
|
||||
@ -3993,7 +3998,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
final YamlConfiguration config = new YamlConfiguration();
|
||||
final File legacyFile = new File(this.getDataFolder(), "events.yml");
|
||||
final File actionsFile = new File(this.getDataFolder(), "actions.yml");
|
||||
// Using isFile() because exists() and renameTo() can return false positives
|
||||
// Using #isFile because #exists and #renameTo can return false positives
|
||||
if (legacyFile.isFile()) {
|
||||
try {
|
||||
if (legacyFile.renameTo(actionsFile)) {
|
||||
@ -4054,7 +4059,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
public void loadConditions() {
|
||||
final YamlConfiguration config = new YamlConfiguration();
|
||||
final File conditionsFile = new File(this.getDataFolder(), "conditions.yml");
|
||||
// Using isFile() because exists() and renameTo() can return false positives
|
||||
// Using #isFile because #exists and #renameTo can return false positives
|
||||
if (conditionsFile.length() != 0) {
|
||||
try {
|
||||
if (conditionsFile.isFile()) {
|
||||
|
@ -36,7 +36,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -216,7 +215,10 @@ public class RequirementsPrompt extends QuestsEditorNumericPrompt {
|
||||
final StringBuilder text = new StringBuilder("\n");
|
||||
final List<String> questReq = (List<String>) context.getSessionData(CK.REQ_QUEST);
|
||||
if (questReq != null) {
|
||||
for (final String s : questReq) {
|
||||
for (String s : questReq) {
|
||||
if (plugin.getQuestById(s) != null) {
|
||||
s = plugin.getQuestById(s).getName();
|
||||
}
|
||||
text.append(ChatColor.GRAY).append(" - ").append(ChatColor.AQUA).append(s).append("\n");
|
||||
}
|
||||
}
|
||||
@ -229,7 +231,10 @@ public class RequirementsPrompt extends QuestsEditorNumericPrompt {
|
||||
final StringBuilder text = new StringBuilder("\n");
|
||||
final List<String> questBlockReq = (List<String>) context.getSessionData(CK.REQ_QUEST_BLOCK);
|
||||
if (questBlockReq != null) {
|
||||
for (final String s : questBlockReq) {
|
||||
for (String s : questBlockReq) {
|
||||
if (plugin.getQuestById(s) != null) {
|
||||
s = plugin.getQuestById(s).getName();
|
||||
}
|
||||
text.append(ChatColor.GRAY).append(" - ").append(ChatColor.AQUA).append(s).append("\n");
|
||||
}
|
||||
}
|
||||
@ -534,88 +539,6 @@ public class RequirementsPrompt extends QuestsEditorNumericPrompt {
|
||||
}
|
||||
}
|
||||
|
||||
public class RequirementsQuestListPrompt extends QuestsEditorStringPrompt {
|
||||
|
||||
private final boolean isRequiredQuest;
|
||||
|
||||
public RequirementsQuestListPrompt(final ConversationContext context, final boolean isRequired) {
|
||||
super(context);
|
||||
this.isRequiredQuest = isRequired;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle(final ConversationContext context) {
|
||||
return Lang.get("reqQuestListTitle");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQueryText(final ConversationContext context) {
|
||||
return Lang.get("reqQuestPrompt");
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
StringBuilder text = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n"
|
||||
+ ChatColor.DARK_PURPLE);
|
||||
boolean none = true;
|
||||
for (final Quest q : plugin.getLoadedQuests()) {
|
||||
text.append(q.getName()).append(", ");
|
||||
none = false;
|
||||
}
|
||||
if (none) {
|
||||
text.append("(").append(Lang.get("none")).append(")\n");
|
||||
} else {
|
||||
text = new StringBuilder(text.substring(0, (text.length() - 2)));
|
||||
text.append("\n");
|
||||
}
|
||||
text.append(ChatColor.YELLOW).append(getQueryText(context));
|
||||
return text.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
|
||||
if (input == null) {
|
||||
return null;
|
||||
}
|
||||
if (!input.equalsIgnoreCase(Lang.get("cmdCancel")) && !input.equalsIgnoreCase(Lang.get("cmdClear"))) {
|
||||
final String[] args = input.split(Lang.get("charSemi"));
|
||||
final LinkedList<String> questNames = new LinkedList<>();
|
||||
for (final String s : args) {
|
||||
if (plugin.getQuest(s) == null) {
|
||||
String text = Lang.get("reqNotAQuestName");
|
||||
text = text.replace("<quest>", ChatColor.LIGHT_PURPLE + s + ChatColor.RED);
|
||||
context.getForWhom().sendRawMessage(text);
|
||||
return new RequirementsQuestListPrompt(context, isRequiredQuest);
|
||||
}
|
||||
if (questNames.contains(s)) {
|
||||
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("listDuplicate"));
|
||||
return new RequirementsQuestListPrompt(context, isRequiredQuest);
|
||||
}
|
||||
questNames.add(plugin.getQuest(s).getName());
|
||||
}
|
||||
questNames.sort(Comparator.naturalOrder());
|
||||
if (isRequiredQuest) {
|
||||
context.setSessionData(CK.REQ_QUEST, questNames);
|
||||
} else {
|
||||
context.setSessionData(CK.REQ_QUEST_BLOCK, questNames);
|
||||
}
|
||||
} else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) {
|
||||
if (isRequiredQuest) {
|
||||
context.setSessionData(CK.REQ_QUEST, null);
|
||||
} else {
|
||||
context.setSessionData(CK.REQ_QUEST_BLOCK, null);
|
||||
}
|
||||
}
|
||||
return new RequirementsPrompt(context);
|
||||
}
|
||||
}
|
||||
|
||||
public class RequirementsItemListPrompt extends QuestsEditorNumericPrompt {
|
||||
|
||||
public RequirementsItemListPrompt(final ConversationContext context) {
|
||||
@ -896,20 +819,23 @@ public class RequirementsPrompt extends QuestsEditorNumericPrompt {
|
||||
}
|
||||
}
|
||||
|
||||
public class CustomRequirementsPrompt extends QuestsEditorStringPrompt {
|
||||
|
||||
public CustomRequirementsPrompt(final ConversationContext context) {
|
||||
public class RequirementsQuestListPrompt extends QuestsEditorStringPrompt {
|
||||
|
||||
private final boolean isRequiredQuest;
|
||||
|
||||
public RequirementsQuestListPrompt(final ConversationContext context, final boolean isRequired) {
|
||||
super(context);
|
||||
this.isRequiredQuest = isRequired;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle(final ConversationContext context) {
|
||||
return Lang.get("customRequirementsTitle");
|
||||
return Lang.get("reqQuestListTitle");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQueryText(final ConversationContext context) {
|
||||
return Lang.get("reqCustomPrompt");
|
||||
return Lang.get("reqQuestPrompt");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -919,194 +845,61 @@ public class RequirementsPrompt extends QuestsEditorNumericPrompt {
|
||||
= new QuestsEditorPostOpenStringPromptEvent(context, this);
|
||||
context.getPlugin().getServer().getPluginManager().callEvent(event);
|
||||
}
|
||||
|
||||
final StringBuilder text = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n");
|
||||
if (plugin.getCustomRequirements().isEmpty()) {
|
||||
text.append(ChatColor.DARK_AQUA).append(ChatColor.UNDERLINE)
|
||||
.append("https://pikamug.gitbook.io/quests/casual/modules\n").append(ChatColor.DARK_PURPLE)
|
||||
.append("(").append(Lang.get("stageEditorNoModules")).append(") ");
|
||||
} else {
|
||||
for (final CustomRequirement cr : plugin.getCustomRequirements()) {
|
||||
text.append(ChatColor.DARK_PURPLE).append(" - ").append(cr.getName()).append("\n");
|
||||
}
|
||||
|
||||
StringBuilder text = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n"
|
||||
+ ChatColor.DARK_PURPLE);
|
||||
boolean none = true;
|
||||
for (final Quest q : plugin.getLoadedQuests()) {
|
||||
text.append(q.getName()).append(", ");
|
||||
none = false;
|
||||
}
|
||||
return text.toString() + ChatColor.YELLOW + getQueryText(context);
|
||||
if (none) {
|
||||
text.append("(").append(Lang.get("none")).append(")\n");
|
||||
} else {
|
||||
text = new StringBuilder(text.substring(0, (text.length() - 2)));
|
||||
text.append("\n");
|
||||
}
|
||||
text.append(ChatColor.YELLOW).append(getQueryText(context));
|
||||
return text.toString();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
|
||||
if (input == null) {
|
||||
return null;
|
||||
}
|
||||
if (!input.equalsIgnoreCase(Lang.get("cmdCancel")) && !input.equalsIgnoreCase(Lang.get("cmdClear"))) {
|
||||
CustomRequirement found = null;
|
||||
// Check if we have a custom requirement with the specified name
|
||||
for (final CustomRequirement cr : plugin.getCustomRequirements()) {
|
||||
if (cr.getName().equalsIgnoreCase(input)) {
|
||||
found = cr;
|
||||
break;
|
||||
final String[] args = input.split(Lang.get("charSemi"));
|
||||
final LinkedList<String> questIds = new LinkedList<>();
|
||||
for (final String s : args) {
|
||||
if (plugin.getQuest(s) == null) {
|
||||
String text = Lang.get("reqNotAQuestName");
|
||||
text = text.replace("<quest>", ChatColor.LIGHT_PURPLE + s + ChatColor.RED);
|
||||
context.getForWhom().sendRawMessage(text);
|
||||
return new RequirementsQuestListPrompt(context, isRequiredQuest);
|
||||
}
|
||||
if (questIds.contains(plugin.getQuest(s).getId())) {
|
||||
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("listDuplicate"));
|
||||
return new RequirementsQuestListPrompt(context, isRequiredQuest);
|
||||
}
|
||||
questIds.add(plugin.getQuest(s).getId());
|
||||
}
|
||||
if (found == null) {
|
||||
// No? Check again, but with locale sensitivity
|
||||
for (final CustomRequirement cr : plugin.getCustomRequirements()) {
|
||||
if (cr.getName().toLowerCase().contains(input.toLowerCase())) {
|
||||
found = cr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found != null) {
|
||||
if (context.getSessionData(CK.REQ_CUSTOM) != null) {
|
||||
// The custom requirement may already have been added, so let's check that
|
||||
final LinkedList<String> list = (LinkedList<String>) context.getSessionData(CK.REQ_CUSTOM);
|
||||
final LinkedList<Map<String, Object>> dataMapList
|
||||
= (LinkedList<Map<String, Object>>) context.getSessionData(CK.REQ_CUSTOM_DATA);
|
||||
if (dataMapList != null && list != null && !list.contains(found.getName())) {
|
||||
// Hasn't been added yet, so let's do it
|
||||
list.add(found.getName());
|
||||
dataMapList.add(found.getData());
|
||||
context.setSessionData(CK.REQ_CUSTOM, list);
|
||||
context.setSessionData(CK.REQ_CUSTOM_DATA, dataMapList);
|
||||
} else {
|
||||
// Already added, so inform user
|
||||
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("reqCustomAlreadyAdded"));
|
||||
return new CustomRequirementsPrompt(context);
|
||||
}
|
||||
} else {
|
||||
// The custom requirement hasn't been added yet, so let's do it
|
||||
final LinkedList<Map<String, Object>> dataMapList = new LinkedList<>();
|
||||
dataMapList.add(found.getData());
|
||||
final LinkedList<String> list = new LinkedList<>();
|
||||
list.add(found.getName());
|
||||
context.setSessionData(CK.REQ_CUSTOM, list);
|
||||
context.setSessionData(CK.REQ_CUSTOM_DATA, dataMapList);
|
||||
}
|
||||
// Send user to the custom data prompt if there is any needed
|
||||
if (!found.getData().isEmpty()) {
|
||||
context.setSessionData(CK.REQ_CUSTOM_DATA_DESCRIPTIONS, found.getDescriptions());
|
||||
return new RequirementCustomDataListPrompt();
|
||||
}
|
||||
if (isRequiredQuest) {
|
||||
context.setSessionData(CK.REQ_QUEST, questIds);
|
||||
} else {
|
||||
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("reqCustomNotFound"));
|
||||
return new CustomRequirementsPrompt(context);
|
||||
context.setSessionData(CK.REQ_QUEST_BLOCK, questIds);
|
||||
}
|
||||
} else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) {
|
||||
context.setSessionData(CK.REQ_CUSTOM, null);
|
||||
context.setSessionData(CK.REQ_CUSTOM_DATA, null);
|
||||
context.setSessionData(CK.REQ_CUSTOM_DATA_TEMP, null);
|
||||
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("reqCustomCleared"));
|
||||
}
|
||||
return new RequirementsPrompt(context);
|
||||
}
|
||||
}
|
||||
|
||||
private class RequirementCustomDataListPrompt extends StringPrompt {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public @NotNull String getPromptText(final ConversationContext context) {
|
||||
final StringBuilder text = new StringBuilder(ChatColor.GOLD + "- ");
|
||||
final LinkedList<String> list = (LinkedList<String>) context.getSessionData(CK.REQ_CUSTOM);
|
||||
final LinkedList<Map<String, Object>> dataMapList
|
||||
= (LinkedList<Map<String, Object>>) context.getSessionData(CK.REQ_CUSTOM_DATA);
|
||||
if (dataMapList != null && list != null) {
|
||||
final String reqName = list.getLast();
|
||||
final Map<String, Object> dataMap = dataMapList.getLast();
|
||||
text.append(reqName).append(" -\n");
|
||||
int index = 1;
|
||||
final LinkedList<String> dataMapKeys = new LinkedList<>(dataMap.keySet());
|
||||
Collections.sort(dataMapKeys);
|
||||
for (final String dataKey : dataMapKeys) {
|
||||
text.append(ChatColor.BLUE).append(ChatColor.BOLD).append(index).append(ChatColor.RESET)
|
||||
.append(ChatColor.YELLOW).append(" - ").append(dataKey);
|
||||
if (dataMap.get(dataKey) != null) {
|
||||
text.append(ChatColor.GRAY).append(" (").append(ChatColor.AQUA)
|
||||
.append(ChatColor.translateAlternateColorCodes('&', dataMap.get(dataKey).toString()))
|
||||
.append(ChatColor.GRAY).append(")\n");
|
||||
} else {
|
||||
text.append(ChatColor.GRAY).append(" (").append(Lang.get("noneSet")).append(ChatColor.GRAY)
|
||||
.append(")\n");
|
||||
}
|
||||
index++;
|
||||
}
|
||||
text.append(ChatColor.GREEN).append(ChatColor.BOLD).append(index).append(ChatColor.YELLOW).append(" - ")
|
||||
.append(Lang.get("done"));
|
||||
}
|
||||
return text.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Prompt acceptInput(final ConversationContext context, final String input) {
|
||||
@SuppressWarnings("unchecked")
|
||||
final LinkedList<Map<String, Object>> dataMapList
|
||||
= (LinkedList<Map<String, Object>>) context.getSessionData(CK.REQ_CUSTOM_DATA);
|
||||
if (dataMapList != null) {
|
||||
final Map<String, Object> dataMap = dataMapList.getLast();
|
||||
final int numInput;
|
||||
try {
|
||||
numInput = Integer.parseInt(input);
|
||||
} catch (final NumberFormatException nfe) {
|
||||
return new RequirementCustomDataListPrompt();
|
||||
}
|
||||
if (numInput < 1 || numInput > dataMap.size() + 1) {
|
||||
return new RequirementCustomDataListPrompt();
|
||||
}
|
||||
if (numInput < dataMap.size() + 1) {
|
||||
final LinkedList<String> dataMapKeys = new LinkedList<>(dataMap.keySet());
|
||||
Collections.sort(dataMapKeys);
|
||||
final String selectedKey = dataMapKeys.get(numInput - 1);
|
||||
context.setSessionData(CK.REQ_CUSTOM_DATA_TEMP, selectedKey);
|
||||
return new RequirementCustomDataPrompt();
|
||||
if (isRequiredQuest) {
|
||||
context.setSessionData(CK.REQ_QUEST, null);
|
||||
} else {
|
||||
if (dataMap.containsValue(null)) {
|
||||
return new RequirementCustomDataListPrompt();
|
||||
} else {
|
||||
context.setSessionData(CK.REQ_CUSTOM_DATA_DESCRIPTIONS, null);
|
||||
}
|
||||
context.setSessionData(CK.REQ_QUEST_BLOCK, null);
|
||||
}
|
||||
}
|
||||
return new RequirementsPrompt(context);
|
||||
}
|
||||
}
|
||||
|
||||
private class RequirementCustomDataPrompt extends StringPrompt {
|
||||
|
||||
@Override
|
||||
public @NotNull String getPromptText(final ConversationContext context) {
|
||||
String text = "";
|
||||
final String temp = (String) context.getSessionData(CK.REQ_CUSTOM_DATA_TEMP);
|
||||
@SuppressWarnings("unchecked")
|
||||
final
|
||||
Map<String, String> descriptions
|
||||
= (Map<String, String>) context.getSessionData(CK.REQ_CUSTOM_DATA_DESCRIPTIONS);
|
||||
if (temp != null && descriptions != null) {
|
||||
if (descriptions.get(temp) != null) {
|
||||
text += ChatColor.GOLD + descriptions.get(temp) + "\n";
|
||||
}
|
||||
String lang = Lang.get("stageEditorCustomDataPrompt");
|
||||
lang = lang.replace("<data>", temp);
|
||||
text += ChatColor.YELLOW + lang;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Prompt acceptInput(final ConversationContext context, final String input) {
|
||||
@SuppressWarnings("unchecked")
|
||||
final
|
||||
LinkedList<Map<String, Object>> dataMapList
|
||||
= (LinkedList<Map<String, Object>>) context.getSessionData(CK.REQ_CUSTOM_DATA);
|
||||
if (dataMapList != null) {
|
||||
final Map<String, Object> dataMap = dataMapList.getLast();
|
||||
dataMap.put((String) context.getSessionData(CK.REQ_CUSTOM_DATA_TEMP), input);
|
||||
context.setSessionData(CK.REQ_CUSTOM_DATA_TEMP, null);
|
||||
}
|
||||
return new RequirementCustomDataListPrompt();
|
||||
}
|
||||
}
|
||||
|
||||
public class RequirementsMcMMOListPrompt extends QuestsEditorNumericPrompt {
|
||||
|
||||
public RequirementsMcMMOListPrompt(final ConversationContext context) {
|
||||
@ -1595,4 +1388,215 @@ public class RequirementsPrompt extends QuestsEditorNumericPrompt {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class CustomRequirementsPrompt extends QuestsEditorStringPrompt {
|
||||
|
||||
public CustomRequirementsPrompt(final ConversationContext context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle(final ConversationContext context) {
|
||||
return Lang.get("customRequirementsTitle");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQueryText(final ConversationContext context) {
|
||||
return Lang.get("reqCustomPrompt");
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
final StringBuilder text = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n");
|
||||
if (plugin.getCustomRequirements().isEmpty()) {
|
||||
text.append(ChatColor.DARK_AQUA).append(ChatColor.UNDERLINE)
|
||||
.append("https://pikamug.gitbook.io/quests/casual/modules\n").append(ChatColor.DARK_PURPLE)
|
||||
.append("(").append(Lang.get("stageEditorNoModules")).append(") ");
|
||||
} else {
|
||||
for (final CustomRequirement cr : plugin.getCustomRequirements()) {
|
||||
text.append(ChatColor.DARK_PURPLE).append(" - ").append(cr.getName()).append("\n");
|
||||
}
|
||||
}
|
||||
return text.toString() + ChatColor.YELLOW + getQueryText(context);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
|
||||
if (input == null) {
|
||||
return null;
|
||||
}
|
||||
if (!input.equalsIgnoreCase(Lang.get("cmdCancel")) && !input.equalsIgnoreCase(Lang.get("cmdClear"))) {
|
||||
CustomRequirement found = null;
|
||||
// Check if we have a custom requirement with the specified name
|
||||
for (final CustomRequirement cr : plugin.getCustomRequirements()) {
|
||||
if (cr.getName().equalsIgnoreCase(input)) {
|
||||
found = cr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found == null) {
|
||||
// No? Check again, but with locale sensitivity
|
||||
for (final CustomRequirement cr : plugin.getCustomRequirements()) {
|
||||
if (cr.getName().toLowerCase().contains(input.toLowerCase())) {
|
||||
found = cr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found != null) {
|
||||
if (context.getSessionData(CK.REQ_CUSTOM) != null) {
|
||||
// The custom requirement may already have been added, so let's check that
|
||||
final LinkedList<String> list = (LinkedList<String>) context.getSessionData(CK.REQ_CUSTOM);
|
||||
final LinkedList<Map<String, Object>> dataMapList
|
||||
= (LinkedList<Map<String, Object>>) context.getSessionData(CK.REQ_CUSTOM_DATA);
|
||||
if (dataMapList != null && list != null && !list.contains(found.getName())) {
|
||||
// Hasn't been added yet, so let's do it
|
||||
list.add(found.getName());
|
||||
dataMapList.add(found.getData());
|
||||
context.setSessionData(CK.REQ_CUSTOM, list);
|
||||
context.setSessionData(CK.REQ_CUSTOM_DATA, dataMapList);
|
||||
} else {
|
||||
// Already added, so inform user
|
||||
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("reqCustomAlreadyAdded"));
|
||||
return new CustomRequirementsPrompt(context);
|
||||
}
|
||||
} else {
|
||||
// The custom requirement hasn't been added yet, so let's do it
|
||||
final LinkedList<Map<String, Object>> dataMapList = new LinkedList<>();
|
||||
dataMapList.add(found.getData());
|
||||
final LinkedList<String> list = new LinkedList<>();
|
||||
list.add(found.getName());
|
||||
context.setSessionData(CK.REQ_CUSTOM, list);
|
||||
context.setSessionData(CK.REQ_CUSTOM_DATA, dataMapList);
|
||||
}
|
||||
// Send user to the custom data prompt if there is any needed
|
||||
if (!found.getData().isEmpty()) {
|
||||
context.setSessionData(CK.REQ_CUSTOM_DATA_DESCRIPTIONS, found.getDescriptions());
|
||||
return new RequirementCustomDataListPrompt();
|
||||
}
|
||||
} else {
|
||||
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("reqCustomNotFound"));
|
||||
return new CustomRequirementsPrompt(context);
|
||||
}
|
||||
} else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) {
|
||||
context.setSessionData(CK.REQ_CUSTOM, null);
|
||||
context.setSessionData(CK.REQ_CUSTOM_DATA, null);
|
||||
context.setSessionData(CK.REQ_CUSTOM_DATA_TEMP, null);
|
||||
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("reqCustomCleared"));
|
||||
}
|
||||
return new RequirementsPrompt(context);
|
||||
}
|
||||
}
|
||||
|
||||
private class RequirementCustomDataListPrompt extends StringPrompt {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public @NotNull String getPromptText(final ConversationContext context) {
|
||||
final StringBuilder text = new StringBuilder(ChatColor.GOLD + "- ");
|
||||
final LinkedList<String> list = (LinkedList<String>) context.getSessionData(CK.REQ_CUSTOM);
|
||||
final LinkedList<Map<String, Object>> dataMapList
|
||||
= (LinkedList<Map<String, Object>>) context.getSessionData(CK.REQ_CUSTOM_DATA);
|
||||
if (dataMapList != null && list != null) {
|
||||
final String reqName = list.getLast();
|
||||
final Map<String, Object> dataMap = dataMapList.getLast();
|
||||
text.append(reqName).append(" -\n");
|
||||
int index = 1;
|
||||
final LinkedList<String> dataMapKeys = new LinkedList<>(dataMap.keySet());
|
||||
Collections.sort(dataMapKeys);
|
||||
for (final String dataKey : dataMapKeys) {
|
||||
text.append(ChatColor.BLUE).append(ChatColor.BOLD).append(index).append(ChatColor.RESET)
|
||||
.append(ChatColor.YELLOW).append(" - ").append(dataKey);
|
||||
if (dataMap.get(dataKey) != null) {
|
||||
text.append(ChatColor.GRAY).append(" (").append(ChatColor.AQUA)
|
||||
.append(ChatColor.translateAlternateColorCodes('&', dataMap.get(dataKey).toString()))
|
||||
.append(ChatColor.GRAY).append(")\n");
|
||||
} else {
|
||||
text.append(ChatColor.GRAY).append(" (").append(Lang.get("noneSet")).append(ChatColor.GRAY)
|
||||
.append(")\n");
|
||||
}
|
||||
index++;
|
||||
}
|
||||
text.append(ChatColor.GREEN).append(ChatColor.BOLD).append(index).append(ChatColor.YELLOW).append(" - ")
|
||||
.append(Lang.get("done"));
|
||||
}
|
||||
return text.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Prompt acceptInput(final ConversationContext context, final String input) {
|
||||
@SuppressWarnings("unchecked")
|
||||
final LinkedList<Map<String, Object>> dataMapList
|
||||
= (LinkedList<Map<String, Object>>) context.getSessionData(CK.REQ_CUSTOM_DATA);
|
||||
if (dataMapList != null) {
|
||||
final Map<String, Object> dataMap = dataMapList.getLast();
|
||||
final int numInput;
|
||||
try {
|
||||
numInput = Integer.parseInt(input);
|
||||
} catch (final NumberFormatException nfe) {
|
||||
return new RequirementCustomDataListPrompt();
|
||||
}
|
||||
if (numInput < 1 || numInput > dataMap.size() + 1) {
|
||||
return new RequirementCustomDataListPrompt();
|
||||
}
|
||||
if (numInput < dataMap.size() + 1) {
|
||||
final LinkedList<String> dataMapKeys = new LinkedList<>(dataMap.keySet());
|
||||
Collections.sort(dataMapKeys);
|
||||
final String selectedKey = dataMapKeys.get(numInput - 1);
|
||||
context.setSessionData(CK.REQ_CUSTOM_DATA_TEMP, selectedKey);
|
||||
return new RequirementCustomDataPrompt();
|
||||
} else {
|
||||
if (dataMap.containsValue(null)) {
|
||||
return new RequirementCustomDataListPrompt();
|
||||
} else {
|
||||
context.setSessionData(CK.REQ_CUSTOM_DATA_DESCRIPTIONS, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new RequirementsPrompt(context);
|
||||
}
|
||||
}
|
||||
|
||||
private class RequirementCustomDataPrompt extends StringPrompt {
|
||||
|
||||
@Override
|
||||
public @NotNull String getPromptText(final ConversationContext context) {
|
||||
String text = "";
|
||||
final String temp = (String) context.getSessionData(CK.REQ_CUSTOM_DATA_TEMP);
|
||||
@SuppressWarnings("unchecked")
|
||||
final
|
||||
Map<String, String> descriptions
|
||||
= (Map<String, String>) context.getSessionData(CK.REQ_CUSTOM_DATA_DESCRIPTIONS);
|
||||
if (temp != null && descriptions != null) {
|
||||
if (descriptions.get(temp) != null) {
|
||||
text += ChatColor.GOLD + descriptions.get(temp) + "\n";
|
||||
}
|
||||
String lang = Lang.get("stageEditorCustomDataPrompt");
|
||||
lang = lang.replace("<data>", temp);
|
||||
text += ChatColor.YELLOW + lang;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Prompt acceptInput(final ConversationContext context, final String input) {
|
||||
@SuppressWarnings("unchecked")
|
||||
final
|
||||
LinkedList<Map<String, Object>> dataMapList
|
||||
= (LinkedList<Map<String, Object>>) context.getSessionData(CK.REQ_CUSTOM_DATA);
|
||||
if (dataMapList != null) {
|
||||
final Map<String, Object> dataMap = dataMapList.getLast();
|
||||
dataMap.put((String) context.getSessionData(CK.REQ_CUSTOM_DATA_TEMP), input);
|
||||
context.setSessionData(CK.REQ_CUSTOM_DATA_TEMP, null);
|
||||
}
|
||||
return new RequirementCustomDataListPrompt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,9 @@ import org.bukkit.event.HandlerList;
|
||||
import me.blackvein.quests.Quests;
|
||||
import me.blackvein.quests.actions.ActionFactory;
|
||||
import me.blackvein.quests.events.QuestsEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Represents an Actions Editor-related event
|
||||
@ -31,14 +34,14 @@ public abstract class ActionsEditorEvent extends QuestsEvent {
|
||||
|
||||
public ActionsEditorEvent(final ConversationContext context, final Prompt prompt) {
|
||||
this.context = context;
|
||||
this.factory = ((Quests)context.getPlugin()).getActionFactory();
|
||||
this.factory = ((Quests) Objects.requireNonNull(context.getPlugin())).getActionFactory();
|
||||
this.prompt = prompt;
|
||||
}
|
||||
|
||||
public ActionsEditorEvent(final ConversationContext context, final Prompt prompt, final boolean async) {
|
||||
super(async);
|
||||
this.context = context;
|
||||
this.factory = ((Quests)context.getPlugin()).getActionFactory();
|
||||
this.factory = ((Quests) Objects.requireNonNull(context.getPlugin())).getActionFactory();
|
||||
this.prompt = prompt;
|
||||
}
|
||||
|
||||
@ -70,7 +73,7 @@ public abstract class ActionsEditorEvent extends QuestsEvent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ import org.bukkit.conversations.ConversationContext;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import me.blackvein.quests.convo.actions.ActionsEditorNumericPrompt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ActionsEditorPostOpenNumericPromptEvent extends ActionsEditorEvent {
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
@ -38,7 +39,7 @@ public class ActionsEditorPostOpenNumericPromptEvent extends ActionsEditorEvent
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ import org.bukkit.conversations.ConversationContext;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import me.blackvein.quests.convo.actions.ActionsEditorStringPrompt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ActionsEditorPostOpenStringPromptEvent extends ActionsEditorEvent {
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
@ -38,7 +39,7 @@ public class ActionsEditorPostOpenStringPromptEvent extends ActionsEditorEvent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user