Improved and fixed share progress level 3

This commit is contained in:
AlessioDP 2019-09-10 00:40:01 +02:00
parent 49bcf4b5f8
commit 5ef3e4a2b1
No known key found for this signature in database
GPG Key ID: B92B813840FFCC9F
3 changed files with 1431 additions and 1408 deletions

View File

@ -160,12 +160,13 @@ public class Quest {
* *
* @param q Player to force * @param q Player to force
*/ */
public void nextStage(Quester q) { public void nextStage(Quester q, boolean enableShareProgress) {
if (q.getCurrentStage(this) == null) { Stage currentStage = q.getCurrentStage(this);
if (currentStage == null) {
plugin.getLogger().severe("Current stage was null for quester " + q.getPlayer().getUniqueId()); plugin.getLogger().severe("Current stage was null for quester " + q.getPlayer().getUniqueId());
return; return;
} }
String stageCompleteMessage = q.getCurrentStage(this).completeMessage; String stageCompleteMessage = currentStage.completeMessage;
if (stageCompleteMessage != null) { if (stageCompleteMessage != null) {
q.getPlayer().sendMessage(plugin.parseStringWithPossibleLineBreaks(stageCompleteMessage, this, q.getPlayer())); q.getPlayer().sendMessage(plugin.parseStringWithPossibleLineBreaks(stageCompleteMessage, this, q.getPlayer()));
} }
@ -173,19 +174,29 @@ public class Quest {
q.resetCompass(); q.resetCompass();
q.findCompassTarget(); q.findCompassTarget();
} }
if (q.getCurrentStage(this).delay < 0) { if (currentStage.delay < 0) {
if (q.currentQuests.get(this) == (orderedStages.size() - 1)) { if (q.currentQuests.get(this) == (orderedStages.size() - 1)) {
if (q.getCurrentStage(this).script != null) { if (currentStage.script != null) {
plugin.getDenizenTrigger().runDenizenScript(q.getCurrentStage(this).script, q); plugin.getDenizenTrigger().runDenizenScript(currentStage.script, q);
} }
if (q.getCurrentStage(this).finishEvent != null) { if (currentStage.finishEvent != null) {
q.getCurrentStage(this).finishEvent.fire(q, this); currentStage.finishEvent.fire(q, this);
} }
completeQuest(q); completeQuest(q);
// Multiplayer
if (enableShareProgress && opts.getShareProgressLevel() == 3) {
List<Quester> mq = q.getMultiplayerQuestersByQuest(this);
for (Quester qq : mq) {
if (currentStage.equals(qq.getCurrentStage(this))) {
completeQuest(qq);
}
}
}
} else { } else {
try { try {
if (q.getCurrentStage(this).finishEvent != null) { if (currentStage.finishEvent != null) {
q.getCurrentStage(this).finishEvent.fire(q, this); currentStage.finishEvent.fire(q, this);
} }
setStage(q, q.currentQuests.get(this) + 1); setStage(q, q.currentQuests.get(this) + 1);
} catch (InvalidStageException e) { } catch (InvalidStageException e) {
@ -193,15 +204,13 @@ public class Quest {
} }
// Multiplayer // Multiplayer
try { if (enableShareProgress && opts.getShareProgressLevel() == 3) {
if (opts.getShareProgressLevel() == 3) { List<Quester> mq = q.getMultiplayerQuestersByQuest(this);
List<Quester> mq = q.getMultiplayerQuestersByQuest(this); for (Quester qq : mq) {
for (Quester qq : mq) { if (currentStage.equals(qq.getCurrentStage(this))) {
setStage(qq, qq.currentQuests.get(this) + 1); nextStage(qq, false);
} }
} }
} catch (InvalidStageException e) {
e.printStackTrace();
} }
} }
if (q.getQuestData(this) != null) { if (q.getQuestData(this) != null) {

View File

@ -1975,17 +1975,31 @@ public class Quester {
} }
p.sendMessage(message); p.sendMessage(message);
} }
Stage currentStage = getCurrentStage(quest);
if (testComplete(quest)) { if (testComplete(quest)) {
quest.nextStage(this); quest.nextStage(this, true);
} }
// Multiplayer // Multiplayer
/* wip new method
if (true && quest.getOptions().getShareProgressLevel() == 2) {
List<Quester> mq = getMultiplayerQuestersByQuest(this);
for (Quester qq : mq) {
if (currentStage.equals(qq.getCurrentStage(quest))) {
completeQuest(qq);
}
}
}
*/
/* old method
if (quest.getOptions().getShareProgressLevel() == 2) { if (quest.getOptions().getShareProgressLevel() == 2) {
List<Quester> mq = getMultiplayerQuestersByQuest(quest); List<Quester> mq = getMultiplayerQuestersByQuest(quest);
for (Quester q : mq) { for (Quester q : mq) {
quest.nextStage(q); if (q.getCurrentStage(quest).equals(this.getCurrentStage(quest))) {
quest.nextStage(q, false);
}
} }
} }*/
} }
/** /**

View File

@ -1121,7 +1121,7 @@ public class CmdExecutor implements CommandExecutor {
msg2 = msg2.replace("<player>", ChatColor.GREEN + cs.getName() + ChatColor.GOLD); msg2 = msg2.replace("<player>", ChatColor.GREEN + cs.getName() + ChatColor.GOLD);
msg2 = msg2.replace("<quest>", ChatColor.DARK_PURPLE + quest.getName() + ChatColor.GOLD); msg2 = msg2.replace("<quest>", ChatColor.DARK_PURPLE + quest.getName() + ChatColor.GOLD);
target.sendMessage(ChatColor.GREEN + msg2); target.sendMessage(ChatColor.GREEN + msg2);
quest.nextStage(quester); quest.nextStage(quester, false);
quester.saveData(); quester.saveData();
} }
} }