From 669d93887ad378dd652263e0bff128977104c158 Mon Sep 17 00:00:00 2001 From: PikaMug Date: Sun, 19 Jan 2020 02:25:04 -0500 Subject: [PATCH] Improve getters/setters for QuestData --- .../main/java/me/blackvein/quests/Quest.java | 4 +- .../java/me/blackvein/quests/QuestData.java | 64 ++++++++++++++----- .../java/me/blackvein/quests/Quester.java | 32 +++++----- .../quests/listeners/CmdExecutor.java | 2 +- .../quests/listeners/PlayerListener.java | 3 +- .../me/blackvein/quests/tasks/StageTimer.java | 8 +-- 6 files changed, 72 insertions(+), 41 deletions(-) diff --git a/main/src/main/java/me/blackvein/quests/Quest.java b/main/src/main/java/me/blackvein/quests/Quest.java index 689407a91..a60e59ffe 100644 --- a/main/src/main/java/me/blackvein/quests/Quest.java +++ b/main/src/main/java/me/blackvein/quests/Quest.java @@ -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 diff --git a/main/src/main/java/me/blackvein/quests/QuestData.java b/main/src/main/java/me/blackvein/quests/QuestData.java index 433d4e68a..f35886999 100644 --- a/main/src/main/java/me/blackvein/quests/QuestData.java +++ b/main/src/main/java/me/blackvein/quests/QuestData.java @@ -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(); + } } diff --git a/main/src/main/java/me/blackvein/quests/Quester.java b/main/src/main/java/me/blackvein/quests/Quester.java index 4968389df..6f6f95094 100644 --- a/main/src/main/java/me/blackvein/quests/Quester.java +++ b/main/src/main/java/me/blackvein/quests/Quester.java @@ -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 chatTriggers = new LinkedList(); @@ -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()); } } diff --git a/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java b/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java index d246e3278..924a86fb0 100644 --- a/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java +++ b/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java @@ -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("", q.getName()); player.sendMessage(ChatColor.GOLD + msg); diff --git a/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java b/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java index 34938d001..5a17182ea 100644 --- a/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java +++ b/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java @@ -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); } } diff --git a/main/src/main/java/me/blackvein/quests/tasks/StageTimer.java b/main/src/main/java/me/blackvein/quests/tasks/StageTimer.java index ff99a30fb..6fe464712 100644 --- a/main/src/main/java/me/blackvein/quests/tasks/StageTimer.java +++ b/main/src/main/java/me/blackvein/quests/tasks/StageTimer.java @@ -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(); }