mirror of
https://github.com/PikaMug/Quests.git
synced 2025-01-27 02:31:48 +01:00
Added multiplayer enabled check
This commit is contained in:
parent
3ff05fb5a8
commit
07356c72d5
@ -195,15 +195,11 @@ public class Quest {
|
|||||||
// Multiplayer
|
// Multiplayer
|
||||||
try {
|
try {
|
||||||
if (opts.getShareProgressLevel() == 3) {
|
if (opts.getShareProgressLevel() == 3) {
|
||||||
List<Quester> mq = q.getMultiplayerQuesters();
|
List<Quester> mq = q.getMultiplayerQuestersByQuest(this);
|
||||||
if (mq != null) {
|
|
||||||
for (Quester qq : mq) {
|
for (Quester qq : mq) {
|
||||||
if (qq.getCurrentQuests().containsKey(this)) {
|
|
||||||
setStage(qq, qq.currentQuests.get(this) + 1);
|
setStage(qq, qq.currentQuests.get(this) + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (InvalidStageException e) {
|
} catch (InvalidStageException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -691,16 +687,12 @@ public class Quest {
|
|||||||
|
|
||||||
// Multiplayer
|
// Multiplayer
|
||||||
if (opts.getShareProgressLevel() == 4) {
|
if (opts.getShareProgressLevel() == 4) {
|
||||||
List<Quester> mq = q.getMultiplayerQuesters();
|
List<Quester> mq = q.getMultiplayerQuestersByQuest(this);
|
||||||
if (mq != null) {
|
|
||||||
for (Quester qq : mq) {
|
for (Quester qq : mq) {
|
||||||
if (qq.getCurrentQuests().containsKey(this)) {
|
|
||||||
completeQuest(qq);
|
completeQuest(qq);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Force player to quit quest and inform them of their failure
|
* Force player to quit quest and inform them of their failure
|
||||||
|
@ -1981,16 +1981,12 @@ public class Quester {
|
|||||||
|
|
||||||
// Multiplayer
|
// Multiplayer
|
||||||
if (quest.getOptions().getShareProgressLevel() == 2) {
|
if (quest.getOptions().getShareProgressLevel() == 2) {
|
||||||
List<Quester> mq = getMultiplayerQuesters();
|
List<Quester> mq = getMultiplayerQuestersByQuest(quest);
|
||||||
if (mq != null) {
|
|
||||||
for (Quester q : mq) {
|
for (Quester q : mq) {
|
||||||
if (q.getCurrentQuests().containsKey(quest)) {
|
|
||||||
quest.nextStage(q);
|
quest.nextStage(q);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether this Quester has completed all objectives for their current stage
|
* Check whether this Quester has completed all objectives for their current stage
|
||||||
@ -3120,49 +3116,83 @@ public class Quester {
|
|||||||
* @param fun The function to execute, the event call
|
* @param fun The function to execute, the event call
|
||||||
*/
|
*/
|
||||||
public void dispatchMultiplayerEvent(String eventName, BiFunction<Quester, Quest, Void> fun) {
|
public void dispatchMultiplayerEvent(String eventName, BiFunction<Quester, Quest, Void> fun) {
|
||||||
List<Quester> mq = getMultiplayerQuesters();
|
Map<Quester, MultiplayerType> mq = getMultiplayerQuesters();
|
||||||
if (mq != null) {
|
for (Entry<Quester, MultiplayerType> q : mq.entrySet()) {
|
||||||
for (Quester q : mq) {
|
for (Quest quest : q.getKey().getCurrentQuests().keySet()) {
|
||||||
for (Quest quest : q.getCurrentQuests().keySet()) {
|
if (q.getKey().containsObjective(quest, eventName)
|
||||||
if (q.containsObjective(quest, eventName) && quest.getOptions().getShareProgressLevel() == 1) {
|
&& quest.getOptions().getShareProgressLevel() == 1
|
||||||
fun.apply(q, quest);
|
&& ((quest.getOptions().getUsePartiesPlugin() && q.getValue().parties)
|
||||||
}
|
|| (quest.getOptions().getUseDungeonsXLPlugin() && q.getValue().dungeonxl))) {
|
||||||
|
fun.apply(q.getKey(), quest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of fellow Questers in a party or group
|
* Get a map of fellow Questers in a party or group
|
||||||
*
|
*
|
||||||
* @return null if no linked plugins, or party/group is null
|
* @return empty if no linked plugins, or party/group is null
|
||||||
*/
|
*/
|
||||||
public List<Quester> getMultiplayerQuesters() {
|
public Map<Quester, MultiplayerType> getMultiplayerQuesters() {
|
||||||
|
Map<Quester, MultiplayerType> ret = new LinkedHashMap<>();
|
||||||
if (plugin.getDependencies().getPartiesApi() != null) {
|
if (plugin.getDependencies().getPartiesApi() != null) {
|
||||||
Party party = plugin.getDependencies().getPartiesApi().getParty(plugin.getDependencies().getPartiesApi().getPartyPlayer(getUUID()).getPartyName());
|
Party party = plugin.getDependencies().getPartiesApi().getParty(plugin.getDependencies().getPartiesApi().getPartyPlayer(getUUID()).getPartyName());
|
||||||
if (party != null) {
|
if (party != null) {
|
||||||
List<Quester> mq = new LinkedList<Quester>();
|
|
||||||
for (UUID id : party.getMembers()) {
|
for (UUID id : party.getMembers()) {
|
||||||
if (!id.equals(getUUID())) {
|
if (!id.equals(getUUID())) {
|
||||||
mq.add(plugin.getQuester(id));
|
ret.put(plugin.getQuester(id), new MultiplayerType(true, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mq;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (plugin.getDependencies().getDungeonsApi() != null) {
|
if (plugin.getDependencies().getDungeonsApi() != null) {
|
||||||
DGroup group = DGroup.getByPlayer(getPlayer());
|
DGroup group = DGroup.getByPlayer(getPlayer());
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
List<Quester> mq = new LinkedList<Quester>();
|
|
||||||
for (UUID id : group.getPlayers()) {
|
for (UUID id : group.getPlayers()) {
|
||||||
if (!id.equals(getUUID())) {
|
if (!id.equals(getUUID())) {
|
||||||
mq.add(plugin.getQuester(id));
|
Quester q = plugin.getQuester(id);
|
||||||
|
if (ret.containsKey(plugin.getQuester(id)))
|
||||||
|
ret.get(q).dungeonxl = true;
|
||||||
|
else
|
||||||
|
ret.put(q, new MultiplayerType(false, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mq;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a map of fellow Questers in a party or group
|
||||||
|
* that are doing the given quest
|
||||||
|
*
|
||||||
|
* @param quest the quest to check
|
||||||
|
* @return empty if no linked plugins, or party/group is null
|
||||||
|
*/
|
||||||
|
public List<Quester> getMultiplayerQuestersByQuest(Quest quest) {
|
||||||
|
List<Quester> ret = new LinkedList<>();
|
||||||
|
Map<Quester, MultiplayerType> mq = getMultiplayerQuesters();
|
||||||
|
for (Entry<Quester, MultiplayerType> q : mq.entrySet()) {
|
||||||
|
if (q.getKey().getCurrentQuests().containsKey(quest)) {
|
||||||
|
if ((quest.getOptions().getUsePartiesPlugin() && q.getValue().parties)
|
||||||
|
|| (quest.getOptions().getUseDungeonsXLPlugin() && q.getValue().dungeonxl)) {
|
||||||
|
ret.add(q.getKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MultiplayerType {
|
||||||
|
public boolean parties;
|
||||||
|
public boolean dungeonxl;
|
||||||
|
|
||||||
|
public MultiplayerType(boolean parties, boolean dungeonxl) {
|
||||||
|
this.parties = parties;
|
||||||
|
this.dungeonxl = dungeonxl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user