mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
feature: mcmmo integration (#336)
Co-authored-by: Draycia <[email protected]> Co-authored-by: Jason Penilla <[email protected]>
This commit is contained in:
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);
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user