Add support for Parties, tested. Fixes #281

This commit is contained in:
BuildTools 2019-01-05 23:55:33 -05:00
parent 665a0fb2fb
commit c991599936
3 changed files with 36 additions and 20 deletions

View File

@ -175,6 +175,19 @@ public class Quest {
if (q.getCurrentStage(this).finishEvent != null) {
q.getCurrentStage(this).finishEvent.fire(q, this);
}
if (Quests.parties != null) {
Party party = Quests.parties.getParty(Quests.parties.getPartyPlayer(q.getUUID()).getPartyName());
if (party != null) {
for (UUID id : party.getMembers()) {
if (!id.equals(q.getUUID())) {
if (plugin.getQuester(id).getCurrentQuests().containsKey(this)) {
completeQuest(plugin.getQuester(id));
}
}
}
plugin.getLogger().info("Quest \'" + name + "\' was completed by party " + party.getName() + " (" + party.getMembers().size() + " members)");
}
}
completeQuest(q);
} else {
try {
@ -684,14 +697,6 @@ public class Quest {
Quests.gpsapi.stopGPS(player);
}
}
if (Quests.parties != null) {
Party party = Quests.parties.getParty(Quests.parties.getPartyPlayer(q.getUUID()).getPartyName());
for (UUID id : party.getMembers()) {
if (q.getCurrentQuests().containsKey(this)) {
completeQuest(plugin.getQuester(id));
}
}
}
q.findCompassTarget();
}

View File

@ -97,6 +97,7 @@ import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import me.blackvein.quests.exceptions.InvalidStageException;
import me.blackvein.quests.listeners.NpcListener;
import me.blackvein.quests.listeners.PartiesListener;
import me.blackvein.quests.listeners.PlayerListener;
import me.blackvein.quests.prompts.QuestAcceptPrompt;
import me.blackvein.quests.util.ItemUtil;
@ -167,9 +168,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
public ConversationFactory NPCConversationFactory;
public QuestFactory questFactory;
public EventFactory eventFactory;
public PlayerListener pListener;
public PlayerListener playerListener;
public NpcListener npcListener;
public NpcEffectThread effListener;
public NpcEffectThread effThread;
public PartiesListener partiesListener;
public QuestTaskTrigger trigger;
public Lang lang = new Lang(this);
public LocaleQuery query = new LocaleQuery(this);
@ -185,9 +187,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
public void onEnable() {
bukkitVersion = Bukkit.getServer().getBukkitVersion().split("-")[0];
query.setBukkitVersion(bukkitVersion);
pListener = new PlayerListener(this);
effListener = new NpcEffectThread(this);
playerListener = new PlayerListener(this);
effThread = new NpcEffectThread(this);
npcListener = new NpcListener(this);
partiesListener = new PartiesListener();
questFactory = new QuestFactory(this);
eventFactory = new EventFactory(this);
linkOtherPlugins();
@ -218,9 +221,12 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
this.conversationFactory = new ConversationFactory(this).withModality(false).withPrefix(new QuestsPrefix()).withFirstPrompt(new QuestPrompt()).withTimeout(acceptTimeout).thatExcludesNonPlayersWithMessage("Console may not perform this conversation!").addConversationAbandonedListener(this);
this.NPCConversationFactory = new ConversationFactory(this).withModality(false).withFirstPrompt(new QuestAcceptPrompt(this)).withTimeout(acceptTimeout).withLocalEcho(false).addConversationAbandonedListener(this);
getServer().getPluginManager().registerEvents(pListener, this);
getServer().getPluginManager().registerEvents(playerListener, this);
if (npcEffects) {
getServer().getScheduler().scheduleSyncRepeatingTask(this, effListener, 20, 20);
getServer().getScheduler().scheduleSyncRepeatingTask(this, effThread, 20, 20);
}
if (parties != null) {
getServer().getPluginManager().registerEvents(partiesListener, this);
}
delayLoadQuestInfo();
}

View File

@ -1,6 +1,7 @@
package me.blackvein.quests.listeners;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@ -14,23 +15,27 @@ public class PartiesListener implements Listener {
@EventHandler
public void onPartyCreate(BukkitPartiesPartyPostCreateEvent event) {
Bukkit.getServer().getPlayer(event.getCreator().getPlayerUUID()).sendMessage("Players added to this party may perform quests together!");
Bukkit.getServer().getPlayer(event.getCreator().getPlayerUUID()).sendMessage(ChatColor.YELLOW + "Players added to this party may perform quests together!");
}
@EventHandler
public void onPartyDeleteEvent(BukkitPartiesPartyPostDeleteEvent event) {
Bukkit.getServer().getPlayer(event.getCommandSender().getPlayerUUID()).sendMessage("The quest party was disbanded.");
Bukkit.getServer().getPlayer(event.getCommandSender().getPlayerUUID()).sendMessage(ChatColor.RED + "The quest party was disbanded.");
}
@EventHandler
public void onPlayerJoinEvent(BukkitPartiesPlayerPostJoinEvent event) {
Bukkit.getServer().getPlayer(event.getInviter()).sendMessage(event.getPartyPlayer().getName() + " can now perform quests with you!");
Bukkit.getServer().getPlayer(event.getPartyPlayer().getPlayerUUID()).sendMessage("You can now perform quests with " + event.getParty().getName());
if (event.isInvited()) {
Bukkit.getServer().getPlayer(event.getInviter()).sendMessage(ChatColor.GREEN + event.getPartyPlayer().getName() + " can now perform quests with you!");
}
Bukkit.getServer().getPlayer(event.getPartyPlayer().getPlayerUUID()).sendMessage(ChatColor.GREEN + "You can now perform quests with " + event.getParty().getName() + ".");
}
@EventHandler
public void onPlayerLeaveEvent(BukkitPartiesPlayerPostLeaveEvent event) {
Bukkit.getServer().getPlayer(event.getKicker().getPlayerUUID()).sendMessage(event.getPartyPlayer().getName() + " can no longer perform quests with you.");
Bukkit.getServer().getPlayer(event.getPartyPlayer().getPlayerUUID()).sendMessage("You can no longer perform quests with " + event.getParty().getName());
if (event.isKicked()) {
Bukkit.getServer().getPlayer(event.getKicker().getPlayerUUID()).sendMessage(ChatColor.RED + event.getPartyPlayer().getName() + " can no longer perform quests with you.");
}
Bukkit.getServer().getPlayer(event.getPartyPlayer().getPlayerUUID()).sendMessage(ChatColor.RED + "You can no longer perform quests with " + event.getParty().getName() + ".");
}
}