Closer to compilation

This commit is contained in:
Draycia committed 2020-09-25 01:45:35 -07:00
1 parent 8db4b9532c
commit 18c6fd7e2b
19 files changed
+379 -318

No files matched your search

@@ -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;
@@ -1,497 +0,0 @@
package net.draycia.carbon.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.channels.ChatChannel;
import net.draycia.carbon.api.events.misc.CarbonEvents;
import net.draycia.carbon.api.events.ChatComponentEvent;
import net.draycia.carbon.api.events.ChatFormatEvent;
import net.draycia.carbon.api.events.MessageContextEvent;
import net.draycia.carbon.api.events.PreChatFormatEvent;
import net.draycia.carbon.api.events.ReceiverContextEvent;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.Context;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.luckperms.api.model.group.Group;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
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;
this.carbonChat = carbonChat;
this.settings = settings;
}
public @NonNull ChannelSettings settings() {
return this.settings;
}
@NonNull
public CarbonChat carbonChat() {
return this.carbonChat;
}
@Override
public boolean testContext(final @NonNull ChatUser sender, final @NonNull ChatUser target) {
final ReceiverContextEvent event = new ReceiverContextEvent(this, sender, target);
CarbonEvents.post(event);
return !event.cancelled();
}
@Override
public boolean canPlayerUse(final @NonNull ChatUser user) {
return user.permissible() && user.hasPermission("carbonchat.channels." + this.name() + ".use");
}
@Override
@NonNull
public List<@NonNull ChatUser> audiences() {
final List<ChatUser> audience = new ArrayList<>();
for (final ChatUser user : this.carbonChat.userService().onlineUsers()) {
if (this.canPlayerSee(user, true)) {
audience.add(user);
}
}
return audience;
}
// private void updateUserNickname(final @NonNull ChatUser user) {
// final Player player = Bukkit.getPlayer(user.uuid());
//
// if (player != null) {
// String nickname = user.nickname();
//
// if (nickname != null) {
// final Component component = this.carbonChat.messageProcessor().processMessage(nickname);
// nickname = CarbonChat.LEGACY.serialize(component);
//
// player.setDisplayName(nickname);
//
// if (this.carbonChat.getConfig().getBoolean("nicknames-set-tab-name")) {
// player.setPlayerListName(nickname);
// }
// }
// }
// }
@Override
@NonNull
public Component sendMessage(final @NonNull ChatUser user, final @NonNull Collection<@NonNull ChatUser> recipients, final @NonNull String message, final boolean fromRemote) {
//this.updateUserNickname(user);
final MessageContextEvent event = new MessageContextEvent(this, user);
CarbonEvents.post(event);
if (event.cancelled()) {
return TextComponent.empty();
}
// Get player's formatting
final String messageFormat = this.format(user);
// Call custom chat event
final PreChatFormatEvent preFormatEvent = new PreChatFormatEvent(user, this, messageFormat, message);
CarbonEvents.post(preFormatEvent);
// Return if cancelled or message is emptied
if (preFormatEvent.cancelled() || preFormatEvent.message().trim().isEmpty()) {
return TextComponent.empty();
}
final String displayName;
if (user.nickname() != null) {
displayName = user.nickname();
} else {
displayName = user.displayName();
}
// Iterate through players who should receive messages in this channel
for (final ChatUser target : recipients) {
// Call second format event. Used for relational stuff (placeholders etc)
final ChatFormatEvent formatEvent = new ChatFormatEvent(user, target, this, preFormatEvent.format(), preFormatEvent.message());
CarbonEvents.post(formatEvent);
// Again, return if cancelled or message is emptied
if (formatEvent.cancelled() || formatEvent.message().trim().isEmpty()) {
continue;
}
final TextColor targetColor = this.channelColor(target);
TextComponent formatComponent = (TextComponent) this.carbonChat.messageProcessor().processMessage(formatEvent.format(),
"br", "\n",
"displayname", displayName,
"color", "<" + targetColor.asHexString() + ">",
"phase", Long.toString(System.currentTimeMillis() % 25),
"server", this.carbonChat.getConfig().getString("server-name", "Server"),
"message", formatEvent.message());
if (this.isUserSpying(user, target)) {
final String prefix = this.carbonChat.getConfig().getString("spy-prefix");
formatComponent = (TextComponent) MiniMessage.get().parse(prefix, "color",
targetColor.asHexString()).append(formatComponent);
}
final ChatComponentEvent newEvent = new ChatComponentEvent(user, target, this, formatComponent,
formatEvent.message());
CarbonEvents.post(newEvent);
target.sendMessage(newEvent.component());
}
final ChatFormatEvent consoleFormatEvent = new ChatFormatEvent(user, null, this, preFormatEvent.format(),
preFormatEvent.message());
CarbonEvents.post(consoleFormatEvent);
final TextColor targetColor = this.channelColor(user);
final TextComponent consoleFormat = (TextComponent) this.carbonChat.messageProcessor().processMessage(consoleFormatEvent.format(),
"br", "\n",
"displayname", displayName,
"color", "<" + targetColor.asHexString() + ">",
"phase", Long.toString(System.currentTimeMillis() % 25),
"server", this.carbonChat.getConfig().getString("server-name", "Server"),
"message", consoleFormatEvent.message());
final ChatComponentEvent consoleEvent = new ChatComponentEvent(user, null, this, consoleFormat,
consoleFormatEvent.message());
CarbonEvents.post(consoleEvent);
if (user.online() && !fromRemote && this.crossServer()) {
this.sendMessageToBungee(user.uuid(), consoleEvent.component());
}
return consoleEvent.component();
}
@Override
@NonNull
public Component sendMessage(final @NonNull ChatUser user, final @NonNull String message, final boolean fromRemote) {
return this.sendMessage(user, this.audiences(), message, fromRemote);
}
@Nullable
public String format(final @NonNull ChatUser user) {
for (final String group : this.groupOverrides()) {
if (this.userHasGroup(user, group)) {
final String format = this.format(group);
if (format != null) {
return format;
}
}
}
if (this.primaryGroupOnly()) {
return this.primaryGroupFormat(user);
} else {
return this.firstFoundUserFormat(user);
}
}
private boolean userHasGroup(final @NonNull ChatUser user, final @NonNull String group) {
if (user.hasGroup(group)) {
return true;
}
if (this.permissionGroupMatching()) {
return user.hasPermission("carbonchat.group." + group);
}
return false;
}
@Nullable
private String firstFoundUserFormat(final @NonNull ChatUser user) {
for (final Group group : user.groups()) {
final String groupFormat = this.format(group);
if (groupFormat != null) {
return groupFormat;
}
}
return this.defaultFormat();
}
@Nullable
private String primaryGroupFormat(final @NonNull ChatUser user) {
final Group primaryGroup = user.primaryGroup();
final String primaryGroupFormat = this.format(primaryGroup);
if (primaryGroupFormat != null) {
return primaryGroupFormat;
}
return this.defaultFormat();
}
@Nullable
private String defaultFormat() {
return this.format(this.defaultFormatName());
}
@Override
@Nullable
public String format(final @NonNull Group group) {
return this.format(group.getName());
}
@Override
@Nullable
public String format(final @NonNull String group) {
return this.settings().formats().get("formats." + group);
}
private boolean isUserSpying(final @NonNull ChatUser sender, final @NonNull ChatUser target) {
if (!this.canPlayerSee(sender, target, false)) {
return target.channelSettings(this).spying();
}
return false;
}
@Override
public void sendComponent(final @NonNull ChatUser player, final @NonNull Component component) {
for (final ChatUser user : this.audiences()) {
if (!user.ignoringUser(player)) {
user.sendMessage(component);
}
}
}
public void sendMessageToBungee(final @NonNull UUID uuid, final @NonNull Component component) {
this.carbonChat.messageService().sendMessage("channel-component", uuid, byteArray -> {
byteArray.writeUTF(this.key());
byteArray.writeUTF(this.carbonChat.messageProcessor().audiences().gsonSerializer().serialize(component));
});
}
@Override
public boolean canPlayerSee(final @NonNull ChatUser target, final boolean checkSpying) {
if (checkSpying && target.permissible() && target.hasPermission("carbonchat.spy." + this.name())) {
if (target.channelSettings(this).spying()) {
return true;
}
}
if (!(target.permissible() && target.hasPermission("carbonchat.channels." + this.name() + ".see"))) {
return false;
}
if (this.ignorable()) {
return !target.channelSettings(this).ignored();
}
return true;
}
public boolean canPlayerSee(final @NonNull ChatUser sender, final @NonNull ChatUser target, final boolean checkSpying) {
if (!this.canPlayerSee(target, checkSpying)) {
return false;
}
if (this.ignorable()) {
return !target.ignoringUser(sender) || (target.permissible() && target.hasPermission("carbonchat.ignore.exempt"));
}
return true;
}
@Override
@Nullable
public TextColor channelColor(final @NonNull ChatUser user) {
final TextColor userColor = user.channelSettings(this).color();
if (userColor != null) {
return userColor;
}
final String input = this.settings().color();
final TextColor color = CarbonUtils.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");
return NamedTextColor.WHITE;
}
return color;
}
@Nullable
public String defaultFormatName() {
return this.settings().defaultFormatName();
}
@Override
public boolean isDefault() {
return this.settings().isDefault();
}
@Override
public boolean ignorable() {
return this.settings().ignorable();
}
@Override
public boolean crossServer() {
return this.settings().crossServer();
}
@Override
public boolean honorsRecipientList() {
return this.settings().honorsRecipientList();
}
@Override
public boolean permissionGroupMatching() {
return this.settings().permissionGroupMatching();
}
@Override
@NonNull
public List<@NonNull String> groupOverrides() {
return this.settings().groupOverrides();
}
@Override
@NonNull
public String name() {
return this.settings().name();
}
@Override
@Nullable
public String messagePrefix() {
return this.settings().messagePrefix();
}
@Override
@Nullable
public String switchMessage() {
return this.settings().switchMessage();
}
@Override
@Nullable
public String switchOtherMessage() {
return this.settings().switchOtherMessage();
}
@Override
@Nullable
public String switchFailureMessage() {
return this.settings().switchFailureMessage();
}
@Override
@Nullable
public String cannotIgnoreMessage() {
return this.settings().cannotIgnoreMessage();
}
@Override
@Nullable
public String toggleOffMessage() {
return this.settings().toggleOffMessage();
}
@Override
@Nullable
public String toggleOnMessage() {
return this.settings().toggleOnMessage();
}
@Override
@Nullable
public String toggleOtherOnMessage() {
return this.settings().toggleOtherOnMessage();
}
@Override
@Nullable
public String toggleOtherOffMessage() {
return this.settings().toggleOtherOffMessage();
}
@Override
@Nullable
public String cannotUseMessage() {
return this.settings().cannotUseMessage();
}
@Override
public boolean primaryGroupOnly() {
return this.settings().primaryGroupOnly();
}
@Override
public boolean shouldCancelChatEvent() {
return this.settings().shouldCancelChatEvent();
}
@Override
@NonNull
public List<@NonNull Pattern> itemLinkPatterns() {
return this.settings().itemLinkPatterns();
}
@Override
@Nullable
public String aliases() {
return this.settings().aliases();
}
@Override
@Nullable
public Context context(final @NonNull String key) {
return this.settings().contexts().get(key);
}
@Override
@NonNull
public String key() {
return this.key;
}
}
@@ -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,109 +0,0 @@
package net.draycia.carbon.managers;
import net.draycia.carbon.channels.CarbonChatChannel;
import net.draycia.carbon.CarbonChatBukkit;
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;
import java.util.Collections;
public class ChannelManager {
@NonNull
private final CarbonChatBukkit carbonChat;
@NonNull
private final ChannelRegistry registry;
@Nullable
@MonotonicNonNull
private String defaultChannelKey = null;
public ChannelManager(final @NonNull CarbonChatBukkit 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);
final String name = section.getString("name");
if (name != null && 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;
}
return channel;
}
public void registerChannel(final @NonNull ChatChannel channel) {
this.registry().register(channel.key(), channel);
if (channel.isDefault() && this.defaultChannelKey == null) {
this.carbonChat.logger().info("Default channel registered: " + channel.name());
this.defaultChannelKey = channel.key();
}
CarbonEvents.post(new ChannelRegisterEvent(Collections.singletonList(channel), this.registry()));
}
public @NonNull Registry<String, ChatChannel> registry() {
return this.registry;
}
public @Nullable ChatChannel defaultChannel() {
if (this.defaultChannelKey != null) {
return this.registry.get(this.defaultChannelKey);
}
return null;
}
public @Nullable ChatChannel channelOrDefault(@Nullable final String key) {
if (key == null) {
return this.defaultChannel();
}
final ChatChannel channel = this.registry.get(key);
if (channel == null) {
return this.defaultChannel();
}
return channel;
}
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);
if (channel != null) {
this.registerChannel(channel);
String prefix = channel.messagePrefix();
if (prefix != null && !prefix.trim().isEmpty()) {
prefix = "(" + prefix + ") ";
} else {
prefix = "";
}
this.carbonChat.logger().info("Registering channel: " + prefix + channel.name());
}
}
}
}
@@ -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,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,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);
}
}
}