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 '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 'org.slf4j:slf4j-api:1.7.25'
api 'net.luckperms:api:5.1' 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.channels.ChannelRegistry;
import net.draycia.carbon.api.commands.settings.CommandSettingsRegistry; import net.draycia.carbon.api.commands.settings.CommandSettingsRegistry;
import net.draycia.carbon.api.config.CarbonSettings; 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.config.ModerationSettings;
import net.draycia.carbon.api.messaging.MessageService; import net.draycia.carbon.api.messaging.MessageService;
import net.draycia.carbon.api.users.ChatUser; import net.draycia.carbon.api.users.ChatUser;
@@ -39,6 +40,8 @@ public interface CarbonChat {
@NonNull CarbonSettings carbonSettings(); @NonNull CarbonSettings carbonSettings();
@NonNull ChannelSettings channelSettings();
@NonNull ChannelRegistry channelRegistry(); @NonNull ChannelRegistry channelRegistry();
@NonNull CommandSettingsRegistry commandSettings(); @NonNull CommandSettingsRegistry commandSettings();
@@ -1,6 +1,6 @@
package net.draycia.carbon.api.adventure; 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.ObjectMapper;
import org.spongepowered.configurate.objectmapping.ObjectMappingException; import org.spongepowered.configurate.objectmapping.ObjectMappingException;
import org.spongepowered.configurate.objectmapping.Setting; 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); 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); MAPPER.bind(this).serialize(node);
} }
@@ -4,7 +4,7 @@ import net.draycia.carbon.api.channels.ChatChannel;
import net.kyori.registry.Registry; import net.kyori.registry.Registry;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; 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.ObjectMapper;
import org.spongepowered.configurate.objectmapping.ObjectMappingException; import org.spongepowered.configurate.objectmapping.ObjectMappingException;
import org.spongepowered.configurate.objectmapping.Setting; 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); 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); 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.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; 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.ObjectMapper;
import org.spongepowered.configurate.objectmapping.ObjectMappingException; import org.spongepowered.configurate.objectmapping.ObjectMappingException;
import org.spongepowered.configurate.objectmapping.Setting; import org.spongepowered.configurate.objectmapping.Setting;
import org.spongepowered.configurate.serialize.ConfigSerializable; import org.spongepowered.configurate.serialize.ConfigSerializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.regex.Pattern;
@ConfigSerializable @ConfigSerializable
public class CarbonSettings { 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); 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); MAPPER.bind(this).serialize(node);
} }
@@ -44,7 +46,7 @@ public class CarbonSettings {
private boolean showTips = true; private boolean showTips = true;
@Setting(comment = "") @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") @Setting(comment = "Options: JSON, MYSQL")
private @Nullable StorageType storageType = StorageType.JSON; 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") "\nFor example, channel-on-join: \"global\" sets their channel to global on join")
private @Nullable String channelOnJoin = ""; 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() { public @NonNull String spyPrefix() {
return this.spyPrefix; return this.spyPrefix;
} }
@@ -98,7 +108,7 @@ public class CarbonSettings {
return this.showTips; return this.showTips;
} }
public @NonNull List<@NonNull ChannelSettings> channelSettings() { public @NonNull List<@NonNull ChannelOptions> channelSettings() {
return this.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; package net.draycia.carbon.api.config;
import net.draycia.carbon.api.Context; import org.spongepowered.configurate.CommentedConfigurationNode;
import org.checkerframework.checker.nullness.qual.NonNull; import org.spongepowered.configurate.objectmapping.ObjectMapper;
import org.checkerframework.checker.nullness.qual.Nullable; import org.spongepowered.configurate.objectmapping.ObjectMappingException;
import org.spongepowered.configurate.objectmapping.Setting; import org.spongepowered.configurate.objectmapping.Setting;
import org.spongepowered.configurate.serialize.ConfigSerializable; import org.spongepowered.configurate.serialize.ConfigSerializable;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.regex.Pattern;
@ConfigSerializable @ConfigSerializable
public class ChannelSettings { public class ChannelSettings {
@Setting private String key = "channel"; private static final ObjectMapper<ChannelSettings> MAPPER;
@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!";
@NonNull static {
public String key() { try {
return this.key; MAPPER = ObjectMapper.forClass(ChannelSettings.class); // We hold on to the instance of our ObjectMapper
} } catch (final ObjectMappingException e) {
throw new ExceptionInInitializerError(e);
@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 static ChannelSettings loadFrom(final CommentedConfigurationNode node) throws ObjectMappingException {
public String messagePrefix() { return MAPPER.bindToNew().populate(node);
return this.messagePrefix;
} }
@Nullable public void saveTo(final CommentedConfigurationNode node) throws ObjectMappingException {
public String switchMessage() { MAPPER.bind(this).serialize(node);
return this.switchMessage;
} }
@Nullable @Setting(comment = "All options here act like the defaults for all channels.\nAdding any of these options to any channel overrides the relevant defaults.")
public String switchOtherMessage() { private SharedChannelOptions sharedChannelOptions = new SharedChannelOptions();
return this.switchOtherMessage;
@Setting
private Map<String, ChannelOptions> channelOptions =
Collections.singletonMap("global", ChannelOptions.defaultChannel());
public SharedChannelOptions defaultChannelOptions() {
return this.sharedChannelOptions;
} }
@Nullable public Map<String, ChannelOptions> channelOptions() {
public String switchFailureMessage() { return this.channelOptions;
return this.switchFailureMessage;
} }
@Nullable public ChannelOptions channelOptions(final String name) {
public String cannotIgnoreMessage() { return this.channelOptions.get(name);
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;
} }
} }
@@ -1,6 +1,6 @@
package net.draycia.carbon.api.config; 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.ObjectMapper;
import org.spongepowered.configurate.objectmapping.ObjectMappingException; import org.spongepowered.configurate.objectmapping.ObjectMappingException;
import org.spongepowered.configurate.objectmapping.Setting; 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); 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); 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' description = 'CarbonChat-Bukkit'
dependencies { dependencies {
compile 'org.spongepowered:configurate-yaml:4.0.0-SNAPSHOT' compile 'org.spongepowered:configurate-hocon:4.0.0-SNAPSHOT'
compile project(":CarbonChat-Common") 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.channels.ChannelRegistry;
import net.draycia.carbon.api.commands.settings.CommandSettingsRegistry; import net.draycia.carbon.api.commands.settings.CommandSettingsRegistry;
import net.draycia.carbon.api.config.CarbonSettings; 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.MessagingType;
import net.draycia.carbon.api.config.ModerationSettings; import net.draycia.carbon.api.config.ModerationSettings;
import net.draycia.carbon.api.config.StorageType; 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.checkerframework.checker.nullness.qual.NonNull;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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.objectmapping.ObjectMappingException;
import org.spongepowered.configurate.yaml.NodeStyle;
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -86,6 +86,7 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
private CommandSettingsRegistry commandSettings; private CommandSettingsRegistry commandSettings;
private ModerationSettings moderationSettings; private ModerationSettings moderationSettings;
private CarbonSettings carbonSettings; private CarbonSettings carbonSettings;
private ChannelSettings channelSettings;
private UserService<BukkitChatUser> userService; private UserService<BukkitChatUser> userService;
private MessageManager messageManager; private MessageManager messageManager;
@@ -228,96 +229,92 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
this.loadCarbonSettings(); this.loadCarbonSettings();
this.loadLanguage(); this.loadLanguage();
this.loadModerationSettings(); this.loadModerationSettings();
this.loadChannelSettings();
this.loadCommandSettings(); this.loadCommandSettings();
} }
private void loadCarbonSettings() { 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 { try {
final BasicConfigurationNode settingsNode = settingsLoader.load(); final CommentedConfigurationNode node =
this.carbonSettings = CarbonSettings.loadFrom(settingsNode); this.loadConfigFile("config.conf", false);
settingsLoader.save(settingsNode);
} catch (final IOException | ObjectMappingException exception) { this.carbonSettings = CarbonSettings.loadFrom(node);
} catch (final ObjectMappingException exception) {
exception.printStackTrace(); exception.printStackTrace();
} }
} }
private void loadLanguage() { 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 { try {
final BasicConfigurationNode languageNode = languageLoader.load(); final CommentedConfigurationNode node =
this.translations = CarbonTranslations.loadFrom(languageNode); this.loadConfigFile("language.conf", false);
languageLoader.save(languageNode);
} catch (final IOException | ObjectMappingException exception) { this.translations = CarbonTranslations.loadFrom(node);
} catch (final ObjectMappingException exception) {
exception.printStackTrace(); exception.printStackTrace();
} }
} }
private void loadModerationSettings() { 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 { try {
final BasicConfigurationNode moderationNode = moderationLoader.load(); final CommentedConfigurationNode node =
this.moderationSettings = ModerationSettings.loadFrom(moderationNode); this.loadConfigFile("moderation.conf", false);
moderationLoader.save(moderationNode);
} catch (final IOException | ObjectMappingException exception) { this.moderationSettings = ModerationSettings.loadFrom(node);
} catch (final ObjectMappingException exception) {
exception.printStackTrace(); exception.printStackTrace();
} }
} }
private void loadCommandSettings() { private void loadCommandSettings() {
// TODO: probably redo this from scratch try {
final File carbonCommands = new File(this.getDataFolder(), "carbon-commands.yml"); final CommentedConfigurationNode node =
this.loadConfigFile("carbonCommands.conf", true);
if (!(carbonCommands.exists())) { this.commandSettings = CommandSettingsRegistry.loadFrom(node);
this.saveResource("carbon-commands.yml", false); } 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() final HoconConfigurationLoader configLoader = HoconConfigurationLoader.builder()
.setNodeStyle(NodeStyle.BLOCK) .setDefaultOptions(opts -> {
.setDefaultOptions(opts -> opts.withShouldCopyDefaults(true)) return opts.withShouldCopyDefaults(true).withSerializers(builder -> {
.setFile(carbonCommands) builder.register(Key.class, KeySerializer.INSTANCE)
.register(Sound.class, SoundSerializer.INSTANCE);
});
})
.setFile(configFile)
.build(); .build();
try { try {
final BasicConfigurationNode commandSettingsNode = commandSettingsLoader.load(); final CommentedConfigurationNode configNode = configLoader.load();
this.commandSettings = CommandSettingsRegistry.loadFrom(commandSettingsNode); configLoader.save(configNode);
commandSettingsLoader.save(commandSettingsNode);
} catch (final IOException | ObjectMappingException exception) { return configNode;
} catch (final IOException exception) {
exception.printStackTrace(); exception.printStackTrace();
} }
return null;
} }
private void registerContexts() { private void registerContexts() {
@@ -371,6 +368,11 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
return this.carbonSettings; return this.carbonSettings;
} }
@Override
public @NonNull ChannelSettings channelSettings() {
return this.channelSettings;
}
@Override @Override
public @NonNull CommandSettingsRegistry commandSettings() { public @NonNull CommandSettingsRegistry commandSettings() {
return this.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: mcMMO:
cancellation-message: '<red>You do not have a party!' 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 # Determines if the player's tab menu name is updated with /nickname
nicknames-set-tab-name: true nicknames-set-tab-name: true
+1 -1
View File
@@ -11,7 +11,7 @@ dependencies {
compileOnly 'com.google.code.gson:gson:2.8.0' 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 'co.aikar:idb-core:1.0.0-SNAPSHOT'
compile 'com.zaxxer:HikariCP:2.4.1' compile 'com.zaxxer:HikariCP:2.4.1'
@@ -470,7 +470,7 @@ public class CarbonChatChannel implements ChatChannel {
@Override @Override
@NonNull @NonNull
public List<@NonNull Pattern> itemLinkPatterns() { public List<@NonNull Pattern> itemLinkPatterns() {
return this.settings().itemLinkPatterns(); return this.carbonChat.carbonSettings().itemLinkPatterns();
} }
@Override @Override