mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 14:38:51 +00:00
Added Parties plugin integration (#735)
Co-authored-by: Draycia <[email protected]>
This commit is contained in:
1 parent
c13a99564d
commit
72caf16a08
8 files changed
+217
No files matched your search
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
+88
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+109
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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%) <display_name>: <message>",
|
||||
"console", "[party: %party%] <username>: <message>"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelPermissions permissions() {
|
||||
return ChannelPermissions.uniformDynamic(player -> channelPermissionResult(
|
||||
this.party(player) != null,
|
||||
() -> this.messages.cannotUseADPPartiesPartyChannel(player)
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Audience> 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<Audience> 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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user