mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 06:28:54 +00:00
More configuration progress
This commit is contained in:
1 parent
3878be3563
commit
f588f3b24b
13 files changed
+318
-256
No files matched your search
@@ -1,9 +1,10 @@
|
||||
package net.draycia.carbon.api.config;
|
||||
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.spongepowered.configurate.BasicConfigurationNode;
|
||||
import org.spongepowered.configurate.objectmapping.ObjectMapper;
|
||||
import org.spongepowered.configurate.objectmapping.ObjectMappingException;
|
||||
import org.spongepowered.configurate.objectmapping.Setting;
|
||||
import org.spongepowered.configurate.serialize.ConfigSerializable;
|
||||
|
||||
@@ -14,17 +15,77 @@ import java.util.Map;
|
||||
@ConfigSerializable
|
||||
public class CarbonSettings {
|
||||
|
||||
@Setting private @NonNull String spyPrefix = "<color>[SPY] ";
|
||||
@Setting private @NonNull String serverName = "Server";
|
||||
@Setting private boolean showTips = true;
|
||||
@Setting private @NonNull List<@NonNull ChannelSettings> channelSettings; // TODO: unfuck this, it's loaded from file?
|
||||
@Setting private @Nullable StorageType storageType = StorageType.JSON;
|
||||
@Setting private @NonNull SQLCredentials sqlCredentials =
|
||||
private static final ObjectMapper<CarbonSettings> MAPPER;
|
||||
|
||||
static {
|
||||
try {
|
||||
MAPPER = ObjectMapper.forClass(CarbonSettings.class); // We hold on to the instance of our ObjectMapper
|
||||
} catch (final ObjectMappingException e) {
|
||||
throw new ExceptionInInitializerError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static CarbonSettings loadFrom(final BasicConfigurationNode node) throws ObjectMappingException {
|
||||
return MAPPER.bindToNew().populate(node);
|
||||
}
|
||||
|
||||
public void saveTo(final BasicConfigurationNode node) throws ObjectMappingException {
|
||||
MAPPER.bind(this).serialize(node);
|
||||
}
|
||||
|
||||
@Setting(comment = "The prefix shown when spying on a user's message")
|
||||
private @NonNull String spyPrefix = "<color>[SPY] ";
|
||||
|
||||
@Setting(comment = "Used for <server> placeholder in channel formats")
|
||||
private @NonNull String serverName = "Server";
|
||||
|
||||
@Setting(comment = "Set this to false to disable warnings and tips when the plugin thinks there may be configuration issues.")
|
||||
private boolean showTips = true;
|
||||
|
||||
@Setting(comment = "")
|
||||
private @NonNull List<@NonNull ChannelSettings> channelSettings; // TODO: unfuck this, it's loaded from file?
|
||||
|
||||
@Setting(comment = "Options: JSON, MYSQL")
|
||||
private @Nullable StorageType storageType = StorageType.JSON;
|
||||
|
||||
@Setting(comment = "The credentials used to connect to your database. Requires storageType=MYSQL")
|
||||
private @NonNull SQLCredentials sqlCredentials =
|
||||
new SQLCredentials("username", "password", "db", "localhost", 3306);
|
||||
@Setting private @NonNull Map<@Nullable String, @NonNull String> customPlaceholders = new HashMap<>();
|
||||
@Setting private @NonNull Pings pings = new Pings();
|
||||
@Setting private @NonNull WhisperPings whisperPings = new WhisperPings();
|
||||
@Setting private @Nullable String channelOnJoin = "";
|
||||
|
||||
@Setting(comment = "Options: NONE, REDIS, BUNGEECORD")
|
||||
private @NonNull MessagingType messagingType = MessagingType.NONE;
|
||||
|
||||
@Setting(comment = " Options:\n" +
|
||||
" 'bungee' - Uses bungee plugin messaging, requires BungeeCord or another proxy which supports it (Velocity!)\n" +
|
||||
" 'redis' - Uses redis for cross server syncing, does not require a server proxy\n" +
|
||||
" 'none' - Do not sync anything cross server, this is the default\n" +
|
||||
"\n" +
|
||||
" Note: In order for channels to sync cross server, you'll need to enable is-cross-server for the\n" +
|
||||
" channel as well as this setting.")
|
||||
private @NonNull RedisCredentials redisCredentials =
|
||||
new RedisCredentials("localhost", "", 6379, 0);
|
||||
|
||||
@Setting(comment = "Used for message formats - custom tags that are replaced in descending order" +
|
||||
"\nFor example, in the default config, <group> wil be replaced with <green>%vault_group%")
|
||||
private @NonNull Map<@Nullable String, @NonNull String> customPlaceholders = new HashMap<String, String>() {
|
||||
{
|
||||
this.put("prefix", "<gray>[<group><gray>]");
|
||||
this.put("group", "<green>%vault_group%");
|
||||
}
|
||||
};
|
||||
|
||||
@Setting(comment = "Plays a sound and highlights the message when someone types your name")
|
||||
private @NonNull ChannelPings channelPings = new ChannelPings();
|
||||
|
||||
@Setting(comment = "Plays a sound when receiving private messages with /whisper /msg")
|
||||
private @NonNull WhisperPings whisperPings = new WhisperPings();
|
||||
|
||||
@Setting(comment = "Sets the player's channel to the specified channel when they join" +
|
||||
"\nSet to \"\" or remove to disable" +
|
||||
"\nSet to DEFAULT to set the player's channel to the default channel on join" +
|
||||
"\nOtherwise, set to a channel to set the player's channel to it on join" +
|
||||
"\nFor example, channel-on-join: \"global\" sets their channel to global on join")
|
||||
private @Nullable String channelOnJoin = "";
|
||||
|
||||
public @NonNull String spyPrefix() {
|
||||
return this.spyPrefix;
|
||||
@@ -50,6 +111,14 @@ public class CarbonSettings {
|
||||
return this.sqlCredentials;
|
||||
}
|
||||
|
||||
public @NonNull MessagingType messagingType() {
|
||||
return this.messagingType;
|
||||
}
|
||||
|
||||
public @NonNull RedisCredentials redisCredentials() {
|
||||
return this.redisCredentials;
|
||||
}
|
||||
|
||||
public Map<String, String> customPlaceholders() {
|
||||
return this.customPlaceholders;
|
||||
}
|
||||
@@ -58,85 +127,12 @@ public class CarbonSettings {
|
||||
return this.channelOnJoin;
|
||||
}
|
||||
|
||||
public @NonNull Pings pings() {
|
||||
return this.pings;
|
||||
public @NonNull ChannelPings channelPings() {
|
||||
return this.channelPings;
|
||||
}
|
||||
|
||||
public @NonNull WhisperPings whisperPings() {
|
||||
return this.whisperPings;
|
||||
}
|
||||
|
||||
public enum StorageType {
|
||||
MYSQL,
|
||||
JSON
|
||||
}
|
||||
|
||||
@ConfigSerializable
|
||||
public final class WhisperPings {
|
||||
@Setting private boolean enabled = true;
|
||||
@Setting private @NonNull Key sound = Key.of(Key.MINECRAFT_NAMESPACE, "entity.experience_orb.pickup");
|
||||
@Setting private Sound.Source source = Sound.Source.PLAYER;
|
||||
@Setting private float volume = 10.0F;
|
||||
@Setting private float pitch = 1.0F;
|
||||
|
||||
public boolean enabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public Key sound() {
|
||||
return this.sound;
|
||||
}
|
||||
|
||||
public Sound.Source source() {
|
||||
return this.source;
|
||||
}
|
||||
|
||||
public float volume() {
|
||||
return this.volume;
|
||||
}
|
||||
|
||||
public float pitch() {
|
||||
return this.pitch;
|
||||
}
|
||||
}
|
||||
|
||||
@ConfigSerializable
|
||||
public final class Pings {
|
||||
@Setting private boolean enabled = true;
|
||||
@Setting private @NonNull String prefix = "";
|
||||
@Setting private boolean caseSensitive = false;
|
||||
@Setting private @NonNull Key sound = Key.of(Key.MINECRAFT_NAMESPACE, "entity.experience_orb.pickup");
|
||||
@Setting private Sound.Source source = Sound.Source.PLAYER;
|
||||
@Setting private float volume = 10.0F;
|
||||
@Setting private float pitch = 1.0F;
|
||||
|
||||
public boolean enabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public String prefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
|
||||
public boolean caseSensitive() {
|
||||
return this.caseSensitive;
|
||||
}
|
||||
|
||||
public Key sound() {
|
||||
return this.sound;
|
||||
}
|
||||
|
||||
public Sound.Source source() {
|
||||
return this.source;
|
||||
}
|
||||
|
||||
public float volume() {
|
||||
return this.volume;
|
||||
}
|
||||
|
||||
public float pitch() {
|
||||
return this.pitch;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package net.draycia.carbon.api.config;
|
||||
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.spongepowered.configurate.objectmapping.Setting;
|
||||
import org.spongepowered.configurate.serialize.ConfigSerializable;
|
||||
|
||||
@ConfigSerializable
|
||||
public final class ChannelPings {
|
||||
@Setting
|
||||
private boolean enabled = true;
|
||||
@Setting private @NonNull String prefix = "";
|
||||
@Setting private boolean caseSensitive = false;
|
||||
@Setting private @NonNull
|
||||
Key sound = Key.of(Key.MINECRAFT_NAMESPACE, "entity.experience_orb.pickup");
|
||||
@Setting private Sound.Source source = Sound.Source.PLAYER;
|
||||
@Setting private float volume = 10.0F;
|
||||
@Setting private float pitch = 1.0F;
|
||||
|
||||
public boolean enabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public String prefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
|
||||
public boolean caseSensitive() {
|
||||
return this.caseSensitive;
|
||||
}
|
||||
|
||||
public Key sound() {
|
||||
return this.sound;
|
||||
}
|
||||
|
||||
public Sound.Source source() {
|
||||
return this.source;
|
||||
}
|
||||
|
||||
public float volume() {
|
||||
return this.volume;
|
||||
}
|
||||
|
||||
public float pitch() {
|
||||
return this.pitch;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package net.draycia.carbon.api.config;
|
||||
|
||||
public enum MessagingType {
|
||||
NONE,
|
||||
REDIS,
|
||||
BUNGEECORD
|
||||
}
|
||||
@@ -1,11 +1,38 @@
|
||||
package net.draycia.carbon.api.config;
|
||||
|
||||
import org.spongepowered.configurate.BasicConfigurationNode;
|
||||
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.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ConfigSerializable
|
||||
public class ModerationSettings {
|
||||
|
||||
private static final ObjectMapper<ModerationSettings> MAPPER;
|
||||
|
||||
static {
|
||||
try {
|
||||
MAPPER = ObjectMapper.forClass(ModerationSettings.class); // We hold on to the instance of our ObjectMapper
|
||||
} catch (final ObjectMappingException e) {
|
||||
throw new ExceptionInInitializerError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static ModerationSettings loadFrom(final BasicConfigurationNode node) throws ObjectMappingException {
|
||||
return MAPPER.bindToNew().populate(node);
|
||||
}
|
||||
|
||||
public void saveTo(final BasicConfigurationNode node) throws ObjectMappingException {
|
||||
MAPPER.bind(this).serialize(node);
|
||||
}
|
||||
|
||||
// TODO: comment this
|
||||
@Setting
|
||||
private String shadowMutePrefix = "[SM] ";
|
||||
@@ -83,4 +110,45 @@ public class ModerationSettings {
|
||||
}
|
||||
}
|
||||
|
||||
@Setting
|
||||
private Filters filters = new Filters();
|
||||
|
||||
public Filters filters() {
|
||||
return this.filters;
|
||||
}
|
||||
|
||||
@ConfigSerializable
|
||||
public final class Filters {
|
||||
|
||||
@Setting
|
||||
private boolean enabled = true;
|
||||
|
||||
@Setting(comment = "The keys (\"****\" for example) are what the text is replaced with.\n" +
|
||||
"The strings in the lists (\"lag\" etc) are what's replaced.\n" +
|
||||
"Set to filters: {} if you want to disable the filter feature.\n" +
|
||||
"Set the key to \"_\" for the replacement to be blank (remove the filtered pattern).")
|
||||
private Map<String, List<Pattern>> replacements = new HashMap<String, List<Pattern>>() {
|
||||
{
|
||||
this.put("****", Collections.singletonList(Pattern.compile("la[g]+")));
|
||||
}
|
||||
};
|
||||
|
||||
@Setting(comment = "Anything in blocked-words will prevent the message from being sent at all.\n" +
|
||||
"Set to blocked-words: [] if you want to disable the blocked words feature.")
|
||||
private List<Pattern> blockedPatterns = Collections.singletonList(Pattern.compile("pineapple doesn't belong on pizza"));
|
||||
|
||||
public boolean enabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public Map<String, List<Pattern>> replacements() {
|
||||
return this.replacements;
|
||||
}
|
||||
|
||||
public List<Pattern> blockedPatterns() {
|
||||
return this.blockedPatterns;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package net.draycia.carbon.common.utils;
|
||||
package net.draycia.carbon.api.config;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@@ -0,0 +1,6 @@
|
||||
package net.draycia.carbon.api.config;
|
||||
|
||||
public enum StorageType {
|
||||
MYSQL,
|
||||
JSON
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package net.draycia.carbon.api.config;
|
||||
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.spongepowered.configurate.objectmapping.Setting;
|
||||
import org.spongepowered.configurate.serialize.ConfigSerializable;
|
||||
|
||||
@ConfigSerializable
|
||||
public final class WhisperPings {
|
||||
@Setting
|
||||
private boolean enabled = true;
|
||||
@Setting private @NonNull
|
||||
Key sound = Key.of(Key.MINECRAFT_NAMESPACE, "entity.experience_orb.pickup");
|
||||
@Setting private Sound.Source source = Sound.Source.PLAYER;
|
||||
@Setting private float volume = 10.0F;
|
||||
@Setting private float pitch = 1.0F;
|
||||
|
||||
public boolean enabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public Key sound() {
|
||||
return this.sound;
|
||||
}
|
||||
|
||||
public Sound.Source source() {
|
||||
return this.source;
|
||||
}
|
||||
|
||||
public float volume() {
|
||||
return this.volume;
|
||||
}
|
||||
|
||||
public float pitch() {
|
||||
return this.pitch;
|
||||
}
|
||||
}
|
||||
@@ -9,12 +9,15 @@ 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.MessagingType;
|
||||
import net.draycia.carbon.api.config.ModerationSettings;
|
||||
import net.draycia.carbon.api.config.StorageType;
|
||||
import net.draycia.carbon.api.messaging.MessageService;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.common.adventure.FormatType;
|
||||
import net.draycia.carbon.common.messaging.EmptyMessageService;
|
||||
import net.draycia.carbon.api.config.SQLCredentials;
|
||||
import net.draycia.carbon.common.messaging.RedisMessageService;
|
||||
import net.draycia.carbon.listeners.contexts.DistanceContext;
|
||||
import net.draycia.carbon.listeners.contexts.EconomyContext;
|
||||
import net.draycia.carbon.listeners.contexts.FilterContext;
|
||||
@@ -42,6 +45,7 @@ import net.draycia.carbon.common.messaging.MessageManager;
|
||||
import net.draycia.carbon.api.users.UserService;
|
||||
import net.draycia.carbon.common.users.JSONUserService;
|
||||
import net.draycia.carbon.common.users.MySQLUserService;
|
||||
import net.draycia.carbon.messaging.BungeeMessageService;
|
||||
import net.draycia.carbon.storage.BukkitChatUser;
|
||||
import net.draycia.carbon.util.CarbonPlaceholders;
|
||||
import net.draycia.carbon.util.FunctionalityConstants;
|
||||
@@ -81,8 +85,6 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
private UserService<BukkitChatUser> userService;
|
||||
private MessageManager messageManager;
|
||||
|
||||
private FilterContext filterContext;
|
||||
|
||||
private CarbonTranslations translations;
|
||||
|
||||
private Logger logger;
|
||||
@@ -104,17 +106,9 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
public void onEnable() {
|
||||
this.logger = LoggerFactory.getLogger(this.getName());
|
||||
|
||||
// Setup metrics
|
||||
final Metrics metrics = new Metrics(this, BSTATS_PLUGIN_ID);
|
||||
|
||||
// Ensure config is present to be modified by the user
|
||||
if (!(new File(this.getDataFolder(), "config.yml").exists())) {
|
||||
this.saveDefaultConfig();
|
||||
}
|
||||
|
||||
if (!(new File(this.getDataFolder(), "moderation.yml").exists())) {
|
||||
this.saveResource("moderation.yml", false);
|
||||
}
|
||||
|
||||
this.reloadConfig();
|
||||
|
||||
// Setup Adventure
|
||||
@@ -122,9 +116,23 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
|
||||
// Initialize managers
|
||||
this.channelRegistry = new ChannelRegistry();
|
||||
this.messageManager = new MessageManager(this, new EmptyMessageService()); // TODO: get message service from config
|
||||
|
||||
final CarbonSettings.StorageType storageType = this.carbonSettings().storageType();
|
||||
// Handle messaging service
|
||||
final MessagingType messagingType = this.carbonSettings().messagingType();
|
||||
final MessageService messageService;
|
||||
|
||||
if (messagingType == MessagingType.REDIS) {
|
||||
messageService = new RedisMessageService(this, this.carbonSettings.redisCredentials());
|
||||
} else if (messagingType == MessagingType.BUNGEECORD) {
|
||||
messageService = new BungeeMessageService(this); // TODO: only support this if bukkit
|
||||
} else {
|
||||
messageService = new EmptyMessageService();
|
||||
}
|
||||
|
||||
this.messageManager = new MessageManager(this, messageService);
|
||||
|
||||
// Handle storage service
|
||||
final StorageType storageType = this.carbonSettings().storageType();
|
||||
|
||||
final Supplier<Iterable<BukkitChatUser>> supplier = () -> {
|
||||
final List<BukkitChatUser> users = new ArrayList<>();
|
||||
@@ -136,11 +144,11 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
return users;
|
||||
};
|
||||
|
||||
if (storageType == CarbonSettings.StorageType.MYSQL) {
|
||||
if (storageType == StorageType.MYSQL) {
|
||||
this.logger().info("Enabling MySQL storage!");
|
||||
final SQLCredentials credentials = this.carbonSettings().sqlCredentials();
|
||||
this.userService = new MySQLUserService<>(this, credentials, supplier, BukkitChatUser::new);
|
||||
} else if (storageType == CarbonSettings.StorageType.JSON) {
|
||||
} else if (storageType == StorageType.JSON) {
|
||||
this.logger().info("Enabling JSON storage!");
|
||||
this.userService = new JSONUserService<>(BukkitChatUser.class, this, supplier, BukkitChatUser::new);
|
||||
} else {
|
||||
@@ -153,9 +161,11 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
this.setupListeners();
|
||||
this.registerContexts();
|
||||
|
||||
// Setup PlaceholderAPI placeholders
|
||||
new CarbonPlaceholders(this).register();
|
||||
|
||||
if (!FunctionalityConstants.HAS_HOVER_EVENT_METHOD) {
|
||||
// Log missing functionality
|
||||
if (this.carbonSettings().showTips() && !FunctionalityConstants.HAS_HOVER_EVENT_METHOD) {
|
||||
this.logger().error("Item linking disabled! Please use Paper 1.16.2 #172 or newer.");
|
||||
}
|
||||
}
|
||||
@@ -208,13 +218,24 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
|
||||
@Override
|
||||
public void reloadConfig() {
|
||||
super.reloadConfig();
|
||||
|
||||
this.loadCarbonSettingS();
|
||||
this.loadLanguage();
|
||||
this.loadModerationSettings();
|
||||
this.loadCommandSettings();
|
||||
}
|
||||
|
||||
private void loadCarbonSettingS() {
|
||||
final File settingsFile = new File(this.getDataFolder(), "config.yml");
|
||||
final YamlConfigurationLoader settingsLoader = YamlConfigurationLoader.builder().setFile(settingsFile).build();
|
||||
|
||||
try {
|
||||
final BasicConfigurationNode settingsNode = settingsLoader.load();
|
||||
this.carbonSettings = CarbonSettings.loadFrom(settingsNode);
|
||||
settingsLoader.save(settingsNode);
|
||||
} catch (final IOException | ObjectMappingException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
private void loadLanguage() {
|
||||
final File languageFile = new File(this.getDataFolder(), "language.yml");
|
||||
final YamlConfigurationLoader languageLoader = YamlConfigurationLoader.builder().setFile(languageFile).build();
|
||||
@@ -227,6 +248,18 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
}
|
||||
}
|
||||
|
||||
private void loadModerationSettings() {
|
||||
final File moderationFile = new File(this.getDataFolder(), "moderation.yml");
|
||||
final YamlConfigurationLoader moderationLoader = YamlConfigurationLoader.builder().setFile(moderationFile).build();
|
||||
|
||||
try {
|
||||
final BasicConfigurationNode moderationNode = moderationLoader.load();
|
||||
this.moderationSettings = ModerationSettings.loadFrom(moderationNode);
|
||||
moderationLoader.save(moderationNode);
|
||||
} catch (final IOException | ObjectMappingException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
private void loadCommandSettings() {
|
||||
// TODO: probably redo this from scratch
|
||||
final File carbonCommands = new File(this.getDataFolder(), "carbon-commands.yml");
|
||||
@@ -246,17 +279,7 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
}
|
||||
}
|
||||
|
||||
private void loadModerationSettings() {
|
||||
|
||||
}
|
||||
|
||||
public void reloadFilters() {
|
||||
this.filterContext.reloadFilters();
|
||||
}
|
||||
|
||||
private void registerContexts() {
|
||||
this.filterContext = new FilterContext(this);
|
||||
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("Towny")) {
|
||||
this.getServer().getPluginManager().registerEvents(new TownyContext(this), this);
|
||||
}
|
||||
@@ -274,6 +297,7 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
}
|
||||
|
||||
new DistanceContext();
|
||||
new FilterContext(this);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
||||
+7
-46
@@ -8,8 +8,6 @@ import net.draycia.carbon.api.Context;
|
||||
import net.kyori.event.PostOrders;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -20,20 +18,13 @@ public class FilterContext {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
@NonNull
|
||||
private final Map<String, List<@NonNull Pattern>> patternReplacements = new HashMap<>();
|
||||
|
||||
@NonNull
|
||||
private final List<@NonNull Pattern> blockedWords = new ArrayList<>();
|
||||
|
||||
public FilterContext(final @NonNull CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.reloadFilters();
|
||||
|
||||
CarbonEvents.register(PreChatFormatEvent.class, PostOrders.FIRST, false, event -> {
|
||||
// if (!carbonChat.moderationSettings().filters().enabled()) {
|
||||
// return;
|
||||
// }
|
||||
if (!carbonChat.moderationSettings().filters().enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.user().permissible() && event.user().hasPermission("carbonchat.filter.exempt")) {
|
||||
return;
|
||||
@@ -45,7 +36,9 @@ public class FilterContext {
|
||||
|
||||
String message = event.message();
|
||||
|
||||
for (final Map.Entry<String, List<Pattern>> entry : this.patternReplacements.entrySet()) {
|
||||
for (final Map.Entry<String, List<Pattern>> entry :
|
||||
this.carbonChat.moderationSettings().filters().replacements().entrySet()) {
|
||||
|
||||
for (final Pattern pattern : entry.getValue()) {
|
||||
final Matcher matcher = pattern.matcher(message);
|
||||
|
||||
@@ -59,7 +52,7 @@ public class FilterContext {
|
||||
|
||||
event.message(message);
|
||||
|
||||
for (final Pattern blockedWord : this.blockedWords) {
|
||||
for (final Pattern blockedWord : this.carbonChat.moderationSettings().filters().blockedPatterns()) {
|
||||
if (blockedWord.matcher(event.message()).find()) {
|
||||
event.cancelled(true);
|
||||
break;
|
||||
@@ -68,38 +61,6 @@ public class FilterContext {
|
||||
});
|
||||
}
|
||||
|
||||
public void reloadFilters() {
|
||||
this.patternReplacements.clear();
|
||||
this.blockedWords.clear();
|
||||
|
||||
// final FileConfiguration config = this.carbonChat.moderationConfig();
|
||||
// final ConfigurationSection filters = config.getConfigurationSection("filters.filters");
|
||||
//
|
||||
// if (filters != null) {
|
||||
// for (final String replacement : filters.getKeys(false)) {
|
||||
// final List<Pattern> patterns = new ArrayList<>();
|
||||
//
|
||||
// for (final String word : filters.getStringList(replacement)) {
|
||||
// if (this.carbonChat.moderationConfig().getBoolean("filters.case-sensitive")) {
|
||||
// patterns.add(Pattern.compile(word));
|
||||
// } else {
|
||||
// patterns.add(Pattern.compile(word, Pattern.CASE_INSENSITIVE));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// this.patternReplacements.put(replacement, patterns);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// for (final String replacement : config.getStringList("filters.blocked-words")) {
|
||||
// if (this.carbonChat.moderationConfig().getBoolean("filters.case-sensitive")) {
|
||||
// this.blockedWords.add(Pattern.compile(replacement));
|
||||
// } else {
|
||||
// this.blockedWords.add(Pattern.compile(replacement, Pattern.CASE_INSENSITIVE));
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
private boolean channelUsesFilter(final @NonNull ChatChannel chatChannel) {
|
||||
final Context context = chatChannel.context("filter");
|
||||
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
# CarbonChat Docs:
|
||||
# https://github.com/Draycia/Chat/wiki
|
||||
|
||||
# Set this to false to disable warnings and tips when the plugin thinks there may be configuration issues.
|
||||
show-tips: true
|
||||
|
||||
# All of the settings under this 'default' section can be applied to each channel individually to override these.
|
||||
# These are provided as a way to configure default channel settings.
|
||||
default:
|
||||
@@ -93,19 +90,6 @@ channels:
|
||||
is-cross-server: false
|
||||
message-prefix: '!'
|
||||
|
||||
# Used for message formats - custom tags that are replaced in descending order
|
||||
# For example, in the default config, <group> wil be replaced with <green>%vault_group%
|
||||
placeholders:
|
||||
prefix: "<gray>[<group><gray>]"
|
||||
group: "<green>%vault_group%"
|
||||
|
||||
# Sets the player's channel to the specified channel when they join
|
||||
# Set to "" or remove to disable
|
||||
# Set to DEFAULT to set the player's channel to the default channel on join
|
||||
# Otherwise, set to a channel to set the player's channel to it on join
|
||||
# For example, channel-on-join: "global" sets their channel to global on join
|
||||
channel-on-join: ""
|
||||
|
||||
# Global context options
|
||||
contexts:
|
||||
Towny:
|
||||
@@ -113,61 +97,9 @@ contexts:
|
||||
mcMMO:
|
||||
cancellation-message: '<red>You do not have a party!'
|
||||
|
||||
# Used for <server> placeholder in channel formats
|
||||
server-name: 'Server'
|
||||
|
||||
item-link-placeholders:
|
||||
- '[item]'
|
||||
- '%item%'
|
||||
|
||||
# The prefix shown when spying on a user's message
|
||||
spy-prefix: '<color>[SPY] '
|
||||
|
||||
# Determines if the player's tab menu name is updated with /nickname
|
||||
nicknames-set-tab-name: true
|
||||
|
||||
# Plays a sound and highlights the message when someone types your name
|
||||
pings:
|
||||
enabled: true
|
||||
case-sensitive: false
|
||||
source: 'PLAYER'
|
||||
sound: 'minecraft:entity.experience_orb.pickup'
|
||||
prefix: '@'
|
||||
volume: 10.0
|
||||
pitch: 1.0
|
||||
# highlight: true # currently disabled and nonfunctional
|
||||
|
||||
# Plays a sound when receiving private messages with /whisper /msg
|
||||
whisper:
|
||||
pings:
|
||||
enabled: true
|
||||
source: 'PLAYER'
|
||||
sound: 'minecraft:entity.experience_orb.pickup'
|
||||
volume: 10.0
|
||||
pitch: 1.0
|
||||
|
||||
# Options:
|
||||
# 'JSON' - Uses JSON text files to store player data
|
||||
# 'MySQL' - Uses MySQL to store player data
|
||||
storage:
|
||||
type: JSON
|
||||
username: 'username'
|
||||
password: 'password'
|
||||
database: 'database'
|
||||
hostname: 'localhost'
|
||||
port: 3306
|
||||
|
||||
# Options:
|
||||
# 'bungee' - Uses bungee plugin messaging, requires BungeeCord or another proxy which supports it (Velocity!)
|
||||
# 'redis' - Uses redis for cross server syncing, does not require a server proxy
|
||||
# 'none' - Do not sync anything cross server, this is the default
|
||||
#
|
||||
# Note: In order for channels to sync cross server, you'll need to enable is-cross-server for the
|
||||
# channel as well as this setting.
|
||||
message-system: 'none'
|
||||
|
||||
redis:
|
||||
host: 'localhost'
|
||||
port: 6379
|
||||
#password: 'password'
|
||||
database: 0
|
||||
@@ -1,18 +0,0 @@
|
||||
filters:
|
||||
enabled: true
|
||||
case-sensitive: false
|
||||
# The keys ("****" for example) are what the text is replaced with
|
||||
# The strings in the lists ("lag" etc) are what's replaced
|
||||
# Set to filters: {} if you want to disable the filter feature.
|
||||
filters:
|
||||
# In this example, any instance of "lag" or "laggggg" will be replaced with "****"
|
||||
"****":
|
||||
- "la[g]+"
|
||||
- "lag"
|
||||
# Underscore = blank, empty. The text will basically be removed.
|
||||
"_":
|
||||
- "broccoli sucks"
|
||||
# Anything in blocked-words will prevent the message from being sent at all.
|
||||
# Set to blocked-words: [] if you want to disable the blocked words feature.
|
||||
blocked-words:
|
||||
- "pineapple doesn't belong on pizza"
|
||||
+7
-7
@@ -14,7 +14,7 @@ public class PingHandler {
|
||||
final CarbonChat carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
CarbonEvents.register(ChatComponentEvent.class, PostOrders.LAST, false, event -> {
|
||||
if (!carbonChat.carbonSettings().pings().enabled()) {
|
||||
if (!carbonChat.carbonSettings().channelPings().enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ public class PingHandler {
|
||||
}
|
||||
|
||||
final String targetName = event.target().name();
|
||||
final String prefix = carbonChat.carbonSettings().pings().prefix();
|
||||
final boolean caseSensitive = carbonChat.carbonSettings().pings().caseSensitive();
|
||||
final String prefix = carbonChat.carbonSettings().channelPings().prefix();
|
||||
final boolean caseSensitive = carbonChat.carbonSettings().channelPings().caseSensitive();
|
||||
|
||||
if (caseSensitive) {
|
||||
if (!event.originalMessage().contains(prefix + targetName)) {
|
||||
@@ -36,10 +36,10 @@ public class PingHandler {
|
||||
}
|
||||
}
|
||||
|
||||
final Key key = carbonChat.carbonSettings().pings().sound();
|
||||
final Sound.Source source = carbonChat.carbonSettings().pings().source();
|
||||
final float volume = carbonChat.carbonSettings().pings().volume();
|
||||
final float pitch = carbonChat.carbonSettings().pings().pitch();
|
||||
final Key key = carbonChat.carbonSettings().channelPings().sound();
|
||||
final Sound.Source source = carbonChat.carbonSettings().channelPings().source();
|
||||
final float volume = carbonChat.carbonSettings().channelPings().volume();
|
||||
final float pitch = carbonChat.carbonSettings().channelPings().pitch();
|
||||
|
||||
event.target().playSound(Sound.of(key, source, volume, pitch));
|
||||
});
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ import io.lettuce.core.pubsub.api.sync.RedisPubSubCommands;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.messaging.MessageService;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.common.utils.RedisCredentials;
|
||||
import net.draycia.carbon.api.config.RedisCredentials;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Base64;
|
||||
|
||||
Reference in new issue
Block a user