Improve getters/setters for QuestData

This commit is contained in:
PikaMug 2020-01-19 02:25:04 -05:00
parent c6d6acf692
commit 669d93887a
6 changed files with 72 additions and 41 deletions

View File

@ -224,8 +224,8 @@ public class Quest {
}
}
if (quester.getQuestData(this) != null) {
quester.getQuestData(this).delayStartTime = 0;
quester.getQuestData(this).delayTimeLeft = -1;
quester.getQuestData(this).setDelayStartTime(0);
quester.getQuestData(this).setDelayTimeLeft(-1);
}
// Multiplayer

View File

@ -1257,27 +1257,57 @@ public class QuestData {
private int fishCaught = 0;
private int playersKilled = 0;
public long delayStartTime = 0;
public long delayTimeLeft = -1;
public boolean delayOver = true;
public void setFishCaught(int i) {
fishCaught = i;
if (doJournalUpdate)
quester.updateJournal();
}
public void setPlayersKilled(int i) {
playersKilled = i;
if (doJournalUpdate)
quester.updateJournal();
}
private long delayStartTime = 0;
private long delayTimeLeft = -1;
private boolean delayOver = true;
public int getFishCaught() {
return fishCaught;
}
public void setFishCaught(int fishCaught) {
this.fishCaught = fishCaught;
if (doJournalUpdate)
quester.updateJournal();
}
public int getPlayersKilled() {
return playersKilled;
}
public void setPlayersKilled(int playersKilled) {
this.playersKilled = playersKilled;
if (doJournalUpdate)
quester.updateJournal();
}
public long getDelayStartTime() {
return delayStartTime;
}
public void setDelayStartTime(long delayStartTime) {
this.delayStartTime = delayStartTime;
if (doJournalUpdate)
quester.updateJournal();
}
public long getDelayTimeLeft() {
return delayTimeLeft;
}
public void setDelayTimeLeft(long delayTimeLeft) {
this.delayTimeLeft = delayTimeLeft;
if (doJournalUpdate)
quester.updateJournal();
}
public boolean isDelayOver() {
return delayOver;
}
public void setDelayOver(boolean delayOver) {
this.delayOver = delayOver;
if (doJournalUpdate)
quester.updateJournal();
}
}

View File

@ -2648,8 +2648,8 @@ public class Quester {
questSec.set("custom-objectives", customObj);
questSec.set("custom-objective-counts", customObjCounts);
}
if (questData.delayTimeLeft > 0) {
questSec.set("stage-delay", questData.delayTimeLeft);
if (questData.getDelayTimeLeft() > 0) {
questSec.set("stage-delay", questData.getDelayTimeLeft());
}
if (questData.actionFired.isEmpty() == false) {
LinkedList<String> chatTriggers = new LinkedList<String>();
@ -3077,7 +3077,7 @@ public class Quester {
}
}
if (questSec.contains("stage-delay")) {
getQuestData(quest).delayTimeLeft = questSec.getLong("stage-delay");
getQuestData(quest).setDelayTimeLeft(questSec.getLong("stage-delay"));
}
if (getCurrentStage(quest).chatActions.isEmpty() == false) {
for (String chatTrig : getCurrentStage(quest).chatActions.keySet()) {
@ -3111,9 +3111,9 @@ public class Quester {
* @param quest The quest of which the timer is for
*/
public void startStageTimer(Quest quest) {
if (getQuestData(quest).delayTimeLeft > -1) {
if (getQuestData(quest).getDelayTimeLeft() > -1) {
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new StageTimer(plugin, this, quest),
(long) (getQuestData(quest).delayTimeLeft * 0.02));
(long) (getQuestData(quest).getDelayTimeLeft() * 0.02));
} else {
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new StageTimer(plugin, this, quest),
(long) (getCurrentStage(quest).delay * 0.02));
@ -3123,7 +3123,7 @@ public class Quester {
.delayMessage), quest, p));
}
}
getQuestData(quest).delayStartTime = System.currentTimeMillis();
getQuestData(quest).setDelayStartTime(System.currentTimeMillis());
}
/**
@ -3131,14 +3131,14 @@ public class Quester {
* @param quest The quest of which the timer is for
*/
public void stopStageTimer(Quest quest) {
if (getQuestData(quest).delayTimeLeft > -1) {
getQuestData(quest).delayTimeLeft = getQuestData(quest).delayTimeLeft - (System.currentTimeMillis()
- getQuestData(quest).delayStartTime);
if (getQuestData(quest).getDelayTimeLeft() > -1) {
getQuestData(quest).setDelayTimeLeft(getQuestData(quest).getDelayTimeLeft() - (System.currentTimeMillis()
- getQuestData(quest).getDelayStartTime()));
} else {
getQuestData(quest).delayTimeLeft = getCurrentStage(quest).delay - (System.currentTimeMillis()
- getQuestData(quest).delayStartTime);
getQuestData(quest).setDelayTimeLeft(getCurrentStage(quest).delay - (System.currentTimeMillis()
- getQuestData(quest).getDelayStartTime()));
}
getQuestData(quest).delayOver = false;
getQuestData(quest).setDelayOver(false);
}
/**
@ -3147,11 +3147,11 @@ public class Quester {
* @return Remaining time in milliseconds
*/
public long getStageTime(Quest quest) {
if (getQuestData(quest).delayTimeLeft > -1) {
return getQuestData(quest).delayTimeLeft - (System.currentTimeMillis()
- getQuestData(quest).delayStartTime);
if (getQuestData(quest).getDelayTimeLeft() > -1) {
return getQuestData(quest).getDelayTimeLeft() - (System.currentTimeMillis()
- getQuestData(quest).getDelayStartTime());
} else {
return getCurrentStage(quest).delay - (System.currentTimeMillis() - getQuestData(quest).delayStartTime);
return getCurrentStage(quest).delay - (System.currentTimeMillis() - getQuestData(quest).getDelayStartTime());
}
}

View File

@ -179,7 +179,7 @@ public class CmdExecutor implements CommandExecutor {
for (Quest q : quester.getCurrentQuests().keySet()) {
Stage stage = quester.getCurrentStage(q);
q.updateCompass(quester, stage);
if (plugin.getQuester(player.getUniqueId()).getQuestData(q).delayStartTime == 0) {
if (plugin.getQuester(player.getUniqueId()).getQuestData(q).getDelayStartTime() == 0) {
String msg = Lang.get(player, "questObjectivesTitle");
msg = msg.replace("<quest>", q.getName());
player.sendMessage(ChatColor.GOLD + msg);

View File

@ -959,7 +959,8 @@ public class PlayerListener implements Listener {
quester.checkQuest(quest);
}
for (Quest quest : quester.getCurrentQuests().keySet()) {
if (quester.getCurrentStage(quest).getDelay() > -1 && quester.getQuestData(quest).delayOver == false) {
if (quester.getCurrentStage(quest).getDelay() > -1
&& quester.getQuestData(quest).isDelayOver() == false) {
quester.startStageTimer(quest);
}
}

View File

@ -43,7 +43,7 @@ public class StageTimer implements Runnable {
if (quester.getQuestData(quest) == null) {
return;
}
if (quester.getQuestData(quest).delayOver) {
if (quester.getQuestData(quest).isDelayOver()) {
if (quest.getStages().indexOf(quester.getCurrentStage(quest)) == (quest.getStages().size() - 1)) {
if (quester.getCurrentStage(quest).getScript() != null) {
plugin.getDependencies().runDenizenScript(quester.getCurrentStage(quest).getScript(), quester);
@ -66,8 +66,8 @@ public class StageTimer implements Runnable {
quester.addEmptiesFor(quest, stageNum);
// Added this line at some point, not sure why. Commented out to fix Github #726
//quester.getCurrentStage(quest).setDelay(-1);
quester.getQuestData(quest).delayStartTime = 0;
quester.getQuestData(quest).delayTimeLeft = -1;
quester.getQuestData(quest).setDelayStartTime(0);
quester.getQuestData(quest).setDelayTimeLeft(-1);
Action stageStartEvent = quester.getCurrentStage(quest).getStartAction();
if (stageStartEvent != null) {
stageStartEvent.fire(quester, quest);
@ -84,7 +84,7 @@ public class StageTimer implements Runnable {
}
}
if (quester.getQuestData(quest) != null) {
quester.getQuestData(quest).delayOver = true;
quester.getQuestData(quest).setDelayOver(true);
}
quester.updateJournal();
}