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