feature: mcmmo integration (#336)

Co-authored-by: Draycia <[email protected]>
Co-authored-by: Jason Penilla <[email protected]>
This commit is contained in:
authored and GitHub committed 2023-11-11 20:51:52 -07:00
1 parent c57ac04898
commit 955c33e522
11 files changed
+242 -6

No files matched your search

+7
View File
@@ -32,6 +32,9 @@ dependencies {
isTransitive = false
}
compileOnly(libs.towny)
compileOnly(libs.mcmmo) {
isTransitive = false
}
runtimeDownload(libs.guice) {
exclude("com.google.guava")
@@ -39,6 +42,7 @@ dependencies {
}
configurablePlugins.dependency(libs.towny)
configurablePlugins.dependency(libs.mcmmo)
tasks {
shadowJar {
@@ -78,7 +82,10 @@ paper {
dependency("EssentialsDiscord", PaperPluginDescription.Load.BEFORE, false)
dependency("DiscordSRV", PaperPluginDescription.Load.BEFORE, false)
dependency("MiniPlaceholders", PaperPluginDescription.Load.BEFORE, false)
// Integrations
dependency("Towny", PaperPluginDescription.Load.BEFORE, false)
dependency("mcMMO", PaperPluginDescription.Load.BEFORE, false)
}
bukkit {
@@ -43,6 +43,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.mcmmo.McmmoIntegration;
import net.draycia.carbon.paper.integration.towny.TownyIntegration;
import net.draycia.carbon.paper.listeners.PaperChatListener;
import net.draycia.carbon.paper.listeners.PaperPlayerJoinListener;
@@ -128,6 +129,9 @@ public final class CarbonChatPaperModule extends CarbonPlatformModule {
protected void configureIntegrations(final Multibinder<Integration> integrations, final Multibinder<Integration.ConfigMeta> configs) {
integrations.addBinding().to(TownyIntegration.class);
configs.addBinding().toInstance(TownyIntegration.configMeta());
integrations.addBinding().to(McmmoIntegration.class);
configs.addBinding().toInstance(McmmoIntegration.configMeta());
}
private void configureListeners() {
@@ -0,0 +1,83 @@
/*
* CarbonChat
*
* Copyright (c) 2023 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.mcmmo;
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 final class McmmoIntegration implements Integration {
private final CarbonChannelRegistry channelRegistry;
private final ConfigManager configManager;
private final Logger logger;
private final Config config;
@Inject
public McmmoIntegration(
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() {
return this.config.enabled && Bukkit.getPluginManager().isPluginEnabled("mcMMO");
}
@Override
public void register() {
if (this.config.partyChannel) {
if (this.configManager.primaryConfig().partyChat().enabled) {
this.logger.warn("Both CarbonChat parties and the mcMMO 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(McmmoPartyChannel.FILE_NAME, McmmoPartyChannel.class);
}
}
public static ConfigMeta configMeta() {
return Integration.configMeta("mcmmo", McmmoIntegration.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 mcMMO party chat.")
boolean partyChannel = true;
}
}
@@ -0,0 +1,116 @@
/*
* CarbonChat
*
* Copyright (c) 2023 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.mcmmo;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.party.PartyManager;
import com.google.inject.Inject;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import net.draycia.carbon.api.channels.ChannelPermissionResult;
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.bukkit.Bukkit;
import org.bukkit.entity.Player;
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 McmmoPartyChannel extends ConfigChatChannel {
public static final String FILE_NAME = "mcmmo-party.conf";
private transient @MonotonicNonNull @Inject CarbonMessages messages;
private transient @MonotonicNonNull @Inject UserManager<?> users;
public McmmoPartyChannel() {
this.key = Key.key("carbon", "partychat");
this.commandAliases = List.of("pc");
this.messageSource = new ConfigChannelMessageSource();
this.messageSource.defaults = Map.of(
"default_format", "(party: %mcmmo_party_name%) <display_name>: <message>",
"console", "[party: %mcmmo_party_name%] <username> - <uuid>: <message>"
);
this.messageSource.locales = Map.of(
Locale.US, Map.of("default_format", "(party: %mcmmo_party_name%) <display_name>: <message>")
);
}
@Override
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
return channelPermissionResult(
this.party(player) != null,
() -> this.messages.cannotUseMcmmoPartyChannel(player)
);
}
@Override
public ChannelPermissionResult hearingPermitted(final CarbonPlayer player) {
return channelPermissionResult(
this.party(player) != null,
() -> this.messages.cannotUseMcmmoPartyChannel(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.cannotUseMcmmoPartyChannel(sender));
}
return Collections.emptyList();
}
final List<Audience> recipients = new ArrayList<>();
for (final Player player : party.getOnlineMembers()) {
final @Nullable CarbonPlayer carbon = this.users.user(player.getUniqueId()).getNow(null);
if (carbon != null) {
recipients.add(carbon);
}
}
recipients.add(this.server.console());
return recipients;
}
private @Nullable Party party(final CarbonPlayer player) {
return PartyManager.getParty(Bukkit.getPlayer(player.uuid()));
}
}