From eac4378fbc9626ea6ce8edfaf89e77c7b5693734 Mon Sep 17 00:00:00 2001 From: sk8ingDuck Date: Fri, 10 Nov 2023 19:41:38 +0100 Subject: [PATCH 1/4] Friends & Party Support --- bedwars-plugin/pom.xml | 10 +++ .../java/com/andrei1058/bedwars/BedWars.java | 7 +- .../bedwars/support/party/FAPAdapter.java | 89 +++++++++++++++++++ bedwars-plugin/src/main/resources/plugin.yml | 2 +- 4 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 bedwars-plugin/src/main/java/com/andrei1058/bedwars/support/party/FAPAdapter.java diff --git a/bedwars-plugin/pom.xml b/bedwars-plugin/pom.xml index 07104ed6c..8eb29dd45 100644 --- a/bedwars-plugin/pom.xml +++ b/bedwars-plugin/pom.xml @@ -70,6 +70,10 @@ papermc https://papermc.io/repo/repository/maven-public/ + + jitpack.io + https://jitpack.io + @@ -325,6 +329,12 @@ 1.18-R0.1-SNAPSHOT provided + + + com.github.sk8ingDuck + FriendSystem-Spigot-API + master + diff --git a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java index 6f351c6b1..aa38c5bb2 100644 --- a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java +++ b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java @@ -71,10 +71,7 @@ import com.andrei1058.bedwars.support.citizens.JoinNPC; import com.andrei1058.bedwars.support.papi.PAPISupport; import com.andrei1058.bedwars.support.papi.SupportPAPI; -import com.andrei1058.bedwars.support.party.NoParty; -import com.andrei1058.bedwars.support.party.PAF; -import com.andrei1058.bedwars.support.party.PAFBungeecordRedisApi; -import com.andrei1058.bedwars.support.party.PartiesAdapter; +import com.andrei1058.bedwars.support.party.*; import com.andrei1058.bedwars.support.preloadedparty.PrePartyListener; import com.andrei1058.bedwars.support.vault.*; import com.andrei1058.bedwars.support.vipfeatures.VipFeatures; @@ -331,6 +328,8 @@ public void onEnable() { } else if (Bukkit.getServer().getPluginManager().isPluginEnabled("Spigot-Party-API-PAF")) { getLogger().info("Hook into Spigot Party API for Party and Friends Extended (by Simonsator) support!"); party = new PAFBungeecordRedisApi(); + } else if (Bukkit.getServer().getPluginManager().isPluginEnabled("FriendSystem-Spigot-API")) { + party = new FAPAdapter(); } if (party instanceof NoParty) { diff --git a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/support/party/FAPAdapter.java b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/support/party/FAPAdapter.java new file mode 100644 index 000000000..cd7c98254 --- /dev/null +++ b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/support/party/FAPAdapter.java @@ -0,0 +1,89 @@ +package com.andrei1058.bedwars.support.party; + +import com.andrei1058.bedwars.api.party.Party; +import me.sk8ingduck.friendsystem.SpigotAPI; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +public class FAPAdapter implements Party { + + private me.sk8ingduck.friendsystem.util.Party getParty(Player player) { + return SpigotAPI.getInstance().getMysql().getParty(player.getUniqueId()); + } + + @Override + public boolean hasParty(Player p) { + return getParty(p) != null; + } + + @Override + public int partySize(Player p) { + return getParty(p) == null ? 0 : getParty(p).getAllMembers().size(); + } + + @Override + public boolean isOwner(Player p) { + return getParty(p) != null && getParty(p).getLeaderUUID().equals(p.getUniqueId()); + } + + public List getMembers(Player owner) { + return getParty(owner) == null ? Collections.emptyList() : + getParty(owner).getAllMembers().stream() + .map(Bukkit::getPlayer) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + } + + @Override + public void createParty(Player owner, Player... members) { + + } + + @Override + public void addMember(Player owner, Player member) { + + } + + @Override + public void removeFromParty(Player member) { + + } + + @Override + public void disband(Player owner) { + + } + + @Override + public boolean isMember(Player owner, Player check) { + me.sk8ingduck.friendsystem.util.Party party = getParty(owner); + if (party == null) return false; + + return party.getAllMembers().contains(check.getUniqueId()); + } + + @Override + public void removePlayer(Player owner, Player target) { + + } + + @Override + public Player getOwner(Player member) { + return getParty(member) == null ? member : Bukkit.getPlayer(getParty(member).getLeaderUUID()); + } + + @Override + public void promote(@NotNull Player owner, @NotNull Player target) { + } + + @Override + public boolean isInternal() { + return false; + } +} diff --git a/bedwars-plugin/src/main/resources/plugin.yml b/bedwars-plugin/src/main/resources/plugin.yml index 407b439c2..975f56f24 100644 --- a/bedwars-plugin/src/main/resources/plugin.yml +++ b/bedwars-plugin/src/main/resources/plugin.yml @@ -4,5 +4,5 @@ version: ${project.version} author: andrei1058 description: BedWars minigame by andrei1058 main: com.andrei1058.bedwars.BedWars -softdepend: [Vault,PlaceholderAPI,Citizens,Parties,SlimeWorldManager,VipFeatures,Enhanced-SlimeWorldManager,PartyAndFriends,Spigot-Party-API-PAF] +softdepend: [Vault,PlaceholderAPI,Citizens,Parties,SlimeWorldManager,VipFeatures,Enhanced-SlimeWorldManager,PartyAndFriends,Spigot-Party-API-PAF,FriendSystem-Spigot-API] #load: STARTUP From 3d59f17b0033f0b9a829b76aeb359ab41978e192 Mon Sep 17 00:00:00 2001 From: sk8ingDuck Date: Fri, 10 Nov 2023 19:45:35 +0100 Subject: [PATCH 2/4] efficiency improvement --- .../bedwars/support/party/FAPAdapter.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/support/party/FAPAdapter.java b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/support/party/FAPAdapter.java index cd7c98254..146bc1d08 100644 --- a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/support/party/FAPAdapter.java +++ b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/support/party/FAPAdapter.java @@ -24,17 +24,20 @@ public boolean hasParty(Player p) { @Override public int partySize(Player p) { - return getParty(p) == null ? 0 : getParty(p).getAllMembers().size(); + me.sk8ingduck.friendsystem.util.Party party = getParty(p); + return party == null ? 0 : party.getAllMembers().size(); } @Override public boolean isOwner(Player p) { - return getParty(p) != null && getParty(p).getLeaderUUID().equals(p.getUniqueId()); + me.sk8ingduck.friendsystem.util.Party party = getParty(p); + return party != null && party.getLeaderUUID().equals(p.getUniqueId()); } public List getMembers(Player owner) { - return getParty(owner) == null ? Collections.emptyList() : - getParty(owner).getAllMembers().stream() + me.sk8ingduck.friendsystem.util.Party party = getParty(owner); + return party == null ? Collections.emptyList() : + party.getAllMembers().stream() .map(Bukkit::getPlayer) .filter(Objects::nonNull) .collect(Collectors.toList()); @@ -75,7 +78,8 @@ public void removePlayer(Player owner, Player target) { @Override public Player getOwner(Player member) { - return getParty(member) == null ? member : Bukkit.getPlayer(getParty(member).getLeaderUUID()); + me.sk8ingduck.friendsystem.util.Party party = getParty(member); + return party == null ? member : Bukkit.getPlayer(party.getLeaderUUID()); } @Override From e08f6928f6fd49f1282f6a899bf9573e3d71ec06 Mon Sep 17 00:00:00 2001 From: sk8ingDuck Date: Wed, 15 Nov 2023 16:07:45 +0100 Subject: [PATCH 3/4] Implemented missing functions --- bedwars-plugin/pom.xml | 2 +- .../bedwars/support/party/FAPAdapter.java | 26 ++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/bedwars-plugin/pom.xml b/bedwars-plugin/pom.xml index 8eb29dd45..13273aaaf 100644 --- a/bedwars-plugin/pom.xml +++ b/bedwars-plugin/pom.xml @@ -333,7 +333,7 @@ com.github.sk8ingDuck FriendSystem-Spigot-API - master + c2b5d9a0c0 diff --git a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/support/party/FAPAdapter.java b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/support/party/FAPAdapter.java index 146bc1d08..e208e7647 100644 --- a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/support/party/FAPAdapter.java +++ b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/support/party/FAPAdapter.java @@ -14,7 +14,7 @@ public class FAPAdapter implements Party { private me.sk8ingduck.friendsystem.util.Party getParty(Player player) { - return SpigotAPI.getInstance().getMysql().getParty(player.getUniqueId()); + return SpigotAPI.getInstance().getPartyManager().getParty(player.getUniqueId()); } @Override @@ -45,22 +45,39 @@ public List getMembers(Player owner) { @Override public void createParty(Player owner, Player... members) { + me.sk8ingduck.friendsystem.util.Party party = getParty(owner); + if (party != null) return; + + String[] memberUUIDs = new String[members.length]; + for (int i = 0; i < members.length; i++) { + memberUUIDs[i] = members[i].getUniqueId().toString(); + } + SpigotAPI.getInstance().getPartyManager().createParty(owner, memberUUIDs); } @Override public void addMember(Player owner, Player member) { + me.sk8ingduck.friendsystem.util.Party party = getParty(owner); + if (party == null) return; + SpigotAPI.getInstance().getPartyManager().addPlayer(party.getLeaderUUID(), member); } @Override public void removeFromParty(Player member) { + me.sk8ingduck.friendsystem.util.Party party = getParty(member); + if (party == null) return; + SpigotAPI.getInstance().getPartyManager().kickPlayer(party.getLeaderUUID(), member); } @Override public void disband(Player owner) { + me.sk8ingduck.friendsystem.util.Party party = getParty(owner); + if (party == null) return; + SpigotAPI.getInstance().getPartyManager().disbandParty(owner); } @Override @@ -73,7 +90,10 @@ public boolean isMember(Player owner, Player check) { @Override public void removePlayer(Player owner, Player target) { + me.sk8ingduck.friendsystem.util.Party party = getParty(owner); + if (party == null) return; + SpigotAPI.getInstance().getPartyManager().kickPlayer(party.getLeaderUUID(), target); } @Override @@ -84,6 +104,10 @@ public Player getOwner(Player member) { @Override public void promote(@NotNull Player owner, @NotNull Player target) { + me.sk8ingduck.friendsystem.util.Party party = getParty(owner); + if (party == null) return; + + SpigotAPI.getInstance().getPartyManager().promotePlayer(party.getLeaderUUID(), target); } @Override From 5eb38328a7f77e5e287b6b29c346e9960c60ad62 Mon Sep 17 00:00:00 2001 From: sk8ingDuck Date: Wed, 6 Dec 2023 17:39:30 +0100 Subject: [PATCH 4/4] Final fixes --- bedwars-plugin/pom.xml | 1 + .../src/main/java/com/andrei1058/bedwars/BedWars.java | 1 + .../java/com/andrei1058/bedwars/support/party/FAPAdapter.java | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/bedwars-plugin/pom.xml b/bedwars-plugin/pom.xml index 13273aaaf..9a4e27467 100644 --- a/bedwars-plugin/pom.xml +++ b/bedwars-plugin/pom.xml @@ -334,6 +334,7 @@ com.github.sk8ingDuck FriendSystem-Spigot-API c2b5d9a0c0 + provided diff --git a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java index aa38c5bb2..3656be629 100644 --- a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java +++ b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java @@ -330,6 +330,7 @@ public void onEnable() { party = new PAFBungeecordRedisApi(); } else if (Bukkit.getServer().getPluginManager().isPluginEnabled("FriendSystem-Spigot-API")) { party = new FAPAdapter(); + getLogger().info("Hook into FriendSystem (by sk8ingDuck)!"); } if (party instanceof NoParty) { diff --git a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/support/party/FAPAdapter.java b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/support/party/FAPAdapter.java index e208e7647..08e233750 100644 --- a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/support/party/FAPAdapter.java +++ b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/support/party/FAPAdapter.java @@ -31,7 +31,7 @@ public int partySize(Player p) { @Override public boolean isOwner(Player p) { me.sk8ingduck.friendsystem.util.Party party = getParty(p); - return party != null && party.getLeaderUUID().equals(p.getUniqueId()); + return party == null || party.getLeaderUUID().equals(p.getUniqueId()); } public List getMembers(Player owner) {