Improve compass resetting behavior with multiple active quests

This commit is contained in:
Nathan Wolf 2016-02-29 12:12:57 -08:00
parent d9b0acd73f
commit 8ca0e797a4
3 changed files with 35 additions and 19 deletions

View File

@ -875,6 +875,10 @@ public class PlayerListener implements Listener, ColorUtil {
plugin.questers.put(evt.getPlayer().getUniqueId(), quester);
if (Quests.getInstance().useCompass) {
quester.resetCompass();
}
for (String s : quester.completedQuests) {
Quest q = plugin.getQuest(s);

View File

@ -89,7 +89,10 @@ public class Quest {
if (stageCompleteMessage != null) {
q.getPlayer().sendMessage(Quests.parseString(stageCompleteMessage, this));
}
resetCompass(q);
if (Quests.getInstance().useCompass) {
q.resetCompass();
q.findCompassTarget();
}
if (q.getCurrentStage(this).delay < 0) {
@ -171,14 +174,13 @@ public class Quest {
}
public void updateCompass(Quester quester, Stage nextStage)
public boolean updateCompass(Quester quester, Stage nextStage)
{
if (!Quests.getInstance().useCompass) return;
if (!Quests.getInstance().useCompass) return false;
Location targetLocation = null;
if (nextStage == null) {
resetCompass(quester);
return;
return false;
}
if (nextStage.citizensToInteract != null && nextStage.citizensToInteract.size() > 0)
{
@ -194,21 +196,9 @@ public class Quest {
}
if (targetLocation != null) {
quester.getPlayer().setCompassTarget(targetLocation);
} else {
resetCompass(quester);
}
}
protected void resetCompass(Quester q) {
if (!Quests.getInstance().useCompass) return;
Player player = q.getPlayer();
if (player == null) return;
Location defaultLocation = player.getBedSpawnLocation();
if (defaultLocation == null) {
defaultLocation = player.getWorld().getSpawnLocation();
}
player.setCompassTarget(defaultLocation);
return targetLocation != null;
}
public String getName() {

View File

@ -3466,5 +3466,27 @@ if (quest != null) {
}
}
public void resetCompass() {
if (!Quests.getInstance().useCompass) return;
Player player = getPlayer();
if (player == null) return;
Location defaultLocation = player.getBedSpawnLocation();
if (defaultLocation == null) {
defaultLocation = player.getWorld().getSpawnLocation();
}
player.setCompassTarget(defaultLocation);
}
public void findCompassTarget() {
if (!Quests.getInstance().useCompass) return;
Player player = getPlayer();
if (player == null) return;
for (Quest quest : currentQuests.keySet()) {
Stage stage = getCurrentStage(quest);
if (stage != null && quest.updateCompass(this, stage)) break;
}
}
}