Finished total Quest Points display, starting crafted quest items

Check if crafting items (shift-click and regular click) counts for
collecting items when placed into inventory.
This commit is contained in:
Blackvein 2012-10-31 21:27:35 -07:00
parent bcf8cee6fe
commit 2d5105713a
5 changed files with 485 additions and 464 deletions

View File

@ -86,6 +86,36 @@ public class Quest {
q.currentStage = stages.get(stages.indexOf(q.currentStage) + 1); q.currentStage = stages.get(stages.indexOf(q.currentStage) + 1);
q.addEmpties(); q.addEmpties();
for (Entry e : q.currentStage.itemsToCollect.entrySet()) {
if ((Boolean) e.getValue() == true) {
Map<Material, Integer> tempMap = (Map<Material, Integer>) e.getKey();
for (Entry e2 : tempMap.entrySet()) {
questItems.put((Material) e2.getKey(), (Integer) e2.getValue());
}
}
}
for (Entry e : q.currentStage.itemsToCraft.entrySet()) {
if ((Boolean) e.getValue() == true) {
Map<Material, Integer> tempMap = (Map<Material, Integer>) e.getKey();
for (Entry e2 : tempMap.entrySet()) {
questItems.put((Material) e2.getKey(), (Integer) e2.getValue());
}
}
}
player.sendMessage(ChatColor.GOLD + "---(Objectives)---"); player.sendMessage(ChatColor.GOLD + "---(Objectives)---");
for(String s : q.getObjectives()){ for(String s : q.getObjectives()){

View File

@ -101,8 +101,6 @@ public class Quester {
public LinkedList<String> getObjectives() { public LinkedList<String> getObjectives() {
if(delayStartTime == 0){
LinkedList<String> unfinishedObjectives = new LinkedList<String>(); LinkedList<String> unfinishedObjectives = new LinkedList<String>();
LinkedList<String> finishedObjectives = new LinkedList<String>(); LinkedList<String> finishedObjectives = new LinkedList<String>();
LinkedList<String> objectives = new LinkedList<String>(); LinkedList<String> objectives = new LinkedList<String>();
@ -493,32 +491,6 @@ public class Quester {
return objectives; return objectives;
}else{
long time;
if(delayTimeLeft > -1)
time = delayTimeLeft - (System.currentTimeMillis() - delayStartTime);
else
time = currentStage.delay - (System.currentTimeMillis() - delayStartTime);
LinkedList<String> obj = new LinkedList<String>();
String s;
if(currentStage.delayMessage != null){
s = currentStage.delayMessage;
s = plugin.parseString(s, currentQuest);
s = s.replaceAll("<time>", Quests.getTime(time));
}else
s = ChatColor.YELLOW + "Wait " + ChatColor.DARK_PURPLE + Quests.getTime(time) + ChatColor.YELLOW + ".";
obj.add(s);
return obj;
}
} }
public boolean hasObjective(String s) { public boolean hasObjective(String s) {
@ -990,10 +962,28 @@ public class Quester {
if (itemsCrafted.containsKey(i.getType())) { if (itemsCrafted.containsKey(i.getType())) {
itemsCrafted.put(i.getType(), (itemsCrafted.get(i.getType()) + i.getAmount())); for (EnumMap m : currentStage.itemsToCraft.keySet()) {
if (m.containsKey(i.getType())) {
if (itemsCrafted.get(i.getType()) < (Integer) m.get(i.getType())) {
int integer = itemsCrafted.get(i.getType());
if ((i.getAmount() + integer) >= (Integer) m.get(i.getType())) {
itemsCrafted.put(i.getType(), (Integer) m.get(i.getType()));
} else {
itemsCrafted.put(i.getType(), (integer + i.getAmount()));
}
if (itemsCrafted.get(i.getType()).equals((Integer) m.get(i.getType()))) {
finishObjective("craftItem", null, i, null, null, null, null, null, null, 0);
}
}
break;
}
if (itemsCrafted.get(i.getType()) >= currentStage.itemsToCraft.get(i.getType())) {
finishObjective("craftItem", i.getType(), null, null, null, null, null, null, null, 0);
} }
} }
@ -1034,16 +1024,7 @@ public class Quester {
} else if (objective.equalsIgnoreCase("collectItem")) { } else if (objective.equalsIgnoreCase("collectItem")) {
String message = ChatColor.GREEN + "(Completed) Collect " + prettyItemString(itemstack.getTypeId()); String message = ChatColor.GREEN + "(Completed) Collect " + prettyItemString(itemstack.getTypeId());
for (Map<Material, Integer> map : currentStage.itemsToCollect.keySet()) { message = message + " " + itemsCollected.get(material) + "/" + itemsCollected.get(material);
if (map.containsKey(itemstack.getType())) {
message = message + " " + map.get(itemstack.getType()) + "/" + map.get(itemstack.getType());
break;
}
}
p.sendMessage(message); p.sendMessage(message);
if (testComplete()) { if (testComplete()) {
@ -1152,7 +1133,7 @@ public class Quester {
} else if (objective.equalsIgnoreCase("craftItem")) { } else if (objective.equalsIgnoreCase("craftItem")) {
String message = ChatColor.GREEN + "(Completed) Craft " + prettyItemString(material.getId()); String message = ChatColor.GREEN + "(Completed) Craft " + prettyItemString(material.getId());
message = message + " " + currentStage.itemsToCraft.get(material) + "/" + currentStage.itemsToCraft.get(material); message = message + " " + itemsCrafted.get(material) + "/" + itemsCrafted.get(material);
p.sendMessage(message); p.sendMessage(message);
if (testComplete()) { if (testComplete()) {
currentQuest.nextStage(this); currentQuest.nextStage(this);
@ -1317,9 +1298,13 @@ public class Quester {
} }
if (currentStage.itemsToCraft.isEmpty() == false) { if (currentStage.itemsToCraft.isEmpty() == false) {
for (Material m : currentStage.itemsToCraft.keySet()) { for (Entry e : currentStage.itemsToCraft.entrySet()) {
itemsCrafted.put(m, 0); for (Object o : ((Map) e.getKey()).keySet()) {
itemsCrafted.put((Material) o, 0);
}
} }
} }
@ -2599,14 +2584,11 @@ public class Quester {
public void startStageTimer(){ public void startStageTimer(){
if(delayTimeLeft > -1){ if(delayTimeLeft > -1)
System.out.println("Starting a new timer."); plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new StageTimer(plugin, this), delayTimeLeft*50);
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new StageTimer(plugin, this), delayTimeLeft/50); else
}else{ plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new StageTimer(plugin, this), currentStage.delay);
System.out.println("Resuming timer.");
System.out.println("Delay: " + currentStage.delay/50 + " ticks. (" + (currentStage.delay/1000) + " seconds)");
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new StageTimer(plugin, this), currentStage.delay/50);
}
delayStartTime = System.currentTimeMillis(); delayStartTime = System.currentTimeMillis();
} }

View File

@ -1321,6 +1321,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
ConfigurationSection section1 = config.getConfigurationSection("quests"); ConfigurationSection section1 = config.getConfigurationSection("quests");
boolean failedToLoad = false; boolean failedToLoad = false;
totalQuestPoints = 0; totalQuestPoints = 0;
boolean firstStage = true;
for (String s : section1.getKeys(false)) { for (String s : section1.getKeys(false)) {
try { try {
@ -2344,6 +2345,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
} }
if(firstStage){
for (Entry e : itemMap.entrySet()) { for (Entry e : itemMap.entrySet()) {
if ((Boolean) e.getValue() == true) { if ((Boolean) e.getValue() == true) {
@ -2351,12 +2354,6 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
Map<Material, Integer> tempMap = (Map<Material, Integer>) e.getKey(); Map<Material, Integer> tempMap = (Map<Material, Integer>) e.getKey();
for (Entry e2 : tempMap.entrySet()) { for (Entry e2 : tempMap.entrySet()) {
if (quest.questItems.containsKey((Material) e2.getKey())) {
quest.questItems.put((Material) e2.getKey(), (quest.questItems.get((Material) e2.getKey()) + (Integer) e2.getValue()));
} else {
quest.questItems.put((Material) e2.getKey(), (Integer) e2.getValue()); quest.questItems.put((Material) e2.getKey(), (Integer) e2.getValue());
} }
@ -2644,15 +2641,32 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
if (Quests.checkList(config.getList("quests." + s + ".stages.ordered." + s2 + ".craft-item-amounts"), Integer.class)) { if (Quests.checkList(config.getList("quests." + s + ".stages.ordered." + s2 + ".craft-item-amounts"), Integer.class)) {
if(config.contains("quests." + s + ".stages.ordered." + s2 + ".craft-quest-items")){
if(Quests.checkList(config.getList("quests." + s + ".stages.ordered." + s2 + ".craft-quest-items"), Boolean.class)){
List<Integer> craftIds = config.getIntegerList("quests." + s + ".stages.ordered." + s2 + ".craft-item-ids"); List<Integer> craftIds = config.getIntegerList("quests." + s + ".stages.ordered." + s2 + ".craft-item-ids");
List<Integer> craftAmounts = config.getIntegerList("quests." + s + ".stages.ordered." + s2 + ".craft-item-amounts"); List<Integer> craftAmounts = config.getIntegerList("quests." + s + ".stages.ordered." + s2 + ".craft-item-amounts");
List<Boolean> craftQuestItems = config.getBooleanList("quests." + s + ".stages.ordered." + s2 + ".craft-quest-items");
for (int i : craftIds) { for (int i : craftIds) {
stage.itemsToCraft.put(Material.getMaterial(i), craftAmounts.get(craftIds.indexOf(i))); EnumMap<Material, Integer> map = new EnumMap<Material, Integer>(Material.class);
if(firstStage)
quest.questItems.put(Material.getMaterial(i), craftAmounts.get(craftIds.indexOf(i)));
map.put(Material.getMaterial(i), craftAmounts.get(craftIds.indexOf(i)));
stage.itemsToCraft.put(map, craftQuestItems.get(craftIds.indexOf(i)));
} }
}
}else{
printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.LIGHT_PURPLE + "Stage " + s2 + ChatColor.GOLD + " of Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is missing " + ChatColor.RED + "craft-quest-items:");
stageFailed = true;
break;
}
} else { } else {
printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "craft-item-amounts: " + ChatColor.GOLD + "in " + ChatColor.LIGHT_PURPLE + "Stage " + s2 + ChatColor.GOLD + " of Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is not a list of numbers!"); printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "craft-item-amounts: " + ChatColor.GOLD + "in " + ChatColor.LIGHT_PURPLE + "Stage " + s2 + ChatColor.GOLD + " of Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is not a list of numbers!");
stageFailed = true; stageFailed = true;
@ -2711,6 +2725,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
break; break;
} }
quest.stages.add(stage); quest.stages.add(stage);
firstStage = false;
} }

View File

@ -84,7 +84,7 @@ public class Stage {
LinkedList<String> locationNames = new LinkedList<String>(); LinkedList<String> locationNames = new LinkedList<String>();
Map<EntityType, Integer> mobsToTame = new EnumMap<EntityType, Integer>(EntityType.class); Map<EntityType, Integer> mobsToTame = new EnumMap<EntityType, Integer>(EntityType.class);
Map<DyeColor, Integer> sheepToShear = new EnumMap<DyeColor, Integer>(DyeColor.class); Map<DyeColor, Integer> sheepToShear = new EnumMap<DyeColor, Integer>(DyeColor.class);
Map<Material, Integer> itemsToCraft = new EnumMap<Material, Integer>(Material.class); Map<EnumMap<Material, Integer>, Boolean> itemsToCraft = new HashMap<EnumMap<Material, Integer>, Boolean>();
String script; String script;
Event event; Event event;
long delay = -1; long delay = -1;

View File

@ -18,15 +18,12 @@ public class StageTimer implements Runnable{
@Override @Override
public void run(){ public void run(){
System.out.println("Running.");
if(quester.delayOver){ if(quester.delayOver){
System.out.println("Delay is over.");
Player player = plugin.getServer().getPlayerExact(quester.name); Player player = plugin.getServer().getPlayerExact(quester.name);
if(quester.currentQuest.stages.indexOf(quester.currentStage) == (quester.currentQuest.stages.size() - 1)){ if(quester.currentQuest.stages.indexOf(quester.currentStage) == (quester.currentQuest.stages.size() - 1)){
System.out.println("Quester is finished Quest.");
if(quester.currentStage.script != null) if(quester.currentStage.script != null)
plugin.trigger.parseQuestTaskTrigger(quester.currentStage.script, player); plugin.trigger.parseQuestTaskTrigger(quester.currentStage.script, player);
if(quester.currentStage.event != null) if(quester.currentStage.event != null)
@ -36,7 +33,6 @@ public class StageTimer implements Runnable{
}else { }else {
System.out.println("Quester is not finished Quest.");
quester.reset(); quester.reset();
player.sendMessage(plugin.parseString(quester.currentStage.finished, quester.currentQuest)); player.sendMessage(plugin.parseString(quester.currentStage.finished, quester.currentQuest));
if(quester.currentStage.script != null) if(quester.currentStage.script != null)
@ -57,8 +53,6 @@ public class StageTimer implements Runnable{
} }
} }
quester.delayOver = true; quester.delayOver = true;