more party plugin compatibility

This commit is contained in:
Jules 2022-01-19 14:16:25 +01:00
parent 68e50a7b56
commit f7f7de6c6f
9 changed files with 176 additions and 66 deletions

View File

@ -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

View File

@ -3,8 +3,8 @@ package net.Indyuce.mmocore.party;
import net.Indyuce.mmocore.api.player.PlayerData;
import org.jetbrains.annotations.Nullable;
public interface PartyModule<T extends AbstractParty> {
public interface PartyModule {
@Nullable
public T getParty(PlayerData playerData);
public AbstractParty getParty(PlayerData playerData);
}

View File

@ -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<PartyModule<?>> provider;
private final Provider<PartyModule> provider;
PartyModuleType(String pluginName, Provider<PartyModule<?>> provider) {
PartyModuleType(String pluginName, Provider<PartyModule> 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();
}
}

View File

@ -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<PlayerData> getOnlineMembers() {
List<PlayerData> 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();
}
}
}

View File

@ -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<PlayerData> getOnlineMembers() {
List<PlayerData> list = new ArrayList<>();
for (OnlinePAFPlayer online : party.getAllPlayers())
list.add(PlayerData.get(online.getUniqueId()));
return list;
}
@Override
public int countMembers() {
return party.getAllPlayers().size();
}
}
}

View File

@ -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<PlayerData> getOnlineMembers() {
List<PlayerData> list = new ArrayList<>();
for (PartyPlayer member : party.getOnlineMembers())
list.add(PlayerData.get(member.getPlayerUUID()));
return list;
}
@Override
public int countMembers() {
return party.getMembers().size();
}
}
}

View File

@ -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<PlayerData> getOnlineMembers() {
List<PlayerData> 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();
}
}

View File

@ -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<DungeonsParty> {
@Override
public DungeonsParty getParty(PlayerData playerData) {
PlayerGroup group = DungeonsXL.getInstance().getPlayerGroup(playerData.getPlayer());
return group == null ? null : new DungeonsParty(group);
}
}

View File

@ -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());
}