Almost finished Stage time delay

> Add time delay reading to loadQuests()
This commit is contained in:
Blackvein 2012-10-31 08:19:29 -07:00
parent ce2aabc98e
commit 028e33f7cf
4 changed files with 176 additions and 112 deletions

View File

@ -693,12 +693,12 @@ public class PlayerListener implements Listener {
Player player = evt.getPlayer();
if(plugin.checkQuester(player.getName()) == false){
Quester quester = plugin.getQuester(player.getName());
if (quester.hasObjective("catchFish") && evt.getState().equals(State.CAUGHT_FISH)) {
quester.catchFish();
}
}
}
@ -707,7 +707,7 @@ public class PlayerListener implements Listener {
public void onPlayerDropItem(PlayerDropItemEvent evt) {
if(plugin.checkQuester(evt.getPlayer().getName()) == false){
Quester quester = plugin.getQuester(evt.getPlayer().getName());
if (quester.currentQuest != null) {
@ -719,7 +719,7 @@ public class PlayerListener implements Listener {
}
}
}
}
@ -728,7 +728,7 @@ public class PlayerListener implements Listener {
public void onPlayerJoin(PlayerJoinEvent evt) {
if(plugin.checkQuester(evt.getPlayer().getName()) == false){
Quester quester = new Quester(plugin);
quester.name = evt.getPlayer().getName();
if (new File(plugin.getDataFolder(), "data/" + quester.name + ".yml").exists()) {
@ -740,23 +740,29 @@ public class PlayerListener implements Listener {
for (String s : quester.completedQuests) {
for (Quest q : plugin.quests) {
Quest q = plugin.getQuest(s);
if (q.name.equalsIgnoreCase(s)) {
if (quester.completedTimes.containsKey(q.name) == false && q.redoDelay > -1) {
quester.completedTimes.put(q.name, System.currentTimeMillis());
}
}
if (q != null) {
if (quester.completedTimes.containsKey(q.name) == false && q.redoDelay > -1)
quester.completedTimes.put(q.name, System.currentTimeMillis());
}
}
quester.checkQuest();
if(quester.currentQuest != null){
if(quester.currentStage.delay > -1){
quester.startStageTimer();
}
}
}
}
@ -765,11 +771,13 @@ public class PlayerListener implements Listener {
public void onPlayerQuit(PlayerQuitEvent evt) {
if(plugin.checkQuester(evt.getPlayer().getName()) == false){
Quester quester = plugin.getQuester(evt.getPlayer().getName());
if(quester.currentStage.delay > -1)
quester.stopStageTimer();
quester.saveData();
plugin.questers.remove(quester.name);
}
}
@ -778,7 +786,7 @@ public class PlayerListener implements Listener {
public void onPlayerMove(PlayerMoveEvent evt) {
if(plugin.checkQuester(evt.getPlayer().getName()) == false){
boolean isPlayer = true;
if (plugin.getServer().getPluginManager().getPlugin("Citizens") != null) {
if (plugin.citizens.getNPCRegistry().isNPC(evt.getPlayer())) {
@ -797,7 +805,7 @@ public class PlayerListener implements Listener {
}
}
}
}

View File

@ -62,35 +62,46 @@ public class Quest {
//
public void nextStage(Quester q){
Player player = plugin.getServer().getPlayerExact(q.name);
if(q.currentStage.delay < 0){
if(stages.indexOf(q.currentStage) == (stages.size() - 1)){
Player player = plugin.getServer().getPlayerExact(q.name);
if(q.currentStage.script != null)
plugin.trigger.parseQuestTaskTrigger(q.currentStage.script, player);
if(q.currentStage.event != null)
q.currentStage.event.happen(player);
completeQuest(q);
if(stages.indexOf(q.currentStage) == (stages.size() - 1)){
}else {
if(q.currentStage.script != null)
plugin.trigger.parseQuestTaskTrigger(q.currentStage.script, player);
if(q.currentStage.event != null)
q.currentStage.event.happen(player);
q.reset();
player.sendMessage(plugin.parseString(q.currentStage.finished, q.currentQuest));
if(q.currentStage.script != null)
plugin.trigger.parseQuestTaskTrigger(q.currentStage.script, player);
if(q.currentStage.event != null)
q.currentStage.event.happen(player);
q.currentStage = stages.get(stages.indexOf(q.currentStage) + 1);
q.addEmpties();
completeQuest(q);
player.sendMessage(ChatColor.GOLD + "---(Objectives)---");
for(String s : q.getObjectives()){
}else {
player.sendMessage(s);
q.reset();
player.sendMessage(plugin.parseString(q.currentStage.finished, q.currentQuest));
if(q.currentStage.script != null)
plugin.trigger.parseQuestTaskTrigger(q.currentStage.script, player);
if(q.currentStage.event != null)
q.currentStage.event.happen(player);
q.currentStage = stages.get(stages.indexOf(q.currentStage) + 1);
q.addEmpties();
player.sendMessage(ChatColor.GOLD + "---(Objectives)---");
for(String s : q.getObjectives()){
player.sendMessage(s);
}
}
q.delayStartTime = 0;
q.delayTimeLeft = -1;
}else{
q.startStageTimer();
}
}
@ -98,7 +109,7 @@ public class Quest {
public String getName(){
return name;
}
public boolean testRequirements(Player player){
Quester quester = plugin.getQuester(player.getName());
@ -201,7 +212,7 @@ public class Quest {
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), s);
none = null;
}
for(String s : permissions){
@ -215,7 +226,7 @@ public class Quest {
Quests.mcmmo.getPlayerProfile(player.getName()).skillUp(Quests.getMcMMOSkill(s), mcmmoAmounts.get(mcmmoSkills.indexOf(s)));
none = null;
}
if(exp > 0){
@ -227,12 +238,12 @@ public class Quest {
plugin.heroes.getCharacterManager().getHero(player).gainExp(heroesExp, ExperienceType.QUESTING, player.getLocation());
none = null;
}
if(heroesClass != null){
plugin.heroes.getCharacterManager().getHero(player).changeHeroClass(plugin.heroes.getClassManager().getClass(heroesClass), false);
none = null;
}
if(heroesSecClass != null){
plugin.heroes.getCharacterManager().getHero(player).changeHeroClass(plugin.heroes.getClassManager().getClass(heroesSecClass), true);
none = null;

View File

@ -379,7 +379,7 @@ public class Quester {
}
}
for (NPC n : currentStage.citizensToKill) {
for (NPC n2 : citizensKilled) {
@ -884,20 +884,20 @@ public class Quester {
}
}
public void killNPC(NPC n) {
if(citizensKilled.contains(n)){
int index = citizensKilled.indexOf(n);
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, 0);
}
}
}
public void reachLocation(Location l) {
@ -1244,7 +1244,7 @@ public class Quester {
}
}
if (currentStage.citizensToKill.isEmpty() == false) {
for (NPC n : currentStage.citizensToKill) {
@ -1777,9 +1777,9 @@ public class Quester {
data.set("has-talked-to", hasTalked);
}
if(citizensKilled.isEmpty() == false) {
LinkedList<Integer> npcIds = new LinkedList<Integer>();
for (NPC n : citizensKilled) {
@ -1790,7 +1790,7 @@ public class Quester {
data.set("citizen-ids-killed", npcIds);
data.set("citizen-amounts-killed", citizenNumKilled);
}
if (locationsReached.isEmpty() == false) {
@ -1886,12 +1886,9 @@ public class Quester {
data.set("items-crafted", itemAmounts);
}
if(delayStartTime > 0){
}
if(delayTimeLeft > 0)
data.set("stage-delay", delayTimeLeft);
} else {
@ -2376,7 +2373,7 @@ public class Quester {
}
}
if (data.contains("citizen-ids-killed")) {
List<Integer> ids = data.getIntegerList("citizen-ids-killed");
@ -2559,11 +2556,11 @@ public class Quester {
}
}
if(data.contains("stage-delay")){
delayTimeLeft = data.getLong("stage-delay");
}
}
@ -2573,27 +2570,36 @@ public class Quester {
}
public void startStageTimer(){
if(delayTimeLeft > -1)
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new StageTimer(this), delayTimeLeft*50);
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new StageTimer(plugin, this), delayTimeLeft*50);
else
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new StageTimer(this), currentStage.delay);
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new StageTimer(plugin, this), currentStage.delay);
delayStartTime = System.currentTimeMillis();
}
public void stopTimer(){
public void stopStageTimer(){
if(delayTimeLeft > -1)
delayTimeLeft = delayTimeLeft - (System.currentTimeMillis() - delayStartTime);
else
delayTimeLeft = currentStage.delay - (System.currentTimeMillis() - delayStartTime);
delayOver = false;
}
public long getStageTime(){
if(delayTimeLeft > -1)
return delayTimeLeft - (System.currentTimeMillis() - delayStartTime);
else
return currentStage.delay - (System.currentTimeMillis() - delayStartTime);
}
public void checkQuest() {
if (currentQuest != null) {
@ -2636,80 +2642,80 @@ public class Quester {
}
}
public static String checkPlacement(Inventory inv, int rawSlot){
if(rawSlot < 0){
return "You may not drop Quest items.";
}
InventoryType type = inv.getType();
if(type.equals(InventoryType.BREWING)){
if(rawSlot < 4){
return "You may not brew using Quest items.";
}
}else if(type.equals(InventoryType.CHEST)){
if(inv.getContents().length == 27){
if(rawSlot < 27){
return "You may not store Quest items.";
}
}else {
if(rawSlot < 54){
return "You may not store Quest items.";
}
}
}else if(type.equals(InventoryType.CRAFTING)){
if(rawSlot < 5){
return "You may not craft using Quest items.";
}else if(rawSlot < 9){
return "You may not equip Quest items.";
}
}else if(type.equals(InventoryType.DISPENSER)){
if(rawSlot < 9){
return "You may not put Quest items in dispensers.";
}
}else if(type.equals(InventoryType.ENCHANTING)){
if(rawSlot == 0){
return "You may not enchant Quest items.";
}
}else if(type.equals(InventoryType.ENDER_CHEST)){
if(rawSlot < 27){
return "You may not store Quest items.";
}
}else if(type.equals(InventoryType.FURNACE)){
if(rawSlot < 3){
return "You may not smelt using Quest items.";
}
}else if(type.equals(InventoryType.WORKBENCH)){
if(rawSlot < 10){
return "You may not craft using Quest items.";
}
}
return null;
}
public static List<Integer> getChangedSlots(Inventory inInv, ItemStack inNew)
{
List<Integer> changed = new ArrayList<Integer>();
@ -2721,7 +2727,7 @@ public class Quester {
{
if(!items.containsKey((Integer)i))
continue;
ItemStack item = items.get((Integer)i);
int slotamount = item.getMaxStackSize() - item.getAmount();
if(slotamount > 1)
@ -2740,7 +2746,7 @@ public class Quester {
}
}
}
if(amount > 0)
{
if(inInv.firstEmpty() != -1)

View File

@ -1,24 +1,63 @@
package me.blackvein.quests;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
public class StageTimer implements Runnable{
Quester quester;
public StageTimer(Quester q){
Quests plugin;
public StageTimer(Quests quests, Quester q){
quester = q;
plugin = quests;
}
@Override
public void run(){
if(quester.delayOver){
quester.currentQuest.nextStage(quester);
Player player = plugin.getServer().getPlayerExact(quester.name);
if(quester.currentQuest.stages.indexOf(quester.currentStage) == (quester.currentQuest.stages.size() - 1)){
if(quester.currentStage.script != null)
plugin.trigger.parseQuestTaskTrigger(quester.currentStage.script, player);
if(quester.currentStage.event != null)
quester.currentStage.event.happen(player);
quester.currentQuest.completeQuest(quester);
}else {
quester.reset();
player.sendMessage(plugin.parseString(quester.currentStage.finished, quester.currentQuest));
if(quester.currentStage.script != null)
plugin.trigger.parseQuestTaskTrigger(quester.currentStage.script, player);
if(quester.currentStage.event != null)
quester.currentStage.event.happen(player);
quester.currentStage = quester.currentQuest.stages.get(quester.currentQuest.stages.indexOf(quester.currentStage) + 1);
quester.addEmpties();
player.sendMessage(ChatColor.GOLD + "---(Objectives)---");
for(String s : quester.getObjectives()){
player.sendMessage(s);
}
}
quester.delayStartTime = 0;
quester.delayTimeLeft = -1;
}
quester.delayOver = true;
}
}