Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Friends & Party System (by sk8ingDuck) #902

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions bedwars-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<dependencies>
Expand Down Expand Up @@ -325,6 +329,13 @@
<version>1.18-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.github.sk8ingDuck</groupId>
<artifactId>FriendSystem-Spigot-API</artifactId>
<version>c2b5d9a0c0</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -331,6 +328,9 @@ 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();
getLogger().info("Hook into FriendSystem (by sk8ingDuck)!");
}

if (party instanceof NoParty) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
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().getPartyManager().getParty(player.getUniqueId());
}

@Override
public boolean hasParty(Player p) {
return getParty(p) != null;
}

@Override
public int partySize(Player p) {
me.sk8ingduck.friendsystem.util.Party party = getParty(p);
return party == null ? 0 : party.getAllMembers().size();
}

@Override
public boolean isOwner(Player p) {
me.sk8ingduck.friendsystem.util.Party party = getParty(p);
return party == null || party.getLeaderUUID().equals(p.getUniqueId());
}

public List<Player> getMembers(Player owner) {
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());
}

@Override
public void createParty(Player owner, Player... members) {
Xxyuri2005xX marked this conversation as resolved.
Show resolved Hide resolved
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
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) {
me.sk8ingduck.friendsystem.util.Party party = getParty(owner);
if (party == null) return;

SpigotAPI.getInstance().getPartyManager().kickPlayer(party.getLeaderUUID(), target);
}

@Override
public Player getOwner(Player member) {
me.sk8ingduck.friendsystem.util.Party party = getParty(member);
return party == null ? member : Bukkit.getPlayer(party.getLeaderUUID());
}

@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
public boolean isInternal() {
return false;
}
}
2 changes: 1 addition & 1 deletion bedwars-plugin/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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