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 c056f085..b3d42a93 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 @@ -653,4 +653,7 @@ public interface CarbonMessages { @Message("integrations.fuuid.cannot_use_mod_channel") Component cannotUseFactionModChannel(Audience audience); + @Message("integrations.plotsquared.cannot_use_plot_channel") + Component cannotUsePlotChannel(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 2a74c7fe..bd27c2bd 100644 --- a/common/src/main/resources/locale/messages-en_US.properties +++ b/common/src/main/resources/locale/messages-en_US.properties @@ -176,3 +176,4 @@ integrations.fuuid.cannot_use_faction_channel=You must join a faction to us 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. integrations.fuuid.cannot_use_mod_channel=You must be a faction mod/admin to use this channel. +integrations.plotsquared.cannot_use_plot_channel=You must be in a plot to use this channel. diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4d401b9d..5e664520 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -53,6 +53,8 @@ rabbitmq = "5.24.0" nats = "2.20.5" h2 = "2.3.232" towny = "0.100.3.0" +plotsquared_bom = "1.52" +plotsquared_core = "7.4.1" mcmmo = "2.2.004" fuuid = "1.6.9.5-U0.6.35" @@ -96,7 +98,7 @@ cloudSigned = { group = "org.incendo", name = "cloud-minecraft-signed-arguments" cloudPaperSigned = { group = "org.incendo", name = "cloud-paper-signed-arguments", version.ref = "cloudMinecraft" } cloudSponge = { group = "org.incendo", name = "cloud-sponge", version.ref = "cloudSponge" } cloudVelocity = { group = "org.incendo", name = "cloud-velocity", version.ref = "cloudMinecraft" } -cloudFabric = { group = "org.incendo", name = "cloud-fabric", version.ref = "cloudModded"} +cloudFabric = { group = "org.incendo", name = "cloud-fabric", version.ref = "cloudModded" } configurateCore = { group = "org.spongepowered", name = "configurate-core", version.ref = "configurate" } configurateHocon = { group = "org.spongepowered", name = "configurate-hocon", version.ref = "configurate" } @@ -149,5 +151,7 @@ discordsrv = { group = "com.discordsrv", name = "discordsrv", version.ref = "dis placeholderapi = { group = "me.clip", name = "placeholderapi", version.ref = "placeholderapi" } miniplaceholders = { group = "io.github.miniplaceholders", name = "miniplaceholders-api", version.ref = "miniplaceholders" } towny = { group = "com.palmergames.bukkit.towny", name = "towny", version.ref = "towny" } +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" } factionsUuid = { group = "com.massivecraft", name = "Factions", version.ref = "fuuid" } diff --git a/paper/build.gradle.kts b/paper/build.gradle.kts index cdc87262..800ad214 100644 --- a/paper/build.gradle.kts +++ b/paper/build.gradle.kts @@ -39,12 +39,16 @@ dependencies { isTransitive = false } compileOnly(libs.factionsUuid) + implementation(libs.plotsquaredbom) + compileOnly(libs.plotsquaredcore) } configurablePlugins { dependency(libs.towny) dependency(libs.mcmmo) dependency(libs.factionsUuid) + dependency(libs.plotsquaredbom) + dependency(libs.plotsquaredcore) } tasks { @@ -92,6 +96,7 @@ paperPluginYaml { server("Towny", Load.BEFORE, false) server("mcMMO", 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 9f06595d..9b94e7ed 100644 --- a/paper/src/main/java/net/draycia/carbon/paper/CarbonChatPaperModule.java +++ b/paper/src/main/java/net/draycia/carbon/paper/CarbonChatPaperModule.java @@ -45,6 +45,7 @@ import net.draycia.carbon.paper.integration.dsrv.DSRVIntegration; import net.draycia.carbon.paper.integration.essxd.EssXDIntegration; import net.draycia.carbon.paper.integration.fuuid.FactionsIntegration; import net.draycia.carbon.paper.integration.mcmmo.McmmoIntegration; +import net.draycia.carbon.paper.integration.plotsquared.PlotSquaredIntegration; import net.draycia.carbon.paper.integration.towny.TownyIntegration; import net.draycia.carbon.paper.listeners.PaperChatListener; import net.draycia.carbon.paper.listeners.PaperPlayerJoinListener; @@ -134,6 +135,9 @@ public final class CarbonChatPaperModule extends CarbonPlatformModule { integrations.addBinding().to(DSRVIntegration.class); configs.addBinding().toInstance(DSRVIntegration.configMeta()); + + integrations.addBinding().to(PlotSquaredIntegration.class); + configs.addBinding().toInstance(PlotSquaredIntegration.configMeta()); } private void configureListeners() { diff --git a/paper/src/main/java/net/draycia/carbon/paper/integration/plotsquared/PlotChannel.java b/paper/src/main/java/net/draycia/carbon/paper/integration/plotsquared/PlotChannel.java new file mode 100644 index 00000000..bd47e919 --- /dev/null +++ b/paper/src/main/java/net/draycia/carbon/paper/integration/plotsquared/PlotChannel.java @@ -0,0 +1,127 @@ +/* + * 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.plotsquared; + +import com.google.inject.Inject; +import com.plotsquared.core.PlotAPI; +import com.plotsquared.core.player.PlotPlayer; +import com.plotsquared.core.plot.Plot; +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.config.ConfigHeader; +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.key.Key; +import net.kyori.adventure.text.Component; +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 +@ConfigHeader(PlotChannel.PLOT_CHANNEL_HEADER) +public class PlotChannel extends ConfigChatChannel { + + protected static final String PLOT_CHANNEL_HEADER = """ + See the PlotSquared Wiki at https://intellectualsites.gitbook.io/plotsquared/customization/placeholders + for placeholders PlotSquared provides to PlaceholderAPI. + """; + protected final static PlotAPI PLOT_API = new PlotAPI(); + + public static final String FILE_NAME = "plotsquared-plotchat.conf"; + + protected transient @MonotonicNonNull @Inject UserManager users; + + public PlotChannel() { + this.key = Key.key("carbon", "plotchat"); + this.commandAliases = List.of("local"); + + this.messageSource = new ConfigChannelMessageSource(); + this.messageSource.defaults = Map.of( + "default_format", ": ", + "console", ": " + ); + } + + protected @Nullable Plot plot(final CarbonPlayer carbonPlayer) { + final @Nullable PlotPlayer plotPlayer = PLOT_API.wrapPlayer(carbonPlayer.uuid()); + if (plotPlayer != null) { + return plotPlayer.getCurrentPlot(); + } + return null; + } + + @Override + public ChannelPermissions permissions() { + return ChannelPermissions.uniformDynamic(player -> channelPermissionResult( + this.plot(player) != null, + () -> this.cannotUseChannel(player) + )); + } + + @Override + public List recipients(final CarbonPlayer sender) { + final @Nullable Plot plot = this.plot(sender); + + if (plot == null) { + if (sender.online()) { + sender.sendMessage(this.cannotUseChannel(sender)); + } + + return Collections.emptyList(); + } + + final List recipients = new ArrayList<>(); + for (final PlotPlayer plotPlayer : this.onlinePlayers(plot)) { + final @Nullable CarbonPlayer carbon = this.users.user(plotPlayer.getUUID()).getNow(null); + if (carbon != null) { + recipients.add(carbon); + } + } + + recipients.add(this.server.console()); + + return recipients; + } + + protected List> onlinePlayers(final Plot plot) { + return plot.getPlayersInPlot(); + } + + protected Component cannotUseChannel(final CarbonPlayer player) { + return this.messages.cannotUsePlotChannel(player); + } + + @Override + public boolean shouldCrossServer() { + return false; + } + +} diff --git a/paper/src/main/java/net/draycia/carbon/paper/integration/plotsquared/PlotSquaredIntegration.java b/paper/src/main/java/net/draycia/carbon/paper/integration/plotsquared/PlotSquaredIntegration.java new file mode 100644 index 00000000..12a106fe --- /dev/null +++ b/paper/src/main/java/net/draycia/carbon/paper/integration/plotsquared/PlotSquaredIntegration.java @@ -0,0 +1,68 @@ +/* + * 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.plotsquared; + +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.bukkit.Bukkit; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.framework.qual.DefaultQualifier; +import org.spongepowered.configurate.objectmapping.ConfigSerializable; + +@DefaultQualifier(NonNull.class) +public final class PlotSquaredIntegration implements Integration { + + private final CarbonChannelRegistry channelRegistry; + private final Config config; + + @Inject + public PlotSquaredIntegration( + final CarbonChannelRegistry channelRegistry, + final ConfigManager configManager + ) { + this.channelRegistry = channelRegistry; + this.config = this.config(configManager, configMeta()); + } + + @Override + public boolean eligible() { + return this.config.enabled && Bukkit.getPluginManager().isPluginEnabled("PlotSquared"); + } + + @Override + public void register() { + if (this.config.plotChannel) { + this.channelRegistry.registerSpecialConfigChannel(PlotChannel.FILE_NAME, PlotChannel.class); + } + } + + public static ConfigMeta configMeta() { + return Integration.configMeta("plotsquared", PlotSquaredIntegration.Config.class); + } + + @ConfigSerializable + public static final class Config { + boolean enabled = true; + boolean plotChannel = true; + } + +}