Skip to content

Commit

Permalink
Add integration for parties plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Redned235 committed Dec 11, 2024
1 parent 5c0c59a commit c8fd344
Show file tree
Hide file tree
Showing 24 changed files with 569 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.bukkit.event.EventHandler;

/**
* A module that allows for hooking into various hologram plugin.
* A module that allows for hooking into various hologram plugins.
*/
@ArenaModule(id = HologramIntegration.ID, name = "Hologram", description = "Adds support for hooking into various Hologram plugins.", authors = "BattlePlugins")
public class HologramIntegration implements ArenaModuleInitializer {
Expand Down
10 changes: 10 additions & 0 deletions module/party-integration/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
repositories {
maven("https://repo.alessiodp.com/releases/")
maven("https://simonsator.de/repo/")
}

dependencies {
compileOnly("com.alessiodp.parties:parties-api:3.2.15")
compileOnly("de.simonsator:Party-and-Friends-MySQL-Edition-Spigot-API:1.6.2-RELEASE")
compileOnly("de.simonsator:spigot-party-api-for-party-and-friends:1.0.7-RELEASE")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.battleplugins.arena.module.party;

import org.battleplugins.arena.event.BattleArenaPostInitializeEvent;
import org.battleplugins.arena.feature.party.Parties;
import org.battleplugins.arena.module.ArenaModule;
import org.battleplugins.arena.module.ArenaModuleInitializer;
import org.battleplugins.arena.module.party.paf.PAFPartiesFeature;
import org.battleplugins.arena.module.party.parties.PartiesPartiesFeature;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;

/**
* A module that allows for hooking into various party plugins.
*/
@ArenaModule(id = PartyIntegration.ID, name = "Party", description = "Adds support for hooking into various Party plugins.", authors = "BattlePlugins")
public class PartyIntegration implements ArenaModuleInitializer {
public static final String ID = "party";

@EventHandler
public void onPostInitialize(BattleArenaPostInitializeEvent event) {
if (Bukkit.getPluginManager().isPluginEnabled("Spigot-Party-API-PAF")) {
Parties.register(new PAFPartiesFeature());

event.getBattleArena().info("Parties for Friends (API) found. Using Spigot-Party-API-PAF for party integration.");
}

if (Bukkit.getPluginManager().isPluginEnabled("Parties")) {
Parties.register(new PartiesPartiesFeature());

event.getBattleArena().info("Parties found. Using Parties for party integration.");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.battleplugins.arena.module.party.paf;

import de.simonsator.partyandfriends.spigot.api.pafplayers.PAFPlayer;
import de.simonsator.partyandfriends.spigot.api.pafplayers.PAFPlayerManager;
import de.simonsator.partyandfriends.spigot.api.party.PartyManager;
import org.battleplugins.arena.feature.PluginFeature;
import org.battleplugins.arena.feature.party.PartiesFeature;
import org.battleplugins.arena.feature.party.Party;
import org.jetbrains.annotations.Nullable;

import java.util.UUID;

public class PAFPartiesFeature extends PluginFeature<PartiesFeature> implements PartiesFeature {

public PAFPartiesFeature() {
super("Spigot-Party-API-PAF");
}

@Override
public @Nullable Party getParty(UUID uuid) {
PAFPlayer player = PAFPlayerManager.getInstance().getPlayer(uuid);
if (player == null) {
return null;
}

return new PAFParty(PartyManager.getInstance().getParty(player));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.battleplugins.arena.module.party.paf;

import de.simonsator.partyandfriends.spigot.api.party.PlayerParty;
import org.battleplugins.arena.feature.party.Party;
import org.battleplugins.arena.feature.party.PartyMember;

import java.util.Set;
import java.util.stream.Collectors;

public class PAFParty implements Party {
private final PlayerParty impl;

public PAFParty(PlayerParty impl) {
this.impl = impl;
}

@Override
public PartyMember getLeader() {
return new PAFPartyMember(this.impl.getLeader());
}

@Override
public Set<PartyMember> getMembers() {
return this.impl.getPlayers().stream()
.map(PAFPartyMember::new)
.collect(Collectors.toSet());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.battleplugins.arena.module.party.paf;

import de.simonsator.partyandfriends.spigot.api.pafplayers.PAFPlayer;
import de.simonsator.partyandfriends.spigot.api.party.PartyManager;
import org.battleplugins.arena.feature.party.Party;
import org.battleplugins.arena.feature.party.PartyMember;

import java.util.UUID;

public class PAFPartyMember implements PartyMember {
private final PAFPlayer impl;

public PAFPartyMember(PAFPlayer impl) {
this.impl = impl;
}

@Override
public String getName() {
return this.impl.getName();
}

@Override
public UUID getUniqueId() {
return this.impl.getUniqueId();
}

@Override
public Party getParty() {
return new PAFParty(PartyManager.getInstance().getParty(this.impl));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.battleplugins.arena.module.party.parties;

import com.alessiodp.parties.api.Parties;
import org.battleplugins.arena.feature.PluginFeature;
import org.battleplugins.arena.feature.party.PartiesFeature;
import org.battleplugins.arena.feature.party.Party;
import org.jetbrains.annotations.Nullable;

import java.util.UUID;

public class PartiesPartiesFeature extends PluginFeature<PartiesPartiesFeature> implements PartiesFeature {

public PartiesPartiesFeature() {
super("Parties");
}

@Override
public @Nullable Party getParty(UUID uuid) {
com.alessiodp.parties.api.interfaces.Party party = Parties.getApi().getPartyOfPlayer(uuid);
if (party == null) {
return null;
}

return new PartiesParty(party);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.battleplugins.arena.module.party.parties;

import com.alessiodp.parties.api.Parties;
import com.alessiodp.parties.api.interfaces.PartyPlayer;
import org.battleplugins.arena.feature.party.Party;
import org.battleplugins.arena.feature.party.PartyMember;

import java.util.Set;
import java.util.stream.Collectors;

public class PartiesParty implements Party {
private final com.alessiodp.parties.api.interfaces.Party impl;

public PartiesParty(com.alessiodp.parties.api.interfaces.Party impl) {
this.impl = impl;
}

@Override
public PartyMember getLeader() {
if (this.impl.getLeader() == null) {
// Return the first member of the party if the leader is null
Set<PartyMember> members = this.getMembers();
if (!members.isEmpty()) {
return members.iterator().next();
}

return null;
}

PartyPlayer player = Parties.getApi().getPartyPlayer(this.impl.getLeader());
if (player == null) {
return null;
}

return new PartiesPartyMember(player);
}

@Override
public Set<PartyMember> getMembers() {
return this.impl.getOnlineMembers()
.stream()
.filter(m -> !m.getPlayerUUID().equals(this.impl.getLeader()))
.map(PartiesPartyMember::new)
.collect(Collectors.toSet());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.battleplugins.arena.module.party.parties;

import com.alessiodp.parties.api.Parties;
import com.alessiodp.parties.api.interfaces.PartyPlayer;
import org.battleplugins.arena.feature.party.Party;
import org.battleplugins.arena.feature.party.PartyMember;

import java.util.UUID;

public class PartiesPartyMember implements PartyMember {
private final PartyPlayer impl;

public PartiesPartyMember(PartyPlayer impl) {
this.impl = impl;
}

@Override
public String getName() {
return this.impl.getName();
}

@Override
public UUID getUniqueId() {
return this.impl.getPlayerUUID();
}

@Override
public Party getParty() {
com.alessiodp.parties.api.interfaces.Party party = Parties.getApi().getPartyOfPlayer(this.impl.getPlayerUUID());
if (party == null) {
return null;
}

return new PartiesParty(party);
}
}
28 changes: 28 additions & 0 deletions plugin/src/main/java/org/battleplugins/arena/BattleArena.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -465,6 +466,21 @@ public CompletableFuture<CompetitionResult> getOrCreateCompetition(Arena arena,
return this.competitionManager.getOrCreateCompetition(arena, player, role, name);
}

/**
* Returns a currently active {@link Competition} for the given {@link Arena},
* {@link Player}s, {@link PlayerRole} and map name. If no competition is found,
* a new one is created if applicable.
*
* @param arena the arena to get the competition for
* @param players the players to get the competition for
* @param role the role of the player
* @param name the name of the competition
* @return the competition result
*/
public CompletableFuture<CompetitionResult> getOrCreateCompetition(Arena arena, Collection<Player> players, PlayerRole role, @Nullable String name) {
return this.competitionManager.getOrCreateCompetition(arena, players, role, name);
}

/**
* Finds a joinable {@link Competition} for the given {@link Player} and {@link PlayerRole}.
*
Expand All @@ -477,6 +493,18 @@ public CompletableFuture<CompetitionResult> findJoinableCompetition(List<Competi
return this.competitionManager.findJoinableCompetition(competitions, player, role);
}

/**
* Finds a joinable {@link Competition} for the given {@link Player}s and {@link PlayerRole}.
*
* @param competitions the competitions to find from
* @param players the players to find the competition for
* @param role the role of the player
* @return the competition result
*/
public CompletableFuture<CompetitionResult> findJoinableCompetition(List<Competition<?>> competitions, Collection<Player> players, PlayerRole role) {
return this.competitionManager.findJoinableCompetition(competitions, players, role);
}

/**
* Adds a new {@link Competition} to the given {@link Arena}.
*
Expand Down
Loading

0 comments on commit c8fd344

Please sign in to comment.