Completed Custom Objectives API

Updated version to 1.8.0
This commit is contained in:
Blackvein 2014-01-11 23:08:28 -08:00
parent 4a8a64b26b
commit c89e4c7459
13 changed files with 854 additions and 90 deletions

BIN
lib/CustomObjective.jar Normal file

Binary file not shown.

View File

@ -3,7 +3,7 @@
<groupId>me.blackvein.quests</groupId>
<artifactId>quests</artifactId>
<version>1.7.3-SNAPSHOT</version>
<version>1.8.0-SNAPSHOT</version>
<name>quests</name>
<url>http://dev.bukkit.org/server-mods/quests/</url>
<packaging>jar</packaging>

View File

@ -0,0 +1,221 @@
package me.blackvein.quests;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
public abstract class CustomObjective implements Listener {
private String name = null;
private String author = null;
public final Map<String,Object> datamap = new HashMap<String, Object>();
public final Map<String, String> descriptions = new HashMap<String, String>();
private String countPrompt = "null";
private String display = "null";
private boolean enableCount = true;
private boolean showCount = true;
private int count = 1;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public void addData(String name) {
datamap.put(name, null);
}
public void addDescription(String data, String description){
descriptions.put(data, description);
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public String getCountPrompt() {
return countPrompt;
}
public void setCountPrompt(String countPrompt) {
this.countPrompt = countPrompt;
}
public boolean isCountShown() {
return showCount;
}
public void setShowCount(boolean showCount) {
this.showCount = showCount;
}
public String getDisplay() {
return display;
}
public void setDisplay(String display) {
this.display = display;
}
public boolean isEnableCount() {
return enableCount;
}
public void setEnableCount(boolean enableCount) {
this.enableCount = enableCount;
}
public Map<String, Object> getDatamap(Player player, CustomObjective obj){
Quester quester = Quests.getInstance().getQuester(player.getName());
if(quester != null){
int index = -1;
int tempIndex = 0;
for(me.blackvein.quests.CustomObjective co : quester.currentStage.customObjectives){
if(co.getName().equals(obj.getName())){
index = tempIndex;
break;
}
tempIndex++;
}
if(index > -1){
return quester.currentStage.customObjectiveData.get(index);
}
}
return null;
}
public static void incrementObjective(Player player, CustomObjective obj, int count){
Quester quester = Quests.getInstance().getQuester(player.getName());
if(quester != null){
//Check if the player has Quest with objective
boolean hasQuest = false;
for(CustomObjective co : quester.currentStage.customObjectives){
if(co.getName().equals(obj.getName())){
hasQuest = true;
break;
}
}
if(hasQuest && quester.hasCustomObjective(obj.getName())){
if(quester.customObjectiveCounts.containsKey(obj.getName())){
int old = quester.customObjectiveCounts.get(obj.getName());
Quests.getInstance().getQuester(player.getName()).customObjectiveCounts.put(obj.getName(), old + count);
}else{
Quests.getInstance().getQuester(player.getName()).customObjectiveCounts.put(obj.getName(), count);
}
int index = -1;
for(int i = 0; i < quester.currentStage.customObjectives.size(); i++){
if(quester.currentStage.customObjectives.get(i).getName().equals(obj.getName())){
index = i;
break;
}
}
if(index > -1){
if(quester.customObjectiveCounts.get(obj.getName()) >= quester.currentStage.customObjectiveCounts.get(index)){
quester.finishObjective("customObj", null, null, null, null, null, null, null, null, obj);
}
}
}
}
}
@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.datamap.keySet()){
if(datamap.containsKey(s) == false)
return false;
}
for(Object val : other.datamap.values()){
if(datamap.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.enableCount != enableCount)
return false;
if(other.showCount != showCount)
return false;
if(other.count != count)
return false;
}
return true;
}
}

View File

@ -56,6 +56,16 @@ public class Quest {
String heroesSecondaryClassReq = null;
Map<String, Map<String, Object>> customRequirements = new HashMap<String, Map<String, Object>>();
Map<String, Map<String, Object>> customRewards = new HashMap<String, Map<String, Object>>();
/**
* Somehow I need to make customObjectives in the Stage class have the same
* sort of thing here ^ where it stores the custom data for the custom objective
* set by the questmaker.
*
*
*
*
*/
public String failRequirements = null;
//
//Rewards

View File

@ -860,7 +860,7 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil {
if (input.equalsIgnoreCase(Lang.get("cmdClear"))) {
context.setSessionData(CK.Q_REDO_DELAY, null);
}
long delay = -1;
long delay;
try {
delay = Long.parseLong(input);
} catch (NumberFormatException e) {
@ -1262,6 +1262,10 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil {
LinkedList<String> shearColors;
LinkedList<Integer> shearAmounts;
LinkedList<String> customObjs = null;
LinkedList<Integer> customObjCounts = null;
LinkedList<Map<String, Object>> customObjsData = null;
String script;
String startEvent;
String finishEvent;
@ -1418,6 +1422,12 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil {
shearAmounts = (LinkedList<Integer>) cc.getSessionData(pref + CK.S_SHEAR_AMOUNTS);
}
if (cc.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES) != null) {
customObjs = (LinkedList<String>) cc.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES);
customObjCounts = (LinkedList<Integer>) cc.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_COUNT);
customObjsData = (LinkedList<Map<String, Object>>) cc.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA);
}
if (cc.getSessionData(pref + CK.S_START_EVENT) != null) {
startEvent = (String) cc.getSessionData(pref + CK.S_START_EVENT);
}
@ -1512,6 +1522,20 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil {
stage.set("mob-tame-amounts", tameAmounts);
stage.set("sheep-to-shear", shearColors);
stage.set("sheep-amounts", shearAmounts);
if(customObjs != null && customObjs.isEmpty() == false){
ConfigurationSection sec = stage.createSection("custom-objectives");
for(int index = 0; index < customObjs.size(); index++){
ConfigurationSection sec2 = sec.createSection("custom" + (index + 1));
sec2.set("name", customObjs.get(index));
sec2.set("count", customObjCounts.get(index));
if(customObjsData.get(index).isEmpty() == false)
sec2.set("data", customObjsData.get(index));
}
}
stage.set("script-to-run", script);
stage.set("start-event", startEvent);
stage.set("finish-event", finishEvent);
@ -1936,6 +1960,26 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil {
cc.setSessionData(pref + CK.S_SHEAR_AMOUNTS, amnts);
}
if (stage.customObjectives.isEmpty() == false) {
LinkedList<String> list = new LinkedList<String>();
LinkedList<Integer> countList = new LinkedList<Integer>();
LinkedList<Map<String, Object>> datamapList = new LinkedList<Map<String, Object>>();
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));
}
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);
}
if (stage.startEvent != null) {
cc.setSessionData(pref + CK.S_START_EVENT, stage.startEvent.getName());

View File

@ -32,7 +32,7 @@ public class Quester {
boolean delayOver = true;
public Quest currentQuest;
public String questToTake;
Stage currentStage;
public Stage currentStage;
public int currentStageIndex = 0;
int questPoints = 0;
Quests plugin;
@ -64,6 +64,7 @@ public class Quester {
LinkedList<Integer> radiiToReachWithin = new LinkedList<Integer>();
Map<EntityType, Integer> mobsTamed = new EnumMap<EntityType, Integer>(EntityType.class);
Map<DyeColor, Integer> sheepSheared = new EnumMap<DyeColor, Integer>(DyeColor.class);
public Map<String, Integer> customObjectiveCounts = new HashMap<String, Integer>();
public Map<String, Boolean> eventFired = new HashMap<String, Boolean>();
final Random random = new Random();
@ -88,9 +89,9 @@ public class Quester {
currentQuest = q;
currentStage = q.orderedStages.getFirst();
addEmpties();
if(!override){
if (!override) {
if (q.moneyReq > 0) {
Quests.economy.withdrawPlayer(name, q.moneyReq);
}
@ -100,26 +101,26 @@ public class Quester {
Quests.removeItem(player.getInventory(), is);
}
}
player.sendMessage(ChatColor.GREEN + "Quest accepted: " + q.name);
player.sendMessage("");
}
player.sendMessage(ChatColor.GOLD + "---(Objectives)---");
for (String s : getObjectives()) {
player.sendMessage(s);
}
String stageStartMessage = currentStage.startMessage;
if (stageStartMessage != null) {
getPlayer().sendMessage(Quests.parseString(stageStartMessage, currentQuest));
}
if (stageStartMessage != null) {
getPlayer().sendMessage(Quests.parseString(stageStartMessage, currentQuest));
}
if(currentStage.chatEvents.isEmpty() == false){
if (currentStage.chatEvents.isEmpty() == false) {
for(String chatTrigger : currentStage.chatEvents.keySet()){
for (String chatTrigger : currentStage.chatEvents.keySet()) {
eventFired.put(chatTrigger, false);
@ -127,13 +128,15 @@ public class Quester {
}
if(q.initialEvent != null)
if (q.initialEvent != null) {
q.initialEvent.fire(this);
if(currentStage.startEvent != null)
}
if (currentStage.startEvent != null) {
currentStage.startEvent.fire(this);
}
saveData();
} else {
player.sendMessage(q.failRequirements);
@ -200,7 +203,7 @@ public class Quester {
if (e2.getValue() < e.getValue()) {
unfinishedObjectives.add(ChatColor.GREEN + "Place " + Quester.prettyItemString(e2.getKey().getId()) + ": " + e2.getValue() + "/" + e.getValue());
unfinishedObjectives.add(ChatColor.GREEN + "Place " + Quester.prettyItemString(e2.getKey().getId()) + ": " + e2.getValue() + "/" + e.getValue());
} else {
@ -397,7 +400,7 @@ public class Quester {
if (e.getKey().equals(n)) {
if ( e.getValue() == false) {
if (e.getValue() == false) {
unfinishedObjectives.add(ChatColor.GREEN + "Talk to " + plugin.getNPCName(n));
@ -417,7 +420,7 @@ public class Quester {
for (Integer n2 : citizensKilled) {
if(n.equals(n2)){
if (n.equals(n2)) {
if (citizenNumKilled.get(citizensKilled.indexOf(n2)) < currentStage.citizenNumToKill.get(currentStage.citizensToKill.indexOf(n))) {
@ -501,6 +504,41 @@ public class Quester {
}
int index = 0;
for (CustomObjective co : currentStage.customObjectives) {
for (Entry<String, Integer> entry : customObjectiveCounts.entrySet()) {
if (co.getName().equals(entry.getKey())) {
String display = co.getDisplay();
Map<String, Object> datamap = currentStage.customObjectiveData.get(index);
for(String key : co.datamap.keySet()){
display = display.replaceAll("%" + ((String) key) + "%", ((String) datamap.get(key)));
}
if (entry.getValue() < currentStage.customObjectiveCounts.get(index)){
if(co.isCountShown() && co.isEnableCount()){
display = display.replaceAll("%count%", entry.getValue() + "/" + currentStage.customObjectiveCounts.get(index));
}
unfinishedObjectives.add(ChatColor.GREEN + display);
}else{
if(co.isCountShown() && co.isEnableCount()){
display = display.replaceAll("%count%", currentStage.customObjectiveCounts.get(index) + "/" + currentStage.customObjectiveCounts.get(index));
}
finishedObjectives.add(ChatColor.GRAY + display);
}
}
}
index++;
}
objectives.addAll(unfinishedObjectives);
objectives.addAll(finishedObjectives);
@ -565,6 +603,30 @@ public class Quester {
}
}
public boolean hasCustomObjective(String s){
if(customObjectiveCounts.containsKey(s)){
int count = customObjectiveCounts.get(s);
int index = -1;
for(int i = 0; i < currentStage.customObjectives.size(); i++){
if(currentStage.customObjectives.get(i).getName().equals(s)){
index = i;
break;
}
}
int count2 = currentStage.customObjectiveCounts.get(index);
return count <= count2;
}
return false;
}
public void damageBlock(Material m) {
@ -575,7 +637,7 @@ public class Quester {
blocksDamaged.put(m, (i + 1));
if (blocksDamaged.get(m).equals(currentStage.blocksToDamage.get(m))) {
finishObjective("damageBlock", m, null, null, null, null, null, null, null);
finishObjective("damageBlock", m, null, null, null, null, null, null, null, null);
}
}
@ -593,7 +655,7 @@ public class Quester {
blocksBroken.put(m, (i + 1));
if (blocksBroken.get(m).equals(currentStage.blocksToBreak.get(m))) {
finishObjective("breakBlock", m, null, null, null, null, null, null, null);
finishObjective("breakBlock", m, null, null, null, null, null, null, null, null);
}
}
@ -610,7 +672,7 @@ public class Quester {
blocksPlaced.put(m, (i + 1));
if (blocksPlaced.get(m).equals(currentStage.blocksToPlace.get(m))) {
finishObjective("placeBlock", m, null, null, null, null, null, null, null);
finishObjective("placeBlock", m, null, null, null, null, null, null, null, null);
}
}
@ -627,7 +689,7 @@ public class Quester {
blocksUsed.put(m, (i + 1));
if (blocksUsed.get(m).equals(currentStage.blocksToUse.get(m))) {
finishObjective("useBlock", m, null, null, null, null, null, null, null);
finishObjective("useBlock", m, null, null, null, null, null, null, null, null);
}
}
@ -645,7 +707,7 @@ public class Quester {
blocksCut.put(m, (i + 1));
if (blocksCut.get(m).equals(currentStage.blocksToCut.get(m))) {
finishObjective("cutBlock", m, null, null, null, null, null, null, null);
finishObjective("cutBlock", m, null, null, null, null, null, null, null, null);
}
}
@ -660,7 +722,7 @@ public class Quester {
fishCaught++;
if (((Integer) fishCaught).equals(currentStage.fishToCatch)) {
finishObjective("catchFish", null, null, null, null, null, null, null, null);
finishObjective("catchFish", null, null, null, null, null, null, null, null, null);
}
}
@ -683,7 +745,7 @@ public class Quester {
itemsEnchanted.put(entry.getKey(), num);
if (num.equals(entry2.getValue())) {
finishObjective("enchantItem", m, null, e, null, null, null, null, null);
finishObjective("enchantItem", m, null, e, null, null, null, null, null, null);
}
}
@ -724,7 +786,7 @@ public class Quester {
mobNumKilled.set(index, numKilledInteger);
if ((numKilledInteger).equals(currentStage.mobNumToKill.get(index))) {
finishObjective("killMob", null, null, null, e, null, null, null, null);
finishObjective("killMob", null, null, null, e, null, null, null, null, null);
}
}
@ -742,7 +804,7 @@ public class Quester {
mobNumKilled.set(mobsKilled.indexOf(e), mobNumKilled.get(mobsKilled.indexOf(e)) + 1);
if ((mobNumKilled.get(mobsKilled.indexOf(e))).equals(currentStage.mobNumToKill.get(mobsKilled.indexOf(e)))) {
finishObjective("killMob", null, null, null, e, null, null, null, null);
finishObjective("killMob", null, null, null, e, null, null, null, null, null);
}
}
@ -776,7 +838,7 @@ public class Quester {
playersKilled++;
if (((Integer) playersKilled).equals(currentStage.playersToKill)) {
finishObjective("killPlayer", null, null, null, null, null, null, null, null);
finishObjective("killPlayer", null, null, null, null, null, null, null, null, null);
}
}
@ -789,7 +851,7 @@ public class Quester {
if (citizensInteracted.get(n.getId()) == false) {
citizensInteracted.put(n.getId(), true);
finishObjective("talkToNPC", null, null, null, null, null, n, null, null);
finishObjective("talkToNPC", null, null, null, null, null, n, null, null, null);
}
}
@ -804,7 +866,7 @@ public class Quester {
if (citizenNumKilled.get(index) < currentStage.citizenNumToKill.get(index)) {
citizenNumKilled.set(index, citizenNumKilled.get(index) + 1);
if (citizenNumKilled.get(index) == currentStage.citizenNumToKill.get(index)) {
finishObjective("killNPC", null, null, null, null, null, n, null, null);
finishObjective("killNPC", null, null, null, null, null, n, null, null, null);
}
}
@ -828,7 +890,7 @@ public class Quester {
if (hasReached.get(index) == false) {
hasReached.set(index, true);
finishObjective("reachLocation", null, null, null, null, null, null, location, null);
finishObjective("reachLocation", null, null, null, null, null, null, location, null, null);
}
@ -849,7 +911,7 @@ public class Quester {
mobsTamed.put(entity, (mobsTamed.get(entity) + 1));
if (mobsTamed.get(entity).equals(currentStage.mobsToTame.get(entity))) {
finishObjective("tameMob", null, null, null, entity, null, null, null, null);
finishObjective("tameMob", null, null, null, entity, null, null, null, null, null);
}
}
@ -863,7 +925,7 @@ public class Quester {
sheepSheared.put(color, (sheepSheared.get(color) + 1));
if (sheepSheared.get(color).equals(currentStage.sheepToShear.get(color))) {
finishObjective("shearSheep", null, null, null, null, null, null, null, color);
finishObjective("shearSheep", null, null, null, null, null, null, null, color, null);
}
}
@ -876,9 +938,9 @@ public class Quester {
ItemStack found = null;
for(ItemStack is : itemsDelivered.keySet()){
for (ItemStack is : itemsDelivered.keySet()) {
if(ItemUtil.compareItems(i, is, true) == 0){
if (ItemUtil.compareItems(i, is, true) == 0) {
found = is;
break;
}
@ -898,14 +960,14 @@ public class Quester {
i.setAmount(i.getAmount() - (req - amount)); //Take away the remaining amount needed to be delivered from the item stack
player.getInventory().setItem(index, i);
player.updateInventory();
finishObjective("deliverItem", null, found, null, null, null, null, null, null);
finishObjective("deliverItem", null, found, null, null, null, null, null, null, null);
} else if ((i.getAmount() + amount) == req) {
itemsDelivered.put(found, req);
player.getInventory().setItem(player.getInventory().first(i), null);
player.updateInventory();
finishObjective("deliverItem", null, found, null, null, null, null, null, null);
finishObjective("deliverItem", null, found, null, null, null, null, null, null, null);
} else {
@ -923,7 +985,7 @@ public class Quester {
}
public void finishObjective(String objective, Material material, ItemStack itemstack, Enchantment enchantment, EntityType mob, String player, NPC npc, Location location, DyeColor color) {
public void finishObjective(String objective, Material material, ItemStack itemstack, Enchantment enchantment, EntityType mob, String player, NPC npc, Location location, DyeColor color, CustomObjective co) {
Player p = plugin.getServer().getPlayerExact(name);
@ -1061,7 +1123,7 @@ public class Quester {
currentQuest.nextStage(this);
}
} else {
} else if (objective.equalsIgnoreCase("reachLocation")) {
String message = ChatColor.GREEN + "(Completed) Go to " + currentStage.locationNames.get(currentStage.locationsToReach.indexOf(location));
p.sendMessage(message);
@ -1069,6 +1131,30 @@ public class Quester {
currentQuest.nextStage(this);
}
} else if (co != null) {
String message = ChatColor.GREEN + "(Completed) " + co.getDisplay();
int index = -1;
for(int i = 0; i < currentStage.customObjectives.size(); i++){
if(currentStage.customObjectives.get(i).getName().equals(co.getName())){
index = i;
break;
}
}
Map<String, Object> datamap = currentStage.customObjectiveData.get(index);
for(String key : co.datamap.keySet()){
message = message.replaceAll("%" + ((String) key) + "%", (String) datamap.get(key));
}
if(co.isCountShown() && co.isEnableCount())
message = message.replaceAll("%count%", currentStage.customObjectiveCounts.get(index) + "/" + currentStage.customObjectiveCounts.get(index));
p.sendMessage(message);
if (testComplete()) {
currentQuest.nextStage(this);
}
}
}
@ -1214,6 +1300,12 @@ public class Quester {
}
}
if (currentStage.customObjectives.isEmpty() == false) {
for(CustomObjective co : currentStage.customObjectives){
customObjectiveCounts.put(co.getName(), 0);
}
}
}
@ -1240,6 +1332,7 @@ public class Quester {
radiiToReachWithin.clear();
mobsTamed.clear();
sheepSheared.clear();
customObjectiveCounts.clear();
}
@ -1532,7 +1625,6 @@ public class Quester {
return difference;
}
public FileConfiguration getBaseData() {
@ -1645,7 +1737,6 @@ public class Quester {
}
}
data.set("enchantments", enchantments);
@ -1819,27 +1910,45 @@ public class Quester {
data.set("sheep-sheared", shearAmounts);
}
if (customObjectiveCounts.isEmpty() == false){
LinkedList<String> customObj = new LinkedList<String>();
LinkedList<Integer> customObjCounts = new LinkedList<Integer>();
for(Entry<String, Integer> entry : customObjectiveCounts.entrySet()){
customObj.add(entry.getKey());
customObjCounts.add(entry.getValue());
}
data.set("custom-objectives", customObj);
data.set("custom-objective-counts", customObjCounts);
}
if (delayTimeLeft > 0) {
data.set("stage-delay", delayTimeLeft);
}
if(eventFired.isEmpty() == false){
if (eventFired.isEmpty() == false) {
LinkedList<String> triggers = new LinkedList<String>();
for(String trigger : eventFired.keySet()){
for (String trigger : eventFired.keySet()) {
if(eventFired.get(trigger) == true)
if (eventFired.get(trigger) == true) {
triggers.add(trigger);
}
}
if(triggers.isEmpty() == false)
if (triggers.isEmpty() == false) {
data.set("chat-triggers", triggers);
}
}
} else {
data.set("currentQuest", "none");
@ -1863,7 +1972,7 @@ public class Quester {
data.set("completed-Quests", completed);
}
if (completedTimes.isEmpty() == false) {
List<String> questTimeNames = new LinkedList<String>();
@ -1880,22 +1989,22 @@ public class Quester {
data.set("completedQuestTimes", questTimes);
}
if (amountsCompleted.isEmpty() == false) {
List<String> list1 = new LinkedList<String>();
List<Integer> list2 = new LinkedList<Integer>();
for(Entry<String, Integer> entry : amountsCompleted.entrySet()){
for (Entry<String, Integer> entry : amountsCompleted.entrySet()) {
list1.add(entry.getKey());
list2.add(entry.getValue());
}
data.set("amountsCompletedQuests", list1);
data.set("amountsCompleted", list2);
}
return data;
@ -1933,20 +2042,20 @@ public class Quester {
}
}
amountsCompleted.clear();
if (data.contains("amountsCompletedQuests")) {
List<String> list1 = data.getStringList("amountsCompletedQuests");
List<Integer> list2 = data.getIntegerList("amountsCompleted");
for(int i = 0; i < list1.size(); i++){
for (int i = 0; i < list1.size(); i++) {
amountsCompleted.put(list1.get(i), list2.get(i));
}
}
questPoints = data.getInt("quest-points");
@ -2000,10 +2109,10 @@ public class Quester {
}
if (stage == null) {
currentQuest = quest;
currentQuest.completeQuest(this);
Quests.log.log(Level.SEVERE, "[Quests] Invalid stage for player: \"" + name + "\". Quest ended.");
return true;
currentQuest = quest;
currentQuest.completeQuest(this);
Quests.log.log(Level.SEVERE, "[Quests] Invalid stage for player: \"" + name + "\". Quest ended.");
return true;
}
currentQuest = quest;
@ -2216,8 +2325,9 @@ public class Quester {
for (String s : data.getStringList("mobs-killed")) {
EntityType mob = Quests.getMobType(s);
if(mob != null)
if (mob != null) {
mobs.add(mob);
}
mobsKilled.clear();
mobNumKilled.clear();
@ -2454,6 +2564,17 @@ public class Quester {
}
}
if (data.contains("custom-objectives")){
List<String> customObj = data.getStringList("custom-objectives");
List<Integer> customObjCount = data.getIntegerList("custom-objective-counts");
for(int i = 0; i < customObj.size(); i++){
customObjectiveCounts.put(customObj.get(i), customObjCount.get(i));
}
}
if (data.contains("stage-delay")) {
@ -2461,9 +2582,9 @@ public class Quester {
}
if(currentStage.chatEvents.isEmpty() == false){
if (currentStage.chatEvents.isEmpty() == false) {
for(String trig : currentStage.chatEvents.keySet()){
for (String trig : currentStage.chatEvents.keySet()) {
eventFired.put(trig, false);
@ -2471,10 +2592,10 @@ public class Quester {
}
if(data.contains("chat-triggers")){
if (data.contains("chat-triggers")) {
List<String> triggers = data.getStringList("chat-triggers");
for(String s : triggers){
for (String s : triggers) {
eventFired.put(s, true);
@ -2494,8 +2615,9 @@ public class Quester {
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new StageTimer(plugin, this), (long) (delayTimeLeft * 0.02));
} else {
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new StageTimer(plugin, this), (long) (currentStage.delay * 0.02));
if (currentStage.delayMessage != null)
plugin.getServer().getPlayer(name).sendMessage(Quests.parseString((currentStage.delayMessage), currentQuest));
if (currentStage.delayMessage != null) {
plugin.getServer().getPlayer(name).sendMessage(Quests.parseString((currentStage.delayMessage), currentQuest));
}
}
delayStartTime = System.currentTimeMillis();
@ -2526,11 +2648,13 @@ public class Quester {
public boolean hasData() {
if(currentQuest != null || currentStage != null)
if (currentQuest != null || currentStage != null) {
return true;
}
if(questPoints > 1)
if (questPoints > 1) {
return true;
}
return completedQuests.isEmpty() == false;

View File

@ -115,6 +115,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
public final List<String> questerBlacklist = new LinkedList<String>();
public final List<CustomRequirement> customRequirements = new LinkedList<CustomRequirement>();
public final List<CustomReward> customRewards = new LinkedList<CustomReward>();
public final List<CustomObjective> customObjectives = new LinkedList<CustomObjective>();
public final LinkedList<Quest> quests = new LinkedList<Quest>();
public final LinkedList<Event> events = new LinkedList<Event>();
public final LinkedList<NPC> questNPCs = new LinkedList<NPC>();
@ -493,6 +494,16 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
String author = reward.getAuthor() == null ? "[Unknown]" : reward.getAuthor();
printInfo("[Quests] Loaded Module: " + name + " by " + author);
}else if(CustomObjective.class.isAssignableFrom(c)){
Class<? extends CustomObjective> objectiveClass = c.asSubclass(CustomObjective.class);
Constructor<? extends CustomObjective> cstrctr = objectiveClass.getConstructor();
CustomObjective objective = cstrctr.newInstance();
customObjectives.add(objective);
String name = objective.getName() == null ? "[" + jar.getName() + "]" : objective.getName();
String author = objective.getAuthor() == null ? "[Unknown]" : objective.getAuthor();
printInfo("[Quests] Loaded Module: " + name + " by " + author);
}else{
printSevere("[Quests] Error: Unable to load module from file: " + jar.getName() + ", jar file is not a valid module!");
}
@ -3257,6 +3268,55 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
}
if (config.contains("quests." + s + ".stages.ordered." + s2 + ".custom-objectives")) {
ConfigurationSection sec = config.getConfigurationSection("quests." + s + ".stages.ordered." + s2 + ".custom-objectives");
for (String path : sec.getKeys(false)) {
String name = sec.getString(path + ".name");
int count = sec.getInt(path + ".count");
CustomObjective found = null;
for (CustomObjective cr : customObjectives) {
if (cr.getName().equalsIgnoreCase(name)) {
found = cr;
break;
}
}
if (found == null) {
printWarning("[Quests] Custom objective \"" + name + "\" for Stage " + s2 + " of Quest \"" + quest.name + "\" could not be found!");
continue;
}
Map<String, Object> data = new HashMap<String, Object>();
ConfigurationSection sec2 = sec.getConfigurationSection(path + ".data");
if (sec2 != null) {
for (String dataPath : sec2.getKeys(false)) {
data.put(dataPath, sec2.get(dataPath));
}
}
oStage.customObjectives.add(found);
oStage.customObjectiveCounts.add(count);
oStage.customObjectiveData.add(data);
try{
getServer().getPluginManager().registerEvents(found, this);
}catch (Exception e){
printWarning("[Quests] Failed to register events for custom objective \"" + name + "\" in Stage " + s2 + " of Quest \"" + quest.name + "\". Does the objective class listen for events?");
if(debug){
printWarning("[Quests] Error log:");
e.printStackTrace();
}
}
}
}
if (config.contains("quests." + s + ".stages.ordered." + s2 + ".start-event")) {
Event evt = Event.loadEvent(config.getString("quests." + s + ".stages.ordered." + s2 + ".start-event"), this);

View File

@ -113,6 +113,10 @@ public class Stage {
public Map<EntityType, Integer> mobsToTame = new EnumMap<EntityType, Integer>(EntityType.class);
public Map<DyeColor, Integer> sheepToShear = new EnumMap<DyeColor, Integer>(DyeColor.class);
public Map<EnumMap<Material, Integer>, Boolean> itemsToCraft = new HashMap<EnumMap<Material, Integer>, Boolean>();
public LinkedList<CustomObjective> customObjectives = new LinkedList<CustomObjective>();
public LinkedList<Integer> customObjectiveCounts = new LinkedList<Integer>();
public LinkedList<String> customObjectiveDisplays = new LinkedList<String>();
public LinkedList<Map<String, Object>> customObjectiveData = new LinkedList<Map<String, Object>>();
public String script;
public Event startEvent = null;
public Event deathEvent = null;
@ -246,6 +250,10 @@ public class Stage {
if (other.itemsToCraft.equals(itemsToCraft) == false) {
return false;
}
if (other.customObjectives.equals(customObjectives) == false) {
return false;
}
if (other.script != null && script != null) {
if (other.script.equals(script) == false) {

View File

@ -1,8 +1,11 @@
package me.blackvein.quests.prompts;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import me.blackvein.quests.CustomObjective;
import me.blackvein.quests.util.ColorUtil;
import me.blackvein.quests.Event;
@ -311,21 +314,31 @@ public class CreateStagePrompt extends FixedSetPrompt implements ColorUtil {
}
}
if (context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES) == null) {
text += PINK + "" + BOLD + "20 " + RESET + PINK + "- Custom Objectives" + GRAY + " (" + Lang.get("noneSet") + ")\n";
} else {
LinkedList<String> customObjs = (LinkedList<String>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES);
text += PINK + "" + BOLD + "20 " + RESET + PINK + "- Custom Objectives" + GRAY + " (" + Lang.get("noneSet") + ")\n";
for(String s : customObjs){
text += PINK + " - " + GOLD + s + "\n";
}
}
if (context.getSessionData(pref + CK.S_START_MESSAGE) == null) {
text += PINK + "" + BOLD + "20 " + RESET + PURPLE + "- " + Lang.get("stageEditorStartMessage") + GRAY + " (" + Lang.get("noneSet") + ")\n";
text += PINK + "" + BOLD + "21 " + RESET + PURPLE + "- " + Lang.get("stageEditorStartMessage") + GRAY + " (" + Lang.get("noneSet") + ")\n";
} else {
text += PINK + "" + BOLD + "20 " + RESET + PURPLE + "- " + Lang.get("stageEditorStartMessage") + GRAY + "(" + AQUA + "\"" + context.getSessionData(pref + CK.S_START_MESSAGE) + "\"" + GRAY + ")\n";
text += PINK + "" + BOLD + "21 " + RESET + PURPLE + "- " + Lang.get("stageEditorStartMessage") + GRAY + "(" + AQUA + "\"" + context.getSessionData(pref + CK.S_START_MESSAGE) + "\"" + GRAY + ")\n";
}
if (context.getSessionData(pref + CK.S_COMPLETE_MESSAGE) == null) {
text += PINK + "" + BOLD + "21 " + RESET + PURPLE + "- " + Lang.get("stageEditorCompleteMessage") + GRAY + " (" + Lang.get("noneSet") + ")\n";
text += PINK + "" + BOLD + "22 " + RESET + PURPLE + "- " + Lang.get("stageEditorCompleteMessage") + GRAY + " (" + Lang.get("noneSet") + ")\n";
} else {
text += PINK + "" + BOLD + "21 " + RESET + PURPLE + "- " + Lang.get("stageEditorCompleteMessage") + GRAY + "(" + AQUA + "\"" + context.getSessionData(pref + CK.S_COMPLETE_MESSAGE) + "\"" + GRAY + ")\n";
text += PINK + "" + BOLD + "22 " + RESET + PURPLE + "- " + Lang.get("stageEditorCompleteMessage") + GRAY + "(" + AQUA + "\"" + context.getSessionData(pref + CK.S_COMPLETE_MESSAGE) + "\"" + GRAY + ")\n";
}
text += RED + "" + BOLD + "22 " + RESET + PURPLE + "- " + Lang.get("stageEditorDelete") + "\n";
text += GREEN + "" + BOLD + "23 " + RESET + PURPLE + "- " + Lang.get("done") + "\n";
text += RED + "" + BOLD + "23 " + RESET + PURPLE + "- " + Lang.get("stageEditorDelete") + "\n";
text += GREEN + "" + BOLD + "24 " + RESET + PURPLE + "- " + Lang.get("done") + "\n";
return text;
@ -398,12 +411,14 @@ public class CreateStagePrompt extends FixedSetPrompt implements ColorUtil {
return new DenizenPrompt();
}
} else if (input.equalsIgnoreCase("20")) {
return new StartMessagePrompt();
return new CustomObjectivesPrompt();
} else if (input.equalsIgnoreCase("21")) {
return new CompleteMessagePrompt();
return new StartMessagePrompt();
} else if (input.equalsIgnoreCase("22")) {
return new DeletePrompt();
return new CompleteMessagePrompt();
} else if (input.equalsIgnoreCase("23")) {
return new DeletePrompt();
} else if (input.equalsIgnoreCase("24")) {
return new StagesPrompt(questFactory);
} else {
return new CreateStagePrompt(stageNum, questFactory, citizens);
@ -3974,4 +3989,278 @@ public class CreateStagePrompt extends FixedSetPrompt implements ColorUtil {
}
}
private class CustomObjectivesPrompt extends StringPrompt {
@Override
public String getPromptText(ConversationContext context) {
String text = PINK + "- Custom Objectives -\n";
if(questFactory.quests.customObjectives.isEmpty()){
text += BOLD + "" + PURPLE + "(No modules loaded)";
}else {
for(CustomObjective co : questFactory.quests.customObjectives)
text += PURPLE + " - " + co.getName() + "\n";
}
return text + YELLOW + "Enter the name of a custom objective to add, or enter \'clear\' to clear all custom objectives, or \'cancel\' to return.";
}
@Override
public Prompt acceptInput(ConversationContext context, String input) {
if (input.equalsIgnoreCase("cancel") == false && input.equalsIgnoreCase("clear") == false) {
CustomObjective found = null;
for(CustomObjective co : questFactory.quests.customObjectives){
if(co.getName().equalsIgnoreCase(input)){
found = co;
break;
}
}
if(found == null){
for(CustomObjective co : questFactory.quests.customObjectives){
if(co.getName().toLowerCase().contains(input.toLowerCase())){
found = co;
break;
}
}
}
if(found != null){
if(context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES) != null){
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<Integer> countList = (LinkedList<Integer>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_COUNT);
if(list.contains(found.getName()) == false){
list.add(found.getName());
datamapList.add(found.datamap);
countList.add(-999);
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES, list);
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA, datamapList);
}else{
context.getForWhom().sendRawMessage(YELLOW + "That custom objective has already been added!");
return new CustomObjectivesPrompt();
}
}else{
LinkedList<Map<String, Object>> datamapList = new LinkedList<Map<String, Object>>();
LinkedList<Integer> countList = new LinkedList<Integer>();
datamapList.add(found.datamap);
countList.add(-999);
LinkedList<String> list = new LinkedList<String>();
list.add(found.getName());
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES, list);
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA, datamapList);
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_COUNT, countList);
}
//Send user to the count prompt / custom data prompt if there is any needed
if(found.isEnableCount())
return new CustomObjectiveCountPrompt();
if(found.datamap.isEmpty() == false){
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA_DESCRIPTIONS, found.descriptions);
return new ObjectiveCustomDataListPrompt();
}
//
}else{
context.getForWhom().sendRawMessage(YELLOW + "Custom objective module not found.");
return new CustomObjectivesPrompt();
}
} else if (input.equalsIgnoreCase("clear")) {
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES, null);
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA, null);
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA_TEMP, null);
context.getForWhom().sendRawMessage(YELLOW + "Custom objectives cleared.");
}
return new CreateStagePrompt(stageNum, questFactory, citizens);
}
}
private class CustomObjectiveCountPrompt extends StringPrompt {
@Override
public String getPromptText(ConversationContext context) {
String text = BOLD + "" + AQUA + "- ";
LinkedList<String> list = (LinkedList<String>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES);
String objName = list.getLast();
text += objName + " -\n";
CustomObjective found = null;
for(CustomObjective co : questFactory.quests.customObjectives){
if(co.getName().equals(objName)){
found = co;
break;
}
}
text += BLUE + found.getCountPrompt() + "\n\n";
return text;
}
@Override
public Prompt acceptInput(ConversationContext context, String input) {
try{
int num = Integer.parseInt(input);
LinkedList<Integer> counts = (LinkedList<Integer>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_COUNT);
counts.set(counts.size() - 1, num);
LinkedList<String> list = (LinkedList<String>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES);
String objName = list.getLast();
CustomObjective found = null;
for(CustomObjective co : questFactory.quests.customObjectives){
if(co.getName().equals(objName)){
found = co;
break;
}
}
if(found.datamap.isEmpty() == false){
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA_DESCRIPTIONS, found.descriptions);
return new ObjectiveCustomDataListPrompt();
}else{
return new CreateStagePrompt(stageNum, questFactory, citizens);
}
}catch (NumberFormatException e){
context.getForWhom().sendRawMessage(RED + "Input was not a number!");
return new CustomObjectiveCountPrompt();
}
}
}
private class ObjectiveCustomDataListPrompt extends StringPrompt {
@Override
public String getPromptText(ConversationContext context) {
String text = BOLD + "" + AQUA + "- ";
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);
String objName = list.getLast();
Map<String, Object> datamap = datamapList.getLast();
text += objName + " -\n";
int index = 1;
LinkedList<String> datamapKeys = new LinkedList<String>();
for(String key : datamap.keySet())
datamapKeys.add(key);
Collections.sort(datamapKeys);
for(String dataKey : datamapKeys){
text += BOLD + "" + DARKBLUE + index + " - " + RESET + BLUE + dataKey;
if(datamap.get(dataKey) != null)
text += GREEN + " (" + (String) datamap.get(dataKey) + ")\n";
else
text += RED + " (Value required)\n";
index++;
}
text += BOLD + "" + DARKBLUE + index + " - " + AQUA + "Finish";
return text;
}
@Override
public Prompt acceptInput(ConversationContext context, String input) {
LinkedList<Map<String, Object>> datamapList = (LinkedList<Map<String, Object>>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA);
Map<String, Object> datamap = datamapList.getLast();
int numInput;
try{
numInput = Integer.parseInt(input);
}catch(NumberFormatException nfe){
return new ObjectiveCustomDataListPrompt();
}
if(numInput < 1 || numInput > datamap.size() + 1)
return new ObjectiveCustomDataListPrompt();
if(numInput < datamap.size() + 1){
LinkedList<String> datamapKeys = new LinkedList<String>();
for(String key : datamap.keySet())
datamapKeys.add(key);
Collections.sort(datamapKeys);
String selectedKey = datamapKeys.get(numInput - 1);
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA_TEMP, selectedKey);
return new ObjectiveCustomDataPrompt();
}else{
if(datamap.containsValue(null)){
return new ObjectiveCustomDataListPrompt();
}else{
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA_DESCRIPTIONS, null);
return new CreateStagePrompt(stageNum, questFactory, citizens);
}
}
}
}
private class ObjectiveCustomDataPrompt extends StringPrompt {
@Override
public String getPromptText(ConversationContext context) {
String text = "";
String temp = (String)context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA_TEMP);
Map<String, String> descriptions = (Map<String, String>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA_DESCRIPTIONS);
if(descriptions.get(temp) != null)
text += GOLD + descriptions.get(temp) + "\n";
text += YELLOW + "Enter value for ";
text += BOLD + temp + RESET + YELLOW + ":";
return text;
}
@Override
public Prompt acceptInput(ConversationContext context, String input) {
LinkedList<Map<String, Object>> datamapList = (LinkedList<Map<String, Object>>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA);
Map<String, Object> datamap = datamapList.getLast();
datamap.put((String)context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA_TEMP), input);
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA_TEMP, null);
return new ObjectiveCustomDataListPrompt();
}
}
}

View File

@ -590,6 +590,8 @@ public class RequirementsPrompt extends FixedSetPrompt implements ColorUtil {
if(list.contains(found.getName()) == false){
list.add(found.getName());
datamapList.add(found.datamap);
context.setSessionData(CK.REQ_CUSTOM, list);
context.setSessionData(CK.REQ_CUSTOM_DATA, datamapList);
}else{
context.getForWhom().sendRawMessage(YELLOW + "That custom requirement has already been added!");
return new CustomRequirementsPrompt();

View File

@ -1168,6 +1168,8 @@ public class RewardsPrompt extends FixedSetPrompt implements ColorUtil {
if(list.contains(found.getName()) == false){
list.add(found.getName());
datamapList.add(found.datamap);
context.setSessionData(CK.REW_CUSTOM, list);
context.setSessionData(CK.REW_CUSTOM_DATA, datamapList);
}else{
context.getForWhom().sendRawMessage(YELLOW + "That custom reward has already been added!");
return new CustomRewardsPrompt();

View File

@ -98,7 +98,11 @@ public class CK {
public static final String S_DENIZEN = "denizen";
public static final String S_COMPLETE_MESSAGE = "completeMessage";
public static final String S_START_MESSAGE = "startMessage";
public static final String S_MINI_EVENTS = "miniEvents";
public static final String S_CUSTOM_OBJECTIVES = "customObjectives";
public static final String S_CUSTOM_OBJECTIVES_COUNT = "customObjectiveCounts";
public static final String S_CUSTOM_OBJECTIVES_DATA = "customObjectiveData";
public static final String S_CUSTOM_OBJECTIVES_DATA_DESCRIPTIONS = "customObjectiveDataDescriptions";
public static final String S_CUSTOM_OBJECTIVES_DATA_TEMP = "customObjectiveDataTemp";
//Events
public static final String E_OLD_EVENT = "oldEvent";

View File

@ -1,6 +1,6 @@
name: Quests
main: me.blackvein.quests.Quests
version: 1.7.3
version: 1.8.0
description: Player questing system
website: http://dev.bukkit.org/server-mods/quests/
dev-url: https://github.com/Blackvein/Quests/