Complete some TODOs

This commit is contained in:
Draycia committed 2020-10-15 02:14:52 -07:00
1 parent 548955134e
commit 4d547f80c7
27 files changed
+155 -67

No files matched your search

@@ -60,6 +60,10 @@ public class AdventureManager implements MessageProcessor {
return this.carbonChat.gsonSerializer().deserialize(input);
}
public FormatType formatType() {
return this.formatType;
}
@Override
public @NonNull AudienceProvider audiences() {
return this.provider;
@@ -182,7 +182,7 @@ public class CarbonChatChannel implements TextChannel {
"phase", Long.toString(System.currentTimeMillis() % 25),
"message", consoleFormatEvent.message());
// TODO: add ConsoleUser to users map
// TODO: add ConsoleUser to users map. Requires "users" to be CarbonUser and not PlayerUser.
final ChatComponentEvent consoleEvent = new ChatComponentEvent(user, null, this, consoleFormat,
consoleFormatEvent.message());
@@ -7,6 +7,7 @@ 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.draycia.carbon.common.commands.AliasedChannelCommand;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -96,11 +97,11 @@ public class ChannelManager {
if (channel != null) {
this.registerChannel(channel);
// TODO: register AliasedChannelCommand for each channel
String prefix = null;
if (channel instanceof TextChannel) {
prefix = ((TextChannel) channel).messagePrefix();
new AliasedChannelCommand(this.carbonChat.commandManager(), (TextChannel) channel);
}
if (prefix != null && !prefix.trim().isEmpty()) {
@@ -108,7 +109,6 @@ public class ChannelManager {
} else {
prefix = "";
}
this.carbonChat.logger().info("Registering channel: " + prefix + channel.name());
}
}
@@ -37,7 +37,6 @@ public class ChannelListCommand {
commandManager.createDefaultCommandMeta())
.senderType(CarbonUser.class) // console & player
.permission("carbonchat.channellist")
// TODO: make this return a PlayerUser
.argument(PlayerUserArgument.optionalPlayerUserArgument()) // carbonchat.channellist.other
.handler(context -> {
if (context.getOptional("user").isPresent()) {
@@ -114,7 +113,6 @@ public class ChannelListCommand {
private void makeList(@NonNull final Iterator<@NonNull ChatChannel> iterator, final TextComponent.@NonNull Builder list) {
final String listSeparator = this.carbonChat.translations().channelListSeparator();
// TODO: Larry, why did you double assign the listSeparatorComponent?
final Component listSeparatorComponent = Component.text(listSeparator);
while (iterator.hasNext()) {
@@ -6,6 +6,7 @@ import cloud.commandframework.context.CommandContext;
import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.channels.TextChannel;
import net.draycia.carbon.api.config.ExceptionMessages;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.List;
@@ -16,7 +17,7 @@ public final class ChannelArgument<C> extends CommandArgument<C, TextChannel> {
private ChannelArgument(final boolean required) {
super(required, "channel", ChannelArgument::parser,
CarbonChatProvider.carbonChat().channelRegistry().defaultChannel().key(),
CarbonChatProvider.carbonChat().channelRegistry().defaultValue().key(),
TextChannel.class, ChannelArgument::suggestions);
}
@@ -24,9 +25,10 @@ public final class ChannelArgument<C> extends CommandArgument<C, TextChannel> {
final @NonNull Queue<String> inputs) {
final String input = inputs.poll();
final ExceptionMessages exceptions = CarbonChatProvider.carbonChat().translations().exceptionMessages();
if (input == null) {
// TODO: make exception messages configurable
return ArgumentParseResult.failure(new IllegalArgumentException("Channel cannot be null"));
return ArgumentParseResult.failure(new IllegalArgumentException(exceptions.channelNotFound()));
}
final ChatChannel channel = CarbonChatProvider.carbonChat()
@@ -35,9 +37,9 @@ public final class ChannelArgument<C> extends CommandArgument<C, TextChannel> {
if (channel instanceof TextChannel) {
return ArgumentParseResult.success((TextChannel) channel);
} else if (channel != null) {
return ArgumentParseResult.failure(new IllegalArgumentException("Channel is not public!"));
return ArgumentParseResult.failure(new IllegalArgumentException(exceptions.channelNotPublic()));
} else {
return ArgumentParseResult.failure(new IllegalArgumentException("Channel does not exist"));
return ArgumentParseResult.failure(new IllegalArgumentException(exceptions.channelNotFound()));
}
}
@@ -25,21 +25,23 @@ public final class PlayerUserArgument<C> extends CommandArgument<C, PlayerUser>
final @NonNull Queue<String> inputs) {
final String input = inputs.poll();
final String playerNotFound = CarbonChatProvider.carbonChat().translations().exceptionMessages()
.playerNotFound();
if (input == null) {
// TODO: make exception messages configurable
return ArgumentParseResult.failure(new IllegalArgumentException("Player not found!"));
return ArgumentParseResult.failure(new IllegalArgumentException(playerNotFound));
}
final UUID uuid = CarbonChatProvider.carbonChat().userService().resolve(input);
if (uuid == null) {
return ArgumentParseResult.failure(new IllegalArgumentException("Player not found!"));
return ArgumentParseResult.failure(new IllegalArgumentException(playerNotFound));
}
final PlayerUser user = CarbonChatProvider.carbonChat().userService().wrap(uuid);
if (user == null) {
return ArgumentParseResult.failure(new IllegalArgumentException("Player not found!"));
return ArgumentParseResult.failure(new IllegalArgumentException(playerNotFound));
}
return ArgumentParseResult.success(user);
@@ -28,7 +28,7 @@ public class PlayerJoinListener {
}
if (channel.equals("DEFAULT")) {
user.selectedChannel(carbonChat.channelRegistry().defaultChannel());
user.selectedChannel(carbonChat.channelRegistry().defaultValue());
return;
}
@@ -1,6 +1,10 @@
package net.draycia.carbon.common.utils;
import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.adventure.MessageProcessor;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.common.adventure.AdventureManager;
import net.draycia.carbon.common.adventure.FormatType;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.TextDecoration;
@@ -27,6 +31,7 @@ public final class ColorUtils {
}
// TODO: find out way to do this
// TODO: add parsePlaceholders() to PlayerUser class
// if (user != null) {
// final Player player = Bukkit.getPlayer(user.uuid());
@@ -62,26 +67,40 @@ public final class ColorUtils {
// TODO: check if MiniMessage or MineDown
String output = input;
// Legacy RGB
output = spigotLegacyRGB.matcher(output).replaceAll("<#$1$2$3$4$5$6>");
String hexReplacement = "<#$1$2$3$4$5$6>";
boolean legacyCapable = false;
// Alternate RGB, TAB (neznamy) && KiteBoard
output = pluginRGB.matcher(output).replaceAll("<#$1$2$3$4$5$6>");
final MessageProcessor messageProcessor = CarbonChatProvider.carbonChat().messageProcessor();
// Legacy Colors
for (final char c : "0123456789abcdef".toCharArray()) {
final LegacyFormat format = LegacyComponentSerializer.parseChar(c);
final TextColor color = format.color();
output = output.replaceAll("[§&]" + c, "<" + color.asHexString() + ">");
if (messageProcessor instanceof AdventureManager) {
if (((AdventureManager) messageProcessor).formatType() == FormatType.MINEDOWN) {
hexReplacement = "&#$1$2$3$4$5$6&";
legacyCapable = true;
}
}
// Legacy Formatting
for (final char c : "klmno".toCharArray()) {
final LegacyFormat format = LegacyComponentSerializer.parseChar(c);
final TextDecoration decoration = format.decoration();
// Legacy RGB
output = spigotLegacyRGB.matcher(output).replaceAll(hexReplacement);
output = output.replaceAll("[§&]" + c, "<" + decoration.name() + ">");
// Alternate RGB, TAB (neznamy) && KiteBoard
output = pluginRGB.matcher(output).replaceAll(hexReplacement);
if (!legacyCapable) {
// Legacy Colors
for (final char c : "0123456789abcdef".toCharArray()) {
final LegacyFormat format = LegacyComponentSerializer.parseChar(c);
final TextColor color = format.color();
output = output.replaceAll("[§&]" + c, "<" + color.asHexString() + ">");
}
// Legacy Formatting
for (final char c : "klmno".toCharArray()) {
final LegacyFormat format = LegacyComponentSerializer.parseChar(c);
final TextDecoration decoration = format.decoration();
output = output.replaceAll("[§&]" + c, "<" + decoration.name() + ">");
}
}
return output;