mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 14:38:49 +00:00
Progress on CarbonChat-Common
This commit is contained in:
1 parent
508ad88e26
commit
64295c84ea
60 files changed
+889
-556
No files matched your search
@@ -1,4 +1,22 @@
|
||||
package net.draycia.carbon.api;
|
||||
|
||||
public class CarbonChat {
|
||||
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.CommandSettingsRegistry;
|
||||
import net.draycia.carbon.api.users.UserService;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public interface CarbonChat {
|
||||
|
||||
@NonNull UserService userService();
|
||||
|
||||
@NonNull MessageProcessor messageProcessor();
|
||||
|
||||
@NonNull ChannelRegistry channelRegistry();
|
||||
|
||||
@NonNull CommandSettingsRegistry commandSettingsRegistry();
|
||||
|
||||
@NonNull CarbonTranslations translations();
|
||||
|
||||
}
|
||||
+201
@@ -0,0 +1,201 @@
|
||||
package net.draycia.carbon.api.adventure;
|
||||
|
||||
import org.spongepowered.configurate.BasicConfigurationNode;
|
||||
import org.spongepowered.configurate.objectmapping.ObjectMapper;
|
||||
import org.spongepowered.configurate.objectmapping.ObjectMappingException;
|
||||
import org.spongepowered.configurate.objectmapping.Setting;
|
||||
import org.spongepowered.configurate.serialize.ConfigSerializable;
|
||||
|
||||
@ConfigSerializable
|
||||
public class CarbonTranslations {
|
||||
|
||||
private static final ObjectMapper<CarbonTranslations> MAPPER;
|
||||
|
||||
static {
|
||||
try {
|
||||
MAPPER = ObjectMapper.forClass(CarbonTranslations.class); // We hold on to the instance of our ObjectMapper
|
||||
} catch (final ObjectMappingException e) {
|
||||
throw new ExceptionInInitializerError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static CarbonTranslations loadFrom(final BasicConfigurationNode node) throws ObjectMappingException {
|
||||
return MAPPER.bindToNew().populate(node);
|
||||
}
|
||||
|
||||
public void saveTo(final BasicConfigurationNode node) throws ObjectMappingException {
|
||||
MAPPER.bind(this).serialize(node);
|
||||
}
|
||||
|
||||
@Setting private String reloaded = "<yellow>Chat config has been reloaded!";
|
||||
@Setting private String messageToOther = "<green>[<gray>Me <gold>-> <gray><target><reset><green>] <message>";
|
||||
@Setting private String messageFromOther = "<green>[<gray><sender><reset> <gold>-> <gray>Me<green>] <message>";
|
||||
@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 noReplyTarget = "<red>You have no one to reply to!";
|
||||
@Setting private String otherNicknameSet = "<green><user><reset>''s nickname was set to <nickname><green>!";
|
||||
@Setting private String otherNicknameReset = "<green><user><reset>'s nickname was reset!";
|
||||
@Setting private String availableChannelsList = "<green>Available Channels:<reset> <list>.";
|
||||
@Setting private String unavailableChannelsList = "<red>Unavailable Channels:<reset> <list>.";
|
||||
@Setting private String channelListSeparator = ", ";
|
||||
@Setting private String userMustBeOnline = "<red><player> must be online!";
|
||||
@Setting private String replyMessageBlank = "<red>Your reply message was blank!";
|
||||
@Setting private String invalidColor = "<red>The input <input> is not a valid color!";
|
||||
@Setting private String cannotSetColor = "<red>You do not have permission to set a color for this channel!";
|
||||
@Setting private String roleplayFormat = "<italic><dark_purple>*<displayname> <reset><message>*</dark_purple></italic>";
|
||||
@Setting private String ignoringUser = "<green>You are now ignoring <gold><player><reset><green>!";
|
||||
@Setting private String notIgnoringUser = "<green>You are no longer ignoring <gold><player><reset><green>!";
|
||||
@Setting private String ignoreExempt = "<red>User <player> <red>is exempt from being ignored!";
|
||||
@Setting private String channelColorSet = "<green>You have set <color><channel> <green>color to <hex>!";
|
||||
@Setting private String spyToggledOn = "<gray>You are now spying on <color><channel> <gray>chat!";
|
||||
@Setting private String spyToggledOff = "<gray>You are no longer spying on <color><channel> <gray>chat!";
|
||||
@Setting private String spyWhispersOn = "<gray>You are now spying on whispers!";
|
||||
@Setting private String spyWhispersOff = "<gray>You are no longer spying on whispers!";
|
||||
@Setting private String nicknameSet = "<green>Your nickname was set to <nickname><reset><green>!";
|
||||
@Setting private String nicknameReset = "<green>Your nickname was reset!";
|
||||
@Setting private String nowShadowMuted = "<yellow>Player <player> is now shadow muted!";
|
||||
@Setting private String noLongerShadowMuted = "<yellow>Player <player> is no longer shadow muted!";
|
||||
@Setting private String shadowMuteExempt = "<red>Player <player> is exempt from being shadow muted!";
|
||||
@Setting private String nowMuted = "<yellow>Player <player> is now muted!";
|
||||
@Setting private String noLongerMuted = "<yellow>Player <player> is no longer muted!";
|
||||
@Setting private String muteExempt = "<red>Player <player> is exempt from being muted!";
|
||||
@Setting private String clearNotify = "<yellow>Chat has been cleared by <player>.";
|
||||
@Setting private String clearExempt = "<yellow>You were exempt from the clear due to your permissions!";
|
||||
|
||||
public String reloaded() {
|
||||
return this.reloaded;
|
||||
}
|
||||
|
||||
public String messageToOther() {
|
||||
return this.messageToOther;
|
||||
}
|
||||
|
||||
public String messageFromOther() {
|
||||
return this.messageFromOther;
|
||||
}
|
||||
|
||||
public String otherPlayerOffline() {
|
||||
return this.otherPlayerOffline;
|
||||
}
|
||||
|
||||
public String spyWhispers() {
|
||||
return this.spyWhispers;
|
||||
}
|
||||
|
||||
public String noReplyTarget() {
|
||||
return this.noReplyTarget;
|
||||
}
|
||||
|
||||
public String otherNicknameSet() {
|
||||
return this.otherNicknameSet;
|
||||
}
|
||||
|
||||
public String otherNicknameReset() {
|
||||
return this.otherNicknameReset;
|
||||
}
|
||||
|
||||
public String availableChannelsList() {
|
||||
return this.availableChannelsList;
|
||||
}
|
||||
|
||||
public String unavailableChannelsList() {
|
||||
return this.unavailableChannelsList;
|
||||
}
|
||||
|
||||
public String channelListSeparator() {
|
||||
return this.channelListSeparator;
|
||||
}
|
||||
|
||||
public String userMustBeOnline() {
|
||||
return this.userMustBeOnline;
|
||||
}
|
||||
|
||||
public String replyMessageBlank() {
|
||||
return this.replyMessageBlank;
|
||||
}
|
||||
|
||||
public String invalidColor() {
|
||||
return this.invalidColor;
|
||||
}
|
||||
|
||||
public String cannotSetColor() {
|
||||
return this.cannotSetColor;
|
||||
}
|
||||
|
||||
public String roleplayFormat() {
|
||||
return this.roleplayFormat;
|
||||
}
|
||||
|
||||
public String ignoringUser() {
|
||||
return this.ignoringUser;
|
||||
}
|
||||
|
||||
public String notIgnoringUser() {
|
||||
return this.notIgnoringUser;
|
||||
}
|
||||
|
||||
public String ignoreExempt() {
|
||||
return this.ignoreExempt;
|
||||
}
|
||||
|
||||
public String channelColorSet() {
|
||||
return this.channelColorSet;
|
||||
}
|
||||
|
||||
public String spyToggledOn() {
|
||||
return this.spyToggledOn;
|
||||
}
|
||||
|
||||
public String spyToggledOff() {
|
||||
return this.spyToggledOff;
|
||||
}
|
||||
|
||||
public String spyWhispersOn() {
|
||||
return this.spyWhispersOn;
|
||||
}
|
||||
|
||||
public String spyWhispersOff() {
|
||||
return this.spyWhispersOff;
|
||||
}
|
||||
|
||||
public String nicknameSet() {
|
||||
return this.nicknameSet;
|
||||
}
|
||||
|
||||
public String nicknameReset() {
|
||||
return this.nicknameReset;
|
||||
}
|
||||
|
||||
public String nowShadowMuted() {
|
||||
return this.nowShadowMuted;
|
||||
}
|
||||
|
||||
public String noLongerShadowMuted() {
|
||||
return this.noLongerShadowMuted;
|
||||
}
|
||||
|
||||
public String shadowMuteExempt() {
|
||||
return this.shadowMuteExempt;
|
||||
}
|
||||
|
||||
public String nowMuted() {
|
||||
return this.nowMuted;
|
||||
}
|
||||
|
||||
public String noLongerMuted() {
|
||||
return this.noLongerMuted;
|
||||
}
|
||||
|
||||
public String muteExempt() {
|
||||
return this.muteExempt;
|
||||
}
|
||||
|
||||
public String clearNotify() {
|
||||
return this.clearNotify;
|
||||
}
|
||||
|
||||
public String clearExempt() {
|
||||
return this.clearExempt;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package net.draycia.carbon.api.adventure;
|
||||
|
||||
import net.kyori.adventure.platform.AudienceProvider;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public interface MessageProcessor {
|
||||
|
||||
@NonNull Component processMessage(@Nullable final String input, @NonNull final String @NonNull ... placeholders);
|
||||
|
||||
@NonNull AudienceProvider audiences();
|
||||
|
||||
}
|
||||
@@ -14,10 +14,17 @@ public class ChannelRegistry implements Registry<String, ChatChannel> {
|
||||
@NonNull
|
||||
private final Map<@NonNull String, @NonNull ChatChannel> registry = new HashMap<>();
|
||||
|
||||
@Nullable
|
||||
private ChatChannel defaultChannel = null;
|
||||
|
||||
@Override
|
||||
public @NonNull ChatChannel register(@NonNull final String key, @NonNull final ChatChannel value) {
|
||||
this.registry.putIfAbsent(key, value);
|
||||
|
||||
if (this.defaultChannel == null && value.isDefault()) {
|
||||
this.defaultChannel = value;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -26,6 +33,10 @@ public class ChannelRegistry implements Registry<String, ChatChannel> {
|
||||
return this.registry.get(key);
|
||||
}
|
||||
|
||||
public @Nullable ChatChannel channelOrDefault(@NonNull final String key) {
|
||||
return this.registry.getOrDefault(key, this.defaultChannel());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String key(@NonNull final ChatChannel value) {
|
||||
return null;
|
||||
@@ -40,4 +51,9 @@ public class ChannelRegistry implements Registry<String, ChatChannel> {
|
||||
public @NonNull Iterator<ChatChannel> iterator() {
|
||||
return this.registry.values().iterator();
|
||||
}
|
||||
|
||||
public @Nullable ChatChannel defaultChannel() {
|
||||
return this.defaultChannel;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,18 +1,22 @@
|
||||
package net.draycia.carbon.api.commands;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.spongepowered.configurate.objectmapping.Setting;
|
||||
import org.spongepowered.configurate.serialize.ConfigSerializable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ConfigSerializable
|
||||
public class CommandSettings {
|
||||
|
||||
@Setting
|
||||
private final boolean enabled;
|
||||
|
||||
@NonNull
|
||||
private final String name;
|
||||
@Setting
|
||||
private @NonNull final String name;
|
||||
|
||||
@NonNull
|
||||
private final List<@NonNull String> aliases;
|
||||
@Setting
|
||||
private @NonNull final List<@NonNull String> aliases;
|
||||
|
||||
public CommandSettings(final boolean enabled, @NonNull final String name, @NonNull final List<@NonNull String> aliases) {
|
||||
this.enabled = enabled;
|
||||
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
package net.draycia.carbon.api.commands;
|
||||
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.kyori.registry.Registry;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.spongepowered.configurate.BasicConfigurationNode;
|
||||
import org.spongepowered.configurate.objectmapping.ObjectMapper;
|
||||
import org.spongepowered.configurate.objectmapping.ObjectMappingException;
|
||||
import org.spongepowered.configurate.objectmapping.Setting;
|
||||
import org.spongepowered.configurate.serialize.ConfigSerializable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@ConfigSerializable
|
||||
public class CommandSettingsRegistry implements Registry<String, CommandSettings> {
|
||||
|
||||
private static final ObjectMapper<CommandSettingsRegistry> MAPPER;
|
||||
|
||||
static {
|
||||
try {
|
||||
MAPPER = ObjectMapper.forClass(CommandSettingsRegistry.class); // We hold on to the instance of our ObjectMapper
|
||||
} catch (final ObjectMappingException e) {
|
||||
throw new ExceptionInInitializerError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static CommandSettingsRegistry loadFrom(final BasicConfigurationNode node) throws ObjectMappingException {
|
||||
return MAPPER.bindToNew().populate(node);
|
||||
}
|
||||
|
||||
public void saveTo(final BasicConfigurationNode node) throws ObjectMappingException {
|
||||
MAPPER.bind(this).serialize(node);
|
||||
}
|
||||
|
||||
@Setting
|
||||
private @NonNull final Map<@NonNull String, @NonNull CommandSettings> registry = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public @NonNull CommandSettings register(@NonNull final String key, @NonNull final CommandSettings value) {
|
||||
this.registry.put(key, value);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable CommandSettings get(@NonNull final String key) {
|
||||
return this.registry.get(key);
|
||||
}
|
||||
|
||||
public @Nullable CommandSettings get(@NonNull final ChatChannel channel) {
|
||||
return this.get(channel.key());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String key(@NonNull final CommandSettings value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Set<String> keySet() {
|
||||
return this.registry.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Iterator<CommandSettings> iterator() {
|
||||
return this.registry.values().iterator();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user