From 2d08d4403be34a3d1d8d4f3558f27a76b671d524 Mon Sep 17 00:00:00 2001 From: Jules Date: Wed, 1 May 2024 22:42:29 -0700 Subject: [PATCH] Compatibility with new MythicDungeons API --- MMOCore-API/pom.xml | 22 +++++++++----- .../Indyuce/mmocore/party/AbstractParty.java | 4 +++ .../mmocore/party/PartyModuleType.java | 6 ++-- ...le.java => MythicDungeonsPartyModule.java} | 30 ++++++++++++------- 4 files changed, 41 insertions(+), 21 deletions(-) rename MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/{DungeonPartiesPartyModule.java => MythicDungeonsPartyModule.java} (53%) diff --git a/MMOCore-API/pom.xml b/MMOCore-API/pom.xml index 8630e6f9..713e1a4d 100644 --- a/MMOCore-API/pom.xml +++ b/MMOCore-API/pom.xml @@ -109,6 +109,14 @@ simonsators Repo https://simonsator.de/repo + + + + aestrus-releases + Aestrus's Repository + https://maven.aestrus.io/releases + + @@ -144,6 +152,13 @@ provided + + net.playavalon + MythicDungeons + 1.3.0-SNAPSHOT + provided + + fr.phoenixdevt Profile-API @@ -216,13 +231,6 @@ provided - - net.playavalon - DungeonParties - 1.0 - provided - - com.alessiodp Parties diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/AbstractParty.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/AbstractParty.java index a64bd689..05fb4e2b 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/AbstractParty.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/AbstractParty.java @@ -17,6 +17,10 @@ public interface AbstractParty { */ List getOnlineMembers(); + /** + * @deprecated Prefer using {@link #getOnlineMembers()} + */ + @Deprecated default PlayerData getMember(int n) { return getOnlineMembers().get(n); } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/PartyModuleType.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/PartyModuleType.java index abfbc663..0ee40aab 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/PartyModuleType.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/PartyModuleType.java @@ -7,15 +7,15 @@ import org.bukkit.Bukkit; import javax.inject.Provider; public enum PartyModuleType { + MMOCORE("MMOCore", MMOCorePartyModule::new), // DUNGEONS("Dungeons", DungeonsPartyModule::new), DUNGEONSXL("DungeonsXL", DungeonsXLPartyModule::new), MCMMO("mcMMO", McMMOPartyModule::new), - MMOCORE("MMOCore", MMOCorePartyModule::new), - PARTIES("Parties", PartiesPartyModule::new), - MYTHICDUNGEONS("MythicDungeons", DungeonPartiesPartyModule::new), + MYTHICDUNGEONS("MythicDungeons", MythicDungeonsPartyModule::new), OBTEAM("OBTeam", OBTeamPartyModule::new), PARTY_AND_FRIENDS("PartyAndFriends", PAFPartyModule::new), PARTY_AND_FRIENDS_BUNGEECORD_VELOCITY("Spigot-Party-API-PAF", PAFProxyPartyModule::new), + PARTIES("Parties", PartiesPartyModule::new), ; private final String pluginName; diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/DungeonPartiesPartyModule.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/MythicDungeonsPartyModule.java similarity index 53% rename from MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/DungeonPartiesPartyModule.java rename to MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/MythicDungeonsPartyModule.java index a4d44190..dcecd232 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/DungeonPartiesPartyModule.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/party/compat/MythicDungeonsPartyModule.java @@ -3,9 +3,10 @@ package net.Indyuce.mmocore.party.compat; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.party.AbstractParty; import net.Indyuce.mmocore.party.PartyModule; -import net.playavalon.avnparty.AvNParty; -import net.playavalon.avnparty.party.Party; -import net.playavalon.avnparty.player.AvalonPlayer; +import net.playavalon.mythicdungeons.api.MythicDungeonsService; +import net.playavalon.mythicdungeons.player.party.partysystem.MythicParty; +import org.apache.commons.lang3.Validate; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.jetbrains.annotations.Nullable; @@ -13,26 +14,33 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; -public class DungeonPartiesPartyModule implements PartyModule, Listener { +public class MythicDungeonsPartyModule implements PartyModule, Listener { + private final MythicDungeonsService hook; + + public MythicDungeonsPartyModule() { + this.hook = Bukkit.getServer().getServicesManager().load(MythicDungeonsService.class); + Validate.notNull(hook, "Could not load compatibility with MythicDungeons"); + } @Nullable @Override public AbstractParty getParty(PlayerData playerData) { - final @Nullable Party party = AvNParty.plugin.players.get(playerData.getPlayer()).getParty(); + final MythicParty party = hook.getParty(playerData.getPlayer()); return party == null ? null : new CustomParty(party); } - class CustomParty implements AbstractParty { - private final Party party; - public CustomParty(Party party) { + static class CustomParty implements AbstractParty { + private final MythicParty party; + + public CustomParty(MythicParty party) { this.party = party; } @Override public boolean hasMember(Player player) { - for (AvalonPlayer member : party.getPlayers()) - if (member.getPlayer().getUniqueId().equals(player.getUniqueId())) return true; + for (Player member : party.getPlayers()) + if (member.getUniqueId().equals(player.getUniqueId())) return true; return false; } @@ -40,7 +48,7 @@ public class DungeonPartiesPartyModule implements PartyModule, Listener { public List getOnlineMembers() { final List list = new ArrayList<>(); - for (AvalonPlayer member : party.getPlayers()) + for (Player member : party.getPlayers()) try { list.add(PlayerData.get(member.getPlayer())); } catch (Exception ignored) {