mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-23 11:05:38 +01:00
Improve support for multiple custom objectives per stage
This commit is contained in:
parent
5f52a5b9d9
commit
666b9bd8bb
@ -166,22 +166,23 @@ public abstract class CustomObjective implements Listener {
|
||||
if (currentStage == null) {
|
||||
return null;
|
||||
}
|
||||
int index = -1;
|
||||
int tempIndex = 0;
|
||||
CustomObjective found = null;
|
||||
for (me.blackvein.quests.CustomObjective co : currentStage.customObjectives) {
|
||||
if (co.getName().equals(obj.getName())) {
|
||||
index = tempIndex;
|
||||
found = co;
|
||||
break;
|
||||
}
|
||||
tempIndex++;
|
||||
}
|
||||
if (index > -1) {
|
||||
if (found != null) {
|
||||
Map<String, Object> m = new HashMap<String, Object>();
|
||||
for (int i = index; i < index + data.size(); i++) {
|
||||
Entry<String, Object> e = currentStage.customObjectiveData.get(i);
|
||||
m.put(e.getKey(), e.getValue());
|
||||
for (Entry<String, Object> datamap : found.getData()) {
|
||||
for (Entry<String, Object> e : currentStage.customObjectiveData) {
|
||||
if (e.getKey().equals(datamap.getKey())) {
|
||||
m.put(e.getKey(), e.getValue());
|
||||
return m;
|
||||
}
|
||||
}
|
||||
}
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -763,7 +763,7 @@ public class QuestFactory implements ConversationAbandonedListener {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void saveQuest(ConversationContext cc, ConfigurationSection cs) {
|
||||
public void saveQuest(ConversationContext cc, ConfigurationSection cs) {
|
||||
String edit = null;
|
||||
if (cc.getSessionData(CK.ED_QUEST_EDIT) != null) {
|
||||
edit = (String) cc.getSessionData(CK.ED_QUEST_EDIT);
|
||||
@ -1301,9 +1301,20 @@ public class QuestFactory implements ConversationAbandonedListener {
|
||||
ConfigurationSection sec2 = sec.createSection("custom" + (index + 1));
|
||||
sec2.set("name", customObjs.get(index));
|
||||
sec2.set("count", customObjCounts.get(index));
|
||||
CustomObjective found = null;
|
||||
for (CustomObjective co : plugin.getCustomObjectives()) {
|
||||
if (co.getName().equals(customObjs.get(index))) {
|
||||
found = co;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ConfigurationSection sec3 = sec2.createSection("data");
|
||||
for (Entry<String, Object> e : customObjsData) {
|
||||
sec3.set(e.getKey(), e.getValue()); // if anything goes wrong it's probably here
|
||||
for (Entry<String, Object> datamap : found.getData()) {
|
||||
for (Entry<String, Object> e : customObjsData) {
|
||||
if (e.getKey().equals(datamap.getKey())) {
|
||||
sec3.set(e.getKey(), e.getValue()); // if anything goes wrong it's probably here
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1666,8 +1677,8 @@ public class QuestFactory implements ConversationAbandonedListener {
|
||||
for (int i = 0; i < stage.customObjectives.size(); i++) {
|
||||
list.add(stage.customObjectives.get(i).getName());
|
||||
countList.add(stage.customObjectiveCounts.get(i));
|
||||
datamapList.add(stage.customObjectiveData.get(i));
|
||||
}
|
||||
datamapList.addAll(stage.customObjectiveData);
|
||||
cc.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES, list);
|
||||
cc.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_COUNT, countList);
|
||||
cc.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA, datamapList);
|
||||
|
@ -1701,7 +1701,8 @@ public class Quester {
|
||||
break;
|
||||
}
|
||||
}
|
||||
List<Entry<String, Object>> sub = getCurrentStage(quest).customObjectiveData.subList(index, getCurrentStage(quest).customObjectiveData.size());
|
||||
List<Entry<String, Object>> sub = new LinkedList<>();
|
||||
sub.addAll(getCurrentStage(quest).customObjectiveData.subList(index, getCurrentStage(quest).customObjectiveData.size()));
|
||||
List<Entry<String, Object>> end = new LinkedList<Entry<String, Object>>(sub);
|
||||
sub.clear(); // since sub is backed by end, this removes all sub-list items from end
|
||||
for (Entry<String, Object> datamap : end) {
|
||||
|
@ -1135,42 +1135,45 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
for (CustomObjective co : stage.customObjectives) {
|
||||
int countsIndex = 0;
|
||||
String display = co.getDisplay();
|
||||
boolean addUnfinished = false;
|
||||
boolean addFinished = false;
|
||||
List<String> unfinished = new LinkedList<String>();
|
||||
List<String> finished = new LinkedList<String>();
|
||||
for (Entry<String, Integer> entry : data.customObjectiveCounts.entrySet()) {
|
||||
if (co.getName().equals(entry.getKey())) {
|
||||
int dataIndex = 0;
|
||||
for (Entry<String,Object> prompt : co.getData()) {
|
||||
String replacement = "%" + prompt.getKey() + "%";
|
||||
try {
|
||||
if (display.contains(replacement))
|
||||
display = display.replace(replacement, ((String) stage.customObjectiveData.get(dataIndex).getValue()));
|
||||
for (Entry<String, Object> e : stage.customObjectiveData) {
|
||||
if (e.getKey().equals(prompt.getKey())) {
|
||||
if (display.contains(replacement)) {
|
||||
display = display.replace(replacement, ((String) e.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (NullPointerException ne) {
|
||||
getLogger().severe("Unable to fetch display for " + co.getName() + " on " + quest.getName());
|
||||
ne.printStackTrace();
|
||||
}
|
||||
dataIndex++;
|
||||
}
|
||||
if (entry.getValue() < stage.customObjectiveCounts.get(countsIndex)) {
|
||||
if (co.canShowCount()) {
|
||||
display = display.replace("%count%", entry.getValue() + "/" + stage.customObjectiveCounts.get(countsIndex));
|
||||
}
|
||||
addUnfinished = true;
|
||||
unfinished.add(display);
|
||||
} else {
|
||||
if (co.canShowCount()) {
|
||||
display = display.replace("%count%", stage.customObjectiveCounts.get(countsIndex)
|
||||
+ "/" + stage.customObjectiveCounts.get(countsIndex));
|
||||
}
|
||||
addFinished = true;
|
||||
finished.add(display);
|
||||
}
|
||||
}
|
||||
countsIndex++;
|
||||
}
|
||||
if (addUnfinished) {
|
||||
quester.getPlayer().sendMessage(ChatColor.GREEN + display);
|
||||
for (String s : unfinished) {
|
||||
quester.getPlayer().sendMessage(ChatColor.GREEN + s);
|
||||
}
|
||||
if (addFinished) {
|
||||
quester.getPlayer().sendMessage(ChatColor.GRAY + display);
|
||||
for (String s : finished) {
|
||||
quester.getPlayer().sendMessage(ChatColor.GRAY + s);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2493,10 +2496,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
return;
|
||||
}
|
||||
Stage oStage = quest.getStage(Integer.valueOf(s2) - 1);
|
||||
oStage.customObjectives=new LinkedList<>();
|
||||
oStage.customObjectiveCounts=new LinkedList<>();
|
||||
oStage.customObjectiveData=new LinkedList<>();
|
||||
oStage.customObjectiveDisplays=new LinkedList<>();
|
||||
oStage.customObjectives = new LinkedList<>();
|
||||
oStage.customObjectiveCounts = new LinkedList<>();
|
||||
oStage.customObjectiveData = new LinkedList<>();
|
||||
oStage.customObjectiveDisplays = new LinkedList<>();
|
||||
if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".custom-objectives")) {
|
||||
ConfigurationSection sec = config.getConfigurationSection("quests." + questKey + ".stages.ordered." + s2 + ".custom-objectives");
|
||||
for (String path : sec.getKeys(false)) {
|
||||
@ -2515,11 +2518,11 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
} else {
|
||||
ConfigurationSection sec2 = sec.getConfigurationSection(path + ".data");
|
||||
oStage.customObjectives.add(found.get());
|
||||
if (count <= 0) {
|
||||
oStage.customObjectiveCounts.add(0);
|
||||
} else {
|
||||
oStage.customObjectiveCounts.add(count);
|
||||
}
|
||||
if (count <= 0) {
|
||||
oStage.customObjectiveCounts.add(0);
|
||||
} else {
|
||||
oStage.customObjectiveCounts.add(count);
|
||||
}
|
||||
for (Entry<String,Object> prompt : found.get().getData()) {
|
||||
Entry<String, Object> data = populateCustoms(sec2, prompt);
|
||||
oStage.customObjectiveData.add(data);
|
||||
|
@ -1418,22 +1418,32 @@ public class CreateStagePrompt extends FixedSetPrompt {
|
||||
String text = ChatColor.BOLD + "" + ChatColor.AQUA + "- ";
|
||||
LinkedList<String> list = (LinkedList<String>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES);
|
||||
LinkedList<Entry<String, Object>> datamapList = (LinkedList<Entry<String, Object>>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA);
|
||||
|
||||
String objName = list.getLast();
|
||||
CustomObjective found = null;
|
||||
for (CustomObjective co : plugin.getCustomObjectives()) {
|
||||
if (co.getName().equals(objName)) {
|
||||
found = co;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found == null) {
|
||||
return "ERROR";
|
||||
}
|
||||
text += objName + " -\n";
|
||||
int index = 1;
|
||||
|
||||
for (Entry<String, Object> datamap : datamapList) {
|
||||
text += ChatColor.BOLD + "" + ChatColor.DARK_BLUE + index + " - " + ChatColor.RESET + ChatColor.BLUE + datamap.getKey();
|
||||
if (datamap.getValue() != null) {
|
||||
text += ChatColor.GREEN + " (" + datamap.getValue().toString() + ")\n";
|
||||
for (Entry<String, Object> datamap : found.getData()) {
|
||||
for (Entry<String, Object> currentData : datamapList) {
|
||||
if (currentData.getKey().equals(datamap.getKey())) {
|
||||
text += ChatColor.BOLD + "" + ChatColor.DARK_BLUE + index + " - " + ChatColor.RESET + ChatColor.BLUE + datamap.getKey();
|
||||
if (currentData.getValue() != null) {
|
||||
text += ChatColor.GREEN + " (" + currentData.getValue().toString() + ")\n";
|
||||
} else {
|
||||
text += ChatColor.RED + " (" + Lang.get("valRequired") + ")\n";
|
||||
}
|
||||
index++;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
text += ChatColor.BOLD + "" + ChatColor.DARK_BLUE + index + " - " + ChatColor.AQUA + Lang.get("finish");
|
||||
return text;
|
||||
}
|
||||
@ -1441,7 +1451,23 @@ public class CreateStagePrompt extends FixedSetPrompt {
|
||||
@Override
|
||||
public Prompt acceptInput(ConversationContext context, String input) {
|
||||
@SuppressWarnings("unchecked")
|
||||
LinkedList<Entry<String, Object>> datamapList = (LinkedList<Entry<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<String> list = (LinkedList<String>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES);
|
||||
String objName = list.getLast();
|
||||
CustomObjective found = null;
|
||||
for (CustomObjective co : plugin.getCustomObjectives()) {
|
||||
if (co.getName().equals(objName)) {
|
||||
found = co;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found == null) {
|
||||
plugin.getLogger().severe("ERROR");
|
||||
return new ObjectiveCustomDataListPrompt();
|
||||
}
|
||||
LinkedList<Entry<String, Object>> datamapList = found.getData();
|
||||
|
||||
int numInput;
|
||||
try {
|
||||
@ -1496,14 +1522,12 @@ public class CreateStagePrompt extends FixedSetPrompt {
|
||||
LinkedList<Entry<String, Object>> datamapList = (LinkedList<Entry<String, Object>>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA);
|
||||
LinkedList<Entry<String, Object>> promptList = new LinkedList<Entry<String, Object>>();
|
||||
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()));
|
||||
}
|
||||
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user