From 72caf16a08cf375eba03166455aaa999c917827a Mon Sep 17 00:00:00 2001 From: JustusJG Date: Mon, 26 Jan 2026 12:42:48 +0100 Subject: [PATCH] Added Parties plugin integration (#735) Co-authored-by: Draycia --- .../common/messages/CarbonMessages.java | 3 + .../locale/messages-en_US.properties | 1 + gradle/libs.versions.toml | 2 + paper/build.gradle.kts | 4 + .../carbon/paper/CarbonChatPaperModule.java | 4 + .../AlessiodpPartiesIntegration.java | 88 ++++++++++++++ .../AlessiodpPartiesPartyChannel.java | 109 ++++++++++++++++++ settings.gradle.kts | 6 + 8 files changed, 217 insertions(+) create mode 100644 paper/src/main/java/net/draycia/carbon/paper/integration/alessiodp_parties/AlessiodpPartiesIntegration.java create mode 100644 paper/src/main/java/net/draycia/carbon/paper/integration/alessiodp_parties/AlessiodpPartiesPartyChannel.java diff --git a/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessages.java b/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessages.java index 52c07e5a..c3b1f5e0 100644 --- a/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessages.java +++ b/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessages.java @@ -658,6 +658,9 @@ public interface CarbonMessages { @Message("integrations.mcmmo.cannot_use_party_channel") Component cannotUseMcmmoPartyChannel(Audience audience); + @Message("integrations.adp_parties.cannot_use_party_channel") + Component cannotUseADPPartiesPartyChannel(Audience audience); + @Message("integrations.fuuid.cannot_use_faction_channel") Component cannotUseFactionChannel(Audience audience); diff --git a/common/src/main/resources/locale/messages-en_US.properties b/common/src/main/resources/locale/messages-en_US.properties index edb76b75..b6d84f1c 100644 --- a/common/src/main/resources/locale/messages-en_US.properties +++ b/common/src/main/resources/locale/messages-en_US.properties @@ -176,6 +176,7 @@ integrations.towny.cannot_use_alliance_channel=You must join an alliance to integrations.towny.cannot_use_nation_channel=You must join a nation to use this channel. integrations.towny.cannot_use_town_channel=You must join a town to use this channel. integrations.mcmmo.cannot_use_party_channel=You must join an mcMMO party to use this channel. +integrations.adp_parties.cannot_use_party_channel=You must join a party to use this channel. integrations.fuuid.cannot_use_faction_channel=You must join a faction to use this channel. integrations.fuuid.cannot_use_alliance_channel=You must join an alliance to use this channel. integrations.fuuid.cannot_use_truce_channel=You must have a truce with another faction to use this channel. diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 090c79b1..70e6985c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -62,6 +62,7 @@ towny = "0.101.2.5" plotsquared_bom = "1.55" plotsquared_core = "7.5.8" mcmmo = "2.2.043" +adpParties = "3.2.9" fuuid = "1.6.9.5-U0.6.35" # synced with version used by lowest supported mc (currently 1.21.4 on paper) @@ -161,4 +162,5 @@ towny = { group = "com.palmergames.bukkit.towny", name = "towny", version.ref = plotsquaredbom = { group = "com.intellectualsites.bom", name = "bom-newest", version.ref = "plotsquared_bom" } plotsquaredcore = { group = "com.intellectualsites.plotsquared", name = "plotsquared-core", version.ref = "plotsquared_core" } mcmmo = { group = "com.gmail.nossr50.mcMMO", name = "mcMMO", version.ref = "mcmmo" } +adpParties = { group = "com.alessiodp.parties", name = "parties-api", version.ref = "adpParties" } factionsUuid = { group = "com.massivecraft", name = "Factions", version.ref = "fuuid" } diff --git a/paper/build.gradle.kts b/paper/build.gradle.kts index b3ee29cc..c0181dfc 100644 --- a/paper/build.gradle.kts +++ b/paper/build.gradle.kts @@ -37,6 +37,7 @@ dependencies { compileOnly(libs.mcmmo) { isTransitive = false } + compileOnly(libs.adpParties) compileOnly(libs.factionsUuid) implementation(libs.plotsquaredbom) compileOnly(libs.plotsquaredcore) @@ -45,6 +46,7 @@ dependencies { configurablePlugins { dependency(libs.towny) dependency(libs.mcmmo) + dependency(libs.adpParties) dependency(libs.factionsUuid) dependency(libs.plotsquaredbom) dependency(libs.plotsquaredcore) @@ -65,6 +67,7 @@ tasks { github("MiniPlaceholders", "MiniPlaceholders", libs.versions.miniplaceholders.get(), "MiniPlaceholders-Paper-${libs.versions.miniplaceholders.get()}.jar") github("MiniPlaceholders", "PlaceholderAPI-Expansion", "1.2.0", "PlaceholderAPI-Expansion-1.2.0.jar") hangar("PlaceholderAPI", libs.versions.placeholderapi.get()) + modrinth("parties", libs.versions.adpParties.get()) } pluginJars.from(luckperms.flatMap { it.outputFile }) providers.gradleProperty("smokeTest").map { it.toBoolean() }.getOrElse(false).let { smokeTest -> @@ -113,6 +116,7 @@ paperPluginYaml { // Integrations server("Towny", Load.BEFORE, false) server("mcMMO", Load.BEFORE, false) + server("Parties", Load.BEFORE, false) server("Factions", Load.BEFORE, false) server("PlotSquared", Load.BEFORE, false) } diff --git a/paper/src/main/java/net/draycia/carbon/paper/CarbonChatPaperModule.java b/paper/src/main/java/net/draycia/carbon/paper/CarbonChatPaperModule.java index 7ad0b80d..28a8207d 100644 --- a/paper/src/main/java/net/draycia/carbon/paper/CarbonChatPaperModule.java +++ b/paper/src/main/java/net/draycia/carbon/paper/CarbonChatPaperModule.java @@ -41,6 +41,7 @@ import net.draycia.carbon.common.users.ProfileResolver; import net.draycia.carbon.common.util.CloudUtils; import net.draycia.carbon.paper.command.PaperCommander; import net.draycia.carbon.paper.command.PaperPlayerCommander; +import net.draycia.carbon.paper.integration.alessiodp_parties.AlessiodpPartiesIntegration; import net.draycia.carbon.paper.integration.dsrv.DSRVIntegration; import net.draycia.carbon.paper.integration.essxd.EssXDIntegration; import net.draycia.carbon.paper.integration.fuuid.FactionsIntegration; @@ -129,6 +130,9 @@ public final class CarbonChatPaperModule extends CarbonPlatformModule { integrations.addBinding().to(McmmoIntegration.class); configs.addBinding().toInstance(McmmoIntegration.configMeta()); + integrations.addBinding().to(AlessiodpPartiesIntegration.class); + configs.addBinding().toInstance(AlessiodpPartiesIntegration.configMeta()); + integrations.addBinding().to(FactionsIntegration.class); configs.addBinding().toInstance(FactionsIntegration.configMeta()); diff --git a/paper/src/main/java/net/draycia/carbon/paper/integration/alessiodp_parties/AlessiodpPartiesIntegration.java b/paper/src/main/java/net/draycia/carbon/paper/integration/alessiodp_parties/AlessiodpPartiesIntegration.java new file mode 100644 index 00000000..42e7394f --- /dev/null +++ b/paper/src/main/java/net/draycia/carbon/paper/integration/alessiodp_parties/AlessiodpPartiesIntegration.java @@ -0,0 +1,88 @@ +/* + * CarbonChat + * + * Copyright (c) 2024 Josua Parks (Vicarious) + * Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package net.draycia.carbon.paper.integration.alessiodp_parties; + +import com.google.inject.Inject; +import net.draycia.carbon.common.channels.CarbonChannelRegistry; +import net.draycia.carbon.common.config.ConfigManager; +import net.draycia.carbon.common.integration.Integration; +import org.apache.logging.log4j.Logger; +import org.bukkit.Bukkit; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.framework.qual.DefaultQualifier; +import org.spongepowered.configurate.objectmapping.ConfigSerializable; +import org.spongepowered.configurate.objectmapping.meta.Comment; + +@DefaultQualifier(NonNull.class) +public class AlessiodpPartiesIntegration implements Integration { + + private final CarbonChannelRegistry channelRegistry; + private final ConfigManager configManager; + private final Logger logger; + private final AlessiodpPartiesIntegration.Config config; + + @Inject + public AlessiodpPartiesIntegration( + final CarbonChannelRegistry channelRegistry, + final ConfigManager configManager, + final Logger logger + ) { + this.channelRegistry = channelRegistry; + this.configManager = configManager; + this.logger = logger; + this.config = this.config(configManager, configMeta()); + } + + @Override + public boolean eligible() { + try { + Class.forName("com.alessiodp.parties.api.Parties"); + return this.config.enabled && Bukkit.getPluginManager().isPluginEnabled("Parties"); + } catch (final ClassNotFoundException ignored) { + return false; + } + } + + @Override + public void register() { + if (this.config.partyChannel) { + if (this.configManager.primaryConfig().partyChat().enabled) { + this.logger.warn("Both CarbonChat parties and the Parties party chat channel are enabled!"); + this.logger.warn("Usually, you want one or the other enabled. Additionally, their default channel configs will conflict."); + } + this.channelRegistry.registerSpecialConfigChannel(AlessiodpPartiesPartyChannel.FILE_NAME, AlessiodpPartiesPartyChannel.class); + } + } + + public static ConfigMeta configMeta() { + return Integration.configMeta("alessiodp-parties", AlessiodpPartiesIntegration.Config.class); + } + + @ConfigSerializable + public static final class Config { + + boolean enabled = true; + + @Comment("You will likely want to disable Carbon's built-in party system above when using Parties party chat.") + boolean partyChannel = true; + + } + +} diff --git a/paper/src/main/java/net/draycia/carbon/paper/integration/alessiodp_parties/AlessiodpPartiesPartyChannel.java b/paper/src/main/java/net/draycia/carbon/paper/integration/alessiodp_parties/AlessiodpPartiesPartyChannel.java new file mode 100644 index 00000000..a6644584 --- /dev/null +++ b/paper/src/main/java/net/draycia/carbon/paper/integration/alessiodp_parties/AlessiodpPartiesPartyChannel.java @@ -0,0 +1,109 @@ +/* + * CarbonChat + * + * Copyright (c) 2024 Josua Parks (Vicarious) + * Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package net.draycia.carbon.paper.integration.alessiodp_parties; + +import com.alessiodp.parties.api.Parties; +import com.alessiodp.parties.api.interfaces.Party; +import com.alessiodp.parties.api.interfaces.PartyPlayer; +import com.google.inject.Inject; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import net.draycia.carbon.api.channels.ChannelPermissions; +import net.draycia.carbon.api.users.CarbonPlayer; +import net.draycia.carbon.api.users.UserManager; +import net.draycia.carbon.common.channels.ConfigChatChannel; +import net.draycia.carbon.common.channels.messages.ConfigChannelMessageSource; +import net.draycia.carbon.common.messages.CarbonMessages; +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.key.Key; +import org.checkerframework.checker.nullness.qual.MonotonicNonNull; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.framework.qual.DefaultQualifier; +import org.spongepowered.configurate.objectmapping.ConfigSerializable; + +import static net.draycia.carbon.api.channels.ChannelPermissionResult.channelPermissionResult; + +@DefaultQualifier(NonNull.class) +@ConfigSerializable +public class AlessiodpPartiesPartyChannel extends ConfigChatChannel { + + public static final String FILE_NAME = "alessiodp-parties-party.conf"; + + private transient @MonotonicNonNull + @Inject CarbonMessages messages; + private transient @MonotonicNonNull @Inject UserManager users; + + public AlessiodpPartiesPartyChannel() { + this.key = Key.key("carbon", "partychat"); + this.commandAliases = List.of("pc"); + + this.messageSource = new ConfigChannelMessageSource(); + this.messageSource.defaults = Map.of( + "default_format", "(party: %party%) : ", + "console", "[party: %party%] : " + ); + } + + @Override + public ChannelPermissions permissions() { + return ChannelPermissions.uniformDynamic(player -> channelPermissionResult( + this.party(player) != null, + () -> this.messages.cannotUseADPPartiesPartyChannel(player) + )); + } + + @Override + public List recipients(final CarbonPlayer sender) { + final @Nullable Party party = this.party(sender); + + if (party == null) { + if (sender.online()) { + sender.sendMessage(this.messages.cannotUseADPPartiesPartyChannel(sender)); + } + + return Collections.emptyList(); + } + + final List recipients = new ArrayList<>(); + for (final PartyPlayer player : party.getOnlineMembers()) { + final @Nullable CarbonPlayer carbon = this.users.user(player.getPlayerUUID()).getNow(null); + if (carbon != null) { + recipients.add(carbon); + } + } + + recipients.add(this.server.console()); + + return recipients; + } + + private @Nullable Party party(final CarbonPlayer player) { + return Parties.getApi().getPartyOfPlayer(player.uuid()); + } + + @Override + public boolean shouldCrossServer() { + return false; + } + +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 8e34a6ca..d4d8cd64 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -58,6 +58,12 @@ dependencyResolutionManagement { includeGroup("com.gmail.nossr50.mcMMO") } } + // Parties + maven("https://repo.alessiodp.com/releases/") { + content { + includeGroup("com.alessiodp.parties") + } + } } repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) }