mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-22 10:36:09 +01:00
Return set of progress-applied quest IDs, per #1570
This commit is contained in:
parent
49da2b01c8
commit
81bddd246c
@ -15,12 +15,14 @@ package me.blackvein.quests;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentSkipListSet;
|
||||
@ -4022,38 +4024,41 @@ public class Quester implements Comparable<Quester> {
|
||||
* @param type The type of objective to progress
|
||||
* @param fun The function to execute, the event call
|
||||
*/
|
||||
public void dispatchMultiplayerEverything(final Quest quest, final ObjectiveType type, final BiFunction<Quester, Quest, Void> fun) {
|
||||
if (quest == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (quest.getOptions().getShareProgressLevel() == 1) {
|
||||
final List<Quester> mq = getMultiplayerQuesters(quest);
|
||||
if (mq == null) {
|
||||
return;
|
||||
}
|
||||
for (final Quester q : mq) {
|
||||
if (q == null) {
|
||||
continue;
|
||||
public Set<String> dispatchMultiplayerEverything(final Quest quest, final ObjectiveType type, final BiFunction<Quester, Quest, Void> fun) {
|
||||
final Set<String> appliedQuestIDs = new HashSet<String>();
|
||||
if (quest != null) {
|
||||
try {
|
||||
if (quest.getOptions().getShareProgressLevel() == 1) {
|
||||
final List<Quester> mq = getMultiplayerQuesters(quest);
|
||||
if (mq == null) {
|
||||
return appliedQuestIDs;
|
||||
}
|
||||
if (quest.getOptions().canShareSameQuestOnly()) {
|
||||
if (q.getCurrentStage(quest) != null) {
|
||||
fun.apply(q, quest);
|
||||
for (final Quester q : mq) {
|
||||
if (q == null) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
q.getCurrentQuests().forEach((otherQuest, i) -> {
|
||||
if (otherQuest.getStage(i).containsObjective(type)) {
|
||||
fun.apply(q, otherQuest);
|
||||
if (quest.getOptions().canShareSameQuestOnly()) {
|
||||
if (q.getCurrentStage(quest) != null) {
|
||||
fun.apply(q, quest);
|
||||
appliedQuestIDs.add(quest.getId());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
q.getCurrentQuests().forEach((otherQuest, i) -> {
|
||||
if (otherQuest.getStage(i).containsObjective(type)) {
|
||||
fun.apply(q, otherQuest);
|
||||
appliedQuestIDs.add(otherQuest.getId());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
plugin.getLogger().severe("Error occurred while dispatching " + type.name() + " for quest ID "
|
||||
+ quest.getId());
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
plugin.getLogger().severe("Error occurred while dispatching " + type.name() + " for quest ID "
|
||||
+ quest.getId());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return appliedQuestIDs;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,6 +13,9 @@
|
||||
|
||||
package me.blackvein.quests.listeners;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
@ -57,7 +60,7 @@ public class BlockListener implements Listener {
|
||||
final ObjectiveType breakType = ObjectiveType.BREAK_BLOCK;
|
||||
final ObjectiveType placeType = ObjectiveType.PLACE_BLOCK;
|
||||
final ObjectiveType cutType = ObjectiveType.CUT_BLOCK;
|
||||
boolean dispatched = false;
|
||||
final Set<String> dispatchedQuestIDs = new HashSet<String>();
|
||||
for (final Quest quest : plugin.getQuests()) {
|
||||
if (evt.isCancelled() == false) {
|
||||
if (!quester.meetsCondition(quest, true)) {
|
||||
@ -73,13 +76,13 @@ public class BlockListener implements Listener {
|
||||
quester.breakBlock(quest, blockItemStack);
|
||||
|
||||
// Multiplayer
|
||||
if (!dispatched) {
|
||||
quester.dispatchMultiplayerEverything(quest, breakType, (final Quester q, final Quest cq) -> {
|
||||
if (!dispatchedQuestIDs.contains(quest.getId())) {
|
||||
dispatchedQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, breakType,
|
||||
(final Quester q, final Quest cq) -> {
|
||||
q.breakBlock(cq, blockItemStack);
|
||||
return null;
|
||||
});
|
||||
}));
|
||||
}
|
||||
dispatched = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,10 +97,9 @@ public class BlockListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
final ObjectiveType type = ObjectiveType.PLACE_BLOCK;
|
||||
final QuesterPreUpdateObjectiveEvent preEvent
|
||||
= new QuesterPreUpdateObjectiveEvent(quester, quest,
|
||||
new Objective(type, is.getAmount(), toPlace.getAmount()));
|
||||
new Objective(placeType, is.getAmount(), toPlace.getAmount()));
|
||||
plugin.getServer().getPluginManager().callEvent(preEvent);
|
||||
|
||||
final int index = quester.getQuestData(quest).blocksPlaced.indexOf(is);
|
||||
@ -107,7 +109,7 @@ public class BlockListener implements Listener {
|
||||
|
||||
final QuesterPostUpdateObjectiveEvent postEvent
|
||||
= new QuesterPostUpdateObjectiveEvent(quester, quest,
|
||||
new Objective(type, newAmount, toPlace.getAmount()));
|
||||
new Objective(placeType, newAmount, toPlace.getAmount()));
|
||||
plugin.getServer().getPluginManager().callEvent(postEvent);
|
||||
}
|
||||
}
|
||||
@ -122,10 +124,9 @@ public class BlockListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
final ObjectiveType type = ObjectiveType.PLACE_BLOCK;
|
||||
final QuesterPreUpdateObjectiveEvent preEvent
|
||||
= new QuesterPreUpdateObjectiveEvent(q, cq,
|
||||
new Objective(type, is.getAmount(), toPlace.getAmount()));
|
||||
new Objective(placeType, is.getAmount(), toPlace.getAmount()));
|
||||
plugin.getServer().getPluginManager().callEvent(preEvent);
|
||||
|
||||
final int index = q.getQuestData(cq).blocksPlaced.indexOf(is);
|
||||
@ -135,7 +136,7 @@ public class BlockListener implements Listener {
|
||||
|
||||
final QuesterPostUpdateObjectiveEvent postEvent
|
||||
= new QuesterPostUpdateObjectiveEvent(q, cq,
|
||||
new Objective(type, newAmount, toPlace.getAmount()));
|
||||
new Objective(placeType, newAmount, toPlace.getAmount()));
|
||||
plugin.getServer().getPluginManager().callEvent(postEvent);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user