Add channel settings

Still need to enable automatic usage of defaults for fallbacks.
This commit is contained in:
Draycia committed 2020-09-25 01:45:36 -07:00
1 parent 935f5a904b
commit 6c9810ea72
15 files changed
+555 -232

No files matched your search

+1 -1
View File
@@ -19,7 +19,7 @@ dependencies {
api 'com.intellectualsites:cloud-core:1.0-SNAPSHOT'
api 'org.spongepowered:configurate-yaml:4.0.0-SNAPSHOT'
api 'org.spongepowered:configurate-hocon:4.0.0-SNAPSHOT'
api 'org.slf4j:slf4j-api:1.7.25'
api 'net.luckperms:api:5.1'
@@ -5,6 +5,7 @@ import net.draycia.carbon.api.adventure.MessageProcessor;
import net.draycia.carbon.api.channels.ChannelRegistry;
import net.draycia.carbon.api.commands.settings.CommandSettingsRegistry;
import net.draycia.carbon.api.config.CarbonSettings;
import net.draycia.carbon.api.config.ChannelSettings;
import net.draycia.carbon.api.config.ModerationSettings;
import net.draycia.carbon.api.messaging.MessageService;
import net.draycia.carbon.api.users.ChatUser;
@@ -39,6 +40,8 @@ public interface CarbonChat {
@NonNull CarbonSettings carbonSettings();
@NonNull ChannelSettings channelSettings();
@NonNull ChannelRegistry channelRegistry();
@NonNull CommandSettingsRegistry commandSettings();
@@ -1,6 +1,6 @@
package net.draycia.carbon.api.adventure;
import org.spongepowered.configurate.BasicConfigurationNode;
import org.spongepowered.configurate.CommentedConfigurationNode;
import org.spongepowered.configurate.objectmapping.ObjectMapper;
import org.spongepowered.configurate.objectmapping.ObjectMappingException;
import org.spongepowered.configurate.objectmapping.Setting;
@@ -19,11 +19,11 @@ public class CarbonTranslations {
}
}
public static CarbonTranslations loadFrom(final BasicConfigurationNode node) throws ObjectMappingException {
public static CarbonTranslations loadFrom(final CommentedConfigurationNode node) throws ObjectMappingException {
return MAPPER.bindToNew().populate(node);
}
public void saveTo(final BasicConfigurationNode node) throws ObjectMappingException {
public void saveTo(final CommentedConfigurationNode node) throws ObjectMappingException {
MAPPER.bind(this).serialize(node);
}
@@ -4,7 +4,7 @@ import net.draycia.carbon.api.channels.ChatChannel;
import net.kyori.registry.Registry;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.configurate.BasicConfigurationNode;
import org.spongepowered.configurate.CommentedConfigurationNode;
import org.spongepowered.configurate.objectmapping.ObjectMapper;
import org.spongepowered.configurate.objectmapping.ObjectMappingException;
import org.spongepowered.configurate.objectmapping.Setting;
@@ -28,11 +28,11 @@ public class CommandSettingsRegistry implements Registry<String, CommandSettings
}
}
public static CommandSettingsRegistry loadFrom(final BasicConfigurationNode node) throws ObjectMappingException {
public static CommandSettingsRegistry loadFrom(final CommentedConfigurationNode node) throws ObjectMappingException {
return MAPPER.bindToNew().populate(node);
}
public void saveTo(final BasicConfigurationNode node) throws ObjectMappingException {
public void saveTo(final CommentedConfigurationNode node) throws ObjectMappingException {
MAPPER.bind(this).serialize(node);
}
@@ -2,16 +2,18 @@ package net.draycia.carbon.api.config;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.configurate.BasicConfigurationNode;
import org.spongepowered.configurate.CommentedConfigurationNode;
import org.spongepowered.configurate.objectmapping.ObjectMapper;
import org.spongepowered.configurate.objectmapping.ObjectMappingException;
import org.spongepowered.configurate.objectmapping.Setting;
import org.spongepowered.configurate.serialize.ConfigSerializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
@ConfigSerializable
public class CarbonSettings {
@@ -26,11 +28,11 @@ public class CarbonSettings {
}
}
public static CarbonSettings loadFrom(final BasicConfigurationNode node) throws ObjectMappingException {
public static CarbonSettings loadFrom(final CommentedConfigurationNode node) throws ObjectMappingException {
return MAPPER.bindToNew().populate(node);
}
public void saveTo(final BasicConfigurationNode node) throws ObjectMappingException {
public void saveTo(final CommentedConfigurationNode node) throws ObjectMappingException {
MAPPER.bind(this).serialize(node);
}
@@ -44,7 +46,7 @@ public class CarbonSettings {
private boolean showTips = true;
@Setting(comment = "")
private @NonNull List<@NonNull ChannelSettings> channelSettings = new ArrayList<>(); // TODO: unfuck this, it's loaded from file?
private @NonNull List<@NonNull ChannelOptions> channelSettings = new ArrayList<>(); // TODO: unfuck this, it's loaded from file?
@Setting(comment = "Options: JSON, MYSQL")
private @Nullable StorageType storageType = StorageType.JSON;
@@ -86,6 +88,14 @@ public class CarbonSettings {
"\nFor example, channel-on-join: \"global\" sets their channel to global on join")
private @Nullable String channelOnJoin = "";
@Setting private List<Pattern> itemLinkPatterns =
Collections.singletonList(Pattern.compile(Pattern.quote("[item]")));
@NonNull
public List<@NonNull Pattern> itemLinkPatterns() {
return this.itemLinkPatterns;
}
public @NonNull String spyPrefix() {
return this.spyPrefix;
}
@@ -98,7 +108,7 @@ public class CarbonSettings {
return this.showTips;
}
public @NonNull List<@NonNull ChannelSettings> channelSettings() {
public @NonNull List<@NonNull ChannelOptions> channelSettings() {
return this.channelSettings;
}
@@ -0,0 +1,176 @@
package net.draycia.carbon.api.config;
import net.draycia.carbon.api.Context;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.configurate.objectmapping.Setting;
import org.spongepowered.configurate.serialize.ConfigSerializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ConfigSerializable
public class ChannelOptions {
@Setting private String key = "channel";
@Setting private String color = "#FFFFFF";
@Setting private Map<String, Context> contexts = new HashMap<>(); // TODO: set defaults
@Setting private Map<String, String> formats = new HashMap<>(); // TODO: set defaults
@Setting private String defaultFormatName = "default";
@Setting private boolean isDefault = false;
@Setting private boolean ignorable = true;
@Setting private boolean crossServer = true;
@Setting private boolean honorsRecipientList = false;
@Setting private boolean permissionGroupMatching = false;
@Setting private List<String> groupOverrides = new ArrayList<>();
@Setting private String name = "";
@Setting private String messagePrefix = "";
@Setting private List<String> aliases = new ArrayList<>();
@Setting private boolean shouldCancelChatEvent = false;
@Setting private boolean primaryGroupOnly = false;
@Setting private String switchMessage = "<gray>You are now in <color><channel> <gray>chat!";
@Setting private String switchOtherMessage = "<gray><player> <reset><gray>is now in <color><channel> <gray>chat!";
@Setting private String switchFailureMessage = "<red>You cannot use channel <channel>!";
@Setting private String toggleOnMessage = "<gray>You can now see <color><channel> <gray>chat!";
@Setting private String toggleOffMessage = "<gray>You can no longer see <color><channel> <gray>chat!";
@Setting private String toggleOtherOnMessage = "<gray><player> <reset><gray>can now see <color><channel> <gray>chat!";
@Setting private String toggleOtherOffMessage = "<gray><player> <reset><gray>can no longer see <color><channel> <gray>chat!";
@Setting private String cannotUseMessage = "You cannot use that channel!";
@Setting private String cannotIgnoreMessage = "<red>You cannot ignore that channel!";
public static ChannelOptions defaultChannel() {
final ChannelOptions settings = new ChannelOptions();
settings.key = "global";
settings.isDefault = true;
settings.name = "Global";
settings.formats = Collections.singletonMap("default", "<color><<displayname><reset><color>> <message>");
return settings;
}
@NonNull
public String key() {
return this.key;
}
@Nullable
public String color() {
return this.color;
}
@Nullable
public Map<String, Context> contexts() {
return this.contexts;
}
@Nullable
public Map<String, String> formats() {
return this.formats;
}
@Nullable
public String defaultFormatName() {
return this.defaultFormatName;
}
public boolean isDefault() {
return this.isDefault;
}
public boolean ignorable() {
return this.ignorable;
}
public boolean crossServer() {
return this.crossServer;
}
public boolean honorsRecipientList() {
return this.honorsRecipientList;
}
public boolean permissionGroupMatching() {
return this.permissionGroupMatching;
}
@NonNull
public List<@NonNull String> groupOverrides() {
return this.groupOverrides;
}
@NonNull
public String name() {
if (this.name == null) {
return this.key;
}
return this.name;
}
@Nullable
public String messagePrefix() {
return this.messagePrefix;
}
@Nullable
public String switchMessage() {
return this.switchMessage;
}
@Nullable
public String switchOtherMessage() {
return this.switchOtherMessage;
}
@Nullable
public String switchFailureMessage() {
return this.switchFailureMessage;
}
@Nullable
public String cannotIgnoreMessage() {
return this.cannotIgnoreMessage;
}
@Nullable
public String toggleOffMessage() {
return this.toggleOffMessage;
}
@Nullable
public String toggleOnMessage() {
return this.toggleOnMessage;
}
@Nullable
public String toggleOtherOnMessage() {
return this.toggleOtherOnMessage;
}
@Nullable
public String toggleOtherOffMessage() {
return this.toggleOtherOffMessage;
}
@Nullable
public String cannotUseMessage() {
return this.cannotUseMessage;
}
public boolean primaryGroupOnly() {
return this.primaryGroupOnly;
}
public boolean shouldCancelChatEvent() {
return this.shouldCancelChatEvent;
}
@Nullable
public List<String> aliases() {
return this.aliases;
}
}
@@ -1,173 +1,52 @@
package net.draycia.carbon.api.config;
import net.draycia.carbon.api.Context;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.configurate.CommentedConfigurationNode;
import org.spongepowered.configurate.objectmapping.ObjectMapper;
import org.spongepowered.configurate.objectmapping.ObjectMappingException;
import org.spongepowered.configurate.objectmapping.Setting;
import org.spongepowered.configurate.serialize.ConfigSerializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
@ConfigSerializable
public class ChannelSettings {
@Setting private String key = "channel";
@Setting private String color = "#FFFFFF";
@Setting private Map<String, Context> contexts = new HashMap<>(); // TODO: set defaults
@Setting private Map<String, String> formats = new HashMap<>(); // TODO: set defaults
@Setting private String defaultFormatName = "default";
@Setting private boolean isDefault = false;
@Setting private boolean ignorable = true;
@Setting private boolean crossServer = true;
@Setting private boolean honorsRecipientList = false;
@Setting private boolean permissionGroupMatching = false;
@Setting private List<String> groupOverrides = new ArrayList<>();
@Setting private String name = null;
@Setting private String messagePrefix = "";
@Setting private List<Pattern> itemLinkPatterns = Collections.singletonList(Pattern.compile(Pattern.quote("[item]")));
@Setting private List<String> aliases = new ArrayList<>();
@Setting private boolean shouldCancelChatEvent = false;
@Setting private boolean primaryGroupOnly = false;
@Setting private String switchMessage = "<gray>You are now in <color><channel> <gray>chat!";
@Setting private String switchOtherMessage = "<gray><player> <reset><gray>is now in <color><channel> <gray>chat!";
@Setting private String switchFailureMessage = "<red>You cannot use channel <channel>!";
@Setting private String toggleOnMessage = "<gray>You can now see <color><channel> <gray>chat!";
@Setting private String toggleOffMessage = "<gray>You can no longer see <color><channel> <gray>chat!";
@Setting private String toggleOtherOnMessage = "<gray><player> <reset><gray>can now see <color><channel> <gray>chat!";
@Setting private String toggleOtherOffMessage = "<gray><player> <reset><gray>can no longer see <color><channel> <gray>chat!";
@Setting private String cannotUseMessage = "You cannot use that channel!";
@Setting private String cannotIgnoreMessage = "<red>You cannot ignore that channel!";
private static final ObjectMapper<ChannelSettings> MAPPER;
@NonNull
public String key() {
return this.key;
}
@Nullable
public String color() {
return this.color;
}
@Nullable
public Map<String, Context> contexts() {
return this.contexts;
}
@Nullable
public Map<String, String> formats() {
return this.formats;
}
@Nullable
public String defaultFormatName() {
return this.defaultFormatName;
}
public boolean isDefault() {
return this.isDefault;
}
public boolean ignorable() {
return this.ignorable;
}
public boolean crossServer() {
return this.crossServer;
}
public boolean honorsRecipientList() {
return this.honorsRecipientList;
}
public boolean permissionGroupMatching() {
return this.permissionGroupMatching;
}
@NonNull
public List<@NonNull String> groupOverrides() {
return this.groupOverrides;
}
@NonNull
public String name() {
if (this.name == null) {
return this.key;
static {
try {
MAPPER = ObjectMapper.forClass(ChannelSettings.class); // We hold on to the instance of our ObjectMapper
} catch (final ObjectMappingException e) {
throw new ExceptionInInitializerError(e);
}
return this.name;
}
@Nullable
public String messagePrefix() {
return this.messagePrefix;
public static ChannelSettings loadFrom(final CommentedConfigurationNode node) throws ObjectMappingException {
return MAPPER.bindToNew().populate(node);
}
@Nullable
public String switchMessage() {
return this.switchMessage;
public void saveTo(final CommentedConfigurationNode node) throws ObjectMappingException {
MAPPER.bind(this).serialize(node);
}
@Nullable
public String switchOtherMessage() {
return this.switchOtherMessage;
@Setting(comment = "All options here act like the defaults for all channels.\nAdding any of these options to any channel overrides the relevant defaults.")
private SharedChannelOptions sharedChannelOptions = new SharedChannelOptions();
@Setting
private Map<String, ChannelOptions> channelOptions =
Collections.singletonMap("global", ChannelOptions.defaultChannel());
public SharedChannelOptions defaultChannelOptions() {
return this.sharedChannelOptions;
}
@Nullable
public String switchFailureMessage() {
return this.switchFailureMessage;
public Map<String, ChannelOptions> channelOptions() {
return this.channelOptions;
}
@Nullable
public String cannotIgnoreMessage() {
return this.cannotIgnoreMessage;
}
@Nullable
public String toggleOffMessage() {
return this.toggleOffMessage;
}
@Nullable
public String toggleOnMessage() {
return this.toggleOnMessage;
}
@Nullable
public String toggleOtherOnMessage() {
return this.toggleOtherOnMessage;
}
@Nullable
public String toggleOtherOffMessage() {
return this.toggleOtherOffMessage;
}
@Nullable
public String cannotUseMessage() {
return this.cannotUseMessage;
}
public boolean primaryGroupOnly() {
return this.primaryGroupOnly;
}
public boolean shouldCancelChatEvent() {
return this.shouldCancelChatEvent;
}
@NonNull
public List<@NonNull Pattern> itemLinkPatterns() {
return this.itemLinkPatterns;
}
@Nullable
public List<String> aliases() {
return this.aliases;
public ChannelOptions channelOptions(final String name) {
return this.channelOptions.get(name);
}
}
@@ -1,6 +1,6 @@
package net.draycia.carbon.api.config;
import org.spongepowered.configurate.BasicConfigurationNode;
import org.spongepowered.configurate.CommentedConfigurationNode;
import org.spongepowered.configurate.objectmapping.ObjectMapper;
import org.spongepowered.configurate.objectmapping.ObjectMappingException;
import org.spongepowered.configurate.objectmapping.Setting;
@@ -25,11 +25,11 @@ public class ModerationSettings {
}
}
public static ModerationSettings loadFrom(final BasicConfigurationNode node) throws ObjectMappingException {
public static ModerationSettings loadFrom(final CommentedConfigurationNode node) throws ObjectMappingException {
return MAPPER.bindToNew().populate(node);
}
public void saveTo(final BasicConfigurationNode node) throws ObjectMappingException {
public void saveTo(final CommentedConfigurationNode node) throws ObjectMappingException {
MAPPER.bind(this).serialize(node);
}
@@ -0,0 +1,132 @@
package net.draycia.carbon.api.config;
import net.draycia.carbon.api.Context;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.configurate.objectmapping.Setting;
import org.spongepowered.configurate.serialize.ConfigSerializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ConfigSerializable
public class SharedChannelOptions {
@Setting private String color = "#FFFFFF";
@Setting private Map<String, Context> contexts = new HashMap<>(); // TODO: set defaults
@Setting private Map<String, String> formats = new HashMap<>(); // TODO: set defaults
@Setting private String defaultFormatName = "default";
@Setting private boolean ignorable = true;
@Setting private boolean crossServer = true;
@Setting private boolean honorsRecipientList = false;
@Setting private boolean permissionGroupMatching = false;
@Setting private List<String> groupOverrides = new ArrayList<>();
@Setting private boolean shouldCancelChatEvent = false;
@Setting private boolean primaryGroupOnly = false;
@Setting private String switchMessage = "<gray>You are now in <color><channel> <gray>chat!";
@Setting private String switchOtherMessage = "<gray><player> <reset><gray>is now in <color><channel> <gray>chat!";
@Setting private String switchFailureMessage = "<red>You cannot use channel <channel>!";
@Setting private String toggleOnMessage = "<gray>You can now see <color><channel> <gray>chat!";
@Setting private String toggleOffMessage = "<gray>You can no longer see <color><channel> <gray>chat!";
@Setting private String toggleOtherOnMessage = "<gray><player> <reset><gray>can now see <color><channel> <gray>chat!";
@Setting private String toggleOtherOffMessage = "<gray><player> <reset><gray>can no longer see <color><channel> <gray>chat!";
@Setting private String cannotUseMessage = "You cannot use that channel!";
@Setting private String cannotIgnoreMessage = "<red>You cannot ignore that channel!";
@Nullable
public String color() {
return this.color;
}
@Nullable
public Map<String, Context> contexts() {
return this.contexts;
}
@Nullable
public Map<String, String> formats() {
return this.formats;
}
@Nullable
public String defaultFormatName() {
return this.defaultFormatName;
}
public boolean ignorable() {
return this.ignorable;
}
public boolean crossServer() {
return this.crossServer;
}
public boolean honorsRecipientList() {
return this.honorsRecipientList;
}
public boolean permissionGroupMatching() {
return this.permissionGroupMatching;
}
@NonNull
public List<@NonNull String> groupOverrides() {
return this.groupOverrides;
}
@Nullable
public String switchMessage() {
return this.switchMessage;
}
@Nullable
public String switchOtherMessage() {
return this.switchOtherMessage;
}
@Nullable
public String switchFailureMessage() {
return this.switchFailureMessage;
}
@Nullable
public String cannotIgnoreMessage() {
return this.cannotIgnoreMessage;
}
@Nullable
public String toggleOffMessage() {
return this.toggleOffMessage;
}
@Nullable
public String toggleOnMessage() {
return this.toggleOnMessage;
}
@Nullable
public String toggleOtherOnMessage() {
return this.toggleOtherOnMessage;
}
@Nullable
public String toggleOtherOffMessage() {
return this.toggleOtherOffMessage;
}
@Nullable
public String cannotUseMessage() {
return this.cannotUseMessage;
}
public boolean primaryGroupOnly() {
return this.primaryGroupOnly;
}
public boolean shouldCancelChatEvent() {
return this.shouldCancelChatEvent;
}
}
+1 -1
View File
@@ -6,7 +6,7 @@ plugins {
description = 'CarbonChat-Bukkit'
dependencies {
compile 'org.spongepowered:configurate-yaml:4.0.0-SNAPSHOT'
compile 'org.spongepowered:configurate-hocon:4.0.0-SNAPSHOT'
compile project(":CarbonChat-Common")
@@ -9,6 +9,7 @@ import net.draycia.carbon.api.adventure.MessageProcessor;
import net.draycia.carbon.api.channels.ChannelRegistry;
import net.draycia.carbon.api.commands.settings.CommandSettingsRegistry;
import net.draycia.carbon.api.config.CarbonSettings;
import net.draycia.carbon.api.config.ChannelSettings;
import net.draycia.carbon.api.config.MessagingType;
import net.draycia.carbon.api.config.ModerationSettings;
import net.draycia.carbon.api.config.StorageType;
@@ -64,10 +65,9 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongepowered.configurate.BasicConfigurationNode;
import org.spongepowered.configurate.CommentedConfigurationNode;
import org.spongepowered.configurate.hocon.HoconConfigurationLoader;
import org.spongepowered.configurate.objectmapping.ObjectMappingException;
import org.spongepowered.configurate.yaml.NodeStyle;
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
import java.io.File;
import java.io.IOException;
@@ -86,6 +86,7 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
private CommandSettingsRegistry commandSettings;
private ModerationSettings moderationSettings;
private CarbonSettings carbonSettings;
private ChannelSettings channelSettings;
private UserService<BukkitChatUser> userService;
private MessageManager messageManager;
@@ -228,96 +229,92 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
this.loadCarbonSettings();
this.loadLanguage();
this.loadModerationSettings();
this.loadChannelSettings();
this.loadCommandSettings();
}
private void loadCarbonSettings() {
final File settingsFile = new File(this.getDataFolder(), "config.yml");
final YamlConfigurationLoader settingsLoader = YamlConfigurationLoader.builder()
.setNodeStyle(NodeStyle.BLOCK)
.setDefaultOptions(opts -> {
return opts.withShouldCopyDefaults(true).withSerializers(builder -> {
builder.register(Key.class, KeySerializer.INSTANCE).register(Sound.class, SoundSerializer.INSTANCE);
});
})
.setFile(settingsFile)
.build();
try {
final BasicConfigurationNode settingsNode = settingsLoader.load();
this.carbonSettings = CarbonSettings.loadFrom(settingsNode);
settingsLoader.save(settingsNode);
} catch (final IOException | ObjectMappingException exception) {
final CommentedConfigurationNode node =
this.loadConfigFile("config.conf", false);
this.carbonSettings = CarbonSettings.loadFrom(node);
} catch (final ObjectMappingException exception) {
exception.printStackTrace();
}
}
private void loadLanguage() {
final File languageFile = new File(this.getDataFolder(), "language.yml");
final YamlConfigurationLoader languageLoader = YamlConfigurationLoader.builder()
.setNodeStyle(NodeStyle.BLOCK)
.setDefaultOptions(opts -> {
return opts.withShouldCopyDefaults(true).withSerializers(builder -> {
builder.register(Key.class, KeySerializer.INSTANCE).register(Sound.class, SoundSerializer.INSTANCE);
});
})
.setFile(languageFile)
.build();
try {
final BasicConfigurationNode languageNode = languageLoader.load();
this.translations = CarbonTranslations.loadFrom(languageNode);
languageLoader.save(languageNode);
} catch (final IOException | ObjectMappingException exception) {
final CommentedConfigurationNode node =
this.loadConfigFile("language.conf", false);
this.translations = CarbonTranslations.loadFrom(node);
} catch (final ObjectMappingException exception) {
exception.printStackTrace();
}
}
private void loadModerationSettings() {
final File moderationFile = new File(this.getDataFolder(), "moderation.yml");
final YamlConfigurationLoader moderationLoader = YamlConfigurationLoader.builder()
.setNodeStyle(NodeStyle.BLOCK)
.setDefaultOptions(opts -> {
return opts.withShouldCopyDefaults(true).withSerializers(builder -> {
builder.register(Key.class, KeySerializer.INSTANCE).register(Sound.class, SoundSerializer.INSTANCE);
});
})
.setFile(moderationFile)
.build();
try {
final BasicConfigurationNode moderationNode = moderationLoader.load();
this.moderationSettings = ModerationSettings.loadFrom(moderationNode);
moderationLoader.save(moderationNode);
} catch (final IOException | ObjectMappingException exception) {
final CommentedConfigurationNode node =
this.loadConfigFile("moderation.conf", false);
this.moderationSettings = ModerationSettings.loadFrom(node);
} catch (final ObjectMappingException exception) {
exception.printStackTrace();
}
}
private void loadCommandSettings() {
// TODO: probably redo this from scratch
final File carbonCommands = new File(this.getDataFolder(), "carbon-commands.yml");
try {
final CommentedConfigurationNode node =
this.loadConfigFile("carbonCommands.conf", true);
if (!(carbonCommands.exists())) {
this.saveResource("carbon-commands.yml", false);
this.commandSettings = CommandSettingsRegistry.loadFrom(node);
} catch (final ObjectMappingException exception) {
exception.printStackTrace();
}
}
private void loadChannelSettings() {
try {
final CommentedConfigurationNode node =
this.loadConfigFile("channels.conf", true);
this.channelSettings = ChannelSettings.loadFrom(node);
} catch (final ObjectMappingException exception) {
exception.printStackTrace();
}
}
private CommentedConfigurationNode loadConfigFile(final String fileName, final boolean saveResource) {
final File configFile = new File(this.getDataFolder(), fileName);
if (!(configFile.exists()) && saveResource) {
this.saveResource(fileName, false);
}
final YamlConfigurationLoader commandSettingsLoader = YamlConfigurationLoader.builder()
.setNodeStyle(NodeStyle.BLOCK)
.setDefaultOptions(opts -> opts.withShouldCopyDefaults(true))
.setFile(carbonCommands)
final HoconConfigurationLoader configLoader = HoconConfigurationLoader.builder()
.setDefaultOptions(opts -> {
return opts.withShouldCopyDefaults(true).withSerializers(builder -> {
builder.register(Key.class, KeySerializer.INSTANCE)
.register(Sound.class, SoundSerializer.INSTANCE);
});
})
.setFile(configFile)
.build();
try {
final BasicConfigurationNode commandSettingsNode = commandSettingsLoader.load();
this.commandSettings = CommandSettingsRegistry.loadFrom(commandSettingsNode);
commandSettingsLoader.save(commandSettingsNode);
} catch (final IOException | ObjectMappingException exception) {
final CommentedConfigurationNode configNode = configLoader.load();
configLoader.save(configNode);
return configNode;
} catch (final IOException exception) {
exception.printStackTrace();
}
return null;
}
private void registerContexts() {
@@ -371,6 +368,11 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
return this.carbonSettings;
}
@Override
public @NonNull ChannelSettings channelSettings() {
return this.channelSettings;
}
@Override
public @NonNull CommandSettingsRegistry commandSettings() {
return this.commandSettings;
@@ -0,0 +1,125 @@
{
"registry": {
"channel": {
"enabled": true,
"name": "channel",
"aliases": [
"ch",
"switch",
"join"
]
},
"channellist": {
"enabled": true,
"name": "channellist",
"aliases": [
"chlist"
]
},
"chatreload": {
"enabled": true,
"name": "chatreload",
"aliases": [
"creload",
"cr"
]
},
"clearchat": {
"enabled": true,
"name": "clearchat",
"aliases": [
"clear",
"cc"
]
},
"ignore": {
"enabled": true,
"name": "ignore",
"aliases": [
"block"
]
},
"me": {
"enabled": true,
"name": "me",
"aliases": [
"rp"
]
},
"message": {
"enabled": true,
"name": "message",
"aliases": [
"msg",
"whisper",
"w"
]
},
"mute": {
"enabled": true,
"name": "mute",
"aliases": [
"m"
]
},
"nickname": {
"enabled": true,
"name": "nickname",
"aliases": [
"nick"
]
},
"reply": {
"enabled": true,
"name": "reply",
"aliases": [
"r"
]
},
"setcolor": {
"enabled": true,
"name": "setcolor",
"aliases": [
"setcolor"
]
},
"shadowmute": {
"enabled": true,
"name": "shadowmute",
"aliases": [
"sm",
"smute"
]
},
"spy": {
"enabled": true,
"name": "spy",
"aliases": [
"spych",
"spychannel"
]
},
"sudochannel": {
"enabled": true,
"name": "sudochannel",
"aliases": [
"sch",
"sudoch",
"schannel",
"chsudo",
"channelsudo"
]
},
"toggle": {
"enabled": true,
"name": "toggle",
"aliases": [
"togglechannel",
"tch",
"togglech",
"tchannel",
"togglec"
]
}
}
}
@@ -97,9 +97,5 @@ contexts:
mcMMO:
cancellation-message: '<red>You do not have a party!'
item-link-placeholders:
- '[item]'
- '%item%'
# Determines if the player's tab menu name is updated with /nickname
nicknames-set-tab-name: true
+1 -1
View File
@@ -11,7 +11,7 @@ dependencies {
compileOnly 'com.google.code.gson:gson:2.8.0'
compile 'org.spongepowered:configurate-yaml:4.0.0-SNAPSHOT'
compile 'org.spongepowered:configurate-hocon:4.0.0-SNAPSHOT'
compile 'co.aikar:idb-core:1.0.0-SNAPSHOT'
compile 'com.zaxxer:HikariCP:2.4.1'
@@ -470,7 +470,7 @@ public class CarbonChatChannel implements ChatChannel {
@Override
@NonNull
public List<@NonNull Pattern> itemLinkPatterns() {
return this.settings().itemLinkPatterns();
return this.carbonChat.carbonSettings().itemLinkPatterns();
}
@Override