*Fix reach location not saving

*Fix infinite stage loop (occurs when 2 or more stage are exactly the
same)
This commit is contained in:
Zino 2013-08-06 10:17:07 +02:00
parent 67592916fd
commit 31df651edc
3 changed files with 4898 additions and 4889 deletions

View File

@ -1,373 +1,375 @@
package me.blackvein.quests; package me.blackvein.quests;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import me.blackvein.quests.util.ItemUtil; import me.blackvein.quests.util.ItemUtil;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.PlayerInventory;
public class Quest { public class Quest {
public String name; public String name;
public String description; public String description;
public String finished; public String finished;
public long redoDelay = -1; public long redoDelay = -1;
public int parties = 0; public int parties = 0;
LinkedList<Stage> stages = new LinkedList<Stage>(); LinkedList<Stage> stages = new LinkedList<Stage>();
NPC npcStart; NPC npcStart;
Location blockStart; Location blockStart;
Quests plugin; Quests plugin;
Event initialEvent; Event initialEvent;
//Requirements //Requirements
int moneyReq = 0; int moneyReq = 0;
int questPointsReq = 0; int questPointsReq = 0;
List<ItemStack> items = new LinkedList<ItemStack>(); List<ItemStack> items = new LinkedList<ItemStack>();
List<Boolean> removeItems = new LinkedList<Boolean>(); List<Boolean> removeItems = new LinkedList<Boolean>();
List<String> neededQuests = new LinkedList<String>(); List<String> neededQuests = new LinkedList<String>();
List<String> blockQuests = new LinkedList<String>(); List<String> blockQuests = new LinkedList<String>();
List<String> permissionReqs = new LinkedList<String>(); List<String> permissionReqs = new LinkedList<String>();
public String failRequirements = null; public String failRequirements = null;
// //
//Rewards //Rewards
int moneyReward = 0; int moneyReward = 0;
int questPoints = 0; int questPoints = 0;
int exp = 0; int exp = 0;
List<String> commands = new LinkedList<String>(); List<String> commands = new LinkedList<String>();
List<String> permissions = new LinkedList<String>(); List<String> permissions = new LinkedList<String>();
LinkedList<ItemStack> itemRewards = new LinkedList<ItemStack>(); LinkedList<ItemStack> itemRewards = new LinkedList<ItemStack>();
//mcMMO //mcMMO
List<String> mcmmoSkills = new LinkedList<String>(); List<String> mcmmoSkills = new LinkedList<String>();
List<Integer> mcmmoAmounts = new LinkedList<Integer>(); List<Integer> mcmmoAmounts = new LinkedList<Integer>();
// //
// //
public void nextStage(Quester q){ public void nextStage(Quester q){
String stageCompleteMessage = q.currentStage.completeMessage; String stageCompleteMessage = q.currentStage.completeMessage;
if (stageCompleteMessage != null) { if (stageCompleteMessage != null) {
q.getPlayer().sendMessage(Quests.parseString(stageCompleteMessage, q.currentQuest)); q.getPlayer().sendMessage(Quests.parseString(stageCompleteMessage, q.currentQuest));
} }
if(q.currentStage.delay < 0){ if(q.currentStage.delay < 0){
Player player = q.getPlayer(); Player player = q.getPlayer();
if(stages.indexOf(q.currentStage) == (stages.size() - 1)){ if(q.currentStageIndex >= (stages.size() - 1)){
if(q.currentStage.script != null) if(q.currentStage.script != null)
plugin.trigger.parseQuestTaskTrigger(q.currentStage.script, player); plugin.trigger.parseQuestTaskTrigger(q.currentStage.script, player);
if(q.currentStage.event != null) if(q.currentStage.event != null)
q.currentStage.event.happen(q); q.currentStage.event.happen(q);
completeQuest(q); completeQuest(q);
}else { }else {
q.reset(); q.reset();
if(q.currentStage.script != null) if(q.currentStage.script != null)
plugin.trigger.parseQuestTaskTrigger(q.currentStage.script, player); plugin.trigger.parseQuestTaskTrigger(q.currentStage.script, player);
if(q.currentStage.event != null) if(q.currentStage.event != null)
q.currentStage.event.happen(q); q.currentStage.event.happen(q);
q.currentStage = stages.get(stages.indexOf(q.currentStage) + 1); q.currentStage = stages.get(stages.indexOf(q.currentStage) + 1);
q.addEmpties(); q.currentStageIndex++;
q.addEmpties();
player.sendMessage(ChatColor.GOLD + "---(Objectives)---");
for(String s : q.getObjectives()){ player.sendMessage(ChatColor.GOLD + "---(Objectives)---");
for(String s : q.getObjectives()){
player.sendMessage(s);
player.sendMessage(s);
}
}
String stageStartMessage = q.currentStage.startMessage;
if (stageStartMessage != null) { String stageStartMessage = q.currentStage.startMessage;
q.getPlayer().sendMessage(Quests.parseString(stageStartMessage, q.currentQuest)); if (stageStartMessage != null) {
} q.getPlayer().sendMessage(Quests.parseString(stageStartMessage, q.currentQuest));
}
}
}
q.delayStartTime = 0;
q.delayTimeLeft = -1; q.delayStartTime = 0;
q.delayTimeLeft = -1;
}else{
q.startStageTimer(); }else{
q.startStageTimer();
}
}
}
}
public String getName(){
return name; public String getName(){
} return name;
}
public boolean testRequirements(Quester quester){
return testRequirements(quester.getPlayer()); public boolean testRequirements(Quester quester){
} return testRequirements(quester.getPlayer());
}
public boolean testRequirements(Player player){
public boolean testRequirements(Player player){
Quester quester = plugin.getQuester(player.getName());
Quester quester = plugin.getQuester(player.getName());
if(moneyReq != 0 && Quests.economy.getBalance(player.getName()) < moneyReq)
return false; if(moneyReq != 0 && Quests.economy.getBalance(player.getName()) < moneyReq)
return false;
PlayerInventory inventory = player.getInventory();
int num = 0; PlayerInventory inventory = player.getInventory();
int num = 0;
for(ItemStack is : items){
for(ItemStack is : items){
for(ItemStack stack : inventory.getContents()){
for(ItemStack stack : inventory.getContents()){
if(stack != null){
if(ItemUtil.compareItems(is, stack, true) == 0) if(stack != null){
num += stack.getAmount(); if(ItemUtil.compareItems(is, stack, true) == 0)
} num += stack.getAmount();
}
}
}
if(num < is.getAmount())
return false; if(num < is.getAmount())
return false;
num = 0;
num = 0;
}
}
for(String s : permissionReqs){
for(String s : permissionReqs){
if(player.hasPermission(s) == false)
return false; if(player.hasPermission(s) == false)
return false;
}
}
if(quester.questPoints < questPointsReq)
return false; if(quester.questPoints < questPointsReq)
return false;
if(quester.completedQuests.containsAll(neededQuests) == false)
return false; if(quester.completedQuests.containsAll(neededQuests) == false)
return false;
for (String q : blockQuests) {
if (quester.completedQuests.contains(q)) { for (String q : blockQuests) {
return false; if (quester.completedQuests.contains(q)) {
} return false;
} }
}
return true;
return true;
}
}
public void completeQuest(Quester q){
public void completeQuest(Quester q){
Player player = plugin.getServer().getPlayerExact(q.name);
q.reset(); Player player = plugin.getServer().getPlayerExact(q.name);
q.completedQuests.add(name); q.reset();
String none = ChatColor.GRAY + "- (None)"; q.completedQuests.add(name);
player.sendMessage(Quests.parseString(finished, q.currentQuest)); String none = ChatColor.GRAY + "- (None)";
if(moneyReward > 0 && Quests.economy != null){ player.sendMessage(Quests.parseString(finished, q.currentQuest));
Quests.economy.depositPlayer(q.name, moneyReward); if(moneyReward > 0 && Quests.economy != null){
none = null; Quests.economy.depositPlayer(q.name, moneyReward);
} none = null;
if(redoDelay > -1) }
q.completedTimes.put(this.name, System.currentTimeMillis()); if(redoDelay > -1)
q.completedTimes.put(this.name, System.currentTimeMillis());
for(ItemStack i : itemRewards){
Quests.addItem(player, i); for(ItemStack i : itemRewards){
none = null; Quests.addItem(player, i);
} none = null;
}
for(String s : commands){
for(String s : commands){
s = s.replaceAll("<player>", player.getName());
s = s.replaceAll("<player>", player.getName());
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), s);
none = null; plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), s);
none = null;
}
}
for(String s : permissions){
for(String s : permissions){
Quests.permission.playerAdd(player, s);
none = null; Quests.permission.playerAdd(player, s);
none = null;
}
}
for(String s : mcmmoSkills){
for(String s : mcmmoSkills){
new McMMOPlayer(player).getProfile().skillUp(Quests.getMcMMOSkill(s), mcmmoAmounts.get(mcmmoSkills.indexOf(s)));
none = null; new McMMOPlayer(player).getProfile().skillUp(Quests.getMcMMOSkill(s), mcmmoAmounts.get(mcmmoSkills.indexOf(s)));
none = null;
}
}
if(exp > 0){
player.giveExp(exp); if(exp > 0){
none = null; player.giveExp(exp);
} none = null;
}
player.sendMessage(ChatColor.GOLD + "**QUEST COMPLETE: " + ChatColor.YELLOW + q.currentQuest.name + ChatColor.GOLD + "**");
player.sendMessage(ChatColor.GREEN + "Rewards:"); player.sendMessage(ChatColor.GOLD + "**QUEST COMPLETE: " + ChatColor.YELLOW + q.currentQuest.name + ChatColor.GOLD + "**");
player.sendMessage(ChatColor.GREEN + "Rewards:");
if(questPoints > 0){
player.sendMessage("- " + ChatColor.DARK_GREEN + questPoints + " Quest Points"); if(questPoints > 0){
q.questPoints += questPoints; player.sendMessage("- " + ChatColor.DARK_GREEN + questPoints + " Quest Points");
none = null; q.questPoints += questPoints;
} none = null;
}
for(ItemStack i : itemRewards){
if(i.hasItemMeta() && i.getItemMeta().hasDisplayName()) for(ItemStack i : itemRewards){
player.sendMessage("- " + ChatColor.DARK_AQUA + ChatColor.ITALIC + i.getItemMeta().getDisplayName() + ChatColor.RESET + ChatColor.GRAY + " x " + i.getAmount()); if(i.hasItemMeta() && i.getItemMeta().hasDisplayName())
else if(i.getDurability() != 0) player.sendMessage("- " + ChatColor.DARK_AQUA + ChatColor.ITALIC + i.getItemMeta().getDisplayName() + ChatColor.RESET + ChatColor.GRAY + " x " + i.getAmount());
player.sendMessage("- " + ChatColor.DARK_GREEN + Quester.prettyItemString(i.getTypeId()) + ":" + i.getDurability() + ChatColor.GRAY + " x " + i.getAmount()); else if(i.getDurability() != 0)
else player.sendMessage("- " + ChatColor.DARK_GREEN + Quester.prettyItemString(i.getTypeId()) + ":" + i.getDurability() + ChatColor.GRAY + " x " + i.getAmount());
player.sendMessage("- " + ChatColor.DARK_GREEN + Quester.prettyItemString(i.getTypeId()) + ChatColor.GRAY + " x " + i.getAmount()); else
player.sendMessage("- " + ChatColor.DARK_GREEN + Quester.prettyItemString(i.getTypeId()) + ChatColor.GRAY + " x " + i.getAmount());
none = null;
} none = null;
}
if(moneyReward > 1){
player.sendMessage("- " + ChatColor.DARK_GREEN + moneyReward + " " + ChatColor.DARK_PURPLE + Quests.getCurrency(true)); if(moneyReward > 1){
none = null; player.sendMessage("- " + ChatColor.DARK_GREEN + moneyReward + " " + ChatColor.DARK_PURPLE + Quests.getCurrency(true));
}else if(moneyReward == 1){ none = null;
player.sendMessage("- " + ChatColor.DARK_GREEN + moneyReward + " " + ChatColor.DARK_PURPLE + Quests.getCurrency(false)); }else if(moneyReward == 1){
none = null; player.sendMessage("- " + ChatColor.DARK_GREEN + moneyReward + " " + ChatColor.DARK_PURPLE + Quests.getCurrency(false));
} none = null;
}
if(exp > 0){
player.sendMessage("- " + ChatColor.DARK_GREEN + exp + ChatColor.DARK_PURPLE + " Experience"); if(exp > 0){
none = null; player.sendMessage("- " + ChatColor.DARK_GREEN + exp + ChatColor.DARK_PURPLE + " Experience");
} none = null;
}
if(none != null){
player.sendMessage(none); if(none != null){
} player.sendMessage(none);
q.currentQuest = null; }
q.currentStage = null; q.currentQuest = null;
q.currentStage = null;
q.saveData(); q.currentStageIndex = 0;
player.updateInventory();
q.saveData();
} player.updateInventory();
@Override }
public boolean equals(Object o){
@Override
if(o instanceof Quest){ public boolean equals(Object o){
Quest other = (Quest) o; if(o instanceof Quest){
if(other.blockStart != null && blockStart != null){ Quest other = (Quest) o;
if(other.blockStart.equals(blockStart) == false)
return false; if(other.blockStart != null && blockStart != null){
}else if(other.blockStart != null && blockStart == null){ if(other.blockStart.equals(blockStart) == false)
return false; return false;
}else if(other.blockStart == null && blockStart != null) }else if(other.blockStart != null && blockStart == null){
return false; return false;
}else if(other.blockStart == null && blockStart != null)
for(String s : other.commands){ return false;
if(commands.size() >= (other.commands.indexOf(s))){ for(String s : other.commands){
if(commands.get(other.commands.indexOf(s)).equals(s) == false) if(commands.size() >= (other.commands.indexOf(s))){
return false;
if(commands.get(other.commands.indexOf(s)).equals(s) == false)
}else{ return false;
return false;
} }else{
return false;
} }
if(other.description.equals(description) == false) }
return false;
if(other.description.equals(description) == false)
if(other.initialEvent != null && initialEvent != null){ return false;
if(other.initialEvent.equals(initialEvent) == false)
return false; if(other.initialEvent != null && initialEvent != null){
}else if(other.initialEvent != null && initialEvent == null){ if(other.initialEvent.equals(initialEvent) == false)
return false; return false;
}else if(other.initialEvent == null && initialEvent != null) }else if(other.initialEvent != null && initialEvent == null){
return false; return false;
}else if(other.initialEvent == null && initialEvent != null)
if(other.exp != exp) return false;
return false;
if(other.exp != exp)
if(other.failRequirements != null && failRequirements != null){ return false;
if(other.failRequirements.equals(failRequirements) == false)
return false; if(other.failRequirements != null && failRequirements != null){
}else if(other.failRequirements != null && failRequirements == null){ if(other.failRequirements.equals(failRequirements) == false)
return false; return false;
}else if(other.failRequirements == null && failRequirements != null) }else if(other.failRequirements != null && failRequirements == null){
return false; return false;
}else if(other.failRequirements == null && failRequirements != null)
if(other.finished.equals(finished) == false) return false;
return false;
if(other.finished.equals(finished) == false)
if(other.items.equals(items) == false) return false;
return false;
if(other.items.equals(items) == false)
if(other.itemRewards.equals(itemRewards) == false) return false;
return false;
if(other.itemRewards.equals(itemRewards) == false)
if(other.mcmmoAmounts.equals(mcmmoAmounts) == false) return false;
return false;
if(other.mcmmoAmounts.equals(mcmmoAmounts) == false)
if(other.mcmmoSkills.equals(mcmmoSkills) == false) return false;
return false;
if(other.mcmmoSkills.equals(mcmmoSkills) == false)
if(other.moneyReq != moneyReq) return false;
return false;
if(other.moneyReq != moneyReq)
if(other.moneyReward != moneyReward) return false;
return false;
if(other.moneyReward != moneyReward)
if(other.name.equals(name) == false) return false;
return false;
if(other.name.equals(name) == false)
if(other.neededQuests.equals(neededQuests) == false) return false;
return false;
if(other.neededQuests.equals(neededQuests) == false)
if (other.blockQuests.equals(blockQuests) == false) return false;
return false;
if (other.blockQuests.equals(blockQuests) == false)
if(other.npcStart != null && npcStart != null){ return false;
if(other.npcStart.equals(npcStart) == false)
return false; if(other.npcStart != null && npcStart != null){
}else if(other.npcStart != null && npcStart == null){ if(other.npcStart.equals(npcStart) == false)
return false; return false;
}else if(other.npcStart == null && npcStart != null) }else if(other.npcStart != null && npcStart == null){
return false; return false;
}else if(other.npcStart == null && npcStart != null)
if(other.permissionReqs.equals(permissionReqs) == false) return false;
return false;
if(other.permissionReqs.equals(permissionReqs) == false)
if(other.permissions.equals(permissions) == false) return false;
return false;
if(other.permissions.equals(permissions) == false)
if(other.questPoints != questPoints) return false;
return false;
if(other.questPoints != questPoints)
if(other.questPointsReq != questPointsReq) return false;
return false;
if(other.questPointsReq != questPointsReq)
if(other.redoDelay != redoDelay) return false;
return false;
if(other.redoDelay != redoDelay)
return false;
if(other.stages.equals(stages) == false)
return false;
if(other.stages.equals(stages) == false)
} return false;
return true; }
} return true;
} }
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff