mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 06:28:53 +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;
|
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.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
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.objectmapping.Setting;
|
||||||
import org.spongepowered.configurate.serialize.ConfigSerializable;
|
import org.spongepowered.configurate.serialize.ConfigSerializable;
|
||||||
|
|
||||||
@@ -14,17 +15,77 @@ import java.util.Map;
|
|||||||
@ConfigSerializable
|
@ConfigSerializable
|
||||||
public class CarbonSettings {
|
public class CarbonSettings {
|
||||||
|
|
||||||
@Setting private @NonNull String spyPrefix = "<color>[SPY] ";
|
private static final ObjectMapper<CarbonSettings> MAPPER;
|
||||||
@Setting private @NonNull String serverName = "Server";
|
|
||||||
@Setting private boolean showTips = true;
|
static {
|
||||||
@Setting private @NonNull List<@NonNull ChannelSettings> channelSettings; // TODO: unfuck this, it's loaded from file?
|
try {
|
||||||
@Setting private @Nullable StorageType storageType = StorageType.JSON;
|
MAPPER = ObjectMapper.forClass(CarbonSettings.class); // We hold on to the instance of our ObjectMapper
|
||||||
@Setting private @NonNull SQLCredentials sqlCredentials =
|
} 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);
|
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(comment = "Options: NONE, REDIS, BUNGEECORD")
|
||||||
@Setting private @NonNull WhisperPings whisperPings = new WhisperPings();
|
private @NonNull MessagingType messagingType = MessagingType.NONE;
|
||||||
@Setting private @Nullable String channelOnJoin = "";
|
|
||||||
|
@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() {
|
public @NonNull String spyPrefix() {
|
||||||
return this.spyPrefix;
|
return this.spyPrefix;
|
||||||
@@ -50,6 +111,14 @@ public class CarbonSettings {
|
|||||||
return this.sqlCredentials;
|
return this.sqlCredentials;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NonNull MessagingType messagingType() {
|
||||||
|
return this.messagingType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NonNull RedisCredentials redisCredentials() {
|
||||||
|
return this.redisCredentials;
|
||||||
|
}
|
||||||
|
|
||||||
public Map<String, String> customPlaceholders() {
|
public Map<String, String> customPlaceholders() {
|
||||||
return this.customPlaceholders;
|
return this.customPlaceholders;
|
||||||
}
|
}
|
||||||
@@ -58,85 +127,12 @@ public class CarbonSettings {
|
|||||||
return this.channelOnJoin;
|
return this.channelOnJoin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NonNull Pings pings() {
|
public @NonNull ChannelPings channelPings() {
|
||||||
return this.pings;
|
return this.channelPings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NonNull WhisperPings whisperPings() {
|
public @NonNull WhisperPings whisperPings() {
|
||||||
return this.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;
|
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.objectmapping.Setting;
|
||||||
import org.spongepowered.configurate.serialize.ConfigSerializable;
|
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
|
@ConfigSerializable
|
||||||
public class ModerationSettings {
|
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
|
// TODO: comment this
|
||||||
@Setting
|
@Setting
|
||||||
private String shadowMutePrefix = "[SM] ";
|
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.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
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.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.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.messaging.MessageService;
|
import net.draycia.carbon.api.messaging.MessageService;
|
||||||
import net.draycia.carbon.api.users.ChatUser;
|
import net.draycia.carbon.api.users.ChatUser;
|
||||||
import net.draycia.carbon.common.adventure.FormatType;
|
import net.draycia.carbon.common.adventure.FormatType;
|
||||||
import net.draycia.carbon.common.messaging.EmptyMessageService;
|
import net.draycia.carbon.common.messaging.EmptyMessageService;
|
||||||
import net.draycia.carbon.api.config.SQLCredentials;
|
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.DistanceContext;
|
||||||
import net.draycia.carbon.listeners.contexts.EconomyContext;
|
import net.draycia.carbon.listeners.contexts.EconomyContext;
|
||||||
import net.draycia.carbon.listeners.contexts.FilterContext;
|
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.api.users.UserService;
|
||||||
import net.draycia.carbon.common.users.JSONUserService;
|
import net.draycia.carbon.common.users.JSONUserService;
|
||||||
import net.draycia.carbon.common.users.MySQLUserService;
|
import net.draycia.carbon.common.users.MySQLUserService;
|
||||||
|
import net.draycia.carbon.messaging.BungeeMessageService;
|
||||||
import net.draycia.carbon.storage.BukkitChatUser;
|
import net.draycia.carbon.storage.BukkitChatUser;
|
||||||
import net.draycia.carbon.util.CarbonPlaceholders;
|
import net.draycia.carbon.util.CarbonPlaceholders;
|
||||||
import net.draycia.carbon.util.FunctionalityConstants;
|
import net.draycia.carbon.util.FunctionalityConstants;
|
||||||
@@ -81,8 +85,6 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
|||||||
private UserService<BukkitChatUser> userService;
|
private UserService<BukkitChatUser> userService;
|
||||||
private MessageManager messageManager;
|
private MessageManager messageManager;
|
||||||
|
|
||||||
private FilterContext filterContext;
|
|
||||||
|
|
||||||
private CarbonTranslations translations;
|
private CarbonTranslations translations;
|
||||||
|
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
@@ -104,17 +106,9 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
|||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
this.logger = LoggerFactory.getLogger(this.getName());
|
this.logger = LoggerFactory.getLogger(this.getName());
|
||||||
|
|
||||||
|
// Setup metrics
|
||||||
final Metrics metrics = new Metrics(this, BSTATS_PLUGIN_ID);
|
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();
|
this.reloadConfig();
|
||||||
|
|
||||||
// Setup Adventure
|
// Setup Adventure
|
||||||
@@ -122,9 +116,23 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
|||||||
|
|
||||||
// Initialize managers
|
// Initialize managers
|
||||||
this.channelRegistry = new ChannelRegistry();
|
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 Supplier<Iterable<BukkitChatUser>> supplier = () -> {
|
||||||
final List<BukkitChatUser> users = new ArrayList<>();
|
final List<BukkitChatUser> users = new ArrayList<>();
|
||||||
@@ -136,11 +144,11 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
|||||||
return users;
|
return users;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (storageType == CarbonSettings.StorageType.MYSQL) {
|
if (storageType == StorageType.MYSQL) {
|
||||||
this.logger().info("Enabling MySQL storage!");
|
this.logger().info("Enabling MySQL storage!");
|
||||||
final SQLCredentials credentials = this.carbonSettings().sqlCredentials();
|
final SQLCredentials credentials = this.carbonSettings().sqlCredentials();
|
||||||
this.userService = new MySQLUserService<>(this, credentials, supplier, BukkitChatUser::new);
|
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.logger().info("Enabling JSON storage!");
|
||||||
this.userService = new JSONUserService<>(BukkitChatUser.class, this, supplier, BukkitChatUser::new);
|
this.userService = new JSONUserService<>(BukkitChatUser.class, this, supplier, BukkitChatUser::new);
|
||||||
} else {
|
} else {
|
||||||
@@ -153,9 +161,11 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
|||||||
this.setupListeners();
|
this.setupListeners();
|
||||||
this.registerContexts();
|
this.registerContexts();
|
||||||
|
|
||||||
|
// Setup PlaceholderAPI placeholders
|
||||||
new CarbonPlaceholders(this).register();
|
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.");
|
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
|
@Override
|
||||||
public void reloadConfig() {
|
public void reloadConfig() {
|
||||||
super.reloadConfig();
|
this.loadCarbonSettingS();
|
||||||
|
|
||||||
this.loadLanguage();
|
this.loadLanguage();
|
||||||
this.loadModerationSettings();
|
this.loadModerationSettings();
|
||||||
this.loadCommandSettings();
|
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() {
|
private void loadLanguage() {
|
||||||
final File languageFile = new File(this.getDataFolder(), "language.yml");
|
final File languageFile = new File(this.getDataFolder(), "language.yml");
|
||||||
final YamlConfigurationLoader languageLoader = YamlConfigurationLoader.builder().setFile(languageFile).build();
|
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() {
|
private void loadCommandSettings() {
|
||||||
// TODO: probably redo this from scratch
|
// TODO: probably redo this from scratch
|
||||||
final File carbonCommands = new File(this.getDataFolder(), "carbon-commands.yml");
|
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() {
|
private void registerContexts() {
|
||||||
this.filterContext = new FilterContext(this);
|
|
||||||
|
|
||||||
if (Bukkit.getPluginManager().isPluginEnabled("Towny")) {
|
if (Bukkit.getPluginManager().isPluginEnabled("Towny")) {
|
||||||
this.getServer().getPluginManager().registerEvents(new TownyContext(this), this);
|
this.getServer().getPluginManager().registerEvents(new TownyContext(this), this);
|
||||||
}
|
}
|
||||||
@@ -274,6 +297,7 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
new DistanceContext();
|
new DistanceContext();
|
||||||
|
new FilterContext(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
|||||||
+7
-46
@@ -8,8 +8,6 @@ import net.draycia.carbon.api.Context;
|
|||||||
import net.kyori.event.PostOrders;
|
import net.kyori.event.PostOrders;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
@@ -20,20 +18,13 @@ public class FilterContext {
|
|||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
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) {
|
public FilterContext(final @NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
this.reloadFilters();
|
|
||||||
|
|
||||||
CarbonEvents.register(PreChatFormatEvent.class, PostOrders.FIRST, false, event -> {
|
CarbonEvents.register(PreChatFormatEvent.class, PostOrders.FIRST, false, event -> {
|
||||||
// if (!carbonChat.moderationSettings().filters().enabled()) {
|
if (!carbonChat.moderationSettings().filters().enabled()) {
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
|
|
||||||
if (event.user().permissible() && event.user().hasPermission("carbonchat.filter.exempt")) {
|
if (event.user().permissible() && event.user().hasPermission("carbonchat.filter.exempt")) {
|
||||||
return;
|
return;
|
||||||
@@ -45,7 +36,9 @@ public class FilterContext {
|
|||||||
|
|
||||||
String message = event.message();
|
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()) {
|
for (final Pattern pattern : entry.getValue()) {
|
||||||
final Matcher matcher = pattern.matcher(message);
|
final Matcher matcher = pattern.matcher(message);
|
||||||
|
|
||||||
@@ -59,7 +52,7 @@ public class FilterContext {
|
|||||||
|
|
||||||
event.message(message);
|
event.message(message);
|
||||||
|
|
||||||
for (final Pattern blockedWord : this.blockedWords) {
|
for (final Pattern blockedWord : this.carbonChat.moderationSettings().filters().blockedPatterns()) {
|
||||||
if (blockedWord.matcher(event.message()).find()) {
|
if (blockedWord.matcher(event.message()).find()) {
|
||||||
event.cancelled(true);
|
event.cancelled(true);
|
||||||
break;
|
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) {
|
private boolean channelUsesFilter(final @NonNull ChatChannel chatChannel) {
|
||||||
final Context context = chatChannel.context("filter");
|
final Context context = chatChannel.context("filter");
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
# CarbonChat Docs:
|
# CarbonChat Docs:
|
||||||
# https://github.com/Draycia/Chat/wiki
|
# 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.
|
# 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.
|
# These are provided as a way to configure default channel settings.
|
||||||
default:
|
default:
|
||||||
@@ -93,19 +90,6 @@ channels:
|
|||||||
is-cross-server: false
|
is-cross-server: false
|
||||||
message-prefix: '!'
|
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
|
# Global context options
|
||||||
contexts:
|
contexts:
|
||||||
Towny:
|
Towny:
|
||||||
@@ -113,61 +97,9 @@ contexts:
|
|||||||
mcMMO:
|
mcMMO:
|
||||||
cancellation-message: '<red>You do not have a party!'
|
cancellation-message: '<red>You do not have a party!'
|
||||||
|
|
||||||
# Used for <server> placeholder in channel formats
|
|
||||||
server-name: 'Server'
|
|
||||||
|
|
||||||
item-link-placeholders:
|
item-link-placeholders:
|
||||||
- '[item]'
|
- '[item]'
|
||||||
- '%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
|
# Determines if the player's tab menu name is updated with /nickname
|
||||||
nicknames-set-tab-name: true
|
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();
|
final CarbonChat carbonChat = CarbonChatProvider.carbonChat();
|
||||||
|
|
||||||
CarbonEvents.register(ChatComponentEvent.class, PostOrders.LAST, false, event -> {
|
CarbonEvents.register(ChatComponentEvent.class, PostOrders.LAST, false, event -> {
|
||||||
if (!carbonChat.carbonSettings().pings().enabled()) {
|
if (!carbonChat.carbonSettings().channelPings().enabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,8 +23,8 @@ public class PingHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final String targetName = event.target().name();
|
final String targetName = event.target().name();
|
||||||
final String prefix = carbonChat.carbonSettings().pings().prefix();
|
final String prefix = carbonChat.carbonSettings().channelPings().prefix();
|
||||||
final boolean caseSensitive = carbonChat.carbonSettings().pings().caseSensitive();
|
final boolean caseSensitive = carbonChat.carbonSettings().channelPings().caseSensitive();
|
||||||
|
|
||||||
if (caseSensitive) {
|
if (caseSensitive) {
|
||||||
if (!event.originalMessage().contains(prefix + targetName)) {
|
if (!event.originalMessage().contains(prefix + targetName)) {
|
||||||
@@ -36,10 +36,10 @@ public class PingHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final Key key = carbonChat.carbonSettings().pings().sound();
|
final Key key = carbonChat.carbonSettings().channelPings().sound();
|
||||||
final Sound.Source source = carbonChat.carbonSettings().pings().source();
|
final Sound.Source source = carbonChat.carbonSettings().channelPings().source();
|
||||||
final float volume = carbonChat.carbonSettings().pings().volume();
|
final float volume = carbonChat.carbonSettings().channelPings().volume();
|
||||||
final float pitch = carbonChat.carbonSettings().pings().pitch();
|
final float pitch = carbonChat.carbonSettings().channelPings().pitch();
|
||||||
|
|
||||||
event.target().playSound(Sound.of(key, source, volume, 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.CarbonChat;
|
||||||
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;
|
||||||
import net.draycia.carbon.common.utils.RedisCredentials;
|
import net.draycia.carbon.api.config.RedisCredentials;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
|||||||
Reference in new issue
Block a user