mirror of
https://github.com/PikaMug/Quests.git
synced 2025-01-30 20:21:45 +01:00
parent
570d589f3f
commit
159af2ab97
@ -12,8 +12,11 @@
|
|||||||
|
|
||||||
package me.blackvein.quests;
|
package me.blackvein.quests;
|
||||||
|
|
||||||
|
import java.util.AbstractMap;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@ -23,10 +26,10 @@ public abstract class CustomObjective implements Listener {
|
|||||||
private Quests plugin = Quests.getPlugin(Quests.class);
|
private Quests plugin = Quests.getPlugin(Quests.class);
|
||||||
private String name = null;
|
private String name = null;
|
||||||
private String author = null;
|
private String author = null;
|
||||||
private Map<String, Object> data = new HashMap<String, Object>();
|
private LinkedList<Entry<String, Object>> data = new LinkedList<Entry<String, Object>>();
|
||||||
private Map<String, String> descriptions = new HashMap<String, String>();
|
private Map<String, String> descriptions = new HashMap<String, String>();
|
||||||
private String countPrompt = "Enter number";
|
private String countPrompt = "Enter number";
|
||||||
private String display = "%data%: %count%";
|
private String display = "Progress: %count%";
|
||||||
private boolean showCount = true;
|
private boolean showCount = true;
|
||||||
private int count = 1;
|
private int count = 1;
|
||||||
|
|
||||||
@ -46,7 +49,7 @@ public abstract class CustomObjective implements Listener {
|
|||||||
this.author = author;
|
this.author = author;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Object> getData() {
|
public LinkedList<Entry<String, Object>> getData() {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,8 +63,9 @@ public abstract class CustomObjective implements Listener {
|
|||||||
* @param defaultValue Value to be used if input is not received
|
* @param defaultValue Value to be used if input is not received
|
||||||
*/
|
*/
|
||||||
public void addStringPrompt(String title, String description, Object defaultValue) {
|
public void addStringPrompt(String title, String description, Object defaultValue) {
|
||||||
data.put(name, defaultValue);
|
Entry<String, Object> prompt = new AbstractMap.SimpleEntry<String, Object>(title, defaultValue);
|
||||||
descriptions.put(name, description);
|
data.add(prompt);
|
||||||
|
descriptions.put(title, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,7 +75,8 @@ public abstract class CustomObjective implements Listener {
|
|||||||
* @deprecated use addPrompt(name, description)
|
* @deprecated use addPrompt(name, description)
|
||||||
*/
|
*/
|
||||||
public void addData(String name) {
|
public void addData(String name) {
|
||||||
data.put(name, null);
|
Entry<String, Object> prompt = new AbstractMap.SimpleEntry<String, Object>(name, null);
|
||||||
|
data.add(prompt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String> getDescriptions() {
|
public Map<String, String> getDescriptions() {
|
||||||
@ -158,8 +163,9 @@ public abstract class CustomObjective implements Listener {
|
|||||||
Quester quester = plugin.getQuester(player.getUniqueId());
|
Quester quester = plugin.getQuester(player.getUniqueId());
|
||||||
if (quester != null) {
|
if (quester != null) {
|
||||||
Stage currentStage = quester.getCurrentStage(quest);
|
Stage currentStage = quester.getCurrentStage(quest);
|
||||||
if (currentStage == null)
|
if (currentStage == null) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
int index = -1;
|
int index = -1;
|
||||||
int tempIndex = 0;
|
int tempIndex = 0;
|
||||||
for (me.blackvein.quests.CustomObjective co : currentStage.customObjectives) {
|
for (me.blackvein.quests.CustomObjective co : currentStage.customObjectives) {
|
||||||
@ -170,7 +176,10 @@ public abstract class CustomObjective implements Listener {
|
|||||||
tempIndex++;
|
tempIndex++;
|
||||||
}
|
}
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
return currentStage.customObjectiveData.get(index);
|
Entry<String, Object> e = currentStage.customObjectiveData.get(index);
|
||||||
|
Map<String, Object> m = new HashMap<String, Object>();
|
||||||
|
m.put(e.getKey(), e.getValue());
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -209,51 +218,4 @@ public abstract class CustomObjective implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (o instanceof CustomObjective) {
|
|
||||||
CustomObjective other = (CustomObjective) o;
|
|
||||||
if (other.name.equals(name) == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (other.author.equals(name) == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for (String s : other.getData().keySet()) {
|
|
||||||
if (getData().containsKey(s) == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (Object val : other.getData().values()) {
|
|
||||||
if (getData().containsValue(val) == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (String s : other.descriptions.keySet()) {
|
|
||||||
if (descriptions.containsKey(s) == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (String s : other.descriptions.values()) {
|
|
||||||
if (descriptions.containsValue(s) == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (other.countPrompt.equals(countPrompt) == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (other.display.equals(display) == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (other.showCount != showCount) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (other.count != count) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -56,8 +56,8 @@ public abstract class CustomRequirement {
|
|||||||
* @param defaultValue Value to be used if input is not received
|
* @param defaultValue Value to be used if input is not received
|
||||||
*/
|
*/
|
||||||
public void addStringPrompt(String title, String description, Object defaultValue) {
|
public void addStringPrompt(String title, String description, Object defaultValue) {
|
||||||
data.put(name, defaultValue);
|
data.put(title, defaultValue);
|
||||||
descriptions.put(name, description);
|
descriptions.put(title, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,8 +57,8 @@ public abstract class CustomReward {
|
|||||||
* @param defaultValue Value to be used if input is not received
|
* @param defaultValue Value to be used if input is not received
|
||||||
*/
|
*/
|
||||||
public void addStringPrompt(String title, String description, Object defaultValue) {
|
public void addStringPrompt(String title, String description, Object defaultValue) {
|
||||||
data.put(name, defaultValue);
|
data.put(title, defaultValue);
|
||||||
descriptions.put(name, description);
|
descriptions.put(title, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -999,7 +999,7 @@ public class QuestFactory implements ConversationAbandonedListener {
|
|||||||
LinkedList<LinkedList<String>> passPhrases;
|
LinkedList<LinkedList<String>> passPhrases;
|
||||||
LinkedList<String> customObjs;
|
LinkedList<String> customObjs;
|
||||||
LinkedList<Integer> customObjCounts;
|
LinkedList<Integer> customObjCounts;
|
||||||
LinkedList<Map<String, Object>> customObjsData;
|
LinkedList<Entry<String, Object>> customObjsData;
|
||||||
String script;
|
String script;
|
||||||
String startEvent;
|
String startEvent;
|
||||||
String finishEvent;
|
String finishEvent;
|
||||||
@ -1151,7 +1151,7 @@ public class QuestFactory implements ConversationAbandonedListener {
|
|||||||
if (cc.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES) != null) {
|
if (cc.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES) != null) {
|
||||||
customObjs = (LinkedList<String>) cc.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES);
|
customObjs = (LinkedList<String>) cc.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES);
|
||||||
customObjCounts = (LinkedList<Integer>) cc.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_COUNT);
|
customObjCounts = (LinkedList<Integer>) cc.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_COUNT);
|
||||||
customObjsData = (LinkedList<Map<String, Object>>) cc.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA);
|
customObjsData = (LinkedList<Entry<String, Object>>) cc.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA);
|
||||||
}
|
}
|
||||||
if (cc.getSessionData(pref + CK.S_START_EVENT) != null) {
|
if (cc.getSessionData(pref + CK.S_START_EVENT) != null) {
|
||||||
startEvent = (String) cc.getSessionData(pref + CK.S_START_EVENT);
|
startEvent = (String) cc.getSessionData(pref + CK.S_START_EVENT);
|
||||||
@ -1267,8 +1267,9 @@ public class QuestFactory implements ConversationAbandonedListener {
|
|||||||
ConfigurationSection sec2 = sec.createSection("custom" + (index + 1));
|
ConfigurationSection sec2 = sec.createSection("custom" + (index + 1));
|
||||||
sec2.set("name", customObjs.get(index));
|
sec2.set("name", customObjs.get(index));
|
||||||
sec2.set("count", customObjCounts.get(index));
|
sec2.set("count", customObjCounts.get(index));
|
||||||
if (customObjsData.get(index).isEmpty() == false) {
|
ConfigurationSection sec3 = sec2.createSection("data");
|
||||||
sec2.set("data", customObjsData.get(index));
|
for (Entry<String, Object> e : customObjsData) {
|
||||||
|
sec3.set(e.getKey(), e.getValue()); // if anything goes wrong it's probably here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1620,7 +1621,7 @@ public class QuestFactory implements ConversationAbandonedListener {
|
|||||||
if (stage.customObjectives.isEmpty() == false) {
|
if (stage.customObjectives.isEmpty() == false) {
|
||||||
LinkedList<String> list = new LinkedList<String>();
|
LinkedList<String> list = new LinkedList<String>();
|
||||||
LinkedList<Integer> countList = new LinkedList<Integer>();
|
LinkedList<Integer> countList = new LinkedList<Integer>();
|
||||||
LinkedList<Map<String, Object>> datamapList = new LinkedList<Map<String, Object>>();
|
LinkedList<Entry<String, Object>> datamapList = new LinkedList<Entry<String, Object>>();
|
||||||
for (int i = 0; i < stage.customObjectives.size(); i++) {
|
for (int i = 0; i < stage.customObjectives.size(); i++) {
|
||||||
list.add(stage.customObjectives.get(i).getName());
|
list.add(stage.customObjectives.get(i).getName());
|
||||||
countList.add(stage.customObjectiveCounts.get(i));
|
countList.add(stage.customObjectiveCounts.get(i));
|
||||||
|
@ -786,10 +786,10 @@ public class Quester {
|
|||||||
for (Entry<String, Integer> entry : getQuestData(quest).customObjectiveCounts.entrySet()) {
|
for (Entry<String, Integer> entry : getQuestData(quest).customObjectiveCounts.entrySet()) {
|
||||||
if (co.getName().equals(entry.getKey())) {
|
if (co.getName().equals(entry.getKey())) {
|
||||||
String display = co.getDisplay();
|
String display = co.getDisplay();
|
||||||
Map<String, Object> datamap = getCurrentStage(quest).customObjectiveData.get(index);
|
Entry<String, Object> datamap = getCurrentStage(quest).customObjectiveData.get(index);
|
||||||
for (String key : co.getData().keySet()) {
|
for (Entry<String,Object> prompt : co.getData()) {
|
||||||
try {
|
try {
|
||||||
display = display.replace("%" + key + "%", ((String) datamap.get(key)));
|
display = display.replace("%" + prompt.getKey() + "%", ((String) datamap.getValue()));
|
||||||
} catch (NullPointerException ne) {
|
} catch (NullPointerException ne) {
|
||||||
plugin.getLogger().severe("Unable to fetch display for " + co.getName() + " on " + quest.getName());
|
plugin.getLogger().severe("Unable to fetch display for " + co.getName() + " on " + quest.getName());
|
||||||
ne.printStackTrace();
|
ne.printStackTrace();
|
||||||
@ -885,20 +885,27 @@ public class Quester {
|
|||||||
|
|
||||||
public boolean hasCustomObjective(Quest quest, String s) {
|
public boolean hasCustomObjective(Quest quest, String s) {
|
||||||
if (getQuestData(quest) == null) {
|
if (getQuestData(quest) == null) {
|
||||||
|
System.out.println("bing");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getQuestData(quest).customObjectiveCounts.containsKey(s)) {
|
if (getQuestData(quest).customObjectiveCounts.containsKey(s)) {
|
||||||
|
System.out.println("bang");
|
||||||
int count = getQuestData(quest).customObjectiveCounts.get(s);
|
int count = getQuestData(quest).customObjectiveCounts.get(s);
|
||||||
int index = -1;
|
int index = -1;
|
||||||
for (int i = 0; i < getCurrentStage(quest).customObjectives.size(); i++) {
|
for (int i = 0; i < getCurrentStage(quest).customObjectives.size(); i++) {
|
||||||
|
System.out.println("bong");
|
||||||
if (getCurrentStage(quest).customObjectives.get(i).getName().equals(s)) {
|
if (getCurrentStage(quest).customObjectives.get(i).getName().equals(s)) {
|
||||||
|
System.out.println("bung");
|
||||||
index = i;
|
index = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int count2 = getCurrentStage(quest).customObjectiveCounts.get(index);
|
int count2 = getCurrentStage(quest).customObjectiveCounts.get(index);
|
||||||
|
System.out.println("count= " + count);
|
||||||
|
System.out.println("count2= " + count2);
|
||||||
return count <= count2;
|
return count <= count2;
|
||||||
}
|
}
|
||||||
|
System.out.println("byng");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1550,10 +1557,9 @@ public class Quester {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Map<String, Object> datamap = getCurrentStage(quest).customObjectiveData.get(index);
|
Entry<String, Object> datamap = getCurrentStage(quest).customObjectiveData.get(index);
|
||||||
for (String key : co.getData().keySet()) {
|
message = message.replace("%" + ((String) datamap.getKey()) + "%", (String) datamap.getValue());
|
||||||
message = message.replace("%" + ((String) key) + "%", (String) datamap.get(key));
|
|
||||||
}
|
|
||||||
if (co.canShowCount()) {
|
if (co.canShowCount()) {
|
||||||
message = message.replace("%count%", getCurrentStage(quest).customObjectiveCounts.get(index) + "/" + getCurrentStage(quest).customObjectiveCounts.get(index));
|
message = message.replace("%count%", getCurrentStage(quest).customObjectiveCounts.get(index) + "/" + getCurrentStage(quest).customObjectiveCounts.get(index));
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import java.lang.reflect.Constructor;
|
|||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.AbstractMap;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.ConcurrentModificationException;
|
import java.util.ConcurrentModificationException;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
@ -487,7 +488,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
Quest quest = new Quest();
|
Quest quest = new Quest();
|
||||||
failedToLoad = false;
|
failedToLoad = false;
|
||||||
if (config.contains("quests." + questKey + ".name")) {
|
if (config.contains("quests." + questKey + ".name")) {
|
||||||
quest.setName(parseString(config.getString("quests." + questKey + ".name"), quest));
|
quest = getQuest(parseString(config.getString("quests." + questKey + ".name"), quest));
|
||||||
loadCustomSections(quest, config, questKey);
|
loadCustomSections(quest, config, questKey);
|
||||||
} else {
|
} else {
|
||||||
skipQuestProcess("Quest block \'" + questKey + "\' is missing " + ChatColor.RED + "name:");
|
skipQuestProcess("Quest block \'" + questKey + "\' is missing " + ChatColor.RED + "name:");
|
||||||
@ -1971,7 +1972,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
private void loadCustomSections(Quest quest, FileConfiguration config, String questKey) throws StageFailedException, SkipQuest {
|
private void loadCustomSections(Quest quest, FileConfiguration config, String questKey) throws StageFailedException, SkipQuest {
|
||||||
ConfigurationSection questStages = config.getConfigurationSection("quests." + questKey + ".stages.ordered");
|
ConfigurationSection questStages = config.getConfigurationSection("quests." + questKey + ".stages.ordered");
|
||||||
for (String s2 : questStages.getKeys(false)) {
|
for (String s2 : questStages.getKeys(false)) {
|
||||||
Stage oStage = new Stage();
|
Stage oStage = quest.getStage(Integer.valueOf(s2) - 1);
|
||||||
if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".custom-objectives")) {
|
if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".custom-objectives")) {
|
||||||
ConfigurationSection sec = config.getConfigurationSection("quests." + questKey + ".stages.ordered." + s2 + ".custom-objectives");
|
ConfigurationSection sec = config.getConfigurationSection("quests." + questKey + ".stages.ordered." + s2 + ".custom-objectives");
|
||||||
for (String path : sec.getKeys(false)) {
|
for (String path : sec.getKeys(false)) {
|
||||||
@ -1989,15 +1990,20 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
ConfigurationSection sec2 = sec.getConfigurationSection(path + ".data");
|
ConfigurationSection sec2 = sec.getConfigurationSection(path + ".data");
|
||||||
Map<String, Object> data = populateCustoms(sec2, found.get().getData()); // Added in Github PR #554
|
for (Entry<String,Object> prompt : found.get().getData()) {
|
||||||
|
Entry<String, Object> data = populateCustoms(sec2, prompt);
|
||||||
oStage.customObjectives.add(found.get());
|
oStage.customObjectives.add(found.get());
|
||||||
|
if (count <= 0) {
|
||||||
|
oStage.customObjectiveCounts.add(0);
|
||||||
|
} else {
|
||||||
oStage.customObjectiveCounts.add(count);
|
oStage.customObjectiveCounts.add(count);
|
||||||
|
}
|
||||||
oStage.customObjectiveData.add(data);
|
oStage.customObjectiveData.add(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Rewards rews = quest.getRewards();
|
Rewards rews = quest.getRewards();
|
||||||
if (config.contains("quests." + questKey + ".rewards.custom-rewards")) {
|
if (config.contains("quests." + questKey + ".rewards.custom-rewards")) {
|
||||||
ConfigurationSection sec = config.getConfigurationSection("quests." + questKey + ".rewards.custom-rewards");
|
ConfigurationSection sec = config.getConfigurationSection("quests." + questKey + ".rewards.custom-rewards");
|
||||||
@ -2049,10 +2055,9 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add possibilty to use fallbacks for customs.
|
* Add possibilty to use fallbacks for customs maps
|
||||||
* Avoid null objects in datamap by initialize the entry value with empty string if no fallback present.
|
* Avoid null objects in datamap by initialize the entry value with empty string if no fallback present.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static Map<String, Object> populateCustoms(ConfigurationSection sec2, Map<String, Object> datamap) {
|
static Map<String, Object> populateCustoms(ConfigurationSection sec2, Map<String, Object> datamap) {
|
||||||
Map<String,Object> data = new HashMap<String,Object>();
|
Map<String,Object> data = new HashMap<String,Object>();
|
||||||
if (sec2 != null) {
|
if (sec2 != null) {
|
||||||
@ -2063,6 +2068,20 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add possibilty to use fallbacks for customs entries
|
||||||
|
* Avoid null objects in datamap by initialize the entry value with empty string if no fallback present.
|
||||||
|
*/
|
||||||
|
static Entry<String, Object> populateCustoms(ConfigurationSection sec2, Entry<String, Object> datamap) {
|
||||||
|
String key = null;;
|
||||||
|
Object value = null;;
|
||||||
|
if (sec2 != null) {
|
||||||
|
key = datamap.getKey();
|
||||||
|
value = datamap.getValue();
|
||||||
|
}
|
||||||
|
return new AbstractMap.SimpleEntry<String, Object>(key, sec2.contains(key) ? sec2.get(key) : value != null ? value : new String());
|
||||||
|
}
|
||||||
|
|
||||||
private void stageFailed(String msg) throws StageFailedException {
|
private void stageFailed(String msg) throws StageFailedException {
|
||||||
stageFailed(new String[] { msg });
|
stageFailed(new String[] { msg });
|
||||||
}
|
}
|
||||||
|
@ -103,8 +103,7 @@ public class Requirements {
|
|||||||
public Map<String, Map<String, Object>> getCustomRequirements() {
|
public Map<String, Map<String, Object>> getCustomRequirements() {
|
||||||
return customRequirements;
|
return customRequirements;
|
||||||
}
|
}
|
||||||
protected void setCustomRequirements(
|
protected void setCustomRequirements(Map<String, Map<String, Object>> customRequirements) {
|
||||||
Map<String, Map<String, Object>> customRequirements) {
|
|
||||||
this.customRequirements = customRequirements;
|
this.customRequirements = customRequirements;
|
||||||
}
|
}
|
||||||
public String getFailRequirements() {
|
public String getFailRequirements() {
|
||||||
|
@ -16,6 +16,7 @@ import java.util.EnumMap;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.bukkit.DyeColor;
|
import org.bukkit.DyeColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -123,7 +124,7 @@ public class Stage {
|
|||||||
protected LinkedList<CustomObjective> customObjectives = new LinkedList<CustomObjective>();
|
protected LinkedList<CustomObjective> customObjectives = new LinkedList<CustomObjective>();
|
||||||
protected LinkedList<Integer> customObjectiveCounts = new LinkedList<Integer>();
|
protected LinkedList<Integer> customObjectiveCounts = new LinkedList<Integer>();
|
||||||
protected LinkedList<String> customObjectiveDisplays = new LinkedList<String>();
|
protected LinkedList<String> customObjectiveDisplays = new LinkedList<String>();
|
||||||
protected LinkedList<Map<String, Object>> customObjectiveData = new LinkedList<Map<String, Object>>();
|
protected LinkedList<Entry<String, Object>> customObjectiveData = new LinkedList<Entry<String, Object>>();
|
||||||
|
|
||||||
public LinkedList<ItemStack> getBlocksToBreak() {
|
public LinkedList<ItemStack> getBlocksToBreak() {
|
||||||
return blocksToBreak;
|
return blocksToBreak;
|
||||||
@ -450,7 +451,7 @@ public class Stage {
|
|||||||
return customObjectiveDisplays;
|
return customObjectiveDisplays;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LinkedList<Map<String, Object>> getCustomObjectiveData() {
|
public LinkedList<Entry<String, Object>> getCustomObjectiveData() {
|
||||||
return customObjectiveData;
|
return customObjectiveData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,12 +12,14 @@
|
|||||||
|
|
||||||
package me.blackvein.quests.prompts;
|
package me.blackvein.quests.prompts;
|
||||||
|
|
||||||
|
import java.util.AbstractMap;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -3868,12 +3870,12 @@ public class CreateStagePrompt extends FixedSetPrompt {
|
|||||||
if (context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES) != null) {
|
if (context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES) != null) {
|
||||||
// The custom objective may already have been added, so let's check that
|
// The custom objective may already have been added, so let's check that
|
||||||
LinkedList<String> list = (LinkedList<String>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES);
|
LinkedList<String> list = (LinkedList<String>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES);
|
||||||
LinkedList<Map<String, Object>> datamapList = (LinkedList<Map<String, Object>>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA);
|
LinkedList<Entry<String, Object>> datamapList = (LinkedList<Entry<String, Object>>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA);
|
||||||
LinkedList<Integer> countList = (LinkedList<Integer>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_COUNT);
|
LinkedList<Integer> countList = (LinkedList<Integer>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_COUNT);
|
||||||
if (list.contains(found.getName()) == false) {
|
if (list.contains(found.getName()) == false) {
|
||||||
// Hasn't been added yet, so let's do it
|
// Hasn't been added yet, so let's do it
|
||||||
list.add(found.getName());
|
list.add(found.getName());
|
||||||
datamapList.add(found.getData());
|
datamapList.addAll(found.getData());
|
||||||
countList.add(-999);
|
countList.add(-999);
|
||||||
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES, list);
|
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES, list);
|
||||||
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA, datamapList);
|
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA, datamapList);
|
||||||
@ -3884,9 +3886,9 @@ public class CreateStagePrompt extends FixedSetPrompt {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// The custom objective hasn't been added yet, so let's do it
|
// The custom objective hasn't been added yet, so let's do it
|
||||||
LinkedList<Map<String, Object>> datamapList = new LinkedList<Map<String, Object>>();
|
LinkedList<Entry<String, Object>> datamapList = new LinkedList<Entry<String, Object>>();
|
||||||
LinkedList<Integer> countList = new LinkedList<Integer>();
|
LinkedList<Integer> countList = new LinkedList<Integer>();
|
||||||
datamapList.add(found.getData());
|
datamapList.addAll(found.getData());
|
||||||
countList.add(-999);
|
countList.add(-999);
|
||||||
LinkedList<String> list = new LinkedList<String>();
|
LinkedList<String> list = new LinkedList<String>();
|
||||||
list.add(found.getName());
|
list.add(found.getName());
|
||||||
@ -3974,25 +3976,23 @@ public class CreateStagePrompt extends FixedSetPrompt {
|
|||||||
public String getPromptText(ConversationContext context) {
|
public String getPromptText(ConversationContext context) {
|
||||||
String text = ChatColor.BOLD + "" + ChatColor.AQUA + "- ";
|
String text = ChatColor.BOLD + "" + ChatColor.AQUA + "- ";
|
||||||
LinkedList<String> list = (LinkedList<String>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES);
|
LinkedList<String> list = (LinkedList<String>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES);
|
||||||
LinkedList<Map<String, Object>> datamapList = (LinkedList<Map<String, Object>>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA);
|
LinkedList<Entry<String, Object>> datamapList = (LinkedList<Entry<String, Object>>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA);
|
||||||
|
|
||||||
String objName = list.getLast();
|
String objName = list.getLast();
|
||||||
Map<String, Object> datamap = datamapList.getLast();
|
|
||||||
text += objName + " -\n";
|
text += objName + " -\n";
|
||||||
int index = 1;
|
int index = 1;
|
||||||
LinkedList<String> datamapKeys = new LinkedList<String>();
|
|
||||||
for (String key : datamap.keySet()) {
|
for (Entry<String, Object> datamap : datamapList) {
|
||||||
datamapKeys.add(key);
|
text += ChatColor.BOLD + "" + ChatColor.DARK_BLUE + index + " - " + ChatColor.RESET + ChatColor.BLUE + datamap.getKey();
|
||||||
}
|
if (datamap.getValue() != null) {
|
||||||
Collections.sort(datamapKeys);
|
text += ChatColor.GREEN + " (" + (String) datamap.getValue() + ")\n";
|
||||||
for (String dataKey : datamapKeys) {
|
|
||||||
text += ChatColor.BOLD + "" + ChatColor.DARK_BLUE + index + " - " + ChatColor.RESET + ChatColor.BLUE + dataKey;
|
|
||||||
if (datamap.get(dataKey) != null) {
|
|
||||||
text += ChatColor.GREEN + " (" + (String) datamap.get(dataKey) + ")\n";
|
|
||||||
} else {
|
} else {
|
||||||
text += ChatColor.RED + " (" + Lang.get("valRequired") + ")\n";
|
text += ChatColor.RED + " (" + Lang.get("valRequired") + ")\n";
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
text += ChatColor.BOLD + "" + ChatColor.DARK_BLUE + index + " - " + ChatColor.AQUA + Lang.get("finish");
|
text += ChatColor.BOLD + "" + ChatColor.DARK_BLUE + index + " - " + ChatColor.AQUA + Lang.get("finish");
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
@ -4000,36 +4000,37 @@ public class CreateStagePrompt extends FixedSetPrompt {
|
|||||||
@Override
|
@Override
|
||||||
public Prompt acceptInput(ConversationContext context, String input) {
|
public Prompt acceptInput(ConversationContext context, String input) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
LinkedList<Map<String, Object>> datamapList = (LinkedList<Map<String, Object>>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA);
|
LinkedList<Entry<String, Object>> datamapList = (LinkedList<Entry<String, Object>>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA);
|
||||||
Map<String, Object> datamap = datamapList.getLast();
|
|
||||||
int numInput;
|
int numInput;
|
||||||
try {
|
try {
|
||||||
numInput = Integer.parseInt(input);
|
numInput = Integer.parseInt(input);
|
||||||
} catch (NumberFormatException nfe) {
|
} catch (NumberFormatException nfe) {
|
||||||
return new ObjectiveCustomDataListPrompt();
|
return new ObjectiveCustomDataListPrompt();
|
||||||
}
|
}
|
||||||
if (numInput < 1 || numInput > datamap.size() + 1) {
|
if (numInput < 1 || numInput > datamapList.size() + 1) {
|
||||||
return new ObjectiveCustomDataListPrompt();
|
return new ObjectiveCustomDataListPrompt();
|
||||||
}
|
}
|
||||||
if (numInput < datamap.size() + 1) {
|
if (numInput < datamapList.size() + 1) {
|
||||||
LinkedList<String> datamapKeys = new LinkedList<String>();
|
LinkedList<String> datamapKeys = new LinkedList<String>();
|
||||||
for (String key : datamap.keySet()) {
|
for (Entry<String, Object> datamap : datamapList) {
|
||||||
datamapKeys.add(key);
|
datamapKeys.add(datamap.getKey());
|
||||||
}
|
}
|
||||||
Collections.sort(datamapKeys);
|
Collections.sort(datamapKeys);
|
||||||
String selectedKey = datamapKeys.get(numInput - 1);
|
String selectedKey = datamapKeys.get(numInput - 1);
|
||||||
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA_TEMP, selectedKey);
|
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA_TEMP, selectedKey);
|
||||||
return new ObjectiveCustomDataPrompt();
|
return new ObjectiveCustomDataPrompt();
|
||||||
} else {
|
} else {
|
||||||
if (datamap.containsValue(null)) {
|
for (Entry<String, Object> datamap : datamapList) {
|
||||||
|
if (datamap.getValue() == null) {
|
||||||
return new ObjectiveCustomDataListPrompt();
|
return new ObjectiveCustomDataListPrompt();
|
||||||
} else {
|
}
|
||||||
|
}
|
||||||
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA_DESCRIPTIONS, null);
|
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA_DESCRIPTIONS, null);
|
||||||
return new CreateStagePrompt(plugin, stageNum, questFactory, citizens);
|
return new CreateStagePrompt(plugin, stageNum, questFactory, citizens);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private class ObjectiveCustomDataPrompt extends StringPrompt {
|
private class ObjectiveCustomDataPrompt extends StringPrompt {
|
||||||
|
|
||||||
@ -4051,9 +4052,19 @@ public class CreateStagePrompt extends FixedSetPrompt {
|
|||||||
@Override
|
@Override
|
||||||
public Prompt acceptInput(ConversationContext context, String input) {
|
public Prompt acceptInput(ConversationContext context, String input) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
LinkedList<Map<String, Object>> datamapList = (LinkedList<Map<String, Object>>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA);
|
LinkedList<Entry<String, Object>> datamapList = (LinkedList<Entry<String, Object>>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA);
|
||||||
Map<String, Object> datamap = datamapList.getLast();
|
LinkedList<Entry<String, Object>> promptList = new LinkedList<Entry<String, Object>>();
|
||||||
datamap.put((String) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA_TEMP), input);
|
String temp = (String) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA_TEMP);
|
||||||
|
|
||||||
|
for (Entry<String, Object> datamap : datamapList) {
|
||||||
|
if (datamap.getKey().equals(temp)) {
|
||||||
|
promptList.add(new AbstractMap.SimpleEntry<String, Object>(datamap.getKey(), input));
|
||||||
|
} else {
|
||||||
|
promptList.add(new AbstractMap.SimpleEntry<String, Object>(datamap.getKey(), datamap.getValue()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA, promptList);
|
||||||
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA_TEMP, null);
|
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA_TEMP, null);
|
||||||
return new ObjectiveCustomDataListPrompt();
|
return new ObjectiveCustomDataListPrompt();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user