From f7f7de6c6f1af352d881d90b49b5f60ed1337958 Mon Sep 17 00:00:00 2001 From: Jules Date: Wed, 19 Jan 2022 14:16:25 +0100 Subject: [PATCH] more party plugin compatibility --- .../Indyuce/mmocore/party/AbstractParty.java | 4 +- .../Indyuce/mmocore/party/PartyModule.java | 4 +- .../mmocore/party/PartyModuleType.java | 13 +++-- .../party/compat/DungeonsPartyModule.java | 53 +++++++++++++++++ .../mmocore/party/compat/PAFPartyModule.java | 52 +++++++++++++++++ .../party/compat/PartiesPartyModule.java | 57 +++++++++++++++++++ .../mmocore/party/dungeon/DungeonsParty.java | 41 ------------- .../party/dungeon/DungeonsPartyModule.java | 15 ----- .../Indyuce/mmocore/party/provided/Party.java | 3 +- 9 files changed, 176 insertions(+), 66 deletions(-) create mode 100644 src/main/java/net/Indyuce/mmocore/party/compat/DungeonsPartyModule.java create mode 100644 src/main/java/net/Indyuce/mmocore/party/compat/PAFPartyModule.java create mode 100644 src/main/java/net/Indyuce/mmocore/party/compat/PartiesPartyModule.java delete mode 100644 src/main/java/net/Indyuce/mmocore/party/dungeon/DungeonsParty.java delete mode 100644 src/main/java/net/Indyuce/mmocore/party/dungeon/DungeonsPartyModule.java diff --git a/src/main/java/net/Indyuce/mmocore/party/AbstractParty.java b/src/main/java/net/Indyuce/mmocore/party/AbstractParty.java index 4bae9093..0b6f0250 100644 --- a/src/main/java/net/Indyuce/mmocore/party/AbstractParty.java +++ b/src/main/java/net/Indyuce/mmocore/party/AbstractParty.java @@ -1,7 +1,7 @@ package net.Indyuce.mmocore.party; import net.Indyuce.mmocore.api.player.PlayerData; -import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; import java.util.List; @@ -10,7 +10,7 @@ public interface AbstractParty { /** * @return If given player is in that party */ - boolean hasMember(OfflinePlayer player); + boolean hasMember(Player player); /** * @return List of online members diff --git a/src/main/java/net/Indyuce/mmocore/party/PartyModule.java b/src/main/java/net/Indyuce/mmocore/party/PartyModule.java index 1c47e74e..24faf048 100644 --- a/src/main/java/net/Indyuce/mmocore/party/PartyModule.java +++ b/src/main/java/net/Indyuce/mmocore/party/PartyModule.java @@ -3,8 +3,8 @@ package net.Indyuce.mmocore.party; import net.Indyuce.mmocore.api.player.PlayerData; import org.jetbrains.annotations.Nullable; -public interface PartyModule { +public interface PartyModule { @Nullable - public T getParty(PlayerData playerData); + public AbstractParty getParty(PlayerData playerData); } diff --git a/src/main/java/net/Indyuce/mmocore/party/PartyModuleType.java b/src/main/java/net/Indyuce/mmocore/party/PartyModuleType.java index 816b457d..a67c7b06 100644 --- a/src/main/java/net/Indyuce/mmocore/party/PartyModuleType.java +++ b/src/main/java/net/Indyuce/mmocore/party/PartyModuleType.java @@ -1,6 +1,8 @@ package net.Indyuce.mmocore.party; -import net.Indyuce.mmocore.party.dungeon.DungeonsPartyModule; +import net.Indyuce.mmocore.party.compat.DungeonsPartyModule; +import net.Indyuce.mmocore.party.compat.PAFPartyModule; +import net.Indyuce.mmocore.party.compat.PartiesPartyModule; import net.Indyuce.mmocore.party.provided.MMOCorePartyModule; import org.bukkit.Bukkit; @@ -9,12 +11,15 @@ import javax.inject.Provider; public enum PartyModuleType { DUNGEONSXL("DungeonsXL", () -> new DungeonsPartyModule()), MMOCORE("MMOCore", () -> new MMOCorePartyModule()), + PARTY_AND_FRIENDS("PartyAndFriends", () -> new PAFPartyModule()), + PARTIES("Parties", () -> new PartiesPartyModule()), + // DUNGEONS("Dungeons", null), ; private final String pluginName; - private final Provider> provider; + private final Provider provider; - PartyModuleType(String pluginName, Provider> provider) { + PartyModuleType(String pluginName, Provider provider) { this.pluginName = pluginName; this.provider = provider; } @@ -23,7 +28,7 @@ public enum PartyModuleType { return Bukkit.getPluginManager().getPlugin(pluginName) != null; } - public PartyModule provideModule() { + public PartyModule provideModule() { return provider.get(); } } diff --git a/src/main/java/net/Indyuce/mmocore/party/compat/DungeonsPartyModule.java b/src/main/java/net/Indyuce/mmocore/party/compat/DungeonsPartyModule.java new file mode 100644 index 00000000..4241bfe8 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/party/compat/DungeonsPartyModule.java @@ -0,0 +1,53 @@ +package net.Indyuce.mmocore.party.compat; + +import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.player.PlayerGroup; +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.party.AbstractParty; +import net.Indyuce.mmocore.party.PartyModule; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class DungeonsPartyModule implements PartyModule { + + @Override + public AbstractParty getParty(PlayerData playerData) { + PlayerGroup group = DungeonsXL.getInstance().getPlayerGroup(playerData.getPlayer()); + return group == null ? null : new CustomParty(group); + } + + class CustomParty implements AbstractParty { + private final PlayerGroup group; + + public CustomParty(PlayerGroup group) { + this.group = group; + } + + @Override + public boolean hasMember(Player player) { + return group.getMembers().contains(player.getUniqueId()); + } + + @Override + public List getOnlineMembers() { + List list = new ArrayList<>(); + + for (UUID playerUid : group.getMembers().getUniqueIds()) { + PlayerData found = PlayerData.get(playerUid); + if (found.isOnline()) + list.add(found); + } + + return list; + } + + @Override + public int countMembers() { + return group.getMembers().getUniqueIds().size(); + } + } + +} diff --git a/src/main/java/net/Indyuce/mmocore/party/compat/PAFPartyModule.java b/src/main/java/net/Indyuce/mmocore/party/compat/PAFPartyModule.java new file mode 100644 index 00000000..2ab5883c --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/party/compat/PAFPartyModule.java @@ -0,0 +1,52 @@ +package net.Indyuce.mmocore.party.compat; + +import de.simonsator.partyandfriends.api.pafplayers.OnlinePAFPlayer; +import de.simonsator.partyandfriends.api.pafplayers.PAFPlayerManager; +import de.simonsator.partyandfriends.api.party.PartyManager; +import de.simonsator.partyandfriends.api.party.PlayerParty; +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.party.AbstractParty; +import net.Indyuce.mmocore.party.PartyModule; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; + +public class PAFPartyModule implements PartyModule { + + @Nullable + @Override + public AbstractParty getParty(PlayerData playerData) { + PlayerParty party = PartyManager.getInstance().getParty(playerData.getUniqueId()); + return party == null ? null : new CustomParty(party); + } + + class CustomParty implements AbstractParty { + private final PlayerParty party; + + public CustomParty(PlayerParty party) { + this.party = party; + } + + @Override + public boolean hasMember(Player player) { + return party.isInParty(PAFPlayerManager.getInstance().getPlayer(player)); + } + + @Override + public List getOnlineMembers() { + List list = new ArrayList<>(); + + for (OnlinePAFPlayer online : party.getAllPlayers()) + list.add(PlayerData.get(online.getUniqueId())); + + return list; + } + + @Override + public int countMembers() { + return party.getAllPlayers().size(); + } + } +} diff --git a/src/main/java/net/Indyuce/mmocore/party/compat/PartiesPartyModule.java b/src/main/java/net/Indyuce/mmocore/party/compat/PartiesPartyModule.java new file mode 100644 index 00000000..be63fb4b --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/party/compat/PartiesPartyModule.java @@ -0,0 +1,57 @@ +package net.Indyuce.mmocore.party.compat; + +import com.alessiodp.parties.api.Parties; +import com.alessiodp.parties.api.interfaces.PartiesAPI; +import com.alessiodp.parties.api.interfaces.Party; +import com.alessiodp.parties.api.interfaces.PartyPlayer; +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.party.AbstractParty; +import net.Indyuce.mmocore.party.PartyModule; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; + +public class PartiesPartyModule implements PartyModule { + private final PartiesAPI api = Parties.getApi(); + + @Nullable + @Override + public AbstractParty getParty(PlayerData playerData) { + Party party = api.getParty(playerData.getUniqueId()); + return party == null ? null : new CustomParty(party); + } + + class CustomParty implements AbstractParty { + private final Party party; + + public CustomParty(Party party) { + this.party = party; + } + + @Override + public boolean hasMember(Player player) { + for (PartyPlayer member : party.getOnlineMembers()) + if (member.getPlayerUUID().equals(player.getUniqueId())) + return true; + + return false; + } + + @Override + public List getOnlineMembers() { + List list = new ArrayList<>(); + + for (PartyPlayer member : party.getOnlineMembers()) + list.add(PlayerData.get(member.getPlayerUUID())); + + return list; + } + + @Override + public int countMembers() { + return party.getMembers().size(); + } + } +} diff --git a/src/main/java/net/Indyuce/mmocore/party/dungeon/DungeonsParty.java b/src/main/java/net/Indyuce/mmocore/party/dungeon/DungeonsParty.java deleted file mode 100644 index 03ee8857..00000000 --- a/src/main/java/net/Indyuce/mmocore/party/dungeon/DungeonsParty.java +++ /dev/null @@ -1,41 +0,0 @@ -package net.Indyuce.mmocore.party.dungeon; - -import de.erethon.dungeonsxl.api.player.PlayerGroup; -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.party.AbstractParty; -import org.bukkit.OfflinePlayer; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -public class DungeonsParty implements AbstractParty { - private final PlayerGroup group; - - public DungeonsParty(PlayerGroup group) { - this.group = group; - } - - @Override - public boolean hasMember(OfflinePlayer player) { - return group.getMembers().contains(player.getUniqueId()); - } - - @Override - public List getOnlineMembers() { - List list = new ArrayList<>(); - - for (UUID playerUid : group.getMembers().getUniqueIds()) { - PlayerData found = PlayerData.get(playerUid); - if (found.isOnline()) - list.add(found); - } - - return list; - } - - @Override - public int countMembers() { - return group.getMembers().getUniqueIds().size(); - } -} diff --git a/src/main/java/net/Indyuce/mmocore/party/dungeon/DungeonsPartyModule.java b/src/main/java/net/Indyuce/mmocore/party/dungeon/DungeonsPartyModule.java deleted file mode 100644 index 037a251b..00000000 --- a/src/main/java/net/Indyuce/mmocore/party/dungeon/DungeonsPartyModule.java +++ /dev/null @@ -1,15 +0,0 @@ -package net.Indyuce.mmocore.party.dungeon; - -import de.erethon.dungeonsxl.DungeonsXL; -import de.erethon.dungeonsxl.api.player.PlayerGroup; -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.party.PartyModule; - -public class DungeonsPartyModule implements PartyModule { - - @Override - public DungeonsParty getParty(PlayerData playerData) { - PlayerGroup group = DungeonsXL.getInstance().getPlayerGroup(playerData.getPlayer()); - return group == null ? null : new DungeonsParty(group); - } -} diff --git a/src/main/java/net/Indyuce/mmocore/party/provided/Party.java b/src/main/java/net/Indyuce/mmocore/party/provided/Party.java index 3f8d8ecc..1550d17c 100644 --- a/src/main/java/net/Indyuce/mmocore/party/provided/Party.java +++ b/src/main/java/net/Indyuce/mmocore/party/provided/Party.java @@ -8,7 +8,6 @@ import net.Indyuce.mmocore.gui.api.PluginInventory; import net.Indyuce.mmocore.gui.social.party.EditablePartyView.PartyViewInventory; import net.Indyuce.mmocore.manager.InventoryManager; import net.Indyuce.mmocore.party.AbstractParty; -import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import java.util.*; @@ -78,7 +77,7 @@ public class Party implements AbstractParty { } @Override - public boolean hasMember(OfflinePlayer player) { + public boolean hasMember(Player player) { return hasMember(player.getUniqueId()); }