mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
Closer to compilation
This commit is contained in:
1 parent
8db4b9532c
commit
18c6fd7e2b
19 files changed
+379
-318
No files matched your search
@@ -4,6 +4,7 @@ import net.draycia.carbon.api.adventure.CarbonTranslations;
|
||||
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.ModerationSettings;
|
||||
import net.draycia.carbon.api.messaging.MessageService;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
@@ -20,7 +21,7 @@ public interface CarbonChat {
|
||||
LegacyComponentSerializer.builder()
|
||||
.extractUrls()
|
||||
.hexColors()
|
||||
.character('§')
|
||||
.character(LegacyComponentSerializer.SECTION_CHAR)
|
||||
.useUnusualXRepeatedCharacterHexFormat()
|
||||
.build();
|
||||
|
||||
@@ -36,6 +37,8 @@ public interface CarbonChat {
|
||||
|
||||
@NonNull MessageService messageService();
|
||||
|
||||
@NonNull CarbonSettings carbonSettings();
|
||||
|
||||
@NonNull ChannelRegistry channelRegistry();
|
||||
|
||||
@NonNull CommandSettingsRegistry commandSettingsRegistry();
|
||||
|
||||
@@ -70,7 +70,7 @@ public interface ChatChannel extends ForwardingAudience {
|
||||
|
||||
@Nullable String messagePrefix();
|
||||
|
||||
@Nullable String aliases();
|
||||
@Nullable List<String> aliases();
|
||||
|
||||
@Nullable String switchMessage();
|
||||
|
||||
|
||||
-1
@@ -4,7 +4,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.spongepowered.configurate.objectmapping.Setting;
|
||||
import org.spongepowered.configurate.serialize.ConfigSerializable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@ConfigSerializable
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package net.draycia.carbon.api.config;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CarbonSettings {
|
||||
|
||||
private @NonNull String spyPrefix;
|
||||
private @NonNull String serverName;
|
||||
private boolean showTips;
|
||||
private @NonNull List<@NonNull ChannelSettings> channelSettings;
|
||||
private @Nullable StorageType storageType;
|
||||
private @NonNull SQLCredentials sqlCredentials;
|
||||
private @NonNull Map<@Nullable String, @NonNull String> customPlaceholders;
|
||||
|
||||
public @NonNull String spyPrefix() {
|
||||
return this.spyPrefix;
|
||||
}
|
||||
|
||||
public @NonNull String serverName() {
|
||||
return this.serverName;
|
||||
}
|
||||
|
||||
public boolean showTips() {
|
||||
return this.showTips;
|
||||
}
|
||||
|
||||
public @NonNull List<@NonNull ChannelSettings> channelSettings() {
|
||||
return this.channelSettings;
|
||||
}
|
||||
|
||||
public @Nullable StorageType storageType() {
|
||||
return this.storageType;
|
||||
}
|
||||
|
||||
public SQLCredentials sqlCredentials() {
|
||||
return this.sqlCredentials;
|
||||
}
|
||||
|
||||
public Map<String, String> customPlaceholders() {
|
||||
return this.customPlaceholders;
|
||||
}
|
||||
|
||||
public enum StorageType {
|
||||
MYSQL,
|
||||
JSON
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
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 java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ChannelSettings {
|
||||
|
||||
private String key;
|
||||
private String color;
|
||||
private Map<String, Context> contexts;
|
||||
private Map<String, String> formats;
|
||||
private String defaultFormatName;
|
||||
private boolean isDefault;
|
||||
private boolean ignorable;
|
||||
private boolean crossServer;
|
||||
private boolean honorsRecipientList;
|
||||
private boolean permissionGroupMatching;
|
||||
private List<String> groupOverrides;
|
||||
private String name;
|
||||
private String messagePrefix;
|
||||
private String switchMessage;
|
||||
private List<Pattern> itemLinkPatterns;
|
||||
private String switchOtherMessage;
|
||||
private List<String> aliases;
|
||||
private boolean shouldCancelChatEvent;
|
||||
private boolean primaryGroupOnly;
|
||||
private String cannotUseMessage;
|
||||
private String toggleOtherOffMessage;
|
||||
private String toggleOtherOnMessage;
|
||||
private String toggleOnMessage;
|
||||
private String toggleOffMessage;
|
||||
private String cannotIgnoreMessage;
|
||||
private String switchFailureMessage;
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<@NonNull Pattern> itemLinkPatterns() {
|
||||
return this.itemLinkPatterns;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<String> aliases() {
|
||||
return this.aliases;
|
||||
}
|
||||
|
||||
}
|
||||
+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;
|
||||
|
||||
@@ -8,11 +8,13 @@ import net.draycia.carbon.api.adventure.CarbonTranslations;
|
||||
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.ModerationSettings;
|
||||
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.listeners.contexts.DistanceContext;
|
||||
import net.draycia.carbon.listeners.contexts.EconomyContext;
|
||||
import net.draycia.carbon.listeners.contexts.FilterContext;
|
||||
@@ -40,15 +42,13 @@ 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.storage.impl.BukkitChatUser;
|
||||
import net.draycia.carbon.storage.BukkitChatUser;
|
||||
import net.draycia.carbon.util.CarbonPlaceholders;
|
||||
import net.draycia.carbon.util.FunctionalityConstants;
|
||||
import net.draycia.carbon.util.Metrics;
|
||||
import dev.jorel.commandapi.CommandAPI;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
@@ -63,17 +63,21 @@ import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
|
||||
private static final int BSTATS_PLUGIN_ID = 8720;
|
||||
|
||||
private Permission permission;
|
||||
|
||||
private ChannelRegistry channelRegistry;
|
||||
private CommandSettingsRegistry commandSettings;
|
||||
private AdventureManager messageProcessor;
|
||||
|
||||
private CommandSettingsRegistry commandSettings;
|
||||
private ModerationSettings moderationSettings;
|
||||
private CarbonSettings carbonSettings;
|
||||
|
||||
private UserService<BukkitChatUser> userService;
|
||||
private MessageManager messageManager;
|
||||
|
||||
@@ -94,15 +98,12 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
@Override
|
||||
public void onLoad() {
|
||||
CarbonChatProvider.register(this);
|
||||
|
||||
CommandAPI.onLoad(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
this.logger = LoggerFactory.getLogger(this.getName());
|
||||
|
||||
CommandAPI.onEnable(this);
|
||||
final Metrics metrics = new Metrics(this, BSTATS_PLUGIN_ID);
|
||||
|
||||
// Ensure config is present to be modified by the user
|
||||
@@ -119,24 +120,32 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
// Setup Adventure
|
||||
this.messageProcessor = new AdventureManager(BukkitAudiences.create(this), FormatType.MINIMESSAGE); // TODO: get format type from config
|
||||
|
||||
// Setup vault and permissions
|
||||
this.permission = this.getServer().getServicesManager().getRegistration(Permission.class).getProvider();
|
||||
|
||||
// Initialize managers
|
||||
this.channelRegistry = new ChannelRegistry();
|
||||
this.messageManager = new MessageManager(this, new EmptyMessageService()); // TODO: get message service from config
|
||||
|
||||
final String storageType = this.getConfig().getString("storage.type");
|
||||
final CarbonSettings.StorageType storageType = this.carbonSettings().storageType();
|
||||
|
||||
if (storageType.equalsIgnoreCase("mysql")) {
|
||||
final Supplier<Iterable<BukkitChatUser>> supplier = () -> {
|
||||
final List<BukkitChatUser> users = new ArrayList<>();
|
||||
|
||||
for (final Player player : Bukkit.getOnlinePlayers()) {
|
||||
users.add(this.userService.wrap(player.getUniqueId()));
|
||||
}
|
||||
|
||||
return users;
|
||||
};
|
||||
|
||||
if (storageType == CarbonSettings.StorageType.MYSQL) {
|
||||
this.logger().info("Enabling MySQL storage!");
|
||||
this.userService = new MySQLUserService(this);
|
||||
} else if (storageType.equalsIgnoreCase("json")) {
|
||||
final SQLCredentials credentials = this.carbonSettings().sqlCredentials();
|
||||
this.userService = new MySQLUserService<>(BukkitChatUser.class, this, credentials, supplier);
|
||||
} else if (storageType == CarbonSettings.StorageType.JSON) {
|
||||
this.logger().info("Enabling JSON storage!");
|
||||
this.userService = new JSONUserService(this);
|
||||
this.userService = new JSONUserService<>(BukkitChatUser.class, this, supplier);
|
||||
} else {
|
||||
this.logger().error("Invalid storage type selected! Falling back to JSON.");
|
||||
this.userService = new JSONUserService(this);
|
||||
this.userService = new JSONUserService<>(BukkitChatUser.class, this, supplier);
|
||||
}
|
||||
|
||||
// Setup listeners
|
||||
@@ -220,12 +229,14 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
|
||||
private void loadCommandSettings() {
|
||||
// TODO: probably redo this from scratch
|
||||
if (!(new File(this.getDataFolder(), "carbon-commands.yml").exists())) {
|
||||
final File carbonCommands = new File(this.getDataFolder(), "carbon-commands.yml");
|
||||
|
||||
if (!(carbonCommands.exists())) {
|
||||
this.saveResource("carbon-commands.yml", false);
|
||||
}
|
||||
|
||||
final File commandSettingsFile = new File(this.getDataFolder(), "carbon-commands.yml");
|
||||
final YamlConfigurationLoader commandSettingsLoader = YamlConfigurationLoader.builder().setFile(commandSettingsFile).build();
|
||||
final YamlConfigurationLoader commandSettingsLoader =
|
||||
YamlConfigurationLoader.builder().setFile(carbonCommands).build();
|
||||
|
||||
try {
|
||||
final BasicConfigurationNode commandSettingsNode = commandSettingsLoader.load();
|
||||
@@ -265,11 +276,6 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
new DistanceContext();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Permission permission() {
|
||||
return this.permission;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public MessageManager messageManager() {
|
||||
return this.messageManager;
|
||||
@@ -300,6 +306,11 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
return this.moderationSettings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull CarbonSettings carbonSettings() {
|
||||
return this.carbonSettings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull MessageProcessor messageProcessor() {
|
||||
return this.messageProcessor;
|
||||
|
||||
+29
-32
@@ -2,13 +2,10 @@ package net.draycia.carbon.listeners.contexts;
|
||||
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.PreChatFormatEvent;
|
||||
import net.draycia.carbon.api.Context;
|
||||
import net.kyori.event.PostOrders;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -34,9 +31,9 @@ public class FilterContext {
|
||||
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;
|
||||
@@ -75,32 +72,32 @@ public class FilterContext {
|
||||
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));
|
||||
}
|
||||
}
|
||||
// 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) {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package net.draycia.carbon.messaging.impl;
|
||||
package net.draycia.carbon.messaging;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package net.draycia.carbon.storage.impl;
|
||||
package net.draycia.carbon.storage;
|
||||
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package net.draycia.carbon.storage.impl;
|
||||
package net.draycia.carbon.storage;
|
||||
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
@@ -133,87 +133,4 @@ public final class CarbonUtils {
|
||||
return TextColor.fromCSSHexString(input);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Argument onlineChatUserArgument() {
|
||||
return new CustomArgument<>(input -> {
|
||||
final CarbonChatBukkit carbonChat = (CarbonChatBukkit) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
|
||||
final Player player = Bukkit.getPlayer(input);
|
||||
|
||||
if (player == null) {
|
||||
throw new CustomArgument.CustomArgumentException("Invalid player for input (" + input + ")");
|
||||
}
|
||||
|
||||
return carbonChat.userService().wrap(player.getUniqueId());
|
||||
// }).overrideSuggestions((sender, args) -> {
|
||||
// ArrayList<String> players = new ArrayList<>();
|
||||
//
|
||||
// for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
// players.add(player.getName());
|
||||
// }
|
||||
//
|
||||
// return players.toArray(new String[0]);
|
||||
});
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Argument chatUserArgument() {
|
||||
return new CustomArgument<>(input -> {
|
||||
final CarbonChatBukkit carbonChat = (CarbonChatBukkit) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
|
||||
return carbonChat.userService().wrap(Bukkit.getOfflinePlayer(input).getUniqueId());
|
||||
// }).overrideSuggestions((sender, args) -> {
|
||||
// ArrayList<String> players = new ArrayList<>();
|
||||
//
|
||||
// for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
// players.add(player.getName());
|
||||
// }
|
||||
//
|
||||
// return players.toArray(new String[0]);
|
||||
});
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Argument textColorArgument() {
|
||||
return new CustomArgument<>(input -> {
|
||||
final TextColor color = parseColor(input);
|
||||
|
||||
if (color == null) {
|
||||
throw new CustomArgument.CustomArgumentException("Invalid color for input (" + input + ")");
|
||||
}
|
||||
|
||||
return color;
|
||||
}).overrideSuggestions(colors);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Argument channelArgument() {
|
||||
return new CustomArgument<>(input -> {
|
||||
final CarbonChatBukkit carbonChat = (CarbonChatBukkit) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
|
||||
final ChatChannel channel = carbonChat.channelRegistry().get(input);
|
||||
|
||||
if (channel == null) {
|
||||
throw new CustomArgument.CustomArgumentException("Invalid channel for input (" + input + ")");
|
||||
}
|
||||
|
||||
return channel;
|
||||
// }).overrideSuggestions((sender, args) -> {
|
||||
// CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
//
|
||||
// ArrayList<String> channels = new ArrayList<>();
|
||||
//
|
||||
// for (ChatChannel channel : this.carbonChat.getChannelManager().getRegistry().values()) {
|
||||
// channels.add(channel.getKey());
|
||||
// }
|
||||
//
|
||||
// return channels.toArray(new String[0]);
|
||||
});
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Argument usableChannelArgument() {
|
||||
throw new NotImplementedException("Not implemented yet.");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package net.draycia.carbon.util;
|
||||
|
||||
import dev.jorel.commandapi.CommandAPI;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettings;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class CommandUtils {
|
||||
|
||||
private CommandUtils() {
|
||||
|
||||
}
|
||||
|
||||
public static void handleDuplicateCommands(final @NonNull CommandSettings settings) {
|
||||
CommandAPI.unregister(settings.name());
|
||||
|
||||
for (final String command : settings.aliases()) {
|
||||
CommandAPI.unregister(command);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+15
-18
@@ -1,8 +1,8 @@
|
||||
package net.draycia.carbon.channels;
|
||||
package net.draycia.carbon.common.channels;
|
||||
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.common.channels.ChannelSettings;
|
||||
import net.draycia.carbon.util.CarbonUtils;
|
||||
import net.draycia.carbon.api.config.ChannelSettings;
|
||||
import net.draycia.carbon.common.utils.ColorUtils;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.ChatComponentEvent;
|
||||
@@ -29,18 +29,13 @@ import java.util.regex.Pattern;
|
||||
|
||||
public class CarbonChatChannel implements ChatChannel {
|
||||
|
||||
@NonNull
|
||||
private final String key;
|
||||
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
@NonNull
|
||||
private final ChannelSettings settings;
|
||||
|
||||
public CarbonChatChannel(final @NonNull String key, final @NonNull CarbonChat carbonChat,
|
||||
@Nullable final ChannelSettings settings) {
|
||||
this.key = key;
|
||||
public CarbonChatChannel(final @NonNull CarbonChat carbonChat, @Nullable final ChannelSettings settings) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.settings = settings;
|
||||
}
|
||||
@@ -155,11 +150,11 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
"displayname", displayName,
|
||||
"color", "<" + targetColor.asHexString() + ">",
|
||||
"phase", Long.toString(System.currentTimeMillis() % 25),
|
||||
"server", this.carbonChat.getConfig().getString("server-name", "Server"),
|
||||
"server", this.carbonChat.carbonSettings().serverName(),
|
||||
"message", formatEvent.message());
|
||||
|
||||
if (this.isUserSpying(user, target)) {
|
||||
final String prefix = this.carbonChat.getConfig().getString("spy-prefix");
|
||||
final String prefix = this.carbonChat.carbonSettings().spyPrefix();
|
||||
|
||||
formatComponent = (TextComponent) MiniMessage.get().parse(prefix, "color",
|
||||
targetColor.asHexString()).append(formatComponent);
|
||||
@@ -185,7 +180,7 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
"displayname", displayName,
|
||||
"color", "<" + targetColor.asHexString() + ">",
|
||||
"phase", Long.toString(System.currentTimeMillis() % 25),
|
||||
"server", this.carbonChat.getConfig().getString("server-name", "Server"),
|
||||
"server", this.carbonChat.carbonSettings().serverName(),
|
||||
"message", consoleFormatEvent.message());
|
||||
|
||||
final ChatComponentEvent consoleEvent = new ChatComponentEvent(user, null, this, consoleFormat,
|
||||
@@ -346,11 +341,13 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
|
||||
final String input = this.settings().color();
|
||||
|
||||
final TextColor color = CarbonUtils.parseColor(user, input);
|
||||
final TextColor color = ColorUtils.parseColor(user, input);
|
||||
|
||||
if (color == null && this.carbonChat.getConfig().getBoolean("show-tips")) {
|
||||
this.carbonChat.logger().error("Tip: Channel color found (" + input + ") is invalid!");
|
||||
this.carbonChat.logger().error("Falling back to #FFFFFF");
|
||||
if (color == null) {
|
||||
if (this.carbonChat.carbonSettings().showTips()) {
|
||||
this.carbonChat.logger().error("Tip: Channel color found (" + input + ") is invalid!");
|
||||
this.carbonChat.logger().error("Falling back to #FFFFFF");
|
||||
}
|
||||
|
||||
return NamedTextColor.WHITE;
|
||||
}
|
||||
@@ -478,7 +475,7 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String aliases() {
|
||||
public List<String> aliases() {
|
||||
return this.settings().aliases();
|
||||
}
|
||||
|
||||
@@ -491,7 +488,7 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
@Override
|
||||
@NonNull
|
||||
public String key() {
|
||||
return this.key;
|
||||
return this.settings().key();
|
||||
}
|
||||
|
||||
}
|
||||
+11
-15
@@ -1,13 +1,12 @@
|
||||
package net.draycia.carbon.managers;
|
||||
package net.draycia.carbon.common.channels;
|
||||
|
||||
import net.draycia.carbon.channels.CarbonChatChannel;
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.config.ChannelSettings;
|
||||
import net.draycia.carbon.api.channels.ChannelRegistry;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.ChannelRegisterEvent;
|
||||
import net.kyori.registry.Registry;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@@ -17,7 +16,7 @@ import java.util.Collections;
|
||||
public class ChannelManager {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChatBukkit carbonChat;
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
@NonNull
|
||||
private final ChannelRegistry registry;
|
||||
@@ -26,19 +25,19 @@ public class ChannelManager {
|
||||
@MonotonicNonNull
|
||||
private String defaultChannelKey = null;
|
||||
|
||||
public ChannelManager(final @NonNull CarbonChatBukkit carbonChat) {
|
||||
public ChannelManager(final @NonNull CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.registry = new ChannelRegistry();
|
||||
|
||||
this.reload();
|
||||
}
|
||||
|
||||
public @Nullable ChatChannel loadChannel(final @NonNull String key, final @NonNull ConfigurationSection section) {
|
||||
final ChatChannel channel = new CarbonChatChannel(key, this.carbonChat, section);
|
||||
public @Nullable ChatChannel loadChannel(final @NonNull ChannelSettings settings) {
|
||||
final ChatChannel channel = new CarbonChatChannel(this.carbonChat, settings);
|
||||
|
||||
final String name = section.getString("name");
|
||||
final String name = settings.name();
|
||||
|
||||
if (name != null && name.length() > 16) {
|
||||
if (name.length() > 16) {
|
||||
this.carbonChat.logger().error("Channel name [" + name + "] too long! Max length: 16.");
|
||||
this.carbonChat.logger().error("Skipping channel, please check your settings!");
|
||||
return null;
|
||||
@@ -85,11 +84,8 @@ public class ChannelManager {
|
||||
}
|
||||
|
||||
private void reload() {
|
||||
for (final String key : this.carbonChat.getConfig().getConfigurationSection("channels").getKeys(false)) {
|
||||
final ConfigurationSection section =
|
||||
this.carbonChat.getConfig().getConfigurationSection("channels").getConfigurationSection(key);
|
||||
|
||||
final ChatChannel channel = this.loadChannel(key, section);
|
||||
for (final ChannelSettings settings : this.carbonChat.carbonSettings().channelSettings()) {
|
||||
final ChatChannel channel = this.loadChannel(settings);
|
||||
|
||||
if (channel != null) {
|
||||
this.registerChannel(channel);
|
||||
-106
@@ -1,106 +0,0 @@
|
||||
package net.draycia.carbon.common.channels;
|
||||
|
||||
import net.draycia.carbon.api.Context;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ChannelSettings {
|
||||
|
||||
@Nullable
|
||||
public String color() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Map<String, Context> contexts() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Map<String, String> formats() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String defaultFormatName() {
|
||||
}
|
||||
|
||||
public boolean isDefault() {
|
||||
}
|
||||
|
||||
public boolean ignorable() {
|
||||
}
|
||||
|
||||
public boolean crossServer() {
|
||||
}
|
||||
|
||||
public boolean honorsRecipientList() {
|
||||
}
|
||||
|
||||
public boolean permissionGroupMatching() {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<@NonNull String> groupOverrides() {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String name() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String messagePrefix() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String switchMessage() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String switchOtherMessage() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String switchFailureMessage() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String cannotIgnoreMessage() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String toggleOffMessage() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String toggleOnMessage() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String toggleOtherOnMessage() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String toggleOtherOffMessage() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String cannotUseMessage() {
|
||||
}
|
||||
|
||||
public boolean primaryGroupOnly() {
|
||||
}
|
||||
|
||||
public boolean shouldCancelChatEvent() {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<@NonNull Pattern> itemLinkPatterns() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String aliases() {
|
||||
}
|
||||
|
||||
}
|
||||
+4
-6
@@ -6,18 +6,16 @@ import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.PreChatFormatEvent;
|
||||
import net.kyori.event.PostOrders;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class CustomPlaceholderHandler {
|
||||
|
||||
public CustomPlaceholderHandler() {
|
||||
final CarbonChat carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
CarbonEvents.register(PreChatFormatEvent.class, PostOrders.FIRST, false, event -> {
|
||||
final ConfigurationSection placeholders = carbonChat.getConfig().getConfigurationSection("placeholders");
|
||||
|
||||
for (final String key : placeholders.getKeys(false)) {
|
||||
final String value = placeholders.getString(key);
|
||||
|
||||
event.format(event.format().replace("<" + key + ">", value));
|
||||
for (final Map.Entry<String, String> entry : carbonChat.carbonSettings().customPlaceholders().entrySet()) {
|
||||
event.format(event.format().replace("<" + entry.getKey() + ">", entry.getValue()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+4
-4
@@ -15,7 +15,7 @@ import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.cache.RemovalNotification;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.api.users.UserService;
|
||||
import net.draycia.carbon.common.utils.SQLCredentials;
|
||||
import net.draycia.carbon.api.config.SQLCredentials;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@@ -43,9 +43,9 @@ public class MySQLUserService<T extends ChatUser> implements UserService<T> {
|
||||
.removalListener(this::saveUser)
|
||||
.build(CacheLoader.from(this::loadUser));
|
||||
|
||||
public MySQLUserService(final @NonNull CarbonChat carbonChat, final @NonNull SQLCredentials credentials,
|
||||
final @NonNull Supplier<@NonNull Iterable<@NonNull T>> supplier,
|
||||
final @NonNull Class<? extends ChatUser> userType) {
|
||||
public MySQLUserService(final @NonNull Class<? extends ChatUser> userType,
|
||||
final @NonNull CarbonChat carbonChat, final @NonNull SQLCredentials credentials,
|
||||
final @NonNull Supplier<@NonNull Iterable<@NonNull T>> supplier) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.userType = userType;
|
||||
this.supplier = supplier;
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package net.draycia.carbon.common.utils;
|
||||
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class ColorUtils {
|
||||
|
||||
private ColorUtils() {
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static TextColor parseColor(@Nullable final String input) {
|
||||
return parseColor(null, input);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static TextColor parseColor(@Nullable final ChatUser user, @Nullable String input) {
|
||||
if (input == null) {
|
||||
input = "white";
|
||||
}
|
||||
|
||||
// TODO: find out way to do this
|
||||
|
||||
// if (user != null) {
|
||||
// final Player player = Bukkit.getPlayer(user.uuid());
|
||||
//
|
||||
// if (player != null) {
|
||||
// input = PlaceholderAPI.setPlaceholders(player, input);
|
||||
// }
|
||||
// }
|
||||
|
||||
for (final NamedTextColor namedColor : NamedTextColor.values()) {
|
||||
if (namedColor.toString().equalsIgnoreCase(input)) {
|
||||
return namedColor;
|
||||
}
|
||||
}
|
||||
|
||||
if (input.contains("&") || input.contains("§")) {
|
||||
input = input.replace("&", "§");
|
||||
|
||||
return LegacyComponentSerializer.legacySection().deserialize(input).color();
|
||||
}
|
||||
|
||||
return TextColor.fromCSSHexString(input);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user