From c99159993659099f9407dd4f53be55e3dbf211bb Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 5 Jan 2019 23:55:33 -0500 Subject: [PATCH] Add support for Parties, tested. Fixes #281 --- src/main/java/me/blackvein/quests/Quest.java | 21 ++++++++++++------- src/main/java/me/blackvein/quests/Quests.java | 18 ++++++++++------ .../quests/listeners/PartiesListener.java | 17 +++++++++------ 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/src/main/java/me/blackvein/quests/Quest.java b/src/main/java/me/blackvein/quests/Quest.java index e067f69fe..e9a27158c 100644 --- a/src/main/java/me/blackvein/quests/Quest.java +++ b/src/main/java/me/blackvein/quests/Quest.java @@ -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(); } diff --git a/src/main/java/me/blackvein/quests/Quests.java b/src/main/java/me/blackvein/quests/Quests.java index f86f7e16b..96837606e 100644 --- a/src/main/java/me/blackvein/quests/Quests.java +++ b/src/main/java/me/blackvein/quests/Quests.java @@ -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(); } diff --git a/src/main/java/me/blackvein/quests/listeners/PartiesListener.java b/src/main/java/me/blackvein/quests/listeners/PartiesListener.java index acb2f9b05..2b7989e46 100644 --- a/src/main/java/me/blackvein/quests/listeners/PartiesListener.java +++ b/src/main/java/me/blackvein/quests/listeners/PartiesListener.java @@ -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() + "."); } }