mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 14:38:51 +00:00
Complete some TODOs
This commit is contained in:
1 parent
548955134e
commit
4d547f80c7
27 files changed
+155
-67
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
package net.draycia.carbon.api;
|
package net.draycia.carbon.api;
|
||||||
|
|
||||||
|
import cloud.commandframework.CommandManager;
|
||||||
import net.draycia.carbon.api.config.CarbonTranslations;
|
import net.draycia.carbon.api.config.CarbonTranslations;
|
||||||
import net.draycia.carbon.api.adventure.MessageProcessor;
|
import net.draycia.carbon.api.adventure.MessageProcessor;
|
||||||
import net.draycia.carbon.api.channels.ChannelRegistry;
|
import net.draycia.carbon.api.channels.ChannelRegistry;
|
||||||
@@ -8,6 +9,7 @@ import net.draycia.carbon.api.config.CarbonSettings;
|
|||||||
import net.draycia.carbon.api.config.ChannelSettings;
|
import net.draycia.carbon.api.config.ChannelSettings;
|
||||||
import net.draycia.carbon.api.config.ModerationSettings;
|
import net.draycia.carbon.api.config.ModerationSettings;
|
||||||
import net.draycia.carbon.api.messaging.MessageService;
|
import net.draycia.carbon.api.messaging.MessageService;
|
||||||
|
import net.draycia.carbon.api.users.CarbonUser;
|
||||||
import net.draycia.carbon.api.users.PlayerUser;
|
import net.draycia.carbon.api.users.PlayerUser;
|
||||||
import net.draycia.carbon.api.users.UserService;
|
import net.draycia.carbon.api.users.UserService;
|
||||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
@@ -53,4 +55,6 @@ public interface CarbonChat {
|
|||||||
|
|
||||||
@NonNull GsonComponentSerializer gsonSerializer();
|
@NonNull GsonComponentSerializer gsonSerializer();
|
||||||
|
|
||||||
|
@NonNull CommandManager<CarbonUser> commandManager();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package net.draycia.carbon.api;
|
||||||
|
|
||||||
|
import net.kyori.registry.DefaultedRegistryGetter;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An extension of the DefaultedRegistryGetter that declares a defaultValue method
|
||||||
|
* @param <K>
|
||||||
|
* @param <V>
|
||||||
|
*/
|
||||||
|
public interface DefaultedKeyValueRegistry<K,V> extends DefaultedRegistryGetter<K, V> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the default value.
|
||||||
|
*
|
||||||
|
* @return the default value
|
||||||
|
*/
|
||||||
|
@NonNull V defaultValue();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package net.draycia.carbon.api.channels;
|
package net.draycia.carbon.api.channels;
|
||||||
|
|
||||||
import net.kyori.registry.DefaultedRegistry;
|
import net.draycia.carbon.api.DefaultedKeyValueRegistry;
|
||||||
import net.kyori.registry.Registry;
|
import net.kyori.registry.Registry;
|
||||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
@@ -11,7 +11,7 @@ import java.util.Iterator;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class ChannelRegistry implements Registry<String, ChatChannel>, DefaultedRegistry<String, ChatChannel> {
|
public class ChannelRegistry implements Registry<String, ChatChannel>, DefaultedKeyValueRegistry<String, ChatChannel> {
|
||||||
|
|
||||||
private @NonNull final Map<@NonNull String, @NonNull ChatChannel> registry = new HashMap<>();
|
private @NonNull final Map<@NonNull String, @NonNull ChatChannel> registry = new HashMap<>();
|
||||||
|
|
||||||
@@ -37,6 +37,12 @@ public class ChannelRegistry implements Registry<String, ChatChannel>, Defaulted
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable String key(@NonNull final ChatChannel value) {
|
public @Nullable String key(@NonNull final ChatChannel value) {
|
||||||
|
for (final Map.Entry<String, ChatChannel> entry : this.registry.entrySet()) {
|
||||||
|
if (entry.getValue().equals(value)) {
|
||||||
|
return entry.getKey();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,17 +56,18 @@ public class ChannelRegistry implements Registry<String, ChatChannel>, Defaulted
|
|||||||
return this.registry.values().iterator();
|
return this.registry.values().iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public @MonotonicNonNull ChatChannel defaultChannel() {
|
|
||||||
return this.defaultChannel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull String defaultKey() {
|
public @NonNull String defaultKey() {
|
||||||
return this.defaultChannel.key();
|
return this.defaultChannel.key();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull ChatChannel defaultValue() {
|
||||||
|
return this.defaultChannel;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull ChatChannel getOrDefault(@NonNull final String key) {
|
public @NonNull ChatChannel getOrDefault(@NonNull final String key) {
|
||||||
return this.registry.getOrDefault(key, this.defaultChannel());
|
return this.registry.getOrDefault(key, this.defaultValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,6 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
// TODO: rename this to something that's less... weird?
|
|
||||||
public interface TextChannel extends ChatChannel, ForwardingAudience {
|
public interface TextChannel extends ChatChannel, ForwardingAudience {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import java.util.Map;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ConfigSerializable
|
@ConfigSerializable
|
||||||
public class CarbonSettings {
|
public final class CarbonSettings {
|
||||||
|
|
||||||
private static final ObjectMapper<CarbonSettings> MAPPER;
|
private static final ObjectMapper<CarbonSettings> MAPPER;
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import org.spongepowered.configurate.objectmapping.ObjectMappingException;
|
|||||||
import org.spongepowered.configurate.objectmapping.meta.Setting;
|
import org.spongepowered.configurate.objectmapping.meta.Setting;
|
||||||
|
|
||||||
@ConfigSerializable
|
@ConfigSerializable
|
||||||
public class CarbonTranslations {
|
public final class CarbonTranslations {
|
||||||
|
|
||||||
private static final ObjectMapper<CarbonTranslations> MAPPER;
|
private static final ObjectMapper<CarbonTranslations> MAPPER;
|
||||||
|
|
||||||
@@ -27,8 +27,9 @@ public class CarbonTranslations {
|
|||||||
MAPPER.save(this, node);
|
MAPPER.save(this, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Setting
|
private ExceptionMessages exceptionMessages = new ExceptionMessages();
|
||||||
private String reloaded = "<yellow>Chat config has been reloaded!";
|
|
||||||
|
@Setting private String reloaded = "<yellow>Chat config has been reloaded!";
|
||||||
@Setting private String otherPlayerOffline = "<red>That player is offline!";
|
@Setting private String otherPlayerOffline = "<red>That player is offline!";
|
||||||
@Setting private String spyWhispers = "<yellow>Spy [<gray><sender><reset> <gold>-> <gray><target><reset><yellow>] <message>";
|
@Setting private String spyWhispers = "<yellow>Spy [<gray><sender><reset> <gold>-> <gray><target><reset><yellow>] <message>";
|
||||||
@Setting private String noReplyTarget = "<red>You have no one to reply to!";
|
@Setting private String noReplyTarget = "<red>You have no one to reply to!";
|
||||||
@@ -64,6 +65,10 @@ public class CarbonTranslations {
|
|||||||
@Setting private String clearExempt = "<yellow>You were exempt from the clear due to your permissions!";
|
@Setting private String clearExempt = "<yellow>You were exempt from the clear due to your permissions!";
|
||||||
@Setting private String cannotWhisperSelf = "<yellow>You cannot whisper yourself!";
|
@Setting private String cannotWhisperSelf = "<yellow>You cannot whisper yourself!";
|
||||||
|
|
||||||
|
public ExceptionMessages exceptionMessages() {
|
||||||
|
return this.exceptionMessages;
|
||||||
|
}
|
||||||
|
|
||||||
public String reloaded() {
|
public String reloaded() {
|
||||||
return this.reloaded;
|
return this.reloaded;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ConfigSerializable
|
@ConfigSerializable
|
||||||
public class ChannelOptions {
|
public final class ChannelOptions {
|
||||||
|
|
||||||
@Setting
|
@Setting
|
||||||
@Comment("What this channel is identified as. This will be what's typed ingame to use the channel.")
|
@Comment("What this channel is identified as. This will be what's typed ingame to use the channel.")
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import java.util.Collections;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ConfigSerializable
|
@ConfigSerializable
|
||||||
public class ChannelSettings {
|
public final class ChannelSettings {
|
||||||
|
|
||||||
private static final ObjectMapper<ChannelSettings> MAPPER;
|
private static final ObjectMapper<ChannelSettings> MAPPER;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package net.draycia.carbon.api.config;
|
||||||
|
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||||
|
import org.spongepowered.configurate.objectmapping.meta.Setting;
|
||||||
|
|
||||||
|
@ConfigSerializable
|
||||||
|
public final class ExceptionMessages {
|
||||||
|
|
||||||
|
@Setting private @NonNull String channelNotFound = "Channel not found!";
|
||||||
|
@Setting private @NonNull String channelNotPublic = "Channel is not public!";
|
||||||
|
@Setting private @NonNull String playerNotFound = "Player not found!";
|
||||||
|
|
||||||
|
public String channelNotFound() {
|
||||||
|
return this.channelNotFound;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String channelNotPublic() {
|
||||||
|
return this.channelNotPublic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String playerNotFound() {
|
||||||
|
return this.playerNotFound;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@ import java.util.Map;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ConfigSerializable
|
@ConfigSerializable
|
||||||
public class ModerationSettings {
|
public final class ModerationSettings {
|
||||||
|
|
||||||
private static final ObjectMapper<ModerationSettings> MAPPER;
|
private static final ObjectMapper<ModerationSettings> MAPPER;
|
||||||
|
|
||||||
@@ -34,8 +34,8 @@ public class ModerationSettings {
|
|||||||
MAPPER.save(this, node);
|
MAPPER.save(this, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: comment this
|
|
||||||
@Setting
|
@Setting
|
||||||
|
@Comment("The text that's prepended to someone else's shadowmuted messages.")
|
||||||
private String shadowMutePrefix = "[SM] ";
|
private String shadowMutePrefix = "[SM] ";
|
||||||
|
|
||||||
public String shadowMutePrefix() {
|
public String shadowMutePrefix() {
|
||||||
@@ -86,19 +86,19 @@ public class ModerationSettings {
|
|||||||
@ConfigSerializable
|
@ConfigSerializable
|
||||||
public static class CapsProtection {
|
public static class CapsProtection {
|
||||||
@Setting
|
@Setting
|
||||||
@Comment("If caps protection is enabled")
|
@Comment("If caps protection is enabled")
|
||||||
private boolean enabled = true;
|
private boolean enabled = true;
|
||||||
|
|
||||||
@Setting
|
@Setting
|
||||||
@Comment("The minimum message length for caps protection to activate")
|
@Comment("The minimum message length for caps protection to activate")
|
||||||
private int minimumLength = 10;
|
private int minimumLength = 10;
|
||||||
|
|
||||||
@Setting
|
@Setting
|
||||||
@Comment("The amount of letters in the message for it to trigger the protection")
|
@Comment("The amount of letters in the message for it to trigger the protection")
|
||||||
private float percentCaps = 0.80F;
|
private float percentCaps = 0.80F;
|
||||||
|
|
||||||
@Setting
|
@Setting
|
||||||
@Comment("If true, stops message from sending. If false, simply changes the message to lowercase")
|
@Comment("If true, stops message from sending. If false, simply changes the message to lowercase")
|
||||||
private boolean blockMessage = false;
|
private boolean blockMessage = false;
|
||||||
|
|
||||||
public boolean enabled() {
|
public boolean enabled() {
|
||||||
@@ -127,12 +127,11 @@ public class ModerationSettings {
|
|||||||
|
|
||||||
@ConfigSerializable
|
@ConfigSerializable
|
||||||
public static class Filters {
|
public static class Filters {
|
||||||
|
|
||||||
@Setting
|
@Setting
|
||||||
private boolean enabled = true;
|
private boolean enabled = true;
|
||||||
|
|
||||||
@Setting
|
@Setting
|
||||||
@Comment("The keys (\"****\" for example) are what the text is replaced with.\n" +
|
@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" +
|
"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 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).")
|
"Set the key to \"_\" for the replacement to be blank (remove the filtered pattern).")
|
||||||
@@ -143,7 +142,7 @@ public class ModerationSettings {
|
|||||||
};
|
};
|
||||||
|
|
||||||
@Setting
|
@Setting
|
||||||
@Comment("Anything in blocked-words will prevent the message from being sent at all.\n" +
|
@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.")
|
"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"));
|
private List<Pattern> blockedPatterns = Collections.singletonList(Pattern.compile("pineapple doesn't belong on pizza"));
|
||||||
|
|
||||||
@@ -158,7 +157,6 @@ public class ModerationSettings {
|
|||||||
public List<Pattern> blockedPatterns() {
|
public List<Pattern> blockedPatterns() {
|
||||||
return this.blockedPatterns;
|
return this.blockedPatterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@ import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
|||||||
import org.spongepowered.configurate.objectmapping.meta.Setting;
|
import org.spongepowered.configurate.objectmapping.meta.Setting;
|
||||||
|
|
||||||
@ConfigSerializable
|
@ConfigSerializable
|
||||||
public class RedisCredentials {
|
public final class RedisCredentials {
|
||||||
|
|
||||||
@Setting private @NonNull String host = "localhost";
|
@Setting private @NonNull String host = "localhost";
|
||||||
@Setting private @Nullable String password = "";
|
@Setting private @Nullable String password = "";
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
|||||||
import org.spongepowered.configurate.objectmapping.meta.Setting;
|
import org.spongepowered.configurate.objectmapping.meta.Setting;
|
||||||
|
|
||||||
@ConfigSerializable
|
@ConfigSerializable
|
||||||
public class SQLCredentials {
|
public final class SQLCredentials {
|
||||||
|
|
||||||
@Setting private @NonNull String username = "username";
|
@Setting private @NonNull String username = "username";
|
||||||
@Setting private @NonNull String password = "password";
|
@Setting private @NonNull String password = "password";
|
||||||
|
|||||||
+1
-1
@@ -12,7 +12,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ConfigSerializable
|
@ConfigSerializable
|
||||||
public class SharedChannelOptions {
|
public final class SharedChannelOptions {
|
||||||
|
|
||||||
@Setting private String color = "#FFFFFF";
|
@Setting private String color = "#FFFFFF";
|
||||||
@Setting private Map<String, Context> contexts = new HashMap<>(); // TODO: set defaults
|
@Setting private Map<String, Context> contexts = new HashMap<>(); // TODO: set defaults
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import org.spongepowered.configurate.objectmapping.meta.Comment;
|
|||||||
import org.spongepowered.configurate.objectmapping.meta.Setting;
|
import org.spongepowered.configurate.objectmapping.meta.Setting;
|
||||||
|
|
||||||
@ConfigSerializable
|
@ConfigSerializable
|
||||||
public class WhisperOptions {
|
public final class WhisperOptions {
|
||||||
|
|
||||||
@Setting
|
@Setting
|
||||||
@Comment("Plays a sound when receiving private messages with /whisper /msg")
|
@Comment("Plays a sound when receiving private messages with /whisper /msg")
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package net.draycia.carbon;
|
package net.draycia.carbon;
|
||||||
|
|
||||||
|
import cloud.commandframework.CommandManager;
|
||||||
import cloud.commandframework.execution.CommandExecutionCoordinator;
|
import cloud.commandframework.execution.CommandExecutionCoordinator;
|
||||||
import cloud.commandframework.paper.PaperCommandManager;
|
import cloud.commandframework.paper.PaperCommandManager;
|
||||||
import net.draycia.carbon.api.CarbonChat;
|
import net.draycia.carbon.api.CarbonChat;
|
||||||
@@ -91,16 +92,14 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
|||||||
|
|
||||||
private ChannelManager channelManager;
|
private ChannelManager channelManager;
|
||||||
private AdventureManager messageProcessor;
|
private AdventureManager messageProcessor;
|
||||||
|
|
||||||
private CommandSettingsRegistry commandSettings;
|
private CommandSettingsRegistry commandSettings;
|
||||||
private ModerationSettings moderationSettings;
|
private ModerationSettings moderationSettings;
|
||||||
private CarbonSettings carbonSettings;
|
private CarbonSettings carbonSettings;
|
||||||
private ChannelSettings channelSettings;
|
private ChannelSettings channelSettings;
|
||||||
|
|
||||||
private UserService<BukkitPlayerUser> userService;
|
private UserService<BukkitPlayerUser> userService;
|
||||||
private MessageManager messageManager;
|
private MessageManager messageManager;
|
||||||
|
|
||||||
private CarbonTranslations translations;
|
private CarbonTranslations translations;
|
||||||
|
private CommandManager<CarbonUser> commandManager;
|
||||||
|
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
|
|
||||||
@@ -393,6 +392,11 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
|||||||
return this.commandSettings;
|
return this.commandSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull CommandManager<CarbonUser> commandManager() {
|
||||||
|
return this.commandManager;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull MessageProcessor messageProcessor() {
|
public @NonNull MessageProcessor messageProcessor() {
|
||||||
return this.messageProcessor;
|
return this.messageProcessor;
|
||||||
|
|||||||
+2
-2
@@ -31,7 +31,7 @@ public class PAPIContext {
|
|||||||
final String[] pieces = context.asString().split("=");
|
final String[] pieces = context.asString().split("=");
|
||||||
|
|
||||||
if (pieces.length != 2) {
|
if (pieces.length != 2) {
|
||||||
return; // TODO: maybe alert of misconfiguration?
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Player receiver = Bukkit.getPlayer(event.recipient().uuid());
|
final Player receiver = Bukkit.getPlayer(event.recipient().uuid());
|
||||||
@@ -59,7 +59,7 @@ public class PAPIContext {
|
|||||||
final String[] pieces = context.asString().split("=");
|
final String[] pieces = context.asString().split("=");
|
||||||
|
|
||||||
if (pieces.length != 2) {
|
if (pieces.length != 2) {
|
||||||
return; // TODO: maybe alert of misconfiguration?
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Player receiver = Bukkit.getPlayer(event.user().uuid());
|
final Player receiver = Bukkit.getPlayer(event.user().uuid());
|
||||||
|
|||||||
+2
-2
@@ -38,11 +38,11 @@ public class BukkitChatListener implements Listener {
|
|||||||
ChatChannel channel = user.selectedChannel();
|
ChatChannel channel = user.selectedChannel();
|
||||||
|
|
||||||
if (channel == null) {
|
if (channel == null) {
|
||||||
if (this.carbonChat.channelRegistry().defaultChannel() == null) {
|
if (this.carbonChat.channelRegistry().defaultValue() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
channel = this.carbonChat.channelRegistry().defaultChannel();
|
channel = this.carbonChat.channelRegistry().defaultValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (channel.shouldCancelChatEvent()) {
|
// if (channel.shouldCancelChatEvent()) {
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearSelectedChannel() {
|
public void clearSelectedChannel() {
|
||||||
this.selectedChannel(this.carbonChat.channelRegistry().defaultChannel());
|
this.selectedChannel(this.carbonChat.channelRegistry().defaultValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ public class CarbonPlaceholders extends PlaceholderExpansion {
|
|||||||
} else if (key.startsWith("selected_channel")) {
|
} else if (key.startsWith("selected_channel")) {
|
||||||
final ChatChannel channel = this.carbonChat.userService().wrap(player.getUniqueId()).selectedChannel();
|
final ChatChannel channel = this.carbonChat.userService().wrap(player.getUniqueId()).selectedChannel();
|
||||||
|
|
||||||
return channel == null ? this.carbonChat.channelRegistry().defaultChannel().name() : channel.name();
|
return channel == null ? this.carbonChat.channelRegistry().defaultValue().name() : channel.name();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
+4
@@ -60,6 +60,10 @@ public class AdventureManager implements MessageProcessor {
|
|||||||
return this.carbonChat.gsonSerializer().deserialize(input);
|
return this.carbonChat.gsonSerializer().deserialize(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FormatType formatType() {
|
||||||
|
return this.formatType;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull AudienceProvider audiences() {
|
public @NonNull AudienceProvider audiences() {
|
||||||
return this.provider;
|
return this.provider;
|
||||||
|
|||||||
+1
-1
@@ -182,7 +182,7 @@ public class CarbonChatChannel implements TextChannel {
|
|||||||
"phase", Long.toString(System.currentTimeMillis() % 25),
|
"phase", Long.toString(System.currentTimeMillis() % 25),
|
||||||
"message", consoleFormatEvent.message());
|
"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,
|
final ChatComponentEvent consoleEvent = new ChatComponentEvent(user, null, this, consoleFormat,
|
||||||
consoleFormatEvent.message());
|
consoleFormatEvent.message());
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -7,6 +7,7 @@ import net.draycia.carbon.api.channels.ChannelRegistry;
|
|||||||
import net.draycia.carbon.api.channels.ChatChannel;
|
import net.draycia.carbon.api.channels.ChatChannel;
|
||||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||||
import net.draycia.carbon.api.events.ChannelRegisterEvent;
|
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.MonotonicNonNull;
|
||||||
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;
|
||||||
@@ -96,11 +97,11 @@ public class ChannelManager {
|
|||||||
|
|
||||||
if (channel != null) {
|
if (channel != null) {
|
||||||
this.registerChannel(channel);
|
this.registerChannel(channel);
|
||||||
// TODO: register AliasedChannelCommand for each channel
|
|
||||||
String prefix = null;
|
String prefix = null;
|
||||||
|
|
||||||
if (channel instanceof TextChannel) {
|
if (channel instanceof TextChannel) {
|
||||||
prefix = ((TextChannel) channel).messagePrefix();
|
prefix = ((TextChannel) channel).messagePrefix();
|
||||||
|
new AliasedChannelCommand(this.carbonChat.commandManager(), (TextChannel) channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prefix != null && !prefix.trim().isEmpty()) {
|
if (prefix != null && !prefix.trim().isEmpty()) {
|
||||||
@@ -108,7 +109,6 @@ public class ChannelManager {
|
|||||||
} else {
|
} else {
|
||||||
prefix = "";
|
prefix = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
this.carbonChat.logger().info("Registering channel: " + prefix + channel.name());
|
this.carbonChat.logger().info("Registering channel: " + prefix + channel.name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-2
@@ -37,7 +37,6 @@ public class ChannelListCommand {
|
|||||||
commandManager.createDefaultCommandMeta())
|
commandManager.createDefaultCommandMeta())
|
||||||
.senderType(CarbonUser.class) // console & player
|
.senderType(CarbonUser.class) // console & player
|
||||||
.permission("carbonchat.channellist")
|
.permission("carbonchat.channellist")
|
||||||
// TODO: make this return a PlayerUser
|
|
||||||
.argument(PlayerUserArgument.optionalPlayerUserArgument()) // carbonchat.channellist.other
|
.argument(PlayerUserArgument.optionalPlayerUserArgument()) // carbonchat.channellist.other
|
||||||
.handler(context -> {
|
.handler(context -> {
|
||||||
if (context.getOptional("user").isPresent()) {
|
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) {
|
private void makeList(@NonNull final Iterator<@NonNull ChatChannel> iterator, final TextComponent.@NonNull Builder list) {
|
||||||
final String listSeparator = this.carbonChat.translations().channelListSeparator();
|
final String listSeparator = this.carbonChat.translations().channelListSeparator();
|
||||||
// TODO: Larry, why did you double assign the listSeparatorComponent?
|
|
||||||
final Component listSeparatorComponent = Component.text(listSeparator);
|
final Component listSeparatorComponent = Component.text(listSeparator);
|
||||||
|
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
|
|||||||
+7
-5
@@ -6,6 +6,7 @@ import cloud.commandframework.context.CommandContext;
|
|||||||
import net.draycia.carbon.api.CarbonChatProvider;
|
import net.draycia.carbon.api.CarbonChatProvider;
|
||||||
import net.draycia.carbon.api.channels.ChatChannel;
|
import net.draycia.carbon.api.channels.ChatChannel;
|
||||||
import net.draycia.carbon.api.channels.TextChannel;
|
import net.draycia.carbon.api.channels.TextChannel;
|
||||||
|
import net.draycia.carbon.api.config.ExceptionMessages;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -16,7 +17,7 @@ public final class ChannelArgument<C> extends CommandArgument<C, TextChannel> {
|
|||||||
|
|
||||||
private ChannelArgument(final boolean required) {
|
private ChannelArgument(final boolean required) {
|
||||||
super(required, "channel", ChannelArgument::parser,
|
super(required, "channel", ChannelArgument::parser,
|
||||||
CarbonChatProvider.carbonChat().channelRegistry().defaultChannel().key(),
|
CarbonChatProvider.carbonChat().channelRegistry().defaultValue().key(),
|
||||||
TextChannel.class, ChannelArgument::suggestions);
|
TextChannel.class, ChannelArgument::suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,9 +25,10 @@ public final class ChannelArgument<C> extends CommandArgument<C, TextChannel> {
|
|||||||
final @NonNull Queue<String> inputs) {
|
final @NonNull Queue<String> inputs) {
|
||||||
final String input = inputs.poll();
|
final String input = inputs.poll();
|
||||||
|
|
||||||
|
final ExceptionMessages exceptions = CarbonChatProvider.carbonChat().translations().exceptionMessages();
|
||||||
|
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
// TODO: make exception messages configurable
|
return ArgumentParseResult.failure(new IllegalArgumentException(exceptions.channelNotFound()));
|
||||||
return ArgumentParseResult.failure(new IllegalArgumentException("Channel cannot be null"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final ChatChannel channel = CarbonChatProvider.carbonChat()
|
final ChatChannel channel = CarbonChatProvider.carbonChat()
|
||||||
@@ -35,9 +37,9 @@ public final class ChannelArgument<C> extends CommandArgument<C, TextChannel> {
|
|||||||
if (channel instanceof TextChannel) {
|
if (channel instanceof TextChannel) {
|
||||||
return ArgumentParseResult.success((TextChannel) channel);
|
return ArgumentParseResult.success((TextChannel) channel);
|
||||||
} else if (channel != null) {
|
} else if (channel != null) {
|
||||||
return ArgumentParseResult.failure(new IllegalArgumentException("Channel is not public!"));
|
return ArgumentParseResult.failure(new IllegalArgumentException(exceptions.channelNotPublic()));
|
||||||
} else {
|
} else {
|
||||||
return ArgumentParseResult.failure(new IllegalArgumentException("Channel does not exist"));
|
return ArgumentParseResult.failure(new IllegalArgumentException(exceptions.channelNotFound()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-4
@@ -25,21 +25,23 @@ public final class PlayerUserArgument<C> extends CommandArgument<C, PlayerUser>
|
|||||||
final @NonNull Queue<String> inputs) {
|
final @NonNull Queue<String> inputs) {
|
||||||
final String input = inputs.poll();
|
final String input = inputs.poll();
|
||||||
|
|
||||||
|
final String playerNotFound = CarbonChatProvider.carbonChat().translations().exceptionMessages()
|
||||||
|
.playerNotFound();
|
||||||
|
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
// TODO: make exception messages configurable
|
return ArgumentParseResult.failure(new IllegalArgumentException(playerNotFound));
|
||||||
return ArgumentParseResult.failure(new IllegalArgumentException("Player not found!"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final UUID uuid = CarbonChatProvider.carbonChat().userService().resolve(input);
|
final UUID uuid = CarbonChatProvider.carbonChat().userService().resolve(input);
|
||||||
|
|
||||||
if (uuid == null) {
|
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);
|
final PlayerUser user = CarbonChatProvider.carbonChat().userService().wrap(uuid);
|
||||||
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return ArgumentParseResult.failure(new IllegalArgumentException("Player not found!"));
|
return ArgumentParseResult.failure(new IllegalArgumentException(playerNotFound));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ArgumentParseResult.success(user);
|
return ArgumentParseResult.success(user);
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ public class PlayerJoinListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (channel.equals("DEFAULT")) {
|
if (channel.equals("DEFAULT")) {
|
||||||
user.selectedChannel(carbonChat.channelRegistry().defaultChannel());
|
user.selectedChannel(carbonChat.channelRegistry().defaultValue());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package net.draycia.carbon.common.utils;
|
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.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.NamedTextColor;
|
||||||
import net.kyori.adventure.text.format.TextColor;
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
import net.kyori.adventure.text.format.TextDecoration;
|
import net.kyori.adventure.text.format.TextDecoration;
|
||||||
@@ -27,6 +31,7 @@ public final class ColorUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: find out way to do this
|
// TODO: find out way to do this
|
||||||
|
// TODO: add parsePlaceholders() to PlayerUser class
|
||||||
|
|
||||||
// if (user != null) {
|
// if (user != null) {
|
||||||
// final Player player = Bukkit.getPlayer(user.uuid());
|
// final Player player = Bukkit.getPlayer(user.uuid());
|
||||||
@@ -62,26 +67,40 @@ public final class ColorUtils {
|
|||||||
// TODO: check if MiniMessage or MineDown
|
// TODO: check if MiniMessage or MineDown
|
||||||
String output = input;
|
String output = input;
|
||||||
|
|
||||||
// Legacy RGB
|
String hexReplacement = "<#$1$2$3$4$5$6>";
|
||||||
output = spigotLegacyRGB.matcher(output).replaceAll("<#$1$2$3$4$5$6>");
|
boolean legacyCapable = false;
|
||||||
|
|
||||||
// Alternate RGB, TAB (neznamy) && KiteBoard
|
final MessageProcessor messageProcessor = CarbonChatProvider.carbonChat().messageProcessor();
|
||||||
output = pluginRGB.matcher(output).replaceAll("<#$1$2$3$4$5$6>");
|
|
||||||
|
|
||||||
// Legacy Colors
|
if (messageProcessor instanceof AdventureManager) {
|
||||||
for (final char c : "0123456789abcdef".toCharArray()) {
|
if (((AdventureManager) messageProcessor).formatType() == FormatType.MINEDOWN) {
|
||||||
final LegacyFormat format = LegacyComponentSerializer.parseChar(c);
|
hexReplacement = "&#$1$2$3$4$5$6&";
|
||||||
final TextColor color = format.color();
|
legacyCapable = true;
|
||||||
|
}
|
||||||
output = output.replaceAll("[§&]" + c, "<" + color.asHexString() + ">");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Legacy Formatting
|
// Legacy RGB
|
||||||
for (final char c : "klmno".toCharArray()) {
|
output = spigotLegacyRGB.matcher(output).replaceAll(hexReplacement);
|
||||||
final LegacyFormat format = LegacyComponentSerializer.parseChar(c);
|
|
||||||
final TextDecoration decoration = format.decoration();
|
|
||||||
|
|
||||||
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;
|
return output;
|
||||||
|
|||||||
Reference in new issue
Block a user