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

@@ -43,6 +43,7 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import net.draycia.carbon.api.channels.ChannelRegistry;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.event.CarbonEventHandler;
@@ -89,6 +90,10 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
private record SpecialHandler<T extends ConfigChatChannel>(Class<T> cls, Supplier<T> defaultSupplier) {}
public <T extends ConfigChatChannel> void registerSpecialConfigChannel(final String fileName, final Class<T> type) {
if (this.handlers.containsKey(fileName)) {
throw new IllegalStateException("Attempting to register duplicate entry (existing: " + this.handlers.get(fileName)
+ ", new: " + type + ") for key " + fileName);
}
this.handlers.put(fileName, new SpecialHandler<>(type, () -> this.injector.getInstance(type)));
}
@@ -219,7 +224,16 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
this.saveSpecialDefaults();
List<Path> channelConfigs = FileUtil.listDirectoryEntries(this.configChannelDir, "*.conf");
if (channelConfigs.size() == this.handlers.size()) {
final Set<String> channelConfigFileNames = channelConfigs
.stream()
.map(Path::getFileName)
.map(Path::toString)
.collect(Collectors.toSet());
final Set<String> expectedHandlerFileNames = this.handlers.keySet();
if (channelConfigs.size() == this.handlers.size() && channelConfigFileNames.containsAll(expectedHandlerFileNames)) {
this.saveDefaultChannelConfig();
channelConfigs = FileUtil.listDirectoryEntries(this.configChannelDir, "*.conf");
}
@@ -236,7 +250,12 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
}
final Key channelKey = chatChannel.key();
if (this.defaultKey.equals(channelKey)) {
this.logger.info("Default channel is [" + channelKey + "]");
this.logger.info("Default channel is [{}]", channelKey);
}
if (this.channelRegistry.keys().contains(channelKey)) {
this.logger.warn("Channel with key [{}] has already been registered, skipping {}", channelKey, channelConfigFile);
continue;
}
this.injector.injectMembers(chatChannel);
@@ -245,7 +264,7 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
}
if (this.channel(this.defaultKey) == null) {
this.logger.warn("No default channel found! Default channel key: [" + this.defaultKey().asString() + "]");
this.logger.warn("No default channel found! Default channel key: [{}]", this.defaultKey());
}
final List<String> channelList = new ArrayList<>();
@@ -256,7 +275,7 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
final String channels = String.join(", ", channelList);
this.logger.info("Registered channels: [" + channels + "]");
this.logger.info("Registered channels: [{}]", channels);
}
private void saveSpecialDefaults() {
@@ -54,6 +54,7 @@ public class PartyChatChannel extends ConfigChatChannel {
public PartyChatChannel() {
this.key = Key.key("carbon", "partychat");
this.commandAliases = List.of("pc");
this.messageSource = new ConfigChannelMessageSource();
this.messageSource.defaults = Map.of(
"default_format", "(party: <party_name>) <display_name>: <message>",
@@ -97,7 +97,7 @@ public class PrimaryConfig {
@Comment("Settings for the clear chat command")
private ClearChatSettings clearChatSettings = new ClearChatSettings();
@Comment("Settings for integrations with other plugins/mods")
@Comment("Settings for integrations with other plugins/mods. Settings only apply when the relevant plugin/mod is present.")
private IntegrationConfigContainer integrations;
@Comment("Whether Carbon should check for updates using the GitHub API on startup.")
@@ -546,4 +546,7 @@ public interface CarbonMessages {
@Message("integrations.towny.cannot_use_town_channel")
Component cannotUseTownChannel(Audience audience);
@Message("integrations.mcmmo.cannot_use_party_channel")
Component cannotUseMcmmoPartyChannel(Audience audience);
}
@@ -152,3 +152,4 @@ pagination.footer=<gray>Page <page><white>/</white><pages> <aqua><buttons>
integrations.towny.cannot_use_alliance_channel=<red>You must join an alliance to use this channel.
integrations.towny.cannot_use_nation_channel=<red>You must join a nation to use this channel.
integrations.towny.cannot_use_town_channel=<red>You must join a town to use this channel.
integrations.mcmmo.cannot_use_party_channel=<red>You must join an mcMMO party to use this channel.
+2
View File
@@ -52,6 +52,7 @@ rabbitmq = "5.20.0"
nats = "2.16.14"
h2 = "2.2.224"
towny = "0.100.0.2"
mcmmo = "2.1.225"
# synced with version used by lowest supported mc (currently 1.19.4 on paper)
gson = "2.10"
@@ -141,3 +142,4 @@ 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" }
mcmmo = { group = "com.gmail.nossr50.mcMMO", name = "mcMMO", version.ref = "mcmmo" }
+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()));
}
}
+1 -1
View File
@@ -38,7 +38,7 @@ dependencyResolutionManagement {
}
}
// CodeMC (Minecraft Open Source)
maven("https://repo.codemc.io") {
maven("https://repo.codemc.io/repository/maven-public/") {
mavenContent {
includeGroup("com.gmail.nossr50.mcMMO")
}